@leed-ai/git-gateway-worker 0.0.0-stage → 0.1.1-next.20261122193358

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 (269) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +49 -2
  3. package/dist/audit/audit-recorder.d.ts +2 -0
  4. package/dist/audit/audit-recorder.js +53 -0
  5. package/dist/audit/audit-recorder.js.map +1 -0
  6. package/dist/audit/push-report.d.ts +13 -0
  7. package/dist/audit/push-report.js +66 -0
  8. package/dist/audit/push-report.js.map +1 -0
  9. package/dist/audit-recorder-K1Ns3tfC.d.ts +31 -0
  10. package/dist/auth/authenticate.d.ts +14 -0
  11. package/dist/auth/authenticate.js +59 -0
  12. package/dist/auth/authenticate.js.map +1 -0
  13. package/dist/auth/authorize.d.ts +12 -0
  14. package/dist/auth/authorize.js +57 -0
  15. package/dist/auth/authorize.js.map +1 -0
  16. package/dist/auth/read-token-auth.d.ts +60 -0
  17. package/dist/auth/read-token-auth.js +83 -0
  18. package/dist/auth/read-token-auth.js.map +1 -0
  19. package/dist/cache/decision-cache.d.ts +2 -0
  20. package/dist/cache/decision-cache.js +45 -0
  21. package/dist/cache/decision-cache.js.map +1 -0
  22. package/dist/commit-workflow-schemas-BWlg7bZR.d.ts +95 -0
  23. package/dist/decision-cache-87U32iSj.d.ts +24 -0
  24. package/dist/gateway-app.d.ts +69 -0
  25. package/dist/gateway-app.js +80 -0
  26. package/dist/gateway-app.js.map +1 -0
  27. package/dist/gateway-context-Boh9I0mk.d.ts +54 -0
  28. package/dist/gateway-env-DnsBU4Pq.d.ts +40 -0
  29. package/dist/gateway-worker.d.ts +13 -0
  30. package/dist/gateway-worker.js +22 -0
  31. package/dist/gateway-worker.js.map +1 -0
  32. package/dist/git-route-Spxi09Rm.d.ts +22 -0
  33. package/dist/health.d.ts +6 -0
  34. package/dist/health.js +16 -0
  35. package/dist/health.js.map +1 -0
  36. package/dist/logger-BZ1zyKLb.d.ts +27 -0
  37. package/dist/logging/logger.d.ts +2 -0
  38. package/dist/logging/logger.js +15 -0
  39. package/dist/logging/logger.js.map +1 -0
  40. package/dist/on-push-DTREOB__.d.ts +62 -0
  41. package/dist/policy/branch-policy.d.ts +24 -0
  42. package/dist/policy/branch-policy.js +125 -0
  43. package/dist/policy/branch-policy.js.map +1 -0
  44. package/dist/policy/enforce-branch-policy.d.ts +30 -0
  45. package/dist/policy/enforce-branch-policy.js +214 -0
  46. package/dist/policy/enforce-branch-policy.js.map +1 -0
  47. package/dist/policy/fast-forward.d.ts +32 -0
  48. package/dist/policy/fast-forward.js +95 -0
  49. package/dist/policy/fast-forward.js.map +1 -0
  50. package/dist/policy/ref-pattern.d.ts +7 -0
  51. package/dist/policy/ref-pattern.js +25 -0
  52. package/dist/policy/ref-pattern.js.map +1 -0
  53. package/dist/policy/rule-branch-policy.d.ts +17 -0
  54. package/dist/policy/rule-branch-policy.js +69 -0
  55. package/dist/policy/rule-branch-policy.js.map +1 -0
  56. package/dist/proxy/defer.d.ts +8 -0
  57. package/dist/proxy/defer.js +15 -0
  58. package/dist/proxy/defer.js.map +1 -0
  59. package/dist/proxy/forward-read.d.ts +11 -0
  60. package/dist/proxy/forward-read.js +53 -0
  61. package/dist/proxy/forward-read.js.map +1 -0
  62. package/dist/proxy/gateway-deps.d.ts +39 -0
  63. package/dist/proxy/gateway-deps.js +0 -0
  64. package/dist/proxy/gateway-env.d.ts +2 -0
  65. package/dist/proxy/gateway-env.js +0 -0
  66. package/dist/proxy/git-responses.d.ts +25 -0
  67. package/dist/proxy/git-responses.js +83 -0
  68. package/dist/proxy/git-responses.js.map +1 -0
  69. package/dist/proxy/git-route.d.ts +2 -0
  70. package/dist/proxy/git-route.js +34 -0
  71. package/dist/proxy/git-route.js.map +1 -0
  72. package/dist/proxy/push-events.d.ts +28 -0
  73. package/dist/proxy/push-events.js +65 -0
  74. package/dist/proxy/push-events.js.map +1 -0
  75. package/dist/proxy/push-guard.d.ts +43 -0
  76. package/dist/proxy/push-guard.js +81 -0
  77. package/dist/proxy/push-guard.js.map +1 -0
  78. package/dist/proxy/push-options.d.ts +16 -0
  79. package/dist/proxy/push-options.js +33 -0
  80. package/dist/proxy/push-options.js.map +1 -0
  81. package/dist/proxy/receive-pack.d.ts +17 -0
  82. package/dist/proxy/receive-pack.js +244 -0
  83. package/dist/proxy/receive-pack.js.map +1 -0
  84. package/dist/proxy/request-log.d.ts +13 -0
  85. package/dist/proxy/request-log.js +41 -0
  86. package/dist/proxy/request-log.js.map +1 -0
  87. package/dist/proxy/resolve-route.d.ts +9 -0
  88. package/dist/proxy/resolve-route.js +22 -0
  89. package/dist/proxy/resolve-route.js.map +1 -0
  90. package/dist/proxy/upstream-call.d.ts +23 -0
  91. package/dist/proxy/upstream-call.js +63 -0
  92. package/dist/proxy/upstream-call.js.map +1 -0
  93. package/dist/proxy/upstream.d.ts +2 -0
  94. package/dist/proxy/upstream.js +68 -0
  95. package/dist/proxy/upstream.js.map +1 -0
  96. package/dist/push-event-f-5TsFUY.d.ts +15 -0
  97. package/dist/push-policy/changed-paths.d.ts +26 -0
  98. package/dist/push-policy/changed-paths.js +117 -0
  99. package/dist/push-policy/changed-paths.js.map +1 -0
  100. package/dist/push-policy/pushed-objects.d.ts +30 -0
  101. package/dist/push-policy/pushed-objects.js +76 -0
  102. package/dist/push-policy/pushed-objects.js.map +1 -0
  103. package/dist/push-policy/run-push-policy.d.ts +35 -0
  104. package/dist/push-policy/run-push-policy.js +77 -0
  105. package/dist/push-policy/run-push-policy.js.map +1 -0
  106. package/dist/push-policy/tree-diff.d.ts +21 -0
  107. package/dist/push-policy/tree-diff.js +78 -0
  108. package/dist/push-policy/tree-diff.js.map +1 -0
  109. package/dist/push-policy/uncheckable.d.ts +14 -0
  110. package/dist/push-policy/uncheckable.js +25 -0
  111. package/dist/push-policy/uncheckable.js.map +1 -0
  112. package/dist/rpc/branch-methods.d.ts +16 -0
  113. package/dist/rpc/branch-methods.js +43 -0
  114. package/dist/rpc/branch-methods.js.map +1 -0
  115. package/dist/rpc/commit-attempt.d.ts +27 -0
  116. package/dist/rpc/commit-attempt.js +85 -0
  117. package/dist/rpc/commit-attempt.js.map +1 -0
  118. package/dist/rpc/commit-graph.d.ts +20 -0
  119. package/dist/rpc/commit-graph.js +38 -0
  120. package/dist/rpc/commit-graph.js.map +1 -0
  121. package/dist/rpc/commit-method.d.ts +13 -0
  122. package/dist/rpc/commit-method.js +30 -0
  123. package/dist/rpc/commit-method.js.map +1 -0
  124. package/dist/rpc/commit-source.d.ts +12 -0
  125. package/dist/rpc/commit-source.js +9 -0
  126. package/dist/rpc/commit-source.js.map +1 -0
  127. package/dist/rpc/gateway-context.d.ts +2 -0
  128. package/dist/rpc/gateway-context.js +30 -0
  129. package/dist/rpc/gateway-context.js.map +1 -0
  130. package/dist/rpc/gateway-rpc.d.ts +10 -0
  131. package/dist/rpc/gateway-rpc.js +48 -0
  132. package/dist/rpc/gateway-rpc.js.map +1 -0
  133. package/dist/rpc/gateway-service.d.ts +24 -0
  134. package/dist/rpc/gateway-service.js +63 -0
  135. package/dist/rpc/gateway-service.js.map +1 -0
  136. package/dist/rpc/history-page.d.ts +35 -0
  137. package/dist/rpc/history-page.js +122 -0
  138. package/dist/rpc/history-page.js.map +1 -0
  139. package/dist/rpc/lifecycle-methods.d.ts +12 -0
  140. package/dist/rpc/lifecycle-methods.js +39 -0
  141. package/dist/rpc/lifecycle-methods.js.map +1 -0
  142. package/dist/rpc/paint-down.d.ts +17 -0
  143. package/dist/rpc/paint-down.js +96 -0
  144. package/dist/rpc/paint-down.js.map +1 -0
  145. package/dist/rpc/promote-attempt.d.ts +21 -0
  146. package/dist/rpc/promote-attempt.js +55 -0
  147. package/dist/rpc/promote-attempt.js.map +1 -0
  148. package/dist/rpc/push-ref.d.ts +21 -0
  149. package/dist/rpc/push-ref.js +47 -0
  150. package/dist/rpc/push-ref.js.map +1 -0
  151. package/dist/rpc/read-methods.d.ts +17 -0
  152. package/dist/rpc/read-methods.js +94 -0
  153. package/dist/rpc/read-methods.js.map +1 -0
  154. package/dist/rpc/read-token.d.ts +39 -0
  155. package/dist/rpc/read-token.js +107 -0
  156. package/dist/rpc/read-token.js.map +1 -0
  157. package/dist/rpc/repo-access.d.ts +36 -0
  158. package/dist/rpc/repo-access.js +75 -0
  159. package/dist/rpc/repo-access.js.map +1 -0
  160. package/dist/rpc/sync-attempt.d.ts +23 -0
  161. package/dist/rpc/sync-attempt.js +105 -0
  162. package/dist/rpc/sync-attempt.js.map +1 -0
  163. package/dist/sync-workflow-schemas-DCNmNE5-.d.ts +57 -0
  164. package/dist/upstream-DvqMCj5N.d.ts +15 -0
  165. package/dist/workflow-starter-BqhwX6oA.d.ts +45 -0
  166. package/dist/workflows/commit-workflow-schemas.d.ts +2 -0
  167. package/dist/workflows/commit-workflow-schemas.js +84 -0
  168. package/dist/workflows/commit-workflow-schemas.js.map +1 -0
  169. package/dist/workflows/commit-workflow.d.ts +16 -0
  170. package/dist/workflows/commit-workflow.js +22 -0
  171. package/dist/workflows/commit-workflow.js.map +1 -0
  172. package/dist/workflows/on-push.d.ts +2 -0
  173. package/dist/workflows/on-push.js +90 -0
  174. package/dist/workflows/on-push.js.map +1 -0
  175. package/dist/workflows/push-event.d.ts +2 -0
  176. package/dist/workflows/push-event.js +28 -0
  177. package/dist/workflows/push-event.js.map +1 -0
  178. package/dist/workflows/run-commit-workflow.d.ts +15 -0
  179. package/dist/workflows/run-commit-workflow.js +49 -0
  180. package/dist/workflows/run-commit-workflow.js.map +1 -0
  181. package/dist/workflows/run-sync-workflow.d.ts +14 -0
  182. package/dist/workflows/run-sync-workflow.js +67 -0
  183. package/dist/workflows/run-sync-workflow.js.map +1 -0
  184. package/dist/workflows/step-errors.d.ts +15 -0
  185. package/dist/workflows/step-errors.js +24 -0
  186. package/dist/workflows/step-errors.js.map +1 -0
  187. package/dist/workflows/step-runner.d.ts +31 -0
  188. package/dist/workflows/step-runner.js +6 -0
  189. package/dist/workflows/step-runner.js.map +1 -0
  190. package/dist/workflows/sync-branch-workflow.d.ts +15 -0
  191. package/dist/workflows/sync-branch-workflow.js +21 -0
  192. package/dist/workflows/sync-branch-workflow.js.map +1 -0
  193. package/dist/workflows/sync-workflow-schemas.d.ts +2 -0
  194. package/dist/workflows/sync-workflow-schemas.js +104 -0
  195. package/dist/workflows/sync-workflow-schemas.js.map +1 -0
  196. package/dist/workflows/workflow-instance-id.d.ts +12 -0
  197. package/dist/workflows/workflow-instance-id.js +33 -0
  198. package/dist/workflows/workflow-instance-id.js.map +1 -0
  199. package/dist/workflows/workflow-runtime.d.ts +7 -0
  200. package/dist/workflows/workflow-runtime.js +11 -0
  201. package/dist/workflows/workflow-runtime.js.map +1 -0
  202. package/dist/workflows/workflow-starter.d.ts +2 -0
  203. package/dist/workflows/workflow-starter.js +40 -0
  204. package/dist/workflows/workflow-starter.js.map +1 -0
  205. package/package.json +381 -4
  206. package/src/audit/audit-recorder.ts +74 -0
  207. package/src/audit/push-report.ts +60 -0
  208. package/src/auth/authenticate.ts +68 -0
  209. package/src/auth/authorize.ts +57 -0
  210. package/src/auth/read-token-auth.ts +119 -0
  211. package/src/cache/decision-cache.ts +57 -0
  212. package/src/gateway-app.ts +147 -0
  213. package/src/gateway-worker.ts +32 -0
  214. package/src/health.ts +12 -0
  215. package/src/logging/logger.ts +40 -0
  216. package/src/policy/branch-policy.ts +119 -0
  217. package/src/policy/enforce-branch-policy.ts +213 -0
  218. package/src/policy/fast-forward.ts +136 -0
  219. package/src/policy/ref-pattern.ts +24 -0
  220. package/src/policy/rule-branch-policy.ts +76 -0
  221. package/src/proxy/defer.ts +18 -0
  222. package/src/proxy/forward-read.ts +52 -0
  223. package/src/proxy/gateway-deps.ts +43 -0
  224. package/src/proxy/gateway-env.ts +43 -0
  225. package/src/proxy/git-responses.ts +89 -0
  226. package/src/proxy/git-route.ts +49 -0
  227. package/src/proxy/push-events.ts +91 -0
  228. package/src/proxy/push-guard.ts +109 -0
  229. package/src/proxy/push-options.ts +38 -0
  230. package/src/proxy/receive-pack.ts +257 -0
  231. package/src/proxy/request-log.ts +44 -0
  232. package/src/proxy/resolve-route.ts +24 -0
  233. package/src/proxy/upstream-call.ts +71 -0
  234. package/src/proxy/upstream.ts +76 -0
  235. package/src/push-policy/changed-paths.ts +143 -0
  236. package/src/push-policy/pushed-objects.ts +88 -0
  237. package/src/push-policy/run-push-policy.ts +99 -0
  238. package/src/push-policy/tree-diff.ts +107 -0
  239. package/src/push-policy/uncheckable.ts +27 -0
  240. package/src/rpc/branch-methods.ts +57 -0
  241. package/src/rpc/commit-attempt.ts +87 -0
  242. package/src/rpc/commit-graph.ts +44 -0
  243. package/src/rpc/commit-method.ts +36 -0
  244. package/src/rpc/commit-source.ts +15 -0
  245. package/src/rpc/gateway-context.ts +77 -0
  246. package/src/rpc/gateway-rpc.ts +65 -0
  247. package/src/rpc/gateway-service.ts +85 -0
  248. package/src/rpc/history-page.ts +163 -0
  249. package/src/rpc/lifecycle-methods.ts +50 -0
  250. package/src/rpc/paint-down.ts +120 -0
  251. package/src/rpc/promote-attempt.ts +52 -0
  252. package/src/rpc/push-ref.ts +54 -0
  253. package/src/rpc/read-methods.ts +111 -0
  254. package/src/rpc/read-token.ts +135 -0
  255. package/src/rpc/repo-access.ts +112 -0
  256. package/src/rpc/sync-attempt.ts +84 -0
  257. package/src/workflows/commit-workflow-schemas.ts +95 -0
  258. package/src/workflows/commit-workflow.ts +39 -0
  259. package/src/workflows/on-push.ts +128 -0
  260. package/src/workflows/push-event.ts +41 -0
  261. package/src/workflows/run-commit-workflow.ts +45 -0
  262. package/src/workflows/run-sync-workflow.ts +52 -0
  263. package/src/workflows/step-errors.ts +26 -0
  264. package/src/workflows/step-runner.ts +36 -0
  265. package/src/workflows/sync-branch-workflow.ts +40 -0
  266. package/src/workflows/sync-workflow-schemas.ts +122 -0
  267. package/src/workflows/workflow-instance-id.ts +26 -0
  268. package/src/workflows/workflow-runtime.ts +13 -0
  269. package/src/workflows/workflow-starter.ts +69 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,50 @@
