@terreno/api 0.11.7 → 0.11.9
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/dist/betterAuthSetup.js +10 -3
- package/dist/configurationPlugin.d.ts +2 -1
- package/dist/configurationPlugin.js +16 -9
- package/dist/errors.d.ts +6 -6
- package/dist/errors.js +22 -22
- package/dist/errors.test.d.ts +1 -0
- package/dist/errors.test.js +280 -0
- package/dist/githubAuth.d.ts +3 -3
- package/dist/githubAuth.js +16 -16
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.js +4 -3
- package/dist/middleware.test.d.ts +1 -0
- package/dist/middleware.test.js +82 -0
- package/dist/notifiers/googleChatNotifier.js +4 -3
- package/dist/notifiers/zoomNotifier.js +12 -11
- package/dist/openApiCompat.js +2 -1
- package/dist/openApiEtag.d.ts +1 -1
- package/dist/openApiEtag.js +4 -3
- package/dist/openApiValidator.d.ts +12 -12
- package/dist/openApiValidator.js +59 -58
- package/dist/plugins.d.ts +12 -1
- package/dist/plugins.js +34 -1
- package/dist/plugins.test.js +212 -8
- package/dist/scriptRunner.d.ts +8 -7
- package/dist/secretProviders.js +17 -7
- package/dist/types/consentForm.d.ts +4 -2
- package/package.json +1 -1
- package/src/betterAuthSetup.ts +10 -3
- package/src/configurationPlugin.ts +18 -9
- package/src/errors.test.ts +302 -0
- package/src/errors.ts +18 -13
- package/src/githubAuth.ts +11 -10
- package/src/middleware.test.ts +71 -0
- package/src/middleware.ts +6 -2
- package/src/notifiers/googleChatNotifier.ts +4 -3
- package/src/notifiers/zoomNotifier.ts +4 -3
- package/src/openApiCompat.ts +2 -1
- package/src/openApiEtag.ts +2 -2
- package/src/openApiValidator.ts +46 -46
- package/src/plugins.test.ts +130 -0
- package/src/plugins.ts +35 -0
- package/src/scriptRunner.ts +23 -27
- package/src/secretProviders.ts +27 -9
- package/src/types/consentForm.ts +6 -4
package/dist/githubAuth.js
CHANGED
|
@@ -39,14 +39,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.githubUserPlugin =
|
|
43
|
-
exports.setupGitHubAuth = setupGitHubAuth;
|
|
44
|
-
exports.addGitHubAuthRoutes = addGitHubAuthRoutes;
|
|
42
|
+
exports.addGitHubAuthRoutes = exports.setupGitHubAuth = exports.githubUserPlugin = void 0;
|
|
45
43
|
var passport_1 = __importDefault(require("passport"));
|
|
46
44
|
var passport_github2_1 = require("passport-github2");
|
|
47
45
|
var auth_1 = require("./auth");
|
|
48
46
|
var errors_1 = require("./errors");
|
|
49
47
|
var logger_1 = require("./logger");
|
|
48
|
+
var plugins_1 = require("./plugins");
|
|
50
49
|
/**
|
|
51
50
|
* Plugin to add GitHub authentication fields to a user schema.
|
|
52
51
|
* Apply this plugin to your User schema if you want to enable GitHub auth.
|
|
@@ -58,20 +57,20 @@ var logger_1 = require("./logger");
|
|
|
58
57
|
* userSchema.plugin(githubUserPlugin);
|
|
59
58
|
* ```
|
|
60
59
|
*/
|
|
61
|
-
function
|
|
60
|
+
var githubUserPlugin = function (schema) {
|
|
62
61
|
schema.add({
|
|
63
62
|
githubAvatarUrl: { type: String },
|
|
64
63
|
githubId: { index: true, sparse: true, type: String, unique: true },
|
|
65
64
|
githubProfileUrl: { type: String },
|
|
66
65
|
githubUsername: { type: String },
|
|
67
66
|
});
|
|
68
|
-
}
|
|
67
|
+
};
|
|
68
|
+
exports.githubUserPlugin = githubUserPlugin;
|
|
69
69
|
/**
|
|
70
70
|
* Sets up GitHub OAuth authentication strategy.
|
|
71
71
|
* Call this after setupAuth() in your server initialization.
|
|
72
72
|
*/
|
|
73
|
-
function
|
|
74
|
-
var _this = this;
|
|
73
|
+
var setupGitHubAuth = function (_app, userModel, githubOptions) {
|
|
75
74
|
var _a;
|
|
76
75
|
var scope = (_a = githubOptions.scope) !== null && _a !== void 0 ? _a : ["user:email"];
|
|
77
76
|
passport_1.default.use("github", new passport_github2_1.Strategy({
|
|
@@ -80,7 +79,7 @@ function setupGitHubAuth(_app, userModel, githubOptions) {
|
|
|
80
79
|
clientSecret: githubOptions.clientSecret,
|
|
81
80
|
passReqToCallback: true,
|
|
82
81
|
scope: scope,
|
|
83
|
-
}, (function (req, accessToken, refreshToken, profile, done) { return __awaiter(
|
|
82
|
+
}, (function (req, accessToken, refreshToken, profile, done) { return __awaiter(void 0, void 0, void 0, function () {
|
|
84
83
|
var existingUser, user, githubId, existingGitHubUser, user, email, existingEmailUser, newUser, error_1;
|
|
85
84
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
86
85
|
return __generator(this, function (_j) {
|
|
@@ -95,7 +94,7 @@ function setupGitHubAuth(_app, userModel, githubOptions) {
|
|
|
95
94
|
return [2 /*return*/, done(null, user)];
|
|
96
95
|
case 2:
|
|
97
96
|
githubId = profile.id;
|
|
98
|
-
return [4 /*yield*/,
|
|
97
|
+
return [4 /*yield*/, (0, plugins_1.findOneOrNoneFor)(userModel, { githubId: githubId })];
|
|
99
98
|
case 3:
|
|
100
99
|
existingGitHubUser = _j.sent();
|
|
101
100
|
if (!existingUser) return [3 /*break*/, 7];
|
|
@@ -129,7 +128,7 @@ function setupGitHubAuth(_app, userModel, githubOptions) {
|
|
|
129
128
|
}
|
|
130
129
|
email = (_d = (_c = profile.emails) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.value;
|
|
131
130
|
if (!email) return [3 /*break*/, 11];
|
|
132
|
-
return [4 /*yield*/,
|
|
131
|
+
return [4 /*yield*/, (0, plugins_1.findOneOrNoneFor)(userModel, { email: email })];
|
|
133
132
|
case 8:
|
|
134
133
|
existingEmailUser = _j.sent();
|
|
135
134
|
if (!existingEmailUser) return [3 /*break*/, 11];
|
|
@@ -167,7 +166,8 @@ function setupGitHubAuth(_app, userModel, githubOptions) {
|
|
|
167
166
|
}
|
|
168
167
|
});
|
|
169
168
|
}); })));
|
|
170
|
-
}
|
|
169
|
+
};
|
|
170
|
+
exports.setupGitHubAuth = setupGitHubAuth;
|
|
171
171
|
/**
|
|
172
172
|
* Adds GitHub OAuth routes to the Express application.
|
|
173
173
|
*
|
|
@@ -177,8 +177,7 @@ function setupGitHubAuth(_app, userModel, githubOptions) {
|
|
|
177
177
|
* - POST /auth/github/link - Links GitHub account to authenticated user (requires JWT auth)
|
|
178
178
|
* - DELETE /auth/github/unlink - Unlinks GitHub account from authenticated user (requires JWT auth)
|
|
179
179
|
*/
|
|
180
|
-
function
|
|
181
|
-
var _this = this;
|
|
180
|
+
var addGitHubAuthRoutes = function (app, userModel, githubOptions, authOptions) {
|
|
182
181
|
var router = require("express").Router();
|
|
183
182
|
// Initiate GitHub OAuth flow
|
|
184
183
|
router.get("/github", function (req, _res, next) {
|
|
@@ -194,7 +193,7 @@ function addGitHubAuthRoutes(app, userModel, githubOptions, authOptions) {
|
|
|
194
193
|
router.get("/github/callback", passport_1.default.authenticate("github", {
|
|
195
194
|
failureRedirect: "/auth/github/failure",
|
|
196
195
|
session: false,
|
|
197
|
-
}), function (req, res) { return __awaiter(
|
|
196
|
+
}), function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
198
197
|
var tokens, returnTo, url, error_2;
|
|
199
198
|
var _a, _b, _c, _d;
|
|
200
199
|
return __generator(this, function (_e) {
|
|
@@ -249,7 +248,7 @@ function addGitHubAuthRoutes(app, userModel, githubOptions, authOptions) {
|
|
|
249
248
|
})(req, res, next);
|
|
250
249
|
}, passport_1.default.authenticate("github", { session: false }));
|
|
251
250
|
// Unlink GitHub from user account
|
|
252
|
-
router.delete("/github/unlink", passport_1.default.authenticate("jwt", { session: false }), function (req, res) { return __awaiter(
|
|
251
|
+
router.delete("/github/unlink", passport_1.default.authenticate("jwt", { session: false }), function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
253
252
|
var user, hasPassword, error_3;
|
|
254
253
|
return __generator(this, function (_a) {
|
|
255
254
|
switch (_a.label) {
|
|
@@ -290,4 +289,5 @@ function addGitHubAuthRoutes(app, userModel, githubOptions, authOptions) {
|
|
|
290
289
|
}); });
|
|
291
290
|
}
|
|
292
291
|
app.use("/auth", router);
|
|
293
|
-
}
|
|
292
|
+
};
|
|
293
|
+
exports.addGitHubAuthRoutes = addGitHubAuthRoutes;
|
package/dist/middleware.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ import type { NextFunction, Request, Response } from "express";
|
|
|
7
7
|
*
|
|
8
8
|
* Expected header: `App-Version`
|
|
9
9
|
*/
|
|
10
|
-
export declare
|
|
10
|
+
export declare const sentryAppVersionMiddleware: (req: Request, _res: Response, next: NextFunction) => void;
|
package/dist/middleware.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.sentryAppVersionMiddleware =
|
|
36
|
+
exports.sentryAppVersionMiddleware = void 0;
|
|
37
37
|
var Sentry = __importStar(require("@sentry/bun"));
|
|
38
38
|
/**
|
|
39
39
|
* Express middleware that captures the app version from the request header
|
|
@@ -43,10 +43,11 @@ var Sentry = __importStar(require("@sentry/bun"));
|
|
|
43
43
|
*
|
|
44
44
|
* Expected header: `App-Version`
|
|
45
45
|
*/
|
|
46
|
-
function
|
|
46
|
+
var sentryAppVersionMiddleware = function (req, _res, next) {
|
|
47
47
|
var appVersion = req.get("App-Version");
|
|
48
48
|
if (appVersion) {
|
|
49
49
|
Sentry.getCurrentScope().setTag("app_version", appVersion);
|
|
50
50
|
}
|
|
51
51
|
next();
|
|
52
|
-
}
|
|
52
|
+
};
|
|
53
|
+
exports.sentryAppVersionMiddleware = sentryAppVersionMiddleware;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
var bun_test_1 = require("bun:test");
|
|
37
|
+
var Sentry = __importStar(require("@sentry/bun"));
|
|
38
|
+
var middleware_1 = require("./middleware");
|
|
39
|
+
var buildReq = function (headers) {
|
|
40
|
+
return {
|
|
41
|
+
get: function (name) { return headers[name]; },
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var buildNext = function () { return (0, bun_test_1.mock)(function () { }); };
|
|
45
|
+
(0, bun_test_1.describe)("sentryAppVersionMiddleware", function () {
|
|
46
|
+
var setTagMock;
|
|
47
|
+
(0, bun_test_1.beforeEach)(function () {
|
|
48
|
+
// bunSetup.ts mocks @sentry/bun so that getCurrentScope() returns a scope
|
|
49
|
+
// with a Bun mock setTag. Clear that mock between tests so each assertion
|
|
50
|
+
// sees only its own calls.
|
|
51
|
+
setTagMock = Sentry.getCurrentScope().setTag;
|
|
52
|
+
setTagMock.mockClear();
|
|
53
|
+
});
|
|
54
|
+
(0, bun_test_1.it)("sets the app_version tag when the App-Version header is present", function () {
|
|
55
|
+
var next = buildNext();
|
|
56
|
+
var req = buildReq({ "App-Version": "1.2.3" });
|
|
57
|
+
(0, middleware_1.sentryAppVersionMiddleware)(req, {}, next);
|
|
58
|
+
(0, bun_test_1.expect)(setTagMock).toHaveBeenCalledTimes(1);
|
|
59
|
+
(0, bun_test_1.expect)(setTagMock.mock.calls[0]).toEqual(["app_version", "1.2.3"]);
|
|
60
|
+
(0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
|
|
61
|
+
});
|
|
62
|
+
(0, bun_test_1.it)("does not set a tag when the App-Version header is missing", function () {
|
|
63
|
+
var next = buildNext();
|
|
64
|
+
var req = buildReq({});
|
|
65
|
+
(0, middleware_1.sentryAppVersionMiddleware)(req, {}, next);
|
|
66
|
+
(0, bun_test_1.expect)(setTagMock).not.toHaveBeenCalled();
|
|
67
|
+
(0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
(0, bun_test_1.it)("does not set a tag when the App-Version header is an empty string", function () {
|
|
70
|
+
var next = buildNext();
|
|
71
|
+
var req = buildReq({ "App-Version": "" });
|
|
72
|
+
(0, middleware_1.sentryAppVersionMiddleware)(req, {}, next);
|
|
73
|
+
(0, bun_test_1.expect)(setTagMock).not.toHaveBeenCalled();
|
|
74
|
+
(0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
|
|
75
|
+
});
|
|
76
|
+
(0, bun_test_1.it)("calls next exactly once with no arguments when the header is present", function () {
|
|
77
|
+
var next = buildNext();
|
|
78
|
+
(0, middleware_1.sentryAppVersionMiddleware)(buildReq({ "App-Version": "9.9.9" }), {}, next);
|
|
79
|
+
(0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
|
|
80
|
+
(0, bun_test_1.expect)(next.mock.calls[0]).toHaveLength(0);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -108,7 +108,7 @@ var sendToGoogleChat = function (messageText_1) {
|
|
|
108
108
|
args_1[_i - 1] = arguments[_i];
|
|
109
109
|
}
|
|
110
110
|
return __awaiter(void 0, __spreadArray([messageText_1], __read(args_1), false), void 0, function (messageText, _a) {
|
|
111
|
-
var chatWebhooksString, msg, chatWebhooks, chatChannel, chatWebhookUrl, msg, formattedMessageText, error_1;
|
|
111
|
+
var chatWebhooksString, msg, chatWebhooks, chatChannel, chatWebhookUrl, msg, formattedMessageText, error_1, errorObj;
|
|
112
112
|
var _b, _c, _d;
|
|
113
113
|
var _e = _a === void 0 ? {} : _a, channel = _e.channel, _f = _e.shouldThrow, shouldThrow = _f === void 0 ? false : _f, env = _e.env;
|
|
114
114
|
return __generator(this, function (_g) {
|
|
@@ -143,12 +143,13 @@ var sendToGoogleChat = function (messageText_1) {
|
|
|
143
143
|
return [3 /*break*/, 4];
|
|
144
144
|
case 3:
|
|
145
145
|
error_1 = _g.sent();
|
|
146
|
-
|
|
146
|
+
errorObj = error_1;
|
|
147
|
+
logger_1.logger.error("Error posting to Google Chat: ".concat((_c = errorObj.text) !== null && _c !== void 0 ? _c : errorObj.message));
|
|
147
148
|
Sentry.captureException(error_1);
|
|
148
149
|
if (shouldThrow) {
|
|
149
150
|
throw new errors_1.APIError({
|
|
150
151
|
status: 500,
|
|
151
|
-
title: "Error posting to Google Chat: ".concat((_d =
|
|
152
|
+
title: "Error posting to Google Chat: ".concat((_d = errorObj.text) !== null && _d !== void 0 ? _d : errorObj.message),
|
|
152
153
|
});
|
|
153
154
|
}
|
|
154
155
|
return [3 /*break*/, 4];
|
|
@@ -103,12 +103,12 @@ var logger_1 = require("../logger");
|
|
|
103
103
|
* Uses Zoom's rich message format (format=full) with structured header and body.
|
|
104
104
|
*/
|
|
105
105
|
var sendToZoom = function (_a, _b) { return __awaiter(void 0, [_a, _b], void 0, function (_c, _d) {
|
|
106
|
-
var zoomWebhooksString, msg, zoomWebhooks, zoomChannel, zoomWebhookUrl, msg, zoomToken, msg, messageBody, error_1;
|
|
107
|
-
var _e, _f, _g, _h, _j, _k
|
|
106
|
+
var zoomWebhooksString, msg, zoomWebhooks, zoomChannel, zoomWebhookUrl, msg, zoomToken, msg, messageBody, error_1, errorMessage;
|
|
107
|
+
var _e, _f, _g, _h, _j, _k;
|
|
108
108
|
var header = _c.header, body = _c.body, subheader = _c.subheader;
|
|
109
|
-
var channel = _d.channel,
|
|
110
|
-
return __generator(this, function (
|
|
111
|
-
switch (
|
|
109
|
+
var channel = _d.channel, _l = _d.shouldThrow, shouldThrow = _l === void 0 ? false : _l, env = _d.env;
|
|
110
|
+
return __generator(this, function (_m) {
|
|
111
|
+
switch (_m.label) {
|
|
112
112
|
case 0:
|
|
113
113
|
zoomWebhooksString = process.env.ZOOM_CHAT_WEBHOOKS;
|
|
114
114
|
if (!zoomWebhooksString) {
|
|
@@ -149,9 +149,9 @@ var sendToZoom = function (_a, _b) { return __awaiter(void 0, [_a, _b], void 0,
|
|
|
149
149
|
text: subheader,
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
_m.label = 1;
|
|
153
153
|
case 1:
|
|
154
|
-
|
|
154
|
+
_m.trys.push([1, 3, , 4]);
|
|
155
155
|
return [4 /*yield*/, axios_1.default.post("".concat(zoomWebhookUrl, "?format=full"), { content: messageBody }, {
|
|
156
156
|
headers: {
|
|
157
157
|
Authorization: zoomToken,
|
|
@@ -159,16 +159,17 @@ var sendToZoom = function (_a, _b) { return __awaiter(void 0, [_a, _b], void 0,
|
|
|
159
159
|
},
|
|
160
160
|
})];
|
|
161
161
|
case 2:
|
|
162
|
-
|
|
162
|
+
_m.sent();
|
|
163
163
|
return [3 /*break*/, 4];
|
|
164
164
|
case 3:
|
|
165
|
-
error_1 =
|
|
166
|
-
|
|
165
|
+
error_1 = _m.sent();
|
|
166
|
+
errorMessage = error_1 instanceof Error ? error_1.message : String(error_1);
|
|
167
|
+
logger_1.logger.error("Error posting to Zoom: ".concat(errorMessage));
|
|
167
168
|
Sentry.captureException(error_1);
|
|
168
169
|
if (shouldThrow) {
|
|
169
170
|
throw new errors_1.APIError({
|
|
170
171
|
status: 500,
|
|
171
|
-
title: "Error posting to Zoom: ".concat(
|
|
172
|
+
title: "Error posting to Zoom: ".concat(errorMessage),
|
|
172
173
|
});
|
|
173
174
|
}
|
|
174
175
|
return [3 /*break*/, 4];
|
package/dist/openApiCompat.js
CHANGED
|
@@ -158,7 +158,7 @@ var patchRouterStack = function (stack) {
|
|
|
158
158
|
*/
|
|
159
159
|
var patchAppUse = function (app) {
|
|
160
160
|
var originalUse = app.use.bind(app);
|
|
161
|
-
|
|
161
|
+
var patchedUse = function () {
|
|
162
162
|
var _a, _b;
|
|
163
163
|
var args = [];
|
|
164
164
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -182,6 +182,7 @@ var patchAppUse = function (app) {
|
|
|
182
182
|
}
|
|
183
183
|
return result;
|
|
184
184
|
};
|
|
185
|
+
app.use = patchedUse;
|
|
185
186
|
};
|
|
186
187
|
exports.patchAppUse = patchAppUse;
|
|
187
188
|
/**
|
package/dist/openApiEtag.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ import type { NextFunction, Request, Response } from "express";
|
|
|
4
4
|
* This middleware should be added before the @wesleytodd/openapi middleware
|
|
5
5
|
* to intercept requests to /openapi.json and add conditional request support.
|
|
6
6
|
*/
|
|
7
|
-
export declare
|
|
7
|
+
export declare const openApiEtagMiddleware: (req: Request, res: Response, next: NextFunction) => void;
|
package/dist/openApiEtag.js
CHANGED
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.openApiEtagMiddleware =
|
|
6
|
+
exports.openApiEtagMiddleware = void 0;
|
|
7
7
|
var node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
8
|
/**
|
|
9
9
|
* Middleware to add ETag support for OpenAPI JSON endpoint.
|
|
10
10
|
* This middleware should be added before the @wesleytodd/openapi middleware
|
|
11
11
|
* to intercept requests to /openapi.json and add conditional request support.
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
13
|
+
var openApiEtagMiddleware = function (req, res, next) {
|
|
14
14
|
// Only handle GET requests to /openapi.json
|
|
15
15
|
if (req.method !== "GET" || req.path !== "/openapi.json") {
|
|
16
16
|
next();
|
|
@@ -35,4 +35,5 @@ function openApiEtagMiddleware(req, res, next) {
|
|
|
35
35
|
return originalJson(body);
|
|
36
36
|
};
|
|
37
37
|
next();
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
|
+
exports.openApiEtagMiddleware = openApiEtagMiddleware;
|
|
@@ -83,7 +83,7 @@ export interface OpenApiValidatorConfig {
|
|
|
83
83
|
* Check whether `configureOpenApiValidator()` has been called.
|
|
84
84
|
* Validation middleware is a no-op when this returns false.
|
|
85
85
|
*/
|
|
86
|
-
export declare
|
|
86
|
+
export declare const isOpenApiValidatorConfigured: () => boolean;
|
|
87
87
|
/**
|
|
88
88
|
* Configure the global OpenAPI validator settings.
|
|
89
89
|
* Calling this function activates validation — middleware that was previously
|
|
@@ -101,17 +101,17 @@ export declare function isOpenApiValidatorConfigured(): boolean;
|
|
|
101
101
|
* });
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
-
export declare
|
|
104
|
+
export declare const configureOpenApiValidator: (config?: Partial<OpenApiValidatorConfig>) => void;
|
|
105
105
|
/**
|
|
106
106
|
* Get the current global validator configuration.
|
|
107
107
|
*/
|
|
108
|
-
export declare
|
|
108
|
+
export declare const getOpenApiValidatorConfig: () => OpenApiValidatorConfig;
|
|
109
109
|
/**
|
|
110
110
|
* Reset the global validator configuration to defaults.
|
|
111
111
|
* Also resets `isConfigured` to false.
|
|
112
112
|
* Useful for testing.
|
|
113
113
|
*/
|
|
114
|
-
export declare
|
|
114
|
+
export declare const resetOpenApiValidatorConfig: () => void;
|
|
115
115
|
/**
|
|
116
116
|
* Options for the request body validator middleware.
|
|
117
117
|
*/
|
|
@@ -149,7 +149,7 @@ export interface RequestBodyValidatorOptions {
|
|
|
149
149
|
* @param options - Optional configuration for this validator
|
|
150
150
|
* @returns Express middleware function
|
|
151
151
|
*/
|
|
152
|
-
export declare
|
|
152
|
+
export declare const validateRequestBody: (schema: Record<string, OpenApiSchemaProperty>, options?: RequestBodyValidatorOptions) => ((req: Request, res: Response, next: NextFunction) => void);
|
|
153
153
|
/**
|
|
154
154
|
* Options for the query parameter validator middleware.
|
|
155
155
|
*/
|
|
@@ -170,7 +170,7 @@ export interface QueryValidatorOptions {
|
|
|
170
170
|
* @param options - Optional configuration for this validator
|
|
171
171
|
* @returns Express middleware function
|
|
172
172
|
*/
|
|
173
|
-
export declare
|
|
173
|
+
export declare const validateQueryParams: (schema: Record<string, OpenApiSchemaProperty>, options?: QueryValidatorOptions) => ((req: Request, res: Response, next: NextFunction) => void);
|
|
174
174
|
/**
|
|
175
175
|
* Options for creating a combined validation middleware.
|
|
176
176
|
*/
|
|
@@ -205,7 +205,7 @@ export interface CreateValidatorOptions {
|
|
|
205
205
|
* ], handler);
|
|
206
206
|
* ```
|
|
207
207
|
*/
|
|
208
|
-
export declare
|
|
208
|
+
export declare const createValidator: (options: CreateValidatorOptions) => ((req: Request, res: Response, next: NextFunction) => void);
|
|
209
209
|
/**
|
|
210
210
|
* Validates response data against a schema.
|
|
211
211
|
* This is primarily for development/testing to ensure responses match documentation.
|
|
@@ -214,7 +214,7 @@ export declare function createValidator(options: CreateValidatorOptions): (req:
|
|
|
214
214
|
* @param schema - The expected schema
|
|
215
215
|
* @returns Object with valid flag and any errors
|
|
216
216
|
*/
|
|
217
|
-
export declare
|
|
217
|
+
export declare const validateResponseData: (data: unknown, schema: Record<string, OpenApiSchemaProperty>) => {
|
|
218
218
|
valid: boolean;
|
|
219
219
|
errors?: ErrorObject[];
|
|
220
220
|
};
|
|
@@ -226,7 +226,7 @@ export declare function validateResponseData(data: unknown, schema: Record<strin
|
|
|
226
226
|
* @param model - A Mongoose model
|
|
227
227
|
* @returns Schema properties suitable for validation
|
|
228
228
|
*/
|
|
229
|
-
export declare
|
|
229
|
+
export declare const getSchemaFromModel: <T>(model: Model<T>) => Record<string, OpenApiSchemaProperty>;
|
|
230
230
|
/**
|
|
231
231
|
* Creates a request body validator middleware from a Mongoose model.
|
|
232
232
|
* This is a convenience function that combines getSchemaFromModel and validateRequestBody.
|
|
@@ -235,7 +235,7 @@ export declare function getSchemaFromModel<T>(model: Model<T>): Record<string, O
|
|
|
235
235
|
* @param options - Optional configuration for the validator
|
|
236
236
|
* @returns Express middleware function
|
|
237
237
|
*/
|
|
238
|
-
export declare
|
|
238
|
+
export declare const validateModelRequestBody: <T>(model: Model<T>, options?: RequestBodyValidatorOptions) => ((req: Request, res: Response, next: NextFunction) => void);
|
|
239
239
|
/**
|
|
240
240
|
* Options for creating validation middleware for a modelRouter.
|
|
241
241
|
*/
|
|
@@ -281,7 +281,7 @@ export interface ModelRouterValidationOptions {
|
|
|
281
281
|
* @param options - Configuration options
|
|
282
282
|
* @returns Object with create and update validation middleware
|
|
283
283
|
*/
|
|
284
|
-
export declare
|
|
284
|
+
export declare const createModelValidators: <T>(model: Model<T>, options?: ModelRouterValidationOptions) => {
|
|
285
285
|
create: (req: Request, res: Response, next: NextFunction) => void;
|
|
286
286
|
update: (req: Request, res: Response, next: NextFunction) => void;
|
|
287
287
|
};
|
|
@@ -293,4 +293,4 @@ export declare function createModelValidators<T>(model: Model<T>, options?: Mode
|
|
|
293
293
|
* @param queryFields - Array of field names allowed for querying
|
|
294
294
|
* @returns Schema properties suitable for query validation
|
|
295
295
|
*/
|
|
296
|
-
export declare
|
|
296
|
+
export declare const buildQuerySchemaFromFields: <T>(model: Model<T>, queryFields?: string[]) => Record<string, OpenApiSchemaProperty>;
|