@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
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
var _a;
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.McpServiceToken = void 0;
|
|
55
|
+
var node_crypto_1 = require("node:crypto");
|
|
56
|
+
var luxon_1 = require("luxon");
|
|
57
|
+
var mongoose_1 = __importDefault(require("mongoose"));
|
|
58
|
+
var plugins_1 = require("../plugins");
|
|
59
|
+
var MCP_SERVICE_TOKEN_PREFIX = "mcp_";
|
|
60
|
+
var MCP_SERVICE_TOKEN_RANDOM_BYTES = 32;
|
|
61
|
+
var MCP_SERVICE_TOKEN_DISPLAY_LENGTH = 8;
|
|
62
|
+
var hashToken = function (token) { return (0, node_crypto_1.createHash)("sha256").update(token).digest("hex"); };
|
|
63
|
+
var mcpServiceTokenSchema = new mongoose_1.default.Schema({
|
|
64
|
+
expiresAt: {
|
|
65
|
+
description: "When this MCP service token expires; unset when it does not expire",
|
|
66
|
+
type: Date,
|
|
67
|
+
},
|
|
68
|
+
lastUsedAt: {
|
|
69
|
+
description: "When this MCP service token most recently authenticated an MCP request",
|
|
70
|
+
type: Date,
|
|
71
|
+
},
|
|
72
|
+
name: {
|
|
73
|
+
description: "User-provided label identifying the MCP service token",
|
|
74
|
+
required: true,
|
|
75
|
+
trim: true,
|
|
76
|
+
type: String,
|
|
77
|
+
},
|
|
78
|
+
revokedAt: {
|
|
79
|
+
description: "When this MCP service token was revoked; unset while it remains active",
|
|
80
|
+
type: Date,
|
|
81
|
+
},
|
|
82
|
+
tokenHash: {
|
|
83
|
+
description: "SHA-256 hash of the full MCP service token plaintext",
|
|
84
|
+
required: true,
|
|
85
|
+
type: String,
|
|
86
|
+
unique: true,
|
|
87
|
+
},
|
|
88
|
+
tokenPrefix: {
|
|
89
|
+
description: "First eight characters after mcp_ used to identify the token safely",
|
|
90
|
+
required: true,
|
|
91
|
+
type: String,
|
|
92
|
+
},
|
|
93
|
+
userId: {
|
|
94
|
+
description: "The user this MCP service token acts as",
|
|
95
|
+
index: true,
|
|
96
|
+
ref: "User",
|
|
97
|
+
required: true,
|
|
98
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
99
|
+
},
|
|
100
|
+
}, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
|
|
101
|
+
mcpServiceTokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
102
|
+
mcpServiceTokenSchema.index({ revokedAt: 1, userId: 1 });
|
|
103
|
+
mcpServiceTokenSchema.plugin(plugins_1.createdUpdatedPlugin);
|
|
104
|
+
mcpServiceTokenSchema.plugin(plugins_1.findOneOrNone);
|
|
105
|
+
mcpServiceTokenSchema.plugin(plugins_1.findExactlyOne);
|
|
106
|
+
var revokeInsteadOfDelete = function (doc) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
switch (_a.label) {
|
|
109
|
+
case 0:
|
|
110
|
+
if (!doc) {
|
|
111
|
+
return [2 /*return*/, null];
|
|
112
|
+
}
|
|
113
|
+
if (!!doc.revokedAt) return [3 /*break*/, 2];
|
|
114
|
+
doc.set("revokedAt", luxon_1.DateTime.now().toJSDate());
|
|
115
|
+
return [4 /*yield*/, doc.save()];
|
|
116
|
+
case 1:
|
|
117
|
+
_a.sent();
|
|
118
|
+
_a.label = 2;
|
|
119
|
+
case 2: return [2 /*return*/, doc];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}); };
|
|
123
|
+
mcpServiceTokenSchema.methods = __assign(__assign({}, mcpServiceTokenSchema.methods), { deleteOne: function () {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
var revoked;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0: return [4 /*yield*/, revokeInsteadOfDelete(this)];
|
|
129
|
+
case 1:
|
|
130
|
+
revoked = _a.sent();
|
|
131
|
+
return [2 /*return*/, revoked !== null && revoked !== void 0 ? revoked : this];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
} });
|
|
136
|
+
mcpServiceTokenSchema.pre("deleteOne", { document: false, query: true }, function () {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
+
var existing;
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
switch (_a.label) {
|
|
141
|
+
case 0: return [4 /*yield*/, (0, plugins_1.findOneOrNoneFor)(this.model, this.getFilter())];
|
|
142
|
+
case 1:
|
|
143
|
+
existing = _a.sent();
|
|
144
|
+
return [4 /*yield*/, revokeInsteadOfDelete(existing)];
|
|
145
|
+
case 2:
|
|
146
|
+
_a.sent();
|
|
147
|
+
this.setQuery({ _id: { $exists: false } });
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
mcpServiceTokenSchema.statics = __assign(__assign({}, mcpServiceTokenSchema.statics), { countActiveForUser: function (userId) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var now;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
now = luxon_1.DateTime.now().toJSDate();
|
|
158
|
+
return [2 /*return*/, this.countDocuments({
|
|
159
|
+
$or: [{ expiresAt: { $exists: false } }, { expiresAt: { $gt: now } }],
|
|
160
|
+
revokedAt: { $exists: false },
|
|
161
|
+
userId: userId,
|
|
162
|
+
})];
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}, issueFor: function (user, options) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
var token, mcpServiceToken;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
token = "".concat(MCP_SERVICE_TOKEN_PREFIX).concat((0, node_crypto_1.randomBytes)(MCP_SERVICE_TOKEN_RANDOM_BYTES).toString("hex"));
|
|
172
|
+
return [4 /*yield*/, this.create({
|
|
173
|
+
expiresAt: options.expiresAt,
|
|
174
|
+
name: options.name,
|
|
175
|
+
tokenHash: hashToken(token),
|
|
176
|
+
tokenPrefix: token.slice(MCP_SERVICE_TOKEN_PREFIX.length, MCP_SERVICE_TOKEN_PREFIX.length + MCP_SERVICE_TOKEN_DISPLAY_LENGTH),
|
|
177
|
+
userId: new mongoose_1.default.Types.ObjectId(String(user._id)),
|
|
178
|
+
})];
|
|
179
|
+
case 1:
|
|
180
|
+
mcpServiceToken = _a.sent();
|
|
181
|
+
return [2 /*return*/, { mcpServiceToken: mcpServiceToken, token: token }];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}, revokeForUser: function (user, tokenId) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
return [2 /*return*/, this.findOneAndUpdate({
|
|
189
|
+
_id: tokenId,
|
|
190
|
+
revokedAt: { $exists: false },
|
|
191
|
+
userId: new mongoose_1.default.Types.ObjectId(String(user._id)),
|
|
192
|
+
}, { $set: { revokedAt: luxon_1.DateTime.now().toJSDate() } }, { returnDocument: "after" })];
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}, verify: function (token) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
var now;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
now = luxon_1.DateTime.now().toJSDate();
|
|
200
|
+
return [2 /*return*/, this.findOneOrNone({
|
|
201
|
+
$or: [{ expiresAt: { $exists: false } }, { expiresAt: { $gt: now } }],
|
|
202
|
+
revokedAt: { $exists: false },
|
|
203
|
+
tokenHash: hashToken(token),
|
|
204
|
+
})];
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
} });
|
|
208
|
+
exports.McpServiceToken = (_a = mongoose_1.default.models.McpServiceToken) !== null && _a !== void 0 ? _a : mongoose_1.default.model("McpServiceToken", mcpServiceTokenSchema);
|
package/dist/openApiBuilder.d.ts
CHANGED
|
@@ -489,13 +489,14 @@ export declare class OpenApiMiddlewareBuilder {
|
|
|
489
489
|
* that integrates with the OpenAPI documentation system. If no OpenAPI
|
|
490
490
|
* path is configured in options, returns a no-op middleware.
|
|
491
491
|
*
|
|
492
|
-
* If validation was enabled via `withValidation()`,
|
|
493
|
-
*
|
|
492
|
+
* If validation was enabled via `withValidation()`, body and query
|
|
493
|
+
* validators are composed into the same RequestHandler (they still run
|
|
494
|
+
* in order: OpenAPI docs, then body, then query).
|
|
494
495
|
*
|
|
495
496
|
* Default error responses (400, 401, 403, 404, 405) are automatically
|
|
496
497
|
* merged with the configured responses.
|
|
497
498
|
*
|
|
498
|
-
* @returns Express middleware
|
|
499
|
+
* @returns Express middleware for OpenAPI documentation and optional validation
|
|
499
500
|
*
|
|
500
501
|
* @example
|
|
501
502
|
* ```typescript
|
|
@@ -507,7 +508,7 @@ export declare class OpenApiMiddlewareBuilder {
|
|
|
507
508
|
* router.get("/users/:id", middleware, getUserHandler);
|
|
508
509
|
* ```
|
|
509
510
|
*/
|
|
510
|
-
build():
|
|
511
|
+
build(): express.RequestHandler;
|
|
511
512
|
}
|
|
512
513
|
/**
|
|
513
514
|
* Creates a new OpenAPI middleware builder.
|
package/dist/openApiBuilder.js
CHANGED
|
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __values = (this && this.__values) || function(o) {
|
|
14
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
|
+
if (m) return m.call(o);
|
|
16
|
+
if (o && typeof o.length === "number") return {
|
|
17
|
+
next: function () {
|
|
18
|
+
if (o && i >= o.length) o = void 0;
|
|
19
|
+
return { value: o && o[i++], done: !o };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
23
|
+
};
|
|
13
24
|
var __read = (this && this.__read) || function (o, n) {
|
|
14
25
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
26
|
if (!m) return o;
|
|
@@ -35,6 +46,51 @@ var merge_1 = __importDefault(require("lodash/merge"));
|
|
|
35
46
|
var logger_1 = require("./logger");
|
|
36
47
|
var openApi_1 = require("./openApi");
|
|
37
48
|
var openApiValidator_1 = require("./openApiValidator");
|
|
49
|
+
var layer_schema_1 = require("./vendor/wesleytodd-openapi/lib/layer-schema");
|
|
50
|
+
/**
|
|
51
|
+
* Run handlers in order as one Express middleware function.
|
|
52
|
+
*
|
|
53
|
+
* `@wesleytodd/openapi` stores path schemas on a Map keyed by the function
|
|
54
|
+
* Express registers. Copying the schema from the documentation handler onto
|
|
55
|
+
* the composed function keeps `/openapi.json` generation working.
|
|
56
|
+
*/
|
|
57
|
+
var composeRequestHandlers = function (handlers) {
|
|
58
|
+
var e_1, _c;
|
|
59
|
+
var composed = function (req, res, next) {
|
|
60
|
+
var run = function (index) {
|
|
61
|
+
if (index >= handlers.length) {
|
|
62
|
+
next();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
handlers[index](req, res, function (error) {
|
|
66
|
+
if (error) {
|
|
67
|
+
next(error);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
run(index + 1);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
run(0);
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
for (var handlers_1 = __values(handlers), handlers_1_1 = handlers_1.next(); !handlers_1_1.done; handlers_1_1 = handlers_1.next()) {
|
|
77
|
+
var handler = handlers_1_1.value;
|
|
78
|
+
var schema = (0, layer_schema_1.get)(handler);
|
|
79
|
+
if (schema) {
|
|
80
|
+
(0, layer_schema_1.set)(composed, schema);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
+
finally {
|
|
87
|
+
try {
|
|
88
|
+
if (handlers_1_1 && !handlers_1_1.done && (_c = handlers_1.return)) _c.call(handlers_1);
|
|
89
|
+
}
|
|
90
|
+
finally { if (e_1) throw e_1.error; }
|
|
91
|
+
}
|
|
92
|
+
return composed;
|
|
93
|
+
};
|
|
38
94
|
/**
|
|
39
95
|
* A fluent builder for constructing OpenAPI middleware.
|
|
40
96
|
*
|
|
@@ -441,13 +497,14 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
441
497
|
* that integrates with the OpenAPI documentation system. If no OpenAPI
|
|
442
498
|
* path is configured in options, returns a no-op middleware.
|
|
443
499
|
*
|
|
444
|
-
* If validation was enabled via `withValidation()`,
|
|
445
|
-
*
|
|
500
|
+
* If validation was enabled via `withValidation()`, body and query
|
|
501
|
+
* validators are composed into the same RequestHandler (they still run
|
|
502
|
+
* in order: OpenAPI docs, then body, then query).
|
|
446
503
|
*
|
|
447
504
|
* Default error responses (400, 401, 403, 404, 405) are automatically
|
|
448
505
|
* merged with the configured responses.
|
|
449
506
|
*
|
|
450
|
-
* @returns Express middleware
|
|
507
|
+
* @returns Express middleware for OpenAPI documentation and optional validation
|
|
451
508
|
*
|
|
452
509
|
* @example
|
|
453
510
|
* ```typescript
|
|
@@ -459,8 +516,6 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
459
516
|
* router.get("/users/:id", middleware, getUserHandler);
|
|
460
517
|
* ```
|
|
461
518
|
*/
|
|
462
|
-
// noExplicitAny: returns either a single RequestHandler or an array depending on validation config — callers spread or invoke
|
|
463
|
-
// biome-ignore lint/suspicious/noExplicitAny: returns either a single RequestHandler or an array depending on validation config
|
|
464
519
|
OpenApiMiddlewareBuilder.prototype.build = function () {
|
|
465
520
|
var _c, _d, _e, _f, _g;
|
|
466
521
|
var noop = function (_a, _b, next) { return next(); };
|
|
@@ -488,12 +543,10 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
488
543
|
if (this.validationConfig.validateQuery && Object.keys(this.queryParamSchemas).length > 0) {
|
|
489
544
|
validators.push((0, openApiValidator_1.validateQueryParams)(this.queryParamSchemas, { enabled: true }));
|
|
490
545
|
}
|
|
491
|
-
// If only one middleware (the openApi one), return it directly
|
|
492
546
|
if (validators.length === 1) {
|
|
493
547
|
return openApiMiddleware;
|
|
494
548
|
}
|
|
495
|
-
|
|
496
|
-
return validators;
|
|
549
|
+
return composeRequestHandlers(validators);
|
|
497
550
|
};
|
|
498
551
|
return OpenApiMiddlewareBuilder;
|
|
499
552
|
}());
|
package/dist/openApiCompat.js
CHANGED
|
@@ -202,7 +202,7 @@ var patchExpressRouterUse = function () {
|
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
204
|
var originalUse = useDescriptor.value;
|
|
205
|
-
Object.defineProperty(routerPrototype, "use", __assign(__assign({}, useDescriptor), { value: function
|
|
205
|
+
Object.defineProperty(routerPrototype, "use", __assign(__assign({}, useDescriptor), { value: function () {
|
|
206
206
|
var _a, _b;
|
|
207
207
|
var args = [];
|
|
208
208
|
for (var _i = 0; _i < arguments.length; _i++) {
|
package/dist/openApiValidator.js
CHANGED
|
@@ -191,8 +191,6 @@ var getAjvInstance = function () {
|
|
|
191
191
|
useDefaults: true,
|
|
192
192
|
validateSchema: false,
|
|
193
193
|
});
|
|
194
|
-
// noExplicitAny: ajv-formats has a known type compat issue with AJV instances
|
|
195
|
-
// biome-ignore lint/suspicious/noExplicitAny: ajv-formats has a known type compat issue with AJV instances
|
|
196
194
|
(0, ajv_formats_1.default)(instance);
|
|
197
195
|
ajvCache.set(key, instance);
|
|
198
196
|
}
|
package/dist/plugins.d.ts
CHANGED
|
@@ -6,6 +6,14 @@ export interface BaseUser {
|
|
|
6
6
|
email: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const baseUserPlugin: (schema: Schema<any, any, any, any>) => void;
|
|
9
|
+
export interface EmailVerified {
|
|
10
|
+
emailVerified: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Opt-in `emailVerified` field for user schemas. Defaults to false so existing
|
|
14
|
+
* documents stay unverified until they complete the email-verification flow.
|
|
15
|
+
*/
|
|
16
|
+
export declare const emailVerificationPlugin: (schema: Parameters<typeof baseUserPlugin>[0]) => void;
|
|
9
17
|
/** For models with the isDeletedPlugin, extend this interface to add the appropriate fields. */
|
|
10
18
|
export interface IsDeleted {
|
|
11
19
|
deleted: boolean;
|
|
@@ -85,7 +93,12 @@ export interface FindExactlyOnePlugin<T> {
|
|
|
85
93
|
export declare class DateOnly extends SchemaType {
|
|
86
94
|
constructor(key: string, options: SchemaTypeOptions<Date>);
|
|
87
95
|
handleSingle(val: unknown): Date | undefined;
|
|
88
|
-
$conditionalHandlers:
|
|
96
|
+
$conditionalHandlers: {
|
|
97
|
+
$gt: (val: unknown) => Date | undefined;
|
|
98
|
+
$gte: (val: unknown) => Date | undefined;
|
|
99
|
+
$lt: (val: unknown) => Date | undefined;
|
|
100
|
+
$lte: (val: unknown) => Date | undefined;
|
|
101
|
+
};
|
|
89
102
|
castForQuery($conditional: string | undefined, val: unknown, context: unknown): Date | undefined;
|
|
90
103
|
cast(val: unknown): Date | undefined;
|
|
91
104
|
get(val: unknown): this;
|
package/dist/plugins.js
CHANGED
|
@@ -95,7 +95,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
98
|
-
exports.DateOnly = exports.excludeArchivedPlugin = exports.upsertPlugin = exports.findExactlyOne = exports.findOneOrNoneFor = exports.findOneOrNone = exports.firebaseJWTPlugin = exports.createdUpdatedPlugin = exports.isDisabledPlugin = exports.isDeletedPlugin = exports.baseUserPlugin = void 0;
|
|
98
|
+
exports.DateOnly = exports.excludeArchivedPlugin = exports.upsertPlugin = exports.findExactlyOne = exports.findOneOrNoneFor = exports.findOneOrNone = exports.firebaseJWTPlugin = exports.createdUpdatedPlugin = exports.isDisabledPlugin = exports.isDeletedPlugin = exports.emailVerificationPlugin = exports.baseUserPlugin = void 0;
|
|
99
99
|
var luxon_1 = require("luxon");
|
|
100
100
|
var mongoose_1 = __importStar(require("mongoose"));
|
|
101
101
|
var errors_1 = require("./errors");
|
|
@@ -123,6 +123,20 @@ var baseUserPlugin = function (schema) {
|
|
|
123
123
|
schema.add({ email: { description: "The user's email address", index: true, type: String } });
|
|
124
124
|
};
|
|
125
125
|
exports.baseUserPlugin = baseUserPlugin;
|
|
126
|
+
/**
|
|
127
|
+
* Opt-in `emailVerified` field for user schemas. Defaults to false so existing
|
|
128
|
+
* documents stay unverified until they complete the email-verification flow.
|
|
129
|
+
*/
|
|
130
|
+
var emailVerificationPlugin = function (schema) {
|
|
131
|
+
schema.add({
|
|
132
|
+
emailVerified: {
|
|
133
|
+
default: false,
|
|
134
|
+
description: "Whether the user has verified their email address",
|
|
135
|
+
type: Boolean,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
exports.emailVerificationPlugin = emailVerificationPlugin;
|
|
126
140
|
// noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
127
141
|
// biome-ignore lint/suspicious/noExplicitAny: Schema generics must be loose to accept arbitrary consumer schemas
|
|
128
142
|
var isDeletedPlugin = function (schema, defaultValue) {
|
|
@@ -404,7 +418,8 @@ var DateOnly = /** @class */ (function (_super) {
|
|
|
404
418
|
__extends(DateOnly, _super);
|
|
405
419
|
function DateOnly(key, options) {
|
|
406
420
|
var _this = _super.call(this, key, options, "DateOnly") || this;
|
|
407
|
-
_this.$conditionalHandlers = __assign(__assign({}, mongoose_1.SchemaType.prototype
|
|
421
|
+
_this.$conditionalHandlers = __assign(__assign({}, mongoose_1.SchemaType.prototype
|
|
422
|
+
.$conditionalHandlers), { $gt: _this.handleSingle, $gte: _this.handleSingle, $lt: _this.handleSingle, $lte: _this.handleSingle });
|
|
408
423
|
return _this;
|
|
409
424
|
}
|
|
410
425
|
DateOnly.prototype.handleSingle = function (val) {
|
|
@@ -414,8 +429,6 @@ var DateOnly = /** @class */ (function (_super) {
|
|
|
414
429
|
// When using $gt, $gte, $lt, $lte, etc, we need to cast the value to a Date
|
|
415
430
|
DateOnly.prototype.castForQuery = function ($conditional, val, context) {
|
|
416
431
|
if ($conditional == null) {
|
|
417
|
-
// noExplicitAny: applySetters is an internal Mongoose SchemaType method not in public type definitions
|
|
418
|
-
// biome-ignore lint/suspicious/noExplicitAny: applySetters is an internal Mongoose SchemaType method not in public type definitions
|
|
419
432
|
return this.applySetters(val, context);
|
|
420
433
|
}
|
|
421
434
|
var handler = this.$conditionalHandlers[$conditional];
|
|
@@ -462,6 +475,4 @@ var DateOnly = /** @class */ (function (_super) {
|
|
|
462
475
|
}(mongoose_1.SchemaType));
|
|
463
476
|
exports.DateOnly = DateOnly;
|
|
464
477
|
// Register DateOnly with Mongoose's Schema.Types
|
|
465
|
-
// noExplicitAny: DateOnly is a custom SchemaType not declared in Mongoose's Schema.Types interface
|
|
466
|
-
// biome-ignore lint/suspicious/noExplicitAny: DateOnly is a custom SchemaType not declared in Mongoose's Schema.Types interface
|
|
467
478
|
mongoose_1.default.Schema.Types.DateOnly = DateOnly;
|
package/dist/populate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Document, Schema } from "mongoose";
|
|
1
|
+
import type { Document, Model, Schema } from "mongoose";
|
|
2
2
|
interface OpenApiSchemaNode {
|
|
3
3
|
description?: string;
|
|
4
4
|
items?: OpenApiSchemaNode;
|
|
@@ -11,7 +11,7 @@ export interface PopulatePath {
|
|
|
11
11
|
fields?: string[];
|
|
12
12
|
}
|
|
13
13
|
export declare const fixMixedFields: (schema: Schema | null, properties: Record<string, OpenApiSchemaNode> | Record<string, unknown> | null) => void;
|
|
14
|
-
export declare const getOpenApiSpecForModel: (model:
|
|
14
|
+
export declare const getOpenApiSpecForModel: <T>(model: Model<T>, { populatePaths, extraModelProperties, }?: {
|
|
15
15
|
populatePaths?: PopulatePath[];
|
|
16
16
|
extraModelProperties?: Record<string, unknown>;
|
|
17
17
|
}) => {
|