@terreno/api 57.4.0 → 57.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/bunfig.toml +1 -1
- package/dist/actions.js +197 -368
- package/dist/adminModelRouter.js +88 -173
- package/dist/api.js +598 -852
- package/dist/audit/auditApp.js +48 -89
- package/dist/audit/auditEventModel.js +15 -16
- package/dist/audit/cloudTasksEnqueue.js +56 -149
- package/dist/audit/diff.js +70 -160
- package/dist/audit/processQueue.js +25 -70
- package/dist/audit/rbacSink.js +25 -66
- package/dist/audit/record.js +129 -251
- package/dist/auth.js +432 -681
- package/dist/authRecovery.js +155 -269
- package/dist/authTokens.js +43 -118
- package/dist/betterAuthApp.js +25 -26
- package/dist/betterAuthSetup.js +258 -413
- package/dist/browserLogsRoute.d.ts +6 -0
- package/dist/browserLogsRoute.js +97 -0
- package/dist/collectionRegistry.js +32 -47
- package/dist/config.js +53 -122
- package/dist/configurationApp.js +180 -361
- package/dist/configurationPlugin.js +130 -302
- package/dist/consentApp.js +276 -421
- package/dist/docLoader.js +78 -126
- package/dist/envConfigurationPlugin.js +25 -147
- package/dist/errors.js +151 -247
- package/dist/example.js +28 -34
- package/dist/expressServer.d.ts +10 -0
- package/dist/expressServer.js +109 -255
- package/dist/frameworkModelNames.d.ts +24 -0
- package/dist/frameworkModelNames.js +31 -0
- package/dist/githubAuth.js +152 -216
- package/dist/httpClient.js +176 -264
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -2
- package/dist/logger.js +145 -278
- package/dist/mcp/auth.js +76 -128
- package/dist/mcp/createMCPRequest.js +4 -5
- package/dist/mcp/handlers.js +268 -480
- package/dist/mcp/query.js +56 -150
- package/dist/mcp/registry.js +17 -30
- package/dist/mcp/schemaGenerator.js +95 -181
- package/dist/mcp/server.js +28 -100
- package/dist/mcp/serviceTokens.js +102 -191
- package/dist/mcp/toolGenerator.js +78 -191
- package/dist/middleware.js +15 -27
- package/dist/migrations/fixtures/all-down/20260910120000-one.js +2 -42
- package/dist/migrations/fixtures/all-down/20260910120001-two.js +2 -42
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +1 -39
- package/dist/migrations/fixtures/bad-name/not-a-migration.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120000-alpha.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120001-beta.js +2 -42
- package/dist/migrations/generate.js +107 -229
- package/dist/migrations/load.js +75 -201
- package/dist/migrations/lock.js +54 -126
- package/dist/migrations/runner.js +192 -446
- package/dist/migrations/schemaCatalog.js +122 -263
- package/dist/models/consentForm.js +6 -6
- package/dist/models/consentResponse.js +5 -5
- package/dist/models/mcpServiceToken.js +66 -156
- package/dist/models/notification.js +6 -6
- package/dist/models/notificationPreference.js +6 -6
- package/dist/models/versionConfig.js +5 -5
- package/dist/notifications/notificationService.js +133 -273
- package/dist/notifications/notificationsApp.js +85 -179
- package/dist/notifications/notificationsBeforeSend.js +19 -64
- package/dist/notifiers/googleChatNotifier.js +36 -117
- package/dist/notifiers/slackNotifier.d.ts +31 -2
- package/dist/notifiers/slackNotifier.js +170 -119
- package/dist/notifiers/zoomNotifier.js +60 -111
- package/dist/openApi.js +107 -122
- package/dist/openApiBuilder.js +117 -159
- package/dist/openApiCompat.js +81 -148
- package/dist/openApiEtag.js +7 -7
- package/dist/openApiValidator.js +177 -286
- package/dist/orgs/orgContext.js +87 -157
- package/dist/orgs/orgPermissions.js +29 -68
- package/dist/orgs/orgPlugin.js +9 -27
- package/dist/orgs/organizationModel.js +65 -166
- package/dist/orgs/organizationSettings.js +29 -36
- package/dist/orgs/orgsApp.js +346 -608
- package/dist/permissions.js +88 -181
- package/dist/plugins.js +125 -218
- package/dist/populate.js +130 -240
- package/dist/rateLimit/applyTrustProxy.js +1 -1
- package/dist/rateLimit/createStore.js +7 -8
- package/dist/rateLimit/memoryStore.js +22 -100
- package/dist/rateLimit/middleware.js +48 -99
- package/dist/rateLimit/mongoStore.js +54 -112
- package/dist/rateLimit/policies.js +41 -75
- package/dist/rateLimit/redisStore.js +39 -133
- package/dist/rbac/access.js +119 -267
- package/dist/rbac/assertAllowed.js +95 -171
- package/dist/rbac/auditModel.js +14 -58
- package/dist/rbac/backfillAdmins.js +24 -130
- package/dist/rbac/fieldViews.js +46 -141
- package/dist/rbac/membershipOrgAdminSource.js +28 -99
- package/dist/rbac/middleware.js +30 -96
- package/dist/rbac/modelRouterAccess.js +130 -307
- package/dist/rbac/permissionUtils.js +40 -179
- package/dist/rbac/realtimeAccess.js +81 -147
- package/dist/rbac/resolve.d.ts +1 -1
- package/dist/rbac/resolve.js +148 -342
- package/dist/rbac/roleManager.js +318 -700
- package/dist/rbac/roleModel.js +44 -171
- package/dist/rbac/routes.js +93 -196
- package/dist/rbac/scopes.js +39 -133
- package/dist/rbac/statements.js +23 -91
- package/dist/rbac/userPlugin.js +3 -29
- package/dist/realtime/changeStreamWatcher.js +489 -800
- package/dist/realtime/deprecation.js +8 -10
- package/dist/realtime/queryMatcher.js +110 -191
- package/dist/realtime/queryStore.js +35 -118
- package/dist/realtime/realtimeApp.js +247 -401
- package/dist/realtime/registry.js +19 -30
- package/dist/realtime/sessionRevalidation.js +132 -358
- package/dist/realtime/socketAuth.js +89 -208
- package/dist/realtime/socketUser.js +10 -56
- package/dist/requestContext.js +93 -139
- package/dist/schemaMetadata.js +179 -274
- package/dist/scriptRunner.js +96 -266
- package/dist/scrubAdminFields.js +36 -108
- package/dist/secretProviders.js +130 -299
- package/dist/seedRunner.js +221 -514
- package/dist/sync/adminBroadcastScope.js +58 -170
- package/dist/sync/adminWindowAccess.js +15 -86
- package/dist/sync/adminWindowMutation.js +110 -181
- package/dist/sync/executors.js +425 -629
- package/dist/sync/loadHarness.js +392 -689
- package/dist/sync/models.js +181 -341
- package/dist/sync/mutationHandler.js +533 -801
- package/dist/sync/registrationSideEffects.js +41 -95
- package/dist/sync/registry.js +29 -49
- package/dist/sync/routes.js +484 -817
- package/dist/sync/scripts/compactTombstones.js +83 -228
- package/dist/sync/serialize.js +18 -58
- package/dist/sync/socketHandlers.js +253 -478
- package/dist/sync/streams.js +49 -117
- package/dist/sync/syncApp.js +12 -15
- package/dist/sync/syncBatch.js +63 -168
- package/dist/sync/syncSeqPlugin.js +430 -702
- package/dist/syncConsents.js +113 -253
- package/dist/terrenoApp.js +166 -276
- package/dist/tests/createTestData.js +146 -256
- package/dist/tests/models.js +14 -54
- package/dist/tests/mongoTestSetup.js +42 -103
- package/dist/tests/testHelper.js +31 -93
- package/dist/tests.js +12 -51
- package/dist/transformers.js +61 -164
- package/dist/utils.js +31 -93
- package/dist/vendor/wesleytodd-openapi/index.js +37 -51
- package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +32 -40
- package/dist/vendor/wesleytodd-openapi/lib/layer-schema.js +3 -3
- package/dist/vendor/wesleytodd-openapi/lib/ui.js +50 -19
- package/dist/vendor/wesleytodd-openapi/lib/validate.js +19 -47
- package/dist/versionCheckPlugin.js +52 -100
- package/dist/webhooks/headerValue.js +2 -2
- package/dist/webhooks/idempotency/memoryStore.js +16 -59
- package/dist/webhooks/idempotency/mongoStore.js +55 -130
- package/dist/webhooks/idempotency/webhookReceipt.js +9 -9
- package/dist/webhooks/rawBody.js +1 -1
- package/dist/webhooks/timingSafeEqual.js +4 -5
- package/dist/webhooks/verifiers/hmac.js +17 -18
- package/dist/webhooks/verifiers/sendgrid.js +20 -22
- package/dist/webhooks/verifiers/stripe.js +31 -65
- package/dist/webhooks/verifiers/twilio.js +23 -73
- package/dist/webhooks/webhooksApp.js +78 -177
- package/dist/zodOpenApi.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/browserLogsRoute.test.ts +165 -0
- package/src/audit/auditApp.test.ts +5 -5
- package/src/audit/auditEventModel.ts +7 -3
- package/src/audit/auditRouter.test.ts +5 -5
- package/src/audit/rbacSink.test.ts +2 -2
- package/src/audit/record.test.ts +2 -2
- package/src/audit/record.ts +3 -2
- package/src/auth.ts +1 -1
- package/src/authRecovery.test.ts +43 -0
- package/src/authRecovery.ts +16 -10
- package/src/authTokens.ts +6 -2
- package/src/authVerification.test.ts +22 -0
- package/src/browserLogsRoute.ts +110 -0
- package/src/configurationPlugin.test.ts +1 -11
- package/src/expressServer.ts +10 -0
- package/src/frameworkModelNames.test.ts +62 -0
- package/src/frameworkModelNames.ts +33 -0
- package/src/index.ts +7 -0
- package/src/isolated/migrateCliConnect.isolated.ts +51 -0
- package/src/mcp/auth.test.ts +34 -1
- package/src/migrations/cli.test.ts +0 -23
- package/src/models/mcpServiceToken.ts +4 -3
- package/src/models/notification.ts +3 -2
- package/src/models/notificationPreference.ts +1 -1
- package/src/notifications/notificationsApp.test.ts +24 -1
- package/src/notifiers/slackNotifier.test.ts +186 -1
- package/src/notifiers/slackNotifier.ts +167 -8
- package/src/orgs/orgPlugin.ts +1 -1
- package/src/orgs/organizationModel.ts +11 -6
- package/src/plugins.test.ts +5 -0
- package/src/plugins.ts +3 -0
- package/src/realtime/realtimeApp.ts +1 -1
- package/src/sync/integration.test.ts +2 -2
- package/src/terrenoApp.ts +3 -0
- package/src/types.d.ts +1 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
- package/tsconfig.json +13 -54
- package/tsconfig.typedoc.json +2 -0
package/dist/openApiBuilder.js
CHANGED
|
@@ -1,52 +1,14 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
14
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
|
-
if (m) return m.call(o);
|
|
16
|
-
if (o && typeof o.length === "number") return {
|
|
17
|
-
next: function () {
|
|
18
|
-
if (o && i >= o.length) o = void 0;
|
|
19
|
-
return { value: o && o[i++], done: !o };
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
23
|
-
};
|
|
24
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
-
if (!m) return o;
|
|
27
|
-
var i = m.call(o), r, ar = [], e;
|
|
28
|
-
try {
|
|
29
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
-
}
|
|
31
|
-
catch (error) { e = { error: error }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
-
}
|
|
36
|
-
finally { if (e) throw e.error; }
|
|
37
|
-
}
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
4
|
};
|
|
43
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
6
|
exports.createOpenApiBuilder = exports.OpenApiMiddlewareBuilder = void 0;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
7
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
const openApi_1 = require("./openApi");
|
|
10
|
+
const openApiValidator_1 = require("./openApiValidator");
|
|
11
|
+
const layer_schema_1 = require("./vendor/wesleytodd-openapi/lib/layer-schema");
|
|
50
12
|
/**
|
|
51
13
|
* Run handlers in order as one Express middleware function.
|
|
52
14
|
*
|
|
@@ -54,15 +16,14 @@ var layer_schema_1 = require("./vendor/wesleytodd-openapi/lib/layer-schema");
|
|
|
54
16
|
* Express registers. Copying the schema from the documentation handler onto
|
|
55
17
|
* the composed function keeps `/openapi.json` generation working.
|
|
56
18
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var run = function (index) {
|
|
19
|
+
const composeRequestHandlers = (handlers) => {
|
|
20
|
+
const composed = (req, res, next) => {
|
|
21
|
+
const run = (index) => {
|
|
61
22
|
if (index >= handlers.length) {
|
|
62
23
|
next();
|
|
63
24
|
return;
|
|
64
25
|
}
|
|
65
|
-
handlers[index](req, res,
|
|
26
|
+
handlers[index](req, res, (error) => {
|
|
66
27
|
if (error) {
|
|
67
28
|
next(error);
|
|
68
29
|
return;
|
|
@@ -72,23 +33,13 @@ var composeRequestHandlers = function (handlers) {
|
|
|
72
33
|
};
|
|
73
34
|
run(0);
|
|
74
35
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
(0, layer_schema_1.set)(composed, schema);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
36
|
+
for (const handler of handlers) {
|
|
37
|
+
const schema = (0, layer_schema_1.get)(handler);
|
|
38
|
+
if (schema) {
|
|
39
|
+
(0, layer_schema_1.set)(composed, schema);
|
|
40
|
+
break;
|
|
83
41
|
}
|
|
84
42
|
}
|
|
85
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
-
finally {
|
|
87
|
-
try {
|
|
88
|
-
if (handlers_1_1 && !handlers_1_1.done && (_c = handlers_1.return)) _c.call(handlers_1);
|
|
89
|
-
}
|
|
90
|
-
finally { if (e_1) throw e_1.error; }
|
|
91
|
-
}
|
|
92
43
|
return composed;
|
|
93
44
|
};
|
|
94
45
|
/**
|
|
@@ -117,32 +68,39 @@ var composeRequestHandlers = function (handlers) {
|
|
|
117
68
|
* .build();
|
|
118
69
|
* ```
|
|
119
70
|
*/
|
|
120
|
-
|
|
71
|
+
class OpenApiMiddlewareBuilder {
|
|
72
|
+
/** Router options containing OpenAPI configuration */
|
|
73
|
+
options;
|
|
74
|
+
/** Accumulated OpenAPI configuration from builder methods */
|
|
75
|
+
config;
|
|
76
|
+
/** Validation configuration */
|
|
77
|
+
validationConfig;
|
|
78
|
+
/** Store the raw request body schema for validation */
|
|
79
|
+
requestBodySchema;
|
|
80
|
+
/** Store the raw query parameter schemas for validation */
|
|
81
|
+
queryParamSchemas = {};
|
|
121
82
|
/**
|
|
122
83
|
* Creates a new OpenApiMiddlewareBuilder instance.
|
|
123
84
|
*
|
|
124
85
|
* @param options - Router options containing the OpenAPI path configuration
|
|
125
86
|
*/
|
|
126
|
-
|
|
127
|
-
/** Store the raw query parameter schemas for validation */
|
|
128
|
-
this.queryParamSchemas = {};
|
|
87
|
+
constructor(options) {
|
|
129
88
|
this.options = options;
|
|
130
89
|
this.config = {
|
|
131
90
|
responses: {},
|
|
132
91
|
};
|
|
133
92
|
this.validationConfig = {};
|
|
134
93
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
var parts = [];
|
|
94
|
+
describeRoute() {
|
|
95
|
+
const parts = [];
|
|
138
96
|
if (this.config.summary) {
|
|
139
|
-
parts.push("
|
|
97
|
+
parts.push(`"${this.config.summary}"`);
|
|
140
98
|
}
|
|
141
|
-
if (
|
|
142
|
-
parts.push(
|
|
99
|
+
if (this.config.tags?.length) {
|
|
100
|
+
parts.push(`tags=[${this.config.tags.join(", ")}]`);
|
|
143
101
|
}
|
|
144
102
|
return parts.length > 0 ? parts.join(" ") : "unnamed route";
|
|
145
|
-
}
|
|
103
|
+
}
|
|
146
104
|
/**
|
|
147
105
|
* Sets the tags for the OpenAPI operation.
|
|
148
106
|
*
|
|
@@ -156,10 +114,10 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
156
114
|
* builder.withTags(["users", "authentication"]);
|
|
157
115
|
* ```
|
|
158
116
|
*/
|
|
159
|
-
|
|
117
|
+
withTags(tags) {
|
|
160
118
|
this.config.tags = tags;
|
|
161
119
|
return this;
|
|
162
|
-
}
|
|
120
|
+
}
|
|
163
121
|
/**
|
|
164
122
|
* Sets the summary for the OpenAPI operation.
|
|
165
123
|
*
|
|
@@ -173,10 +131,10 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
173
131
|
* builder.withSummary("Get user by ID");
|
|
174
132
|
* ```
|
|
175
133
|
*/
|
|
176
|
-
|
|
134
|
+
withSummary(summary) {
|
|
177
135
|
this.config.summary = summary;
|
|
178
136
|
return this;
|
|
179
|
-
}
|
|
137
|
+
}
|
|
180
138
|
/**
|
|
181
139
|
* Sets an explicit `operationId` for the OpenAPI operation.
|
|
182
140
|
*
|
|
@@ -194,10 +152,10 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
194
152
|
* builder.withOperationId("getUserStats");
|
|
195
153
|
* ```
|
|
196
154
|
*/
|
|
197
|
-
|
|
155
|
+
withOperationId(operationId) {
|
|
198
156
|
this.config.operationId = operationId;
|
|
199
157
|
return this;
|
|
200
|
-
}
|
|
158
|
+
}
|
|
201
159
|
/**
|
|
202
160
|
* Sets the description for the OpenAPI operation.
|
|
203
161
|
*
|
|
@@ -212,10 +170,10 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
212
170
|
* builder.withDescription("Retrieves a user by their unique identifier. Returns 404 if not found.");
|
|
213
171
|
* ```
|
|
214
172
|
*/
|
|
215
|
-
|
|
173
|
+
withDescription(description) {
|
|
216
174
|
this.config.description = description;
|
|
217
175
|
return this;
|
|
218
|
-
}
|
|
176
|
+
}
|
|
219
177
|
/**
|
|
220
178
|
* Sets the request body schema for the OpenAPI operation.
|
|
221
179
|
*
|
|
@@ -237,34 +195,26 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
237
195
|
* });
|
|
238
196
|
* ```
|
|
239
197
|
*/
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
.filter(function (_c) {
|
|
245
|
-
var _d = __read(_c, 2), _ = _d[0], prop = _d[1];
|
|
246
|
-
return prop.required;
|
|
247
|
-
})
|
|
248
|
-
.map(function (_c) {
|
|
249
|
-
var _d = __read(_c, 2), key = _d[0], _ = _d[1];
|
|
250
|
-
return key;
|
|
251
|
-
});
|
|
198
|
+
withRequestBody(schema, options) {
|
|
199
|
+
const required = Object.entries(schema)
|
|
200
|
+
.filter(([_, prop]) => prop.required)
|
|
201
|
+
.map(([key, _]) => key);
|
|
252
202
|
this.config.requestBody = {
|
|
253
|
-
content:
|
|
254
|
-
|
|
203
|
+
content: {
|
|
204
|
+
[options?.mediaType ?? "application/json"]: {
|
|
255
205
|
schema: {
|
|
256
206
|
properties: schema,
|
|
257
207
|
required: required.length > 0 ? required : undefined,
|
|
258
208
|
type: "object",
|
|
259
209
|
},
|
|
260
210
|
},
|
|
261
|
-
|
|
262
|
-
required:
|
|
211
|
+
},
|
|
212
|
+
required: options?.required ?? true,
|
|
263
213
|
};
|
|
264
214
|
// Store the schema for validation
|
|
265
215
|
this.requestBodySchema = schema;
|
|
266
216
|
return this;
|
|
267
|
-
}
|
|
217
|
+
}
|
|
268
218
|
/**
|
|
269
219
|
* Adds a response definition to the OpenAPI operation.
|
|
270
220
|
*
|
|
@@ -290,9 +240,7 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
290
240
|
* builder.withResponse(204, "No content");
|
|
291
241
|
* ```
|
|
292
242
|
*/
|
|
293
|
-
|
|
294
|
-
var _c;
|
|
295
|
-
var _d, _e;
|
|
243
|
+
withResponse(statusCode, schema, options) {
|
|
296
244
|
if (typeof schema === "string") {
|
|
297
245
|
this.config.responses[statusCode] = {
|
|
298
246
|
description: schema,
|
|
@@ -300,19 +248,19 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
300
248
|
}
|
|
301
249
|
else {
|
|
302
250
|
this.config.responses[statusCode] = {
|
|
303
|
-
content:
|
|
304
|
-
|
|
251
|
+
content: {
|
|
252
|
+
[options?.mediaType ?? "application/json"]: {
|
|
305
253
|
schema: {
|
|
306
254
|
properties: schema,
|
|
307
255
|
type: "object",
|
|
308
256
|
},
|
|
309
257
|
},
|
|
310
|
-
|
|
311
|
-
description:
|
|
258
|
+
},
|
|
259
|
+
description: options?.description ?? "Success",
|
|
312
260
|
};
|
|
313
261
|
}
|
|
314
262
|
return this;
|
|
315
|
-
}
|
|
263
|
+
}
|
|
316
264
|
/**
|
|
317
265
|
* Adds an array response definition to the OpenAPI operation.
|
|
318
266
|
*
|
|
@@ -335,12 +283,10 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
335
283
|
* }, {description: "List of users"});
|
|
336
284
|
* ```
|
|
337
285
|
*/
|
|
338
|
-
|
|
339
|
-
var _c;
|
|
340
|
-
var _d, _e;
|
|
286
|
+
withArrayResponse(statusCode, itemSchema, options) {
|
|
341
287
|
this.config.responses[statusCode] = {
|
|
342
|
-
content:
|
|
343
|
-
|
|
288
|
+
content: {
|
|
289
|
+
[options?.mediaType ?? "application/json"]: {
|
|
344
290
|
schema: {
|
|
345
291
|
items: {
|
|
346
292
|
properties: itemSchema,
|
|
@@ -349,11 +295,11 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
349
295
|
type: "array",
|
|
350
296
|
},
|
|
351
297
|
},
|
|
352
|
-
|
|
353
|
-
description:
|
|
298
|
+
},
|
|
299
|
+
description: options?.description ?? "Success",
|
|
354
300
|
};
|
|
355
301
|
return this;
|
|
356
|
-
}
|
|
302
|
+
}
|
|
357
303
|
/**
|
|
358
304
|
* Adds a query parameter to the OpenAPI operation.
|
|
359
305
|
*
|
|
@@ -374,22 +320,24 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
374
320
|
* });
|
|
375
321
|
* ```
|
|
376
322
|
*/
|
|
377
|
-
|
|
378
|
-
var _c;
|
|
323
|
+
withQueryParameter(name, schema, options) {
|
|
379
324
|
if (!this.config.parameters) {
|
|
380
325
|
this.config.parameters = [];
|
|
381
326
|
}
|
|
382
327
|
this.config.parameters.push({
|
|
383
|
-
description: options
|
|
328
|
+
description: options?.description,
|
|
384
329
|
in: "query",
|
|
385
|
-
name
|
|
386
|
-
required:
|
|
387
|
-
schema
|
|
330
|
+
name,
|
|
331
|
+
required: options?.required ?? false,
|
|
332
|
+
schema,
|
|
388
333
|
});
|
|
389
334
|
// Store for validation
|
|
390
|
-
this.queryParamSchemas[name] =
|
|
335
|
+
this.queryParamSchemas[name] = {
|
|
336
|
+
...schema,
|
|
337
|
+
required: options?.required,
|
|
338
|
+
};
|
|
391
339
|
return this;
|
|
392
|
-
}
|
|
340
|
+
}
|
|
393
341
|
/**
|
|
394
342
|
* Adds a path parameter to the OpenAPI operation.
|
|
395
343
|
*
|
|
@@ -409,19 +357,19 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
409
357
|
* });
|
|
410
358
|
* ```
|
|
411
359
|
*/
|
|
412
|
-
|
|
360
|
+
withPathParameter(name, schema, options) {
|
|
413
361
|
if (!this.config.parameters) {
|
|
414
362
|
this.config.parameters = [];
|
|
415
363
|
}
|
|
416
364
|
this.config.parameters.push({
|
|
417
|
-
description: options
|
|
365
|
+
description: options?.description,
|
|
418
366
|
in: "path",
|
|
419
|
-
name
|
|
367
|
+
name,
|
|
420
368
|
required: true,
|
|
421
|
-
schema
|
|
369
|
+
schema,
|
|
422
370
|
});
|
|
423
371
|
return this;
|
|
424
|
-
}
|
|
372
|
+
}
|
|
425
373
|
/**
|
|
426
374
|
* Enables runtime validation for this route.
|
|
427
375
|
*
|
|
@@ -442,15 +390,14 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
442
390
|
* .build();
|
|
443
391
|
* ```
|
|
444
392
|
*/
|
|
445
|
-
|
|
446
|
-
var _c, _d, _e;
|
|
393
|
+
withValidation(options) {
|
|
447
394
|
this.validationConfig = {
|
|
448
|
-
enabled:
|
|
449
|
-
validateBody:
|
|
450
|
-
validateQuery:
|
|
395
|
+
enabled: options?.enabled ?? true,
|
|
396
|
+
validateBody: options?.body ?? true,
|
|
397
|
+
validateQuery: options?.query ?? true,
|
|
451
398
|
};
|
|
452
399
|
return this;
|
|
453
|
-
}
|
|
400
|
+
}
|
|
454
401
|
/**
|
|
455
402
|
* Builds and returns the OpenAPI middleware along with schemas.
|
|
456
403
|
*
|
|
@@ -470,26 +417,32 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
470
417
|
* }, {bodySchema, validate: true}));
|
|
471
418
|
* ```
|
|
472
419
|
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
var noop = function (_a, _b, next) { return next(); };
|
|
420
|
+
buildWithSchemas() {
|
|
421
|
+
const noop = (_a, _b, next) => next();
|
|
476
422
|
// Build the OpenAPI documentation middleware only (no validation middleware)
|
|
477
|
-
|
|
478
|
-
if (
|
|
479
|
-
openApiMiddleware = this.options.openApi.path((0, merge_1.default)(
|
|
423
|
+
let openApiMiddleware = noop;
|
|
424
|
+
if (this.options.openApi?.path) {
|
|
425
|
+
openApiMiddleware = this.options.openApi.path((0, merge_1.default)({
|
|
426
|
+
...this.config,
|
|
427
|
+
responses: {
|
|
428
|
+
...this.config.responses,
|
|
429
|
+
...openApi_1.defaultOpenApiErrorResponses,
|
|
430
|
+
},
|
|
431
|
+
}, this.options.openApiOverwrite?.get ?? {}));
|
|
480
432
|
}
|
|
481
433
|
else {
|
|
482
|
-
logger_1.logger.debug(
|
|
434
|
+
logger_1.logger.debug(`No options.openApi provided in buildWithSchemas for ${this.describeRoute()}, skipping OpenApiMiddleware`);
|
|
483
435
|
}
|
|
484
|
-
|
|
485
|
-
|
|
436
|
+
const globalConfig = (0, openApiValidator_1.getOpenApiValidatorConfig)();
|
|
437
|
+
const validationEnabled = this.validationConfig.enabled ??
|
|
438
|
+
((0, openApiValidator_1.isOpenApiValidatorConfigured)() && (globalConfig.validateRequests ?? false));
|
|
486
439
|
return {
|
|
487
440
|
bodySchema: this.requestBodySchema,
|
|
488
441
|
middleware: openApiMiddleware,
|
|
489
442
|
querySchema: Object.keys(this.queryParamSchemas).length > 0 ? this.queryParamSchemas : undefined,
|
|
490
|
-
validationEnabled
|
|
443
|
+
validationEnabled,
|
|
491
444
|
};
|
|
492
|
-
}
|
|
445
|
+
}
|
|
493
446
|
/**
|
|
494
447
|
* Builds and returns the OpenAPI middleware.
|
|
495
448
|
*
|
|
@@ -516,25 +469,31 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
516
469
|
* router.get("/users/:id", middleware, getUserHandler);
|
|
517
470
|
* ```
|
|
518
471
|
*/
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
var noop = function (_a, _b, next) { return next(); };
|
|
472
|
+
build() {
|
|
473
|
+
const noop = (_a, _b, next) => next();
|
|
522
474
|
// Build the OpenAPI documentation middleware
|
|
523
|
-
|
|
524
|
-
if (
|
|
525
|
-
openApiMiddleware = this.options.openApi.path((0, merge_1.default)(
|
|
475
|
+
let openApiMiddleware = noop;
|
|
476
|
+
if (this.options.openApi?.path) {
|
|
477
|
+
openApiMiddleware = this.options.openApi.path((0, merge_1.default)({
|
|
478
|
+
...this.config,
|
|
479
|
+
responses: {
|
|
480
|
+
...this.config.responses,
|
|
481
|
+
...openApi_1.defaultOpenApiErrorResponses,
|
|
482
|
+
},
|
|
483
|
+
}, this.options.openApiOverwrite?.get ?? {}));
|
|
526
484
|
}
|
|
527
485
|
else {
|
|
528
|
-
logger_1.logger.debug(
|
|
486
|
+
logger_1.logger.debug(`No options.openApi provided in build for ${this.describeRoute()}, skipping OpenApiMiddleware`);
|
|
529
487
|
}
|
|
530
488
|
// Check if validation should be enabled
|
|
531
|
-
|
|
532
|
-
|
|
489
|
+
const globalConfig = (0, openApiValidator_1.getOpenApiValidatorConfig)();
|
|
490
|
+
const shouldValidate = this.validationConfig.enabled ??
|
|
491
|
+
((0, openApiValidator_1.isOpenApiValidatorConfigured)() && (globalConfig.validateRequests ?? false));
|
|
533
492
|
if (!shouldValidate) {
|
|
534
493
|
return openApiMiddleware;
|
|
535
494
|
}
|
|
536
495
|
// Build validation middleware
|
|
537
|
-
|
|
496
|
+
const validators = [openApiMiddleware];
|
|
538
497
|
// Add body validation if we have a request body schema
|
|
539
498
|
if (this.validationConfig.validateBody && this.requestBodySchema) {
|
|
540
499
|
validators.push((0, openApiValidator_1.validateRequestBody)(this.requestBodySchema, { enabled: true }));
|
|
@@ -547,9 +506,8 @@ var OpenApiMiddlewareBuilder = /** @class */ (function () {
|
|
|
547
506
|
return openApiMiddleware;
|
|
548
507
|
}
|
|
549
508
|
return composeRequestHandlers(validators);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
}());
|
|
509
|
+
}
|
|
510
|
+
}
|
|
553
511
|
exports.OpenApiMiddlewareBuilder = OpenApiMiddlewareBuilder;
|
|
554
512
|
/**
|
|
555
513
|
* Creates a new OpenAPI middleware builder.
|
|
@@ -578,7 +536,7 @@ exports.OpenApiMiddlewareBuilder = OpenApiMiddlewareBuilder;
|
|
|
578
536
|
* router.get("/analytics/stats", statsMiddleware, getStatsHandler);
|
|
579
537
|
* ```
|
|
580
538
|
*/
|
|
581
|
-
|
|
539
|
+
const createOpenApiBuilder = (options) => {
|
|
582
540
|
return new OpenApiMiddlewareBuilder(options);
|
|
583
541
|
};
|
|
584
542
|
exports.createOpenApiBuilder = createOpenApiBuilder;
|