@terreno/api 0.29.0 → 0.31.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 (79) hide show
  1. package/CHANGELOG.md +2 -43
  2. package/LICENSE +21 -202
  3. package/dist/actions.js +17 -8
  4. package/dist/actions.openApi.test.js +1 -3
  5. package/dist/actions.test.js +8 -5
  6. package/dist/api.arrayOperations.test.js +16 -8
  7. package/dist/api.coverage.test.js +2 -3
  8. package/dist/api.d.ts +3 -2
  9. package/dist/api.errorPaths.test.js +608 -1
  10. package/dist/api.errors.test.js +9 -0
  11. package/dist/api.js +137 -170
  12. package/dist/api.query.test.js +20 -8
  13. package/dist/api.test.js +12 -6
  14. package/dist/auth.coverage.test.d.ts +1 -0
  15. package/dist/auth.coverage.test.js +202 -0
  16. package/dist/auth.test.js +159 -0
  17. package/dist/betterAuthSetup.d.ts +15 -1
  18. package/dist/betterAuthSetup.js +4 -6
  19. package/dist/configurationPlugin.js +2 -2
  20. package/dist/consentApp.test.js +1 -5
  21. package/dist/docLoader.js +5 -1
  22. package/dist/envConfigurationPlugin.d.ts +1 -1
  23. package/dist/envConfigurationPlugin.js +0 -2
  24. package/dist/errors.d.ts +14 -0
  25. package/dist/errors.js +24 -2
  26. package/dist/errors.test.js +137 -0
  27. package/dist/expressServer.js +11 -5
  28. package/dist/githubAuth.js +1 -4
  29. package/dist/httpClient.js +5 -1
  30. package/dist/openApiBuilder.test.js +0 -2
  31. package/dist/openApiValidator.test.js +34 -0
  32. package/dist/plugins.d.ts +6 -5
  33. package/dist/plugins.js +56 -10
  34. package/dist/plugins.test.js +73 -17
  35. package/dist/populate.test.js +9 -12
  36. package/dist/realtime/realtime.test.js +231 -0
  37. package/dist/realtime/realtimeApp.d.ts +1 -1
  38. package/dist/realtime/realtimeApp.js +6 -2
  39. package/dist/realtime/realtimeAppSetup.test.d.ts +1 -0
  40. package/dist/realtime/realtimeAppSetup.test.js +213 -0
  41. package/dist/realtime/registry.d.ts +3 -2
  42. package/dist/tests/models.d.ts +27 -11
  43. package/dist/tests/models.js +5 -3
  44. package/dist/tests/testHelper.d.ts +9 -3
  45. package/package.json +4 -5
  46. package/src/actions.openApi.test.ts +7 -10
  47. package/src/actions.test.ts +27 -15
  48. package/src/actions.ts +21 -12
  49. package/src/api.arrayOperations.test.ts +16 -8
  50. package/src/api.coverage.test.ts +9 -10
  51. package/src/api.errorPaths.test.ts +360 -4
  52. package/src/api.errors.test.ts +12 -0
  53. package/src/api.query.test.ts +20 -8
  54. package/src/api.test.ts +12 -6
  55. package/src/api.ts +162 -171
  56. package/src/auth.coverage.test.ts +101 -0
  57. package/src/auth.test.ts +125 -2
  58. package/src/betterAuthSetup.ts +7 -7
  59. package/src/configurationPlugin.ts +2 -2
  60. package/src/consentApp.test.ts +12 -12
  61. package/src/docLoader.ts +6 -2
  62. package/src/envConfigurationPlugin.ts +2 -6
  63. package/src/errors.test.ts +106 -1
  64. package/src/errors.ts +25 -1
  65. package/src/expressServer.ts +11 -5
  66. package/src/githubAuth.ts +1 -3
  67. package/src/httpClient.ts +6 -2
  68. package/src/models/versionConfig.ts +1 -1
  69. package/src/openApiBuilder.test.ts +24 -9
  70. package/src/openApiValidator.test.ts +41 -0
  71. package/src/plugins.test.ts +59 -9
  72. package/src/plugins.ts +81 -39
  73. package/src/populate.test.ts +25 -16
  74. package/src/realtime/changeStreamWatcher.ts +8 -1
  75. package/src/realtime/realtime.test.ts +239 -0
  76. package/src/realtime/realtimeApp.ts +8 -5
  77. package/src/realtime/realtimeAppSetup.test.ts +161 -0
  78. package/src/realtime/registry.ts +3 -4
  79. package/src/tests/models.ts +8 -6
