@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.
Files changed (208) hide show
  1. package/README.md +5 -5
  2. package/bunfig.toml +1 -1
  3. package/dist/actions.js +197 -368
  4. package/dist/adminModelRouter.js +88 -173
  5. package/dist/api.js +598 -852
  6. package/dist/audit/auditApp.js +48 -89
  7. package/dist/audit/auditEventModel.js +15 -16
  8. package/dist/audit/cloudTasksEnqueue.js +56 -149
  9. package/dist/audit/diff.js +70 -160
  10. package/dist/audit/processQueue.js +25 -70
  11. package/dist/audit/rbacSink.js +25 -66
  12. package/dist/audit/record.js +129 -251
  13. package/dist/auth.js +432 -681
  14. package/dist/authRecovery.js +155 -269
  15. package/dist/authTokens.js +43 -118
  16. package/dist/betterAuthApp.js +25 -26
  17. package/dist/betterAuthSetup.js +258 -413
  18. package/dist/browserLogsRoute.d.ts +6 -0
  19. package/dist/browserLogsRoute.js +97 -0
  20. package/dist/collectionRegistry.js +32 -47
  21. package/dist/config.js +53 -122
  22. package/dist/configurationApp.js +180 -361
  23. package/dist/configurationPlugin.js +130 -302
  24. package/dist/consentApp.js +276 -421
  25. package/dist/docLoader.js +78 -126
  26. package/dist/envConfigurationPlugin.js +25 -147
  27. package/dist/errors.js +151 -247
  28. package/dist/example.js +28 -34
  29. package/dist/expressServer.d.ts +10 -0
  30. package/dist/expressServer.js +109 -255
  31. package/dist/frameworkModelNames.d.ts +24 -0
  32. package/dist/frameworkModelNames.js +31 -0
  33. package/dist/githubAuth.js +152 -216
  34. package/dist/httpClient.js +176 -264
  35. package/dist/index.d.ts +2 -0
  36. package/dist/index.js +7 -2
  37. package/dist/logger.js +145 -278
  38. package/dist/mcp/auth.js +76 -128
  39. package/dist/mcp/createMCPRequest.js +4 -5
  40. package/dist/mcp/handlers.js +268 -480
  41. package/dist/mcp/query.js +56 -150
  42. package/dist/mcp/registry.js +17 -30
  43. package/dist/mcp/schemaGenerator.js +95 -181
  44. package/dist/mcp/server.js +28 -100
  45. package/dist/mcp/serviceTokens.js +102 -191
  46. package/dist/mcp/toolGenerator.js +78 -191
  47. package/dist/middleware.js +15 -27
  48. package/dist/migrations/fixtures/all-down/20260910120000-one.js +2 -42
  49. package/dist/migrations/fixtures/all-down/20260910120001-two.js +2 -42
  50. package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +1 -39
  51. package/dist/migrations/fixtures/bad-name/not-a-migration.js +1 -39
  52. package/dist/migrations/fixtures/valid/20260910120000-alpha.js +1 -39
  53. package/dist/migrations/fixtures/valid/20260910120001-beta.js +2 -42
  54. package/dist/migrations/generate.js +107 -229
  55. package/dist/migrations/load.js +75 -201
  56. package/dist/migrations/lock.js +54 -126
  57. package/dist/migrations/runner.js +192 -446
  58. package/dist/migrations/schemaCatalog.js +122 -263
  59. package/dist/models/consentForm.js +6 -6
  60. package/dist/models/consentResponse.js +5 -5
  61. package/dist/models/mcpServiceToken.js +66 -156
  62. package/dist/models/notification.js +6 -6
  63. package/dist/models/notificationPreference.js +6 -6
  64. package/dist/models/versionConfig.js +5 -5
  65. package/dist/notifications/notificationService.js +133 -273
  66. package/dist/notifications/notificationsApp.js +85 -179
  67. package/dist/notifications/notificationsBeforeSend.js +19 -64
  68. package/dist/notifiers/googleChatNotifier.js +36 -117
  69. package/dist/notifiers/slackNotifier.d.ts +31 -2
  70. package/dist/notifiers/slackNotifier.js +170 -119
  71. package/dist/notifiers/zoomNotifier.js +60 -111
  72. package/dist/openApi.js +107 -122
  73. package/dist/openApiBuilder.js +117 -159
  74. package/dist/openApiCompat.js +81 -148
  75. package/dist/openApiEtag.js +7 -7
  76. package/dist/openApiValidator.js +177 -286
  77. package/dist/orgs/orgContext.js +87 -157
  78. package/dist/orgs/orgPermissions.js +29 -68
  79. package/dist/orgs/orgPlugin.js +9 -27
  80. package/dist/orgs/organizationModel.js +65 -166
  81. package/dist/orgs/organizationSettings.js +29 -36
  82. package/dist/orgs/orgsApp.js +346 -608
  83. package/dist/permissions.js +88 -181
  84. package/dist/plugins.js +125 -218
  85. package/dist/populate.js +130 -240
  86. package/dist/rateLimit/applyTrustProxy.js +1 -1
  87. package/dist/rateLimit/createStore.js +7 -8
  88. package/dist/rateLimit/memoryStore.js +22 -100
  89. package/dist/rateLimit/middleware.js +48 -99
  90. package/dist/rateLimit/mongoStore.js +54 -112
  91. package/dist/rateLimit/policies.js +41 -75
  92. package/dist/rateLimit/redisStore.js +39 -133
  93. package/dist/rbac/access.js +119 -267
  94. package/dist/rbac/assertAllowed.js +95 -171
  95. package/dist/rbac/auditModel.js +14 -58
  96. package/dist/rbac/backfillAdmins.js +24 -130
  97. package/dist/rbac/fieldViews.js +46 -141
  98. package/dist/rbac/membershipOrgAdminSource.js +28 -99
  99. package/dist/rbac/middleware.js +30 -96
  100. package/dist/rbac/modelRouterAccess.js +130 -307
  101. package/dist/rbac/permissionUtils.js +40 -179
  102. package/dist/rbac/realtimeAccess.js +81 -147
  103. package/dist/rbac/resolve.d.ts +1 -1
  104. package/dist/rbac/resolve.js +148 -342
  105. package/dist/rbac/roleManager.js +318 -700
  106. package/dist/rbac/roleModel.js +44 -171
  107. package/dist/rbac/routes.js +93 -196
  108. package/dist/rbac/scopes.js +39 -133
  109. package/dist/rbac/statements.js +23 -91
  110. package/dist/rbac/userPlugin.js +3 -29
  111. package/dist/realtime/changeStreamWatcher.js +489 -800
  112. package/dist/realtime/deprecation.js +8 -10
  113. package/dist/realtime/queryMatcher.js +110 -191
  114. package/dist/realtime/queryStore.js +35 -118
  115. package/dist/realtime/realtimeApp.js +247 -401
  116. package/dist/realtime/registry.js +19 -30
  117. package/dist/realtime/sessionRevalidation.js +132 -358
  118. package/dist/realtime/socketAuth.js +89 -208
  119. package/dist/realtime/socketUser.js +10 -56
  120. package/dist/requestContext.js +93 -139
  121. package/dist/schemaMetadata.js +179 -274
  122. package/dist/scriptRunner.js +96 -266
  123. package/dist/scrubAdminFields.js +36 -108
  124. package/dist/secretProviders.js +130 -299
  125. package/dist/seedRunner.js +221 -514
  126. package/dist/sync/adminBroadcastScope.js +58 -170
  127. package/dist/sync/adminWindowAccess.js +15 -86
  128. package/dist/sync/adminWindowMutation.js +110 -181
  129. package/dist/sync/executors.js +425 -629
  130. package/dist/sync/loadHarness.js +392 -689
  131. package/dist/sync/models.js +181 -341
  132. package/dist/sync/mutationHandler.js +533 -801
  133. package/dist/sync/registrationSideEffects.js +41 -95
  134. package/dist/sync/registry.js +29 -49
  135. package/dist/sync/routes.js +484 -817
  136. package/dist/sync/scripts/compactTombstones.js +83 -228
  137. package/dist/sync/serialize.js +18 -58
  138. package/dist/sync/socketHandlers.js +253 -478
  139. package/dist/sync/streams.js +49 -117
  140. package/dist/sync/syncApp.js +12 -15
  141. package/dist/sync/syncBatch.js +63 -168
  142. package/dist/sync/syncSeqPlugin.js +430 -702
  143. package/dist/syncConsents.js +113 -253
  144. package/dist/terrenoApp.js +166 -276
  145. package/dist/tests/createTestData.js +146 -256
  146. package/dist/tests/models.js +14 -54
  147. package/dist/tests/mongoTestSetup.js +42 -103
  148. package/dist/tests/testHelper.js +31 -93
  149. package/dist/tests.js +12 -51
  150. package/dist/transformers.js +61 -164
  151. package/dist/utils.js +31 -93
  152. package/dist/vendor/wesleytodd-openapi/index.js +37 -51
  153. package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +32 -40
  154. package/dist/vendor/wesleytodd-openapi/lib/layer-schema.js +3 -3
  155. package/dist/vendor/wesleytodd-openapi/lib/ui.js +50 -19
  156. package/dist/vendor/wesleytodd-openapi/lib/validate.js +19 -47
  157. package/dist/versionCheckPlugin.js +52 -100
  158. package/dist/webhooks/headerValue.js +2 -2
  159. package/dist/webhooks/idempotency/memoryStore.js +16 -59
  160. package/dist/webhooks/idempotency/mongoStore.js +55 -130
  161. package/dist/webhooks/idempotency/webhookReceipt.js +9 -9
  162. package/dist/webhooks/rawBody.js +1 -1
  163. package/dist/webhooks/timingSafeEqual.js +4 -5
  164. package/dist/webhooks/verifiers/hmac.js +17 -18
  165. package/dist/webhooks/verifiers/sendgrid.js +20 -22
  166. package/dist/webhooks/verifiers/stripe.js +31 -65
  167. package/dist/webhooks/verifiers/twilio.js +23 -73
  168. package/dist/webhooks/webhooksApp.js +78 -177
  169. package/dist/zodOpenApi.js +2 -2
  170. package/package.json +6 -6
  171. package/src/__tests__/browserLogsRoute.test.ts +165 -0
  172. package/src/audit/auditApp.test.ts +5 -5
  173. package/src/audit/auditEventModel.ts +7 -3
  174. package/src/audit/auditRouter.test.ts +5 -5
  175. package/src/audit/rbacSink.test.ts +2 -2
  176. package/src/audit/record.test.ts +2 -2
  177. package/src/audit/record.ts +3 -2
  178. package/src/auth.ts +1 -1
  179. package/src/authRecovery.test.ts +43 -0
  180. package/src/authRecovery.ts +16 -10
  181. package/src/authTokens.ts +6 -2
  182. package/src/authVerification.test.ts +22 -0
  183. package/src/browserLogsRoute.ts +110 -0
  184. package/src/configurationPlugin.test.ts +1 -11
  185. package/src/expressServer.ts +10 -0
  186. package/src/frameworkModelNames.test.ts +62 -0
  187. package/src/frameworkModelNames.ts +33 -0
  188. package/src/index.ts +7 -0
  189. package/src/isolated/migrateCliConnect.isolated.ts +51 -0
  190. package/src/mcp/auth.test.ts +34 -1
  191. package/src/migrations/cli.test.ts +0 -23
  192. package/src/models/mcpServiceToken.ts +4 -3
  193. package/src/models/notification.ts +3 -2
  194. package/src/models/notificationPreference.ts +1 -1
  195. package/src/notifications/notificationsApp.test.ts +24 -1
  196. package/src/notifiers/slackNotifier.test.ts +186 -1
  197. package/src/notifiers/slackNotifier.ts +167 -8
  198. package/src/orgs/orgPlugin.ts +1 -1
  199. package/src/orgs/organizationModel.ts +11 -6
  200. package/src/plugins.test.ts +5 -0
  201. package/src/plugins.ts +3 -0
  202. package/src/realtime/realtimeApp.ts +1 -1
  203. package/src/sync/integration.test.ts +2 -2
  204. package/src/terrenoApp.ts +3 -0
  205. package/src/types.d.ts +1 -0
  206. package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
  207. package/tsconfig.json +13 -54
  208. 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
