@terreno/api 57.4.0 → 57.6.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 +5 -5
- package/bunfig.toml +1 -1
- package/dist/actions.js +197 -368
- package/dist/adminModelRouter.js +88 -173
- package/dist/api.js +598 -852
- package/dist/audit/auditApp.js +48 -89
- package/dist/audit/auditEventModel.js +15 -16
- package/dist/audit/cloudTasksEnqueue.js +56 -149
- package/dist/audit/diff.js +70 -160
- package/dist/audit/processQueue.js +25 -70
- package/dist/audit/rbacSink.js +25 -66
- package/dist/audit/record.js +129 -251
- package/dist/auth.js +432 -681
- package/dist/authRecovery.js +155 -269
- package/dist/authTokens.js +43 -118
- package/dist/betterAuthApp.js +25 -26
- package/dist/betterAuthSetup.js +258 -413
- package/dist/browserLogsRoute.d.ts +6 -0
- package/dist/browserLogsRoute.js +97 -0
- package/dist/collectionRegistry.js +32 -47
- package/dist/config.js +53 -122
- package/dist/configurationApp.js +180 -361
- package/dist/configurationPlugin.js +130 -302
- package/dist/consentApp.js +276 -421
- package/dist/docLoader.js +78 -126
- package/dist/envConfigurationPlugin.js +25 -147
- package/dist/errors.js +151 -247
- package/dist/example.js +28 -34
- package/dist/expressServer.d.ts +10 -0
- package/dist/expressServer.js +109 -255
- package/dist/frameworkModelNames.d.ts +24 -0
- package/dist/frameworkModelNames.js +31 -0
- package/dist/githubAuth.js +152 -216
- package/dist/httpClient.js +176 -264
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -2
- package/dist/logger.js +145 -278
- package/dist/mcp/auth.js +76 -128
- package/dist/mcp/createMCPRequest.js +4 -5
- package/dist/mcp/handlers.js +268 -480
- package/dist/mcp/query.js +56 -150
- package/dist/mcp/registry.js +17 -30
- package/dist/mcp/schemaGenerator.js +95 -181
- package/dist/mcp/server.js +28 -100
- package/dist/mcp/serviceTokens.js +102 -191
- package/dist/mcp/toolGenerator.js +78 -191
- package/dist/middleware.js +15 -27
- package/dist/migrations/fixtures/all-down/20260910120000-one.js +2 -42
- package/dist/migrations/fixtures/all-down/20260910120001-two.js +2 -42
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +1 -39
- package/dist/migrations/fixtures/bad-name/not-a-migration.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120000-alpha.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120001-beta.js +2 -42
- package/dist/migrations/generate.js +107 -229
- package/dist/migrations/load.js +75 -201
- package/dist/migrations/lock.js +54 -126
- package/dist/migrations/runner.js +192 -446
- package/dist/migrations/schemaCatalog.js +122 -263
- package/dist/models/consentForm.js +6 -6
- package/dist/models/consentResponse.js +5 -5
- package/dist/models/mcpServiceToken.js +66 -156
- package/dist/models/notification.js +6 -6
- package/dist/models/notificationPreference.js +6 -6
- package/dist/models/versionConfig.js +5 -5
- package/dist/notifications/notificationService.js +133 -273
- package/dist/notifications/notificationsApp.js +85 -179
- package/dist/notifications/notificationsBeforeSend.js +19 -64
- package/dist/notifiers/googleChatNotifier.js +36 -117
- package/dist/notifiers/slackNotifier.d.ts +31 -2
- package/dist/notifiers/slackNotifier.js +170 -119
- package/dist/notifiers/zoomNotifier.js +60 -111
- package/dist/openApi.js +107 -122
- package/dist/openApiBuilder.js +117 -159
- package/dist/openApiCompat.js +81 -148
- package/dist/openApiEtag.js +7 -7
- package/dist/openApiValidator.js +177 -286
- package/dist/orgs/orgContext.js +87 -157
- package/dist/orgs/orgPermissions.js +29 -68
- package/dist/orgs/orgPlugin.js +9 -27
- package/dist/orgs/organizationModel.js +65 -166
- package/dist/orgs/organizationSettings.js +29 -36
- package/dist/orgs/orgsApp.js +346 -608
- package/dist/permissions.js +88 -181
- package/dist/plugins.js +125 -218
- package/dist/populate.js +130 -240
- package/dist/rateLimit/applyTrustProxy.js +1 -1
- package/dist/rateLimit/createStore.js +7 -8
- package/dist/rateLimit/memoryStore.js +22 -100
- package/dist/rateLimit/middleware.js +48 -99
- package/dist/rateLimit/mongoStore.js +54 -112
- package/dist/rateLimit/policies.js +41 -75
- package/dist/rateLimit/redisStore.js +39 -133
- package/dist/rbac/access.js +119 -267
- package/dist/rbac/assertAllowed.js +95 -171
- package/dist/rbac/auditModel.js +14 -58
- package/dist/rbac/backfillAdmins.js +24 -130
- package/dist/rbac/fieldViews.js +46 -141
- package/dist/rbac/membershipOrgAdminSource.js +28 -99
- package/dist/rbac/middleware.js +30 -96
- package/dist/rbac/modelRouterAccess.js +130 -307
- package/dist/rbac/permissionUtils.js +40 -179
- package/dist/rbac/realtimeAccess.js +81 -147
- package/dist/rbac/resolve.d.ts +1 -1
- package/dist/rbac/resolve.js +148 -342
- package/dist/rbac/roleManager.js +318 -700
- package/dist/rbac/roleModel.js +44 -171
- package/dist/rbac/routes.js +93 -196
- package/dist/rbac/scopes.js +39 -133
- package/dist/rbac/statements.js +23 -91
- package/dist/rbac/userPlugin.js +3 -29
- package/dist/realtime/changeStreamWatcher.js +489 -800
- package/dist/realtime/deprecation.js +8 -10
- package/dist/realtime/queryMatcher.js +110 -191
- package/dist/realtime/queryStore.js +35 -118
- package/dist/realtime/realtimeApp.js +247 -401
- package/dist/realtime/registry.js +19 -30
- package/dist/realtime/sessionRevalidation.js +132 -358
- package/dist/realtime/socketAuth.js +89 -208
- package/dist/realtime/socketUser.js +10 -56
- package/dist/requestContext.js +93 -139
- package/dist/schemaMetadata.js +179 -274
- package/dist/scriptRunner.js +96 -266
- package/dist/scrubAdminFields.js +36 -108
- package/dist/secretProviders.js +130 -299
- package/dist/seedRunner.js +221 -514
- package/dist/sync/adminBroadcastScope.js +58 -170
- package/dist/sync/adminWindowAccess.js +15 -86
- package/dist/sync/adminWindowMutation.js +110 -181
- package/dist/sync/executors.js +425 -629
- package/dist/sync/loadHarness.js +392 -689
- package/dist/sync/models.js +181 -341
- package/dist/sync/mutationHandler.js +533 -801
- package/dist/sync/registrationSideEffects.js +41 -95
- package/dist/sync/registry.js +29 -49
- package/dist/sync/routes.js +484 -817
- package/dist/sync/scripts/compactTombstones.js +83 -228
- package/dist/sync/serialize.js +18 -58
- package/dist/sync/socketHandlers.js +253 -478
- package/dist/sync/streams.js +49 -117
- package/dist/sync/syncApp.js +12 -15
- package/dist/sync/syncBatch.js +63 -168
- package/dist/sync/syncSeqPlugin.js +430 -702
- package/dist/syncConsents.js +113 -253
- package/dist/terrenoApp.js +166 -276
- package/dist/tests/createTestData.js +146 -256
- package/dist/tests/models.js +14 -54
- package/dist/tests/mongoTestSetup.js +42 -103
- package/dist/tests/testHelper.js +31 -93
- package/dist/tests.js +12 -51
- package/dist/transformers.js +61 -164
- package/dist/utils.js +31 -93
- package/dist/vendor/wesleytodd-openapi/index.js +37 -51
- package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +32 -40
- package/dist/vendor/wesleytodd-openapi/lib/layer-schema.js +3 -3
- package/dist/vendor/wesleytodd-openapi/lib/ui.js +50 -19
- package/dist/vendor/wesleytodd-openapi/lib/validate.js +19 -47
- package/dist/versionCheckPlugin.js +52 -100
- package/dist/webhooks/headerValue.js +2 -2
- package/dist/webhooks/idempotency/memoryStore.js +16 -59
- package/dist/webhooks/idempotency/mongoStore.js +55 -130
- package/dist/webhooks/idempotency/webhookReceipt.js +9 -9
- package/dist/webhooks/rawBody.js +1 -1
- package/dist/webhooks/timingSafeEqual.js +4 -5
- package/dist/webhooks/verifiers/hmac.js +17 -18
- package/dist/webhooks/verifiers/sendgrid.js +20 -22
- package/dist/webhooks/verifiers/stripe.js +31 -65
- package/dist/webhooks/verifiers/twilio.js +23 -73
- package/dist/webhooks/webhooksApp.js +78 -177
- package/dist/zodOpenApi.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/browserLogsRoute.test.ts +165 -0
- package/src/audit/auditApp.test.ts +5 -5
- package/src/audit/auditEventModel.ts +7 -3
- package/src/audit/auditRouter.test.ts +5 -5
- package/src/audit/rbacSink.test.ts +2 -2
- package/src/audit/record.test.ts +2 -2
- package/src/audit/record.ts +3 -2
- package/src/auth.ts +1 -1
- package/src/authRecovery.test.ts +43 -0
- package/src/authRecovery.ts +16 -10
- package/src/authTokens.ts +6 -2
- package/src/authVerification.test.ts +22 -0
- package/src/browserLogsRoute.ts +110 -0
- package/src/configurationPlugin.test.ts +1 -11
- package/src/expressServer.ts +10 -0
- package/src/frameworkModelNames.test.ts +62 -0
- package/src/frameworkModelNames.ts +33 -0
- package/src/index.ts +7 -0
- package/src/isolated/migrateCliConnect.isolated.ts +51 -0
- package/src/mcp/auth.test.ts +34 -1
- package/src/migrations/cli.test.ts +0 -23
- package/src/models/mcpServiceToken.ts +4 -3
- package/src/models/notification.ts +3 -2
- package/src/models/notificationPreference.ts +1 -1
- package/src/notifications/notificationsApp.test.ts +24 -1
- package/src/notifiers/slackNotifier.test.ts +186 -1
- package/src/notifiers/slackNotifier.ts +167 -8
- package/src/orgs/orgPlugin.ts +1 -1
- package/src/orgs/organizationModel.ts +11 -6
- package/src/plugins.test.ts +5 -0
- package/src/plugins.ts +3 -0
- package/src/realtime/realtimeApp.ts +1 -1
- package/src/sync/integration.test.ts +2 -2
- package/src/terrenoApp.ts +3 -0
- package/src/types.d.ts +1 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
- package/tsconfig.json +13 -54
- package/tsconfig.typedoc.json +2 -0
|
@@ -1,162 +1,90 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
var __values = (this && this.__values) || function(o) {
|
|
28
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
29
|
-
if (m) return m.call(o);
|
|
30
|
-
if (o && typeof o.length === "number") return {
|
|
31
|
-
next: function () {
|
|
32
|
-
if (o && i >= o.length) o = void 0;
|
|
33
|
-
return { value: o && o[i++], done: !o };
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.generateToolDescription = exports.generateInputSchema = exports.writeExcludeFields = exports.restWriteExcludeFields = exports.isFieldExcluded = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return excludeFields.some(
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const schemaMetadata_1 = require("../schemaMetadata");
|
|
6
|
+
const OPERATOR_HINT = `{"$in": [...]} or {"$gte": ...}`;
|
|
7
|
+
const DOCUMENTED_FIELD_OPERATORS = "$eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $regex";
|
|
8
|
+
const isFieldExcluded = (fieldPath, excludeFields) => {
|
|
9
|
+
return excludeFields.some((excluded) => {
|
|
46
10
|
if (fieldPath === excluded) {
|
|
47
11
|
return true;
|
|
48
12
|
}
|
|
49
|
-
if (fieldPath.startsWith(
|
|
13
|
+
if (fieldPath.startsWith(`${excluded}.`)) {
|
|
50
14
|
return true;
|
|
51
15
|
}
|
|
52
16
|
return false;
|
|
53
17
|
});
|
|
54
18
|
};
|
|
55
19
|
exports.isFieldExcluded = isFieldExcluded;
|
|
56
|
-
|
|
57
|
-
var _a, _b;
|
|
20
|
+
const restWriteExcludeFields = (method, validation) => {
|
|
58
21
|
if (typeof validation !== "object" || validation === null) {
|
|
59
22
|
return [];
|
|
60
23
|
}
|
|
61
|
-
|
|
24
|
+
const options = validation;
|
|
62
25
|
if (method === "create") {
|
|
63
|
-
return
|
|
26
|
+
return options.excludeFromCreate ?? [];
|
|
64
27
|
}
|
|
65
28
|
if (method === "update") {
|
|
66
|
-
return
|
|
29
|
+
return options.excludeFromUpdate ?? [];
|
|
67
30
|
}
|
|
68
31
|
return [];
|
|
69
32
|
};
|
|
70
33
|
exports.restWriteExcludeFields = restWriteExcludeFields;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return __spreadArray(__spreadArray([], __read(((_a = config.excludeFields) !== null && _a !== void 0 ? _a : [])), false), __read(restExcludeFields), false);
|
|
34
|
+
const writeExcludeFields = (config, restExcludeFields) => {
|
|
35
|
+
return [...(config.excludeFields ?? []), ...restExcludeFields];
|
|
74
36
|
};
|
|
75
37
|
exports.writeExcludeFields = writeExcludeFields;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
path: path,
|
|
93
|
-
required: field.required,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
98
|
-
finally {
|
|
99
|
-
try {
|
|
100
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
101
|
-
}
|
|
102
|
-
finally { if (e_1) throw e_1.error; }
|
|
38
|
+
const getModelFields = (model, excludeFields) => {
|
|
39
|
+
const description = (0, schemaMetadata_1.describeModel)(model);
|
|
40
|
+
const fields = [];
|
|
41
|
+
for (const [path, field] of Object.entries(description.fields)) {
|
|
42
|
+
if (schemaMetadata_1.SYSTEM_FIELD_PATHS.has(path) || field.system) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if ((0, exports.isFieldExcluded)(path, excludeFields)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
fields.push({
|
|
49
|
+
description: field.description,
|
|
50
|
+
field,
|
|
51
|
+
path,
|
|
52
|
+
required: field.required,
|
|
53
|
+
});
|
|
103
54
|
}
|
|
104
55
|
return fields;
|
|
105
56
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var excludeFields = (0, exports.writeExcludeFields)(config, restExcludeFields);
|
|
111
|
-
var populatable = (populatePaths !== null && populatePaths !== void 0 ? populatePaths : []).map(function (populatePath) { return populatePath.path; });
|
|
112
|
-
var populateParam = populatable.length
|
|
57
|
+
const generateInputSchema = (model, method, config, queryFields, populatePaths, restExcludeFields = []) => {
|
|
58
|
+
const excludeFields = (0, exports.writeExcludeFields)(config, restExcludeFields);
|
|
59
|
+
const populatable = (populatePaths ?? []).map((populatePath) => populatePath.path);
|
|
60
|
+
const populateParam = populatable.length
|
|
113
61
|
? zod_1.z
|
|
114
62
|
.string()
|
|
115
63
|
.optional()
|
|
116
|
-
.describe(
|
|
64
|
+
.describe(`Comma-separated subset of the populate-able paths: ${populatable.join(", ")}`)
|
|
117
65
|
: undefined;
|
|
118
66
|
switch (method) {
|
|
119
67
|
case "create": {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
var zodType = (0, schemaMetadata_1.fieldDescriptionToZodType)(field, zod_1.z);
|
|
126
|
-
shape[path] = required ? zodType : zodType.optional();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
130
|
-
finally {
|
|
131
|
-
try {
|
|
132
|
-
if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1);
|
|
133
|
-
}
|
|
134
|
-
finally { if (e_2) throw e_2.error; }
|
|
68
|
+
const fields = getModelFields(model, excludeFields);
|
|
69
|
+
const shape = {};
|
|
70
|
+
for (const { field, path, required } of fields) {
|
|
71
|
+
const zodType = (0, schemaMetadata_1.fieldDescriptionToZodType)(field, zod_1.z);
|
|
72
|
+
shape[path] = required ? zodType : zodType.optional();
|
|
135
73
|
}
|
|
136
74
|
return zod_1.z.object(shape);
|
|
137
75
|
}
|
|
138
76
|
case "update": {
|
|
139
|
-
|
|
140
|
-
|
|
77
|
+
const fields = getModelFields(model, excludeFields);
|
|
78
|
+
const shape = {
|
|
141
79
|
id: zod_1.z.string().describe("Document ID to update"),
|
|
142
80
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var _f = fields_2_1.value, field = _f.field, path = _f.path;
|
|
146
|
-
shape[path] = (0, schemaMetadata_1.fieldDescriptionToZodType)(field, zod_1.z).optional();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
150
|
-
finally {
|
|
151
|
-
try {
|
|
152
|
-
if (fields_2_1 && !fields_2_1.done && (_b = fields_2.return)) _b.call(fields_2);
|
|
153
|
-
}
|
|
154
|
-
finally { if (e_3) throw e_3.error; }
|
|
81
|
+
for (const { field, path } of fields) {
|
|
82
|
+
shape[path] = (0, schemaMetadata_1.fieldDescriptionToZodType)(field, zod_1.z).optional();
|
|
155
83
|
}
|
|
156
84
|
return zod_1.z.object(shape);
|
|
157
85
|
}
|
|
158
86
|
case "read": {
|
|
159
|
-
|
|
87
|
+
const shape = {
|
|
160
88
|
id: zod_1.z.string().describe("Document ID to read"),
|
|
161
89
|
};
|
|
162
90
|
if (populateParam) {
|
|
@@ -165,44 +93,34 @@ var generateInputSchema = function (model, method, config, queryFields, populate
|
|
|
165
93
|
return zod_1.z.object(shape);
|
|
166
94
|
}
|
|
167
95
|
case "list": {
|
|
168
|
-
|
|
96
|
+
const shape = {
|
|
169
97
|
limit: zod_1.z
|
|
170
98
|
.number()
|
|
171
99
|
.optional()
|
|
172
|
-
.describe(
|
|
100
|
+
.describe(`Max items to return (default: ${config.maxLimit ?? 50})`),
|
|
173
101
|
page: zod_1.z.number().optional().describe("Page number (1-based)"),
|
|
174
102
|
sort: zod_1.z.string().optional().describe("Sort field (prefix with - for descending)"),
|
|
175
103
|
};
|
|
176
104
|
if (populateParam) {
|
|
177
105
|
shape.populate = populateParam;
|
|
178
106
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
.optional()
|
|
186
|
-
.describe("Filter by ".concat(field, ": an exact value or an operator object, e.g. ").concat(OPERATOR_HINT));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
190
|
-
finally {
|
|
191
|
-
try {
|
|
192
|
-
if (filterableFields_1_1 && !filterableFields_1_1.done && (_c = filterableFields_1.return)) _c.call(filterableFields_1);
|
|
193
|
-
}
|
|
194
|
-
finally { if (e_4) throw e_4.error; }
|
|
107
|
+
const filterableFields = (queryFields ?? []).filter((field) => !(0, exports.isFieldExcluded)(field, excludeFields));
|
|
108
|
+
for (const field of filterableFields) {
|
|
109
|
+
shape[field] = zod_1.z
|
|
110
|
+
.any()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe(`Filter by ${field}: an exact value or an operator object, e.g. ${OPERATOR_HINT}`);
|
|
195
113
|
}
|
|
196
114
|
if (filterableFields.length) {
|
|
197
|
-
|
|
115
|
+
const logicalDescription = `Combine filters on ${filterableFields.join(", ")}, e.g. [{"${filterableFields[0]}": ...}]`;
|
|
198
116
|
shape.$and = zod_1.z
|
|
199
117
|
.array(zod_1.z.record(zod_1.z.string(), zod_1.z.any()))
|
|
200
118
|
.optional()
|
|
201
|
-
.describe(
|
|
119
|
+
.describe(`Match all of these filters. ${logicalDescription}`);
|
|
202
120
|
shape.$or = zod_1.z
|
|
203
121
|
.array(zod_1.z.record(zod_1.z.string(), zod_1.z.any()))
|
|
204
122
|
.optional()
|
|
205
|
-
.describe(
|
|
123
|
+
.describe(`Match any of these filters. ${logicalDescription}`);
|
|
206
124
|
}
|
|
207
125
|
return zod_1.z.object(shape);
|
|
208
126
|
}
|
|
@@ -215,90 +133,86 @@ var generateInputSchema = function (model, method, config, queryFields, populate
|
|
|
215
133
|
}
|
|
216
134
|
};
|
|
217
135
|
exports.generateInputSchema = generateInputSchema;
|
|
218
|
-
|
|
219
|
-
var _a, _b;
|
|
136
|
+
const describeFieldKind = (field) => {
|
|
220
137
|
if (field.isArray) {
|
|
221
|
-
if (
|
|
222
|
-
|
|
138
|
+
if (field.item?.kind) {
|
|
139
|
+
const itemLabel = field.item.kind === "objectId"
|
|
223
140
|
? field.item.ref
|
|
224
|
-
?
|
|
141
|
+
? `ref:${field.item.ref}`
|
|
225
142
|
: "ObjectId"
|
|
226
143
|
: field.item.kind.charAt(0).toUpperCase() + field.item.kind.slice(1);
|
|
227
|
-
return
|
|
144
|
+
return `(${itemLabel}[])`;
|
|
228
145
|
}
|
|
229
146
|
return "(Array)";
|
|
230
147
|
}
|
|
231
148
|
if (field.kind === "objectId") {
|
|
232
|
-
return field.ref ?
|
|
149
|
+
return field.ref ? `(ref: ${field.ref})` : "(ObjectId)";
|
|
233
150
|
}
|
|
234
|
-
if (field.kind === "string" &&
|
|
235
|
-
return
|
|
151
|
+
if (field.kind === "string" && field.enum?.length) {
|
|
152
|
+
return `(enum: ${field.enum.join("|")})`;
|
|
236
153
|
}
|
|
237
|
-
|
|
238
|
-
return
|
|
154
|
+
const label = field.kind.charAt(0).toUpperCase() + field.kind.slice(1);
|
|
155
|
+
return `(${label})`;
|
|
239
156
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
var parts = [path, describeFieldKind(field)];
|
|
157
|
+
const describeField = ({ field, path, required }) => {
|
|
158
|
+
const parts = [path, describeFieldKind(field)];
|
|
243
159
|
if (required) {
|
|
244
160
|
parts.push("required");
|
|
245
161
|
}
|
|
246
162
|
return parts.join(" ");
|
|
247
163
|
};
|
|
248
|
-
|
|
249
|
-
var _a;
|
|
250
|
-
if (restExcludeFields === void 0) { restExcludeFields = []; }
|
|
164
|
+
const generateToolDescription = (model, method, config, queryFields, populatePaths, restExcludeFields = []) => {
|
|
251
165
|
if (config.description) {
|
|
252
|
-
|
|
253
|
-
return
|
|
166
|
+
const methodPrefix = `${method.charAt(0).toUpperCase()}${method.slice(1)}`;
|
|
167
|
+
return `${methodPrefix}: ${config.description}`;
|
|
254
168
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
169
|
+
const modelName = model.modelName;
|
|
170
|
+
const excludeFields = (0, exports.writeExcludeFields)(config, restExcludeFields);
|
|
171
|
+
const maxLimit = config.maxLimit ?? 50;
|
|
258
172
|
switch (method) {
|
|
259
173
|
case "list": {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (availableQueryFields
|
|
263
|
-
parts.push(
|
|
264
|
-
parts.push(
|
|
174
|
+
const parts = [`List ${modelName} items.`];
|
|
175
|
+
const availableQueryFields = queryFields?.filter((f) => !(0, exports.isFieldExcluded)(f, excludeFields));
|
|
176
|
+
if (availableQueryFields?.length) {
|
|
177
|
+
parts.push(`Filterable by: ${availableQueryFields.join(", ")}.`);
|
|
178
|
+
parts.push(`Filters accept an exact value or an operator object (${DOCUMENTED_FIELD_OPERATORS}), and can be combined with $and/$or.`);
|
|
265
179
|
}
|
|
266
|
-
parts.push(
|
|
180
|
+
parts.push(`Sortable. Paginated (max ${maxLimit}).`);
|
|
267
181
|
return parts.join(" ");
|
|
268
182
|
}
|
|
269
183
|
case "read": {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
.map(
|
|
274
|
-
.filter(
|
|
184
|
+
const parts = [`Read a single ${modelName} by ID.`];
|
|
185
|
+
const fields = getModelFields(model, excludeFields);
|
|
186
|
+
const refFields = (populatePaths ?? [])
|
|
187
|
+
.map((populatePath) => fields.find((field) => field.path === populatePath.path))
|
|
188
|
+
.filter((field) => Boolean(field?.field.ref));
|
|
275
189
|
if (refFields.length) {
|
|
276
|
-
parts.push(
|
|
190
|
+
parts.push(`Populate-able refs: ${refFields.map((f) => `${f.path} (${f.field.ref})`).join(", ")}.`);
|
|
277
191
|
}
|
|
278
192
|
return parts.join(" ");
|
|
279
193
|
}
|
|
280
194
|
case "create": {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
195
|
+
const fields = getModelFields(model, excludeFields);
|
|
196
|
+
const parts = [`Create a new ${modelName}.`];
|
|
197
|
+
const fieldDescs = fields.map(describeField);
|
|
284
198
|
if (fieldDescs.length) {
|
|
285
|
-
parts.push(
|
|
199
|
+
parts.push(`Fields: ${fieldDescs.join(", ")}.`);
|
|
286
200
|
}
|
|
287
201
|
return parts.join(" ");
|
|
288
202
|
}
|
|
289
203
|
case "update": {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
204
|
+
const fields = getModelFields(model, excludeFields);
|
|
205
|
+
const parts = [`Update an existing ${modelName} by ID. Send only the fields to change.`];
|
|
206
|
+
const fieldNames = fields.map((f) => f.path);
|
|
293
207
|
if (fieldNames.length) {
|
|
294
|
-
parts.push(
|
|
208
|
+
parts.push(`Updatable fields: ${fieldNames.join(", ")}.`);
|
|
295
209
|
}
|
|
296
210
|
return parts.join(" ");
|
|
297
211
|
}
|
|
298
212
|
case "delete":
|
|
299
|
-
return
|
|
213
|
+
return `Delete a ${modelName} by ID.`;
|
|
300
214
|
default:
|
|
301
|
-
return
|
|
215
|
+
return `${method} on ${modelName}`;
|
|
302
216
|
}
|
|
303
217
|
};
|
|
304
218
|
exports.generateToolDescription = generateToolDescription;
|
package/dist/mcp/server.js
CHANGED
|
@@ -1,106 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
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);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __values = (this && this.__values) || function(o) {
|
|
39
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
-
if (m) return m.call(o);
|
|
41
|
-
if (o && typeof o.length === "number") return {
|
|
42
|
-
next: function () {
|
|
43
|
-
if (o && i >= o.length) o = void 0;
|
|
44
|
-
return { value: o && o[i++], done: !o };
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
-
};
|
|
49
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
3
|
exports.mountMCPServer = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
4
|
+
const node_1 = require("@modelcontextprotocol/node");
|
|
5
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
const requestContext_1 = require("../requestContext");
|
|
8
|
+
const auth_1 = require("./auth");
|
|
9
|
+
const toolGenerator_1 = require("./toolGenerator");
|
|
10
|
+
const mountMCPServer = (app, options) => {
|
|
11
|
+
const tools = (0, toolGenerator_1.getAllMCPTools)();
|
|
59
12
|
if (tools.length === 0) {
|
|
60
13
|
return;
|
|
61
14
|
}
|
|
62
|
-
|
|
15
|
+
const authContext = {
|
|
63
16
|
betterAuth: options.betterAuth,
|
|
64
17
|
mcpServiceTokens: options.mcpServiceTokens,
|
|
65
18
|
userModel: options.userModel,
|
|
66
19
|
};
|
|
67
|
-
logger_1.logger.info(
|
|
20
|
+
logger_1.logger.info(`Mounting MCP server with ${tools.length} tools at /mcp`);
|
|
68
21
|
// The 2026-07-28 handler is stateless: it creates one server per request and also serves
|
|
69
22
|
// 2025-era clients through the SDK's stateless legacy fallback.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
switch (_c.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
headers = {};
|
|
77
|
-
requestInfo === null || requestInfo === void 0 ? void 0 : requestInfo.headers.forEach(function (value, key) {
|
|
78
|
-
headers[key] = value;
|
|
79
|
-
});
|
|
80
|
-
return [4 /*yield*/, (0, auth_1.extractUserFromHeaders)(headers, authContext)];
|
|
81
|
-
case 1:
|
|
82
|
-
user = _c.sent();
|
|
83
|
-
if (user === null || user === void 0 ? void 0 : user.id) {
|
|
84
|
-
(0, requestContext_1.setRequestContext)({ userId: user.id });
|
|
85
|
-
}
|
|
86
|
-
return [2 /*return*/, createMcpServerInstance(tools, user)];
|
|
87
|
-
}
|
|
23
|
+
const handler = (0, server_1.createMcpHandler)(async ({ requestInfo }) => {
|
|
24
|
+
const headers = {};
|
|
25
|
+
requestInfo?.headers.forEach((value, key) => {
|
|
26
|
+
headers[key] = value;
|
|
88
27
|
});
|
|
89
|
-
|
|
28
|
+
const user = await (0, auth_1.extractUserFromHeaders)(headers, authContext);
|
|
29
|
+
if (user?.id) {
|
|
30
|
+
(0, requestContext_1.setRequestContext)({ userId: user.id });
|
|
31
|
+
}
|
|
32
|
+
return createMcpServerInstance(tools, user);
|
|
33
|
+
}, {
|
|
90
34
|
legacy: "stateless",
|
|
91
|
-
onerror:
|
|
35
|
+
onerror: (error) => logger_1.logger.catch(error),
|
|
92
36
|
responseMode: "auto",
|
|
93
37
|
});
|
|
94
|
-
|
|
95
|
-
app.all("/mcp",
|
|
38
|
+
const nodeHandler = (0, node_1.toNodeHandler)(handler);
|
|
39
|
+
app.all("/mcp", (req, res) => {
|
|
96
40
|
// express.json() consumed the request stream, so pass its parsed body explicitly.
|
|
97
41
|
void nodeHandler(req, res, req.body);
|
|
98
42
|
});
|
|
99
43
|
};
|
|
100
44
|
exports.mountMCPServer = mountMCPServer;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
var server = new server_1.McpServer({
|
|
45
|
+
const createMcpServerInstance = (tools, user) => {
|
|
46
|
+
const server = new server_1.McpServer({
|
|
104
47
|
name: "terreno-api-mcp",
|
|
105
48
|
version: "1.0.0",
|
|
106
49
|
}, {
|
|
@@ -108,27 +51,12 @@ var createMcpServerInstance = function (tools, user) {
|
|
|
108
51
|
tools: {},
|
|
109
52
|
},
|
|
110
53
|
});
|
|
111
|
-
|
|
54
|
+
// Register each tool with the MCP server
|
|
55
|
+
for (const tool of tools) {
|
|
112
56
|
server.registerTool(tool.name, {
|
|
113
57
|
description: tool.description,
|
|
114
58
|
inputSchema: tool.zodSchema,
|
|
115
|
-
},
|
|
116
|
-
return [2 /*return*/, tool.handler(args, user)];
|
|
117
|
-
}); }); });
|
|
118
|
-
};
|
|
119
|
-
try {
|
|
120
|
-
// Register each tool with the MCP server
|
|
121
|
-
for (var tools_1 = __values(tools), tools_1_1 = tools_1.next(); !tools_1_1.done; tools_1_1 = tools_1.next()) {
|
|
122
|
-
var tool = tools_1_1.value;
|
|
123
|
-
_loop_1(tool);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
127
|
-
finally {
|
|
128
|
-
try {
|
|
129
|
-
if (tools_1_1 && !tools_1_1.done && (_a = tools_1.return)) _a.call(tools_1);
|
|
130
|
-
}
|
|
131
|
-
finally { if (e_1) throw e_1.error; }
|
|
59
|
+
}, async (args) => tool.handler(args, user));
|
|
132
60
|
}
|
|
133
61
|
return server;
|
|
134
62
|
};
|