@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/openApi.js
CHANGED
|
@@ -1,55 +1,19 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.readOpenApiMiddleware = exports.deleteOpenApiMiddleware = exports.patchOpenApiMiddleware = exports.createOpenApiMiddleware = exports.listOpenApiMiddleware = exports.getOpenApiMiddleware = exports.defaultOpenApiErrorResponses = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
7
|
+
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
8
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
9
|
+
const mongoose_to_swagger_1 = __importDefault(require("mongoose-to-swagger"));
|
|
10
|
+
const logger_1 = require("./logger");
|
|
11
|
+
const populate_1 = require("./populate");
|
|
12
|
+
const noop = (_a, _b, next) => next();
|
|
13
|
+
const m2sOptions = {
|
|
50
14
|
props: ["readOnly", "required", "enum", "default"],
|
|
51
15
|
};
|
|
52
|
-
|
|
16
|
+
const apiErrorContent = {
|
|
53
17
|
"application/json": {
|
|
54
18
|
schema: { $ref: "#/components/schemas/APIError" },
|
|
55
19
|
},
|
|
@@ -77,9 +41,9 @@ exports.defaultOpenApiErrorResponses = {
|
|
|
77
41
|
},
|
|
78
42
|
};
|
|
79
43
|
// We repeat this constantly, so we make it a component so we only have to define it once.
|
|
80
|
-
|
|
44
|
+
const createAPIErrorComponent = (openApi) => {
|
|
81
45
|
// Create a schema component called APIError
|
|
82
|
-
openApi
|
|
46
|
+
openApi?.component("schemas", "APIError", {
|
|
83
47
|
properties: {
|
|
84
48
|
code: {
|
|
85
49
|
description: "An application-specific error code, expressed as a string value.",
|
|
@@ -139,72 +103,73 @@ var createAPIErrorComponent = function (openApi) {
|
|
|
139
103
|
type: "object",
|
|
140
104
|
});
|
|
141
105
|
};
|
|
142
|
-
|
|
143
|
-
var _c, _d, _e, _f, _g;
|
|
106
|
+
const getOpenApiMiddleware = (model, options) => {
|
|
144
107
|
createAPIErrorComponent(options.openApi);
|
|
145
|
-
if (!
|
|
108
|
+
if (!options.openApi?.path) {
|
|
146
109
|
// Just log this once rather than for each middleware.
|
|
147
|
-
logger_1.logger.debug(
|
|
110
|
+
logger_1.logger.debug(`No options.openApi provided for model "${model.modelName}" in getOpenApiMiddleware, skipping *OpenApiMiddleware`);
|
|
148
111
|
return noop;
|
|
149
112
|
}
|
|
150
|
-
if (
|
|
113
|
+
if (options.permissions?.read?.length === 0) {
|
|
151
114
|
return noop;
|
|
152
115
|
}
|
|
153
|
-
|
|
116
|
+
const { properties, required } = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
154
117
|
extraModelProperties: options.openApiExtraModelProperties,
|
|
155
118
|
populatePaths: options.populatePaths,
|
|
156
|
-
})
|
|
119
|
+
});
|
|
157
120
|
return options.openApi.path((0, merge_1.default)({
|
|
158
|
-
responses:
|
|
121
|
+
responses: {
|
|
122
|
+
200: {
|
|
159
123
|
content: {
|
|
160
124
|
"application/json": {
|
|
161
125
|
schema: {
|
|
162
|
-
properties
|
|
163
|
-
required:
|
|
126
|
+
properties,
|
|
127
|
+
required: [...required, "_id", "created", "updated"],
|
|
164
128
|
type: "object",
|
|
165
129
|
},
|
|
166
130
|
},
|
|
167
131
|
},
|
|
168
132
|
description: "Successful read",
|
|
169
|
-
}
|
|
133
|
+
},
|
|
134
|
+
...exports.defaultOpenApiErrorResponses,
|
|
135
|
+
},
|
|
170
136
|
tags: [model.collection.collectionName],
|
|
171
|
-
},
|
|
137
|
+
}, options.openApiOverwrite?.get ?? {}));
|
|
172
138
|
};
|
|
173
139
|
exports.getOpenApiMiddleware = getOpenApiMiddleware;
|
|
174
|
-
|
|
140
|
+
const resolveSyncScopeLabel = (scope) => {
|
|
175
141
|
if (typeof scope === "function") {
|
|
176
142
|
return "custom";
|
|
177
143
|
}
|
|
178
144
|
return scope.type;
|
|
179
145
|
};
|
|
180
|
-
|
|
146
|
+
const buildTerrenoSyncExtension = (sync, routePath, fallbackCollection) => {
|
|
181
147
|
if (!sync) {
|
|
182
148
|
return {};
|
|
183
149
|
}
|
|
184
|
-
|
|
150
|
+
const rawPath = routePath ?? (fallbackCollection ? `/${fallbackCollection}` : undefined);
|
|
185
151
|
if (!rawPath) {
|
|
186
152
|
return {};
|
|
187
153
|
}
|
|
188
|
-
|
|
154
|
+
const collection = rawPath.replace(/^\//, "");
|
|
189
155
|
return {
|
|
190
156
|
"x-terreno-sync": {
|
|
191
|
-
collection
|
|
157
|
+
collection,
|
|
192
158
|
scope: resolveSyncScopeLabel(sync.scope),
|
|
193
159
|
},
|
|
194
160
|
};
|
|
195
161
|
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
162
|
+
const listOpenApiMiddleware = (model, options, routePath) => {
|
|
163
|
+
if (!options.openApi?.path) {
|
|
199
164
|
return noop;
|
|
200
165
|
}
|
|
201
|
-
if (
|
|
166
|
+
if (options.permissions?.list?.length === 0) {
|
|
202
167
|
return noop;
|
|
203
168
|
}
|
|
204
|
-
|
|
169
|
+
const modelSwagger = (0, mongoose_to_swagger_1.default)(model, m2sOptions);
|
|
205
170
|
// TODO: handle permissions
|
|
206
171
|
// Convert modelRouter queryFields into OpenAPI parameters
|
|
207
|
-
|
|
172
|
+
const defaultQueryParams = [
|
|
208
173
|
{
|
|
209
174
|
in: "query",
|
|
210
175
|
name: "_id",
|
|
@@ -221,12 +186,14 @@ var listOpenApiMiddleware = function (model, options, routePath) {
|
|
|
221
186
|
},
|
|
222
187
|
},
|
|
223
188
|
];
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
189
|
+
const modelQueryParams = (0, flatten_1.default)(options.queryFields
|
|
190
|
+
// Remove _id from queryFields, we handle that above.
|
|
191
|
+
?.filter((field) => field !== "_id")
|
|
192
|
+
.map((field) => {
|
|
193
|
+
const params = [];
|
|
227
194
|
// Check for datetime/number to support gt/gte/lt/lte
|
|
228
|
-
if (
|
|
229
|
-
|
|
195
|
+
if (modelSwagger.properties[field]?.type === "number" ||
|
|
196
|
+
modelSwagger.properties[field]?.format === "date-time") {
|
|
230
197
|
params.push({
|
|
231
198
|
in: "query",
|
|
232
199
|
name: field,
|
|
@@ -257,7 +224,7 @@ var listOpenApiMiddleware = function (model, options, routePath) {
|
|
|
257
224
|
properties: {
|
|
258
225
|
$in: {
|
|
259
226
|
items: {
|
|
260
|
-
type:
|
|
227
|
+
type: modelSwagger.properties[field]?.type,
|
|
261
228
|
},
|
|
262
229
|
type: "array",
|
|
263
230
|
},
|
|
@@ -270,11 +237,15 @@ var listOpenApiMiddleware = function (model, options, routePath) {
|
|
|
270
237
|
}
|
|
271
238
|
return params;
|
|
272
239
|
}));
|
|
273
|
-
|
|
240
|
+
const { properties, required } = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
274
241
|
extraModelProperties: options.openApiExtraModelProperties,
|
|
275
242
|
populatePaths: options.populatePaths,
|
|
276
|
-
})
|
|
277
|
-
return options.openApi.path((0, merge_1.default)(
|
|
243
|
+
});
|
|
244
|
+
return options.openApi.path((0, merge_1.default)({
|
|
245
|
+
...buildTerrenoSyncExtension(options.sync, routePath, model.collection.collectionName),
|
|
246
|
+
parameters: [
|
|
247
|
+
...defaultQueryParams,
|
|
248
|
+
...(modelQueryParams ?? []),
|
|
278
249
|
// pagination
|
|
279
250
|
{
|
|
280
251
|
in: "query",
|
|
@@ -297,15 +268,17 @@ var listOpenApiMiddleware = function (model, options, routePath) {
|
|
|
297
268
|
type: "number",
|
|
298
269
|
},
|
|
299
270
|
},
|
|
300
|
-
],
|
|
271
|
+
],
|
|
272
|
+
responses: {
|
|
273
|
+
200: {
|
|
301
274
|
content: {
|
|
302
275
|
"application/json": {
|
|
303
276
|
schema: {
|
|
304
277
|
properties: {
|
|
305
278
|
data: {
|
|
306
279
|
items: {
|
|
307
|
-
properties
|
|
308
|
-
required:
|
|
280
|
+
properties,
|
|
281
|
+
required: [...required, "_id", "created", "updated"],
|
|
309
282
|
type: "object",
|
|
310
283
|
},
|
|
311
284
|
type: "array",
|
|
@@ -328,133 +301,145 @@ var listOpenApiMiddleware = function (model, options, routePath) {
|
|
|
328
301
|
},
|
|
329
302
|
},
|
|
330
303
|
description: "Successful list",
|
|
331
|
-
}
|
|
304
|
+
},
|
|
305
|
+
...exports.defaultOpenApiErrorResponses,
|
|
306
|
+
},
|
|
307
|
+
tags: [model.collection.collectionName],
|
|
308
|
+
}, options.openApiOverwrite?.list ?? {}));
|
|
332
309
|
};
|
|
333
310
|
exports.listOpenApiMiddleware = listOpenApiMiddleware;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
311
|
+
const createOpenApiMiddleware = (model, options) => {
|
|
312
|
+
if (!options.openApi?.path) {
|
|
337
313
|
return noop;
|
|
338
314
|
}
|
|
339
|
-
if (
|
|
315
|
+
if (options.permissions?.create?.length === 0) {
|
|
340
316
|
return noop;
|
|
341
317
|
}
|
|
342
|
-
|
|
318
|
+
const { properties, required } = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
343
319
|
extraModelProperties: options.openApiExtraModelProperties,
|
|
344
320
|
populatePaths: options.populatePaths,
|
|
345
|
-
})
|
|
321
|
+
});
|
|
346
322
|
return options.openApi.path((0, merge_1.default)({
|
|
347
323
|
requestBody: {
|
|
348
324
|
content: {
|
|
349
325
|
"application/json": {
|
|
350
326
|
schema: {
|
|
351
|
-
properties
|
|
327
|
+
properties,
|
|
352
328
|
type: "object",
|
|
353
329
|
},
|
|
354
330
|
},
|
|
355
331
|
},
|
|
356
332
|
required: true,
|
|
357
333
|
},
|
|
358
|
-
responses:
|
|
334
|
+
responses: {
|
|
335
|
+
201: {
|
|
359
336
|
content: {
|
|
360
337
|
"application/json": {
|
|
361
338
|
schema: {
|
|
362
|
-
properties
|
|
363
|
-
required:
|
|
339
|
+
properties,
|
|
340
|
+
required: [...required, "_id", "created", "updated"],
|
|
364
341
|
type: "object",
|
|
365
342
|
},
|
|
366
343
|
},
|
|
367
344
|
},
|
|
368
345
|
description: "Successful create",
|
|
369
|
-
}
|
|
346
|
+
},
|
|
347
|
+
...exports.defaultOpenApiErrorResponses,
|
|
348
|
+
},
|
|
370
349
|
tags: [model.collection.collectionName],
|
|
371
|
-
},
|
|
350
|
+
}, options.openApiOverwrite?.create ?? {}));
|
|
372
351
|
};
|
|
373
352
|
exports.createOpenApiMiddleware = createOpenApiMiddleware;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
353
|
+
const patchOpenApiMiddleware = (model, options) => {
|
|
354
|
+
if (!options.openApi?.path) {
|
|
377
355
|
return noop;
|
|
378
356
|
}
|
|
379
|
-
if (
|
|
357
|
+
if (options.permissions?.update?.length === 0) {
|
|
380
358
|
return noop;
|
|
381
359
|
}
|
|
382
|
-
|
|
360
|
+
const { properties, required } = (0, populate_1.getOpenApiSpecForModel)(model, {
|
|
383
361
|
extraModelProperties: options.openApiExtraModelProperties,
|
|
384
362
|
populatePaths: options.populatePaths,
|
|
385
|
-
})
|
|
363
|
+
});
|
|
386
364
|
return options.openApi.path((0, merge_1.default)({
|
|
387
365
|
requestBody: {
|
|
388
366
|
content: {
|
|
389
367
|
"application/json": {
|
|
390
368
|
schema: {
|
|
391
|
-
properties
|
|
369
|
+
properties,
|
|
392
370
|
type: "object",
|
|
393
371
|
},
|
|
394
372
|
},
|
|
395
373
|
},
|
|
396
374
|
required: true,
|
|
397
375
|
},
|
|
398
|
-
responses:
|
|
376
|
+
responses: {
|
|
377
|
+
200: {
|
|
399
378
|
content: {
|
|
400
379
|
"application/json": {
|
|
401
380
|
schema: {
|
|
402
|
-
properties
|
|
403
|
-
required:
|
|
381
|
+
properties,
|
|
382
|
+
required: [...required, "_id", "created", "updated"],
|
|
404
383
|
type: "object",
|
|
405
384
|
},
|
|
406
385
|
},
|
|
407
386
|
},
|
|
408
387
|
description: "Successful update",
|
|
409
|
-
}
|
|
388
|
+
},
|
|
389
|
+
...exports.defaultOpenApiErrorResponses,
|
|
390
|
+
},
|
|
410
391
|
tags: [model.collection.collectionName],
|
|
411
|
-
},
|
|
392
|
+
}, options.openApiOverwrite?.update ?? {}));
|
|
412
393
|
};
|
|
413
394
|
exports.patchOpenApiMiddleware = patchOpenApiMiddleware;
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
395
|
+
const deleteOpenApiMiddleware = (model, options) => {
|
|
396
|
+
if (!options.openApi?.path) {
|
|
417
397
|
return noop;
|
|
418
398
|
}
|
|
419
|
-
if (
|
|
399
|
+
if (options.permissions?.delete?.length === 0) {
|
|
420
400
|
return noop;
|
|
421
401
|
}
|
|
422
402
|
return options.openApi.path((0, merge_1.default)({
|
|
423
|
-
responses:
|
|
403
|
+
responses: {
|
|
404
|
+
204: {
|
|
424
405
|
description: "Successful delete",
|
|
425
|
-
}
|
|
406
|
+
},
|
|
407
|
+
...exports.defaultOpenApiErrorResponses,
|
|
408
|
+
},
|
|
426
409
|
tags: [model.collection.collectionName],
|
|
427
|
-
},
|
|
410
|
+
}, options.openApiOverwrite?.delete ?? {}));
|
|
428
411
|
};
|
|
429
412
|
exports.deleteOpenApiMiddleware = deleteOpenApiMiddleware;
|
|
430
413
|
// This is a generic OpenAPI wrapper for a read that returns any object described by `properties`.
|
|
431
414
|
// Useful for endpoints that don't directly map to a model.
|
|
432
415
|
/** @internal */
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (!((_c = options.openApi) === null || _c === void 0 ? void 0 : _c.path)) {
|
|
416
|
+
const readOpenApiMiddleware = (options, properties, required, queryParameters) => {
|
|
417
|
+
if (!options.openApi?.path) {
|
|
436
418
|
// Just log this once rather than for each middleware.
|
|
437
419
|
logger_1.logger.debug("No options.openApi provided in readOpenApiMiddleware, skipping *OpenApiMiddleware");
|
|
438
420
|
return noop;
|
|
439
421
|
}
|
|
440
|
-
if (
|
|
422
|
+
if (options.permissions?.read?.length === 0) {
|
|
441
423
|
return noop;
|
|
442
424
|
}
|
|
443
425
|
return options.openApi.path((0, merge_1.default)({
|
|
444
426
|
parameters: queryParameters,
|
|
445
|
-
responses:
|
|
427
|
+
responses: {
|
|
428
|
+
200: {
|
|
446
429
|
content: {
|
|
447
430
|
"application/json": {
|
|
448
431
|
schema: {
|
|
449
|
-
properties
|
|
450
|
-
required
|
|
432
|
+
properties,
|
|
433
|
+
required,
|
|
451
434
|
type: "object",
|
|
452
435
|
},
|
|
453
436
|
},
|
|
454
437
|
},
|
|
455
438
|
description: "Successful read",
|
|
456
|
-
}
|
|
439
|
+
},
|
|
440
|
+
...exports.defaultOpenApiErrorResponses,
|
|
441
|
+
},
|
|
457
442
|
tags: [],
|
|
458
|
-
},
|
|
443
|
+
}, options.openApiOverwrite?.get ?? {}));
|
|
459
444
|
};
|
|
460
445
|
exports.readOpenApiMiddleware = readOpenApiMiddleware;
|