@proofoftech/flowsafe 0.1.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 (204) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +202 -0
  3. package/README.md +273 -0
  4. package/dist/approval-api/contract.d.ts +45 -0
  5. package/dist/approval-api/contract.d.ts.map +1 -0
  6. package/dist/approval-api/contract.js +37 -0
  7. package/dist/approval-api/contract.js.map +1 -0
  8. package/dist/approval-api/d1-store.d.ts +52 -0
  9. package/dist/approval-api/d1-store.d.ts.map +1 -0
  10. package/dist/approval-api/d1-store.js +468 -0
  11. package/dist/approval-api/d1-store.js.map +1 -0
  12. package/dist/approval-api/grants.d.ts +52 -0
  13. package/dist/approval-api/grants.d.ts.map +1 -0
  14. package/dist/approval-api/grants.js +200 -0
  15. package/dist/approval-api/grants.js.map +1 -0
  16. package/dist/approval-api/index.d.ts +21 -0
  17. package/dist/approval-api/index.d.ts.map +1 -0
  18. package/dist/approval-api/index.js +18 -0
  19. package/dist/approval-api/index.js.map +1 -0
  20. package/dist/approval-api/retention.d.ts +32 -0
  21. package/dist/approval-api/retention.d.ts.map +1 -0
  22. package/dist/approval-api/retention.js +81 -0
  23. package/dist/approval-api/retention.js.map +1 -0
  24. package/dist/approval-api/router.d.ts +51 -0
  25. package/dist/approval-api/router.d.ts.map +1 -0
  26. package/dist/approval-api/router.js +245 -0
  27. package/dist/approval-api/router.js.map +1 -0
  28. package/dist/approval-api/service.d.ts +134 -0
  29. package/dist/approval-api/service.d.ts.map +1 -0
  30. package/dist/approval-api/service.js +537 -0
  31. package/dist/approval-api/service.js.map +1 -0
  32. package/dist/approval-api/store.d.ts +126 -0
  33. package/dist/approval-api/store.d.ts.map +1 -0
  34. package/dist/approval-api/store.js +189 -0
  35. package/dist/approval-api/store.js.map +1 -0
  36. package/dist/approval-api/tenant-brand.d.ts +35 -0
  37. package/dist/approval-api/tenant-brand.d.ts.map +1 -0
  38. package/dist/approval-api/tenant-brand.js +18 -0
  39. package/dist/approval-api/tenant-brand.js.map +1 -0
  40. package/dist/approval-api/tenant-context.d.ts +44 -0
  41. package/dist/approval-api/tenant-context.d.ts.map +1 -0
  42. package/dist/approval-api/tenant-context.js +49 -0
  43. package/dist/approval-api/tenant-context.js.map +1 -0
  44. package/dist/approval-api/tenant-store.d.ts +36 -0
  45. package/dist/approval-api/tenant-store.d.ts.map +1 -0
  46. package/dist/approval-api/tenant-store.js +122 -0
  47. package/dist/approval-api/tenant-store.js.map +1 -0
  48. package/dist/approval-api/types.d.ts +247 -0
  49. package/dist/approval-api/types.d.ts.map +1 -0
  50. package/dist/approval-api/types.js +157 -0
  51. package/dist/approval-api/types.js.map +1 -0
  52. package/dist/approval-ui/App.d.ts +11 -0
  53. package/dist/approval-ui/App.d.ts.map +1 -0
  54. package/dist/approval-ui/App.js +15 -0
  55. package/dist/approval-ui/App.js.map +1 -0
  56. package/dist/approval-ui/DetailView.d.ts +13 -0
  57. package/dist/approval-ui/DetailView.d.ts.map +1 -0
  58. package/dist/approval-ui/DetailView.js +20 -0
  59. package/dist/approval-ui/DetailView.js.map +1 -0
  60. package/dist/approval-ui/MetricsView.d.ts +7 -0
  61. package/dist/approval-ui/MetricsView.d.ts.map +1 -0
  62. package/dist/approval-ui/MetricsView.js +22 -0
  63. package/dist/approval-ui/MetricsView.js.map +1 -0
  64. package/dist/approval-ui/QueueView.d.ts +11 -0
  65. package/dist/approval-ui/QueueView.d.ts.map +1 -0
  66. package/dist/approval-ui/QueueView.js +59 -0
  67. package/dist/approval-ui/QueueView.js.map +1 -0
  68. package/dist/approval-ui/client.d.ts +34 -0
  69. package/dist/approval-ui/client.d.ts.map +1 -0
  70. package/dist/approval-ui/client.js +103 -0
  71. package/dist/approval-ui/client.js.map +1 -0
  72. package/dist/approval-ui/components.d.ts +125 -0
  73. package/dist/approval-ui/components.d.ts.map +1 -0
  74. package/dist/approval-ui/components.js +54 -0
  75. package/dist/approval-ui/components.js.map +1 -0
  76. package/dist/approval-ui/index.d.ts +21 -0
  77. package/dist/approval-ui/index.d.ts.map +1 -0
  78. package/dist/approval-ui/index.js +21 -0
  79. package/dist/approval-ui/index.js.map +1 -0
  80. package/dist/approval-ui/mount.d.ts +23 -0
  81. package/dist/approval-ui/mount.d.ts.map +1 -0
  82. package/dist/approval-ui/mount.js +17 -0
  83. package/dist/approval-ui/mount.js.map +1 -0
  84. package/dist/approval-ui/tips.d.ts +32 -0
  85. package/dist/approval-ui/tips.d.ts.map +1 -0
  86. package/dist/approval-ui/tips.js +32 -0
  87. package/dist/approval-ui/tips.js.map +1 -0
  88. package/dist/approval-ui/use-approval-dashboard.d.ts +70 -0
  89. package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -0
  90. package/dist/approval-ui/use-approval-dashboard.js +148 -0
  91. package/dist/approval-ui/use-approval-dashboard.js.map +1 -0
  92. package/dist/approval-ui/view-model.d.ts +24 -0
  93. package/dist/approval-ui/view-model.d.ts.map +1 -0
  94. package/dist/approval-ui/view-model.js +62 -0
  95. package/dist/approval-ui/view-model.js.map +1 -0
  96. package/dist/artifacts/index.d.ts +123 -0
  97. package/dist/artifacts/index.d.ts.map +1 -0
  98. package/dist/artifacts/index.js +223 -0
  99. package/dist/artifacts/index.js.map +1 -0
  100. package/dist/audit-export/index.d.ts +71 -0
  101. package/dist/audit-export/index.d.ts.map +1 -0
  102. package/dist/audit-export/index.js +124 -0
  103. package/dist/audit-export/index.js.map +1 -0
  104. package/dist/do-runner/breakwater-keys.d.ts +23 -0
  105. package/dist/do-runner/breakwater-keys.d.ts.map +1 -0
  106. package/dist/do-runner/breakwater-keys.js +38 -0
  107. package/dist/do-runner/breakwater-keys.js.map +1 -0
  108. package/dist/do-runner/cf-types.d.ts +26 -0
  109. package/dist/do-runner/cf-types.d.ts.map +1 -0
  110. package/dist/do-runner/cf-types.js +13 -0
  111. package/dist/do-runner/cf-types.js.map +1 -0
  112. package/dist/do-runner/d1-storage.d.ts +128 -0
  113. package/dist/do-runner/d1-storage.d.ts.map +1 -0
  114. package/dist/do-runner/d1-storage.js +287 -0
  115. package/dist/do-runner/d1-storage.js.map +1 -0
  116. package/dist/do-runner/durable-object.d.ts +28 -0
  117. package/dist/do-runner/durable-object.d.ts.map +1 -0
  118. package/dist/do-runner/durable-object.js +164 -0
  119. package/dist/do-runner/durable-object.js.map +1 -0
  120. package/dist/do-runner/index.d.ts +12 -0
  121. package/dist/do-runner/index.d.ts.map +1 -0
  122. package/dist/do-runner/index.js +11 -0
  123. package/dist/do-runner/index.js.map +1 -0
  124. package/dist/do-runner/init.d.ts +38 -0
  125. package/dist/do-runner/init.d.ts.map +1 -0
  126. package/dist/do-runner/init.js +45 -0
  127. package/dist/do-runner/init.js.map +1 -0
  128. package/dist/do-runner/path-safe-id.d.ts +19 -0
  129. package/dist/do-runner/path-safe-id.d.ts.map +1 -0
  130. package/dist/do-runner/path-safe-id.js +70 -0
  131. package/dist/do-runner/path-safe-id.js.map +1 -0
  132. package/dist/do-runner/resume-ledger.d.ts +48 -0
  133. package/dist/do-runner/resume-ledger.d.ts.map +1 -0
  134. package/dist/do-runner/resume-ledger.js +59 -0
  135. package/dist/do-runner/resume-ledger.js.map +1 -0
  136. package/dist/do-runner/runtime.d.ts +161 -0
  137. package/dist/do-runner/runtime.d.ts.map +1 -0
  138. package/dist/do-runner/runtime.js +509 -0
  139. package/dist/do-runner/runtime.js.map +1 -0
  140. package/dist/host-kit/approval-bridge.d.ts +109 -0
  141. package/dist/host-kit/approval-bridge.d.ts.map +1 -0
  142. package/dist/host-kit/approval-bridge.js +262 -0
  143. package/dist/host-kit/approval-bridge.js.map +1 -0
  144. package/dist/host-kit/bearer-auth.d.ts +19 -0
  145. package/dist/host-kit/bearer-auth.d.ts.map +1 -0
  146. package/dist/host-kit/bearer-auth.js +67 -0
  147. package/dist/host-kit/bearer-auth.js.map +1 -0
  148. package/dist/host-kit/do-response.d.ts +13 -0
  149. package/dist/host-kit/do-response.d.ts.map +1 -0
  150. package/dist/host-kit/do-response.js +24 -0
  151. package/dist/host-kit/do-response.js.map +1 -0
  152. package/dist/host-kit/do-run-topology.d.ts +32 -0
  153. package/dist/host-kit/do-run-topology.d.ts.map +1 -0
  154. package/dist/host-kit/do-run-topology.js +39 -0
  155. package/dist/host-kit/do-run-topology.js.map +1 -0
  156. package/dist/host-kit/env-vars.d.ts +26 -0
  157. package/dist/host-kit/env-vars.d.ts.map +1 -0
  158. package/dist/host-kit/env-vars.js +48 -0
  159. package/dist/host-kit/env-vars.js.map +1 -0
  160. package/dist/host-kit/host-approval-service.d.ts +125 -0
  161. package/dist/host-kit/host-approval-service.d.ts.map +1 -0
  162. package/dist/host-kit/host-approval-service.js +187 -0
  163. package/dist/host-kit/host-approval-service.js.map +1 -0
  164. package/dist/host-kit/index.d.ts +18 -0
  165. package/dist/host-kit/index.d.ts.map +1 -0
  166. package/dist/host-kit/index.js +34 -0
  167. package/dist/host-kit/index.js.map +1 -0
  168. package/dist/host-kit/module.d.ts +34 -0
  169. package/dist/host-kit/module.d.ts.map +1 -0
  170. package/dist/host-kit/module.js +17 -0
  171. package/dist/host-kit/module.js.map +1 -0
  172. package/dist/host-kit/registration.d.ts +11 -0
  173. package/dist/host-kit/registration.d.ts.map +1 -0
  174. package/dist/host-kit/registration.js +21 -0
  175. package/dist/host-kit/registration.js.map +1 -0
  176. package/dist/host-kit/run-route-error.d.ts +11 -0
  177. package/dist/host-kit/run-route-error.d.ts.map +1 -0
  178. package/dist/host-kit/run-route-error.js +22 -0
  179. package/dist/host-kit/run-route-error.js.map +1 -0
  180. package/dist/host-kit/run-router.d.ts +60 -0
  181. package/dist/host-kit/run-router.d.ts.map +1 -0
  182. package/dist/host-kit/run-router.js +212 -0
  183. package/dist/host-kit/run-router.js.map +1 -0
  184. package/dist/host-kit/subdomain-check.d.ts +23 -0
  185. package/dist/host-kit/subdomain-check.d.ts.map +1 -0
  186. package/dist/host-kit/subdomain-check.js +60 -0
  187. package/dist/host-kit/subdomain-check.js.map +1 -0
  188. package/dist/host-kit/tenant-registry.d.ts +51 -0
  189. package/dist/host-kit/tenant-registry.d.ts.map +1 -0
  190. package/dist/host-kit/tenant-registry.js +87 -0
  191. package/dist/host-kit/tenant-registry.js.map +1 -0
  192. package/dist/host-kit/verifier.d.ts +63 -0
  193. package/dist/host-kit/verifier.d.ts.map +1 -0
  194. package/dist/host-kit/verifier.js +191 -0
  195. package/dist/host-kit/verifier.js.map +1 -0
  196. package/dist/host-kit/workflow-meta.d.ts +25 -0
  197. package/dist/host-kit/workflow-meta.d.ts.map +1 -0
  198. package/dist/host-kit/workflow-meta.js +12 -0
  199. package/dist/host-kit/workflow-meta.js.map +1 -0
  200. package/dist/index.d.ts +9 -0
  201. package/dist/index.d.ts.map +1 -0
  202. package/dist/index.js +25 -0
  203. package/dist/index.js.map +1 -0
  204. package/package.json +95 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # @proofoftech/flowsafe
