@terreno/api 0.25.0 → 0.27.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 (114) hide show
  1. package/.ai/guidelines/core.md +1 -0
  2. package/README.md +4 -3
  3. package/dist/__tests__/openApiCompat.test.js +8 -2
  4. package/dist/__tests__/versionCheckPlugin.test.js +15 -0
  5. package/dist/actions.openApi.test.js +1 -0
  6. package/dist/actions.test.js +1 -0
  7. package/dist/api.arrayOperations.test.js +1 -0
  8. package/dist/api.coverage.test.d.ts +1 -0
  9. package/dist/api.coverage.test.js +191 -0
  10. package/dist/api.errorPaths.test.d.ts +1 -0
  11. package/dist/api.errorPaths.test.js +278 -0
  12. package/dist/api.errors.test.js +1 -0
  13. package/dist/api.hooks.test.js +1 -0
  14. package/dist/api.js +160 -167
  15. package/dist/api.query.test.js +1 -0
  16. package/dist/api.test.js +1 -0
  17. package/dist/auth.js +1 -0
  18. package/dist/auth.test.js +122 -0
  19. package/dist/betterAuthApp.test.js +1 -2
  20. package/dist/betterAuthSetup.js +1 -0
  21. package/dist/betterAuthSetup.test.js +1 -0
  22. package/dist/configuration.test.js +1 -0
  23. package/dist/configurationApp.js +1 -0
  24. package/dist/configurationPlugin.test.js +80 -0
  25. package/dist/consentApp.test.js +1 -0
  26. package/dist/docLoader.js +1 -3
  27. package/dist/envConfigurationPlugin.js +1 -0
  28. package/dist/example.js +3 -2
  29. package/dist/expressServer.js +6 -6
  30. package/dist/expressServer.test.js +23 -0
  31. package/dist/githubAuth.js +2 -0
  32. package/dist/githubAuth.test.js +1 -0
  33. package/dist/index.d.ts +9 -2
  34. package/dist/index.js +28 -3
  35. package/dist/logger.test.js +107 -0
  36. package/dist/openApi.test.js +52 -0
  37. package/dist/openApiBuilder.js +2 -1
  38. package/dist/openApiBuilder.test.js +3 -2
  39. package/dist/openApiValidator.js +1 -0
  40. package/dist/openApiValidator.test.js +41 -0
  41. package/dist/permissions.middleware.test.js +1 -0
  42. package/dist/permissions.test.js +1 -0
  43. package/dist/plugins.js +8 -0
  44. package/dist/plugins.test.js +1 -0
  45. package/dist/populate.js +4 -2
  46. package/dist/populate.test.js +1 -0
  47. package/dist/realtime/realtime.test.js +13 -3
  48. package/dist/realtime/types.d.ts +1 -1
  49. package/dist/requestContext.test.js +28 -0
  50. package/dist/terrenoApp.js +1 -0
  51. package/dist/tests/createTestData.js +11 -6
  52. package/dist/tests/fixtures/compileAuthEntry.js +1 -1
  53. package/dist/tests/models.js +1 -0
  54. package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +3 -1
  55. package/package.json +7 -7
  56. package/src/__tests__/openApiCompat.test.ts +8 -2
  57. package/src/__tests__/versionCheckPlugin.test.ts +9 -0
  58. package/src/actions.openApi.test.ts +1 -0
  59. package/src/actions.test.ts +1 -0
  60. package/src/api.arrayOperations.test.ts +1 -0
  61. package/src/api.coverage.test.ts +121 -0
  62. package/src/api.errorPaths.test.ts +171 -0
  63. package/src/api.errors.test.ts +1 -0
  64. package/src/api.hooks.test.ts +1 -0
  65. package/src/api.query.test.ts +1 -0
  66. package/src/api.test.ts +1 -0
  67. package/src/api.ts +13 -9
  68. package/src/auth.test.ts +91 -2
  69. package/src/auth.ts +6 -0
  70. package/src/betterAuthApp.test.ts +3 -3
  71. package/src/betterAuthSetup.test.ts +1 -0
  72. package/src/betterAuthSetup.ts +3 -0
  73. package/src/configuration.test.ts +1 -0
  74. package/src/configurationApp.ts +2 -0
  75. package/src/configurationPlugin.test.ts +46 -1
  76. package/src/consentApp.test.ts +1 -0
  77. package/src/docLoader.ts +1 -2
  78. package/src/envConfigurationPlugin.ts +2 -0
  79. package/src/example.ts +3 -2
  80. package/src/expressServer.test.ts +13 -0
  81. package/src/expressServer.ts +5 -3
  82. package/src/githubAuth.test.ts +1 -0
  83. package/src/githubAuth.ts +2 -0
  84. package/src/index.ts +40 -2
  85. package/src/logger.test.ts +78 -0
  86. package/src/openApi.test.ts +54 -0
  87. package/src/openApiBuilder.test.ts +7 -6
  88. package/src/openApiBuilder.ts +2 -1
  89. package/src/openApiValidator.test.ts +64 -0
  90. package/src/openApiValidator.ts +1 -0
  91. package/src/permissions.middleware.test.ts +1 -0
  92. package/src/permissions.test.ts +1 -0
  93. package/src/plugins.test.ts +1 -0
  94. package/src/plugins.ts +9 -0
  95. package/src/populate.test.ts +1 -0
  96. package/src/populate.ts +4 -2
  97. package/src/realtime/realtime.test.ts +13 -3
  98. package/src/realtime/realtimeApp.ts +1 -0
  99. package/src/realtime/registry.ts +1 -0
  100. package/src/realtime/types.ts +1 -2
  101. package/src/requestContext.test.ts +32 -0
  102. package/src/terrenoApp.ts +1 -0
  103. package/src/tests/createTestData.ts +11 -6
  104. package/src/tests/fixtures/compileAuthEntry.ts +1 -1
  105. package/src/tests/models.ts +1 -0
  106. package/src/vendor/wesleytodd-openapi/lib/generate-doc.js +4 -1
  107. package/tsconfig.json +3 -3
  108. package/dist/notifiers/index.d.ts +0 -3
  109. package/dist/notifiers/index.js +0 -19
  110. package/dist/realtime/index.d.ts +0 -6
  111. package/dist/realtime/index.js +0 -27
  112. package/src/notifiers/index.ts +0 -3
  113. package/src/realtime/index.ts +0 -34
  114. /package/{types.d.ts → src/types.d.ts} +0 -0