1
- # Temporary Holding Version
1
+ # @leed-ai/git-gateway-worker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The git-gateway Cloudflare Worker: smart-HTTP proxy, auth and branch-policy pipeline, RPC entrypoint and Workflows.
4
+
5
+ Part of [git-gateway](https://github.com/leed-ai/git-gateway). Status: in development; see the [design](https://github.com/leed-ai/git-gateway/blob/main/docs/design.md).
6
+
7
+ Peer dependencies: `zod` (`^4`), `hono` (`^4`). Install them alongside this package.
8
+
9
+ ## Usage
10
+
11
+ ```ts
12
+ import { createGatewayWorker } from '@leed-ai/git-gateway-worker/gateway-worker';
13
+ import { consoleLogger } from '@leed-ai/git-gateway-worker/logging/logger';
14
+ import { RuleBranchPolicy } from '@leed-ai/git-gateway-worker/policy/rule-branch-policy';
15
+
16
+ export default createGatewayWorker((env) => ({
17
+ backend, // any StorageBackend, e.g. ArtifactsBackend over env.ARTIFACTS
18
+ authenticator, // e.g. JwtAuthenticator from @leed-ai/git-gateway-auth-jwt
19
+ authorizer: { authorize: async (principal, repo, operation) => true },
20
+ branchPolicy: new RuleBranchPolicy({
21
+ rules: [{ pattern: 'refs/heads/main', message: 'main is protected' }],
22
+ }),
23
+ audit: (event) => {}, // every authenticated operation
24
+ logger: consoleLogger,
25
+ }));
26
+ ```
27
+
28
+ `gateway-app` (`createGatewayApp`) is the same gateway as a Hono app. Each request to `/<repo>.git/…` runs route resolution, authentication (401 with `WWW-Authenticate: Basic` when it fails, so git asks its credential helper), authorization (refused in-protocol with `ERR`, or with HTTP 403 and the reason as the body when `smartHttp.deniedStatus` is `403`) and, for pushes, the branch policy (refused per ref with `ng <ref> <reason>`; a push is forwarded only when every update is allowed). The request then streams to the storage host with a credential minted for it alone. Fast-forward-only updates are proven from storage, or from the pushed pack as it streams, holding back the pack checksum until they are proven. See the [design](https://github.com/leed-ai/git-gateway/blob/main/docs/design.md#smart-http-proxy).
29
+
30
+ Push options (`git push -o …`) are refused unless their name is in `smartHttp.allowedPushOptions` (default none): the storage host acts on them with the gateway's own credential — GitLab opens and auto-merges merge requests on `merge_request.*` — so an unchecked option would reach refs the branch policy never saw.
31
+
32
+ **Push events.** After the storage host accepts a push through the proxy, the refs its report marks `ok` are passed to `onPush` (through `waitUntil`; failures go to `onPushError` and never change the response). The RPC service does the same for every ref update it writes. Sync rules (`gateway.syncRules` on the app, `config.syncRules` on the RPC service) start a `SyncBranchWorkflow` after every accepted push to a rule's `from` branch; pass the binding as `syncWorkflow`, without which a gateway with sync rules refuses to start.
33
+
34
+ **Read tokens.** `mintReadToken()` (RPC) issues `ggr_…` tokens good for cloning one repository. Compose the proxy with `withReadTokens` (`auth/read-token-auth`) so they are accepted beside the deployment's own credentials, with the same secret as the RPC service:
35
+
36
+ ```ts
37
+ import { withReadTokens } from '@leed-ai/git-gateway-worker/auth/read-token-auth';
38
+
39
+ createGatewayWorker((env) => ({
40
+ backend,
41
+ ...withReadTokens({ secret: env.READ_TOKEN_SECRET, authenticator, authorizer }),
42
+ branchPolicy,
43
+ }));
44
+ ```
45
+
46
+ A read-token principal (subject `read-token:<id>`, role `read:<repo>`) may fetch its repository until the token expires, and never push or read another; another authenticator's principal that claims the `read-token:` subject is refused.
47
+
48
+ ## License
49
+
50
+ Apache-2.0
@@ -0,0 +1,2 @@
1
+ import { n as AuditRecorder, r as Defer, t as AuditFacts } from "../audit-recorder-K1Ns3tfC.js";
2
+ export { AuditFacts, AuditRecorder, Defer };
@@ -0,0 +1,53 @@
1
+ import { AuditEvent } from "@leed-ai/git-gateway-contract/proxy/audit-event";
2
+ // src/audit/audit-recorder.ts
3
+ /**
4
+ * Builds audit events and hands them to the deployment's hook without ever affecting the
5
+ * response: the hook runs deferred, and a hook that throws (or an event the schema rejects) is
6
+ * logged and dropped.
7
+ */
8
+ var AuditRecorder = class {
9
+ #hook;
10
+ #logger;
11
+ #now;
12
+ constructor(hook, logger, now) {
13
+ this.#hook = hook;
14
+ this.#logger = logger;
15
+ this.#now = now;
16
+ }
17
+ /** Whether a hook is configured (when not, callers can skip gathering facts). */
18
+ get enabled() {
19
+ return this.#hook !== void 0;
20
+ }
21
+ /** Records one event, deferred; `facts` may be a promise (for a push whose report is still streaming). */
22
+ record(facts, defer, requestId) {
23
+ const hook = this.#hook;
24
+ if (hook === void 0) return;
25
+ defer((async () => {
26
+ try {
27
+ const resolved = await facts;
28
+ const event = AuditEvent.parse({
29
+ requestId: resolved.requestId,
30
+ at: this.#now().toISOString(),
31
+ principal: resolved.principal,
32
+ repo: resolved.git.repo,
33
+ operation: resolved.git.operation,
34
+ endpoint: resolved.git.endpoint,
35
+ outcome: resolved.outcome,
36
+ reason: resolved.reason,
37
+ refs: resolved.refs
38
+ });
39
+ await hook(event);
40
+ } catch (error) {
41
+ this.#logger.log({
42
+ level: "error",
43
+ message: "audit hook failed",
44
+ requestId,
45
+ error: error instanceof Error ? error.message : String(error)
46
+ });
47
+ }
48
+ })());
49
+ }
50
+ };
51
+ export { AuditRecorder };
52
+
53
+ //# sourceMappingURL=audit-recorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-recorder.js","names":[],"sources":["../../src/audit/audit-recorder.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { AuditEvent, type AuditRefOutcome } from '@leed-ai/git-gateway-contract/proxy/audit-event';\nimport type { AuditHook } from '@leed-ai/git-gateway-contract/proxy/gateway-hooks';\nimport type { Principal } from '@leed-ai/git-gateway-contract/proxy/principal';\n\nimport type { Logger } from '../logging/logger.ts';\nimport type { GitRequest } from '../proxy/git-route.ts';\n\n/** What one request contributes to its audit event. */\nexport interface AuditFacts {\n readonly requestId: string;\n readonly principal: Principal;\n readonly git: GitRequest;\n readonly outcome: AuditEvent['outcome'];\n readonly reason: string | null;\n readonly refs: readonly AuditRefOutcome[];\n}\n\n/** Runs work after the response, through the runtime's `waitUntil` when there is one. */\nexport type Defer = (work: Promise<unknown>) => void;\n\n/**\n * Builds audit events and hands them to the deployment's hook without ever affecting the\n * response: the hook runs deferred, and a hook that throws (or an event the schema rejects) is\n * logged and dropped.\n */\nexport class AuditRecorder {\n readonly #hook: AuditHook | undefined;\n readonly #logger: Logger;\n readonly #now: () => Date;\n\n constructor(hook: AuditHook | undefined, logger: Logger, now: () => Date) {\n this.#hook = hook;\n this.#logger = logger;\n this.#now = now;\n }\n\n /** Whether a hook is configured (when not, callers can skip gathering facts). */\n get enabled(): boolean {\n return this.#hook !== undefined;\n }\n\n /** Records one event, deferred; `facts` may be a promise (for a push whose report is still streaming). */\n record(facts: AuditFacts | Promise<AuditFacts>, defer: Defer, requestId: string): void {\n const hook = this.#hook;\n if (hook === undefined) return;\n defer(\n (async () => {\n try {\n const resolved = await facts;\n const event = AuditEvent.parse({\n requestId: resolved.requestId,\n at: this.#now().toISOString(),\n principal: resolved.principal,\n repo: resolved.git.repo,\n operation: resolved.git.operation,\n endpoint: resolved.git.endpoint,\n outcome: resolved.outcome,\n reason: resolved.reason,\n refs: resolved.refs,\n });\n await hook(event);\n } catch (error) {\n this.#logger.log({\n level: 'error',\n message: 'audit hook failed',\n requestId,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n })(),\n );\n }\n}\n"],"mappings":";;;;;;;AA0BA,IAAa,gBAAb,MAA2B;CACzB;CACA;CACA;CAEA,YAAY,MAA6B,QAAgB,KAAiB;EACxE,KAAK,QAAQ;EACb,KAAK,UAAU;EACf,KAAK,OAAO;CACd;;CAGA,IAAI,UAAmB;EACrB,OAAO,KAAK,UAAU,KAAA;CACxB;;CAGA,OAAO,OAAyC,OAAc,WAAyB;EACrF,MAAM,OAAO,KAAK;EAClB,IAAI,SAAS,KAAA,GAAW;EACxB,OACG,YAAY;GACX,IAAI;IACF,MAAM,WAAW,MAAM;IACvB,MAAM,QAAQ,WAAW,MAAM;KAC7B,WAAW,SAAS;KACpB,IAAI,KAAK,KAAK,CAAC,CAAC,YAAY;KAC5B,WAAW,SAAS;KACpB,MAAM,SAAS,IAAI;KACnB,WAAW,SAAS,IAAI;KACxB,UAAU,SAAS,IAAI;KACvB,SAAS,SAAS;KAClB,QAAQ,SAAS;KACjB,MAAM,SAAS;IACjB,CAAC;IACD,MAAM,KAAK,KAAK;GAClB,SAAS,OAAO;IACd,KAAK,QAAQ,IAAI;KACf,OAAO;KACP,SAAS;KACT;KACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAC9D,CAAC;GACH;EACF,EAAA,CAAG,CACL;CACF;AACF"}
@@ -0,0 +1,13 @@
1
+ import { AuditRefOutcome } from "@leed-ai/git-gateway-contract/proxy/audit-event";
2
+ import { ReceivePackRequest } from "@leed-ai/git-gateway-core/schemas/receive-pack";
3
+ /** The ref outcomes of a push before the storage host has answered: every update "unknown". */
4
+ export declare function unknownOutcomes(request: ReceivePackRequest): AuditRefOutcome[];
5
+ /** Every update of a push refused with its reason. */
6
+ export declare function rejectedOutcomes(request: ReceivePackRequest, reasons: ReadonlyMap<string, string>, fallback: string): AuditRefOutcome[];
7
+ /**
8
+ * Reads up to `maxBytes` of a storage host's receive-pack response (one branch of a tee) and
9
+ * turns its report-status into per-ref outcomes. When the response is larger, unreadable or not a
10
+ * report, every ref is "unknown". Never throws.
11
+ */
12
+ export declare function readPushOutcomes(stream: ReadableStream<Uint8Array>, request: ReceivePackRequest, maxBytes: number): Promise<AuditRefOutcome[]>;
13
+ //# sourceMappingURL=push-report.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { concatBytes } from "@leed-ai/git-gateway-core/bytes";
2
+ import { parseReportStatus, reportStatusFraming } from "@leed-ai/git-gateway-core/receive-pack/report-status";
3
+ // src/audit/push-report.ts
4
+ /** The ref outcomes of a push before the storage host has answered: every update "unknown". */
5
+ function unknownOutcomes(request) {
6
+ return request.commands.map((command) => ({
7
+ ...command,
8
+ status: "unknown",
9
+ reason: null
10
+ }));
11
+ }
12
+ /** Every update of a push refused with its reason. */
13
+ function rejectedOutcomes(request, reasons, fallback) {
14
+ return request.commands.map((command) => ({
15
+ ...command,
16
+ status: "rejected",
17
+ reason: reasons.get(command.ref) ?? fallback
18
+ }));
19
+ }
20
+ /**
21
+ * Reads up to `maxBytes` of a storage host's receive-pack response (one branch of a tee) and
22
+ * turns its report-status into per-ref outcomes. When the response is larger, unreadable or not a
23
+ * report, every ref is "unknown". Never throws.
24
+ */
25
+ async function readPushOutcomes(stream, request, maxBytes) {
26
+ const reader = stream.getReader();
27
+ const chunks = [];
28
+ let total = 0;
29
+ try {
30
+ for (let next = await reader.read(); !next.done; next = await reader.read()) {
31
+ total += next.value.length;
32
+ if (total > maxBytes) {
33
+ await reader.cancel();
34
+ return unknownOutcomes(request);
35
+ }
36
+ chunks.push(next.value);
37
+ }
38
+ const report = parseReportStatus(concatBytes(chunks), reportStatusFraming(request.capabilities));
39
+ const byRef = new Map(report.refs.map((status) => [status.ref, status]));
40
+ return request.commands.map((command) => {
41
+ const status = byRef.get(command.ref);
42
+ if (status === void 0) return {
43
+ ...command,
44
+ status: "unknown",
45
+ reason: null
46
+ };
47
+ if (status.status === "ok" && report.unpack === "ok") return {
48
+ ...command,
49
+ status: "ok",
50
+ reason: null
51
+ };
52
+ const reason = status.status === "ng" ? status.reason : `unpack failed: ${report.unpack}`;
53
+ return {
54
+ ...command,
55
+ status: "rejected",
56
+ reason: reason.slice(0, 1e3)
57
+ };
58
+ });
59
+ } catch {
60
+ await reader.cancel().catch(() => void 0);
61
+ return unknownOutcomes(request);
62
+ }
63
+ }
64
+ export { readPushOutcomes, rejectedOutcomes, unknownOutcomes };
65
+
66
+ //# sourceMappingURL=push-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-report.js","names":[],"sources":["../../src/audit/push-report.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { AuditRefOutcome } from '@leed-ai/git-gateway-contract/proxy/audit-event';\nimport { concatBytes } from '@leed-ai/git-gateway-core/bytes';\nimport { parseReportStatus, reportStatusFraming } from '@leed-ai/git-gateway-core/receive-pack/report-status';\nimport type { ReceivePackRequest } from '@leed-ai/git-gateway-core/schemas/receive-pack';\n\n/** The ref outcomes of a push before the storage host has answered: every update \"unknown\". */\nexport function unknownOutcomes(request: ReceivePackRequest): AuditRefOutcome[] {\n return request.commands.map((command) => ({ ...command, status: 'unknown', reason: null }));\n}\n\n/** Every update of a push refused with its reason. */\nexport function rejectedOutcomes(\n request: ReceivePackRequest,\n reasons: ReadonlyMap<string, string>,\n fallback: string,\n): AuditRefOutcome[] {\n return request.commands.map((command) => ({\n ...command,\n status: 'rejected',\n reason: reasons.get(command.ref) ?? fallback,\n }));\n}\n\n/**\n * Reads up to `maxBytes` of a storage host's receive-pack response (one branch of a tee) and\n * turns its report-status into per-ref outcomes. When the response is larger, unreadable or not a\n * report, every ref is \"unknown\". Never throws.\n */\nexport async function readPushOutcomes(\n stream: ReadableStream<Uint8Array>,\n request: ReceivePackRequest,\n maxBytes: number,\n): Promise<AuditRefOutcome[]> {\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n try {\n for (let next = await reader.read(); !next.done; next = await reader.read()) {\n total += next.value.length;\n if (total > maxBytes) {\n await reader.cancel();\n return unknownOutcomes(request);\n }\n chunks.push(next.value);\n }\n const report = parseReportStatus(concatBytes(chunks), reportStatusFraming(request.capabilities));\n const byRef = new Map(report.refs.map((status) => [status.ref, status]));\n return request.commands.map((command) => {\n const status = byRef.get(command.ref);\n if (status === undefined) return { ...command, status: 'unknown', reason: null };\n if (status.status === 'ok' && report.unpack === 'ok') return { ...command, status: 'ok', reason: null };\n const reason = status.status === 'ng' ? status.reason : `unpack failed: ${report.unpack}`;\n return { ...command, status: 'rejected', reason: reason.slice(0, 1000) };\n });\n } catch {\n await reader.cancel().catch(() => undefined);\n return unknownOutcomes(request);\n }\n}\n"],"mappings":";;;;AAOA,SAAgB,gBAAgB,SAAgD;CAC9E,OAAO,QAAQ,SAAS,KAAK,aAAa;EAAE,GAAG;EAAS,QAAQ;EAAW,QAAQ;CAAK,EAAE;AAC5F;;AAGA,SAAgB,iBACd,SACA,SACA,UACmB;CACnB,OAAO,QAAQ,SAAS,KAAK,aAAa;EACxC,GAAG;EACH,QAAQ;EACR,QAAQ,QAAQ,IAAI,QAAQ,GAAG,KAAK;CACtC,EAAE;AACJ;;;;;;AAOA,eAAsB,iBACpB,QACA,SACA,UAC4B;CAC5B,MAAM,SAAS,OAAO,UAAU;CAChC,MAAM,SAAuB,CAAC;CAC9B,IAAI,QAAQ;CACZ,IAAI;EACF,KAAK,IAAI,OAAO,MAAM,OAAO,KAAK,GAAG,CAAC,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK,GAAG;GAC3E,SAAS,KAAK,MAAM;GACpB,IAAI,QAAQ,UAAU;IACpB,MAAM,OAAO,OAAO;IACpB,OAAO,gBAAgB,OAAO;GAChC;GACA,OAAO,KAAK,KAAK,KAAK;EACxB;EACA,MAAM,SAAS,kBAAkB,YAAY,MAAM,GAAG,oBAAoB,QAAQ,YAAY,CAAC;EAC/F,MAAM,QAAQ,IAAI,IAAI,OAAO,KAAK,KAAK,WAAW,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;EACvE,OAAO,QAAQ,SAAS,KAAK,YAAY;GACvC,MAAM,SAAS,MAAM,IAAI,QAAQ,GAAG;GACpC,IAAI,WAAW,KAAA,GAAW,OAAO;IAAE,GAAG;IAAS,QAAQ;IAAW,QAAQ;GAAK;GAC/E,IAAI,OAAO,WAAW,QAAQ,OAAO,WAAW,MAAM,OAAO;IAAE,GAAG;IAAS,QAAQ;IAAM,QAAQ;GAAK;GACtG,MAAM,SAAS,OAAO,WAAW,OAAO,OAAO,SAAS,kBAAkB,OAAO;GACjF,OAAO;IAAE,GAAG;IAAS,QAAQ;IAAY,QAAQ,OAAO,MAAM,GAAG,GAAI;GAAE;EACzE,CAAC;CACH,QAAQ;EACN,MAAM,OAAO,OAAO,CAAC,CAAC,YAAY,KAAA,CAAS;EAC3C,OAAO,gBAAgB,OAAO;CAChC;AACF"}
@@ -0,0 +1,31 @@
1
+ import { r as Logger } from "./logger-BZ1zyKLb.js";
2
+ import { t as GitRequest } from "./git-route-Spxi09Rm.js";
3
+ import { AuditEvent, AuditRefOutcome } from "@leed-ai/git-gateway-contract/proxy/audit-event";
4
+ import { Principal } from "@leed-ai/git-gateway-contract/proxy/principal";
5
+ import { AuditHook } from "@leed-ai/git-gateway-contract/proxy/gateway-hooks";
6
+ /** What one request contributes to its audit event. */
7
+ interface AuditFacts {
8
+ readonly requestId: string;
9
+ readonly principal: Principal;
10
+ readonly git: GitRequest;
11
+ readonly outcome: AuditEvent['outcome'];
12
+ readonly reason: string | null;
13
+ readonly refs: readonly AuditRefOutcome[];
14
+ }
15
+ /** Runs work after the response, through the runtime's `waitUntil` when there is one. */
16
+ type Defer = (work: Promise<unknown>) => void;
17
+ /**
18
+ * Builds audit events and hands them to the deployment's hook without ever affecting the
19
+ * response: the hook runs deferred, and a hook that throws (or an event the schema rejects) is
20
+ * logged and dropped.
21
+ */
22
+ declare class AuditRecorder {
23
+ #private;
24
+ constructor(hook: AuditHook | undefined, logger: Logger, now: () => Date);
25
+ /** Whether a hook is configured (when not, callers can skip gathering facts). */
26
+ get enabled(): boolean;
27
+ /** Records one event, deferred; `facts` may be a promise (for a push whose report is still streaming). */
28
+ record(facts: AuditFacts | Promise<AuditFacts>, defer: Defer, requestId: string): void;
29
+ }
30
+ export { AuditRecorder as n, Defer as r, AuditFacts as t };
31
+ //# sourceMappingURL=audit-recorder-K1Ns3tfC.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { GatewayDeps } from "../proxy/gateway-deps.js";
2
+ import { n as GatewayEnv } from "../gateway-env-DnsBU4Pq.js";
3
+ import { MiddlewareHandler } from "hono";
4
+ import { Principal } from "@leed-ai/git-gateway-contract/proxy/principal";
5
+ /** Milliseconds a decision about `principal` may be cached: the configured TTL, never past its expiry. */
6
+ export declare function decisionTtl(deps: GatewayDeps, principal: Principal): number;
7
+ /**
8
+ * Authentication middleware: establishes the request's principal with the deployment's
9
+ * Authenticator, through the decision cache (keyed by a SHA-256 fingerprint of the credential,
10
+ * never the credential). No principal — or one whose credential has expired — answers 401 with
11
+ * `WWW-Authenticate: Basic`, so git asks its credential helper and retries.
12
+ */
13
+ export declare function authenticate(deps: GatewayDeps): MiddlewareHandler<GatewayEnv>;
14
+ //# sourceMappingURL=authenticate.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { textResponse, unauthorized } from "../proxy/git-responses.js";
2
+ import { Principal } from "@leed-ai/git-gateway-contract/proxy/principal";
3
+ import { credentialFingerprint, readCredential } from "@leed-ai/git-gateway-contract/proxy/request-credential";
4
+ // src/auth/authenticate.ts
5
+ /** Milliseconds a decision about `principal` may be cached: the configured TTL, never past its expiry. */
6
+ function decisionTtl(deps, principal) {
7
+ if (principal.expiresAt === null) return deps.cacheTtlMs;
8
+ return Math.min(deps.cacheTtlMs, Date.parse(principal.expiresAt) - deps.now().getTime());
9
+ }
10
+ const expired = (deps, principal) => principal.expiresAt !== null && Date.parse(principal.expiresAt) <= deps.now().getTime();
11
+ /**
12
+ * Authentication middleware: establishes the request's principal with the deployment's
13
+ * Authenticator, through the decision cache (keyed by a SHA-256 fingerprint of the credential,
14
+ * never the credential). No principal — or one whose credential has expired — answers 401 with
15
+ * `WWW-Authenticate: Basic`, so git asks its credential helper and retries.
16
+ */
17
+ function authenticate(deps) {
18
+ return async (context, next) => {
19
+ const requestId = context.get("requestId");
20
+ const credential = readCredential(context.req.raw);
21
+ const key = credential === null ? null : `authn:${await credentialFingerprint(credential)}`;
22
+ const cached = key === null ? void 0 : deps.cache.get(key);
23
+ let principal = cached?.kind === "principal" ? cached.principal : null;
24
+ if (principal === null) {
25
+ try {
26
+ const found = await deps.authenticator.authenticate(context.req.raw);
27
+ principal = found === null ? null : Principal.parse(found);
28
+ } catch (error) {
29
+ deps.logger.log({
30
+ level: "error",
31
+ message: "authenticator failed",
32
+ requestId,
33
+ error: error instanceof Error ? error.message : String(error)
34
+ });
35
+ return textResponse(503, "Authentication is unavailable; try again later", { "X-Request-Id": requestId });
36
+ }
37
+ if (principal !== null && key !== null && !expired(deps, principal)) deps.cache.set(key, {
38
+ kind: "principal",
39
+ principal
40
+ }, decisionTtl(deps, principal));
41
+ }
42
+ if (principal === null || expired(deps, principal)) {
43
+ deps.logger.log({
44
+ level: "info",
45
+ message: "authentication required",
46
+ requestId,
47
+ credential: credential === null ? "none" : principal === null ? "rejected" : "expired"
48
+ });
49
+ const response = unauthorized(deps.config.realm);
50
+ response.headers.set("X-Request-Id", requestId);
51
+ return response;
52
+ }
53
+ context.set("principal", principal);
54
+ return next();
55
+ };
56
+ }
57
+ export { authenticate, decisionTtl };
58
+
59
+ //# sourceMappingURL=authenticate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticate.js","names":[],"sources":["../../src/auth/authenticate.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { Principal } from '@leed-ai/git-gateway-contract/proxy/principal';\nimport type { MiddlewareHandler } from 'hono';\n\nimport type { GatewayDeps } from '../proxy/gateway-deps.ts';\nimport type { GatewayEnv } from '../proxy/gateway-env.ts';\nimport { textResponse, unauthorized } from '../proxy/git-responses.ts';\nimport {\n credentialFingerprint,\n readCredential,\n} from '@leed-ai/git-gateway-contract/proxy/request-credential';\n\n/** Milliseconds a decision about `principal` may be cached: the configured TTL, never past its expiry. */\nexport function decisionTtl(deps: GatewayDeps, principal: Principal): number {\n if (principal.expiresAt === null) return deps.cacheTtlMs;\n return Math.min(deps.cacheTtlMs, Date.parse(principal.expiresAt) - deps.now().getTime());\n}\n\nconst expired = (deps: GatewayDeps, principal: Principal): boolean =>\n principal.expiresAt !== null && Date.parse(principal.expiresAt) <= deps.now().getTime();\n\n/**\n * Authentication middleware: establishes the request's principal with the deployment's\n * Authenticator, through the decision cache (keyed by a SHA-256 fingerprint of the credential,\n * never the credential). No principal — or one whose credential has expired — answers 401 with\n * `WWW-Authenticate: Basic`, so git asks its credential helper and retries.\n */\nexport function authenticate(deps: GatewayDeps): MiddlewareHandler<GatewayEnv> {\n return async (context, next) => {\n const requestId = context.get('requestId');\n const credential = readCredential(context.req.raw);\n const key = credential === null ? null : `authn:${await credentialFingerprint(credential)}`;\n const cached = key === null ? undefined : deps.cache.get(key);\n let principal = cached?.kind === 'principal' ? cached.principal : null;\n if (principal === null) {\n try {\n const found = await deps.authenticator.authenticate(context.req.raw);\n principal = found === null ? null : Principal.parse(found);\n } catch (error) {\n deps.logger.log({\n level: 'error',\n message: 'authenticator failed',\n requestId,\n error: error instanceof Error ? error.message : String(error),\n });\n return textResponse(503, 'Authentication is unavailable; try again later', {\n 'X-Request-Id': requestId,\n });\n }\n if (principal !== null && key !== null && !expired(deps, principal)) {\n deps.cache.set(key, { kind: 'principal', principal }, decisionTtl(deps, principal));\n }\n }\n if (principal === null || expired(deps, principal)) {\n deps.logger.log({\n level: 'info',\n message: 'authentication required',\n requestId,\n credential: credential === null ? 'none' : principal === null ? 'rejected' : 'expired',\n });\n const response = unauthorized(deps.config.realm);\n response.headers.set('X-Request-Id', requestId);\n return response;\n }\n context.set('principal', principal);\n return next();\n };\n}\n"],"mappings":";;;;;AAaA,SAAgB,YAAY,MAAmB,WAA8B;CAC3E,IAAI,UAAU,cAAc,MAAM,OAAO,KAAK;CAC9C,OAAO,KAAK,IAAI,KAAK,YAAY,KAAK,MAAM,UAAU,SAAS,IAAI,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC;AACzF;AAEA,MAAM,WAAW,MAAmB,cAClC,UAAU,cAAc,QAAQ,KAAK,MAAM,UAAU,SAAS,KAAK,KAAK,IAAI,CAAC,CAAC,QAAQ;;;;;;;AAQxF,SAAgB,aAAa,MAAkD;CAC7E,OAAO,OAAO,SAAS,SAAS;EAC9B,MAAM,YAAY,QAAQ,IAAI,WAAW;EACzC,MAAM,aAAa,eAAe,QAAQ,IAAI,GAAG;EACjD,MAAM,MAAM,eAAe,OAAO,OAAO,SAAS,MAAM,sBAAsB,UAAU;EACxF,MAAM,SAAS,QAAQ,OAAO,KAAA,IAAY,KAAK,MAAM,IAAI,GAAG;EAC5D,IAAI,YAAY,QAAQ,SAAS,cAAc,OAAO,YAAY;EAClE,IAAI,cAAc,MAAM;GACtB,IAAI;IACF,MAAM,QAAQ,MAAM,KAAK,cAAc,aAAa,QAAQ,IAAI,GAAG;IACnE,YAAY,UAAU,OAAO,OAAO,UAAU,MAAM,KAAK;GAC3D,SAAS,OAAO;IACd,KAAK,OAAO,IAAI;KACd,OAAO;KACP,SAAS;KACT;KACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAC9D,CAAC;IACD,OAAO,aAAa,KAAK,kDAAkD,EACzE,gBAAgB,UAClB,CAAC;GACH;GACA,IAAI,cAAc,QAAQ,QAAQ,QAAQ,CAAC,QAAQ,MAAM,SAAS,GAChE,KAAK,MAAM,IAAI,KAAK;IAAE,MAAM;IAAa;GAAU,GAAG,YAAY,MAAM,SAAS,CAAC;EAEtF;EACA,IAAI,cAAc,QAAQ,QAAQ,MAAM,SAAS,GAAG;GAClD,KAAK,OAAO,IAAI;IACd,OAAO;IACP,SAAS;IACT;IACA,YAAY,eAAe,OAAO,SAAS,cAAc,OAAO,aAAa;GAC/E,CAAC;GACD,MAAM,WAAW,aAAa,KAAK,OAAO,KAAK;GAC/C,SAAS,QAAQ,IAAI,gBAAgB,SAAS;GAC9C,OAAO;EACT;EACA,QAAQ,IAAI,aAAa,SAAS;EAClC,OAAO,KAAK;CACd;AACF"}
@@ -0,0 +1,12 @@
1
+ import { GatewayDeps } from "../proxy/gateway-deps.js";
2
+ import { n as GatewayEnv } from "../gateway-env-DnsBU4Pq.js";
3
+ import { MiddlewareHandler } from "hono";
4
+ /**
5
+ * Authorization middleware: asks the deployment's Authorizer whether the principal may read
6
+ * (fetch) or write (push) the repository, through the decision cache keyed by principal subject
7
+ * and roles, repository and operation. A refusal is audited and answered as `smartHttp.deniedStatus`
8
+ * says: in-protocol with an "ERR" packet (default), so git prints "remote error: …", or HTTP 403
9
+ * with the reason as the body.
10
+ */
11
+ export declare function authorize(deps: GatewayDeps): MiddlewareHandler<GatewayEnv>;
12
+ //# sourceMappingURL=authorize.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { deferWith } from "../proxy/defer.js";
2
+ import { errResponse, textResponse } from "../proxy/git-responses.js";
3
+ import { decisionTtl } from "./authenticate.js";
4
+ // src/auth/authorize.ts
5
+ /**
6
+ * Authorization middleware: asks the deployment's Authorizer whether the principal may read
7
+ * (fetch) or write (push) the repository, through the decision cache keyed by principal subject
8
+ * and roles, repository and operation. A refusal is audited and answered as `smartHttp.deniedStatus`
9
+ * says: in-protocol with an "ERR" packet (default), so git prints "remote error: …", or HTTP 403
10
+ * with the reason as the body.
11
+ */
12
+ function authorize(deps) {
13
+ return async (context, next) => {
14
+ const requestId = context.get("requestId");
15
+ const principal = context.get("principal");
16
+ const git = context.get("git");
17
+ const key = `authz:${principal.subject}\u0000${principal.roles.join(" ")}\u0000${git.repo}\u0000${git.operation}`;
18
+ const cached = deps.cache.get(key);
19
+ let allowed = cached?.kind === "allowed" ? cached.allowed : null;
20
+ if (allowed === null) {
21
+ try {
22
+ allowed = await deps.authorizer.authorize(principal, git.repo, git.operation);
23
+ } catch (error) {
24
+ deps.logger.log({
25
+ level: "error",
26
+ message: "authorizer failed",
27
+ requestId,
28
+ error: error instanceof Error ? error.message : String(error)
29
+ });
30
+ return textResponse(503, "Authorization is unavailable; try again later", { "X-Request-Id": requestId });
31
+ }
32
+ deps.cache.set(key, {
33
+ kind: "allowed",
34
+ allowed
35
+ }, decisionTtl(deps, principal));
36
+ }
37
+ if (!allowed) {
38
+ const reason = `access denied: ${principal.subject} may not ${git.operation === "read" ? "read" : "push to"} ${git.repo}`;
39
+ deps.audit.record({
40
+ requestId,
41
+ principal,
42
+ git,
43
+ outcome: "denied",
44
+ reason,
45
+ refs: []
46
+ }, deferWith(context), requestId);
47
+ if (deps.config.deniedStatus === 403) return textResponse(403, reason, { "X-Request-Id": requestId });
48
+ const response = errResponse(git.service, git.endpoint === "info-refs" ? "info-refs" : "rpc", reason);
49
+ response.headers.set("X-Request-Id", requestId);
50
+ return response;
51
+ }
52
+ return next();
53
+ };
54
+ }
55
+ export { authorize };
56
+
57
+ //# sourceMappingURL=authorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.js","names":[],"sources":["../../src/auth/authorize.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { MiddlewareHandler } from 'hono';\n\nimport type { GatewayDeps } from '../proxy/gateway-deps.ts';\nimport type { GatewayEnv } from '../proxy/gateway-env.ts';\nimport { deferWith } from '../proxy/defer.ts';\nimport { errResponse, textResponse } from '../proxy/git-responses.ts';\nimport { decisionTtl } from './authenticate.ts';\n\n/**\n * Authorization middleware: asks the deployment's Authorizer whether the principal may read\n * (fetch) or write (push) the repository, through the decision cache keyed by principal subject\n * and roles, repository and operation. A refusal is audited and answered as `smartHttp.deniedStatus`\n * says: in-protocol with an \"ERR\" packet (default), so git prints \"remote error: …\", or HTTP 403\n * with the reason as the body.\n */\nexport function authorize(deps: GatewayDeps): MiddlewareHandler<GatewayEnv> {\n return async (context, next) => {\n const requestId = context.get('requestId');\n const principal = context.get('principal');\n const git = context.get('git');\n const key = `authz:${principal.subject}\\u0000${principal.roles.join(' ')}\\u0000${git.repo}\\u0000${git.operation}`;\n const cached = deps.cache.get(key);\n let allowed = cached?.kind === 'allowed' ? cached.allowed : null;\n if (allowed === null) {\n try {\n allowed = await deps.authorizer.authorize(principal, git.repo, git.operation);\n } catch (error) {\n deps.logger.log({\n level: 'error',\n message: 'authorizer failed',\n requestId,\n error: error instanceof Error ? error.message : String(error),\n });\n return textResponse(503, 'Authorization is unavailable; try again later', {\n 'X-Request-Id': requestId,\n });\n }\n deps.cache.set(key, { kind: 'allowed', allowed }, decisionTtl(deps, principal));\n }\n if (!allowed) {\n const reason = `access denied: ${principal.subject} may not ${git.operation === 'read' ? 'read' : 'push to'} ${git.repo}`;\n deps.audit.record(\n { requestId, principal, git, outcome: 'denied', reason, refs: [] },\n deferWith(context),\n requestId,\n );\n if (deps.config.deniedStatus === 403) {\n return textResponse(403, reason, { 'X-Request-Id': requestId });\n }\n const response = errResponse(git.service, git.endpoint === 'info-refs' ? 'info-refs' : 'rpc', reason);\n response.headers.set('X-Request-Id', requestId);\n return response;\n }\n return next();\n };\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAgB,UAAU,MAAkD;CAC1E,OAAO,OAAO,SAAS,SAAS;EAC9B,MAAM,YAAY,QAAQ,IAAI,WAAW;EACzC,MAAM,YAAY,QAAQ,IAAI,WAAW;EACzC,MAAM,MAAM,QAAQ,IAAI,KAAK;EAC7B,MAAM,MAAM,SAAS,UAAU,QAAQ,QAAQ,UAAU,MAAM,KAAK,GAAG,EAAE,QAAQ,IAAI,KAAK,QAAQ,IAAI;EACtG,MAAM,SAAS,KAAK,MAAM,IAAI,GAAG;EACjC,IAAI,UAAU,QAAQ,SAAS,YAAY,OAAO,UAAU;EAC5D,IAAI,YAAY,MAAM;GACpB,IAAI;IACF,UAAU,MAAM,KAAK,WAAW,UAAU,WAAW,IAAI,MAAM,IAAI,SAAS;GAC9E,SAAS,OAAO;IACd,KAAK,OAAO,IAAI;KACd,OAAO;KACP,SAAS;KACT;KACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAC9D,CAAC;IACD,OAAO,aAAa,KAAK,iDAAiD,EACxE,gBAAgB,UAClB,CAAC;GACH;GACA,KAAK,MAAM,IAAI,KAAK;IAAE,MAAM;IAAW;GAAQ,GAAG,YAAY,MAAM,SAAS,CAAC;EAChF;EACA,IAAI,CAAC,SAAS;GACZ,MAAM,SAAS,kBAAkB,UAAU,QAAQ,WAAW,IAAI,cAAc,SAAS,SAAS,UAAU,GAAG,IAAI;GACnH,KAAK,MAAM,OACT;IAAE;IAAW;IAAW;IAAK,SAAS;IAAU;IAAQ,MAAM,CAAC;GAAE,GACjE,UAAU,OAAO,GACjB,SACF;GACA,IAAI,KAAK,OAAO,iBAAiB,KAC/B,OAAO,aAAa,KAAK,QAAQ,EAAE,gBAAgB,UAAU,CAAC;GAEhE,MAAM,WAAW,YAAY,IAAI,SAAS,IAAI,aAAa,cAAc,cAAc,OAAO,MAAM;GACpG,SAAS,QAAQ,IAAI,gBAAgB,SAAS;GAC9C,OAAO;EACT;EACA,OAAO,KAAK;CACd;AACF"}