@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.
- 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 +617 -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/api.arrayOperations.test.ts +44 -0
- package/src/api.ts +64 -39
- 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
package/dist/sync/executors.js
CHANGED
|
@@ -1,99 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
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);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
54
|
-
var t = {};
|
|
55
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
56
|
-
t[p] = s[p];
|
|
57
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
58
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
59
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
60
|
-
t[p[i]] = s[p[i]];
|
|
61
|
-
}
|
|
62
|
-
return t;
|
|
63
|
-
};
|
|
64
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
4
|
};
|
|
67
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
6
|
exports.runPostDelete = exports.executeDelete = exports.runPostUpdate = exports.executeUpdate = exports.runPostCreate = exports.executeCreate = exports.isVersionError = exports.isExecutorConflictError = exports.ExecutorConflictError = void 0;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
7
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
|
+
const api_1 = require("../api");
|
|
10
|
+
const auth_1 = require("../auth");
|
|
11
|
+
const docLoader_1 = require("../docLoader");
|
|
12
|
+
const errors_1 = require("../errors");
|
|
13
|
+
const permissions_1 = require("../permissions");
|
|
14
|
+
const modelRouterAccess_1 = require("../rbac/modelRouterAccess");
|
|
15
|
+
const transformers_1 = require("../transformers");
|
|
78
16
|
/**
|
|
79
17
|
* Thrown by executeUpdate when a concurrency check fails. Carries the current server document
|
|
80
18
|
* (canonical copy) so callers can serialize it into a conflict response: the REST handler
|
|
81
19
|
* turns timestamp conflicts into the legacy 409 `{data, error, message}` body, and the sync
|
|
82
20
|
* mutation channel returns the doc + seq in its conflict nack.
|
|
83
21
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
22
|
+
class ExecutorConflictError extends errors_1.APIError {
|
|
23
|
+
/** Which concurrency mode detected the conflict. */
|
|
24
|
+
conflictType;
|
|
25
|
+
/** The current server document at conflict time. */
|
|
26
|
+
doc;
|
|
27
|
+
/** The doc's `_syncSeq` at conflict time (seq mode only). */
|
|
28
|
+
serverSeq;
|
|
29
|
+
constructor({ conflictType, doc, serverSeq, ...apiErrorData }) {
|
|
30
|
+
super(apiErrorData);
|
|
31
|
+
this.conflictType = conflictType;
|
|
32
|
+
this.doc = doc;
|
|
33
|
+
this.serverSeq = serverSeq;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
97
36
|
exports.ExecutorConflictError = ExecutorConflictError;
|
|
98
37
|
/**
|
|
99
38
|
* Duck-typed guard for {@link ExecutorConflictError}. The package compiles to ES5, where
|
|
@@ -102,11 +41,11 @@ exports.ExecutorConflictError = ExecutorConflictError;
|
|
|
102
41
|
* source directly is unaffected — which is why unit/integration tests never caught it).
|
|
103
42
|
* Always use this guard instead of `instanceof ExecutorConflictError`.
|
|
104
43
|
*/
|
|
105
|
-
|
|
44
|
+
const isExecutorConflictError = (error) => {
|
|
106
45
|
if (error instanceof ExecutorConflictError) {
|
|
107
46
|
return true;
|
|
108
47
|
}
|
|
109
|
-
|
|
48
|
+
const candidate = error;
|
|
110
49
|
return (!!candidate &&
|
|
111
50
|
typeof candidate === "object" &&
|
|
112
51
|
(candidate.conflictType === "timestamp" || candidate.conflictType === "seq") &&
|
|
@@ -117,16 +56,14 @@ exports.isExecutorConflictError = isExecutorConflictError;
|
|
|
117
56
|
* Minimal stand-in for an Express request when executors run outside HTTP. Only `user` is
|
|
118
57
|
* populated — see the module doc comment for the hook compatibility contract.
|
|
119
58
|
*/
|
|
120
|
-
|
|
59
|
+
const stubRequest = (user) => ({ user });
|
|
121
60
|
/**
|
|
122
61
|
* True for the Mongoose error thrown when an `optimisticConcurrency` save matched no
|
|
123
62
|
* document (its `__v` filter failed) — i.e. another write landed since the load.
|
|
124
63
|
* Name-checked rather than `instanceof` for the same ES5-dist reason as
|
|
125
64
|
* {@link isExecutorConflictError}.
|
|
126
65
|
*/
|
|
127
|
-
|
|
128
|
-
return (error === null || error === void 0 ? void 0 : error.name) === "VersionError";
|
|
129
|
-
};
|
|
66
|
+
const isVersionError = (error) => error?.name === "VersionError";
|
|
130
67
|
exports.isVersionError = isVersionError;
|
|
131
68
|
/**
|
|
132
69
|
* Re-read the document a version-conflicted save lost to, so the conflict response carries
|
|
@@ -135,158 +72,119 @@ exports.isVersionError = isVersionError;
|
|
|
135
72
|
* client needs to learn that too. Returns undefined if the read fails — the caller falls
|
|
136
73
|
* back to its own instance rather than failing the request.
|
|
137
74
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return [2 /*return*/, found[0]];
|
|
148
|
-
case 2:
|
|
149
|
-
_a = _b.sent();
|
|
150
|
-
return [2 /*return*/, undefined];
|
|
151
|
-
case 3: return [2 /*return*/];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}); };
|
|
75
|
+
const reloadDocForConflict = async (model, id) => {
|
|
76
|
+
try {
|
|
77
|
+
const found = await model.find({ _id: id, deleted: { $in: [true, false] } }).limit(1);
|
|
78
|
+
return found[0];
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
155
84
|
/**
|
|
156
85
|
* Create a document through the same pipeline as `POST /`: method-level permissions,
|
|
157
86
|
* `transformer.transform`, `preCreate`, `Model.create` (Mongoose validation), population,
|
|
158
87
|
* and `postCreate`. Throws APIErrors with the same statuses/titles as the REST handler.
|
|
159
88
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
catch (error) {
|
|
184
|
-
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
185
|
-
code: "transform-error",
|
|
186
|
-
status: 400,
|
|
187
|
-
title: "Transform error",
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
if (!options.preCreate) return [3 /*break*/, 7];
|
|
191
|
-
_d.label = 3;
|
|
192
|
-
case 3:
|
|
193
|
-
_d.trys.push([3, 5, , 6]);
|
|
194
|
-
return [4 /*yield*/, options.preCreate(cleanedBody, request)];
|
|
195
|
-
case 4:
|
|
196
|
-
cleanedBody = _d.sent();
|
|
197
|
-
return [3 /*break*/, 6];
|
|
198
|
-
case 5:
|
|
199
|
-
error_1 = _d.sent();
|
|
200
|
-
throw (0, errors_1.passthroughOrWrap)(error_1, {
|
|
201
|
-
code: "pre-create-hook-error",
|
|
202
|
-
status: 400,
|
|
203
|
-
title: "preCreate hook error",
|
|
204
|
-
});
|
|
205
|
-
case 6:
|
|
206
|
-
if (cleanedBody === undefined) {
|
|
207
|
-
throw new errors_1.ForbiddenError({
|
|
208
|
-
code: "create-not-allowed",
|
|
209
|
-
detail: "A body must be returned from preCreate",
|
|
210
|
-
title: "Create not allowed",
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
if (cleanedBody === null) {
|
|
214
|
-
throw new errors_1.ForbiddenError({
|
|
215
|
-
code: "create-not-allowed",
|
|
216
|
-
detail: "preCreate hook returned null",
|
|
217
|
-
title: "Create not allowed",
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
_d.label = 7;
|
|
221
|
-
case 7:
|
|
222
|
-
cleanedBody = (0, auth_1.omitUserRolesFromWriteBody)(writeModelName !== null && writeModelName !== void 0 ? writeModelName : model.modelName, options.accessControl, cleanedBody, request
|
|
223
|
-
.terrenoAllowUserAdminWrite === true);
|
|
224
|
-
if (cleanedBody === undefined) {
|
|
225
|
-
throw new errors_1.BadRequestError({
|
|
226
|
-
code: "invalid-request-body",
|
|
227
|
-
detail: "Body is undefined",
|
|
228
|
-
title: "Invalid request body",
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
return [4 /*yield*/, (0, modelRouterAccess_1.validateAccessWritePayload)({
|
|
232
|
-
body: cleanedBody,
|
|
233
|
-
options: options,
|
|
234
|
-
phase: "create",
|
|
235
|
-
user: user,
|
|
236
|
-
})];
|
|
237
|
-
case 8:
|
|
238
|
-
_d.sent();
|
|
239
|
-
_d.label = 9;
|
|
240
|
-
case 9:
|
|
241
|
-
_d.trys.push([9, 11, , 12]);
|
|
242
|
-
return [4 /*yield*/, model.create(cleanedBody)];
|
|
243
|
-
case 10:
|
|
244
|
-
data = (_d.sent());
|
|
245
|
-
return [3 /*break*/, 12];
|
|
246
|
-
case 11:
|
|
247
|
-
error_2 = _d.sent();
|
|
248
|
-
throw (0, errors_1.passthroughOrWrapWrite)(error_2, {
|
|
249
|
-
code: "create-error",
|
|
250
|
-
status: 400,
|
|
251
|
-
title: "Create error",
|
|
252
|
-
});
|
|
253
|
-
case 12:
|
|
254
|
-
if (!options.populatePaths) return [3 /*break*/, 16];
|
|
255
|
-
_d.label = 13;
|
|
256
|
-
case 13:
|
|
257
|
-
_d.trys.push([13, 15, , 16]);
|
|
258
|
-
populateQuery = (0, api_1.addPopulateToQuery)(model.findById(data._id), options.populatePaths);
|
|
259
|
-
return [4 /*yield*/, populateQuery.exec()];
|
|
260
|
-
case 14:
|
|
261
|
-
data = (_d.sent());
|
|
262
|
-
return [3 /*break*/, 16];
|
|
263
|
-
case 15:
|
|
264
|
-
error_3 = _d.sent();
|
|
265
|
-
throw (0, errors_1.passthroughOrWrap)(error_3, {
|
|
266
|
-
code: "populate-error",
|
|
267
|
-
status: 400,
|
|
268
|
-
title: "Populate error",
|
|
269
|
-
});
|
|
270
|
-
case 16:
|
|
271
|
-
if (!(options.postCreate && !skipPostHooks)) return [3 /*break*/, 20];
|
|
272
|
-
_d.label = 17;
|
|
273
|
-
case 17:
|
|
274
|
-
_d.trys.push([17, 19, , 20]);
|
|
275
|
-
return [4 /*yield*/, options.postCreate(data, request)];
|
|
276
|
-
case 18:
|
|
277
|
-
_d.sent();
|
|
278
|
-
return [3 /*break*/, 20];
|
|
279
|
-
case 19:
|
|
280
|
-
error_4 = _d.sent();
|
|
281
|
-
throw (0, errors_1.passthroughOrWrap)(error_4, {
|
|
282
|
-
code: "post-create-hook-error",
|
|
283
|
-
status: 400,
|
|
284
|
-
title: "postCreate hook error",
|
|
285
|
-
});
|
|
286
|
-
case 20: return [2 /*return*/, { doc: data }];
|
|
89
|
+
const executeCreate = async ({ model, options, user, body, req, skipPermissionChecks, skipPostHooks, writeModelName, }) => {
|
|
90
|
+
const request = req ?? stubRequest(user);
|
|
91
|
+
if (!skipPermissionChecks &&
|
|
92
|
+
!(await (0, permissions_1.checkPermissions)("create", options.permissions.create, user))) {
|
|
93
|
+
throw new errors_1.APIError({
|
|
94
|
+
status: 405,
|
|
95
|
+
title: `Access to CREATE on ${model.modelName} denied for ${user?.id}`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
let cleanedBody;
|
|
99
|
+
try {
|
|
100
|
+
cleanedBody = (0, transformers_1.transform)(options, body, "create", user);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
104
|
+
code: "transform-error",
|
|
105
|
+
status: 400,
|
|
106
|
+
title: "Transform error",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (options.preCreate) {
|
|
110
|
+
try {
|
|
111
|
+
cleanedBody = await options.preCreate(cleanedBody, request);
|
|
287
112
|
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
115
|
+
code: "pre-create-hook-error",
|
|
116
|
+
status: 400,
|
|
117
|
+
title: "preCreate hook error",
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (cleanedBody === undefined) {
|
|
121
|
+
throw new errors_1.ForbiddenError({
|
|
122
|
+
code: "create-not-allowed",
|
|
123
|
+
detail: "A body must be returned from preCreate",
|
|
124
|
+
title: "Create not allowed",
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (cleanedBody === null) {
|
|
128
|
+
throw new errors_1.ForbiddenError({
|
|
129
|
+
code: "create-not-allowed",
|
|
130
|
+
detail: "preCreate hook returned null",
|
|
131
|
+
title: "Create not allowed",
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
cleanedBody = (0, auth_1.omitUserRolesFromWriteBody)(writeModelName ?? model.modelName, options.accessControl, cleanedBody, request
|
|
136
|
+
.terrenoAllowUserAdminWrite === true);
|
|
137
|
+
if (cleanedBody === undefined) {
|
|
138
|
+
throw new errors_1.BadRequestError({
|
|
139
|
+
code: "invalid-request-body",
|
|
140
|
+
detail: "Body is undefined",
|
|
141
|
+
title: "Invalid request body",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
await (0, modelRouterAccess_1.validateAccessWritePayload)({
|
|
145
|
+
body: cleanedBody,
|
|
146
|
+
options,
|
|
147
|
+
phase: "create",
|
|
148
|
+
user,
|
|
288
149
|
});
|
|
289
|
-
|
|
150
|
+
let data;
|
|
151
|
+
try {
|
|
152
|
+
data = (await model.create(cleanedBody));
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw (0, errors_1.passthroughOrWrapWrite)(error, {
|
|
156
|
+
code: "create-error",
|
|
157
|
+
status: 400,
|
|
158
|
+
title: "Create error",
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (options.populatePaths) {
|
|
162
|
+
try {
|
|
163
|
+
const populateQuery = (0, api_1.addPopulateToQuery)(model.findById(data._id), options.populatePaths);
|
|
164
|
+
data = (await populateQuery.exec());
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
168
|
+
code: "populate-error",
|
|
169
|
+
status: 400,
|
|
170
|
+
title: "Populate error",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (options.postCreate && !skipPostHooks) {
|
|
175
|
+
try {
|
|
176
|
+
await options.postCreate(data, request);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
180
|
+
code: "post-create-hook-error",
|
|
181
|
+
status: 400,
|
|
182
|
+
title: "postCreate hook error",
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { doc: data };
|
|
187
|
+
};
|
|
290
188
|
exports.executeCreate = executeCreate;
|
|
291
189
|
/**
|
|
292
190
|
* C5 (FIX 6): run `postCreate` outside the write transaction/ledger-finalize
|
|
@@ -295,20 +193,11 @@ exports.executeCreate = executeCreate;
|
|
|
295
193
|
* (the document write already committed and the ledger already finalized
|
|
296
194
|
* `applied`).
|
|
297
195
|
*/
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (!options.postCreate) return [3 /*break*/, 2];
|
|
304
|
-
return [4 /*yield*/, options.postCreate(doc, request)];
|
|
305
|
-
case 1:
|
|
306
|
-
_c.sent();
|
|
307
|
-
_c.label = 2;
|
|
308
|
-
case 2: return [2 /*return*/];
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
}); };
|
|
196
|
+
const runPostCreate = async ({ doc, options, request, }) => {
|
|
197
|
+
if (options.postCreate) {
|
|
198
|
+
await options.postCreate(doc, request);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
312
201
|
exports.runPostCreate = runPostCreate;
|
|
313
202
|
/**
|
|
314
203
|
* Update a document through the same pipeline as `PATCH /:id`: method-level and object-level
|
|
@@ -317,239 +206,193 @@ exports.runPostCreate = runPostCreate;
|
|
|
317
206
|
* population, and `postUpdate`. Throws APIErrors with the same statuses/titles as the REST
|
|
318
207
|
* handler; concurrency conflicts throw `ExecutorConflictError` (409) carrying the server doc.
|
|
319
208
|
*/
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
catch (error) {
|
|
367
|
-
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
368
|
-
code: "transform-error",
|
|
369
|
-
detail: "PATCH failed on ".concat(id, " for user ").concat(user === null || user === void 0 ? void 0 : user.id, ": ").concat((0, errors_1.errorMessage)(error)),
|
|
370
|
-
status: 403,
|
|
371
|
-
title: "PATCH failed",
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
// `_updatedAt` is conflict-detection metadata, not a model field: strip it from both the
|
|
375
|
-
// raw and transformed bodies before preUpdate processes them (mirrors the REST handler).
|
|
376
|
-
if (body && typeof body === "object") {
|
|
377
|
-
delete body._updatedAt;
|
|
378
|
-
}
|
|
379
|
-
if (cleanedBody && typeof cleanedBody === "object") {
|
|
380
|
-
delete cleanedBody._updatedAt;
|
|
381
|
-
}
|
|
382
|
-
if (!options.preUpdate) return [3 /*break*/, 12];
|
|
383
|
-
_k.label = 8;
|
|
384
|
-
case 8:
|
|
385
|
-
_k.trys.push([8, 10, , 11]);
|
|
386
|
-
return [4 /*yield*/, options.preUpdate(cleanedBody, request)];
|
|
387
|
-
case 9:
|
|
388
|
-
cleanedBody = _k.sent();
|
|
389
|
-
return [3 /*break*/, 11];
|
|
390
|
-
case 10:
|
|
391
|
-
error_5 = _k.sent();
|
|
392
|
-
throw (0, errors_1.passthroughOrWrap)(error_5, {
|
|
393
|
-
code: "pre-update-hook-error",
|
|
394
|
-
detail: "preUpdate hook error on ".concat(id, ": ").concat((0, errors_1.errorMessage)(error_5)),
|
|
395
|
-
status: 400,
|
|
396
|
-
title: "preUpdate hook error",
|
|
397
|
-
});
|
|
398
|
-
case 11:
|
|
399
|
-
if (cleanedBody === undefined) {
|
|
400
|
-
throw new errors_1.ForbiddenError({
|
|
401
|
-
code: "update-not-allowed",
|
|
402
|
-
detail: "A body must be returned from preUpdate",
|
|
403
|
-
title: "Update not allowed",
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
if (cleanedBody === null) {
|
|
407
|
-
throw new errors_1.ForbiddenError({
|
|
408
|
-
code: "update-not-allowed",
|
|
409
|
-
detail: "preUpdate hook on ".concat(id, " returned null"),
|
|
410
|
-
title: "Update not allowed",
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
_k.label = 12;
|
|
414
|
-
case 12:
|
|
415
|
-
cleanedBody = (0, auth_1.omitUserRolesFromWriteBody)(writeModelName !== null && writeModelName !== void 0 ? writeModelName : model.modelName, options.accessControl, cleanedBody, request
|
|
416
|
-
.terrenoAllowUserAdminWrite === true);
|
|
417
|
-
return [4 /*yield*/, (0, modelRouterAccess_1.validateAccessWritePayload)({
|
|
418
|
-
body: cleanedBody,
|
|
419
|
-
doc: doc,
|
|
420
|
-
options: options,
|
|
421
|
-
phase: "write",
|
|
422
|
-
user: user,
|
|
423
|
-
})];
|
|
424
|
-
case 13:
|
|
425
|
-
_k.sent();
|
|
426
|
-
// Conflict detection runs after preUpdate so that unauthorized mutations
|
|
427
|
-
// are rejected before we leak document data in a conflict response.
|
|
428
|
-
if ((concurrencyCheck === null || concurrencyCheck === void 0 ? void 0 : concurrencyCheck.type) === "timestamp") {
|
|
429
|
-
clientTimestamp = luxon_1.DateTime.fromJSDate(concurrencyCheck.ifUnmodifiedSince);
|
|
430
|
-
if (!clientTimestamp.isValid) {
|
|
431
|
-
throw new errors_1.APIError({
|
|
432
|
-
detail: (_f = concurrencyCheck.invalidTimestampDetail) !== null && _f !== void 0 ? _f : "Conflict-detection timestamp could not be parsed as a date",
|
|
433
|
-
status: 400,
|
|
434
|
-
title: "Invalid conflict-detection timestamp",
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
docRecord = doc;
|
|
438
|
-
serverTimestamp = null;
|
|
439
|
-
serverTimestampValue = (_g = docRecord.updated) !== null && _g !== void 0 ? _g : docRecord.created;
|
|
440
|
-
if (serverTimestampValue instanceof Date) {
|
|
441
|
-
serverTimestamp = luxon_1.DateTime.fromJSDate(serverTimestampValue);
|
|
442
|
-
}
|
|
443
|
-
else if (typeof serverTimestampValue === "string") {
|
|
444
|
-
serverTimestamp = luxon_1.DateTime.fromISO(serverTimestampValue);
|
|
445
|
-
}
|
|
446
|
-
if (serverTimestamp && !serverTimestamp.isValid) {
|
|
447
|
-
throw new errors_1.APIError({
|
|
448
|
-
detail: "Document timestamp could not be parsed as a date",
|
|
449
|
-
status: 400,
|
|
450
|
-
title: "Invalid server timestamp",
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
if (serverTimestamp && clientTimestamp < serverTimestamp) {
|
|
454
|
-
throw new ExecutorConflictError({
|
|
455
|
-
conflictType: "timestamp",
|
|
456
|
-
detail: "Document was modified since your last read",
|
|
457
|
-
disableExternalErrorTracking: true,
|
|
458
|
-
doc: doc,
|
|
459
|
-
status: 409,
|
|
460
|
-
title: "Conflict",
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
else if ((concurrencyCheck === null || concurrencyCheck === void 0 ? void 0 : concurrencyCheck.type) === "seq") {
|
|
465
|
-
serverSeq = (_h = doc._syncSeq) !== null && _h !== void 0 ? _h : 0;
|
|
466
|
-
if (concurrencyCheck.baseSeq !== serverSeq) {
|
|
467
|
-
throw new ExecutorConflictError({
|
|
468
|
-
conflictType: "seq",
|
|
469
|
-
detail: "Document was modified since your last read",
|
|
470
|
-
disableExternalErrorTracking: true,
|
|
471
|
-
doc: doc,
|
|
472
|
-
serverSeq: serverSeq,
|
|
473
|
-
status: 409,
|
|
474
|
-
title: "Sync conflict on ".concat(model.modelName, ":").concat(id, ": baseSeq ").concat(concurrencyCheck.baseSeq, " does not match server seq ").concat(serverSeq),
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
prevDoc = (0, cloneDeep_1.default)(doc);
|
|
479
|
-
_k.label = 14;
|
|
480
|
-
case 14:
|
|
481
|
-
_k.trys.push([14, 16, , 19]);
|
|
482
|
-
doc.set(cleanedBody);
|
|
483
|
-
return [4 /*yield*/, doc.save()];
|
|
484
|
-
case 15:
|
|
485
|
-
_k.sent();
|
|
486
|
-
return [3 /*break*/, 19];
|
|
487
|
-
case 16:
|
|
488
|
-
error_6 = _k.sent();
|
|
489
|
-
if (!((concurrencyCheck === null || concurrencyCheck === void 0 ? void 0 : concurrencyCheck.type) === "seq" && (0, exports.isVersionError)(error_6))) return [3 /*break*/, 18];
|
|
490
|
-
return [4 /*yield*/, reloadDocForConflict(model, id)];
|
|
491
|
-
case 17:
|
|
492
|
-
current = _k.sent();
|
|
493
|
-
serverSeq = (_j = current === null || current === void 0 ? void 0 : current._syncSeq) !== null && _j !== void 0 ? _j : 0;
|
|
494
|
-
throw new ExecutorConflictError({
|
|
495
|
-
conflictType: "seq",
|
|
496
|
-
detail: "Document was modified since your last read",
|
|
497
|
-
disableExternalErrorTracking: true,
|
|
498
|
-
doc: current !== null && current !== void 0 ? current : doc,
|
|
499
|
-
serverSeq: serverSeq,
|
|
500
|
-
status: 409,
|
|
501
|
-
title: "Sync conflict on ".concat(model.modelName, ":").concat(id, ": a concurrent write landed while this update was in flight (baseSeq ").concat(concurrencyCheck.baseSeq, ")"),
|
|
502
|
-
});
|
|
503
|
-
case 18: throw (0, errors_1.passthroughOrWrapWrite)(error_6, {
|
|
504
|
-
code: "update-save-error",
|
|
505
|
-
detail: "preUpdate hook save error on ".concat(id, ": ").concat((0, errors_1.errorMessage)(error_6)),
|
|
209
|
+
const executeUpdate = async ({ model, options, user, id, body, concurrencyCheck, existingDoc, req, skipPermissionChecks, skipPostHooks, writeModelName, }) => {
|
|
210
|
+
const request = req ?? stubRequest(user);
|
|
211
|
+
if (!skipPermissionChecks &&
|
|
212
|
+
!(await (0, permissions_1.checkPermissions)("update", options.permissions.update, user))) {
|
|
213
|
+
throw new errors_1.APIError({
|
|
214
|
+
status: 405,
|
|
215
|
+
title: `Access to UPDATE on ${model.modelName} denied for ${user?.id}`,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
let doc = existingDoc ?? (await (0, docLoader_1.loadDocOr404)(model, id, options.populatePaths));
|
|
219
|
+
if (!skipPermissionChecks &&
|
|
220
|
+
!(await (0, permissions_1.checkPermissions)("update", options.permissions.update, user, doc))) {
|
|
221
|
+
throw new errors_1.APIError({
|
|
222
|
+
status: 403,
|
|
223
|
+
title: `Access to GET on ${model.modelName}:${id} denied for ${user?.id}`,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
let cleanedBody;
|
|
227
|
+
try {
|
|
228
|
+
cleanedBody = (0, transformers_1.transform)(options, body, "update", user);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
232
|
+
code: "transform-error",
|
|
233
|
+
detail: `PATCH failed on ${id} for user ${user?.id}: ${(0, errors_1.errorMessage)(error)}`,
|
|
234
|
+
status: 403,
|
|
235
|
+
title: "PATCH failed",
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
// `_updatedAt` is conflict-detection metadata, not a model field: strip it from both the
|
|
239
|
+
// raw and transformed bodies before preUpdate processes them (mirrors the REST handler).
|
|
240
|
+
if (body && typeof body === "object") {
|
|
241
|
+
delete body._updatedAt;
|
|
242
|
+
}
|
|
243
|
+
if (cleanedBody && typeof cleanedBody === "object") {
|
|
244
|
+
delete cleanedBody._updatedAt;
|
|
245
|
+
}
|
|
246
|
+
if (options.preUpdate) {
|
|
247
|
+
try {
|
|
248
|
+
cleanedBody = await options.preUpdate(cleanedBody, request);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
252
|
+
code: "pre-update-hook-error",
|
|
253
|
+
detail: `preUpdate hook error on ${id}: ${(0, errors_1.errorMessage)(error)}`,
|
|
506
254
|
status: 400,
|
|
507
|
-
title: "preUpdate hook
|
|
255
|
+
title: "preUpdate hook error",
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (cleanedBody === undefined) {
|
|
259
|
+
throw new errors_1.ForbiddenError({
|
|
260
|
+
code: "update-not-allowed",
|
|
261
|
+
detail: "A body must be returned from preUpdate",
|
|
262
|
+
title: "Update not allowed",
|
|
508
263
|
});
|
|
509
|
-
case 19:
|
|
510
|
-
if (!options.populatePaths) return [3 /*break*/, 21];
|
|
511
|
-
populateQuery = (0, api_1.addPopulateToQuery)(model.findById(doc._id), options.populatePaths);
|
|
512
|
-
return [4 /*yield*/, populateQuery.exec()];
|
|
513
|
-
case 20:
|
|
514
|
-
doc = (_k.sent());
|
|
515
|
-
_k.label = 21;
|
|
516
|
-
case 21:
|
|
517
|
-
if (!(options.postUpdate && !skipPostHooks)) return [3 /*break*/, 25];
|
|
518
|
-
_k.label = 22;
|
|
519
|
-
case 22:
|
|
520
|
-
_k.trys.push([22, 24, , 25]);
|
|
521
|
-
return [4 /*yield*/, options.postUpdate(doc, cleanedBody, request, prevDoc)];
|
|
522
|
-
case 23:
|
|
523
|
-
_k.sent();
|
|
524
|
-
return [3 /*break*/, 25];
|
|
525
|
-
case 24:
|
|
526
|
-
error_7 = _k.sent();
|
|
527
|
-
throw (0, errors_1.passthroughOrWrap)(error_7, {
|
|
528
|
-
code: "post-update-hook-error",
|
|
529
|
-
detail: "postUpdate hook error on ".concat(id, ": ").concat((0, errors_1.errorMessage)(error_7)),
|
|
530
|
-
status: 400,
|
|
531
|
-
title: "postUpdate hook error",
|
|
532
|
-
});
|
|
533
|
-
case 25: return [2 /*return*/, { cleanedBody: cleanedBody, doc: doc, prevDoc: prevDoc }];
|
|
534
264
|
}
|
|
265
|
+
if (cleanedBody === null) {
|
|
266
|
+
throw new errors_1.ForbiddenError({
|
|
267
|
+
code: "update-not-allowed",
|
|
268
|
+
detail: `preUpdate hook on ${id} returned null`,
|
|
269
|
+
title: "Update not allowed",
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
cleanedBody = (0, auth_1.omitUserRolesFromWriteBody)(writeModelName ?? model.modelName, options.accessControl, cleanedBody, request
|
|
274
|
+
.terrenoAllowUserAdminWrite === true);
|
|
275
|
+
await (0, modelRouterAccess_1.validateAccessWritePayload)({
|
|
276
|
+
body: cleanedBody,
|
|
277
|
+
doc,
|
|
278
|
+
options,
|
|
279
|
+
phase: "write",
|
|
280
|
+
user,
|
|
535
281
|
});
|
|
536
|
-
|
|
282
|
+
// Conflict detection runs after preUpdate so that unauthorized mutations
|
|
283
|
+
// are rejected before we leak document data in a conflict response.
|
|
284
|
+
if (concurrencyCheck?.type === "timestamp") {
|
|
285
|
+
const clientTimestamp = luxon_1.DateTime.fromJSDate(concurrencyCheck.ifUnmodifiedSince);
|
|
286
|
+
if (!clientTimestamp.isValid) {
|
|
287
|
+
throw new errors_1.APIError({
|
|
288
|
+
detail: concurrencyCheck.invalidTimestampDetail ??
|
|
289
|
+
"Conflict-detection timestamp could not be parsed as a date",
|
|
290
|
+
status: 400,
|
|
291
|
+
title: "Invalid conflict-detection timestamp",
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
const docRecord = doc;
|
|
295
|
+
let serverTimestamp = null;
|
|
296
|
+
const serverTimestampValue = docRecord.updated ?? docRecord.created;
|
|
297
|
+
if (serverTimestampValue instanceof Date) {
|
|
298
|
+
serverTimestamp = luxon_1.DateTime.fromJSDate(serverTimestampValue);
|
|
299
|
+
}
|
|
300
|
+
else if (typeof serverTimestampValue === "string") {
|
|
301
|
+
serverTimestamp = luxon_1.DateTime.fromISO(serverTimestampValue);
|
|
302
|
+
}
|
|
303
|
+
if (serverTimestamp && !serverTimestamp.isValid) {
|
|
304
|
+
throw new errors_1.APIError({
|
|
305
|
+
detail: "Document timestamp could not be parsed as a date",
|
|
306
|
+
status: 400,
|
|
307
|
+
title: "Invalid server timestamp",
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (serverTimestamp && clientTimestamp < serverTimestamp) {
|
|
311
|
+
throw new ExecutorConflictError({
|
|
312
|
+
conflictType: "timestamp",
|
|
313
|
+
detail: "Document was modified since your last read",
|
|
314
|
+
disableExternalErrorTracking: true,
|
|
315
|
+
doc,
|
|
316
|
+
status: 409,
|
|
317
|
+
title: "Conflict",
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else if (concurrencyCheck?.type === "seq") {
|
|
322
|
+
const serverSeq = doc._syncSeq ?? 0;
|
|
323
|
+
if (concurrencyCheck.baseSeq !== serverSeq) {
|
|
324
|
+
throw new ExecutorConflictError({
|
|
325
|
+
conflictType: "seq",
|
|
326
|
+
detail: "Document was modified since your last read",
|
|
327
|
+
disableExternalErrorTracking: true,
|
|
328
|
+
doc,
|
|
329
|
+
serverSeq,
|
|
330
|
+
status: 409,
|
|
331
|
+
title: `Sync conflict on ${model.modelName}:${id}: baseSeq ${concurrencyCheck.baseSeq} does not match server seq ${serverSeq}`,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// Make a copy for passing pre-saved values to hooks.
|
|
336
|
+
const prevDoc = (0, cloneDeep_1.default)(doc);
|
|
337
|
+
// Using .save here runs the risk of a versioning error if you try to make two simultaneous
|
|
338
|
+
// updates. We won't wind up with corrupted data, just an API error.
|
|
339
|
+
try {
|
|
340
|
+
doc.set(cleanedBody);
|
|
341
|
+
await doc.save();
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
// Task 9.13: `syncPlugin` enables Mongoose `optimisticConcurrency` on synced schemas, so
|
|
345
|
+
// this save is conditional on the `__v` the document was loaded at. A concurrent write
|
|
346
|
+
// that landed between the seq check above and this save therefore throws a VersionError
|
|
347
|
+
// instead of silently overwriting it — the same lost update the seq check exists to
|
|
348
|
+
// prevent, just detected at write time. Report it as the conflict the seq check would
|
|
349
|
+
// have produced had the other write landed a moment earlier.
|
|
350
|
+
if (concurrencyCheck?.type === "seq" && (0, exports.isVersionError)(error)) {
|
|
351
|
+
const current = await reloadDocForConflict(model, id);
|
|
352
|
+
const serverSeq = current?._syncSeq ?? 0;
|
|
353
|
+
throw new ExecutorConflictError({
|
|
354
|
+
conflictType: "seq",
|
|
355
|
+
detail: "Document was modified since your last read",
|
|
356
|
+
disableExternalErrorTracking: true,
|
|
357
|
+
doc: current ?? doc,
|
|
358
|
+
serverSeq,
|
|
359
|
+
status: 409,
|
|
360
|
+
title: `Sync conflict on ${model.modelName}:${id}: a concurrent write landed while this update was in flight (baseSeq ${concurrencyCheck.baseSeq})`,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
throw (0, errors_1.passthroughOrWrapWrite)(error, {
|
|
364
|
+
code: "update-save-error",
|
|
365
|
+
detail: `preUpdate hook save error on ${id}: ${(0, errors_1.errorMessage)(error)}`,
|
|
366
|
+
status: 400,
|
|
367
|
+
title: "preUpdate hook save error",
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (options.populatePaths) {
|
|
371
|
+
const populateQuery = (0, api_1.addPopulateToQuery)(model.findById(doc._id), options.populatePaths);
|
|
372
|
+
doc = (await populateQuery.exec());
|
|
373
|
+
}
|
|
374
|
+
if (options.postUpdate && !skipPostHooks) {
|
|
375
|
+
try {
|
|
376
|
+
await options.postUpdate(doc, cleanedBody, request, prevDoc);
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
380
|
+
code: "post-update-hook-error",
|
|
381
|
+
detail: `postUpdate hook error on ${id}: ${(0, errors_1.errorMessage)(error)}`,
|
|
382
|
+
status: 400,
|
|
383
|
+
title: "postUpdate hook error",
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return { cleanedBody: cleanedBody, doc, prevDoc: prevDoc };
|
|
388
|
+
};
|
|
537
389
|
exports.executeUpdate = executeUpdate;
|
|
538
390
|
/** C5 (FIX 6): run `postUpdate` outside the write/ledger-finalize window — see `runPostCreate`. */
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (!options.postUpdate) return [3 /*break*/, 2];
|
|
545
|
-
return [4 /*yield*/, options.postUpdate(doc, cleanedBody, request, prevDoc)];
|
|
546
|
-
case 1:
|
|
547
|
-
_c.sent();
|
|
548
|
-
_c.label = 2;
|
|
549
|
-
case 2: return [2 /*return*/];
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
}); };
|
|
391
|
+
const runPostUpdate = async ({ doc, cleanedBody, prevDoc, options, request, }) => {
|
|
392
|
+
if (options.postUpdate) {
|
|
393
|
+
await options.postUpdate(doc, cleanedBody, request, prevDoc);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
553
396
|
exports.runPostUpdate = runPostUpdate;
|
|
554
397
|
/**
|
|
555
398
|
* Delete a document through the same pipeline as `DELETE /:id`: method-level and object-level
|
|
@@ -557,166 +400,119 @@ exports.runPostUpdate = runPostUpdate;
|
|
|
557
400
|
* schema has a Boolean `deleted` path, else `doc.deleteOne()`), and `postDelete`. Throws
|
|
558
401
|
* APIErrors with the same statuses/titles as the REST handler.
|
|
559
402
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
_g.trys.push([3, 5, , 10]);
|
|
586
|
-
return [4 /*yield*/, (0, docLoader_1.loadDocOr404)(model, id, options.populatePaths)];
|
|
587
|
-
case 4:
|
|
588
|
-
doc = (_g.sent());
|
|
589
|
-
return [3 /*break*/, 10];
|
|
590
|
-
case 5:
|
|
591
|
-
error_8 = _g.sent();
|
|
592
|
-
alreadyDeleted = (0, errors_1.isAPIError)(error_8) &&
|
|
593
|
-
error_8.status === 404 &&
|
|
594
|
-
((_f = error_8.meta) === null || _f === void 0 ? void 0 : _f.deleted) === "true";
|
|
595
|
-
if (!alreadyDeleted) return [3 /*break*/, 9];
|
|
596
|
-
return [4 /*yield*/, model.find({ _id: id, deleted: { $in: [true, false] } }).limit(1)];
|
|
597
|
-
case 6:
|
|
598
|
-
tombstone = _g.sent();
|
|
599
|
-
resolved = tombstone[0];
|
|
403
|
+
const executeDelete = async ({ model, options, user, id, existingDoc, req, skipPermissionChecks, skipPostHooks, }) => {
|
|
404
|
+
const request = req ?? stubRequest(user);
|
|
405
|
+
if (!skipPermissionChecks &&
|
|
406
|
+
!(await (0, permissions_1.checkPermissions)("delete", options.permissions.delete, user))) {
|
|
407
|
+
throw new errors_1.APIError({
|
|
408
|
+
status: 405,
|
|
409
|
+
title: `Access to DELETE on ${model.modelName} denied for ${user?.id}`,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
// C8: delete of an already-deleted doc is idempotent — loadDocOr404 auto-filters
|
|
413
|
+
// soft-deleted docs and would 404 (a `validation` nack over sync). Load the tombstone
|
|
414
|
+
// directly and return it as an idempotent success (its existing seq) instead.
|
|
415
|
+
let doc = existingDoc;
|
|
416
|
+
if (!doc) {
|
|
417
|
+
try {
|
|
418
|
+
doc = (await (0, docLoader_1.loadDocOr404)(model, id, options.populatePaths));
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
const alreadyDeleted = (0, errors_1.isAPIError)(error) &&
|
|
422
|
+
error.status === 404 &&
|
|
423
|
+
error.meta?.deleted === "true";
|
|
424
|
+
if (alreadyDeleted) {
|
|
425
|
+
// Hydrate the tombstone bypassing the isDeletedPlugin find filter.
|
|
426
|
+
const tombstone = await model.find({ _id: id, deleted: { $in: [true, false] } }).limit(1);
|
|
427
|
+
const resolved = tombstone[0];
|
|
600
428
|
if (!resolved) {
|
|
601
|
-
throw
|
|
602
|
-
}
|
|
603
|
-
_d = !skipPermissionChecks;
|
|
604
|
-
if (!_d) return [3 /*break*/, 8];
|
|
605
|
-
return [4 /*yield*/, (0, permissions_1.checkPermissions)("delete", options.permissions.delete, user, resolved)];
|
|
606
|
-
case 7:
|
|
607
|
-
_d = !(_g.sent());
|
|
608
|
-
_g.label = 8;
|
|
609
|
-
case 8:
|
|
610
|
-
if (_d) {
|
|
611
|
-
throw new errors_1.APIError({
|
|
612
|
-
status: 403,
|
|
613
|
-
title: "Access to GET on ".concat(model.modelName, ":").concat(id, " denied for ").concat(user === null || user === void 0 ? void 0 : user.id),
|
|
614
|
-
});
|
|
429
|
+
throw error;
|
|
615
430
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
case 10:
|
|
619
|
-
_e = !skipPermissionChecks;
|
|
620
|
-
if (!_e) return [3 /*break*/, 12];
|
|
621
|
-
return [4 /*yield*/, (0, permissions_1.checkPermissions)("delete", options.permissions.delete, user, doc)];
|
|
622
|
-
case 11:
|
|
623
|
-
_e = !(_g.sent());
|
|
624
|
-
_g.label = 12;
|
|
625
|
-
case 12:
|
|
626
|
-
if (_e) {
|
|
431
|
+
if (!skipPermissionChecks &&
|
|
432
|
+
!(await (0, permissions_1.checkPermissions)("delete", options.permissions.delete, user, resolved))) {
|
|
627
433
|
throw new errors_1.APIError({
|
|
628
434
|
status: 403,
|
|
629
|
-
title:
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
if (!options.preDelete) return [3 /*break*/, 17];
|
|
633
|
-
body = void 0;
|
|
634
|
-
_g.label = 13;
|
|
635
|
-
case 13:
|
|
636
|
-
_g.trys.push([13, 15, , 16]);
|
|
637
|
-
return [4 /*yield*/, options.preDelete(doc, request)];
|
|
638
|
-
case 14:
|
|
639
|
-
body = _g.sent();
|
|
640
|
-
return [3 /*break*/, 16];
|
|
641
|
-
case 15:
|
|
642
|
-
error_9 = _g.sent();
|
|
643
|
-
throw (0, errors_1.passthroughOrWrap)(error_9, {
|
|
644
|
-
code: "pre-delete-hook-error",
|
|
645
|
-
detail: "preDelete hook error on ".concat(id, ": ").concat((0, errors_1.errorMessage)(error_9)),
|
|
646
|
-
status: 403,
|
|
647
|
-
title: "preDelete hook error",
|
|
648
|
-
});
|
|
649
|
-
case 16:
|
|
650
|
-
if (body === undefined) {
|
|
651
|
-
throw new errors_1.ForbiddenError({
|
|
652
|
-
code: "delete-not-allowed",
|
|
653
|
-
detail: "A body must be returned from preDelete",
|
|
654
|
-
title: "Delete not allowed",
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
if (body === null) {
|
|
658
|
-
throw new errors_1.ForbiddenError({
|
|
659
|
-
code: "delete-not-allowed",
|
|
660
|
-
detail: "preDelete hook for ".concat(id, " returned null"),
|
|
661
|
-
title: "Delete not allowed",
|
|
435
|
+
title: `Access to GET on ${model.modelName}:${id} denied for ${user?.id}`,
|
|
662
436
|
});
|
|
663
437
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
model.schema.paths.deleted.instance === "Boolean")) return [3 /*break*/, 19];
|
|
668
|
-
doc.deleted = true;
|
|
669
|
-
return [4 /*yield*/, doc.save()];
|
|
670
|
-
case 18:
|
|
671
|
-
_g.sent();
|
|
672
|
-
return [3 /*break*/, 22];
|
|
673
|
-
case 19:
|
|
674
|
-
_g.trys.push([19, 21, , 22]);
|
|
675
|
-
return [4 /*yield*/, doc.deleteOne()];
|
|
676
|
-
case 20:
|
|
677
|
-
_g.sent();
|
|
678
|
-
return [3 /*break*/, 22];
|
|
679
|
-
case 21:
|
|
680
|
-
error_10 = _g.sent();
|
|
681
|
-
throw (0, errors_1.passthroughOrWrap)(error_10, {
|
|
682
|
-
code: "delete-error",
|
|
683
|
-
status: 400,
|
|
684
|
-
title: "Delete error",
|
|
685
|
-
});
|
|
686
|
-
case 22:
|
|
687
|
-
if (!(options.postDelete && !skipPostHooks)) return [3 /*break*/, 26];
|
|
688
|
-
_g.label = 23;
|
|
689
|
-
case 23:
|
|
690
|
-
_g.trys.push([23, 25, , 26]);
|
|
691
|
-
return [4 /*yield*/, options.postDelete(request, doc)];
|
|
692
|
-
case 24:
|
|
693
|
-
_g.sent();
|
|
694
|
-
return [3 /*break*/, 26];
|
|
695
|
-
case 25:
|
|
696
|
-
error_11 = _g.sent();
|
|
697
|
-
throw (0, errors_1.passthroughOrWrap)(error_11, {
|
|
698
|
-
code: "post-delete-hook-error",
|
|
699
|
-
status: 400,
|
|
700
|
-
title: "postDelete hook error",
|
|
701
|
-
});
|
|
702
|
-
case 26: return [2 /*return*/, { doc: doc }];
|
|
438
|
+
return { doc: resolved };
|
|
439
|
+
}
|
|
440
|
+
throw error;
|
|
703
441
|
}
|
|
704
|
-
}
|
|
705
|
-
|
|
442
|
+
}
|
|
443
|
+
if (!skipPermissionChecks &&
|
|
444
|
+
!(await (0, permissions_1.checkPermissions)("delete", options.permissions.delete, user, doc))) {
|
|
445
|
+
throw new errors_1.APIError({
|
|
446
|
+
status: 403,
|
|
447
|
+
title: `Access to GET on ${model.modelName}:${id} denied for ${user?.id}`,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
if (options.preDelete) {
|
|
451
|
+
let body;
|
|
452
|
+
try {
|
|
453
|
+
body = await options.preDelete(doc, request);
|
|
454
|
+
}
|
|
455
|
+
catch (error) {
|
|
456
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
457
|
+
code: "pre-delete-hook-error",
|
|
458
|
+
detail: `preDelete hook error on ${id}: ${(0, errors_1.errorMessage)(error)}`,
|
|
459
|
+
status: 403,
|
|
460
|
+
title: "preDelete hook error",
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
if (body === undefined) {
|
|
464
|
+
throw new errors_1.ForbiddenError({
|
|
465
|
+
code: "delete-not-allowed",
|
|
466
|
+
detail: "A body must be returned from preDelete",
|
|
467
|
+
title: "Delete not allowed",
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
if (body === null) {
|
|
471
|
+
throw new errors_1.ForbiddenError({
|
|
472
|
+
code: "delete-not-allowed",
|
|
473
|
+
detail: `preDelete hook for ${id} returned null`,
|
|
474
|
+
title: "Delete not allowed",
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
// Support .deleted from isDeleted plugin
|
|
479
|
+
if (Object.keys(model.schema.paths).includes("deleted") &&
|
|
480
|
+
model.schema.paths.deleted.instance === "Boolean") {
|
|
481
|
+
doc.deleted = true;
|
|
482
|
+
await doc.save();
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
// For models without the isDeleted plugin
|
|
486
|
+
try {
|
|
487
|
+
await doc.deleteOne();
|
|
488
|
+
}
|
|
489
|
+
catch (error) {
|
|
490
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
491
|
+
code: "delete-error",
|
|
492
|
+
status: 400,
|
|
493
|
+
title: "Delete error",
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (options.postDelete && !skipPostHooks) {
|
|
498
|
+
try {
|
|
499
|
+
await options.postDelete(request, doc);
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
throw (0, errors_1.passthroughOrWrap)(error, {
|
|
503
|
+
code: "post-delete-hook-error",
|
|
504
|
+
status: 400,
|
|
505
|
+
title: "postDelete hook error",
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return { doc };
|
|
510
|
+
};
|
|
706
511
|
exports.executeDelete = executeDelete;
|
|
707
512
|
/** C5 (FIX 6): run `postDelete` outside the write/ledger-finalize window — see `runPostCreate`. */
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
if (!options.postDelete) return [3 /*break*/, 2];
|
|
714
|
-
return [4 /*yield*/, options.postDelete(request, doc)];
|
|
715
|
-
case 1:
|
|
716
|
-
_c.sent();
|
|
717
|
-
_c.label = 2;
|
|
718
|
-
case 2: return [2 /*return*/];
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
}); };
|
|
513
|
+
const runPostDelete = async ({ doc, options, request, }) => {
|
|
514
|
+
if (options.postDelete) {
|
|
515
|
+
await options.postDelete(request, doc);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
722
518
|
exports.runPostDelete = runPostDelete;
|