@terreno/api 0.30.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.
- package/CHANGELOG.md +2 -122
- package/LICENSE +21 -202
- package/dist/actions.openApi.test.js +1 -3
- package/dist/actions.test.js +0 -2
- package/dist/api.coverage.test.js +0 -2
- package/dist/api.d.ts +3 -2
- package/dist/api.errorPaths.test.js +86 -0
- package/dist/betterAuthSetup.d.ts +15 -1
- package/dist/betterAuthSetup.js +4 -6
- package/dist/configurationPlugin.js +2 -2
- package/dist/consentApp.test.js +1 -5
- package/dist/expressServer.js +11 -5
- package/dist/githubAuth.js +1 -4
- package/dist/openApiBuilder.test.js +0 -2
- package/dist/openApiValidator.test.js +34 -0
- package/dist/plugins.d.ts +3 -2
- package/dist/plugins.js +5 -1
- package/dist/plugins.test.js +12 -0
- package/dist/populate.test.js +9 -12
- package/dist/realtime/realtime.test.js +231 -0
- package/dist/realtime/realtimeApp.d.ts +1 -1
- package/dist/realtime/realtimeApp.js +6 -2
- package/dist/realtime/realtimeAppSetup.test.d.ts +1 -0
- package/dist/realtime/realtimeAppSetup.test.js +213 -0
- package/dist/tests/models.d.ts +27 -11
- package/dist/tests/models.js +5 -3
- package/dist/tests/testHelper.d.ts +9 -3
- package/package.json +4 -5
- package/src/actions.openApi.test.ts +7 -10
- package/src/actions.test.ts +19 -12
- package/src/actions.ts +2 -2
- package/src/api.coverage.test.ts +7 -9
- package/src/api.errorPaths.test.ts +47 -1
- package/src/api.ts +22 -11
- package/src/betterAuthSetup.ts +7 -7
- package/src/configurationPlugin.ts +2 -2
- package/src/consentApp.test.ts +12 -12
- package/src/expressServer.ts +11 -5
- package/src/githubAuth.ts +1 -3
- package/src/models/versionConfig.ts +1 -1
- package/src/openApiBuilder.test.ts +24 -9
- package/src/openApiValidator.test.ts +41 -0
- package/src/plugins.test.ts +14 -0
- package/src/plugins.ts +9 -4
- package/src/populate.test.ts +25 -16
- package/src/realtime/realtime.test.ts +239 -0
- package/src/realtime/realtimeApp.ts +8 -5
- package/src/realtime/realtimeAppSetup.test.ts +161 -0
- package/src/tests/models.ts +8 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,125 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The changelog for all `@terreno/*` packages lives at the repository root:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
`title`, so anywhere the framework re-wrapped an inner error and rebuilt the wrapper's text with
|
|
7
|
-
`errorMessage(inner)`, the inner error's `detail`, `code`, `meta`, `fields`, and `status` were
|
|
8
|
-
silently dropped. This release makes `modelRouter` pass those errors through instead.
|
|
9
|
-
|
|
10
|
-
### Fixed
|
|
11
|
-
|
|
12
|
-
- **`modelRouter` no longer re-wraps an `APIError` raised inside your code.** Every catch that used
|
|
13
|
-
to build a generic wrapper now re-throws an `APIError` untouched, so its `status`, `title`,
|
|
14
|
-
`detail`, `code`, and `meta` reach the client. This covers `model.create()`, the create/update
|
|
15
|
-
`doc.save()`, populate-after-create, `postCreate`, `postUpdate`, `postDelete`, `queryFilter`, the
|
|
16
|
-
list query, list serialization, `doc.deleteOne()`, every `responseHandler` call, and the
|
|
17
|
-
`preUpdate` / `doc.save()` / `postUpdate` steps of the array-operation `PATCH` helper. Previously
|
|
18
|
-
only the `transform`, `preCreate`, `preUpdate`, and `preDelete` catches had the guard. The most
|
|
19
|
-
common casualty was an `APIError` thrown from Mongoose document middleware (`pre("save")`,
|
|
20
|
-
`pre("validate")`), which reached the client as `{status: 400, title: "Create error", code:
|
|
21
|
-
"create-error"}` with the consumer's `code` and `meta` gone.
|
|
22
|
-
- **Mongoose validation and cast errors from `modelRouter` writes now carry per-field messages
|
|
23
|
-
again.** The `model.create()` and `doc.save()` catches run `mongooseErrorToAPIError` before falling
|
|
24
|
-
back to a generic wrapper, so a `ValidationError` surfaces as
|
|
25
|
-
`{status: 400, title: "Validation failed", meta: {fields: {...}}}` rather than
|
|
26
|
-
`{title: "Create error", detail: "Validation failed: name: Path \`name\` is required."}`. These
|
|
27
|
-
errors are also marked `disableExternalErrorTracking`, so bad client input stops paging Sentry.
|
|
28
|
-
- **`queryFilter` wrapper details are readable.** That catch used `String(error)`, which emitted
|
|
29
|
-
`"Error: <message>"` for an `Error` and `"[object Object]"` for a thrown non-`Error`. It now uses
|
|
30
|
-
the same message extraction as every other catch.
|
|
31
|
-
- **Framework-thrown errors follow the 0.28.0 contract.** `api.ts`, `plugins.ts`, `actions.ts`, and
|
|
32
|
-
`docLoader.ts` no longer interpolate per-occurrence values into `title`; the specific text moved to
|
|
33
|
-
`detail` (plus `meta` / `source` where it is structured), and each error carries a kebab-case
|
|
34
|
-
`code` and, where applicable, a status subclass (`BadRequestError`, `ForbiddenError`,
|
|
35
|
-
`NotFoundError`, `ValidationError`, `InternalServerError`). Titles are now stable strings, so
|
|
36
|
-
Sentry groups them by logical error instead of by occurrence.
|
|
37
|
-
- **`findOneOrNone`, `findOneOrNoneFor`, and `findExactlyOne` accept `Partial<APIErrorOptions>`** for
|
|
38
|
-
`errorArgs` instead of the deprecated `Partial<APIErrorConstructor>`. `errorArgs` is still applied
|
|
39
|
-
last, so every field including `status` remains overridable.
|
|
40
|
-
|
|
41
|
-
### Added
|
|
42
|
-
|
|
43
|
-
- **`errorDetail(error)`** — returns `` `${title}: ${detail}` `` for an `APIError` and
|
|
44
|
-
`errorMessage(error)` for anything else. Used for the `detail` of framework wrapper errors so a
|
|
45
|
-
nested `APIError`'s text is never lost if one does reach a wrapper.
|
|
46
|
-
|
|
47
|
-
### Changed (behavior)
|
|
48
|
-
|
|
49
|
-
- **`apiUnauthorizedMiddleware` only matches a plain `Error("Unauthorized")`.** It is registered
|
|
50
|
-
ahead of `apiErrorMiddleware`, and because `message` is now exactly `title`, it was rewriting **any**
|
|
51
|
-
`APIError` titled `"Unauthorized"` into a bare 401 and discarding its status, `code`, and `detail`.
|
|
52
|
-
A `new ForbiddenError({title: "Unauthorized"})` now stays a **403** with its own body; Passport's
|
|
53
|
-
plain `Error("Unauthorized")` still becomes a quiet 401.
|
|
54
|
-
- **An `APIError` thrown from a hook or from Mongoose middleware now returns its own status.**
|
|
55
|
-
Previously the wrapper's hardcoded status (usually 400, or 403 for `transform`/`preDelete`) won.
|
|
56
|
-
If you throw a non-4xx `APIError` from `postCreate`, `postUpdate`, `postDelete`, `queryFilter`,
|
|
57
|
-
`responseHandler`, or a `pre("save")` hook, clients now see that status instead of 400.
|
|
58
|
-
- **Framework error titles changed** where they used to embed per-occurrence values. The old text is
|
|
59
|
-
preserved in `detail`. Notable renames: `` `${param} is not allowed as a query param.` `` →
|
|
60
|
-
`"Query parameter not allowed"`; `` `Invalid page: ${page}` `` → `"Invalid page"`;
|
|
61
|
-
`` `Invalid date for query parameter ${key}` `` → `"Invalid date query parameter"`;
|
|
62
|
-
`` `Could not find ${field}/${itemId}` `` → `"Array item not found"`;
|
|
63
|
-
`` `Could not find document to PATCH: ${id}` `` → `"Document not found"`;
|
|
64
|
-
`` `Malformed body, array operations…` `` → `"Malformed array operation body"`;
|
|
65
|
-
`` `Invalid array operation: ${op}` `` → `"Invalid array operation"`;
|
|
66
|
-
`` `Patch not allowed for user…` `` → `"Update not allowed"`;
|
|
67
|
-
`` `Access to ${method} on ${model}…denied` `` → `"Access denied"` (both `modelRouter` array
|
|
68
|
-
operations and `runActionPermissions`); and the `plugins.ts` query statics now use
|
|
69
|
-
`"findExactlyOne query returned no documents"`, `"findExactlyOne query returned multiple
|
|
70
|
-
documents"`, `"findOne query returned multiple documents"`, and `"upsert find query returned
|
|
71
|
-
multiple documents"` with the model name in `detail`/`meta`. Clients that string-match on `title`
|
|
72
|
-
should match on `code` instead.
|
|
73
|
-
- **A Mongoose validation failure on an array-operation `PATCH` returns `"Validation failed"`** with
|
|
74
|
-
`meta.fields` rather than `"PATCH Pre Update error"`.
|
|
75
|
-
|
|
76
|
-
### Unchanged
|
|
77
|
-
|
|
78
|
-
No HTTP statuses were changed. The 405 that `runActionPermissions` returns when a pre-document
|
|
79
|
-
permission check fails is kept as-is: `modelRouter`'s array operations return 405 for the same check,
|
|
80
|
-
so it is an existing (if odd) convention rather than a typo to fix in a patch release.
|
|
81
|
-
|
|
82
|
-
## 0.20.0
|
|
83
|
-
|
|
84
|
-
### Changed (breaking)
|
|
85
|
-
|
|
86
|
-
- **`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.
|
|
87
|
-
- **`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.
|
|
88
|
-
- **`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.
|
|
89
|
-
- **`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.
|
|
90
|
-
- **`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"`.
|
|
91
|
-
|
|
92
|
-
### Added
|
|
93
|
-
|
|
94
|
-
- **`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`.
|
|
95
|
-
- **`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.
|
|
96
|
-
- **`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.
|
|
97
|
-
- **`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.
|
|
98
|
-
- **`ConfigurationApp` lifecycle hooks** — `preUpdate(body, req)` (validate/normalize) and `postUpdate(config, prevValue, req)` (audit logging). Both payloads have secret values redacted.
|
|
99
|
-
- **`flattenToDotPaths`** — exported helper used by `updateConfig`.
|
|
100
|
-
|
|
101
|
-
### Migration
|
|
102
|
-
|
|
103
|
-
- 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.
|
|
104
|
-
- If you depended on the `_singleton` unique index, pass `configurationPlugin(schema, {enforceSingletonIndex: true})`.
|
|
105
|
-
- For GCP-with-env-fallback and caching, compose `new CachingSecretProvider(new CompositeSecretProvider([gcp, env]), {ttlMs})`.
|
|
106
|
-
|
|
107
|
-
## 0.16.0
|
|
108
|
-
|
|
109
|
-
### Added
|
|
110
|
-
|
|
111
|
-
- **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.
|
|
112
|
-
- **`loadDocOr404`** — Shared document loader used by permission middleware and instance actions (soft-delete-aware 404 metadata preserved).
|
|
113
|
-
|
|
114
|
-
### Changed
|
|
115
|
-
|
|
116
|
-
- Permission middleware doc loading now delegates to `loadDocOr404` (behavior-preserving).
|
|
117
|
-
|
|
118
|
-
### Dependencies
|
|
119
|
-
|
|
120
|
-
- Added `@asteasolutions/zod-to-openapi` ^8.5.0 (direct dependency).
|
|
121
|
-
- Added **`zod` ^4.3.6 as a peer dependency** — backends that define action Zod schemas must install `zod`.
|
|
122
|
-
|
|
123
|
-
### Migration
|
|
124
|
-
|
|
125
|
-
- 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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.
|
|
@@ -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,
|
package/dist/actions.test.js
CHANGED
|
@@ -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"));
|
|
@@ -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"));
|
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:
|
|
287
|
-
export declare function modelRouter<T>(model:
|
|
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
|
*/
|
|
@@ -79,6 +79,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
79
79
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
83
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
84
|
+
if (!m) return o;
|
|
85
|
+
var i = m.call(o), r, ar = [], e;
|
|
86
|
+
try {
|
|
87
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
88
|
+
}
|
|
89
|
+
catch (error) { e = { error: error }; }
|
|
90
|
+
finally {
|
|
91
|
+
try {
|
|
92
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
93
|
+
}
|
|
94
|
+
finally { if (e) throw e.error; }
|
|
95
|
+
}
|
|
96
|
+
return ar;
|
|
97
|
+
};
|
|
98
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
99
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
100
|
+
if (ar || !(i in from)) {
|
|
101
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
102
|
+
ar[i] = from[i];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
106
|
+
};
|
|
82
107
|
var __values = (this && this.__values) || function(o) {
|
|
83
108
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
84
109
|
if (m) return m.call(o);
|
|
@@ -97,6 +122,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
97
122
|
var bun_test_1 = require("bun:test");
|
|
98
123
|
var Sentry = __importStar(require("@sentry/bun"));
|
|
99
124
|
var chai_1 = require("chai");
|
|
125
|
+
var luxon_1 = require("luxon");
|
|
100
126
|
var mongoose_1 = __importDefault(require("mongoose"));
|
|
101
127
|
var supertest_1 = __importDefault(require("supertest"));
|
|
102
128
|
var api_1 = require("./api");
|
|
@@ -322,6 +348,66 @@ var anyPermissions = {
|
|
|
322
348
|
}
|
|
323
349
|
});
|
|
324
350
|
}); });
|
|
351
|
+
(0, bun_test_1.it)("wraps failures while assembling the list response", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
352
|
+
var ownerId, res;
|
|
353
|
+
return __generator(this, function (_a) {
|
|
354
|
+
switch (_a.label) {
|
|
355
|
+
case 0:
|
|
356
|
+
mountFood({
|
|
357
|
+
responseHandler: function (data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
358
|
+
var serialized;
|
|
359
|
+
return __generator(this, function (_a) {
|
|
360
|
+
serialized = __spreadArray([], __read(data), false);
|
|
361
|
+
serialized.slice = function () {
|
|
362
|
+
throw new Error("slice exploded");
|
|
363
|
+
};
|
|
364
|
+
return [2 /*return*/, serialized];
|
|
365
|
+
});
|
|
366
|
+
}); },
|
|
367
|
+
});
|
|
368
|
+
ownerId = new mongoose_1.default.Types.ObjectId();
|
|
369
|
+
return [4 /*yield*/, tests_1.FoodModel.create([
|
|
370
|
+
{ calories: 1, name: "First", ownerId: ownerId },
|
|
371
|
+
{ calories: 2, name: "Second", ownerId: ownerId },
|
|
372
|
+
])];
|
|
373
|
+
case 1:
|
|
374
|
+
_a.sent();
|
|
375
|
+
return [4 /*yield*/, server.get("/food?limit=1")];
|
|
376
|
+
case 2:
|
|
377
|
+
res = _a.sent();
|
|
378
|
+
chai_1.assert.equal(res.body.title, "Serialization error");
|
|
379
|
+
chai_1.assert.include(res.body.detail, "slice exploded");
|
|
380
|
+
return [2 /*return*/];
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}); });
|
|
384
|
+
(0, bun_test_1.it)("rejects a patch when the stored timestamp cannot be parsed", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
385
|
+
var timestampSchema, TimestampModel, doc, res;
|
|
386
|
+
return __generator(this, function (_a) {
|
|
387
|
+
switch (_a.label) {
|
|
388
|
+
case 0:
|
|
389
|
+
timestampSchema = new mongoose_1.default.Schema({
|
|
390
|
+
name: { description: "The name", type: String },
|
|
391
|
+
updated: { description: "Last update, as an ISO string", type: String },
|
|
392
|
+
});
|
|
393
|
+
TimestampModel = mongoose_1.default.model("StringTimestamp_".concat(Date.now()), timestampSchema);
|
|
394
|
+
app.use("/timestamped", (0, api_1.modelRouter)(TimestampModel, { allowAnonymous: true, permissions: anyPermissions }));
|
|
395
|
+
server = (0, supertest_1.default)(app);
|
|
396
|
+
return [4 /*yield*/, TimestampModel.create({ name: "Timeless", updated: "not-a-date" })];
|
|
397
|
+
case 1:
|
|
398
|
+
doc = _a.sent();
|
|
399
|
+
return [4 /*yield*/, server
|
|
400
|
+
.patch("/timestamped/".concat(doc._id))
|
|
401
|
+
.set("If-Unmodified-Since", luxon_1.DateTime.now().toHTTP())
|
|
402
|
+
.send({ name: "Renamed" })
|
|
403
|
+
.expect(400)];
|
|
404
|
+
case 2:
|
|
405
|
+
res = _a.sent();
|
|
406
|
+
chai_1.assert.equal(res.body.title, "Invalid server timestamp");
|
|
407
|
+
return [2 /*return*/];
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}); });
|
|
325
411
|
});
|
|
326
412
|
// A domain error of the shape consumers throw: stable title, kebab-case code, per-occurrence
|
|
327
413
|
// detail, and structured meta the client renders.
|
|
@@ -32,7 +32,20 @@ export declare const createBetterAuth: (options: CreateBetterAuthOptions) => Bet
|
|
|
32
32
|
* and populates req.user with the application User model.
|
|
33
33
|
*/
|
|
34
34
|
export declare const createBetterAuthSessionMiddleware: (auth: BetterAuthInstance, userModel?: UserModel) => (req: Request, _res: Response, next: NextFunction) => Promise<void>;
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Syncs a Better Auth user to the application User model.
|
|
37
|
+
* Creates or updates the user as needed.
|
|
38
|
+
*/
|
|
39
|
+
interface MutableUserDoc {
|
|
40
|
+
admin?: boolean;
|
|
41
|
+
email?: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
betterAuthId?: string;
|
|
44
|
+
oauthProvider?: string | null;
|
|
45
|
+
id?: string;
|
|
46
|
+
save: () => Promise<unknown>;
|
|
47
|
+
}
|
|
48
|
+
export declare const syncBetterAuthUser: (userModel: UserModel, betterAuthUser: BetterAuthUser, oauthProvider?: string) => Promise<MutableUserDoc>;
|
|
36
49
|
/**
|
|
37
50
|
* Mounts Better Auth routes on the Express app.
|
|
38
51
|
*/
|
|
@@ -57,3 +70,4 @@ export declare const getBetterAuthSession: (req: Request) => BetterAuthSessionDa
|
|
|
57
70
|
* Checks if the request has a valid Better Auth session.
|
|
58
71
|
*/
|
|
59
72
|
export declare const hasBetterAuthSession: (req: Request) => boolean;
|
|
73
|
+
export {};
|
package/dist/betterAuthSetup.js
CHANGED
|
@@ -190,11 +190,8 @@ var createBetterAuthSessionMiddleware = function (auth, userModel) {
|
|
|
190
190
|
}); };
|
|
191
191
|
};
|
|
192
192
|
exports.createBetterAuthSessionMiddleware = createBetterAuthSessionMiddleware;
|
|
193
|
-
var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider
|
|
194
|
-
|
|
195
|
-
// biome-ignore lint/suspicious/noExplicitAny: return is a consumer-defined user document; tests inspect varied fields
|
|
196
|
-
) { return __awaiter(void 0, void 0, void 0, function () {
|
|
197
|
-
var existingUser, userByEmail, useAsId, newUser, error_2;
|
|
193
|
+
var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider) { return __awaiter(void 0, void 0, void 0, function () {
|
|
194
|
+
var existingUser, userByEmail, useAsId, UserDocumentConstructor, newUser, error_2;
|
|
198
195
|
return __generator(this, function (_a) {
|
|
199
196
|
switch (_a.label) {
|
|
200
197
|
case 0:
|
|
@@ -231,7 +228,8 @@ var syncBetterAuthUser = function (userModel, betterAuthUser, oauthProvider
|
|
|
231
228
|
return [2 /*return*/, userByEmail];
|
|
232
229
|
case 6:
|
|
233
230
|
useAsId = mongoose_1.default.isValidObjectId(betterAuthUser.id) ? { _id: betterAuthUser.id } : {};
|
|
234
|
-
|
|
231
|
+
UserDocumentConstructor = userModel;
|
|
232
|
+
newUser = new UserDocumentConstructor(__assign(__assign({}, useAsId), { admin: false, betterAuthId: betterAuthUser.id, email: betterAuthUser.email, name: betterAuthUser.name || betterAuthUser.email.split("@")[0], oauthProvider: oauthProvider || null }));
|
|
235
233
|
return [4 /*yield*/, newUser.save()];
|
|
236
234
|
case 7:
|
|
237
235
|
_a.sent();
|
|
@@ -314,7 +314,7 @@ var configurationPlugin = function (schema, options) {
|
|
|
314
314
|
if (Object.keys(setFields).length === 0) {
|
|
315
315
|
return [2 /*return*/, this.getConfig()];
|
|
316
316
|
}
|
|
317
|
-
return [4 /*yield*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, {
|
|
317
|
+
return [4 /*yield*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, { returnDocument: "after", runValidators: true })];
|
|
318
318
|
case 1:
|
|
319
319
|
updated = _e.sent();
|
|
320
320
|
if (updated) {
|
|
@@ -327,7 +327,7 @@ var configurationPlugin = function (schema, options) {
|
|
|
327
327
|
// No singleton yet — create one (with subdocument defaults applied), then
|
|
328
328
|
// apply the patch.
|
|
329
329
|
_e.sent();
|
|
330
|
-
return [2 /*return*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, {
|
|
330
|
+
return [2 /*return*/, this.findOneAndUpdate(singletonFilter, { $set: setFields }, { returnDocument: "after", runValidators: true }).orFail()];
|
|
331
331
|
}
|
|
332
332
|
});
|
|
333
333
|
});
|
package/dist/consentApp.test.js
CHANGED
|
@@ -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 supertest_1 = __importDefault(require("supertest"));
|
|
62
60
|
var consentApp_1 = require("./consentApp");
|
|
@@ -556,9 +554,7 @@ var buildApp = function (consentAppOptions) {
|
|
|
556
554
|
case 1:
|
|
557
555
|
_a.sent();
|
|
558
556
|
filteredApp = buildApp({
|
|
559
|
-
resolveConsentForms: function (_user, forms) {
|
|
560
|
-
return forms.filter(function (f) { return f.type === "privacy"; });
|
|
561
|
-
},
|
|
557
|
+
resolveConsentForms: function (_user, forms) { return forms.filter(function (f) { return f.type === "privacy"; }); },
|
|
562
558
|
});
|
|
563
559
|
return [4 /*yield*/, (0, tests_1.authAsUser)(filteredApp, "notAdmin")];
|
|
564
560
|
case 2:
|