@openlup/platform 0.0.0-stage → 0.15.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 +19 -0
- package/LICENSE +204 -0
- package/README.md +125 -2
- package/dist/bff/dispatch.d.ts +27 -0
- package/dist/bff/dispatch.js +47 -0
- package/dist/bff/envelope.d.ts +46 -0
- package/dist/bff/envelope.js +80 -0
- package/dist/bff/health.d.ts +24 -0
- package/dist/bff/health.js +19 -0
- package/dist/bff/index.d.ts +6 -0
- package/dist/bff/index.js +6 -0
- package/dist/bff/lazyRoute.d.ts +4 -0
- package/dist/bff/lazyRoute.js +13 -0
- package/dist/bff/requestContext.d.ts +17 -0
- package/dist/bff/requestContext.js +26 -0
- package/dist/bff/routerRewrite.d.ts +2 -0
- package/dist/bff/routerRewrite.js +31 -0
- package/dist/blob/binding.d.ts +16 -0
- package/dist/blob/binding.js +37 -0
- package/dist/blob/filesystem.d.ts +8 -0
- package/dist/blob/filesystem.js +71 -0
- package/dist/blob/index.d.ts +6 -0
- package/dist/blob/index.js +6 -0
- package/dist/blob/s3.d.ts +32 -0
- package/dist/blob/s3.js +56 -0
- package/dist/blob/s3Client.d.ts +25 -0
- package/dist/blob/s3Client.js +76 -0
- package/dist/blob/supabase.d.ts +40 -0
- package/dist/blob/supabase.js +59 -0
- package/dist/blob/vercel.d.ts +63 -0
- package/dist/blob/vercel.js +69 -0
- package/dist/composition/composeBundle.d.ts +47 -0
- package/dist/composition/composeBundle.js +45 -0
- package/dist/composition/httpBinding.d.ts +8 -0
- package/dist/composition/httpBinding.js +18 -0
- package/dist/composition/index.d.ts +3 -0
- package/dist/composition/index.js +3 -0
- package/dist/composition/nodeHost.d.ts +103 -0
- package/dist/composition/nodeHost.js +145 -0
- package/dist/data/binding.d.ts +34 -0
- package/dist/data/binding.js +92 -0
- package/dist/data/index.d.ts +5 -0
- package/dist/data/index.js +5 -0
- package/dist/data/postgresGateway.d.ts +42 -0
- package/dist/data/postgresGateway.js +135 -0
- package/dist/data/queryBuilder.d.ts +54 -0
- package/dist/data/queryBuilder.js +240 -0
- package/dist/data/queryBuilderSql.d.ts +76 -0
- package/dist/data/queryBuilderSql.js +145 -0
- package/dist/data/supabaseClientFactory.d.ts +34 -0
- package/dist/data/supabaseClientFactory.js +56 -0
- package/dist/data/supabaseGateway.d.ts +22 -0
- package/dist/data/supabaseGateway.js +49 -0
- package/dist/http/deadline.d.ts +20 -0
- package/dist/http/deadline.js +93 -0
- package/dist/http/index.d.ts +6 -0
- package/dist/http/index.js +5 -0
- package/dist/http/requestAdapter.d.ts +38 -0
- package/dist/http/requestAdapter.js +203 -0
- package/dist/http/runtime.d.ts +83 -0
- package/dist/http/runtime.js +199 -0
- package/dist/http/security.d.ts +44 -0
- package/dist/http/security.js +114 -0
- package/dist/http/staticAssets.d.ts +3 -0
- package/dist/http/staticAssets.js +42 -0
- package/dist/http/types.d.ts +23 -0
- package/dist/http/types.js +6 -0
- package/dist/job-ledger/index.d.ts +5 -0
- package/dist/job-ledger/index.js +3 -0
- package/dist/job-ledger/ports.d.ts +10 -0
- package/dist/job-ledger/ports.js +7 -0
- package/dist/job-ledger/postgres.d.ts +10 -0
- package/dist/job-ledger/postgres.js +101 -0
- package/dist/job-ledger/sql.d.ts +7 -0
- package/dist/job-ledger/sql.js +10 -0
- package/dist/job-ledger/supabase.d.ts +77 -0
- package/dist/job-ledger/supabase.js +202 -0
- package/dist/kernel/index.d.ts +1 -0
- package/dist/kernel/index.js +1 -0
- package/dist/kernel/platformKernel.d.ts +34 -0
- package/dist/kernel/platformKernel.js +115 -0
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.js +1 -0
- package/dist/migrations/postgresRunner.d.ts +50 -0
- package/dist/migrations/postgresRunner.js +176 -0
- package/dist/scheduler/advisoryLock.d.ts +44 -0
- package/dist/scheduler/advisoryLock.js +114 -0
- package/dist/scheduler/cronGuard.d.ts +10 -0
- package/dist/scheduler/cronGuard.js +19 -0
- package/dist/scheduler/cronSecret.d.ts +5 -0
- package/dist/scheduler/cronSecret.js +23 -0
- package/dist/scheduler/handlers.d.ts +9 -0
- package/dist/scheduler/handlers.js +10 -0
- package/dist/scheduler/httpEntry.d.ts +16 -0
- package/dist/scheduler/httpEntry.js +31 -0
- package/dist/scheduler/index.d.ts +9 -0
- package/dist/scheduler/index.js +9 -0
- package/dist/scheduler/jobRegistry.d.ts +21 -0
- package/dist/scheduler/jobRegistry.js +39 -0
- package/dist/scheduler/jobs.d.ts +48 -0
- package/dist/scheduler/jobs.js +92 -0
- package/dist/scheduler/nodeScheduler.d.ts +42 -0
- package/dist/scheduler/nodeScheduler.js +73 -0
- package/dist/scheduler/vercelScheduler.d.ts +29 -0
- package/dist/scheduler/vercelScheduler.js +51 -0
- package/package.json +108 -4
- package/release-gates.json +121 -0
- package/sql/20260809150000_job_run_ledger.sql +301 -0
- package/sql/20260809150001_job_run_ledger_v3.sql +70 -0
- package/src/bff/dispatch.ts +81 -0
- package/src/bff/envelope.ts +142 -0
- package/src/bff/health.ts +37 -0
- package/src/bff/index.ts +30 -0
- package/src/bff/lazyRoute.ts +28 -0
- package/src/bff/requestContext.ts +48 -0
- package/src/bff/routerRewrite.ts +38 -0
- package/src/blob/binding.ts +55 -0
- package/src/blob/filesystem.ts +86 -0
- package/src/blob/index.ts +17 -0
- package/src/blob/s3.ts +87 -0
- package/src/blob/s3Client.ts +91 -0
- package/src/blob/supabase.ts +88 -0
- package/src/blob/vercel.ts +127 -0
- package/src/composition/composeBundle.ts +109 -0
- package/src/composition/httpBinding.ts +30 -0
- package/src/composition/index.ts +17 -0
- package/src/composition/nodeHost.ts +289 -0
- package/src/data/binding.ts +157 -0
- package/src/data/index.ts +33 -0
- package/src/data/postgresGateway.ts +186 -0
- package/src/data/queryBuilder.ts +300 -0
- package/src/data/queryBuilderSql.ts +183 -0
- package/src/data/supabaseClientFactory.ts +92 -0
- package/src/data/supabaseGateway.ts +76 -0
- package/src/http/deadline.ts +117 -0
- package/src/http/index.ts +36 -0
- package/src/http/requestAdapter.ts +215 -0
- package/src/http/runtime.ts +319 -0
- package/src/http/security.ts +155 -0
- package/src/http/staticAssets.ts +42 -0
- package/src/http/types.ts +31 -0
- package/src/job-ledger/index.ts +25 -0
- package/src/job-ledger/ports.ts +27 -0
- package/src/job-ledger/postgres.ts +121 -0
- package/src/job-ledger/sql.ts +12 -0
- package/src/job-ledger/supabase.ts +294 -0
- package/src/kernel/index.ts +17 -0
- package/src/kernel/platformKernel.ts +153 -0
- package/src/migrations/index.ts +10 -0
- package/src/migrations/postgresRunner.ts +255 -0
- package/src/scheduler/advisoryLock.ts +145 -0
- package/src/scheduler/cronGuard.ts +30 -0
- package/src/scheduler/cronSecret.ts +26 -0
- package/src/scheduler/handlers.ts +24 -0
- package/src/scheduler/httpEntry.ts +49 -0
- package/src/scheduler/index.ts +47 -0
- package/src/scheduler/jobRegistry.ts +57 -0
- package/src/scheduler/jobs.ts +119 -0
- package/src/scheduler/nodeScheduler.ts +123 -0
- package/src/scheduler/vercelScheduler.ts +71 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Notable changes to this public-source workspace package are recorded here.
|
|
4
|
+
“Unreleased” means no npm version carries the change yet; immutable OpenLup
|
|
5
|
+
source previews may already ship some changes, and their release notes say
|
|
6
|
+
which. Declaration snapshots track candidate drift, not a stable API or
|
|
7
|
+
SemVer promise.
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
## [0.15.0]
|
|
12
|
+
|
|
13
|
+
- Publishable on the npm `latest` dist-tag as `0.15.0`, from tag
|
|
14
|
+
`openlup-platform-v0.15.0`.
|
|
15
|
+
|
|
16
|
+
- First publication of `@openlup/platform`, the server substrate for an OpenLup application, with one module subpath each for `http`, `bff`, `scheduler`, `blob`, `data`, `migrations`, `job-ledger`, `kernel` and `composition`.
|
|
17
|
+
- Transport-neutral scheduled jobs: a `run(context)` contract, an empty job registry, a lease-aware runner and an authenticated HTTP cron entry, with a constant-time cron secret comparison.
|
|
18
|
+
- Per-capability bundle readiness that refuses an unknown bundle and reports every missing scheduler, lock and blob setting together.
|
|
19
|
+
- Blob capability selection with filesystem, Vercel Blob, Supabase Storage and S3 bindings; `pg`, `@types/pg` and `@aws-sdk/client-s3` are optional peers, and an adapter refuses a missing peer with `OPENLUP_E_PEER_MISSING`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Copyright (c) 2026 Bartlomiej Roszkowski
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @openlup/platform
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
Development preview. This package joins core and outbox in the publishable set from the next set version; this configuration does not establish a registry release or a stable API. Its repository-directory publish command refuses publication; the authorized package-release workflow owns publication.
|
|
4
|
+
|
|
5
|
+
It holds the runnable server substrate an OpenLup application composes: the Node HTTP runtime, BFF dispatch, scheduling and job leases, blob storage, data gateways, the node-postgres migration runner and bundle composition. Ports and their contracts stay in `@openlup/core/platform-runtime`.
|
|
6
|
+
|
|
7
|
+
## Package surface
|
|
8
|
+
|
|
9
|
+
`release-gates.json` declares kind `rail`: this foundation provides runtime infrastructure over core ports, matching the architecture's rail responsibility. Its nine experimental entries each bind a declaration snapshot and package-owned smoke tests. The API checker reads this same inventory.
|
|
10
|
+
|
|
11
|
+
| Export | Contents |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `./http` | Node request adaptation, deadlines, security headers and static documents, and `createNodeHttpRuntime` with its fixed request order |
|
|
14
|
+
| `./bff` | `createBffDispatcher`, `lazyBffRoute`, the hosted router URL rewrite, the response envelope (`createBffResponder`), the observed request context and the health route |
|
|
15
|
+
| `./scheduler` | Transport-neutral scheduled jobs (`ScheduledJob`, the job registry, the lease-aware runner and the authenticated HTTP cron entry), path-declared jobs from configuration, the node-cron scheduler with per-job advisory locks, hosted cron verification, the cron entrypoint guard (it compares the presented bearer token with `CRON_SECRET` in constant time) and direct job bindings |
|
|
16
|
+
| `./blob` | Filesystem, S3-compatible, Supabase Storage and Vercel Blob adapters, and `bindBlobPort` |
|
|
17
|
+
| `./data` | Supabase and node-postgres data gateways, the role-free transaction lane, the query builder and the data bindings |
|
|
18
|
+
| `./migrations` | The node-postgres `MigrationRunnerPort` |
|
|
19
|
+
| `./job-ledger` | The job-run ledger port, its PostgreSQL and managed (Supabase) adapters, the managed v2/v3 compatibility calls and the location of its SQL |
|
|
20
|
+
| `./kernel` | The bundle identifiers, descriptors and readiness |
|
|
21
|
+
| `./composition` | `createBundleComposer`, the Node HTTP binding helpers and `createNodeHost` |
|
|
22
|
+
|
|
23
|
+
## Scheduled jobs
|
|
24
|
+
|
|
25
|
+
A job is `{ id, schedule, lease?, run(context) }` with a UTC cron expression. Domains and packages contribute jobs to `createScheduledJobRegistry`, which refuses duplicate ids and ships empty. The Node host runs registry jobs on its own timers and calls `run` directly, with no HTTP request and no secret. `createScheduledJobHttpEntry` mounts the same job behind the cron guard for a hosted cron. A job that declares `lease` runs only after the injected job-lease port grants it; a lease held elsewhere skips the run, and a finish the port refuses fails the run. `scheduledJobsFromContribution` turns a contribution's cadence schedules into jobs and refuses a cadence that no cron expression matches exactly; a contribution run that reports a failed outcome fails the job.
|
|
26
|
+
|
|
27
|
+
## Bundle readiness
|
|
28
|
+
|
|
29
|
+
`PLATFORM_BUNDLE` selects `vercel-supabase` (the default when absent), `node-supabase` or `node-postgres`. A bundle's readiness refuses, before any traffic or timer: an unknown `PLATFORM_BUNDLE` (resolution itself still falls back to the default); a self-host bundle without `APP_BASE_URL`; and, reported together under `OPENLUP_E_ENV_MISSING`, every selected capability without its settings: the scheduler without `CRON_SECRET`, Node scheduling without `DATABASE_URL` for its cluster lock (never a silent single-instance lock), and the selected blob capability without its settings (see Blob storage). An unknown `PLATFORM_BLOB` is refused too. The Node host checks readiness at boot.
|
|
30
|
+
|
|
31
|
+
## Blob storage
|
|
32
|
+
|
|
33
|
+
`PLATFORM_BLOB` selects the blob capability; without it the bundle's own applies (filesystem for node-postgres, the local development default). `bindBlobPort` builds each one from the environment and the clients the application injects:
|
|
34
|
+
|
|
35
|
+
- `filesystem`: `BLOB_FS_ROOT`, `BLOB_FS_BASE_URL`;
|
|
36
|
+
- `s3`: `BLOB_S3_BUCKET`, `BLOB_S3_BASE_URL`, and a default client from `createS3ClientFromEnv` (`BLOB_S3_REGION`, `BLOB_S3_ENDPOINT`, `BLOB_S3_FORCE_PATH_STYLE`, `BLOB_S3_ACCESS_KEY_ID` with `BLOB_S3_SECRET_ACCESS_KEY`). `@aws-sdk/client-s3` is an optional peer loaded on first use, so only an application that selects S3 installs it;
|
|
37
|
+
- `supabase`: `BLOB_SUPABASE_BUCKET` and `BlobBindingDeps.supabaseStorageClient`, a factory returning the structural `SupabaseStorageClient` declared in blob. Blob itself reads no data-gateway settings. The default composer supplies this factory from the data-gateway settings and its optional `createSupabaseClient` dependency, using the service-role key with `persistSession: false` and `autoRefreshToken: false`. For this binding, a blank `SUPABASE_URL` falls back to `VITE_SUPABASE_URL`, consistently with readiness;
|
|
38
|
+
- `vercel-blob`: the injected `@vercel/blob` module and `BLOB_READ_WRITE_TOKEN`.
|
|
39
|
+
|
|
40
|
+
The Node host passes the composed ports, blob storage included, to the HTTP runtime builder and to the jobs contributed to it. The reference repository's compose file starts a local S3-compatible service with `--profile local-storage`; missing storage credentials refuse at service startup, while an omitted `OBJECT_STORAGE_PORT` selects an ephemeral loopback port. The inactive profile requires no storage settings. A conformance test runs upload, read-back, delete and access refusal against that image; initialization failure with Docker available fails the test. Hosted S3 provider certification is not claimed.
|
|
41
|
+
|
|
42
|
+
## What the application supplies
|
|
43
|
+
|
|
44
|
+
The package carries no deployment identity. The application passes it every value that names a deployment or a domain:
|
|
45
|
+
|
|
46
|
+
- the BFF route table, the not-found response, the request preflight and the per-request hook;
|
|
47
|
+
- how a request reference is chosen, and the health payload with its strict contract;
|
|
48
|
+
- the security header policy, including the content security policy, the production hosts and the robots.txt body;
|
|
49
|
+
- its own entrypoints, by exact path or by path rule;
|
|
50
|
+
- the job configuration file or object, the direct job bindings and the host admission check;
|
|
51
|
+
- the migration catalogue, the migration lock name and the object-inventory projector;
|
|
52
|
+
- the release correlation, default failure reason and read-failure messages that the job-run ledgers record;
|
|
53
|
+
- the environment, passed explicitly, and the provider clients it needs (the Supabase `createClient`, the `@vercel/blob` module, optionally its own PostgreSQL gateway factory), so the package itself reads no environment variable (an injected SDK may read its own credentials; the static and migration roots default to the working directory). Its optional SDK peers are `pg`, whose types its PostgreSQL declarations use, and `@aws-sdk/client-s3`, loaded lazily by the default S3 client. Blob declarations use structural types and need no S3 SDK;
|
|
54
|
+
- an optional scheduler profile for the Node host: a fenced projection of the declared jobs with its own bindings and validation hooks.
|
|
55
|
+
|
|
56
|
+
`createBundleComposer` binds the blob slot by default; pass `createBundleComposer({ createSupabaseClient })` to enable its Supabase Storage binding when the data-gateway settings and bucket are present. Without that client Supabase Storage stays unbound. A custom `blob` binder still overrides the default. The HTTP, scheduler, data, migrations, analytics and transactional slots stay `null` until the application supplies their binders; `createDataBindings` builds the data binder from the application's database client factory.
|
|
57
|
+
|
|
58
|
+
## Job-run ledger SQL
|
|
59
|
+
|
|
60
|
+
`JOB_RUN_LEDGER_MIGRATIONS` lists the two files a fresh installation applies, in order, through its own migration chain:
|
|
61
|
+
|
|
62
|
+
1. [`sql/20260809150000_job_run_ledger.sql`](sql/20260809150000_job_run_ledger.sql): the job controls, runs, and the v2 claim and finish; its bytes and migration identity equal the reference application's platform migration of that name.
|
|
63
|
+
2. [`sql/20260809150001_job_run_ledger_v3.sql`](sql/20260809150001_job_run_ledger_v3.sql): the v3 claim and finish the PostgreSQL ledger calls, as `CREATE OR REPLACE`, with bodies byte-equal to the reference chain's definitions.
|
|
64
|
+
|
|
65
|
+
The package SQL and the reference application's platform migration chain are alternative install paths, never applied together: the reference chain defines all four job-control functions itself, with plain `CREATE FUNCTION`, so it fails on a database where the package SQL already created them. The package file `20260809150001_job_run_ledger_v3` has a migration identity no reference migration uses. Importing the package never applies SQL.
|
|
66
|
+
|
|
67
|
+
## Optional peers
|
|
68
|
+
|
|
69
|
+
`pg`, `@types/pg` and `@aws-sdk/client-s3` are optional peers. Install `pg` and
|
|
70
|
+
`@types/pg` alongside this package when selecting PostgreSQL adapters; install
|
|
71
|
+
`@aws-sdk/client-s3` when selecting S3 blob storage. Loading an unselected adapter
|
|
72
|
+
never installs or initializes its SDK. The PostgreSQL scheduler lock also loads
|
|
73
|
+
`pg` only on its first operation.
|
|
74
|
+
|
|
75
|
+
A selected capability whose SDK is absent rejects its first loading operation
|
|
76
|
+
with `OPENLUP_E_PEER_MISSING: <package> is required by <capability>; install it
|
|
77
|
+
alongside @openlup/platform`. The original module-resolution error is the cause.
|
|
78
|
+
A broken SDK, a missing transitive dependency or a provider error propagates
|
|
79
|
+
unchanged. Blob `exists` retains its boolean contract and returns false on a
|
|
80
|
+
failed HEAD; use an upload or list operation to observe an S3 loading refusal.
|
|
81
|
+
|
|
82
|
+
## Verification
|
|
83
|
+
|
|
84
|
+
This package's tests are part of the repository's required test selection; from this directory, `npm test` runs them alone. The tests rewrite the originating application's characterization with neutral names and synthetic data, and a boundary test refuses any environment read or provider import in the package source.
|
|
85
|
+
|
|
86
|
+
`npm run api:check` compares each of the nine declaration entry graphs with the
|
|
87
|
+
committed `api/*.api.md` reports. After building, deliberately regenerate them
|
|
88
|
+
with `node --experimental-strip-types ./scripts/api-contract.ts --update` from
|
|
89
|
+
this package, and review the declaration changes.
|
|
90
|
+
|
|
91
|
+
The source-checkout binding `npm run test:consumer` runs
|
|
92
|
+
[`platform-cold-consumer.ts`](../../scripts/packages/platform-cold-consumer.ts).
|
|
93
|
+
It requires the cold package producer's verified `OPENLUP_PACK_MANIFEST` and
|
|
94
|
+
exact `OPENLUP_PACK_COMMIT`; it never substitutes a workspace build or repacks
|
|
95
|
+
on refusal. `ci:required` invokes that proof; API checks remain in the shared
|
|
96
|
+
cheap phase. The producer must include publishable core and platform tarballs;
|
|
97
|
+
the package inventory includes both at the same set version. Cold packing requires a clean committed package tree; an uncommitted preparation cannot produce the manifest.
|
|
98
|
+
|
|
99
|
+
The proof installs those tarballs, locked Zod and explicit Node type tooling
|
|
100
|
+
offline from the default npm cache into an OS temporary directory outside the checkout.
|
|
101
|
+
It verifies optional-peer absence physically and through both CommonJS and ESM
|
|
102
|
+
resolution, refuses symlinks and ancestor package sources, checks the complete
|
|
103
|
+
export classification, imports every nonadapter entry with an empty environment,
|
|
104
|
+
and compiles its types in strict NodeNext and Bundler modes without skipping
|
|
105
|
+
library checks. A type leak fails the proof even if runtime imports pass.
|
|
106
|
+
|
|
107
|
+
It then checks actual missing-SDK refusals, installs the three peers at the root
|
|
108
|
+
lockfile's exact versions using `npm install --prefer-offline --no-audit --fund=false`
|
|
109
|
+
and the default npm cache, compiles all adapter declarations and runs the real SDKs against owned
|
|
110
|
+
in-memory fixtures: S3 upload/HEAD/list/delete through the real SDK and
|
|
111
|
+
deterministic invalid-URL refusals after the default SDK/driver loads.
|
|
112
|
+
These fixtures contact no live provider. The PostgreSQL adapters then run their SQL conformance
|
|
113
|
+
against a disposable database: the CI job's pinned PostgreSQL service when the job supplies its
|
|
114
|
+
identity (`OPENLUP_PROOF_SERVICE_CONTAINER` and `OPENLUP_PROOF_SERVICE_PORT`), as the outbox proof
|
|
115
|
+
uses it, or otherwise an owned, labelled container of the same pinned image. There is no skip:
|
|
116
|
+
without either the proof fails. Temporary consumer files, the proof database and an owned container
|
|
117
|
+
are removed on completion. Missing cached packages fail the initial offline installation;
|
|
118
|
+
the SDK-present install can fetch missing registry metadata or packages. Neither
|
|
119
|
+
phase redirects npm to an empty temporary cache.
|
|
120
|
+
|
|
121
|
+
The composition declarations describe the injected Supabase factory structurally;
|
|
122
|
+
they do not import the data entry or its PostgreSQL types. The cold proof still
|
|
123
|
+
requires all five nonadapter entries to import in fresh processes and compile
|
|
124
|
+
in both resolution modes with all three optional peers absent.
|
|
125
|
+
|
|
126
|
+
<!-- openlup-doc-impact {"unit":"platform-substrate","digest":"sha256-00994d288cfec0c8dc0ae9aeae2ff542e2e9af2fedcb4dd2dfeb6c99523be92d","reason":"The manifest moves to the 0.15.0 set version with the exact @openlup/core 0.15.0 peer pin. The package surface, settings and verification described here are unchanged by this preparation delta."} -->
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HttpRequest, HttpResponse } from "../http/index.js";
|
|
2
|
+
export type RouteEntry = {
|
|
3
|
+
route: string;
|
|
4
|
+
pattern: RegExp;
|
|
5
|
+
params: string[];
|
|
6
|
+
handler: (req: HttpRequest, res: HttpResponse) => unknown;
|
|
7
|
+
/** Fail unsupported hosted bundles closed before auth without weakening direct-route auth. */
|
|
8
|
+
availability?: "direct-postgres";
|
|
9
|
+
};
|
|
10
|
+
/** Match `routes` against one request and run the handler, or answer not found. */
|
|
11
|
+
export type BffDispatch = (routes: readonly RouteEntry[], req: HttpRequest, res: HttpResponse) => Promise<unknown>;
|
|
12
|
+
export interface BffDispatcherOptions {
|
|
13
|
+
/** Environment read on each request to decide a route's bundle availability. */
|
|
14
|
+
env: () => Record<string, string | undefined>;
|
|
15
|
+
/** Writes the deployment's not-found response for an unmatched or unavailable path. */
|
|
16
|
+
notFound: (res: HttpResponse, pathname: string) => void;
|
|
17
|
+
/** Runs once per request before matching (for example, ambient request configuration). */
|
|
18
|
+
beforeDispatch?: () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Runs after matching and before the handler, for example route authorization; resolving false
|
|
21
|
+
* means it already answered. Required, so no composition skips it by omission; a deployment
|
|
22
|
+
* without guarded routes passes `() => true`.
|
|
23
|
+
*/
|
|
24
|
+
preflight: (req: HttpRequest, res: HttpResponse, route: string) => Promise<boolean> | boolean;
|
|
25
|
+
}
|
|
26
|
+
/** Build the dispatcher a deployment mounts on its hosted and Node entrypoints alike. */
|
|
27
|
+
export declare function createBffDispatcher(options: BffDispatcherOptions): BffDispatch;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// BFF dispatch mechanism.
|
|
2
|
+
//
|
|
3
|
+
// The route table and its handlers belong to the deployment. This module owns the
|
|
4
|
+
// platform-neutral matching loop, so every HttpRuntimePort adapter (a hosted function or the Node
|
|
5
|
+
// runtime of this package) mounts the same route table without duplicating dispatch logic.
|
|
6
|
+
//
|
|
7
|
+
// Per request, in order: the deployment's `beforeDispatch` hook, path normalization, the first
|
|
8
|
+
// matching route, its availability, its decoded path parameters, the deployment's `preflight`
|
|
9
|
+
// hook, then the handler. An unmatched or unavailable path goes to the deployment's `notFound`.
|
|
10
|
+
import { getBundleDescriptor, resolveBundleId } from "../kernel/index.js";
|
|
11
|
+
// Only the pathname is read, and it does not depend on the URL base; this host only completes a
|
|
12
|
+
// request that carries no Host header.
|
|
13
|
+
const FALLBACK_HOST = "bff.invalid";
|
|
14
|
+
function requestPath(req) {
|
|
15
|
+
const rawUrl = typeof req.url === "string" ? req.url : "/";
|
|
16
|
+
const host = typeof req.headers?.host === "string" ? req.headers.host : FALLBACK_HOST;
|
|
17
|
+
return new URL(rawUrl, "https://" + host).pathname.replace(/\/+$/, "") || "/";
|
|
18
|
+
}
|
|
19
|
+
/** Build the dispatcher a deployment mounts on its hosted and Node entrypoints alike. */
|
|
20
|
+
export function createBffDispatcher(options) {
|
|
21
|
+
return async function dispatch(routes, req, res) {
|
|
22
|
+
options.beforeDispatch?.();
|
|
23
|
+
const pathname = requestPath(req);
|
|
24
|
+
for (const entry of routes) {
|
|
25
|
+
const match = entry.pattern.exec(pathname);
|
|
26
|
+
if (!match)
|
|
27
|
+
continue;
|
|
28
|
+
if (entry.availability === "direct-postgres"
|
|
29
|
+
&& getBundleDescriptor(resolveBundleId(options.env())).capabilities.data !== "postgres") {
|
|
30
|
+
options.notFound(res, pathname);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (entry.params.length > 0) {
|
|
34
|
+
const query = { ...(req.query ?? {}) };
|
|
35
|
+
entry.params.forEach((param, index) => {
|
|
36
|
+
query[param] = decodeURIComponent(match[index + 1] ?? "");
|
|
37
|
+
});
|
|
38
|
+
req.query = query;
|
|
39
|
+
}
|
|
40
|
+
if (!(await options.preflight(req, res, entry.route)))
|
|
41
|
+
return undefined;
|
|
42
|
+
return entry.handler(req, res);
|
|
43
|
+
}
|
|
44
|
+
options.notFound(res, pathname);
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { HttpResponse } from "../http/index.js";
|
|
2
|
+
export declare const BFF_REQUEST_REFERENCE_HEADER = "x-request-id";
|
|
3
|
+
export declare const BFF_ERROR_CODES: readonly ["BAD_REQUEST", "UNAUTHORIZED", "FORBIDDEN", "NOT_FOUND", "METHOD_NOT_ALLOWED", "CONFLICT", "RATE_LIMITED", "UPSTREAM_UNAVAILABLE", "INTERNAL", "INVALID_RESPONSE"];
|
|
4
|
+
export type BffErrorCode = (typeof BFF_ERROR_CODES)[number];
|
|
5
|
+
export type BffMeta = {
|
|
6
|
+
requestId?: string;
|
|
7
|
+
contractVersion?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
export type BffError = {
|
|
11
|
+
code: BffErrorCode;
|
|
12
|
+
message: string;
|
|
13
|
+
details?: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type BffSuccessResponse<T> = {
|
|
16
|
+
ok: true;
|
|
17
|
+
data: T;
|
|
18
|
+
meta?: BffMeta;
|
|
19
|
+
};
|
|
20
|
+
export type BffErrorResponse = {
|
|
21
|
+
ok: false;
|
|
22
|
+
error: BffError;
|
|
23
|
+
meta?: BffMeta;
|
|
24
|
+
};
|
|
25
|
+
export type BffResponse<T> = BffSuccessResponse<T> | BffErrorResponse;
|
|
26
|
+
/** The HTTP status each error code answers with unless the caller names another. */
|
|
27
|
+
export declare const BFF_ERROR_STATUS: Readonly<Record<BffErrorCode, number>>;
|
|
28
|
+
export interface BffErrorOptions {
|
|
29
|
+
status?: number;
|
|
30
|
+
details?: unknown;
|
|
31
|
+
meta?: BffMeta;
|
|
32
|
+
}
|
|
33
|
+
export interface BffSuccessOptions {
|
|
34
|
+
cacheControl?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface BffResponderOptions {
|
|
37
|
+
/** The request reference observed for this response, if the deployment records one. */
|
|
38
|
+
responseRequestId?: (res: HttpResponse) => string | undefined;
|
|
39
|
+
}
|
|
40
|
+
export interface BffResponder {
|
|
41
|
+
sendBffSuccess<T>(res: HttpResponse, data: T, meta?: BffMeta, options?: BffSuccessOptions): void;
|
|
42
|
+
sendBffError(res: HttpResponse, code: BffErrorCode, message: string, options?: BffErrorOptions): void;
|
|
43
|
+
sendMethodNotAllowed(res: HttpResponse, allowedMethods: readonly string[]): void;
|
|
44
|
+
}
|
|
45
|
+
/** Build the envelope writers a deployment's handlers share. */
|
|
46
|
+
export declare function createBffResponder(options?: BffResponderOptions): BffResponder;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// BFF response envelope.
|
|
2
|
+
//
|
|
3
|
+
// Every BFF response is JSON `{ ok: true, data, meta? }` or `{ ok: false, error: { code, message,
|
|
4
|
+
// details? }, meta? }`. A private response carries the request reference in the `x-request-id`
|
|
5
|
+
// header and, for errors or responses with meta, in `meta.requestId`; a shared-cache response
|
|
6
|
+
// (public or s-maxage) carries neither. `undefined` members are stripped before serialization.
|
|
7
|
+
export const BFF_REQUEST_REFERENCE_HEADER = "x-request-id";
|
|
8
|
+
export const BFF_ERROR_CODES = [
|
|
9
|
+
"BAD_REQUEST",
|
|
10
|
+
"UNAUTHORIZED",
|
|
11
|
+
"FORBIDDEN",
|
|
12
|
+
"NOT_FOUND",
|
|
13
|
+
"METHOD_NOT_ALLOWED",
|
|
14
|
+
"CONFLICT",
|
|
15
|
+
"RATE_LIMITED",
|
|
16
|
+
"UPSTREAM_UNAVAILABLE",
|
|
17
|
+
"INTERNAL",
|
|
18
|
+
"INVALID_RESPONSE",
|
|
19
|
+
];
|
|
20
|
+
/** The HTTP status each error code answers with unless the caller names another. */
|
|
21
|
+
export const BFF_ERROR_STATUS = {
|
|
22
|
+
BAD_REQUEST: 400,
|
|
23
|
+
UNAUTHORIZED: 401,
|
|
24
|
+
FORBIDDEN: 403,
|
|
25
|
+
NOT_FOUND: 404,
|
|
26
|
+
METHOD_NOT_ALLOWED: 405,
|
|
27
|
+
CONFLICT: 409,
|
|
28
|
+
RATE_LIMITED: 429,
|
|
29
|
+
UPSTREAM_UNAVAILABLE: 503,
|
|
30
|
+
INTERNAL: 500,
|
|
31
|
+
INVALID_RESPONSE: 502,
|
|
32
|
+
};
|
|
33
|
+
/** Build the envelope writers a deployment's handlers share. */
|
|
34
|
+
export function createBffResponder(options = {}) {
|
|
35
|
+
function sendBffSuccess(res, data, meta, successOptions = {}) {
|
|
36
|
+
sendJson(res, 200, { ok: true, data, meta }, successOptions.cacheControl);
|
|
37
|
+
}
|
|
38
|
+
function sendBffError(res, code, message, errorOptions = {}) {
|
|
39
|
+
sendJson(res, errorOptions.status ?? BFF_ERROR_STATUS[code], {
|
|
40
|
+
ok: false,
|
|
41
|
+
error: { code, message, details: errorOptions.details },
|
|
42
|
+
meta: errorOptions.meta,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function sendMethodNotAllowed(res, allowedMethods) {
|
|
46
|
+
res.setHeader("Allow", allowedMethods.join(", "));
|
|
47
|
+
sendBffError(res, "METHOD_NOT_ALLOWED", "Method not allowed", { status: 405 });
|
|
48
|
+
}
|
|
49
|
+
function sendJson(res, status, body, cacheControl = "no-store") {
|
|
50
|
+
const shared = /(?:^|,)\s*(?:public\b|s-maxage\s*=)/i.test(cacheControl);
|
|
51
|
+
const requestId = shared ? undefined : options.responseRequestId?.(res);
|
|
52
|
+
const responseBody = withRequestReference(body, requestId, shared);
|
|
53
|
+
res.setHeader("Content-Type", "application/json");
|
|
54
|
+
res.setHeader("Cache-Control", cacheControl);
|
|
55
|
+
if (shared && typeof res.removeHeader === "function")
|
|
56
|
+
res.removeHeader(BFF_REQUEST_REFERENCE_HEADER);
|
|
57
|
+
else if (requestId)
|
|
58
|
+
res.setHeader(BFF_REQUEST_REFERENCE_HEADER, requestId);
|
|
59
|
+
res.status(status).json(stripUndefined(responseBody));
|
|
60
|
+
}
|
|
61
|
+
return { sendBffSuccess, sendBffError, sendMethodNotAllowed };
|
|
62
|
+
}
|
|
63
|
+
function withRequestReference(body, requestId, omitRequestId) {
|
|
64
|
+
if (requestId && (body.ok === false || body.meta)) {
|
|
65
|
+
return { ...body, meta: { ...body.meta, requestId } };
|
|
66
|
+
}
|
|
67
|
+
if (!omitRequestId || !body.meta || !("requestId" in body.meta))
|
|
68
|
+
return body;
|
|
69
|
+
const { requestId: _omitted, ...meta } = body.meta;
|
|
70
|
+
return { ...body, meta: Object.keys(meta).length > 0 ? meta : undefined };
|
|
71
|
+
}
|
|
72
|
+
function stripUndefined(value) {
|
|
73
|
+
if (Array.isArray(value))
|
|
74
|
+
return value.map(stripUndefined);
|
|
75
|
+
if (!value || typeof value !== "object")
|
|
76
|
+
return value;
|
|
77
|
+
return Object.fromEntries(Object.entries(value)
|
|
78
|
+
.filter(([, entryValue]) => entryValue !== undefined)
|
|
79
|
+
.map(([key, entryValue]) => [key, stripUndefined(entryValue)]));
|
|
80
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpRequest, HttpResponse } from "../http/index.js";
|
|
2
|
+
import type { BffResponder } from "./envelope.js";
|
|
3
|
+
export interface HealthContract<T extends {
|
|
4
|
+
contractVersion: string;
|
|
5
|
+
}> {
|
|
6
|
+
safeParse(value: unknown): {
|
|
7
|
+
success: true;
|
|
8
|
+
data: T;
|
|
9
|
+
} | {
|
|
10
|
+
success: false;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface HealthHandlerOptions<T extends {
|
|
14
|
+
contractVersion: string;
|
|
15
|
+
}> {
|
|
16
|
+
responder: BffResponder;
|
|
17
|
+
/** The deployment's strict health contract. */
|
|
18
|
+
contract: HealthContract<T>;
|
|
19
|
+
/** Builds this request's health payload: service identity, release provenance and the rest. */
|
|
20
|
+
read: () => unknown;
|
|
21
|
+
}
|
|
22
|
+
export declare function createHealthHandler<T extends {
|
|
23
|
+
contractVersion: string;
|
|
24
|
+
}>(options: HealthHandlerOptions<T>): (req: HttpRequest, res: HttpResponse) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// BFF health route.
|
|
2
|
+
//
|
|
3
|
+
// GET answers the deployment's health payload, validated by the deployment's strict contract, with
|
|
4
|
+
// the payload's contract version in `meta`; any other method answers 405 with `Allow: GET`. A
|
|
5
|
+
// payload that fails its own contract answers INTERNAL rather than an unchecked body.
|
|
6
|
+
export function createHealthHandler(options) {
|
|
7
|
+
return function health(req, res) {
|
|
8
|
+
if (req.method !== "GET") {
|
|
9
|
+
options.responder.sendMethodNotAllowed(res, ["GET"]);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const result = options.contract.safeParse(options.read());
|
|
13
|
+
if (!result.success) {
|
|
14
|
+
options.responder.sendBffError(res, "INTERNAL", "Health contract is invalid");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
options.responder.sendBffSuccess(res, result.data, { contractVersion: result.data.contractVersion });
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createBffDispatcher, type BffDispatch, type BffDispatcherOptions, type RouteEntry } from "./dispatch.js";
|
|
2
|
+
export { lazyBffRoute } from "./lazyRoute.js";
|
|
3
|
+
export { rewriteBffRouterRequestUrl } from "./routerRewrite.js";
|
|
4
|
+
export { BFF_ERROR_CODES, BFF_ERROR_STATUS, BFF_REQUEST_REFERENCE_HEADER, createBffResponder, type BffError, type BffErrorCode, type BffErrorOptions, type BffErrorResponse, type BffMeta, type BffResponder, type BffResponderOptions, type BffResponse, type BffSuccessOptions, type BffSuccessResponse, } from "./envelope.js";
|
|
5
|
+
export { createHealthHandler, type HealthContract, type HealthHandlerOptions, } from "./health.js";
|
|
6
|
+
export { createRequestContextStore, type ObservedRequestContext, type RequestContextOptions, type RequestContextStore, } from "./requestContext.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createBffDispatcher } from "./dispatch.js";
|
|
2
|
+
export { lazyBffRoute } from "./lazyRoute.js";
|
|
3
|
+
export { rewriteBffRouterRequestUrl } from "./routerRewrite.js";
|
|
4
|
+
export { BFF_ERROR_CODES, BFF_ERROR_STATUS, BFF_REQUEST_REFERENCE_HEADER, createBffResponder, } from "./envelope.js";
|
|
5
|
+
export { createHealthHandler, } from "./health.js";
|
|
6
|
+
export { createRequestContextStore, } from "./requestContext.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function lazyBffRoute(load) {
|
|
2
|
+
let handler;
|
|
3
|
+
let loading;
|
|
4
|
+
return (req, res) => {
|
|
5
|
+
if (handler)
|
|
6
|
+
return handler(req, res);
|
|
7
|
+
loading ??= load().then((module) => (handler = module.default), (error) => {
|
|
8
|
+
loading = undefined;
|
|
9
|
+
throw error;
|
|
10
|
+
});
|
|
11
|
+
return loading.then((loaded) => loaded(req, res));
|
|
12
|
+
};
|
|
13
|
+
}
|