2
+
3
+ ## 0.1.0 — 2026-07-11
4
+
5
+ First publishable cut. Approval UX + Cloudflare-native durable execution for
6
+ Mastra workflows: Durable Object runner (`init()` import-swap, server-minted
7
+ tenant-prefixed run ids, durable resume ledger), approval queue API (CAS-guarded
8
+ D1/in-memory stores, tenant-bound factories, separation-of-duties service,
9
+ SLA sweep, derivation-based grant minting), styling-agnostic React approval
10
+ dashboard (headless hook + slot components, optional react peer), host-kit
11
+ (run router, tenant resolver, bearer auth seam, approval bridge), Cloudflare
12
+ Queues audit export, R2 artifact store, and a copy-ready production Worker
13
+ template in `deploy/`.
14
+
15
+ `@proofoftech/breakwater` is an optional peer: only the `./host-kit/module`
16
+ subpath references its types. Install it when wiring `WorkflowModule` audit
17
+ contexts; every other subpath works without it.
18
+
19
+ Requires `@mastra/core` ^1.50.0 (peer), Node >= 22, ESM only
20
+ (`moduleResolution` `node16`/`nodenext`/`bundler`). React 18 or 19 only for
21
+ `./approval-ui`.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 proofoftech
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.
package/README.md ADDED
@@ -0,0 +1,273 @@
1
+ # flowsafe
2
+
3
+ Approval UX and durable execution for Mastra workflows, running on Cloudflare
4
+ Workers and Durable Objects.
5
+
6
+ ## Purpose
7
+
8
+ flowsafe provides human-in-the-loop approval gates for Mastra workflows and
9
+ durable execution via the Durable Object import-swap pattern. It ships as a
10
+ standalone service with a React approval UI and a DO-based workflow runner.
11
+
12
+ ## Subpackages
13
+
14
+ | Subpackage | Role |
15
+ |---|---|
16
+ | `approval-api` | REST API for submitting and reviewing approval requests |
17
+ | `approval-ui` | Styling-agnostic React UI surfacing pending approvals and history |
18
+ | `do-runner` | Durable Object workflow runner (import-swap pattern) |
19
+ | `audit-export` | Cloudflare Queues → SIEM audit export (producer sink + batch consumer) |
20
+ | `artifacts` | R2-backed workflow artifact storage keyed by run identity |
21
+ | `host-kit` | Host-agnostic glue: the identity seam (`TokenVerifier`), the tenant resolver, the shared `/workflows` + `/runs` routes, the tenants registry, the suspension→approval bridge |
22
+
23
+ A copy-ready production deployment lives in [`deploy/`](deploy/) — a Worker
24
+ wiring all of the above with cron-owned SLA enforcement and retention purge.
25
+
26
+ ## Installation
27
+
28
+ ```
29
+ npm install @proofoftech/flowsafe
30
+ ```
31
+
32
+ Support matrix: Node >= 22, ESM only (TypeScript `moduleResolution`
33
+ `node16`/`nodenext`/`bundler`; no CJS build), `@mastra/core` ^1.50.0 as a
34
+ peer. React 18 or 19 is an optional peer used only by `./approval-ui`;
35
+ `@proofoftech/breakwater` is an optional peer whose types only the
36
+ `./host-kit/module` subpath references.
37
+
38
+ ## Status
39
+
40
+ Implemented, tested, and spike-verified. The do-runner + D1 adapter run a
41
+ Mastra workflow on Workers + DO under `wrangler dev`, suspend at an approval
42
+ step, survive a full dev-server restart, and resume to completion from the
43
+ D1 snapshot — proven as a pass/fail command by
44
+ `pnpm --filter @proofoftech/flowsafe spike:verify`.
45
+
46
+ The approval queue + dashboard + SLA are implemented, tested, and
47
+ spike-verified on workerd: a suspension queues a D1-backed approval request
48
+ (CAS-guarded store, one open request per suspended step); a reviewer decision
49
+ — role-checked, audited, SLA-tracked, self-approval denied by default —
50
+ resumes the run through its Durable Object; and the runtime's
51
+ `requestContextForRun` provider derives the breakwater connector grant
52
+ (`breakwater.approvedConnectors`) from APPROVED records on every
53
+ start/resume, leg-scoped to the resumed step. Grants never travel in HTTP
54
+ bodies: a resume that bypasses `decide()` for its step finds no grant and
55
+ fails closed at the connector gate — even when the same connector was
56
+ approved at an earlier gate of the run.
57
+
58
+ flowsafe is **multi-tenant by construction** (see
59
+ [Multi-tenancy](#multi-tenancy) below): run ids carry their tenant, approval
60
+ stores are bound to one tenant at construction, and the cross-tenant SLA sweep
61
+ is cron-only code that a request handler cannot reach — enforced by the type
62
+ system, not by convention.
63
+
64
+ ## Usage
65
+
66
+ ```typescript
67
+ import { z } from 'zod';
68
+ import { DurableObjectRunner, init, type RunnerRuntime } from '@proofoftech/flowsafe/do-runner';
69
+
70
+ // Inside the Durable Object: init(env) builds D1-backed storage from the
71
+ // conventional `DB` binding (or pass { storage } explicitly, e.g. in tests)
72
+ // and returns import-swapped factories. Workflow definition code is
73
+ // unchanged Mastra code.
74
+ export class MyRunner extends DurableObjectRunner<Env> {
75
+ protected build(env: Env): RunnerRuntime {
76
+ const { createWorkflow, createStep, runtime } = init(env);
77
+ const gate = createStep({
78
+ id: 'approval',
79
+ inputSchema: z.object({ topic: z.string() }),
80
+ outputSchema: z.object({ topic: z.string(), approvedBy: z.string() }),
81
+ suspendSchema: z.object({ reason: z.string() }),
82
+ resumeSchema: z.object({ approvedBy: z.string() }),
83
+ execute: async ({ inputData, resumeData, suspend }) => {
84
+ if (!resumeData) return suspend({ reason: 'approval required' });
85
+ return { topic: inputData.topic, approvedBy: resumeData.approvedBy };
86
+ },
87
+ });
88
+ createWorkflow({
89
+ id: 'gated',
90
+ inputSchema: z.object({ topic: z.string() }),
91
+ outputSchema: z.object({ topic: z.string(), approvedBy: z.string() }),
92
+ })
93
+ .then(gate)
94
+ .commit();
95
+ return runtime;
96
+ }
97
+ }
98
+ ```
99
+
100
+ The DO exposes `POST /runs`, `GET /runs/:workflowId/:runId`, and
101
+ `POST /runs/:workflowId/:runId/resume`; route one DO instance per run
102
+ (`idFromName(workflowId + ':' + runId)`) from your Worker. See
103
+ `spike/worker.ts` for a complete Worker, and run the end-to-end spike with
104
+ `pnpm spike` (wrangler dev on `spike/wrangler.jsonc`).
105
+
106
+ ### Approval queue (`@proofoftech/flowsafe/approval-api`)
107
+
108
+ ```typescript
109
+ import {
110
+ approvalGrantProvider,
111
+ ApprovalService,
112
+ createApprovalRouter,
113
+ createTenantResolver,
114
+ D1ApprovalStoreFactory,
115
+ resumeViaRuntime,
116
+ sweepSLA,
117
+ } from '@proofoftech/flowsafe/approval-api';
118
+ import { bearerActorAuthenticator, staticTokenVerifier, parseActorTokens }
119
+ from '@proofoftech/flowsafe/host-kit';
120
+
121
+ // Hoist the factory to module scope: it owns one memoized schema-init pass,
122
+ // so rebuilding it per request re-runs the DDL every time.
123
+ const factory = new D1ApprovalStoreFactory(env.DB); // shares the runner's D1
124
+
125
+ // 1. Grant-minting seam. Inside a Durable Object, bind the store to THIS
126
+ // instance's tenant (recovered from its own idFromName identity), so the
127
+ // mint can only ever read its own tenant's records.
128
+ const { createWorkflow, createStep, runtime } = init(env, {
129
+ requestContextForRun: approvalGrantProvider(factory.forTenant(this.tenantId)),
130
+ });
131
+
132
+ // 2. Authenticate FIRST, then construct. The resolver validates the actor's
133
+ // tenant and binds the store to it, so there is no pre-auth service for a
134
+ // later refactor to reach for.
135
+ const resolve = createTenantResolver({
136
+ authenticate: bearerActorAuthenticator(
137
+ staticTokenVerifier(parseActorTokens(env.APPROVAL_ACTOR_TOKENS)),
138
+ ),
139
+ storeFactory: factory,
140
+ buildService: (store) =>
141
+ new ApprovalService({
142
+ store, // tenant-bound; required
143
+ defaultSlaSeconds: 15 * 60,
144
+ resumeRun: resumeViaRuntime(runtime), // or a DO-stub fetch
145
+ audit: (event) => auditLogger.record(event),
146
+ }),
147
+ });
148
+
149
+ // 3. REST surface (list/get/claim/decide/delegate/metrics). The create route
150
+ // is off unless you pass allowCreate.
151
+ const router = createApprovalRouter({ resolve });
152
+ ```
153
+
154
+ Escalation is **cron-only**. There is deliberately no HTTP sweep route: the
155
+ sweep is an unfiltered cross-tenant read *and write*, so it lives in a
156
+ standalone `sweepSLA(factory.system(), { systemActor, audit, onEscalation })`
157
+ that takes a `SystemApprovalStore` — a type a request handler cannot obtain.
158
+ Call it from `scheduled()`. Breached open requests transition to `escalated`
159
+ (still decidable) and fire `onEscalation`.
160
+
161
+ Grant scope: a step-keyed approval unlocks its connectors only for the leg
162
+ that resumes that step, and only for the suspension it was decided during —
163
+ when the same step suspends again, the earlier approval is spent and the new
164
+ suspension needs its own decision. Create a step-less approval for
165
+ deliberately run-scoped standing grants. Self-approval (decider ==
166
+ requester) is denied unless the service is constructed with
167
+ `allowSelfDecision: true`. If a decision's
168
+ resume attempt fails (`resume.ok === false`), the decision is already
169
+ durable — re-drive the run by POSTing its resume route with the record's
170
+ `stepPath` and the `defaultResumeData` shape; grants re-derive from the
171
+ store.
172
+
173
+ ### Dashboard (`@proofoftech/flowsafe/approval-ui`)
174
+
175
+ A React dashboard over the REST API — queue, detail + decision form, metrics.
176
+ It is **styling-library agnostic**: the views render through injected slot
177
+ components, so you plug in your own design system — or use the built-in unstyled
178
+ HTML default. `react`/`react-dom` are optional peers needed only for this
179
+ subpath, and it runs on React 18+.
180
+
181
+ ```typescript
182
+ import { ApprovalApiClient, createApprovalDashboard } from '@proofoftech/flowsafe/approval-ui';
183
+
184
+ const client = new ApprovalApiClient({ headers: { authorization: `Bearer ${token}` } });
185
+
186
+ // Unstyled HTML default — zero extra deps; style via the flowsafe-* class hooks.
187
+ const dashboard = createApprovalDashboard(document.getElementById('root')!, { client });
188
+
189
+ // …or supply a design-system adapter for the ApprovalUIComponents slots:
190
+ // createApprovalDashboard(el, { client, components: myAdapter });
191
+ ```
192
+
193
+ For a headless integration, drive `useApprovalDashboard(client)` yourself and
194
+ render any UI you like. A ready-to-run reference app lives in the repo's
195
+ `showcase` package (`packages/showcase/` — `pnpm --filter showcase dev`, or
196
+ `pnpm dev` at the root): a full Vite build that injects an
197
+ [Astryx](https://astryx.atmeta.com) adapter, bundles that library's CSS, and —
198
+ in dev — mounts a live seeded approval-api at `/api/approvals` so
199
+ claim/decide/delegate drive real state.
200
+
201
+ ## Multi-tenancy
202
+
203
+ Three invariants, each enforced at a single chokepoint. Everything else is a
204
+ corollary.
205
+
206
+ **INV-1 — the run id carries the tenant.** Every `runId` is minted
207
+ server-side as `` `${tenantId}_${uuid}` `` from the *authenticated* tenant.
208
+ `createRunRouter` rejects a client-supplied `body.runId` with 400,
209
+ `RunnerRuntime.start` requires a `runId` (there is no generation fallback),
210
+ and the Durable Object refuses any request whose `(workflowId, runId)`
211
+ disagrees with its own `ctx.id.name`. Because `runId` is the key everything
212
+ else derives from, this makes the Mastra snapshot row, the DO instance, the
213
+ per-run lock, the grant-mint predicate, and the R2 key tenant-disjoint with
214
+ no schema change and no signature change. Status and resume additionally
215
+ check ownership and answer **404** — not 403 — for another tenant's run, so
216
+ the route is not an existence oracle.
217
+
218
+ **INV-2 — the store is bound to one tenant at construction.** Approval
219
+ stores come only from a factory (`D1ApprovalStoreFactory.forTenant()`), and
220
+ the bound type carries a `unique symbol` brand: an unbound store, or the
221
+ cron-only `SystemApprovalStore`, is a *compile error* wherever a request
222
+ handler expects a bound one. `tenantId` is deliberately not a member of
223
+ `ApprovalListFilter` — an omissible tenant filter is the canonical fail-open.
224
+ Requests flow through a `TenantResolver` (authenticate → validate → bind), so
225
+ no pre-auth store exists.
226
+
227
+ **INV-3 — the charset makes the prefix exact.** `tenantId` matches
228
+ `^[a-z0-9]{3,32}$`. That set contains no character in `[0x5F, 0x60]` —
229
+ neither `_` nor `` ` `` — so `runId.startsWith(tenantId + '_')` cannot match
230
+ another tenant (`acme` never matches `acmecorp`), and the offboarding range
231
+ delete `` run_id >= '<tid>_' AND run_id < '<tid>`' `` selects exactly one
232
+ tenant's rows. Loosening the charset silently breaks both; a
233
+ character-exhaustive test pins it.
234
+
235
+ Consequences worth knowing:
236
+
237
+ - **Provision before you issue tokens.** `provisionTenant(db, { tenantId, kind })`
238
+ (import from `@proofoftech/flowsafe/host-kit`)
239
+ inserts into the `tenants` registry or fails. Nothing else enforces tenant-id
240
+ uniqueness, and two clients slugged `acme` would merge entirely.
241
+ - **Every actor carries a tenant.** `ApprovalActor` is `{ id, role, tenantId }`;
242
+ a bearer-map entry or JWT claim without an INV-3-valid `tenantId` is dropped
243
+ and its token 401s. breakwater's own `Actor` stays tenant-agnostic.
244
+ - **Connector budgets are per-tenant.** The runtime mints an opaque
245
+ `breakwater.isolationScope` on every leg of a tenant-salted run, and
246
+ breakwater segments its idempotency and rate-limit keys by it — so one
247
+ tenant exhausting a connector's budget cannot throttle another, and two
248
+ tenants sharing a business-level idempotency key do not replay each other's
249
+ results. Absent scope preserves the single-tenant keys exactly; there is no
250
+ flag to forget.
251
+ - **Offboarding is one call.** `purgeTenant(db, { tenantId, artifactStore })`
252
+ (import from `@proofoftech/flowsafe/do-runner` or the package root)
253
+ reaps snapshots of *any* status (a run abandoned at a gate is never eligible
254
+ for the terminal-only retention purge), the tenant's approval records, and
255
+ its R2 artifacts. Only purge tenants whose tokens have already expired.
256
+
257
+ ### Deployment & ops
258
+
259
+ Copy [`deploy/`](deploy/) as a production starting point: a Worker wiring one
260
+ DO per run, the D1 approval queue, the tenant resolver over a bearer-token
261
+ verifier, an optional subdomain↔tenant cross-check, and a cron trigger that
262
+ owns the SLA sweep and snapshot retention purge. `pnpm deploy:dev` runs it on
263
+ local workerd (no Cloudflare account); `pnpm deploy:cf` deploys it. Checklist
264
+ and configuration table: [`deploy/README.md`](deploy/README.md).
265
+
266
+ Audit export ships as a Cloudflare Queues sink + SIEM consumer
267
+ (`@proofoftech/flowsafe/audit-export`): `queueAuditSink(env.QUEUE)` plugs into
268
+ any breakwater/approval audit sink, and `createAuditQueueConsumer({ endpoint })`
269
+ POSTs each batch as NDJSON, acking on 2xx and retrying otherwise. Workflow
270
+ artifacts persist to R2 via `R2ArtifactStore`
271
+ (`@proofoftech/flowsafe/artifacts`), keyed `workflowId/runId/name`.
272
+
273
+ See `docs/flowsafe-architecture.md` and `docs/do-runner-design.md` for design details.
@@ -0,0 +1,45 @@
1
+ export { BREAKWATER_ACTOR_KEY, BREAKWATER_APPROVED_CONNECTORS_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, } from '../do-runner/breakwater-keys.js';
2
+ /** breakwater's five roles (security-threat-model.md, RBAC model). */
3
+ export type ApprovalRole = 'admin' | 'builder' | 'operator' | 'reviewer' | 'viewer';
4
+ export declare const APPROVAL_ROLES: readonly ApprovalRole[];
5
+ /**
6
+ * Roles permitted to START a run at the HTTP route — the coarse start-role gate
7
+ * every host applies to POST /runs, before any per-workflow allowedRoles check.
8
+ * A strict subset of APPROVAL_ROLES; reviewer/viewer are review-only. A
9
+ * host-level concept (breakwater has no equivalent), so there is no cross-package
10
+ * mirror to keep.
11
+ */
12
+ export declare const RUN_START_ROLES: readonly ApprovalRole[];
13
+ /**
14
+ * The acting principal — breakwater's Actor shape plus the platform's tenant
15
+ * dimension. breakwater stays tenant-agnostic (it is a standalone library);
16
+ * flowsafe is the multi-tenant host, so ITS actor carries the tenant. The
17
+ * e2e mirror tripwire pins "breakwater's Actor fields + tenantId".
18
+ *
19
+ * `tenantId` crosses an authentication boundary (bearer map or JWT claims):
20
+ * every verifier must validate it against TENANT_ID_PATTERN (INV-3,
21
+ * do-runner/path-safe-id.ts) before constructing an ApprovalActor — the type
22
+ * says `string`, but the type system has no authority over a decoded token.
23
+ */
24
+ export interface ApprovalActor {
25
+ id: string;
26
+ role: ApprovalRole;
27
+ tenantId: string;
28
+ }
29
+ /**
30
+ * Audit event the approval service emits — structurally assignable to
31
+ * breakwater AuditLogger.record's argument, so wiring is one line:
32
+ * `audit: (event) => auditLogger.record(event)`.
33
+ */
34
+ export interface ApprovalAuditEvent {
35
+ actor: ApprovalActor | null;
36
+ /** Dotted verb, e.g. 'approval.decide'. */
37
+ action: string;
38
+ /** What was acted on, e.g. 'approval:<id>'. */
39
+ resource: string;
40
+ decision: 'allowed' | 'denied' | 'error';
41
+ reason?: string;
42
+ detail?: Record<string, unknown>;
43
+ }
44
+ export type ApprovalAuditSink = (event: ApprovalAuditEvent) => void;
45
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/approval-api/contract.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AAEzC,sEAAsE;AACtE,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,SAAS,GACT,UAAU,GACV,UAAU,GACV,QAAQ,CAAC;AAEb,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAMjD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAIlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC5B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC"}
@@ -0,0 +1,37 @@
1
+ // The breakwater <-> flowsafe wire contract (mirrored by value), plus the
2
+ // flowsafe host role policy derived from it (RUN_START_ROLES).
3
+ //
4
+ // flowsafe deliberately does NOT import @proofoftech/breakwater at runtime:
5
+ // the packages compose over documented requestContext keys
6
+ // (docs/security-threat-model.md, trust boundary 6), and a
7
+ // runtime dependency would force breakwater's dist to exist before flowsafe
8
+ // typechecks (the repo gate runs typecheck before build). Literal equality
9
+ // with breakwater's exported constants is enforced by the cross-package
10
+ // contract tests in end-to-end.test.ts — drift fails the suite, not
11
+ // production.
12
+ // The requestContext key literals live in do-runner/breakwater-keys.ts —
13
+ // the runtime mints the workflow-scope key itself, and homing the literals
14
+ // in a do-runner leaf keeps approval-api -> do-runner as the only
15
+ // cross-directory dependency direction. Re-exported here because this
16
+ // module is the approval-api's contract surface.
17
+ export { BREAKWATER_ACTOR_KEY, BREAKWATER_APPROVED_CONNECTORS_KEY, BREAKWATER_WORKFLOW_SCOPE_KEY, } from '../do-runner/breakwater-keys.js';
18
+ export const APPROVAL_ROLES = [
19
+ 'admin',
20
+ 'builder',
21
+ 'operator',
22
+ 'reviewer',
23
+ 'viewer',
24
+ ];
25
+ /**
26
+ * Roles permitted to START a run at the HTTP route — the coarse start-role gate
27
+ * every host applies to POST /runs, before any per-workflow allowedRoles check.
28
+ * A strict subset of APPROVAL_ROLES; reviewer/viewer are review-only. A
29
+ * host-level concept (breakwater has no equivalent), so there is no cross-package
30
+ * mirror to keep.
31
+ */
32
+ export const RUN_START_ROLES = [
33
+ 'admin',
34
+ 'operator',
35
+ 'builder',
36
+ ];
37
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/approval-api/contract.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+DAA+D;AAC/D,EAAE;AACF,4EAA4E;AAC5E,2DAA2D;AAC3D,2DAA2D;AAC3D,4EAA4E;AAC5E,2EAA2E;AAC3E,wEAAwE;AACxE,oEAAoE;AACpE,cAAc;AAEd,yEAAyE;AACzE,2EAA2E;AAC3E,kEAAkE;AAClE,sEAAsE;AACtE,iDAAiD;AACjD,OAAO,EACL,oBAAoB,EACpB,kCAAkC,EAClC,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AAUzC,MAAM,CAAC,MAAM,cAAc,GAA4B;IACrD,OAAO;IACP,SAAS;IACT,UAAU;IACV,UAAU;IACV,QAAQ;CACT,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAA4B;IACtD,OAAO;IACP,UAAU;IACV,SAAS;CACV,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { type ApprovalPatch, type ApprovalStore, type CreateResult } from './store.js';
2
+ import { type SystemApprovalStore, TENANT_BOUND } from './tenant-brand.js';
3
+ import { type ApprovalListFilter, type ApprovalMetrics, type ApprovalRecord, type ApprovalStatus } from './types.js';
4
+ /**
5
+ * The subset of D1Database this store uses, held structurally so tests can
6
+ * back it with real SQLite (node:sqlite) and Workers pass env.DB directly.
7
+ */
8
+ export interface ApprovalDatabase {
9
+ prepare(query: string): ApprovalPreparedStatement;
10
+ }
11
+ export interface ApprovalPreparedStatement {
12
+ bind(...values: unknown[]): ApprovalPreparedStatement;
13
+ first<T = unknown>(): Promise<T | null>;
14
+ run(): Promise<unknown>;
15
+ all<T = unknown>(): Promise<{
16
+ results: T[];
17
+ }>;
18
+ }
19
+ export interface D1ApprovalStoreOptions {
20
+ tenantId: string;
21
+ /**
22
+ * Shared schema gate: the factory memoizes ONE schema-init promise across
23
+ * every per-request forTenant() store, so DDL runs once per isolate rather
24
+ * than once per request. Default: this instance memoizes its own.
25
+ */
26
+ ready?: () => Promise<void>;
27
+ }
28
+ /**
29
+ * One-shot schema creation + fail-closed shape check. Exported for the
30
+ * factory (which owns the cross-instance memo) and the schema tests.
31
+ *
32
+ * REFUSES a pre-tenant table: `ALTER TABLE ... ADD COLUMN tenant_id TEXT NOT
33
+ * NULL` without a default is rejected by SQLite even on an empty table, and a
34
+ * NULL/'' tenant is an isolation hole — so there is deliberately NO backfill.
35
+ * A database created before the tenant column must be recreated (nothing is
36
+ * deployed; local `.wrangler/` state is deleted, not migrated).
37
+ */
38
+ export declare function createApprovalSchema(db: ApprovalDatabase): Promise<void>;
39
+ export declare class D1ApprovalStore implements ApprovalStore {
40
+ #private;
41
+ readonly tenantId: string;
42
+ readonly [TENANT_BOUND]: true;
43
+ constructor(db: ApprovalDatabase, options: D1ApprovalStoreOptions);
44
+ create(record: ApprovalRecord): Promise<CreateResult>;
45
+ get(id: string): Promise<ApprovalRecord | null>;
46
+ list(filter?: ApprovalListFilter): Promise<ApprovalRecord[]>;
47
+ metrics(nowMs: number): Promise<ApprovalMetrics>;
48
+ transition(id: string, from: readonly ApprovalStatus[], patch: ApprovalPatch): Promise<ApprovalRecord | null>;
49
+ }
50
+ /** The cron-only cross-tenant view over the same table — see tenant-brand.ts. */
51
+ export declare function d1SystemApprovalStore(db: ApprovalDatabase, ready: () => Promise<void>): SystemApprovalStore;
52
+ //# sourceMappingURL=d1-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d1-store.d.ts","sourceRoot":"","sources":["../../src/approval-api/d1-store.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EAMpB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB,CAAC;CACnD;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,yBAAyB,CAAC;IACtD,KAAK,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACxC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxB,GAAG,CAAC,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;CAC/C;AA0RD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,gBAAgB,GACnB,OAAO,CAAC,IAAI,CAAC,CA+Bf;AAED,qBAAa,eAAgB,YAAW,aAAa;;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAG,IAAI,CAAU;gBAK5B,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,sBAAsB;IAW3D,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAoErD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAU/C,IAAI,CAAC,MAAM,GAAE,kBAAuB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAmBhE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAShD,UAAU,CACd,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,SAAS,cAAc,EAAE,EAC/B,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;CAgDlC;AAMD,iFAAiF;AACjF,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,gBAAgB,EACpB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACzB,mBAAmB,CA8DrB"}