package/CHANGELOG.md CHANGED
@@ -1,46 +1,5 @@
1
1
  # Changelog
2
2
 
3
- ## 0.20.0
3
+ The changelog for all `@terreno/*` packages lives at the repository root:
4
4
 
5
- ### Changed (breaking)
6
-
7
- - **`ConfigurationApp` `POST {basePath}/list-secrets` no longer persists secret values.** Previously it resolved secrets from the provider and wrote the resolved plaintext values into the configuration document. It is now a **read-only validation/status** endpoint: it reports, per secret field, only non-sensitive metadata (`path`, `secretName`, `version`, and a boolean `resolvable`/`isConfigured`) and never writes to the document or returns secret values. A `POST {basePath}/validate-secrets` alias with the same behavior is also registered.
8
- - **`ConfigurationApp` `PATCH {basePath}` strips `secret: true` fields** from the incoming body, so a secret value can never be written through the update path. Secret fields are read-only via this surface.
9
- - **`configurationPlugin` no longer adds the `_singleton` unique index by default.** It is now opt-in via `enforceSingletonIndex: true` so it does not double-enforce or conflict with consumers that already guarantee a single non-deleted document via the pre-save guard or their own soft-delete plugin/indexes.
10
- - **`configurationPlugin` singleton semantics are now soft-delete aware.** `getConfig`, `updateConfig`, and the pre-save guard operate on `{deleted: false}` when the schema has a `deleted` path (e.g. via `isDeletedPlugin`). A soft-deleted document no longer blocks creating a new singleton; hard deletes (`deleteOne`/`deleteMany`/`findOneAndDelete`) remain blocked.
11
- - **`configurationPlugin.updateConfig` now applies updates via `findOneAndUpdate({$set})` with dotted paths** instead of `Object.assign` + `doc.save()`. This preserves sibling fields inside nested subdocuments on partial patches and tolerates legacy/out-of-schema fields already persisted under `strict: "throw"`.
12
-
13
- ### Added
14
-
15
- - **`SecretProvider.getSecret(secretName, version?)`** — optional `version` parameter. `GcpSecretProvider` resolves `projects/{projectId}/secrets/{name}/versions/{version}` (default `latest`, full resource paths still honored); `EnvSecretProvider` ignores it. Secret fields can declare a `secretVersion` schema option, surfaced on `SecretFieldMeta.version` and passed through `resolveSecrets`.
16
- - **`CompositeSecretProvider`** — composes an ordered list of providers and returns the first non-null result; a failing provider is warn-logged (secret name only) and resolution falls through to the next.
17
- - **`CachingSecretProvider`** — wraps any provider with an in-memory TTL cache keyed by `secretName@version`, with `clear()` / `clearKey()` for rotation and tests. Caches `null` results. Never logs values.
18
- - **`ConfigurationApp` pluggable permissions** — `permissions: {read?, update?, meta?, listSecrets?}` accepts terreno permission functions (e.g. `[IsStaff]`), AND-combined like `modelRouter`. Defaults to admin-only for every route.
19
- - **`ConfigurationApp` lifecycle hooks** — `preUpdate(body, req)` (validate/normalize) and `postUpdate(config, prevValue, req)` (audit logging). Both payloads have secret values redacted.
20
- - **`flattenToDotPaths`** — exported helper used by `updateConfig`.
21
-
22
- ### Migration
23
-
24
- - If you relied on `list-secrets` to populate secret values into the configuration document, stop. Resolve secrets on-demand at runtime via `Model.resolveSecrets(provider)` (returns an in-memory `Map`) and read them from memory; never persist them.
25
- - If you depended on the `_singleton` unique index, pass `configurationPlugin(schema, {enforceSingletonIndex: true})`.
26
- - For GCP-with-env-fallback and caching, compose `new CachingSecretProvider(new CompositeSecretProvider([gcp, env]), {ttlMs})`.
27
-
28
- ## 0.16.0
29
-
30
- ### Added
31
-
32
- - **modelRouter actions** — Declare `instanceActions` and `collectionActions` on `ModelRouterOptions` for named operations at `/resource/:id/action` and `/resource/action`. Handlers receive `{req, res, user, doc?, body, query}`; return values are wrapped in `{data: ...}`. OpenAPI operations are emitted automatically when `openApi` is configured.
33
- - **`loadDocOr404`** — Shared document loader used by permission middleware and instance actions (soft-delete-aware 404 metadata preserved).
34
-
35
- ### Changed
36
-
37
- - Permission middleware doc loading now delegates to `loadDocOr404` (behavior-preserving).
38
-
39
- ### Dependencies
40
-
41
- - Added `@asteasolutions/zod-to-openapi` ^8.5.0 (direct dependency).
42
- - Added **`zod` ^4.3.6 as a peer dependency** — backends that define action Zod schemas must install `zod`.
43
-
44
- ### Migration
45
-
46
- - Regenerate frontend SDKs after adding actions; `operationId` values follow `{tag}_{actionName}` (e.g. `todos_markComplete`).
5
+ [../CHANGELOG.md](../CHANGELOG.md)
package/LICENSE CHANGED
@@ -1,202 +1,21 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2020 Josh Gachnang
190
- Copyright 2022 Flourish Health Inc.
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Flourish Health, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/actions.js CHANGED
@@ -121,15 +121,22 @@ var runActionPermissions = function (action, scope, model, req, doc) { return __
121
121
  return [2 /*return*/];
122
122
  }