- var __assign = (this && this.__assign) || function () {
9
- __assign = Object.assign || function(t) {
10
- for (var s, i = 1, n = arguments.length; i < n; i++) {
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
- var doc = Object.assign({
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(function (_layer) {
32
- iterateStack('', null, _layer, function (path, routeLayer, 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
- var schema = getSchema(layer.handle);
25
+ const schema = getSchema(layer.handle);
37
26
  if (!schema || !layer.method) {
38
27
  return;
39
28
  }
40
- var operation = Object.assign({}, schema);
29
+ const operation = Object.assign({}, schema);
41
30
  // Add route params to schema
42
31
  if (routeLayer && routeLayer.keys && routeLayer.keys.length) {
43
- var keys_1 = {};
44
- var params_1 = routeLayer.keys.map(function (k, i) {
45
- var prev = i > 0 && routeLayer.keys[i - 1];
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
- var param;
39
+ let param;
51
40
  if (schema.parameters) {
52
- param = schema.parameters.find(function (p) { return p.name === k.name && p.in === 'path'; });
41
+ param = schema.parameters.find((p) => p.name === k.name && p.in === 'path');
53
42
  }
54
43
  // Reformat the path
55
- keys_1[k.name] = '{' + k.name + '}';
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(function (e) { return e; });
52
+ .filter((e) => e);
64
53
  if (schema.parameters) {
65
- schema.parameters.forEach(function (p) {
66
- if (p.name && !params_1.find(function (pp) { return p.name === pp.name; })) {
67
- params_1.push(p);
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 = params_1.filter(function (p) { return typeof p.name === 'string' && p.name; });
60
+ operation.parameters = params.filter((p) => typeof p.name === 'string' && p.name);
72
61
  try {
73
- path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)'), { encode: function (value) { return value; } })(keys_1);
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(function (l) {
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
- var r_1 = layer.regexp.toString();
103
- layer.route.path.forEach(function (p, i) { return iterateStack(path + p, layer, __assign(__assign({}, layer), {
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(function (k) { return typeof p === 'string' ? p.includes("/:".concat(k.name)) : false; }),
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("(".concat(r_1.substring(2, r_1.length - 3).split('|')[i], ")")), route: __assign(__assign({}, layer.route), { path: '' }) }), cb); });
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(function (l) { return iterateStack(path + layer.route.path, layer, l, cb); });
102
+ layer.route.stack.forEach((l) => iterateStack(path + layer.route.path, layer, l, cb));
111
103
  }
112
104
  function processComplexMatch(thing, keys) {
113
- var i = 0;
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, function () { return "{".concat(keys[i++].name, "}"); })
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
- var match = thing
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
- var schemas = new Map();
4
+ const schemas = new Map();
5
5
  module.exports = {
6
- set: function (handler, schema) {
6
+ set: (handler, schema) => {
7
7
  schemas.set(handler, schema);
8
8
  },
9
- get: function (handler) {
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
- var __rest = (this && this.__rest) || function (s, e) {
5
- var t = {};
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
7
- t[p] = s[p];
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("window.onload = function () {\n window.ui = SwaggerUIBundle({\n url: '".concat(documentUrl, "',\n dom_id: '#swagger-ui',\n ").concat((plugins === null || plugins === void 0 ? void 0 : plugins.length) ? "plugins: [".concat(plugins, "],") : '', "\n ...").concat(JSON.stringify(options), "\n })\n}"));
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', "\n <link rel=\"stylesheet\" type=\"text/css\" href=\"./swagger-ui.css\" >\n ", "\n <div id=\"swagger-ui\"></div>\n <script src=\"./swagger-ui-bundle.js\"></script>\n <script src=\"./swagger-ui-standalone-preset.js\"></script>\n <script src=\"./swagger-ui-init.js\"></script>\n "));
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 "<!DOCTYPE html>\n<html>\n <head>\n <title>".concat(title, "</title>\n <meta charset=\"utf-8\"/>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <style>\n html {\n box-sizing: border-box;\n overflow: -moz-scrollbars-vertical;\n overflow-y: scroll;\n }\n *,\n *:before,\n *:after {\n box-sizing: inherit;\n }\n body {\n margin: 0;\n padding: 0;\n background: #fafafa;\n }\n </style>\n ").concat(head, "\n </head>\n <body>\n ").concat(body, "\n </body>\n</html>\n ");
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
- var __assign = (this && this.__assign) || function () {
5
- __assign = Object.assign || function(t) {
6
- for (var s, i = 1, n = arguments.length; i < n; i++) {
7
- s = arguments[i];
8
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
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
- var ajv;
63
- var validate;
35
+ let ajv;
36
+ let validate;
64
37
  function makeValidator() {
65
- var reqSchema = structuredClone(BASE_REQ_SCHEMA);
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(function (p) {
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
- var name_1 = p.name.toLowerCase();
80
- reqSchema.properties.headers.properties[name_1] = p.schema;
81
- p.required && !reqSchema.properties.headers.required.includes(p.name) && reqSchema.properties.headers.required.push(name_1);
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(function (_a) {
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("Validation of content type not supported: ".concat(contentType));
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
- var r = req;
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: __assign({}, req.query),
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: __assign({}, req.params),
113
+ value: { ...req.params },
142
114
  writable: true,
143
115
  enumerable: true,
144
116
  configurable: true
145
117
  });
146
118
  }
147
- var validationStatus = validate(r);
119
+ const validationStatus = validate(r);
148
120
  if (validationStatus === true) {
149
121
  return next();
150
122
  }
151
123
  // build error?
152
- var err = new Error('Request validation failed');
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
- var api_1 = require("./api");
41
- var versionConfig_1 = require("./models/versionConfig");
42
- var DEFAULT_WARNING_MESSAGE = "A new version is available. Please update for the best experience.";
43
- var DEFAULT_REQUIRED_MESSAGE = "This version is no longer supported. Please update to continue.";
44
- var DEFAULT_POLLING_INTERVAL_MINUTES = 1440;
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
- var VersionCheckPlugin = /** @class */ (function () {
50
- function VersionCheckPlugin() {
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
- VersionCheckPlugin.prototype.register = function (app) {
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
- var headerValue = function (req, header) {
5
- var raw = req.headers[header.toLowerCase()];
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
- var claimKey = function (_a) {
41
- var source = _a.source, eventId = _a.eventId;
42
- return "".concat(source, "\0").concat(eventId);
4
+ const claimKey = ({ source, eventId }) => {
5
+ return `${source}\0${eventId}`;
43
6
  };
44
- var createMemoryIdempotencyStore = function () {
45
- var claimed = new Set();
46
- var claim = function (args) { return __awaiter(void 0, void 0, void 0, function () {
47
- var key;
48
- return __generator(this, function (_a) {
49
- key = claimKey(args);
50
- if (claimed.has(key)) {
51
- return [2 /*return*/, "duplicate"];
52
- }
53
- claimed.add(key);
54
- return [2 /*return*/, "claimed"];
55
- });
56
- }); };
57
- var release = function (args) { return __awaiter(void 0, void 0, void 0, function () {
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;