@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
|
@@ -5,54 +5,43 @@
|
|
|
5
5
|
// The main-branch approach works correctly with the openApiCompat.ts regexp shim.
|
|
6
6
|
// License: ISC (see ../LICENSE)
|
|
7
7
|
'use strict';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
s = arguments[i];
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
17
|
-
return __assign.apply(this, arguments);
|
|
18
|
-
};
|
|
19
|
-
var pathToRegexp = require('path-to-regexp');
|
|
20
|
-
var minimumViableDocument = require('./minimum-doc');
|
|
21
|
-
var _a = require('./layer-schema'), getSchema = _a.get, setSchema = _a.set;
|
|
8
|
+
const pathToRegexp = require('path-to-regexp');
|
|
9
|
+
const minimumViableDocument = require('./minimum-doc');
|
|
10
|
+
const { get: getSchema, set: setSchema } = require('./layer-schema');
|
|
22
11
|
module.exports = function generateDocument(baseDocument, router, basePath) {
|
|
23
12
|
// Merge document with select minimum defaults
|
|
24
|
-
|
|
13
|
+
const doc = Object.assign({
|
|
25
14
|
openapi: minimumViableDocument.openapi
|
|
26
15
|
}, baseDocument, {
|
|
27
16
|
info: Object.assign({}, minimumViableDocument.info, baseDocument.info),
|
|
28
17
|
paths: Object.assign({}, minimumViableDocument.paths, baseDocument.paths)
|
|
29
18
|
});
|
|
30
19
|
// Iterate the middleware stack and add any paths and schemas, etc
|
|
31
|
-
router && router.stack.forEach(
|
|
32
|
-
iterateStack('', null, _layer,
|
|
20
|
+
router && router.stack.forEach((_layer) => {
|
|
21
|
+
iterateStack('', null, _layer, (path, routeLayer, layer) => {
|
|
33
22
|
if (basePath && path.startsWith(basePath)) {
|
|
34
23
|
path = path.replace(basePath, '');
|
|
35
24
|
}
|
|
36
|
-
|
|
25
|
+
const schema = getSchema(layer.handle);
|
|
37
26
|
if (!schema || !layer.method) {
|
|
38
27
|
return;
|
|
39
28
|
}
|
|
40
|
-
|
|
29
|
+
const operation = Object.assign({}, schema);
|
|
41
30
|
// Add route params to schema
|
|
42
31
|
if (routeLayer && routeLayer.keys && routeLayer.keys.length) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
const keys = {};
|
|
33
|
+
const params = routeLayer.keys.map((k, i) => {
|
|
34
|
+
const prev = i > 0 && routeLayer.keys[i - 1];
|
|
46
35
|
// do not count parameters without a name if they are next to a named parameter
|
|
47
36
|
if (typeof k.name === 'number' && prev && prev.offset + prev.name.length + 1 >= k.offset) {
|
|
48
37
|
return null;
|
|
49
38
|
}
|
|
50
|
-
|
|
39
|
+
let param;
|
|
51
40
|
if (schema.parameters) {
|
|
52
|
-
param = schema.parameters.find(
|
|
41
|
+
param = schema.parameters.find((p) => p.name === k.name && p.in === 'path');
|
|
53
42
|
}
|
|
54
43
|
// Reformat the path
|
|
55
|
-
|
|
44
|
+
keys[k.name] = '{' + k.name + '}';
|
|
56
45
|
return Object.assign({
|
|
57
46
|
name: k.name,
|
|
58
47
|
in: 'path',
|
|
@@ -60,17 +49,17 @@ module.exports = function generateDocument(baseDocument, router, basePath) {
|
|
|
60
49
|
schema: k.schema || { type: 'string' }
|
|
61
50
|
}, param || {});
|
|
62
51
|
})
|
|
63
|
-
.filter(
|
|
52
|
+
.filter((e) => e);
|
|
64
53
|
if (schema.parameters) {
|
|
65
|
-
schema.parameters.forEach(
|
|
66
|
-
if (p.name && !
|
|
67
|
-
|
|
54
|
+
schema.parameters.forEach((p) => {
|
|
55
|
+
if (p.name && !params.find((pp) => p.name === pp.name)) {
|
|
56
|
+
params.push(p);
|
|
68
57
|
}
|
|
69
58
|
});
|
|
70
59
|
}
|
|
71
|
-
operation.parameters =
|
|
60
|
+
operation.parameters = params.filter((p) => typeof p.name === 'string' && p.name);
|
|
72
61
|
try {
|
|
73
|
-
path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)'), { encode:
|
|
62
|
+
path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)'), { encode: (value) => value })(keys);
|
|
74
63
|
}
|
|
75
64
|
catch (_e) {
|
|
76
65
|
// Express 5 stores path params in matchers instead of layer.keys, so keys
|
|
@@ -90,7 +79,7 @@ module.exports = function generateDocument(baseDocument, router, basePath) {
|
|
|
90
79
|
function iterateStack(path, routeLayer, layer, cb) {
|
|
91
80
|
cb(path, routeLayer, layer);
|
|
92
81
|
if (layer.name === 'router') {
|
|
93
|
-
layer.handle.stack.forEach(
|
|
82
|
+
layer.handle.stack.forEach(l => {
|
|
94
83
|
path = path || '';
|
|
95
84
|
iterateStack(path + split(layer.regexp, layer.keys).join('/'), layer, l, cb);
|
|
96
85
|
});
|
|
@@ -99,25 +88,28 @@ function iterateStack(path, routeLayer, layer, cb) {
|
|
|
99
88
|
return;
|
|
100
89
|
}
|
|
101
90
|
if (Array.isArray(layer.route.path)) {
|
|
102
|
-
|
|
103
|
-
layer.route.path.forEach(
|
|
91
|
+
const r = layer.regexp.toString();
|
|
92
|
+
layer.route.path.forEach((p, i) => iterateStack(path + p, layer, {
|
|
93
|
+
...layer,
|
|
104
94
|
// Checking if p is a string here since p may be a regex expression
|
|
105
|
-
keys: layer.keys.filter(
|
|
95
|
+
keys: layer.keys.filter((k) => typeof p === 'string' ? p.includes(`/:${k.name}`) : false),
|
|
106
96
|
// There may be an issue here if the regex has a '|', but that seems to only be the case with user defined regex
|
|
107
|
-
regexp: new RegExp(
|
|
97
|
+
regexp: new RegExp(`(${r.substring(2, r.length - 3).split('|')[i]})`),
|
|
98
|
+
route: { ...layer.route, path: '' }
|
|
99
|
+
}, cb));
|
|
108
100
|
return;
|
|
109
101
|
}
|
|
110
|
-
layer.route.stack.forEach(
|
|
102
|
+
layer.route.stack.forEach((l) => iterateStack(path + layer.route.path, layer, l, cb));
|
|
111
103
|
}
|
|
112
104
|
function processComplexMatch(thing, keys) {
|
|
113
|
-
|
|
105
|
+
let i = 0;
|
|
114
106
|
return thing
|
|
115
107
|
.toString()
|
|
116
108
|
// The replace below replaces the regex used by Express to match dynamic parameters
|
|
117
109
|
// (i.e. /:id, /:name, etc...) with the name(s) of those parameter(s)
|
|
118
110
|
// This could have been accomplished with replaceAll for Node version 15 and above
|
|
119
111
|
// no-useless-escape is disabled since we need three backslashes
|
|
120
|
-
.replace(/\(\?\:\(\[\^\\\/\]\+\?\)\)/g,
|
|
112
|
+
.replace(/\(\?\:\(\[\^\\\/\]\+\?\)\)/g, () => `{${keys[i++].name}}`)
|
|
121
113
|
.replace(/\\(.)/g, '$1')
|
|
122
114
|
// The replace below removes the regex used at the start of the string and
|
|
123
115
|
// the regex used to match the query parameters
|
|
@@ -143,7 +135,7 @@ function split(thing, keys) {
|
|
|
143
135
|
return [];
|
|
144
136
|
}
|
|
145
137
|
else {
|
|
146
|
-
|
|
138
|
+
const match = thing
|
|
147
139
|
.toString()
|
|
148
140
|
.replace('\\/?', '')
|
|
149
141
|
.replace('(?=\\/|$)', '$')
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Vendored from https://github.com/wesleytodd/express-openapi (branch: express-5)
|
|
2
2
|
// License: ISC (see ../LICENSE)
|
|
3
3
|
'use strict';
|
|
4
|
-
|
|
4
|
+
const schemas = new Map();
|
|
5
5
|
module.exports = {
|
|
6
|
-
set:
|
|
6
|
+
set: (handler, schema) => {
|
|
7
7
|
schemas.set(handler, schema);
|
|
8
8
|
},
|
|
9
|
-
get:
|
|
9
|
+
get: (handler) => {
|
|
10
10
|
return schemas.get(handler);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
@@ -1,37 +1,68 @@
|
|
|
1
1
|
// Vendored from https://github.com/wesleytodd/express-openapi (branch: express-5)
|
|
2
2
|
// License: ISC (see ../LICENSE)
|
|
3
3
|
'use strict';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
9
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
10
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
11
|
-
t[p[i]] = s[p[i]];
|
|
12
|
-
}
|
|
13
|
-
return t;
|
|
14
|
-
};
|
|
15
|
-
var path = require('path');
|
|
16
|
-
var serve = require('serve-static');
|
|
17
|
-
module.exports.serveSwaggerUI = function serveSwaggerUI(documentUrl, opts) {
|
|
18
|
-
if (opts === void 0) { opts = {}; }
|
|
19
|
-
var plugins = opts.plugins, options = __rest(opts, ["plugins"]);
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const serve = require('serve-static');
|
|
6
|
+
module.exports.serveSwaggerUI = function serveSwaggerUI(documentUrl, opts = {}) {
|
|
7
|
+
const { plugins, ...options } = opts;
|
|
20
8
|
return [serve(path.resolve(require.resolve('swagger-ui-dist'), '..'), { index: false }),
|
|
21
9
|
function returnUiInit(req, res, next) {
|
|
22
10
|
if (req.path.endsWith('/swagger-ui-init.js')) {
|
|
23
11
|
res.type('.js');
|
|
24
|
-
res.send(
|
|
12
|
+
res.send(`window.onload = function () {
|
|
13
|
+
window.ui = SwaggerUIBundle({
|
|
14
|
+
url: '${documentUrl}',
|
|
15
|
+
dom_id: '#swagger-ui',
|
|
16
|
+
${plugins?.length ? `plugins: [${plugins}],` : ''}
|
|
17
|
+
...${JSON.stringify(options)}
|
|
18
|
+
})
|
|
19
|
+
}`);
|
|
25
20
|
}
|
|
26
21
|
else {
|
|
27
22
|
next();
|
|
28
23
|
}
|
|
29
24
|
},
|
|
30
25
|
function renderSwaggerHtml(req, res) {
|
|
31
|
-
res.type('html').send(renderHtmlPage('Swagger UI',
|
|
26
|
+
res.type('html').send(renderHtmlPage('Swagger UI', `
|
|
27
|
+
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
|
28
|
+
`, `
|
|
29
|
+
<div id="swagger-ui"></div>
|
|
30
|
+
<script src="./swagger-ui-bundle.js"></script>
|
|
31
|
+
<script src="./swagger-ui-standalone-preset.js"></script>
|
|
32
|
+
<script src="./swagger-ui-init.js"></script>
|
|
33
|
+
`));
|
|
32
34
|
}
|
|
33
35
|
];
|
|
34
36
|
};
|
|
35
37
|
function renderHtmlPage(title, head, body) {
|
|
36
|
-
return
|
|
38
|
+
return `<!DOCTYPE html>
|
|
39
|
+
<html>
|
|
40
|
+
<head>
|
|
41
|
+
<title>${title}</title>
|
|
42
|
+
<meta charset="utf-8"/>
|
|
43
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
44
|
+
<style>
|
|
45
|
+
html {
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
overflow: -moz-scrollbars-vertical;
|
|
48
|
+
overflow-y: scroll;
|
|
49
|
+
}
|
|
50
|
+
*,
|
|
51
|
+
*:before,
|
|
52
|
+
*:after {
|
|
53
|
+
box-sizing: inherit;
|
|
54
|
+
}
|
|
55
|
+
body {
|
|
56
|
+
margin: 0;
|
|
57
|
+
padding: 0;
|
|
58
|
+
background: #fafafa;
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
61
|
+
${head}
|
|
62
|
+
</head>
|
|
63
|
+
<body>
|
|
64
|
+
${body}
|
|
65
|
+
</body>
|
|
66
|
+
</html>
|
|
67
|
+
`;
|
|
37
68
|
}
|
|
@@ -1,38 +1,11 @@
|
|
|
1
1
|
// Vendored from https://github.com/wesleytodd/express-openapi (branch: express-5)
|
|
2
2
|
// License: ISC (see ../LICENSE)
|
|
3
3
|
'use strict';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
t[p] = s[p];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
return __assign.apply(this, arguments);
|
|
14
|
-
};
|
|
15
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
16
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
17
|
-
if (!m) return o;
|
|
18
|
-
var i = m.call(o), r, ar = [], e;
|
|
19
|
-
try {
|
|
20
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
21
|
-
}
|
|
22
|
-
catch (error) { e = { error: error }; }
|
|
23
|
-
finally {
|
|
24
|
-
try {
|
|
25
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
26
|
-
}
|
|
27
|
-
finally { if (e) throw e.error; }
|
|
28
|
-
}
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
var Ajv = require('ajv');
|
|
32
|
-
var addFormats = require('ajv-formats');
|
|
33
|
-
var addKeywords = require('ajv-keywords');
|
|
34
|
-
var httpErrors = require('http-errors');
|
|
35
|
-
var BASE_REQ_SCHEMA = {
|
|
4
|
+
const Ajv = require('ajv');
|
|
5
|
+
const addFormats = require('ajv-formats');
|
|
6
|
+
const addKeywords = require('ajv-keywords');
|
|
7
|
+
const httpErrors = require('http-errors');
|
|
8
|
+
const BASE_REQ_SCHEMA = {
|
|
36
9
|
type: 'object',
|
|
37
10
|
required: ['headers', 'params', 'query'],
|
|
38
11
|
properties: {
|
|
@@ -59,13 +32,13 @@ var BASE_REQ_SCHEMA = {
|
|
|
59
32
|
}
|
|
60
33
|
};
|
|
61
34
|
module.exports = function makeValidatorMiddleware(middleware, schema, opts) {
|
|
62
|
-
|
|
63
|
-
|
|
35
|
+
let ajv;
|
|
36
|
+
let validate;
|
|
64
37
|
function makeValidator() {
|
|
65
|
-
|
|
38
|
+
const reqSchema = structuredClone(BASE_REQ_SCHEMA);
|
|
66
39
|
// Compile req schema on first request
|
|
67
40
|
// Build param validation
|
|
68
|
-
schema.parameters && schema.parameters.forEach(
|
|
41
|
+
schema.parameters && schema.parameters.forEach((p) => {
|
|
69
42
|
switch (p.in) {
|
|
70
43
|
case 'path':
|
|
71
44
|
reqSchema.properties.params.properties[p.name] = p.schema;
|
|
@@ -76,23 +49,22 @@ module.exports = function makeValidatorMiddleware(middleware, schema, opts) {
|
|
|
76
49
|
p.required && !reqSchema.properties.query.required.includes(p.name) && reqSchema.properties.query.required.push(p.name);
|
|
77
50
|
break;
|
|
78
51
|
case 'header': {
|
|
79
|
-
|
|
80
|
-
reqSchema.properties.headers.properties[
|
|
81
|
-
p.required && !reqSchema.properties.headers.required.includes(p.name) && reqSchema.properties.headers.required.push(
|
|
52
|
+
const name = p.name.toLowerCase();
|
|
53
|
+
reqSchema.properties.headers.properties[name] = p.schema;
|
|
54
|
+
p.required && !reqSchema.properties.headers.required.includes(p.name) && reqSchema.properties.headers.required.push(name);
|
|
82
55
|
break;
|
|
83
56
|
}
|
|
84
57
|
}
|
|
85
58
|
});
|
|
86
59
|
// Compile req body schema
|
|
87
60
|
schema.requestBody && Object.entries(schema.requestBody.content)
|
|
88
|
-
.forEach(
|
|
89
|
-
var _b = __read(_a, 2), contentType = _b[0], schema = _b[1].schema;
|
|
61
|
+
.forEach(([contentType, { schema }]) => {
|
|
90
62
|
switch (contentType) {
|
|
91
63
|
case 'application/json':
|
|
92
64
|
reqSchema.properties.body = schema;
|
|
93
65
|
break;
|
|
94
66
|
default:
|
|
95
|
-
throw new TypeError(
|
|
67
|
+
throw new TypeError(`Validation of content type not supported: ${contentType}`);
|
|
96
68
|
}
|
|
97
69
|
});
|
|
98
70
|
// Add components for references
|
|
@@ -125,31 +97,31 @@ module.exports = function makeValidatorMiddleware(middleware, schema, opts) {
|
|
|
125
97
|
validate = makeValidator();
|
|
126
98
|
}
|
|
127
99
|
// Validate request
|
|
128
|
-
|
|
100
|
+
let r = req;
|
|
129
101
|
if (opts.coerce !== true) {
|
|
130
102
|
r = makeReqCopy(req);
|
|
131
103
|
}
|
|
132
104
|
else {
|
|
133
105
|
// Redifine query and params as normal objects we can write to, so we can coerce the data
|
|
134
106
|
Object.defineProperty(req, 'query', {
|
|
135
|
-
value:
|
|
107
|
+
value: { ...req.query },
|
|
136
108
|
writable: true,
|
|
137
109
|
enumerable: true,
|
|
138
110
|
configurable: true
|
|
139
111
|
});
|
|
140
112
|
Object.defineProperty(req, 'params', {
|
|
141
|
-
value:
|
|
113
|
+
value: { ...req.params },
|
|
142
114
|
writable: true,
|
|
143
115
|
enumerable: true,
|
|
144
116
|
configurable: true
|
|
145
117
|
});
|
|
146
118
|
}
|
|
147
|
-
|
|
119
|
+
const validationStatus = validate(r);
|
|
148
120
|
if (validationStatus === true) {
|
|
149
121
|
return next();
|
|
150
122
|
}
|
|
151
123
|
// build error?
|
|
152
|
-
|
|
124
|
+
const err = new Error('Request validation failed');
|
|
153
125
|
err.validationErrors = validate.errors;
|
|
154
126
|
err.validationSchema = validate.schema;
|
|
155
127
|
next(httpErrors(400, err));
|
|
@@ -1,109 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.VersionCheckPlugin = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
const versionConfig_1 = require("./models/versionConfig");
|
|
6
|
+
const DEFAULT_WARNING_MESSAGE = "A new version is available. Please update for the best experience.";
|
|
7
|
+
const DEFAULT_REQUIRED_MESSAGE = "This version is no longer supported. Please update to continue.";
|
|
8
|
+
const DEFAULT_POLLING_INTERVAL_MINUTES = 1440;
|
|
45
9
|
/**
|
|
46
10
|
* TerrenoPlugin that adds a public GET /version-check endpoint for upgrade enforcement.
|
|
47
11
|
* Compares client build number against admin-configured thresholds per platform.
|
|
48
12
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
13
|
+
class VersionCheckPlugin {
|
|
14
|
+
register(app) {
|
|
15
|
+
app.get("/version-check", (0, api_1.asyncHandler)(async (req, res) => {
|
|
16
|
+
const versionParam = req.query.version;
|
|
17
|
+
const platform = req.query.platform;
|
|
18
|
+
let version;
|
|
19
|
+
if (typeof versionParam === "string") {
|
|
20
|
+
version = parseInt(versionParam, 10);
|
|
21
|
+
}
|
|
22
|
+
else if (typeof versionParam === "number") {
|
|
23
|
+
version = versionParam;
|
|
24
|
+
}
|
|
25
|
+
if (version === undefined || Number.isNaN(version)) {
|
|
26
|
+
return res.json({ status: "ok" });
|
|
27
|
+
}
|
|
28
|
+
const platformNormalized = platform === "web" || platform === "mobile" ? platform : "web";
|
|
29
|
+
const config = await versionConfig_1.VersionConfig.findOneOrNone({ _singleton: "config" });
|
|
30
|
+
if (!config) {
|
|
31
|
+
return res.json({
|
|
32
|
+
pollingIntervalMs: DEFAULT_POLLING_INTERVAL_MINUTES * 60 * 1000,
|
|
33
|
+
status: "ok",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const requiredVersion = platformNormalized === "web"
|
|
37
|
+
? (config.webRequiredVersion ?? 0)
|
|
38
|
+
: (config.mobileRequiredVersion ?? 0);
|
|
39
|
+
const warningVersion = platformNormalized === "web"
|
|
40
|
+
? (config.webWarningVersion ?? 0)
|
|
41
|
+
: (config.mobileWarningVersion ?? 0);
|
|
42
|
+
const response = {
|
|
43
|
+
pollingIntervalMs: (config.pollingIntervalMinutes ?? DEFAULT_POLLING_INTERVAL_MINUTES) * 60 * 1000,
|
|
44
|
+
requiredVersion: requiredVersion > 0 ? requiredVersion : undefined,
|
|
45
|
+
status: "ok",
|
|
46
|
+
updateUrl: config.updateUrl || undefined,
|
|
47
|
+
warningVersion: warningVersion > 0 ? warningVersion : undefined,
|
|
48
|
+
};
|
|
49
|
+
if (requiredVersion > 0 && version < requiredVersion) {
|
|
50
|
+
response.status = "required";
|
|
51
|
+
response.message = config.requiredMessage ?? DEFAULT_REQUIRED_MESSAGE;
|
|
52
|
+
}
|
|
53
|
+
else if (warningVersion > 0 && version < warningVersion) {
|
|
54
|
+
response.status = "warning";
|
|
55
|
+
response.message = config.warningMessage ?? DEFAULT_WARNING_MESSAGE;
|
|
56
|
+
}
|
|
57
|
+
return res.json(response);
|
|
58
|
+
}));
|
|
51
59
|
}
|
|
52
|
-
|
|
53
|
-
var _this = this;
|
|
54
|
-
app.get("/version-check", (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
55
|
-
var versionParam, platform, version, platformNormalized, config, requiredVersion, warningVersion, response;
|
|
56
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
57
|
-
return __generator(this, function (_h) {
|
|
58
|
-
switch (_h.label) {
|
|
59
|
-
case 0:
|
|
60
|
-
versionParam = req.query.version;
|
|
61
|
-
platform = req.query.platform;
|
|
62
|
-
if (typeof versionParam === "string") {
|
|
63
|
-
version = parseInt(versionParam, 10);
|
|
64
|
-
}
|
|
65
|
-
else if (typeof versionParam === "number") {
|
|
66
|
-
version = versionParam;
|
|
67
|
-
}
|
|
68
|
-
if (version === undefined || Number.isNaN(version)) {
|
|
69
|
-
return [2 /*return*/, res.json({ status: "ok" })];
|
|
70
|
-
}
|
|
71
|
-
platformNormalized = platform === "web" || platform === "mobile" ? platform : "web";
|
|
72
|
-
return [4 /*yield*/, versionConfig_1.VersionConfig.findOneOrNone({ _singleton: "config" })];
|
|
73
|
-
case 1:
|
|
74
|
-
config = _h.sent();
|
|
75
|
-
if (!config) {
|
|
76
|
-
return [2 /*return*/, res.json({
|
|
77
|
-
pollingIntervalMs: DEFAULT_POLLING_INTERVAL_MINUTES * 60 * 1000,
|
|
78
|
-
status: "ok",
|
|
79
|
-
})];
|
|
80
|
-
}
|
|
81
|
-
requiredVersion = platformNormalized === "web"
|
|
82
|
-
? ((_a = config.webRequiredVersion) !== null && _a !== void 0 ? _a : 0)
|
|
83
|
-
: ((_b = config.mobileRequiredVersion) !== null && _b !== void 0 ? _b : 0);
|
|
84
|
-
warningVersion = platformNormalized === "web"
|
|
85
|
-
? ((_c = config.webWarningVersion) !== null && _c !== void 0 ? _c : 0)
|
|
86
|
-
: ((_d = config.mobileWarningVersion) !== null && _d !== void 0 ? _d : 0);
|
|
87
|
-
response = {
|
|
88
|
-
pollingIntervalMs: ((_e = config.pollingIntervalMinutes) !== null && _e !== void 0 ? _e : DEFAULT_POLLING_INTERVAL_MINUTES) * 60 * 1000,
|
|
89
|
-
requiredVersion: requiredVersion > 0 ? requiredVersion : undefined,
|
|
90
|
-
status: "ok",
|
|
91
|
-
updateUrl: config.updateUrl || undefined,
|
|
92
|
-
warningVersion: warningVersion > 0 ? warningVersion : undefined,
|
|
93
|
-
};
|
|
94
|
-
if (requiredVersion > 0 && version < requiredVersion) {
|
|
95
|
-
response.status = "required";
|
|
96
|
-
response.message = (_f = config.requiredMessage) !== null && _f !== void 0 ? _f : DEFAULT_REQUIRED_MESSAGE;
|
|
97
|
-
}
|
|
98
|
-
else if (warningVersion > 0 && version < warningVersion) {
|
|
99
|
-
response.status = "warning";
|
|
100
|
-
response.message = (_g = config.warningMessage) !== null && _g !== void 0 ? _g : DEFAULT_WARNING_MESSAGE;
|
|
101
|
-
}
|
|
102
|
-
return [2 /*return*/, res.json(response)];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}); }));
|
|
106
|
-
};
|
|
107
|
-
return VersionCheckPlugin;
|
|
108
|
-
}());
|
|
60
|
+
}
|
|
109
61
|
exports.VersionCheckPlugin = VersionCheckPlugin;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.headerValue = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const headerValue = (req, header) => {
|
|
5
|
+
const raw = req.headers[header.toLowerCase()];
|
|
6
6
|
if (Array.isArray(raw)) {
|
|
7
7
|
return raw[0];
|
|
8
8
|
}
|
|
@@ -1,65 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.createMemoryIdempotencyStore = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return "".concat(source, "\0").concat(eventId);
|
|
4
|
+
const claimKey = ({ source, eventId }) => {
|
|
5
|
+
return `${source}\0${eventId}`;
|
|
43
6
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return __generator(this, function (_a) {
|
|
59
|
-
claimed.delete(claimKey(args));
|
|
60
|
-
return [2 /*return*/];
|
|
61
|
-
});
|
|
62
|
-
}); };
|
|
63
|
-
return { claim: claim, release: release };
|
|
7
|
+
const createMemoryIdempotencyStore = () => {
|
|
8
|
+
const claimed = new Set();
|
|
9
|
+
const claim = async (args) => {
|
|
10
|
+
const key = claimKey(args);
|
|
11
|
+
if (claimed.has(key)) {
|
|
12
|
+
return "duplicate";
|
|
13
|
+
}
|
|
14
|
+
claimed.add(key);
|
|
15
|
+
return "claimed";
|
|
16
|
+
};
|
|
17
|
+
const release = async (args) => {
|
|
18
|
+
claimed.delete(claimKey(args));
|
|
19
|
+
};
|
|
20
|
+
return { claim, release };
|
|
64
21
|
};
|
|
65
22
|
exports.createMemoryIdempotencyStore = createMemoryIdempotencyStore;
|