123
123
  if (!doc) {
124
+ // Status kept at 405 for backwards compatibility with the same pre-document permission denial
125
+ // in modelRouter's array operations; changing it would break consumers matching on it.
124
126
  throw new errors_1.APIError({
127
+ code: "action-access-denied",
128
+ detail: "Access to ".concat(method.toUpperCase(), " on ").concat(model.modelName, " ") + "denied for ".concat((_a = req.user) === null || _a === void 0 ? void 0 : _a.id),
129
+ meta: { action: method.toUpperCase(), model: model.modelName },
125
130
  status: 405,
126
- title: "Access to ".concat(method.toUpperCase(), " on ").concat(model.modelName, " ") + "denied for ".concat((_a = req.user) === null || _a === void 0 ? void 0 : _a.id),
131
+ title: "Access denied",
127
132
  });
128
133
  }
129
- throw new errors_1.APIError({
130
- status: 403,
131
- title: "Access to ".concat(method.toUpperCase(), " on ").concat(model.modelName, ":").concat(req.params.id, " ") +
134
+ throw new errors_1.ForbiddenError({
135
+ code: "action-access-denied",
136
+ detail: "Access to ".concat(method.toUpperCase(), " on ").concat(model.modelName, ":").concat(req.params.id, " ") +
132
137
  "denied for ".concat((_b = req.user) === null || _b === void 0 ? void 0 : _b.id),
138
+ meta: { action: method.toUpperCase(), model: model.modelName },
139
+ title: "Access denied",
133
140
  });
134
141
  }
135
142
  });
