@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.
Files changed (208) 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 +598 -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/audit/auditApp.test.ts +5 -5
  173. package/src/audit/auditEventModel.ts +7 -3
  174. package/src/audit/auditRouter.test.ts +5 -5
  175. package/src/audit/rbacSink.test.ts +2 -2
  176. package/src/audit/record.test.ts +2 -2
  177. package/src/audit/record.ts +3 -2
  178. package/src/auth.ts +1 -1
  179. package/src/authRecovery.test.ts +43 -0
  180. package/src/authRecovery.ts +16 -10
  181. package/src/authTokens.ts +6 -2
  182. package/src/authVerification.test.ts +22 -0
  183. package/src/browserLogsRoute.ts +110 -0
  184. package/src/configurationPlugin.test.ts +1 -11
  185. package/src/expressServer.ts +10 -0
  186. package/src/frameworkModelNames.test.ts +62 -0
  187. package/src/frameworkModelNames.ts +33 -0
  188. package/src/index.ts +7 -0
  189. package/src/isolated/migrateCliConnect.isolated.ts +51 -0
  190. package/src/mcp/auth.test.ts +34 -1
  191. package/src/migrations/cli.test.ts +0 -23
  192. package/src/models/mcpServiceToken.ts +4 -3
  193. package/src/models/notification.ts +3 -2
  194. package/src/models/notificationPreference.ts +1 -1
  195. package/src/notifications/notificationsApp.test.ts +24 -1
  196. package/src/notifiers/slackNotifier.test.ts +186 -1
  197. package/src/notifiers/slackNotifier.ts +167 -8
  198. package/src/orgs/orgPlugin.ts +1 -1
  199. package/src/orgs/organizationModel.ts +11 -6
  200. package/src/plugins.test.ts +5 -0
  201. package/src/plugins.ts +3 -0
  202. package/src/realtime/realtimeApp.ts +1 -1
  203. package/src/sync/integration.test.ts +2 -2
  204. package/src/terrenoApp.ts +3 -0
  205. package/src/types.d.ts +1 -0
  206. package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
  207. package/tsconfig.json +13 -54
  208. package/tsconfig.typedoc.json +2 -0
@@ -1,115 +1,30 @@
1
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 __rest = (this && this.__rest) || function (s, e) {
50
- var t = {};
51
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
- t[p] = s[p];
53
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
- t[p[i]] = s[p[i]];
57
- }
58
- return t;
59
- };
60
- var __values = (this && this.__values) || function(o) {
61
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
62
- if (m) return m.call(o);
63
- if (o && typeof o.length === "number") return {
64
- next: function () {
65
- if (o && i >= o.length) o = void 0;
66
- return { value: o && o[i++], done: !o };
67
- }
68
- };
69
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
70
- };
71
- var __read = (this && this.__read) || function (o, n) {
72
- var m = typeof Symbol === "function" && o[Symbol.iterator];
73
- if (!m) return o;
74
- var i = m.call(o), r, ar = [], e;
75
- try {
76
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
77
- }
78
- catch (error) { e = { error: error }; }
79
- finally {
80
- try {
81
- if (r && !r.done && (m = i["return"])) m.call(i);
82
- }
83
- finally { if (e) throw e.error; }
84
- }
85
- return ar;
86
- };
87
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
88
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
89
4
  };
90
5
  Object.defineProperty(exports, "__esModule", { value: true });
91
6
  exports.handleDelete = exports.handleUpdate = exports.handleCreate = exports.handleRead = exports.handleList = exports.getMCPErrorCause = void 0;
92
- var mongoose_1 = __importDefault(require("mongoose"));
93
- var api_1 = require("../api");
94
- var errors_1 = require("../errors");
95
- var permissions_1 = require("../permissions");
96
- var executors_1 = require("../sync/executors");
97
- var transformers_1 = require("../transformers");
98
- var createMCPRequest_1 = require("./createMCPRequest");
99
- var query_1 = require("./query");
100
- var schemaGenerator_1 = require("./schemaGenerator");
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const api_1 = require("../api");
9
+ const errors_1 = require("../errors");
10
+ const permissions_1 = require("../permissions");
11
+ const executors_1 = require("../sync/executors");
12
+ const transformers_1 = require("../transformers");
13
+ const createMCPRequest_1 = require("./createMCPRequest");
14
+ const query_1 = require("./query");
15
+ const schemaGenerator_1 = require("./schemaGenerator");
101
16
  // Causes stay server-side: a WeakMap lets the observability wrapper capture the
102
17
  // original exception without adding stack traces or internal details to the MCP result.
