@terreno/api 57.4.0 → 57.6.1

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