@@ -161,9 +168,10 @@ var validateActionRequest = function (_a) {
161
168
  if (action.body) {
162
169
  var parsedBody = action.body.safeParse(req.body);
163
170
  if (!parsedBody.success) {
164
- throw new errors_1.APIError({
171
+ throw new errors_1.ValidationError({
172
+ code: "action-body-validation-failed",
173
+ detail: "The request body did not match the action's schema",
165
174
  fields: flattenZodFieldErrors(parsedBody.error.flatten().fieldErrors),
166
- status: 400,
167
175
  title: "Validation failed",
168
176
  });
169
177
  }
@@ -176,9 +184,10 @@ var validateActionRequest = function (_a) {
176
184
  if (action.query) {
177
185
  var parsedQuery = action.query.safeParse(req.query);
178
186
  if (!parsedQuery.success) {
179
- throw new errors_1.APIError({
187
+ throw new errors_1.ValidationError({
188
+ code: "action-query-validation-failed",
189
+ detail: "The query parameters did not match the action's schema",
180
190
  fields: flattenZodFieldErrors(parsedQuery.error.flatten().fieldErrors),
181
- status: 400,
182
191
  title: "Validation failed",
183
192
  });
184
193
  }
@@ -66,8 +66,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
66
66
  return (mod && mod.__esModule) ? mod : { "default": mod };
67
67
  };
68
68
  Object.defineProperty(exports, "__esModule", { value: true });
69
- // noExplicitAny: test mock typing
70
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
71
69
  var bun_test_1 = require("bun:test");
72
70
  var supertest_1 = __importDefault(require("supertest"));
73
71
  var api_1 = require("./api");
@@ -226,7 +224,7 @@ var assertActionOpenApiSpec = function (spec) {
226
224
  var app;
227
225
  (0, bun_test_1.beforeEach)(function () {
228
226
  var configureApp = function (router, routerOptions) {
229
- router.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, __assign(__assign({}, foodActionRouterOptions), routerOptions)));
227
+ router.use("/food", (0, api_1.modelRouter)(tests_1.FoodModel, __assign(__assign({}, foodActionRouterOptions), { openApi: routerOptions === null || routerOptions === void 0 ? void 0 : routerOptions.openApi })));
230
228
  };
231
229
  app = new terrenoApp_1.TerrenoApp({
232
230
  configureApp: configureApp,
@@ -66,8 +66,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
66
66
  return (mod && mod.__esModule) ? mod : { "default": mod };
67
67
  };
68
68
  Object.defineProperty(exports, "__esModule", { value: true });
69
- // noExplicitAny: test mock typing
70
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
71
69
  var bun_test_1 = require("bun:test");
72
70
  var mongoose_1 = require("mongoose");
73
71
  var supertest_1 = __importDefault(require("supertest"));
@@ -265,7 +263,8 @@ var allPermissions = {
265
263
  return [4 /*yield*/, agent.post("/food/disabled").send({}).expect(405)];
266
264
  case 2:
267
265
  res = _a.sent();
268
- (0, bun_test_1.expect)(res.body.title).toContain("Access to CREATE on Food denied");
266
+ (0, bun_test_1.expect)(res.body.title).toBe("Access denied");
267
+ (0, bun_test_1.expect)(res.body.detail).toContain("Access to CREATE on Food denied");
269
268
  return [2 /*return*/];
270
269
  }
271
270
  });
@@ -485,7 +484,8 @@ var allPermissions = {
485
484
  return [4 /*yield*/, agent.post("/food/adminOnly").send({}).expect(405)];
486
485
  case 2:
487
486
  res = _a.sent();
488
- (0, bun_test_1.expect)(res.body.title).toContain("Access to CREATE on Food denied");
487
+ (0, bun_test_1.expect)(res.body.title).toBe("Access denied");
488
+ (0, bun_test_1.expect)(res.body.detail).toContain("Access to CREATE on Food denied");
489
489
  return [2 /*return*/];
490
490
  }
491
491
  });
@@ -522,7 +522,8 @@ var allPermissions = {
522
522
  return [4 /*yield*/, agent.post("/food/".concat(adminFood._id, "/ownerOnly")).send({}).expect(403)];
523
523
  case 3:
524
524
  res = _a.sent();
525
- (0, bun_test_1.expect)(res.body.title).toContain("Access to UPDATE on Food:".concat(adminFood._id, " denied"));
525
+ (0, bun_test_1.expect)(res.body.title).toBe("Access denied");
526
+ (0, bun_test_1.expect)(res.body.detail).toContain("Access to UPDATE on Food:".concat(adminFood._id, " denied"));
526
527
  return [2 /*return*/];
527
528
  }
528
529
  });
@@ -607,6 +608,7 @@ var allPermissions = {
607
608
  case 1:
608
609
  res = _a.sent();
609
610
  (0, bun_test_1.expect)(res.body.title).toBe("Validation failed");
611
+ (0, bun_test_1.expect)(res.body.code).toBe("action-body-validation-failed");
610
612
  (0, bun_test_1.expect)(res.body.meta.fields.email).toBeDefined();
611
613
  return [2 /*return*/];
612
614
  }
@@ -666,6 +668,7 @@ var allPermissions = {
666
668
  case 1:
667
669
  res = _a.sent();
668
670
  (0, bun_test_1.expect)(res.body.title).toBe("Validation failed");
671
+ (0, bun_test_1.expect)(res.body.code).toBe("action-query-validation-failed");
669
672
  (0, bun_test_1.expect)(res.body.meta.fields.email).toBeDefined();
670
673
  return [2 /*return*/];
671
674
  }
@@ -145,7 +145,8 @@ var transformers_1 = require("./transformers");
145
145
  .expect(400)];
146
146
  case 1:
147
147
  res = _a.sent();
148
- (0, bun_test_1.expect)(res.body.title).toBe("Malformed body, array operations should have a single, top level key, got: name,show");
148
+ (0, bun_test_1.expect)(res.body.title).toBe("Malformed array operation body");
149
+ (0, bun_test_1.expect)(res.body.detail).toBe("Malformed body, array operations should have a single, top level key, got: name,show");
149
150
  return [4 /*yield*/, agent
150
151
  .post("/food/".concat(apple._id, "/categories"))
151
152
  .send({ categories: { name: "Good Seller", show: false } })
@@ -175,7 +176,8 @@ var transformers_1 = require("./transformers");
175
176
  .expect(404)];
176
177
  case 1:
177
178
  res = _a.sent();
178
- (0, bun_test_1.expect)(res.body.title).toBe("Could not find categories/xyz");
179
+ (0, bun_test_1.expect)(res.body.title).toBe("Array item not found");
180
+ (0, bun_test_1.expect)(res.body.detail).toBe("Could not find categories/xyz");
179
181
  return [4 /*yield*/, agent
180
182
  .patch("/food/".concat(apple._id, "/categories/").concat(apple.categories[1]._id))
181
183
  .send({ categories: { name: "Good Seller", show: false } })
@@ -195,7 +197,8 @@ var transformers_1 = require("./transformers");
195
197
  case 0: return [4 /*yield*/, agent.delete("/food/".concat(apple._id, "/categories/xyz")).expect(404)];
196
198
  case 1:
197
199
  res = _a.sent();
198
- (0, bun_test_1.expect)(res.body.title).toBe("Could not find categories/xyz");
200
+ (0, bun_test_1.expect)(res.body.title).toBe("Array item not found");
201
+ (0, bun_test_1.expect)(res.body.detail).toBe("Could not find categories/xyz");
199
202
  return [4 /*yield*/, agent
200
203
  .delete("/food/".concat(apple._id, "/categories/").concat(apple.categories[0]._id))
201
204
  .expect(200)];
@@ -234,7 +237,8 @@ var transformers_1 = require("./transformers");
234
237
  .expect(404)];
235
238
  case 1:
236
239
  res = _a.sent();
237
- (0, bun_test_1.expect)(res.body.title).toBe("Could not find tags/xyz");
240
+ (0, bun_test_1.expect)(res.body.title).toBe("Array item not found");
241
+ (0, bun_test_1.expect)(res.body.detail).toBe("Could not find tags/xyz");
238
242
  return [4 /*yield*/, agent
239
243
  .patch("/food/".concat(apple._id, "/tags/healthy"))
240
244
  .send({ tags: "unhealthy" })
@@ -253,7 +257,8 @@ var transformers_1 = require("./transformers");
253
257
  case 0: return [4 /*yield*/, agent.delete("/food/".concat(apple._id, "/tags/xyz")).expect(404)];
254
258
  case 1:
255
259
  res = _a.sent();
256
- (0, bun_test_1.expect)(res.body.title).toBe("Could not find tags/xyz");
260
+ (0, bun_test_1.expect)(res.body.title).toBe("Array item not found");
261
+ (0, bun_test_1.expect)(res.body.detail).toBe("Could not find tags/xyz");
257
262
  return [4 /*yield*/, agent.delete("/food/".concat(apple._id, "/tags/healthy")).expect(200)];
258
263
  case 2:
259
264
  res = _a.sent();
@@ -650,7 +655,8 @@ var transformers_1 = require("./transformers");
650
655
  return [4 /*yield*/, agent.post("/food/".concat(apple._id, "/tags")).send({ tags: "organic" }).expect(405)];
651
656
  case 2:
652
657
  res = _a.sent();
653
- (0, bun_test_1.expect)(res.body.title).toContain("Access to PATCH");
658
+ (0, bun_test_1.expect)(res.body.title).toBe("Access denied");
659
+ (0, bun_test_1.expect)(res.body.detail).toContain("Access to PATCH");
654
660
  return [2 /*return*/];
655
661
  }
656
662
  });