103
- var errorCauses = new WeakMap();
104
- var getMCPErrorCause = function (result) {
18
+ const errorCauses = new WeakMap();
19
+ const getMCPErrorCause = (result) => {
105
20
  return errorCauses.get(result);
106
21
  };
107
22
  exports.getMCPErrorCause = getMCPErrorCause;
108
- var isPlainObject = function (value) {
23
+ const isPlainObject = (value) => {
109
24
  return typeof value === "object" && value !== null && !Array.isArray(value);
110
25
  };
111
26
  /** Mongoose documents only expose their fields through toObject(). */
112
- var toPlain = function (value) {
27
+ const toPlain = (value) => {
113
28
  if (isPlainObject(value) && typeof value.toObject === "function") {
114
29
  return value.toObject();
115
30
  }
@@ -120,35 +35,24 @@ var toPlain = function (value) {
120
35
  * through untouched. Rebuilding them entry by entry would replace an ObjectId with its
121
36
  * raw `{buffer: ...}` internals and a Date with `{}`.
122
37
  */
123
- var isSelfSerializing = function (value) {
38
+ const isSelfSerializing = (value) => {
124
39
  return typeof value.toJSON === "function";
125
40
  };
126
41
  /**
127
42
  * Delete a dot-notation path, descending into arrays element-wise so paths through
128
43
  * arrays of subdocuments (e.g. "items.secret") are removed from every element.
129
44
  */
130
- var deleteAtPath = function (obj, segments) {
131
- var e_1, _a;
45
+ const deleteAtPath = (obj, segments) => {
132
46
  if (Array.isArray(obj)) {
133
- try {
134
- for (var obj_1 = __values(obj), obj_1_1 = obj_1.next(); !obj_1_1.done; obj_1_1 = obj_1.next()) {
135
- var item = obj_1_1.value;
136
- deleteAtPath(item, segments);
137
- }
138
- }
139
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
140
- finally {
141
- try {
142
- if (obj_1_1 && !obj_1_1.done && (_a = obj_1.return)) _a.call(obj_1);
143
- }
144
- finally { if (e_1) throw e_1.error; }
47
+ for (const item of obj) {
48
+ deleteAtPath(item, segments);
145
49
  }
146
50
  return;
147
51
  }
148
52
  if (!isPlainObject(obj) || segments.length === 0) {
149
53
  return;
150
54
  }
151
- var _b = __read(segments), head = _b[0], rest = _b.slice(1);
55
+ const [head, ...rest] = segments;
152
56
  if (rest.length === 0) {
153
57
  delete obj[head];
154
58
  return;
@@ -163,58 +67,36 @@ var deleteAtPath = function (obj, segments) {
163
67
  * path when only one specific location should be removed. Literal object keys that
164
68
  * equal a denylist entry (including dotted names) are also dropped.
165
69
  */
166
- var stripExcludedFields = function (data, excludeFields) {
167
- var e_2, _a;
70
+ const stripExcludedFields = (data, excludeFields) => {
168
71
  if (!excludeFields.length || !data) {
169
72
  return data;
170
73
  }
171
- var bareKeys = new Set(excludeFields.filter(function (field) { return !field.includes("."); }));
172
- var dotPaths = excludeFields
173
- .filter(function (field) { return field.includes("."); })
174
- .map(function (field) { return field.split("."); });
175
- var strip = function (value) {
176
- var e_3, _a;
177
- var plain = toPlain(value);
74
+ const bareKeys = new Set(excludeFields.filter((field) => !field.includes(".")));
75
+ const dotPaths = excludeFields
76
+ .filter((field) => field.includes("."))
77
+ .map((field) => field.split("."));
78
+ const strip = (value) => {
79
+ const plain = toPlain(value);
178
80
  if (Array.isArray(plain)) {
179
81
  return plain.map(strip);
180
82
  }
181
83
  if (!isPlainObject(plain) || isSelfSerializing(plain)) {
182
84
  return plain;
183
85
  }
184
- var result = {};
185
- try {
186
- for (var _b = __values(Object.entries(plain)), _c = _b.next(); !_c.done; _c = _b.next()) {
187
- var _d = __read(_c.value, 2), key = _d[0], nested = _d[1];
188
- // Exact key match covers both bare names and literal dotted keys
189
- // ("metadata.nested.token") that Mongoose would otherwise treat as a path.
190
- if (bareKeys.has(key) || excludeFields.includes(key)) {
191
- continue;
192
- }
193
- result[key] = strip(nested);
86
+ const result = {};
87
+ for (const [key, nested] of Object.entries(plain)) {
88
+ // Exact key match covers both bare names and literal dotted keys
89
+ // ("metadata.nested.token") that Mongoose would otherwise treat as a path.
90
+ if (bareKeys.has(key) || excludeFields.includes(key)) {
91
+ continue;
194
92
  }
195
- }
196
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
197
- finally {
198
- try {
199
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
200
- }
201
- finally { if (e_3) throw e_3.error; }
93
+ result[key] = strip(nested);
202
94
  }
203
95
  return result;
204
96
  };
205
- var stripped = strip(data);
206
- try {
207
- for (var dotPaths_1 = __values(dotPaths), dotPaths_1_1 = dotPaths_1.next(); !dotPaths_1_1.done; dotPaths_1_1 = dotPaths_1.next()) {
208
- var segments = dotPaths_1_1.value;
209
- deleteAtPath(stripped, segments);
210
- }
211
- }
212
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
213
- finally {
214
- try {
215
- if (dotPaths_1_1 && !dotPaths_1_1.done && (_a = dotPaths_1.return)) _a.call(dotPaths_1);
216
- }
217
- finally { if (e_2) throw e_2.error; }
97
+ const stripped = strip(data);
98
+ for (const segments of dotPaths) {
99
+ deleteAtPath(stripped, segments);
218
100
  }
219
101
  return stripped;
220
102
  };
@@ -227,52 +109,36 @@ var stripExcludedFields = function (data, excludeFields) {
227
109
  * whole referenced documents, so a requested path must match a declared one. Requesting
228
110
  * paths only narrows the set; anything undeclared is an error rather than a silent widen.
229
111
  */
230
- var resolvePopulatePaths = function (populateStr, declaredPaths) {
231
- var e_4, _a;
232
- var declared = declaredPaths !== null && declaredPaths !== void 0 ? declaredPaths : [];
112
+ const resolvePopulatePaths = (populateStr, declaredPaths) => {
113
+ const declared = declaredPaths ?? [];
233
114
  if (!populateStr) {
234
115
  return { paths: declared };
235
116
  }
236
- var requested = populateStr
117
+ const requested = populateStr
237
118
  .split(",")
238
- .map(function (path) { return path.trim(); })
119
+ .map((path) => path.trim())
239
120
  .filter(Boolean);
240
121
  if (!requested.length) {
241
122
  return { paths: declared };
242
123
  }
243
- var paths = [];
244
- var _loop_1 = function (path) {
245
- var match = declared.find(function (declaredPath) { return declaredPath.path === path; });
124
+ const paths = [];
125
+ for (const path of requested) {
126
+ const match = declared.find((declaredPath) => declaredPath.path === path);
246
127
  if (!match) {
247
- var allowed = declared.map(function (declaredPath) { return declaredPath.path; }).join(", ");
248
- return { value: {
249
- error: allowed
250
- ? "".concat(path, " is not a populate-able path. Allowed: ").concat(allowed)
251
- : "".concat(path, " is not a populate-able path. This model has no populate-able paths"),
252
- } };
128
+ const allowed = declared.map((declaredPath) => declaredPath.path).join(", ");
129
+ return {
130
+ error: allowed
131
+ ? `${path} is not a populate-able path. Allowed: ${allowed}`
132
+ : `${path} is not a populate-able path. This model has no populate-able paths`,
133
+ };
253
134
  }
254
135
  if (!paths.includes(match)) {
255
136
  paths.push(match);
256
137
  }
257
- };
258
- try {
259
- for (var requested_1 = __values(requested), requested_1_1 = requested_1.next(); !requested_1_1.done; requested_1_1 = requested_1.next()) {
260
- var path = requested_1_1.value;
261
- var state_1 = _loop_1(path);
262
- if (typeof state_1 === "object")
263
- return state_1.value;
264
- }
265
- }
266
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
267
- finally {
268
- try {
269
- if (requested_1_1 && !requested_1_1.done && (_a = requested_1.return)) _a.call(requested_1);
270
- }
271
- finally { if (e_4) throw e_4.error; }
272
138
  }
273
- return { paths: paths };
139
+ return { paths };
274
140
  };
275
- var asOptionalString = function (value) {
141
+ const asOptionalString = (value) => {
276
142
  return typeof value === "string" ? value : undefined;
277
143
  };
278
144
  /**
@@ -282,42 +148,34 @@ var asOptionalString = function (value) {
282
148
  * Mixed/embedded objects and arrays), and a dotted path is deleted at that
283
149
  * location only. The incoming args object is not mutated.
284
150
  */
285
- var omitDeniedWriteFields = function (body, denied) {
151
+ const omitDeniedWriteFields = (body, denied) => {
286
152
  if (denied.length === 0) {
287
153
  return body;
288
154
  }
289
155
  return stripExcludedFields(body, denied);
290
156
  };
291
157
  /** Mongoose's populated query result types don't narrow to a single document. */
292
- var asDocument = function (result) {
293
- return (result !== null && result !== void 0 ? result : null);
158
+ const asDocument = (result) => {
159
+ return (result ?? null);
294
160
  };
295
161
  /**
296
162
  * Run a findById query and map Mongoose CastError (malformed ids) to null so
297
163
  * callers can return a structured not-found. 24-hex ids with mixed case are
298
164
  * valid for findById even though `isValidObjectId` requires canonical lowercase.
299
165
  */
300
- var execFindByIdQuery = function (query) { return __awaiter(void 0, void 0, void 0, function () {
301
- var _a, error_1;
302
- return __generator(this, function (_b) {
303
- switch (_b.label) {
304
- case 0:
305
- _b.trys.push([0, 2, , 3]);
306
- _a = asDocument;
307
- return [4 /*yield*/, query.exec()];
308
- case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
309
- case 2:
310
- error_1 = _b.sent();
311
- if (error_1 instanceof mongoose_1.default.Error.CastError) {
312
- return [2 /*return*/, null];
313
- }
314
- throw error_1;
315
- case 3: return [2 /*return*/];
166
+ const execFindByIdQuery = async (query) => {
167
+ try {
168
+ return asDocument(await query.exec());
169
+ }
170
+ catch (error) {
171
+ if (error instanceof mongoose_1.default.Error.CastError) {
172
+ return null;
316
173
  }
317
- });
318
- }); };
319
- var missingDocumentResult = function (id) {
320
- return errorResult("Document ".concat(id, " not found"));
174
+ throw error;
175
+ }
176
+ };
177
+ const missingDocumentResult = (id) => {
178
+ return errorResult(`Document ${id} not found`);
321
179
  };
322
180
  /**
323
181
  * Mirror REST's `authenticateMiddleware(options.allowAnonymous)`, which answers 401 before
@@ -325,298 +183,228 @@ var missingDocumentResult = function (id) {
325
183
  * `IsAuthenticatedOrReadOnly` would let an anonymous MCP client list or read data that the
326
184
  * same router refuses over HTTP.
327
185
  */
328
- var requiresAuthentication = function (entry, user) {
186
+ const requiresAuthentication = (entry, user) => {
329
187
  return !user && entry.options.allowAnonymous !== true;
330
188
  };
331
189
  /** Map executor/APIError failures onto the MCP error envelope. */
332
- var fromExecutorError = function (error) {
190
+ const fromExecutorError = (error) => {
333
191
  if ((0, errors_1.isAPIError)(error)) {
334
192
  return errorResult(error.title, error);
335
193
  }
336
194
  return errorResult(errorMessage(error), error);
337
195
  };
338
- var deniedWriteFields = function (entry, phase) {
196
+ const deniedWriteFields = (entry, phase) => {
339
197
  return (0, schemaGenerator_1.writeExcludeFields)(entry.config, (0, schemaGenerator_1.restWriteExcludeFields)(phase, entry.options.validation));
340
198
  };
341
- var serializeResponse = function (data, method, entry, user) { return __awaiter(void 0, void 0, void 0, function () {
342
- var excludeFields, result_1, responseHandler, result, error_2;
343
- var _a, _b;
344
- return __generator(this, function (_c) {
345
- switch (_c.label) {
346
- case 0:
347
- _c.trys.push([0, 4, , 5]);
348
- excludeFields = (_a = entry.config.excludeFields) !== null && _a !== void 0 ? _a : [];
349
- if (!entry.config.mcpResponseHandler) return [3 /*break*/, 2];
350
- return [4 /*yield*/, entry.config.mcpResponseHandler(data, method, user)];
351
- case 1:
352
- result_1 = _c.sent();
353
- return [2 /*return*/, { value: stripExcludedFields(result_1, excludeFields) }];
354
- case 2:
355
- responseHandler = (_b = entry.options.responseHandler) !== null && _b !== void 0 ? _b : transformers_1.defaultResponseHandler;
356
- return [4 /*yield*/, responseHandler(data, method, (0, createMCPRequest_1.createMCPRequest)({ user: user }), entry.options)];
357
- case 3:
358
- result = _c.sent();
359
- return [2 /*return*/, { value: stripExcludedFields(result, excludeFields) }];
360
- case 4:
361
- error_2 = _c.sent();
362
- if ((0, errors_1.isAPIError)(error_2)) {
363
- return [2 /*return*/, { error: errorResult(error_2.title, error_2) }];
364
- }
365
- return [2 /*return*/, { error: errorResult("Response handler failed: ".concat(errorMessage(error_2)), error_2) }];
366
- case 5: return [2 /*return*/];
199
+ const serializeResponse = async (data, method, entry, user) => {
200
+ try {
201
+ const excludeFields = entry.config.excludeFields ?? [];
202
+ if (entry.config.mcpResponseHandler) {
203
+ const result = await entry.config.mcpResponseHandler(data, method, user);
204
+ return { value: stripExcludedFields(result, excludeFields) };
367
205
  }
368
- });
369
- }); };
370
- var handleList = function (entry, args, user) { return __awaiter(void 0, void 0, void 0, function () {
371
- var model, config, options, maxLimit, _a, queryError, builtFilter, query, filtered, error_3, limit, page, builtQuery, total, sort, _b, populateError, populatePaths, populatedQuery, data, more, sliced, serialized;
372
- var _c, _d;
373
- return __generator(this, function (_e) {
374
- switch (_e.label) {
375
- case 0:
376
- model = entry.model, config = entry.config, options = entry.options;
377
- maxLimit = (_c = config.maxLimit) !== null && _c !== void 0 ? _c : 50;
378
- if (requiresAuthentication(entry, user)) {
379
- return [2 /*return*/, errorResult("Permission denied: authentication required")];
380
- }
381
- return [4 /*yield*/, (0, permissions_1.checkPermissions)("list", options.permissions.list, user)];
382
- case 1:
383
- // Check permissions
384
- if (!(_e.sent())) {
385
- return [2 /*return*/, errorResult("Permission denied: cannot list")];
386
- }
387
- _a = (0, query_1.buildListQuery)({ args: args, config: config, options: options }), queryError = _a.error, builtFilter = _a.query;
388
- if (queryError || !builtFilter) {
389
- return [2 /*return*/, errorResult(queryError !== null && queryError !== void 0 ? queryError : "Could not build query")];
390
- }
391
- query = builtFilter;
392
- if (!options.queryFilter) return [3 /*break*/, 5];
393
- _e.label = 2;
394
- case 2:
395
- _e.trys.push([2, 4, , 5]);
396
- return [4 /*yield*/, options.queryFilter(user, query)];
397
- case 3:
398
- filtered = _e.sent();
399
- if (filtered === null) {
400
- return [2 /*return*/, textResult(JSON.stringify({ data: [], more: false, page: 1, total: 0 }))];
401
- }
402
- query = __assign(__assign({}, query), filtered);
403
- return [3 /*break*/, 5];
404
- case 4:
405
- error_3 = _e.sent();
406
- if ((0, errors_1.isAPIError)(error_3)) {
407
- return [2 /*return*/, errorResult(error_3.title, error_3)];
408
- }
409
- return [2 /*return*/, errorResult("queryFilter failed: ".concat(errorMessage(error_3)), error_3)];
410
- case 5:
411
- limit = Math.max(1, Math.min(Number(args.limit) || maxLimit, maxLimit));
412
- page = Math.max(1, Number(args.page) || 1);
413
- builtQuery = model.find(query).limit(limit + 1);
414
- return [4 /*yield*/, model.countDocuments(query)];
415
- case 6:
416
- total = _e.sent();
417
- if (page > 1) {
418
- builtQuery = builtQuery.skip((page - 1) * limit);
419
- }
420
- sort = (_d = asOptionalString(args.sort)) !== null && _d !== void 0 ? _d : options.sort;
421
- if (sort) {
422
- builtQuery = builtQuery.sort(sort);
423
- }
424
- _b = resolvePopulatePaths(asOptionalString(args.populate), options.populatePaths), populateError = _b.error, populatePaths = _b.paths;
425
- if (populateError || !populatePaths) {
426
- return [2 /*return*/, errorResult(populateError !== null && populateError !== void 0 ? populateError : "Could not resolve populate paths")];
427
- }
428
- populatedQuery = (0, api_1.addPopulateToQuery)(builtQuery, populatePaths);
429
- return [4 /*yield*/, populatedQuery.exec()];
430
- case 7:
431
- data = _e.sent();
432
- more = data.length > limit;
433
- sliced = more ? data.slice(0, limit) : data;
434
- return [4 /*yield*/, serializeResponse(sliced, "list", entry, user)];
435
- case 8:
436
- serialized = _e.sent();
437
- if ("error" in serialized) {
438
- return [2 /*return*/, serialized.error];
439
- }
440
- return [2 /*return*/, textResult(JSON.stringify({ data: serialized.value, more: more, page: page, total: total }))];
206
+ // Use the model router's responseHandler if available, otherwise default
207
+ const responseHandler = entry.options.responseHandler ?? transformers_1.defaultResponseHandler;
208
+ const result = await responseHandler(data, method, (0, createMCPRequest_1.createMCPRequest)({ user }), entry.options);
209
+ return { value: stripExcludedFields(result, excludeFields) };
210
+ }
211
+ catch (error) {
212
+ if ((0, errors_1.isAPIError)(error)) {
213
+ return { error: errorResult(error.title, error) };
441
214
  }
442
- });
443
- }); };
444
- exports.handleList = handleList;
445
- var handleRead = function (entry, args, user) { return __awaiter(void 0, void 0, void 0, function () {
446
- var model, options, _a, populateError, populatePaths, id, data, serialized;
447
- return __generator(this, function (_b) {
448
- switch (_b.label) {
449
- case 0:
450
- model = entry.model, options = entry.options;
451
- if (requiresAuthentication(entry, user)) {
452
- return [2 /*return*/, errorResult("Permission denied: authentication required")];
453
- }
454
- return [4 /*yield*/, (0, permissions_1.checkPermissions)("read", options.permissions.read, user)];
455
- case 1:
456
- // Check method-level permission
457
- if (!(_b.sent())) {
458
- return [2 /*return*/, errorResult("Permission denied: cannot read")];
459
- }
460
- _a = resolvePopulatePaths(asOptionalString(args.populate), options.populatePaths), populateError = _a.error, populatePaths = _a.paths;
461
- if (populateError || !populatePaths) {
462
- return [2 /*return*/, errorResult(populateError !== null && populateError !== void 0 ? populateError : "Could not resolve populate paths")];
463
- }
464
- id = asOptionalString(args.id);
465
- if (!id) {
466
- return [2 /*return*/, missingDocumentResult(args.id)];
467
- }
468
- return [4 /*yield*/, execFindByIdQuery((0, api_1.addPopulateToQuery)(model.findById(id), populatePaths))];
469
- case 2:
470
- data = _b.sent();
471
- if (!data) {
472
- return [2 /*return*/, missingDocumentResult(id)];
473
- }
474
- return [4 /*yield*/, (0, permissions_1.checkPermissions)("read", options.permissions.read, user, data)];
475
- case 3:
476
- // Check object-level permission
477
- if (!(_b.sent())) {
478
- return [2 /*return*/, errorResult("Permission denied: cannot read this document")];
479
- }
480
- return [4 /*yield*/, serializeResponse(data, "read", entry, user)];
481
- case 4:
482
- serialized = _b.sent();
483
- if ("error" in serialized) {
484
- return [2 /*return*/, serialized.error];
485
- }
486
- return [2 /*return*/, textResult(JSON.stringify({ data: serialized.value }))];
215
+ return { error: errorResult(`Response handler failed: ${errorMessage(error)}`, error) };
216
+ }
217
+ };
218
+ const handleList = async (entry, args, user) => {
219
+ const { model, config, options } = entry;
220
+ const maxLimit = config.maxLimit ?? 50;
221
+ if (requiresAuthentication(entry, user)) {
222
+ return errorResult("Permission denied: authentication required");
223
+ }
224
+ // Check permissions
225
+ if (!(await (0, permissions_1.checkPermissions)("list", options.permissions.list, user))) {
226
+ return errorResult("Permission denied: cannot list");
227
+ }
228
+ // Build query from args — only fields in queryFields, with an allowlist of operators
229
+ const { error: queryError, query: builtFilter } = (0, query_1.buildListQuery)({ args, config, options });
230
+ if (queryError || !builtFilter) {
231
+ return errorResult(queryError ?? "Could not build query");
232
+ }
233
+ let query = builtFilter;
234
+ // Apply query filter
235
+ if (options.queryFilter) {
236
+ try {
237
+ const filtered = await options.queryFilter(user, query);
238
+ if (filtered === null) {
239
+ return textResult(JSON.stringify({ data: [], more: false, page: 1, total: 0 }));
240
+ }
241
+ query = { ...query, ...filtered };
487
242
  }
488
- });
489
- }); };
490
- exports.handleRead = handleRead;
491
- var handleCreate = function (entry, args, user) { return __awaiter(void 0, void 0, void 0, function () {
492
- var model, options, body, req, data, result, error_4, serialized;
493
- return __generator(this, function (_a) {
494
- switch (_a.label) {
495
- case 0:
496
- model = entry.model, options = entry.options;
497
- if (requiresAuthentication(entry, user)) {
498
- return [2 /*return*/, errorResult("Permission denied: authentication required")];
499
- }
500
- body = omitDeniedWriteFields(args, deniedWriteFields(entry, "create"));
501
- req = (0, createMCPRequest_1.createMCPRequest)({ body: body, user: user });
502
- _a.label = 1;
503
- case 1:
504
- _a.trys.push([1, 3, , 4]);
505
- return [4 /*yield*/, (0, executors_1.executeCreate)({
506
- body: body,
507
- model: model,
508
- options: options,
509
- req: req,
510
- user: user,
511
- writeModelName: entry.modelName,
512
- })];
513
- case 2:
514
- result = _a.sent();
515
- data = result.doc;
516
- return [3 /*break*/, 4];
517
- case 3:
518
- error_4 = _a.sent();
519
- return [2 /*return*/, fromExecutorError(error_4)];
520
- case 4: return [4 /*yield*/, serializeResponse(data, "create", entry, user)];
521
- case 5:
522
- serialized = _a.sent();
523
- if ("error" in serialized) {
524
- return [2 /*return*/, serialized.error];
525
- }
526
- return [2 /*return*/, textResult(JSON.stringify({ data: serialized.value }))];
243
+ catch (error) {
244
+ if ((0, errors_1.isAPIError)(error)) {
245
+ return errorResult(error.title, error);
246
+ }
247
+ return errorResult(`queryFilter failed: ${errorMessage(error)}`, error);
527
248
  }
528
- });
529
- }); };
249
+ }
250
+ // Pagination
251
+ const limit = Math.max(1, Math.min(Number(args.limit) || maxLimit, maxLimit));
252
+ const page = Math.max(1, Number(args.page) || 1);
253
+ let builtQuery = model.find(query).limit(limit + 1);
254
+ const total = await model.countDocuments(query);
255
+ if (page > 1) {
256
+ builtQuery = builtQuery.skip((page - 1) * limit);
257
+ }
258
+ // Sort
259
+ const sort = asOptionalString(args.sort) ?? options.sort;
260
+ if (sort) {
261
+ builtQuery = builtQuery.sort(sort);
262
+ }
263
+ // Populate
264
+ const { error: populateError, paths: populatePaths } = resolvePopulatePaths(asOptionalString(args.populate), options.populatePaths);
265
+ if (populateError || !populatePaths) {
266
+ return errorResult(populateError ?? "Could not resolve populate paths");
267
+ }
268
+ const populatedQuery = (0, api_1.addPopulateToQuery)(builtQuery, populatePaths);
269
+ const data = await populatedQuery.exec();
270
+ const more = data.length > limit;
271
+ const sliced = more ? data.slice(0, limit) : data;
272
+ const serialized = await serializeResponse(sliced, "list", entry, user);
273
+ if ("error" in serialized) {
274
+ return serialized.error;
275
+ }
276
+ return textResult(JSON.stringify({ data: serialized.value, more, page, total }));
277
+ };
278
+ exports.handleList = handleList;
279
+ const handleRead = async (entry, args, user) => {
280
+ const { model, options } = entry;
281
+ if (requiresAuthentication(entry, user)) {
282
+ return errorResult("Permission denied: authentication required");
283
+ }
284
+ // Check method-level permission
285
+ if (!(await (0, permissions_1.checkPermissions)("read", options.permissions.read, user))) {
286
+ return errorResult("Permission denied: cannot read");
287
+ }
288
+ const { error: populateError, paths: populatePaths } = resolvePopulatePaths(asOptionalString(args.populate), options.populatePaths);
289
+ if (populateError || !populatePaths) {
290
+ return errorResult(populateError ?? "Could not resolve populate paths");
291
+ }
292
+ const id = asOptionalString(args.id);
293
+ if (!id) {
294
+ return missingDocumentResult(args.id);
295
+ }
296
+ const data = await execFindByIdQuery((0, api_1.addPopulateToQuery)(model.findById(id), populatePaths));
297
+ if (!data) {
298
+ return missingDocumentResult(id);
299
+ }
300
+ // Check object-level permission
301
+ if (!(await (0, permissions_1.checkPermissions)("read", options.permissions.read, user, data))) {
302
+ return errorResult("Permission denied: cannot read this document");
303
+ }
304
+ const serialized = await serializeResponse(data, "read", entry, user);
305
+ if ("error" in serialized) {
306
+ return serialized.error;
307
+ }
308
+ return textResult(JSON.stringify({ data: serialized.value }));
309
+ };
310
+ exports.handleRead = handleRead;
311
+ const handleCreate = async (entry, args, user) => {
312
+ const { model, options } = entry;
313
+ if (requiresAuthentication(entry, user)) {
314
+ return errorResult("Permission denied: authentication required");
315
+ }
316
+ const body = omitDeniedWriteFields(args, deniedWriteFields(entry, "create"));
317
+ const req = (0, createMCPRequest_1.createMCPRequest)({ body, user });
318
+ let data;
319
+ try {
320
+ const result = await (0, executors_1.executeCreate)({
321
+ body,
322
+ model,
323
+ options,
324
+ req,
325
+ user,
326
+ writeModelName: entry.modelName,
327
+ });
328
+ data = result.doc;
329
+ }
330
+ catch (error) {
331
+ return fromExecutorError(error);
332
+ }
333
+ const serialized = await serializeResponse(data, "create", entry, user);
334
+ if ("error" in serialized) {
335
+ return serialized.error;
336
+ }
337
+ return textResult(JSON.stringify({ data: serialized.value }));
338
+ };
530
339
  exports.handleCreate = handleCreate;
531
- var handleUpdate = function (entry, args, user) { return __awaiter(void 0, void 0, void 0, function () {
532
- var model, options, id, updateFields, documentId, body, req, doc, result, error_5, serialized;
533
- return __generator(this, function (_a) {
534
- switch (_a.label) {
535
- case 0:
536
- model = entry.model, options = entry.options;
537
- id = args.id, updateFields = __rest(args, ["id"]);
538
- if (requiresAuthentication(entry, user)) {
539
- return [2 /*return*/, errorResult("Permission denied: authentication required")];
540
- }
541
- documentId = asOptionalString(id);
542
- if (!documentId) {
543
- return [2 /*return*/, missingDocumentResult(id)];
544
- }
545
- body = omitDeniedWriteFields(updateFields, deniedWriteFields(entry, "update"));
546
- req = (0, createMCPRequest_1.createMCPRequest)({ body: body, user: user });
547
- _a.label = 1;
548
- case 1:
549
- _a.trys.push([1, 3, , 4]);
550
- return [4 /*yield*/, (0, executors_1.executeUpdate)({
551
- body: body,
552
- id: documentId,
553
- model: model,
554
- options: options,
555
- req: req,
556
- user: user,
557
- writeModelName: entry.modelName,
558
- })];
559
- case 2:
560
- result = _a.sent();
561
- doc = result.doc;
562
- return [3 /*break*/, 4];
563
- case 3:
564
- error_5 = _a.sent();
565
- return [2 /*return*/, fromExecutorError(error_5)];
566
- case 4: return [4 /*yield*/, serializeResponse(doc, "update", entry, user)];
567
- case 5:
568
- serialized = _a.sent();
569
- if ("error" in serialized) {
570
- return [2 /*return*/, serialized.error];
571
- }
572
- return [2 /*return*/, textResult(JSON.stringify({ data: serialized.value }))];
573
- }
574
- });
575
- }); };
340
+ const handleUpdate = async (entry, args, user) => {
341
+ const { model, options } = entry;
342
+ const { id, ...updateFields } = args;
343
+ if (requiresAuthentication(entry, user)) {
344
+ return errorResult("Permission denied: authentication required");
345
+ }
346
+ const documentId = asOptionalString(id);
347
+ if (!documentId) {
348
+ return missingDocumentResult(id);
349
+ }
350
+ const body = omitDeniedWriteFields(updateFields, deniedWriteFields(entry, "update"));
351
+ const req = (0, createMCPRequest_1.createMCPRequest)({ body, user });
352
+ let doc;
353
+ try {
354
+ const result = await (0, executors_1.executeUpdate)({
355
+ body,
356
+ id: documentId,
357
+ model,
358
+ options,
359
+ req,
360
+ user,
361
+ writeModelName: entry.modelName,
362
+ });
363
+ doc = result.doc;
364
+ }
365
+ catch (error) {
366
+ return fromExecutorError(error);
367
+ }
368
+ const serialized = await serializeResponse(doc, "update", entry, user);
369
+ if ("error" in serialized) {
370
+ return serialized.error;
371
+ }
372
+ return textResult(JSON.stringify({ data: serialized.value }));
373
+ };
576
374
  exports.handleUpdate = handleUpdate;
577
- var handleDelete = function (entry, args, user) { return __awaiter(void 0, void 0, void 0, function () {
578
- var model, options, id, documentId, error_6;
579
- return __generator(this, function (_a) {
580
- switch (_a.label) {
581
- case 0:
582
- model = entry.model, options = entry.options;
583
- id = args.id;
584
- if (requiresAuthentication(entry, user)) {
585
- return [2 /*return*/, errorResult("Permission denied: authentication required")];
586
- }
587
- documentId = asOptionalString(id);
588
- if (!documentId) {
589
- return [2 /*return*/, missingDocumentResult(id)];
590
- }
591
- _a.label = 1;
592
- case 1:
593
- _a.trys.push([1, 3, , 4]);
594
- return [4 /*yield*/, (0, executors_1.executeDelete)({
595
- id: documentId,
596
- model: model,
597
- options: options,
598
- req: (0, createMCPRequest_1.createMCPRequest)({ body: args, user: user }),
599
- user: user,
600
- })];
601
- case 2:
602
- _a.sent();
603
- return [3 /*break*/, 4];
604
- case 3:
605
- error_6 = _a.sent();
606
- return [2 /*return*/, fromExecutorError(error_6)];
607
- case 4: return [2 /*return*/, textResult(JSON.stringify({ success: true }))];
608
- }
609
- });
610
- }); };
375
+ const handleDelete = async (entry, args, user) => {
376
+ const { model, options } = entry;
377
+ const { id } = args;
378
+ if (requiresAuthentication(entry, user)) {
379
+ return errorResult("Permission denied: authentication required");
380
+ }
381
+ const documentId = asOptionalString(id);
382
+ if (!documentId) {
383
+ return missingDocumentResult(id);
384
+ }
385
+ try {
386
+ await (0, executors_1.executeDelete)({
387
+ id: documentId,
388
+ model,
389
+ options,
390
+ req: (0, createMCPRequest_1.createMCPRequest)({ body: args, user }),
391
+ user,
392
+ });
393
+ }
394
+ catch (error) {
395
+ return fromExecutorError(error);
396
+ }
397
+ return textResult(JSON.stringify({ success: true }));
398
+ };
611
399
  exports.handleDelete = handleDelete;
612
- var errorMessage = function (error) {
400
+ const errorMessage = (error) => {
613
401
  return error instanceof Error ? error.message : String(error);
614
402
  };
615
- var textResult = function (text) { return ({
616
- content: [{ text: text, type: "text" }],
617
- }); };
618
- var errorResult = function (message, cause) {
619
- var result = {
403
+ const textResult = (text) => ({
404
+ content: [{ text, type: "text" }],
405
+ });
406
+ const errorResult = (message, cause) => {
407
+ const result = {
620
408
  content: [{ text: JSON.stringify({ error: message }), type: "text" }],
621
409
  isError: true,
622
410
  };