@@ -1,6 +1,8 @@
1
+ import {DateTime} from "luxon";
1
2
  import type {HydratedDocument} from "mongoose";
2
3
  import type {PassportLocalMongooseDocument} from "passport-local-mongoose";
3
4
 
5
+ import {APIError} from "../errors";
4
6
  import {logger} from "../logger";
5
7
  import {FoodModel, RequiredModel, type User, UserModel} from "./models";
6
8
  import type {CachedTestData, TestData, TestFoods, TestRequired, TestUsers} from "./types";
@@ -41,12 +43,12 @@ export const createStandardFoods = async (users: TestUsers): Promise<TestFoods>
41
43
  FoodModel.create({
42
44
  calories: 1,
43
45
  categories: [{name: "Vegetables", show: true}],
44
- created: new Date("2021-12-03T00:00:20.000Z"),
46
+ created: DateTime.fromISO("2021-12-03T00:00:20.000Z").toJSDate(),
45
47
  eatenBy: [admin._id],
46
48
  expiration: "2026-12-31",
47
49
  hidden: false,
48
50
  lastEatenWith: {
49
- dressing: new Date("2021-12-03T19:00:30.000Z"),
51
+ dressing: DateTime.fromISO("2021-12-03T19:00:30.000Z").toJSDate(),
50
52
  },
51
53
  likesIds: [
52
54
  {likes: true, userId: admin._id},
@@ -63,7 +65,7 @@ export const createStandardFoods = async (users: TestUsers): Promise<TestFoods>
63
65
  }),
64
66
  FoodModel.create({
65
67
  calories: 100,
66
- created: new Date("2021-12-03T00:00:30.000Z"),
68
+ created: DateTime.fromISO("2021-12-03T00:00:30.000Z").toJSDate(),
67
69
  expiration: "2026-12-31",
68
70
  hidden: true,
69
71
  likesIds: [{likes: true, userId: admin._id}],
@@ -74,7 +76,7 @@ export const createStandardFoods = async (users: TestUsers): Promise<TestFoods>
74
76
  }),
75
77
  FoodModel.create({
76
78
  calories: 100,
77
- created: new Date("2021-12-03T00:00:00.000Z"),
79
+ created: DateTime.fromISO("2021-12-03T00:00:00.000Z").toJSDate(),
78
80
  eatenBy: [admin._id, notAdmin._id],
79
81
  expiration: "2026-12-31",
80
82
  hidden: false,
@@ -86,7 +88,7 @@ export const createStandardFoods = async (users: TestUsers): Promise<TestFoods>
86
88
  }),
87
89
  FoodModel.create({
88
90
  calories: 800,
89
- created: new Date("2022-01-01T00:00:00.000Z"),
91
+ created: DateTime.fromISO("2022-01-01T00:00:00.000Z").toJSDate(),
90
92
  expiration: "2026-12-31",
91
93
  hidden: false,
92
94
  likesIds: [{likes: true, userId: adminOther._id}],
@@ -165,7 +167,10 @@ export const loadTestDataFromDocuments = async (cached: CachedTestData): Promise
165
167
  !sample ||
166
168
  !withAbout
167
169
  ) {
168
- throw new Error("[createTestData] Cached test data references missing documents");
170
+ throw new APIError({
171
+ status: 500,
172
+ title: "[createTestData] Cached test data references missing documents",
173
+ });
169
174
  }
170
175
 
171
176
  return {
@@ -31,7 +31,7 @@ app.get("/secure", authenticateMiddleware(), (_req, res) => {
31
31
 
32
32
  app.use(apiUnauthorizedMiddleware);
33
33
  app.use(apiErrorMiddleware);
34
- // Terreno's fallthrough: anything reaching here surfaces as a 500. The
34
+ // Terreno's fallthrough turns requests reaching here into a 500. The
35
35
  // regression turns auth failures into exactly this kind of error.
36
36
  app.use((err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
37
37
  res.status(500).json({status: 500, title: `Fallthrough error: ${err.message}`});
@@ -126,6 +126,7 @@ const foodSchema = new Schema<Food>(
126
126
  type: Schema.Types.ObjectId,
127
127
  },
128
128
  ],
129
+ // noExplicitAny: DateOnly is a custom SchemaType not recognized by Mongoose's built-in type definitions
129
130
  // biome-ignore lint/suspicious/noExplicitAny: DateOnly is a custom SchemaType not recognized by Mongoose's built-in type definitions
130
131
  expiration: {description: "Expiration date of the food", type: DateOnly as any},
131
132
  hidden: {
@@ -68,7 +68,7 @@ module.exports = function generateDocument (baseDocument, router, basePath) {
68
68
 
69
69
  operation.parameters = params.filter((p) => typeof p.name === 'string' && p.name)
70
70
  try {
71
- path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)'))(keys, { encode: (value) => value })
71
+ path = pathToRegexp.compile(path.replace(/\*|\(\*\)/g, '(.*)'), { encode: (value) => value })(keys)
72
72
  } catch (_e) {
73
73
  // Express 5 stores path params in matchers instead of layer.keys, so keys
74
74
  // may be incomplete. Fall back to simple regex replacement of :param → {param}.
@@ -76,6 +76,9 @@ module.exports = function generateDocument (baseDocument, router, basePath) {
76
76
  }
77
77
  }
78
78
 
79
+ // Normalize any percent-encoded path parameters to OpenAPI syntax.
80
+ path = path.replace(/%7B/gi, '{').replace(/%7D/gi, '}')
81
+
79
82
  doc.paths[path] = doc.paths[path] || {}
80
83
  doc.paths[path][layer.method] = operation
81
84
  setSchema(layer.handle, operation)
package/tsconfig.json CHANGED
@@ -3,7 +3,6 @@
3
3
  // "lib": [], /* Specify library files to be included in the compilation. */
4
4
  "allowJs": true /* Allow javascript files to be compiled. */,
5
5
  "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
6
- "baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
7
6
  "declaration": true /* Generates corresponding '.d.ts' file. */,
8
7
  "downlevelIteration": true,
9
8
  "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
@@ -26,6 +25,7 @@
26
25
  /* Module Resolution Options */
27
26
  "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
28
27
  // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
28
+ "rootDir": "./src",
29
29
  // "removeComments": true, /* Do not emit comments to output. */
30
30
  "noEmit": false /* Do not emit outputs. */,
31
31
  "noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
@@ -42,7 +42,7 @@
42
42
  // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
43
43
  // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
44
44
  // "typeRoots": [], /* List of folders to include type definitions from. */
45
- // "types": ["types/*.d.ts"] /* Type declaration files to be included in compilation. */,
45
+ "types": ["bun", "node"] /* Type declaration files to be included in compilation. */,
46
46
  "skipLibCheck": true,
47
47
  // "importHelpers": true, /* Import emit helpers from 'tslib'. */
48
48
  // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
@@ -56,5 +56,5 @@
56
56
  "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
57
57
  },
58
58
  "exclude": ["node_modules"],
59
- "include": ["src/**/*.ts*", "src/*.ts", "src/**/*.js", "types.d.ts"]
59
+ "include": ["src/**/*.ts*", "src/*.ts", "src/**/*.js"]
60
60
  }
@@ -1,3 +0,0 @@
1
- export * from "./googleChatNotifier";
2
- export * from "./slackNotifier";
3
- export * from "./zoomNotifier";
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./googleChatNotifier"), exports);
18
- __exportStar(require("./slackNotifier"), exports);
19
- __exportStar(require("./zoomNotifier"), exports);
@@ -1,6 +0,0 @@
1
- export { startChangeStreamWatcher, stopChangeStreamWatcher } from "./changeStreamWatcher";
2
- export { matchesQuery } from "./queryMatcher";
3
- export { addQuerySubscription, clearQueryStore, computeQueryId, getQuerySubscriptionsForCollection, removeAllSocketQueries, removeQuerySubscription, } from "./queryStore";
4
- export { installRealtimeSocketHandlers, MAX_DOCUMENT_SUBSCRIPTIONS, MAX_MODEL_SUBSCRIPTIONS, MAX_QUERY_SUBSCRIPTIONS, RealtimeApp, type RealtimeSocketLike, } from "./realtimeApp";
5
- export { clearRealtimeRegistry, findRegistryEntryByCollection, findRegistryEntryByRoutePath, getRealtimeRegistry, type RealtimeRegistryEntry, registerRealtime, } from "./registry";
6
- export type { ChangeStreamConfig, DocumentSubscription, QuerySubscription, RealtimeAppOptions, RealtimeConfig, RealtimeEvent, } from "./types";
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerRealtime = exports.getRealtimeRegistry = exports.findRegistryEntryByRoutePath = exports.findRegistryEntryByCollection = exports.clearRealtimeRegistry = exports.RealtimeApp = exports.MAX_QUERY_SUBSCRIPTIONS = exports.MAX_MODEL_SUBSCRIPTIONS = exports.MAX_DOCUMENT_SUBSCRIPTIONS = exports.installRealtimeSocketHandlers = exports.removeQuerySubscription = exports.removeAllSocketQueries = exports.getQuerySubscriptionsForCollection = exports.computeQueryId = exports.clearQueryStore = exports.addQuerySubscription = exports.matchesQuery = exports.stopChangeStreamWatcher = exports.startChangeStreamWatcher = void 0;
4
- var changeStreamWatcher_1 = require("./changeStreamWatcher");
5
- Object.defineProperty(exports, "startChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.startChangeStreamWatcher; } });
6
- Object.defineProperty(exports, "stopChangeStreamWatcher", { enumerable: true, get: function () { return changeStreamWatcher_1.stopChangeStreamWatcher; } });
7
- var queryMatcher_1 = require("./queryMatcher");
8
- Object.defineProperty(exports, "matchesQuery", { enumerable: true, get: function () { return queryMatcher_1.matchesQuery; } });
9
- var queryStore_1 = require("./queryStore");
10
- Object.defineProperty(exports, "addQuerySubscription", { enumerable: true, get: function () { return queryStore_1.addQuerySubscription; } });
11
- Object.defineProperty(exports, "clearQueryStore", { enumerable: true, get: function () { return queryStore_1.clearQueryStore; } });
12
- Object.defineProperty(exports, "computeQueryId", { enumerable: true, get: function () { return queryStore_1.computeQueryId; } });
13
- Object.defineProperty(exports, "getQuerySubscriptionsForCollection", { enumerable: true, get: function () { return queryStore_1.getQuerySubscriptionsForCollection; } });
14
- Object.defineProperty(exports, "removeAllSocketQueries", { enumerable: true, get: function () { return queryStore_1.removeAllSocketQueries; } });
15
- Object.defineProperty(exports, "removeQuerySubscription", { enumerable: true, get: function () { return queryStore_1.removeQuerySubscription; } });
16
- var realtimeApp_1 = require("./realtimeApp");
17
- Object.defineProperty(exports, "installRealtimeSocketHandlers", { enumerable: true, get: function () { return realtimeApp_1.installRealtimeSocketHandlers; } });
18
- Object.defineProperty(exports, "MAX_DOCUMENT_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_DOCUMENT_SUBSCRIPTIONS; } });
19
- Object.defineProperty(exports, "MAX_MODEL_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_MODEL_SUBSCRIPTIONS; } });
20
- Object.defineProperty(exports, "MAX_QUERY_SUBSCRIPTIONS", { enumerable: true, get: function () { return realtimeApp_1.MAX_QUERY_SUBSCRIPTIONS; } });
21
- Object.defineProperty(exports, "RealtimeApp", { enumerable: true, get: function () { return realtimeApp_1.RealtimeApp; } });
22
- var registry_1 = require("./registry");
23
- Object.defineProperty(exports, "clearRealtimeRegistry", { enumerable: true, get: function () { return registry_1.clearRealtimeRegistry; } });
24
- Object.defineProperty(exports, "findRegistryEntryByCollection", { enumerable: true, get: function () { return registry_1.findRegistryEntryByCollection; } });
25
- Object.defineProperty(exports, "findRegistryEntryByRoutePath", { enumerable: true, get: function () { return registry_1.findRegistryEntryByRoutePath; } });
26
- Object.defineProperty(exports, "getRealtimeRegistry", { enumerable: true, get: function () { return registry_1.getRealtimeRegistry; } });
27
- Object.defineProperty(exports, "registerRealtime", { enumerable: true, get: function () { return registry_1.registerRealtime; } });
@@ -1,3 +0,0 @@
1
- export * from "./googleChatNotifier";
2
- export * from "./slackNotifier";
3
- export * from "./zoomNotifier";
@@ -1,34 +0,0 @@
1
- export {startChangeStreamWatcher, stopChangeStreamWatcher} from "./changeStreamWatcher";
2
- export {matchesQuery} from "./queryMatcher";
3
- export {
4
- addQuerySubscription,
5
- clearQueryStore,
6
- computeQueryId,
7
- getQuerySubscriptionsForCollection,
8
- removeAllSocketQueries,
9
- removeQuerySubscription,
10
- } from "./queryStore";
11
- export {
12
- installRealtimeSocketHandlers,
13
- MAX_DOCUMENT_SUBSCRIPTIONS,
14
- MAX_MODEL_SUBSCRIPTIONS,
15
- MAX_QUERY_SUBSCRIPTIONS,
16
- RealtimeApp,
17
- type RealtimeSocketLike,
18
- } from "./realtimeApp";
19
- export {
20
- clearRealtimeRegistry,
21
- findRegistryEntryByCollection,
22
- findRegistryEntryByRoutePath,
23
- getRealtimeRegistry,
24
- type RealtimeRegistryEntry,
25
- registerRealtime,
26
- } from "./registry";
27
- export type {
28
- ChangeStreamConfig,
29
- DocumentSubscription,
30
- QuerySubscription,
31
- RealtimeAppOptions,
32
- RealtimeConfig,
33
- RealtimeEvent,
34
- } from "./types";
File without changes