@@ -678,7 +684,8 @@ var transformers_1 = require("./transformers");
678
684
  return [4 /*yield*/, agent.post("/food/".concat(fakeId, "/tags")).send({ tags: "organic" }).expect(404)];
679
685
  case 2:
680
686
  res = _a.sent();
681
- (0, bun_test_1.expect)(res.body.title).toContain("Could not find document to PATCH");
687
+ (0, bun_test_1.expect)(res.body.title).toBe("Document not found");
688
+ (0, bun_test_1.expect)(res.body.detail).toContain("Could not find document to PATCH");
682
689
  return [2 /*return*/];
683
690
  }
684
691
  });
@@ -707,7 +714,8 @@ var transformers_1 = require("./transformers");
707
714
  return [4 /*yield*/, agent.post("/food/".concat(apple._id, "/tags")).send({ tags: "organic" }).expect(403)];
708
715
  case 2:
709
716
  res = _a.sent();
710
- (0, bun_test_1.expect)(res.body.title).toContain("Patch not allowed");
717
+ (0, bun_test_1.expect)(res.body.title).toBe("Update not allowed");
718
+ (0, bun_test_1.expect)(res.body.detail).toContain("Patch not allowed");
711
719
  return [2 /*return*/];
712
720
  }
713
721
  });
