@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/openApiCompat.js
CHANGED
|
@@ -1,51 +1,4 @@
|
|
|
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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
41
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
42
|
-
if (ar || !(i in from)) {
|
|
43
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
-
ar[i] = from[i];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
-
};
|
|
49
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
4
|
};
|
|
@@ -61,18 +14,18 @@ exports.openApiCompatMiddleware = exports.patchAppUse = exports.patchExpressRout
|
|
|
61
14
|
*
|
|
62
15
|
* @see https://github.com/wesleytodd/express-openapi/issues/70
|
|
63
16
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
17
|
+
const express_1 = __importDefault(require("express"));
|
|
18
|
+
const MOUNT_PATH_KEY = "__openApiMountPath";
|
|
19
|
+
let isExpressRouterUsePatched = false;
|
|
67
20
|
/**
|
|
68
21
|
* Extract Express 4-style keys from a path string.
|
|
69
22
|
* Parses `:paramName` and `*paramName` segments into `{name, optional}` objects
|
|
70
23
|
* that @wesleytodd/openapi expects.
|
|
71
24
|
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
25
|
+
const extractKeysFromPath = (path) => {
|
|
26
|
+
const keys = [];
|
|
27
|
+
const paramRegex = /[:*](\w+)\??/g;
|
|
28
|
+
let match;
|
|
76
29
|
// biome-ignore lint/suspicious/noAssignInExpressions: standard regex exec loop
|
|
77
30
|
while ((match = paramRegex.exec(path)) !== null) {
|
|
78
31
|
keys.push({ name: match[1], optional: match[0].endsWith("?") });
|
|
@@ -89,92 +42,80 @@ var extractKeysFromPath = function (path) {
|
|
|
89
42
|
* Express 4-style capture group `(?:([^\/]+?))` so that `processComplexMatch()`
|
|
90
43
|
* in the openapi library can map them to `{paramName}` using `layer.keys`.
|
|
91
44
|
*/
|
|
92
|
-
|
|
45
|
+
const buildRegexpForPath = (pathStr, isMount) => {
|
|
93
46
|
// Replace :param segments with Express 4-style capture groups, then escape the rest
|
|
94
|
-
|
|
47
|
+
const parts = pathStr.split("/").map((segment) => {
|
|
95
48
|
if (segment.startsWith(":")) {
|
|
96
49
|
return "(?:([^\\/]+?))";
|
|
97
50
|
}
|
|
98
51
|
return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
99
52
|
});
|
|
100
|
-
|
|
53
|
+
const pattern = parts.join("\\/");
|
|
101
54
|
if (isMount) {
|
|
102
|
-
return new RegExp(
|
|
55
|
+
return new RegExp(`^${pattern}\\/?(?=\\/|$)`);
|
|
103
56
|
}
|
|
104
|
-
return new RegExp(
|
|
57
|
+
return new RegExp(`^${pattern}\\/?$`);
|
|
105
58
|
};
|
|
106
|
-
|
|
59
|
+
const annotateMountLayers = (stack, stackBefore, args) => {
|
|
107
60
|
if (!stack) {
|
|
108
61
|
return;
|
|
109
62
|
}
|
|
110
|
-
|
|
63
|
+
const mountPath = typeof args[0] === "string" ? args[0] : undefined;
|
|
111
64
|
if (!mountPath || mountPath === "/") {
|
|
112
65
|
return;
|
|
113
66
|
}
|
|
114
|
-
|
|
115
|
-
for (
|
|
67
|
+
const normalizedMountPath = mountPath.replace(/\/+$/, "");
|
|
68
|
+
for (let i = stackBefore; i < stack.length; i++) {
|
|
116
69
|
stack[i][MOUNT_PATH_KEY] = normalizedMountPath;
|
|
117
70
|
}
|
|
118
71
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (layer.
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
72
|
+
const patchRouterStack = (stack) => {
|
|
73
|
+
for (const layer of stack) {
|
|
74
|
+
if (layer.regexp === undefined) {
|
|
75
|
+
// Determine the path string for this layer
|
|
76
|
+
let pathStr;
|
|
77
|
+
const isMount = layer.name === "router" || !!layer.handle?.stack;
|
|
78
|
+
if (layer.slash) {
|
|
79
|
+
// Express 5 layers use .slash instead of .regexp.fast_slash
|
|
80
|
+
layer.regexp = { fast_slash: true };
|
|
81
|
+
}
|
|
82
|
+
else if (layer[MOUNT_PATH_KEY]) {
|
|
83
|
+
pathStr = layer[MOUNT_PATH_KEY];
|
|
84
|
+
layer.regexp = buildRegexpForPath(pathStr, isMount);
|
|
85
|
+
}
|
|
86
|
+
else if (layer.path && typeof layer.path === "string") {
|
|
87
|
+
pathStr = layer.path;
|
|
88
|
+
layer.regexp = buildRegexpForPath(pathStr, false);
|
|
89
|
+
}
|
|
90
|
+
else if (layer.route?.path && typeof layer.route.path === "string") {
|
|
91
|
+
pathStr = layer.route.path;
|
|
92
|
+
layer.regexp = buildRegexpForPath(pathStr, false);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
layer.regexp = /^\/?$/;
|
|
96
|
+
}
|
|
97
|
+
// Populate keys in Express 4 format: [{name, optional}]
|
|
98
|
+
// @wesleytodd/openapi reads layer.keys[i].name for path parameters
|
|
99
|
+
if (!layer.keys || (Array.isArray(layer.keys) && layer.keys.length === 0)) {
|
|
100
|
+
if (pathStr) {
|
|
101
|
+
layer.keys = extractKeysFromPath(pathStr);
|
|
144
102
|
}
|
|
145
103
|
else {
|
|
146
|
-
layer.
|
|
147
|
-
}
|
|
148
|
-
// Populate keys in Express 4 format: [{name, optional}]
|
|
149
|
-
// @wesleytodd/openapi reads layer.keys[i].name for path parameters
|
|
150
|
-
if (!layer.keys || (Array.isArray(layer.keys) && layer.keys.length === 0)) {
|
|
151
|
-
if (pathStr) {
|
|
152
|
-
layer.keys = extractKeysFromPath(pathStr);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
layer.keys = [];
|
|
156
|
-
}
|
|
104
|
+
layer.keys = [];
|
|
157
105
|
}
|
|
158
|
-
else if (Array.isArray(layer.keys) && typeof layer.keys[0] === "string") {
|
|
159
|
-
// Express 5 stores keys as plain strings after match() — convert to objects
|
|
160
|
-
layer.keys = layer.keys.map(function (k) { return ({ name: k, optional: false }); });
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// Recursively patch nested stacks even when this layer already had a regexp.
|
|
164
|
-
if ((_d = layer.handle) === null || _d === void 0 ? void 0 : _d.stack) {
|
|
165
|
-
patchRouterStack(layer.handle.stack);
|
|
166
106
|
}
|
|
167
|
-
if ((
|
|
168
|
-
|
|
107
|
+
else if (Array.isArray(layer.keys) && typeof layer.keys[0] === "string") {
|
|
108
|
+
// Express 5 stores keys as plain strings after match() — convert to objects
|
|
109
|
+
layer.keys = layer.keys.map((k) => ({ name: k, optional: false }));
|
|
169
110
|
}
|
|
170
111
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
112
|
+
// Recursively patch nested stacks even when this layer already had a regexp.
|
|
113
|
+
if (layer.handle?.stack) {
|
|
114
|
+
patchRouterStack(layer.handle.stack);
|
|
115
|
+
}
|
|
116
|
+
if (layer.route?.stack) {
|
|
117
|
+
patchRouterStack(layer.route.stack);
|
|
176
118
|
}
|
|
177
|
-
finally { if (e_1) throw e_1.error; }
|
|
178
119
|
}
|
|
179
120
|
};
|
|
180
121
|
/**
|
|
@@ -185,34 +126,32 @@ var patchRouterStack = function (stack) {
|
|
|
185
126
|
* Express 5's Router puts `use` a few prototypes up from the instance, so we walk
|
|
186
127
|
* the chain until we find the own `use` descriptor.
|
|
187
128
|
*/
|
|
188
|
-
|
|
129
|
+
const patchExpressRouterUse = () => {
|
|
189
130
|
if (isExpressRouterUsePatched) {
|
|
190
131
|
return;
|
|
191
132
|
}
|
|
192
133
|
isExpressRouterUsePatched = true;
|
|
193
|
-
|
|
134
|
+
let routerPrototype = Object.getPrototypeOf(express_1.default.Router());
|
|
194
135
|
while (routerPrototype && !Object.getOwnPropertyDescriptor(routerPrototype, "use")) {
|
|
195
136
|
routerPrototype = Object.getPrototypeOf(routerPrototype);
|
|
196
137
|
}
|
|
197
138
|
if (!routerPrototype) {
|
|
198
139
|
return;
|
|
199
140
|
}
|
|
200
|
-
|
|
201
|
-
if (!
|
|
141
|
+
const useDescriptor = Object.getOwnPropertyDescriptor(routerPrototype, "use");
|
|
142
|
+
if (!useDescriptor?.value) {
|
|
202
143
|
return;
|
|
203
144
|
}
|
|
204
|
-
|
|
205
|
-
Object.defineProperty(routerPrototype, "use",
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
var stackBefore = (_b = (_a = this.stack) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
212
|
-
var result = originalUse.apply(this, args);
|
|
145
|
+
const originalUse = useDescriptor.value;
|
|
146
|
+
Object.defineProperty(routerPrototype, "use", {
|
|
147
|
+
...useDescriptor,
|
|
148
|
+
value(...args) {
|
|
149
|
+
const stackBefore = this.stack?.length ?? 0;
|
|
150
|
+
const result = originalUse.apply(this, args);
|
|
213
151
|
annotateMountLayers(this.stack, stackBefore, args);
|
|
214
152
|
return result;
|
|
215
|
-
}
|
|
153
|
+
},
|
|
154
|
+
});
|
|
216
155
|
};
|
|
217
156
|
exports.patchExpressRouterUse = patchExpressRouterUse;
|
|
218
157
|
/**
|
|
@@ -222,23 +161,18 @@ exports.patchExpressRouterUse = patchExpressRouterUse;
|
|
|
222
161
|
*
|
|
223
162
|
* Must be called before any routes are registered.
|
|
224
163
|
*/
|
|
225
|
-
|
|
164
|
+
const patchAppUse = (app) => {
|
|
226
165
|
(0, exports.patchExpressRouterUse)();
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
var _a, _b, _c, _d;
|
|
231
|
-
var args = [];
|
|
232
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
233
|
-
args[_i] = arguments[_i];
|
|
234
|
-
}
|
|
166
|
+
const internal = app;
|
|
167
|
+
const originalUse = app.use.bind(app);
|
|
168
|
+
const patchedUse = (...args) => {
|
|
235
169
|
// Track stack length before the call
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
170
|
+
const router = internal._router ?? internal.router;
|
|
171
|
+
const stackBefore = router?.stack?.length ?? 0;
|
|
172
|
+
const result = originalUse(...args);
|
|
239
173
|
// After use(), check if new layers were added and annotate them
|
|
240
|
-
|
|
241
|
-
annotateMountLayers(routerAfter
|
|
174
|
+
const routerAfter = internal._router ?? internal.router;
|
|
175
|
+
annotateMountLayers(routerAfter?.stack, stackBefore, args);
|
|
242
176
|
return result;
|
|
243
177
|
};
|
|
244
178
|
app.use = patchedUse;
|
|
@@ -248,11 +182,10 @@ exports.patchAppUse = patchAppUse;
|
|
|
248
182
|
* Express middleware that patches the router stack before OpenAPI doc
|
|
249
183
|
* generation. Must be mounted before the openapi middleware.
|
|
250
184
|
*/
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (router === null || router === void 0 ? void 0 : router.stack) {
|
|
185
|
+
const openApiCompatMiddleware = (req, _res, next) => {
|
|
186
|
+
const internal = req.app;
|
|
187
|
+
const router = internal._router ?? internal.router;
|
|
188
|
+
if (router?.stack) {
|
|
256
189
|
patchRouterStack(router.stack);
|
|
257
190
|
}
|
|
258
191
|
next();
|
package/dist/openApiEtag.js
CHANGED
|
@@ -4,23 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.openApiEtagMiddleware = void 0;
|
|
7
|
-
|
|
7
|
+
const 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
|
-
|
|
13
|
+
const openApiEtagMiddleware = (req, res, next) => {
|
|
14
14
|
if (req.method !== "GET" || req.path !== "/openapi.json") {
|
|
15
15
|
next();
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
res.json =
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const originalJson = res.json.bind(res);
|
|
19
|
+
res.json = (body) => {
|
|
20
|
+
const jsonString = JSON.stringify(body);
|
|
21
|
+
const etag = `"${node_crypto_1.default.createHash("sha256").update(jsonString).digest("hex").substring(0, 16)}"`;
|
|
22
22
|
res.set("ETag", etag);
|
|
23
|
-
|
|
23
|
+
const ifNoneMatch = req.get("If-None-Match");
|
|
24
24
|
if (ifNoneMatch === etag) {
|
|
25
25
|
res.status(304).end();
|
|
26
26
|
return res;
|