@@ -55,8 +55,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
55
55
  return (mod && mod.__esModule) ? mod : { "default": mod };
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
- // noExplicitAny: test mock typing
59
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
60
58
  var bun_test_1 = require("bun:test");
61
59
  var mongoose_1 = __importDefault(require("mongoose"));
62
60
  var supertest_1 = __importDefault(require("supertest"));
@@ -158,7 +156,8 @@ var ExplosiveModel = mongoose_1.default.model("ExplosiveCoverage", explosiveSche
158
156
  .expect(400)];
159
157
  case 1:
160
158
  res = _a.sent();
161
- (0, bun_test_1.expect)(res.body.title).toContain("PATCH Pre Update error");
159
+ (0, bun_test_1.expect)(res.body.title).toBe("Validation failed");
160
+ (0, bun_test_1.expect)(res.body.meta.fields["eatenBy.0"]).toContain("ObjectId");
162
161
  return [2 /*return*/];
163
162
  }
164
163
  });
package/dist/api.d.ts CHANGED
@@ -7,6 +7,7 @@ import { type RESTPermissions } from "./permissions";
7
7
  import type { PopulatePath } from "./populate";
8
8
  import type { RealtimeConfig } from "./realtime/types";
9
9
  import { type TerrenoTransformer } from "./transformers";
10
+ type ModelLike<T> = Model<T, any, any, any, any, any>;
10
11
  export type JSONPrimitive = string | number | boolean | null;
11
12
  export interface JSONArray extends Array<JSONValue> {
12
13
  }
@@ -283,8 +284,8 @@ export interface ModelRouterRegistration {
283
284
  * const todoRouter = modelRouter("/todos", Todo, options);
284
285
  * app.register(todoRouter);
285
286
  */
286
- export declare function modelRouter<T>(path: string, model: Model<T>, options: ModelRouterOptions<T>): ModelRouterRegistration;
287
- export declare function modelRouter<T>(model: Model<T>, options: ModelRouterOptions<T>): express.Router;
287
+ export declare function modelRouter<T>(path: string, model: ModelLike<T>, options: ModelRouterOptions<T>): ModelRouterRegistration;
288
+ export declare function modelRouter<T>(model: ModelLike<T>, options: ModelRouterOptions<T>): express.Router;
288
289
  /**
289
290
  * Options for the asyncHandler function.
290
291
  */