@venizia/ignis 0.4.8-9 → 0.5.0-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 (265) hide show
  1. package/dist/esm/base/applications/base.js +5 -2
  2. package/dist/esm/base/applications/base.js.map +1 -1
  3. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js +1 -1
  4. package/dist/esm/base/middlewares/request-spy/request-spy.middleware.js.map +1 -1
  5. package/dist/esm/components/api-reference/common/keys.d.ts +2 -1
  6. package/dist/esm/components/api-reference/common/keys.js +4 -1
  7. package/dist/esm/components/api-reference/common/keys.js.map +1 -1
  8. package/dist/esm/components/api-reference/common/types.d.ts +7 -4
  9. package/dist/esm/components/api-reference/common/types.js.map +1 -1
  10. package/dist/esm/components/api-reference/component.js +8 -3
  11. package/dist/esm/components/api-reference/component.js.map +1 -1
  12. package/dist/esm/components/auth/authenticate/component.js +13 -18
  13. package/dist/esm/components/auth/authenticate/component.js.map +1 -1
  14. package/dist/esm/components/auth/authenticate/controllers/factory.d.ts +3 -3
  15. package/dist/esm/components/auth/authenticate/controllers/factory.js +1 -1
  16. package/dist/esm/components/auth/authenticate/controllers/factory.js.map +1 -1
  17. package/dist/esm/components/auth/authenticate/controllers/jwks/controller.js.map +1 -1
  18. package/dist/esm/components/auth/authenticate/controllers/jwks/definitions.d.ts +2 -2
  19. package/dist/esm/components/auth/authenticate/controllers/service-certs/controller.js.map +1 -1
  20. package/dist/esm/components/auth/authenticate/controllers/service-certs/definitions.d.ts +2 -2
  21. package/dist/esm/components/auth/authenticate/services/basic/service.js +1 -1
  22. package/dist/esm/components/auth/authenticate/services/basic/service.js.map +1 -1
  23. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.d.ts +5 -3
  24. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js +19 -2
  25. package/dist/esm/components/auth/authenticate/services/bearer/abstract.service.js.map +1 -1
  26. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.d.ts +3 -3
  27. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js +1 -1
  28. package/dist/esm/components/auth/authenticate/services/bearer/jwks/issuer.service.js.map +1 -1
  29. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.d.ts +3 -3
  30. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js +2 -2
  31. package/dist/esm/components/auth/authenticate/services/bearer/jwks/verifier.service.js.map +1 -1
  32. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.d.ts +3 -3
  33. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js +1 -1
  34. package/dist/esm/components/auth/authenticate/services/bearer/jws.service.js.map +1 -1
  35. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.d.ts +10 -22
  36. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js +16 -112
  37. package/dist/esm/components/auth/authenticate/services/jwks-url-policy.js.map +1 -1
  38. package/dist/esm/components/auth/authenticate/services/service/signer.service.d.ts +11 -0
  39. package/dist/esm/components/auth/authenticate/services/service/signer.service.js +18 -0
  40. package/dist/esm/components/auth/authenticate/services/service/signer.service.js.map +1 -1
  41. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js +1 -1
  42. package/dist/esm/components/auth/authenticate/services/service/verifier.service.js.map +1 -1
  43. package/dist/esm/components/auth/authenticate/strategies/basic.strategy.js.map +1 -1
  44. package/dist/esm/components/auth/authenticate/strategies/jwks/issuer.js.map +1 -1
  45. package/dist/esm/components/auth/authenticate/strategies/jwks/verifier.js.map +1 -1
  46. package/dist/esm/components/auth/authenticate/strategies/jws.strategy.js.map +1 -1
  47. package/dist/esm/components/auth/authenticate/strategies/service.strategy.js.map +1 -1
  48. package/dist/esm/components/auth/authorize/adapters/common/types.d.ts +1 -2
  49. package/dist/esm/components/auth/authorize/adapters/common/types.js.map +1 -1
  50. package/dist/esm/components/auth/authorize/component.js.map +1 -1
  51. package/dist/esm/components/controller/grpc/common/types.d.ts +1 -1
  52. package/dist/esm/components/controller/grpc/common/types.js +4 -1
  53. package/dist/esm/components/controller/grpc/common/types.js.map +1 -1
  54. package/dist/esm/components/controller/grpc/grpc.component.js.map +1 -1
  55. package/dist/esm/components/health-check/common/keys.d.ts +4 -2
  56. package/dist/esm/components/health-check/common/keys.js +7 -2
  57. package/dist/esm/components/health-check/common/keys.js.map +1 -1
  58. package/dist/esm/components/health-check/common/types.d.ts +1 -1
  59. package/dist/esm/components/health-check/common/types.js.map +1 -1
  60. package/dist/esm/components/health-check/component.js +1 -3
  61. package/dist/esm/components/health-check/component.js.map +1 -1
  62. package/dist/esm/components/mail/common/constants.d.ts +32 -14
  63. package/dist/esm/components/mail/common/constants.js +25 -32
  64. package/dist/esm/components/mail/common/constants.js.map +1 -1
  65. package/dist/esm/components/mail/common/errors.d.ts +19 -1
  66. package/dist/esm/components/mail/common/errors.js +13 -1
  67. package/dist/esm/components/mail/common/errors.js.map +1 -1
  68. package/dist/esm/components/mail/common/keys.d.ts +14 -11
  69. package/dist/esm/components/mail/common/keys.js +34 -11
  70. package/dist/esm/components/mail/common/keys.js.map +1 -1
  71. package/dist/esm/components/mail/common/types/message.d.ts +7 -4
  72. package/dist/esm/components/mail/common/types/message.js.map +1 -1
  73. package/dist/esm/components/mail/common/types/options.d.ts +54 -10
  74. package/dist/esm/components/mail/common/types/options.js.map +1 -1
  75. package/dist/esm/components/mail/common/types/queue.d.ts +25 -12
  76. package/dist/esm/components/mail/common/types/queue.js.map +1 -1
  77. package/dist/esm/components/mail/common/types/template.d.ts +8 -4
  78. package/dist/esm/components/mail/common/types/template.js.map +1 -1
  79. package/dist/esm/components/mail/common/types/verification.d.ts +1 -0
  80. package/dist/esm/components/mail/common/types/verification.js.map +1 -1
  81. package/dist/esm/components/mail/component.js +11 -2
  82. package/dist/esm/components/mail/component.js.map +1 -1
  83. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.d.ts +3 -1
  84. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js +27 -33
  85. package/dist/esm/components/mail/helpers/executors/bull-mq-executor.helper.js.map +1 -1
  86. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.d.ts +2 -0
  87. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js +17 -10
  88. package/dist/esm/components/mail/helpers/executors/internal-queue-executor.helper.js.map +1 -1
  89. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js +11 -6
  90. package/dist/esm/components/mail/helpers/transporters/amazon-ses-transporter.helper.js.map +1 -1
  91. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.d.ts +2 -3
  92. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js +15 -6
  93. package/dist/esm/components/mail/helpers/transporters/mailgun-transporter.helper.js.map +1 -1
  94. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.d.ts +2 -3
  95. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js +2 -2
  96. package/dist/esm/components/mail/helpers/transporters/nodemail-transporter.helper.js.map +1 -1
  97. package/dist/esm/components/mail/providers/mail-queue-executor.provider.d.ts +2 -2
  98. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js +7 -9
  99. package/dist/esm/components/mail/providers/mail-queue-executor.provider.js.map +1 -1
  100. package/dist/esm/components/mail/providers/mail-transporter.provider.js +7 -7
  101. package/dist/esm/components/mail/providers/mail-transporter.provider.js.map +1 -1
  102. package/dist/esm/components/mail/services/generators/numeric-code.d.ts +1 -6
  103. package/dist/esm/components/mail/services/generators/numeric-code.js +3 -31
  104. package/dist/esm/components/mail/services/generators/numeric-code.js.map +1 -1
  105. package/dist/esm/components/mail/services/generators/random-token.d.ts +4 -1
  106. package/dist/esm/components/mail/services/generators/random-token.js +9 -6
  107. package/dist/esm/components/mail/services/generators/random-token.js.map +1 -1
  108. package/dist/esm/components/mail/services/mail.service.d.ts +1 -2
  109. package/dist/esm/components/mail/services/mail.service.js +22 -19
  110. package/dist/esm/components/mail/services/mail.service.js.map +1 -1
  111. package/dist/esm/components/mail/services/template.service.d.ts +8 -6
  112. package/dist/esm/components/mail/services/template.service.js +34 -33
  113. package/dist/esm/components/mail/services/template.service.js.map +1 -1
  114. package/dist/esm/components/mail/utilities/attachment.utility.js +8 -6
  115. package/dist/esm/components/mail/utilities/attachment.utility.js.map +1 -1
  116. package/dist/esm/components/mail/utilities/header.utility.d.ts +14 -0
  117. package/dist/esm/components/mail/utilities/header.utility.js +44 -0
  118. package/dist/esm/components/mail/utilities/header.utility.js.map +1 -0
  119. package/dist/esm/components/mail/utilities/index.d.ts +2 -0
  120. package/dist/esm/components/mail/utilities/index.js +2 -0
  121. package/dist/esm/components/mail/utilities/index.js.map +1 -1
  122. package/dist/esm/components/mail/utilities/mime.utility.d.ts +5 -1
  123. package/dist/esm/components/mail/utilities/mime.utility.js +12 -58
  124. package/dist/esm/components/mail/utilities/mime.utility.js.map +1 -1
  125. package/dist/esm/components/mail/utilities/template-renderer.utility.d.ts +31 -0
  126. package/dist/esm/components/mail/utilities/template-renderer.utility.js +184 -0
  127. package/dist/esm/components/mail/utilities/template-renderer.utility.js.map +1 -0
  128. package/dist/esm/components/mail/utilities/type.utility.d.ts +2 -3
  129. package/dist/esm/components/mail/utilities/type.utility.js +6 -7
  130. package/dist/esm/components/mail/utilities/type.utility.js.map +1 -1
  131. package/dist/esm/components/request-tracker/component.d.ts +2 -1
  132. package/dist/esm/components/request-tracker/component.js +5 -5
  133. package/dist/esm/components/request-tracker/component.js.map +1 -1
  134. package/dist/esm/components/server-info/common/keys.d.ts +2 -1
  135. package/dist/esm/components/server-info/common/keys.js +4 -1
  136. package/dist/esm/components/server-info/common/keys.js.map +1 -1
  137. package/dist/esm/components/server-info/common/types.d.ts +1 -1
  138. package/dist/esm/components/server-info/common/types.js.map +1 -1
  139. package/dist/esm/components/server-info/component.js +1 -3
  140. package/dist/esm/components/server-info/component.js.map +1 -1
  141. package/dist/esm/components/socket-io/common/keys.d.ts +9 -6
  142. package/dist/esm/components/socket-io/common/keys.js +19 -6
  143. package/dist/esm/components/socket-io/common/keys.js.map +1 -1
  144. package/dist/esm/components/socket-io/component.js +1 -1
  145. package/dist/esm/components/socket-io/component.js.map +1 -1
  146. package/dist/esm/components/socket-io/handlers/bun.handler.d.ts +13 -3
  147. package/dist/esm/components/socket-io/handlers/bun.handler.js.map +1 -1
  148. package/dist/esm/components/static-asset/common/constants.d.ts +51 -24
  149. package/dist/esm/components/static-asset/common/constants.js +75 -47
  150. package/dist/esm/components/static-asset/common/constants.js.map +1 -1
  151. package/dist/esm/components/static-asset/common/errors.d.ts +30 -35
  152. package/dist/esm/components/static-asset/common/errors.js +31 -33
  153. package/dist/esm/components/static-asset/common/errors.js.map +1 -1
  154. package/dist/esm/components/static-asset/common/index.d.ts +1 -1
  155. package/dist/esm/components/static-asset/common/index.js +1 -1
  156. package/dist/esm/components/static-asset/common/index.js.map +1 -1
  157. package/dist/esm/components/static-asset/common/keys.d.ts +14 -2
  158. package/dist/esm/components/static-asset/common/keys.js +17 -2
  159. package/dist/esm/components/static-asset/common/keys.js.map +1 -1
  160. package/dist/esm/components/static-asset/common/types.d.ts +267 -147
  161. package/dist/esm/components/static-asset/common/types.js.map +1 -1
  162. package/dist/esm/components/static-asset/common/validation.d.ts +10 -0
  163. package/dist/esm/components/static-asset/common/validation.js +8 -0
  164. package/dist/esm/components/static-asset/common/validation.js.map +1 -0
  165. package/dist/esm/components/static-asset/component.d.ts +4 -2
  166. package/dist/esm/components/static-asset/component.js +27 -31
  167. package/dist/esm/components/static-asset/component.js.map +1 -1
  168. package/dist/esm/components/static-asset/controller/factory.d.ts +37 -79
  169. package/dist/esm/components/static-asset/controller/factory.js +26 -917
  170. package/dist/esm/components/static-asset/controller/factory.js.map +1 -1
  171. package/dist/esm/components/static-asset/controller/index.d.ts +1 -0
  172. package/dist/esm/components/static-asset/controller/index.js +1 -0
  173. package/dist/esm/components/static-asset/controller/index.js.map +1 -1
  174. package/dist/esm/components/static-asset/controller/routes/context.d.ts +62 -0
  175. package/dist/esm/components/static-asset/controller/routes/context.js +45 -0
  176. package/dist/esm/components/static-asset/controller/routes/context.js.map +1 -0
  177. package/dist/esm/components/static-asset/controller/routes/definition.d.ts +40 -0
  178. package/dist/esm/components/static-asset/controller/routes/definition.js +83 -0
  179. package/dist/esm/components/static-asset/controller/routes/definition.js.map +1 -0
  180. package/dist/esm/components/static-asset/controller/routes/direct-upload.d.ts +3 -0
  181. package/dist/esm/components/static-asset/controller/routes/direct-upload.js +153 -0
  182. package/dist/esm/components/static-asset/controller/routes/direct-upload.js.map +1 -0
  183. package/dist/esm/components/static-asset/controller/routes/labels.d.ts +16 -0
  184. package/dist/esm/components/static-asset/controller/routes/labels.js +19 -0
  185. package/dist/esm/components/static-asset/controller/routes/labels.js.map +1 -0
  186. package/dist/esm/components/static-asset/controller/routes/objects.d.ts +7 -0
  187. package/dist/esm/components/static-asset/controller/routes/objects.js +193 -0
  188. package/dist/esm/components/static-asset/controller/routes/objects.js.map +1 -0
  189. package/dist/esm/components/static-asset/controller/routes/serve.d.ts +29 -0
  190. package/dist/esm/components/static-asset/controller/routes/serve.js +152 -0
  191. package/dist/esm/components/static-asset/controller/routes/serve.js.map +1 -0
  192. package/dist/esm/components/static-asset/controller/routes/table.d.ts +12 -0
  193. package/dist/esm/components/static-asset/controller/routes/table.js +52 -0
  194. package/dist/esm/components/static-asset/controller/routes/table.js.map +1 -0
  195. package/dist/esm/components/static-asset/controller/routes/upload.d.ts +10 -0
  196. package/dist/esm/components/static-asset/controller/routes/upload.js +175 -0
  197. package/dist/esm/components/static-asset/controller/routes/upload.js.map +1 -0
  198. package/dist/esm/components/static-asset/index.d.ts +2 -1
  199. package/dist/esm/components/static-asset/index.js +2 -1
  200. package/dist/esm/components/static-asset/index.js.map +1 -1
  201. package/dist/esm/components/static-asset/models/base.model.d.ts +4 -4
  202. package/dist/esm/components/static-asset/models/base.model.js.map +1 -1
  203. package/dist/esm/components/static-asset/services/commitment.service.d.ts +103 -0
  204. package/dist/esm/components/static-asset/services/commitment.service.js +252 -0
  205. package/dist/esm/components/static-asset/services/commitment.service.js.map +1 -0
  206. package/dist/esm/components/static-asset/services/index.d.ts +3 -0
  207. package/dist/esm/components/static-asset/services/index.js +3 -0
  208. package/dist/esm/components/static-asset/services/index.js.map +1 -0
  209. package/dist/esm/components/static-asset/services/policy.service.d.ts +45 -0
  210. package/dist/esm/components/static-asset/services/policy.service.js +104 -0
  211. package/dist/esm/components/static-asset/services/policy.service.js.map +1 -0
  212. package/dist/esm/components/static-asset/utilities/commit-token.utility.d.ts +28 -0
  213. package/dist/esm/components/static-asset/utilities/commit-token.utility.js +112 -0
  214. package/dist/esm/components/static-asset/utilities/commit-token.utility.js.map +1 -0
  215. package/dist/esm/components/static-asset/utilities/entry.utility.d.ts +69 -0
  216. package/dist/esm/components/static-asset/utilities/entry.utility.js +160 -0
  217. package/dist/esm/components/static-asset/utilities/entry.utility.js.map +1 -0
  218. package/dist/esm/components/static-asset/utilities/index.d.ts +6 -0
  219. package/dist/esm/components/static-asset/utilities/index.js +6 -0
  220. package/dist/esm/components/static-asset/utilities/index.js.map +1 -0
  221. package/dist/esm/components/static-asset/{ingest.d.ts → utilities/ingest.utility.d.ts} +8 -8
  222. package/dist/esm/components/static-asset/{ingest.js → utilities/ingest.utility.js} +21 -23
  223. package/dist/esm/components/static-asset/utilities/ingest.utility.js.map +1 -0
  224. package/dist/esm/components/static-asset/{controller/key-scope.d.ts → utilities/key-scope.utility.d.ts} +21 -2
  225. package/dist/esm/components/static-asset/utilities/key-scope.utility.js +74 -0
  226. package/dist/esm/components/static-asset/utilities/key-scope.utility.js.map +1 -0
  227. package/dist/esm/components/static-asset/{controller/meta-link.d.ts → utilities/meta-link.utility.d.ts} +9 -9
  228. package/dist/esm/components/static-asset/{controller/meta-link.js → utilities/meta-link.utility.js} +10 -10
  229. package/dist/esm/components/static-asset/utilities/meta-link.utility.js.map +1 -0
  230. package/dist/esm/components/static-asset/utilities/object-link.utility.d.ts +16 -0
  231. package/dist/esm/components/static-asset/utilities/object-link.utility.js +20 -0
  232. package/dist/esm/components/static-asset/utilities/object-link.utility.js.map +1 -0
  233. package/dist/esm/components/static-asset/utilities/pinned-file.utility.d.ts +39 -0
  234. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js +53 -0
  235. package/dist/esm/components/static-asset/utilities/pinned-file.utility.js.map +1 -0
  236. package/dist/esm/components/static-asset/utilities/route-options.utility.d.ts +43 -0
  237. package/dist/esm/components/static-asset/utilities/route-options.utility.js +71 -0
  238. package/dist/esm/components/static-asset/utilities/route-options.utility.js.map +1 -0
  239. package/dist/esm/components/static-asset/utilities/toggle.utility.d.ts +5 -0
  240. package/dist/esm/components/static-asset/utilities/toggle.utility.js +5 -0
  241. package/dist/esm/components/static-asset/utilities/toggle.utility.js.map +1 -0
  242. package/dist/esm/components/websocket/common/keys.d.ts +12 -10
  243. package/dist/esm/components/websocket/common/keys.js +31 -10
  244. package/dist/esm/components/websocket/common/keys.js.map +1 -1
  245. package/dist/esm/components/websocket/component.js.map +1 -1
  246. package/dist/esm/testing/assert-application-boots.d.ts +2 -2
  247. package/dist/esm/testing/assert-application-boots.js +6 -2
  248. package/dist/esm/testing/assert-application-boots.js.map +1 -1
  249. package/dist/presets/app/preset.json +4 -4
  250. package/dist/presets/lib/preset.json +3 -3
  251. package/dist/presets/shared/preset.json +1 -1
  252. package/package.json +8 -8
  253. package/dist/esm/components/static-asset/common/commit-token.d.ts +0 -28
  254. package/dist/esm/components/static-asset/common/commit-token.js +0 -48
  255. package/dist/esm/components/static-asset/common/commit-token.js.map +0 -1
  256. package/dist/esm/components/static-asset/controller/base.definition.d.ts +0 -30
  257. package/dist/esm/components/static-asset/controller/base.definition.js +0 -307
  258. package/dist/esm/components/static-asset/controller/base.definition.js.map +0 -1
  259. package/dist/esm/components/static-asset/controller/key-scope.js +0 -41
  260. package/dist/esm/components/static-asset/controller/key-scope.js.map +0 -1
  261. package/dist/esm/components/static-asset/controller/meta-link.js.map +0 -1
  262. package/dist/esm/components/static-asset/controller/route-options.d.ts +0 -29
  263. package/dist/esm/components/static-asset/controller/route-options.js +0 -47
  264. package/dist/esm/components/static-asset/controller/route-options.js.map +0 -1
  265. package/dist/esm/components/static-asset/ingest.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../../../../../../src/components/static-asset/controller/routes/serve.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,cAAc,GAIf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAGL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEvE,iKAAiK;AACjK,MAAM,OAAO,gBAAgB;IAC3B;;;OAGG;IACH,MAAM,CAAC,wBAAwB,CAAC,IAAoD;QAIlF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAChC,MAAM,SAAS,GAAG,MAAM;aACrB,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;aACrC,WAAW,EAAE;aACb,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACb,IAAI,EAAE,CAAC;QAEV,IAAI,CAAC,uBAAuB,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACvD,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,wBAAwB,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;QAC1F,CAAC;QAED,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACxD,CAAC;IAED;;;;;OAKG;IACH,M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AAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;KAC3D,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAwB;IAC9C,WAAW,CAAC,EAAE,GAAG,EAAE,oBAAoB,CAAC,kBAAkB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAChG,WAAW,CAAC;QACV,GAAG,EAAE,oBAAoB,CAAC,uBAAuB;QACjD,OAAO,EAAE,UAAU;QACnB,MAAM,EAAE,IAAI;KACb,CAAC;CACH,CAAC","sourcesContent":["import type { TRouteContext } from '@/base/controllers';\nimport {\n ContentDispositionTypes,\n RequestUtility,\n type IFileStat,\n type IObjectRef,\n type IStorageHelper,\n} from '@venizia/ignis-helpers';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { StaticAssetContentTypes, StaticAssetHeaders, StaticAssetRouteKeys } from '../../common';\nimport {\n type IStaticAssetRoute,\n type IStaticAssetRouteEnv,\n StaticAssetFeatures,\n StaticAssetRouteUtility,\n} from './context';\nimport { StaticAssetDefinition, StaticAssetPaths } from './definition';\n\n/** The serve side of an entry's controller, public so a route of your own makes the same decisions: the served content type and the `ETag` and `304` answers. */\nexport class StaticAssetServe {\n /**\n * The served type comes from the object NAME, never the backend or the uploader: a renderable type on\n * the API origin is stored XSS. The backend's own content-type is never sent.\n */\n static resolveServedContentType(opts: { helper: IStorageHelper; object: IObjectRef }): {\n contentType: string;\n isRenderable: boolean;\n } {\n const { helper, object } = opts;\n const candidate = helper\n .getMimeType({ filename: object.key })\n .toLowerCase()\n .split(';')[0]\n .trim();\n\n if (!StaticAssetContentTypes.RENDERABLE.has(candidate)) {\n return { contentType: HTTP.HeaderValues.APPLICATION_OCTET_STREAM, isRenderable: false };\n }\n\n return { contentType: candidate, isRenderable: true };\n }\n\n /**\n * Sets `ETag` and `Last-Modified` from `stat` and answers whether the client's copy is current. A `true`\n * means the caller returns a 304 without reading the object; the headers are already on `ctx`.\n * `If-None-Match` decides alone when present (weak comparison, `*` matches any); otherwise\n * `If-Modified-Since` does. An application's own route can call it with a `stat` it already holds.\n */\n static applyValidators(opts: { ctx: TRouteContext; stat: IFileStat }): boolean {\n const { ctx, stat } = opts;\n const { etag, lastModified } = stat;\n const quotedEtag =\n etag && !etag.startsWith('\"') && !etag.startsWith('W/\"') ? `\"${etag}\"` : etag;\n\n if (quotedEtag) {\n ctx.header(HTTP.Headers.ETAG, quotedEtag);\n }\n\n if (lastModified) {\n ctx.header(HTTP.Headers.LAST_MODIFIED, lastModified.toUTCString());\n }\n\n const ifNoneMatch = ctx.req.header(HTTP.Headers.IF_NONE_MATCH);\n\n if (ifNoneMatch !== undefined) {\n const wanted = ifNoneMatch.split(',').map((tag) => tag.trim());\n const stripWeak = (tag: string) => tag.replace(/^W\\//, '');\n\n return wanted.some(\n (tag) => tag === '*' || (!!quotedEtag && stripWeak(tag) === stripWeak(quotedEtag)),\n );\n }\n\n const ifModifiedSince = ctx.req.header(HTTP.Headers.IF_MODIFIED_SINCE);\n\n if (!ifModifiedSince || !lastModified) {\n return false;\n }\n\n const since = Date.parse(ifModifiedSince);\n\n // HTTP dates have whole-second precision.\n return !Number.isNaN(since) && Math.floor(lastModified.getTime() / 1000) * 1000 <= since;\n }\n}\n\n/**\n * Reads one `Range` header. Only a single byte range is honoured - multipart ranges need a multipart\n * body no browser asks for here. An unsatisfiable or malformed range returns `null`, and the caller\n * serves the whole object, which is what RFC 9110 allows.\n */\nconst readByteRange = (opts: {\n header: string | undefined;\n size: number;\n}): { start: number; end: number } | null => {\n const { header, size } = opts;\n\n if (!header || size <= 0) {\n return null;\n }\n\n const match = /^bytes=(\\d*)-(\\d*)$/.exec(header.trim());\n\n if (!match) {\n return null;\n }\n\n const [, rawStart, rawEnd] = match;\n\n // `bytes=-500` means the LAST 500 bytes, not \"from 0 to 500\".\n if (!rawStart) {\n const suffixLength = Number(rawEnd);\n\n if (!Number.isInteger(suffixLength) || suffixLength <= 0) {\n return null;\n }\n\n return { start: Math.max(size - suffixLength, 0), end: size - 1 };\n }\n\n const start = Number(rawStart);\n const end = rawEnd ? Number(rawEnd) : size - 1;\n\n if (!Number.isInteger(start) || !Number.isInteger(end) || start > end || start >= size) {\n return null;\n }\n\n return { start, end: Math.min(end, size - 1) };\n};\n\n/**\n * Streams one object. `attach` forces a download; without it a type outside the allow-list still\n * downloads instead of rendering, which is the XSS boundary. Both honour `Range`.\n */\nconst serve = async (opts: {\n ctx: TRouteContext;\n env: IStaticAssetRouteEnv;\n attach: boolean;\n}): Promise<Response> => {\n const { ctx, env, attach } = opts;\n const { helper } = env;\n const { bucket, object } = await StaticAssetRouteUtility.resolveTarget({\n ctx,\n env,\n isObject: true,\n });\n const stat = await helper.getStat({ bucket, object });\n const { size } = stat;\n\n if (StaticAssetServe.applyValidators({ ctx, stat })) {\n return new Response(null, {\n headers: ctx.res.headers,\n status: HTTP.ResultCodes.RS_3.NotModified,\n });\n }\n\n const served = StaticAssetServe.resolveServedContentType({ helper, object });\n ctx.header(HTTP.Headers.CONTENT_TYPE, served.contentType);\n ctx.header(HTTP.Headers.X_CONTENT_TYPE_OPTIONS, StaticAssetHeaders.NOSNIFF);\n // Sandboxed even when renderable, so an unforeseen renderable type cannot reach this origin.\n ctx.header(HTTP.Headers.CONTENT_SECURITY_POLICY, StaticAssetHeaders.CSP_SANDBOX);\n // Advertised unconditionally: a player only offers seeking once it sees this.\n ctx.header(HTTP.Headers.ACCEPT_RANGES, StaticAssetHeaders.RANGE_UNIT);\n\n if (attach || !served.isRenderable) {\n ctx.header(\n HTTP.Headers.CONTENT_DISPOSITION,\n RequestUtility.buildContentDispositionHeader({\n filename: object.key.split('/').pop() ?? object.key,\n type: ContentDispositionTypes.ATTACHMENT,\n }),\n );\n }\n\n const range = readByteRange({ header: ctx.req.header(HTTP.Headers.RANGE), size });\n\n if (range) {\n ctx.header(HTTP.Headers.CONTENT_LENGTH, String(range.end - range.start + 1));\n ctx.header(\n HTTP.Headers.CONTENT_RANGE,\n `${StaticAssetHeaders.RANGE_UNIT} ${range.start}-${range.end}/${size}`,\n );\n } else {\n ctx.header(HTTP.Headers.CONTENT_LENGTH, size.toString());\n }\n\n const stream = await helper.getObjectStream({ bucket, object, range: range ?? undefined });\n\n return new Response(stream, {\n headers: ctx.res.headers,\n status: range ? HTTP.ResultCodes.RS_2.PartialContent : HTTP.ResultCodes.RS_2.Ok,\n });\n};\n\nconst streamRoute = (opts: {\n key:\n | typeof StaticAssetRouteKeys.GET_OBJECT_BY_NAME\n | typeof StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME;\n segment: string;\n attach: boolean;\n}): IStaticAssetRoute => ({\n key: opts.key,\n feature: StaticAssetFeatures.OBJECT,\n build: (env) => ({\n config: StaticAssetDefinition.stream({\n method: HTTP.Methods.GET,\n path: `/${opts.segment}/${StaticAssetPaths.object({ env })}`,\n params: StaticAssetPaths.objectParams(),\n }),\n handler: (ctx) => serve({ ctx, env, attach: opts.attach }),\n }),\n});\n\nexport const serveRoutes: IStaticAssetRoute[] = [\n streamRoute({ key: StaticAssetRouteKeys.GET_OBJECT_BY_NAME, segment: 'objects', attach: false }),\n streamRoute({\n key: StaticAssetRouteKeys.DOWNLOAD_OBJECT_BY_NAME,\n segment: 'download',\n attach: true,\n }),\n];\n"]}
@@ -0,0 +1,12 @@
1
+ import type { BaseRestController } from '../../../../base/controllers/index.js';
2
+ import { type IStaticAssetRoute, type IStaticAssetRouteEnv } from './context.js';
3
+ export declare class StaticAssetRouteTable {
4
+ /** Every built-in route, in registration order. Whether one is registered is decided in `register`, nowhere else. */
5
+ static readonly ROUTES: IStaticAssetRoute[];
6
+ /** Binds each route whose feature is on and that the application did not turn off. */
7
+ static register(opts: {
8
+ controller: BaseRestController;
9
+ env: IStaticAssetRouteEnv;
10
+ }): void;
11
+ }
12
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { StaticAssetRouteOptionsUtility } from '../../utilities/route-options.utility.js';
2
+ import { StaticAssetFeatures, } from './context.js';
3
+ import { directUploadRoutes } from './direct-upload.js';
4
+ import { metaLinkRoutes, objectRoutes } from './objects.js';
5
+ import { serveRoutes } from './serve.js';
6
+ import { uploadRoute } from './upload.js';
7
+ /** Whether the entry has the feature a route belongs to. */
8
+ const FEATURE_GATES = {
9
+ [StaticAssetFeatures.OBJECT]: () => true,
10
+ [StaticAssetFeatures.SERVER_UPLOAD]: (env) => env.serverUpload !== undefined,
11
+ [StaticAssetFeatures.DIRECT_UPLOAD]: (env) => env.directUpload !== undefined,
12
+ [StaticAssetFeatures.VALIDATION]: (env) => env.directUpload?.validation !== undefined,
13
+ [StaticAssetFeatures.META_LINK]: (env) => env.metaLink !== undefined,
14
+ };
15
+ export class StaticAssetRouteTable {
16
+ /** Every built-in route, in registration order. Whether one is registered is decided in `register`, nowhere else. */
17
+ static { this.ROUTES = [
18
+ ...serveRoutes,
19
+ uploadRoute,
20
+ ...objectRoutes,
21
+ ...directUploadRoutes,
22
+ ...metaLinkRoutes,
23
+ ]; }
24
+ /** Binds each route whose feature is on and that the application did not turn off. */
25
+ static register(opts) {
26
+ const { controller, env } = opts;
27
+ for (const route of StaticAssetRouteTable.ROUTES) {
28
+ if (!FEATURE_GATES[route.feature](env)) {
29
+ continue;
30
+ }
31
+ const { isEnabled, override } = StaticAssetRouteOptionsUtility.readRoute({
32
+ key: route.key,
33
+ route: env.routes[route.key],
34
+ auth: env.auth,
35
+ });
36
+ if (!isEnabled) {
37
+ continue;
38
+ }
39
+ const { config, handler } = route.build(env);
40
+ controller
41
+ .bindRoute({
42
+ configs: {
43
+ ...config,
44
+ ...override,
45
+ middleware: route.middleware?.({ env, own: override.middleware }) ?? override.middleware,
46
+ },
47
+ })
48
+ .to({ handler });
49
+ }
50
+ }
51
+ }
52
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sourceRoot":"","sources":["../../../../../../src/components/static-asset/controller/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,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;gBACvC,SAAS;YACX,CAAC;YAED,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,8BAA8B,CAAC,SAAS,CAAC;gBACvE,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;gBAC5B,IAAI,EAAE,GAAG,CAAC,IAAI;aACf,CAAC,CAAC;YAEH,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,SAAS;YACX,CAAC;YAED,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAE7C,UAAU;iBACP,SAAS,CAAC;gBACT,OAAO,EAAE;oBACP,GAAG,MAAM;oBACT,GAAG,QAAQ;oBACX,UAAU,EACR,KAAK,CAAC,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,QAAQ,CAAC,UAAU;iBAC/E;aACF,CAAC;iBACD,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACrB,CAAC;IACH,CAAC","sourcesContent":["import type { BaseRestController } from '@/base/controllers';\nimport { StaticAssetRouteOptionsUtility } from '../../utilities/route-options.utility';\nimport {\n type IStaticAssetRoute,\n type IStaticAssetRouteEnv,\n StaticAssetFeatures,\n type TStaticAssetFeature,\n} from './context';\nimport { directUploadRoutes } from './direct-upload';\nimport { metaLinkRoutes, objectRoutes } from './objects';\nimport { serveRoutes } from './serve';\nimport { uploadRoute } from './upload';\n\n/** Whether the entry has the feature a route belongs to. */\nconst FEATURE_GATES: Record<TStaticAssetFeature, (env: IStaticAssetRouteEnv) => boolean> = {\n [StaticAssetFeatures.OBJECT]: () => true,\n [StaticAssetFeatures.SERVER_UPLOAD]: (env) => env.serverUpload !== undefined,\n [StaticAssetFeatures.DIRECT_UPLOAD]: (env) => env.directUpload !== undefined,\n [StaticAssetFeatures.VALIDATION]: (env) => env.directUpload?.validation !== undefined,\n [StaticAssetFeatures.META_LINK]: (env) => env.metaLink !== undefined,\n};\n\nexport class StaticAssetRouteTable {\n /** Every built-in route, in registration order. Whether one is registered is decided in `register`, nowhere else. */\n static readonly ROUTES: IStaticAssetRoute[] = [\n ...serveRoutes,\n uploadRoute,\n ...objectRoutes,\n ...directUploadRoutes,\n ...metaLinkRoutes,\n ];\n\n /** Binds each route whose feature is on and that the application did not turn off. */\n static register(opts: { controller: BaseRestController; env: IStaticAssetRouteEnv }): void {\n const { controller, env } = opts;\n\n for (const route of StaticAssetRouteTable.ROUTES) {\n if (!FEATURE_GATES[route.feature](env)) {\n continue;\n }\n\n const { isEnabled, override } = StaticAssetRouteOptionsUtility.readRoute({\n key: route.key,\n route: env.routes[route.key],\n auth: env.auth,\n });\n\n if (!isEnabled) {\n continue;\n }\n\n const { config, handler } = route.build(env);\n\n controller\n .bindRoute({\n configs: {\n ...config,\n ...override,\n middleware:\n route.middleware?.({ env, own: override.middleware }) ?? override.middleware,\n },\n })\n .to({ handler });\n }\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { z } from '@hono/zod-openapi';
2
+ import { type IStaticAssetRoute } from './context.js';
3
+ /** What an upload or a commit says about the MetaLink row: the row, or a code when only the row failed. */
4
+ export declare const MetaLinkOutcomeSchema: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
5
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
6
+ }, z.core.$strip>, z.ZodObject<{
7
+ error: z.ZodString;
8
+ }, z.core.$strip>]>>;
9
+ export declare const uploadRoute: IStaticAssetRoute;
10
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1,175 @@
1
+ import { z } from '@hono/zod-openapi';
2
+ import { BaseStorageHelper, RequestUtility, } from '@venizia/ignis-helpers';
3
+ import { HTTP } from '@venizia/ignis-helpers/common';
4
+ import { getError, UuidHelper } from '@venizia/ignis-helpers/core';
5
+ import { StaticAssetErrors, StaticAssetMetaLinkCodes, StaticAssetRouteKeys, } from '../../common/index.js';
6
+ import { StaticAssetKeyScopeUtility } from '../../utilities/key-scope.utility.js';
7
+ import { StaticAssetMetaLinkUtility } from '../../utilities/meta-link.utility.js';
8
+ import { StaticAssetRouteOptionsUtility } from '../../utilities/route-options.utility.js';
9
+ import { StaticAssetFeatures, StaticAssetRouteUtility, } from './context.js';
10
+ import { StaticAssetDefinition } from './definition.js';
11
+ import { StaticAssetLabelsUtility, UploadLabelsSchema } from './labels.js';
12
+ import { MetaLinkRowSchema } from './objects.js';
13
+ const MultipartBodySchema = z.object({
14
+ files: z.union([z.instanceof(File), z.array(z.instanceof(File))]).openapi({
15
+ type: 'array',
16
+ items: { type: 'string', format: 'binary' },
17
+ }),
18
+ ...UploadLabelsSchema.shape,
19
+ folderPath: z.string().optional().openapi({
20
+ description: 'Target folder path for uploaded files (e.g., "photos/2024")',
21
+ example: 'photos/2024',
22
+ }),
23
+ });
24
+ /** What an upload or a commit says about the MetaLink row: the row, or a code when only the row failed. */
25
+ export const MetaLinkOutcomeSchema = z
26
+ .union([z.object({ data: MetaLinkRowSchema }), z.object({ error: z.string() })])
27
+ .optional();
28
+ class StaticAssetUploadHandler {
29
+ /**
30
+ * Built per request: the hook is offered the bucket, which only the route knows. The default key is
31
+ * `<keyPrefix><folder>/<uuid>/<name>`. A hook's key is checked against the scope, never rewritten: the
32
+ * application may record that key elsewhere.
33
+ */
34
+ static buildNaming(opts) {
35
+ const { env, bucketName, objectKey } = opts;
36
+ const { helper, keyPrefix } = env;
37
+ return (naming) => {
38
+ // The component's own name: the original name must stay one segment.
39
+ if (!objectKey && !helper.isValidSegment({ segment: naming.file.originalName })) {
40
+ throw getError({ message: '[upload] Invalid original file name' });
41
+ }
42
+ // A uuid folder right before the name, as the direct upload has: two uploads of one name never overwrite each other, and the caller's folder still groups the keys.
43
+ const normalized = BaseStorageHelper.normalizeObjectName(naming);
44
+ const nameStart = normalized.lastIndexOf('/') + 1;
45
+ const defaultKey = `${keyPrefix ?? ''}${normalized.slice(0, nameStart)}${UuidHelper.getInstance().v4()}/${normalized.slice(nameStart)}`;
46
+ const key = objectKey
47
+ ? objectKey({ bucket: { name: bucketName }, file: naming.file, defaultKey })
48
+ : defaultKey;
49
+ if (!StaticAssetKeyScopeUtility.isInScope({ key, keyPrefix })) {
50
+ throw getError({
51
+ error: StaticAssetErrors.OBJECT_KEY_OUT_OF_SCOPE,
52
+ message: `Object key is outside the key prefix of this entry | key: ${key} | keyPrefix: ${keyPrefix}`,
53
+ });
54
+ }
55
+ return key;
56
+ };
57
+ }
58
+ static async recordMetaLinks(opts) {
59
+ const { env, uploaded, labels } = opts;
60
+ const { helper, metaLink } = env;
61
+ if (!metaLink) {
62
+ return uploaded;
63
+ }
64
+ const results = [];
65
+ for (const uploadResult of uploaded) {
66
+ try {
67
+ const fileStat = await helper.getStat({
68
+ bucket: uploadResult.bucket,
69
+ object: uploadResult.object,
70
+ });
71
+ const data = await StaticAssetMetaLinkUtility.createRow({
72
+ metaLink,
73
+ helper,
74
+ storage: env.storage,
75
+ uploadResult,
76
+ fileStat,
77
+ labels,
78
+ });
79
+ results.push({ ...uploadResult, metaLink: { data } });
80
+ }
81
+ catch (error) {
82
+ env.logger
83
+ .for('UPLOAD')
84
+ .error('Failed to create MetaLink | objectName: %s | Error: %s', uploadResult.object.key, error);
85
+ // A CODE, never the driver text: this 200 bypasses the error middleware that strips
86
+ // `detail`/`table`/`constraint`. The real error is logged in full above.
87
+ results.push({
88
+ ...uploadResult,
89
+ metaLink: { error: StaticAssetMetaLinkCodes.CREATE_FAILED },
90
+ });
91
+ }
92
+ }
93
+ return results;
94
+ }
95
+ static async handle(opts) {
96
+ const { ctx, env } = opts;
97
+ const serverUpload = StaticAssetRouteUtility.requireFeature({
98
+ value: env.serverUpload,
99
+ feature: StaticAssetFeatures.SERVER_UPLOAD,
100
+ });
101
+ const { bucket } = await StaticAssetRouteUtility.resolveTarget({ ctx, env });
102
+ const { files, fields } = await RequestUtility.parseMultipartBody({
103
+ context: ctx,
104
+ maxFiles: serverUpload.maxFiles,
105
+ });
106
+ const labels = StaticAssetLabelsUtility.parse({ fields });
107
+ const folderPath = fields.folderPath || undefined;
108
+ const uploadFiles = files.map((file) => {
109
+ const { buffer } = file;
110
+ if (!buffer?.length) {
111
+ throw getError({
112
+ error: StaticAssetErrors.FILE_EMPTY,
113
+ message: `Empty file content | name: ${file.originalname}`,
114
+ });
115
+ }
116
+ // Authoritative: `buffer.length`, not the client-declared `size`.
117
+ if (serverUpload.maxBytes !== undefined && buffer.length > serverUpload.maxBytes) {
118
+ throw getError({
119
+ error: StaticAssetErrors.UPLOAD_TOO_LARGE,
120
+ message: `File ${file.originalname} of ${buffer.length} bytes exceeds the maximum of ${serverUpload.maxBytes}`,
121
+ });
122
+ }
123
+ return {
124
+ originalName: file.originalname,
125
+ mimetype: file.mimetype,
126
+ buffer,
127
+ size: file.size,
128
+ encoding: file.encoding,
129
+ folderPath,
130
+ };
131
+ });
132
+ const uploaded = await env.helper.upload({
133
+ bucket,
134
+ files: uploadFiles,
135
+ normalizeNameFn: StaticAssetUploadHandler.buildNaming({
136
+ env,
137
+ bucketName: bucket.name,
138
+ objectKey: serverUpload.objectKey,
139
+ }),
140
+ normalizeLinkFn: env.link,
141
+ // The storage checks the caller's folders against `maxFolderDepth`, and the finished key, scope included, against the deeper bound.
142
+ maxFolderDepth: env.maxFolderDepth,
143
+ maxKeyDepth: env.objectKeyMaxDepth,
144
+ });
145
+ const results = await StaticAssetUploadHandler.recordMetaLinks({ env, uploaded, labels });
146
+ return ctx.json(results, HTTP.ResultCodes.RS_2.Ok);
147
+ }
148
+ }
149
+ export const uploadRoute = {
150
+ key: StaticAssetRouteKeys.UPLOAD,
151
+ feature: StaticAssetFeatures.SERVER_UPLOAD,
152
+ build: (env) => ({
153
+ config: StaticAssetDefinition.multipart({
154
+ method: HTTP.Methods.POST,
155
+ path: '/objects',
156
+ body: MultipartBodySchema,
157
+ response: z.array(z.object({
158
+ bucket: z.object({ name: z.string() }),
159
+ object: z.object({ key: z.string(), size: z.number(), contentType: z.string() }),
160
+ link: z.string(),
161
+ metaLink: MetaLinkOutcomeSchema,
162
+ })),
163
+ }),
164
+ handler: (ctx) => StaticAssetUploadHandler.handle({ ctx, env }),
165
+ }),
166
+ // The route's body validator reads the whole multipart body, so the body limit has to run before it.
167
+ middleware: ({ env, own }) => env.serverUpload?.maxBytes === undefined
168
+ ? own
169
+ : StaticAssetRouteOptionsUtility.appendBodyLimit({
170
+ middleware: own,
171
+ maxBytes: env.serverUpload.maxBytes,
172
+ maxFiles: env.serverUpload.maxFiles,
173
+ }),
174
+ };
175
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../../../../../src/components/static-asset/controller/routes/upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EACL,iBAAiB,EACjB,cAAc,GAIf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,oBAAoB,GAGrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EAGL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,M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AE,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;gBAChF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;gBAChB,QAAQ,EAAE,qBAAqB;aAChC,CAAC,CACH;SACF,CAAC;QACF,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;KAChE,CAAC;IACF,qGAAqG;IACrG,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,CAC3B,GAAG,CAAC,YAAY,EAAE,QAAQ,KAAK,SAAS;QACtC,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,8BAA8B,CAAC,eAAe,CAAC;YAC7C,UAAU,EAAE,GAAG;YACf,QAAQ,EAAE,GAAG,CAAC,YAAY,CAAC,QAAQ;YACnC,QAAQ,EAAE,GAAG,CAAC,YAAY,CAAC,QAAQ;SACpC,CAAC;CACT,CAAC","sourcesContent":["import type { TRouteContext } from '@/base/controllers';\nimport { z } from '@hono/zod-openapi';\nimport {\n BaseStorageHelper,\n RequestUtility,\n type IUploadFile,\n type IUploadResult,\n type TUploadNaming,\n} from '@venizia/ignis-helpers';\nimport { HTTP } from '@venizia/ignis-helpers/common';\nimport { getError, UuidHelper } from '@venizia/ignis-helpers/core';\nimport {\n StaticAssetErrors,\n StaticAssetMetaLinkCodes,\n StaticAssetRouteKeys,\n type TStaticAssetObjectKeyResolver,\n type TStaticAssetUploadLabels,\n} from '../../common';\nimport { StaticAssetKeyScopeUtility } from '../../utilities/key-scope.utility';\nimport { StaticAssetMetaLinkUtility } from '../../utilities/meta-link.utility';\nimport { StaticAssetRouteOptionsUtility } from '../../utilities/route-options.utility';\nimport {\n type IStaticAssetRoute,\n type IStaticAssetRouteEnv,\n StaticAssetFeatures,\n StaticAssetRouteUtility,\n} from './context';\nimport { StaticAssetDefinition } from './definition';\nimport { StaticAssetLabelsUtility, UploadLabelsSchema } from './labels';\nimport { MetaLinkRowSchema } from './objects';\n\nconst MultipartBodySchema = z.object({\n files: z.union([z.instanceof(File), z.array(z.instanceof(File))]).openapi({\n type: 'array',\n items: { type: 'string', format: 'binary' },\n }),\n ...UploadLabelsSchema.shape,\n folderPath: z.string().optional().openapi({\n description: 'Target folder path for uploaded files (e.g., \"photos/2024\")',\n example: 'photos/2024',\n }),\n});\n\n/** What an upload or a commit says about the MetaLink row: the row, or a code when only the row failed. */\nexport const MetaLinkOutcomeSchema = z\n .union([z.object({ data: MetaLinkRowSchema }), z.object({ error: z.string() })])\n .optional();\n\nclass StaticAssetUploadHandler {\n /**\n * Built per request: the hook is offered the bucket, which only the route knows. The default key is\n * `<keyPrefix><folder>/<uuid>/<name>`. A hook's key is checked against the scope, never rewritten: the\n * application may record that key elsewhere.\n */\n static buildNaming(opts: {\n env: IStaticAssetRouteEnv;\n bucketName: string;\n objectKey?: TStaticAssetObjectKeyResolver;\n }) {\n const { env, bucketName, objectKey } = opts;\n const { helper, keyPrefix } = env;\n\n return (naming: { file: TUploadNaming }) => {\n // The component's own name: the original name must stay one segment.\n if (!objectKey && !helper.isValidSegment({ segment: naming.file.originalName })) {\n throw getError({ message: '[upload] Invalid original file name' });\n }\n\n // A uuid folder right before the name, as the direct upload has: two uploads of one name never overwrite each other, and the caller's folder still groups the keys.\n const normalized = BaseStorageHelper.normalizeObjectName(naming);\n const nameStart = normalized.lastIndexOf('/') + 1;\n const defaultKey = `${keyPrefix ?? ''}${normalized.slice(0, nameStart)}${UuidHelper.getInstance().v4()}/${normalized.slice(nameStart)}`;\n const key = objectKey\n ? objectKey({ bucket: { name: bucketName }, file: naming.file, defaultKey })\n : defaultKey;\n\n if (!StaticAssetKeyScopeUtility.isInScope({ key, keyPrefix })) {\n throw getError({\n error: StaticAssetErrors.OBJECT_KEY_OUT_OF_SCOPE,\n message: `Object key is outside the key prefix of this entry | key: ${key} | keyPrefix: ${keyPrefix}`,\n });\n }\n\n return key;\n };\n }\n\n static async recordMetaLinks(opts: {\n env: IStaticAssetRouteEnv;\n uploaded: IUploadResult[];\n labels: TStaticAssetUploadLabels;\n }): Promise<IUploadResult[]> {\n const { env, uploaded, labels } = opts;\n const { helper, metaLink } = env;\n\n if (!metaLink) {\n return uploaded;\n }\n\n const results: IUploadResult[] = [];\n\n for (const uploadResult of uploaded) {\n try {\n const fileStat = await helper.getStat({\n bucket: uploadResult.bucket,\n object: uploadResult.object,\n });\n const data = await StaticAssetMetaLinkUtility.createRow({\n metaLink,\n helper,\n storage: env.storage,\n uploadResult,\n fileStat,\n labels,\n });\n\n results.push({ ...uploadResult, metaLink: { data } });\n } catch (error) {\n env.logger\n .for('UPLOAD')\n .error(\n 'Failed to create MetaLink | objectName: %s | Error: %s',\n uploadResult.object.key,\n error,\n );\n // A CODE, never the driver text: this 200 bypasses the error middleware that strips\n // `detail`/`table`/`constraint`. The real error is logged in full above.\n results.push({\n ...uploadResult,\n metaLink: { error: StaticAssetMetaLinkCodes.CREATE_FAILED },\n });\n }\n }\n\n return results;\n }\n\n static async handle(opts: { ctx: TRouteContext; env: IStaticAssetRouteEnv }) {\n const { ctx, env } = opts;\n const serverUpload = StaticAssetRouteUtility.requireFeature({\n value: env.serverUpload,\n feature: StaticAssetFeatures.SERVER_UPLOAD,\n });\n const { bucket } = await StaticAssetRouteUtility.resolveTarget({ ctx, env });\n\n const { files, fields } = await RequestUtility.parseMultipartBody({\n context: ctx,\n maxFiles: serverUpload.maxFiles,\n });\n const labels = StaticAssetLabelsUtility.parse({ fields });\n const folderPath = fields.folderPath || undefined;\n\n const uploadFiles: IUploadFile[] = files.map((file) => {\n const { buffer } = file;\n\n if (!buffer?.length) {\n throw getError({\n error: StaticAssetErrors.FILE_EMPTY,\n message: `Empty file content | name: ${file.originalname}`,\n });\n }\n\n // Authoritative: `buffer.length`, not the client-declared `size`.\n if (serverUpload.maxBytes !== undefined && buffer.length > serverUpload.maxBytes) {\n throw getError({\n error: StaticAssetErrors.UPLOAD_TOO_LARGE,\n message: `File ${file.originalname} of ${buffer.length} bytes exceeds the maximum of ${serverUpload.maxBytes}`,\n });\n }\n\n return {\n originalName: file.originalname,\n mimetype: file.mimetype,\n buffer,\n size: file.size,\n encoding: file.encoding,\n folderPath,\n };\n });\n\n const uploaded = await env.helper.upload({\n bucket,\n files: uploadFiles,\n normalizeNameFn: StaticAssetUploadHandler.buildNaming({\n env,\n bucketName: bucket.name,\n objectKey: serverUpload.objectKey,\n }),\n normalizeLinkFn: env.link,\n // The storage checks the caller's folders against `maxFolderDepth`, and the finished key, scope included, against the deeper bound.\n maxFolderDepth: env.maxFolderDepth,\n maxKeyDepth: env.objectKeyMaxDepth,\n });\n const results = await StaticAssetUploadHandler.recordMetaLinks({ env, uploaded, labels });\n\n return ctx.json(results, HTTP.ResultCodes.RS_2.Ok);\n }\n}\n\nexport const uploadRoute: IStaticAssetRoute = {\n key: StaticAssetRouteKeys.UPLOAD,\n feature: StaticAssetFeatures.SERVER_UPLOAD,\n build: (env) => ({\n config: StaticAssetDefinition.multipart({\n method: HTTP.Methods.POST,\n path: '/objects',\n body: MultipartBodySchema,\n response: z.array(\n z.object({\n bucket: z.object({ name: z.string() }),\n object: z.object({ key: z.string(), size: z.number(), contentType: z.string() }),\n link: z.string(),\n metaLink: MetaLinkOutcomeSchema,\n }),\n ),\n }),\n handler: (ctx) => StaticAssetUploadHandler.handle({ ctx, env }),\n }),\n // The route's body validator reads the whole multipart body, so the body limit has to run before it.\n middleware: ({ env, own }) =>\n env.serverUpload?.maxBytes === undefined\n ? own\n : StaticAssetRouteOptionsUtility.appendBodyLimit({\n middleware: own,\n maxBytes: env.serverUpload.maxBytes,\n maxFiles: env.serverUpload.maxFiles,\n }),\n};\n"]}
@@ -1,7 +1,8 @@
1
1
  export * from './common/index.js';
2
2
  export * from './component.js';
3
3
  export * from './controller/index.js';
4
+ export * from './services/index.js';
5
+ export * from './utilities/index.js';
4
6
  export * from './models/index.js';
5
7
  export * from './repositories/index.js';
6
- export * from './ingest.js';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,8 @@
1
1
  export * from './common/index.js';
2
2
  export * from './component.js';
3
3
  export * from './controller/index.js';
4
+ export * from './services/index.js';
5
+ export * from './utilities/index.js';
4
6
  export * from './models/index.js';
5
7
  export * from './repositories/index.js';
6
- export * from './ingest.js';
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/static-asset/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC","sourcesContent":["export * from './common';\nexport * from './component';\nexport * from './controller';\nexport * from './models';\nexport * from './repositories';\nexport * from './ingest';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/static-asset/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC","sourcesContent":["export * from './common';\nexport * from './component';\nexport * from './controller';\nexport * from './services';\nexport * from './utilities';\nexport * from './models';\nexport * from './repositories';\n"]}
@@ -112,7 +112,7 @@ export declare class BaseMetaLinkModel extends BaseRelationalEntity<typeof BaseM
112
112
  tableName: "MetaLink";
113
113
  dataType: "json";
114
114
  columnType: "PgJsonb";
115
- data: Record<string, any>;
115
+ data: Record<string, unknown>;
116
116
  driverParam: unknown;
117
117
  notNull: false;
118
118
  hasDefault: false;
@@ -124,7 +124,7 @@ export declare class BaseMetaLinkModel extends BaseRelationalEntity<typeof BaseM
124
124
  identity: undefined;
125
125
  generated: undefined;
126
126
  }, {}, {
127
- $type: Record<string, any>;
127
+ $type: Record<string, unknown>;
128
128
  }>;
129
129
  storageType: import("drizzle-orm/pg-core").PgColumn<{
130
130
  name: "storage_type";
@@ -391,7 +391,7 @@ export declare class BaseMetaLinkModel extends BaseRelationalEntity<typeof BaseM
391
391
  tableName: "MetaLink";
392
392
  dataType: "json";
393
393
  columnType: "PgJsonb";
394
- data: Record<string, any>;
394
+ data: Record<string, unknown>;
395
395
  driverParam: unknown;
396
396
  notNull: false;
397
397
  hasDefault: false;
@@ -403,7 +403,7 @@ export declare class BaseMetaLinkModel extends BaseRelationalEntity<typeof BaseM
403
403
  identity: undefined;
404
404
  generated: undefined;
405
405
  }, {}, {
406
- $type: Record<string, any>;
406
+ $type: Record<string, unknown>;
407
407
  }>;
408
408
  storageType: import("drizzle-orm/pg-core").PgColumn<{
409
409
  name: "storage_type";
@@ -1 +1 @@
1
- {"version":3,"file":"base.model.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/models/base.model.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,GAGnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEpF,mNAAmN;AAE5M,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,oBAAqD;aAC1E,WAAM,GAAG,OAAO,CAC9B,UAAU,EACV;QACE,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC;QACxE,GAAG,kBAAkB,CAAC,kBAAkB,EAAE;QAC1C,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;QACzC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO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EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;GACxB,iBAAiB,CAqC7B","sourcesContent":["import { model } from '@/base/metadata';\nimport {\n BaseRelationalEntity,\n PostgresIdEnricher,\n PostgresTzEnricher,\n type TTableObject,\n type TTableSchemaWithId,\n} from '@venizia/ignis-connectors/postgres';\nimport { boolean, index, integer, jsonb, pgTable, text } from 'drizzle-orm/pg-core';\n\n/** One row per (object, owner) pairing, NOT per object: one product image attached to the product and to each variant is the common case, so `(bucketName, objectName)` is indexed and deliberately NOT unique. */\n@model({ migration: { use: false } })\nexport class BaseMetaLinkModel extends BaseRelationalEntity<typeof BaseMetaLinkModel.schema> {\n static override schema = pgTable(\n 'MetaLink',\n {\n ...PostgresIdEnricher.generateColumnDefs({ id: { dataType: 'string' } }),\n ...PostgresTzEnricher.generateColumnDefs(),\n bucketName: text('bucket_name').notNull(),\n objectName: text('object_name').notNull(),\n link: text().notNull(),\n mimetype: text().notNull(),\n size: integer().notNull(),\n etag: text(),\n metadata: jsonb().$type<Record<string, any>>(),\n storageType: text('storage_type').notNull(),\n isSynced: boolean('is_synced').notNull().default(false),\n\n /** An opaque label the caller chooses - a size, a role, a rendition name. The component stores and returns it and reads no meaning into it. */\n variant: text(),\n\n /** Display order within ONE principal. Defaults to 0 so legacy rows tie and `ORDER BY sequence, createdAt` reproduces the order they already had. */\n sequence: integer().notNull().default(0),\n\n /** A polymorphic owner: the type names the table, the id the row. Both nullable - an object may belong to nothing yet, which is how `recreate-metalink` writes one. */\n principalType: text('principal_type'),\n principalId: text('principal_id'),\n },\n (def) => [\n index(`IDX_MetaLink_bucketName`).on(def.bucketName),\n index(`IDX_MetaLink_objectName`).on(def.objectName),\n index(`IDX_MetaLink_storageType`).on(def.storageType),\n index(`IDX_MetaLink_isSynced`).on(def.isSynced),\n // Ordering runs inside a principal filter, so filter columns lead and the sort column trails.\n index(`IDX_MetaLink_principal_sequence`).on(def.principalType, def.principalId, def.sequence),\n ],\n );\n\n static override relations = () => [];\n}\n\n/** The table schema of `BaseMetaLinkModel`. */\nexport type TMetaLinkSchema = typeof BaseMetaLinkModel.schema;\n/** A MetaLink row as selected from the table. */\nexport type TMetaLink = TTableObject<TMetaLinkSchema>;\n\n/** Any table whose row carries the MetaLink fields. The component reads and writes the ROW, so the table is free to carry another name or to live in another Postgres schema. */\nexport type TMetaLinkCompatibleSchema = TTableSchemaWithId & { $inferSelect: TMetaLink };\n"]}
1
+ {"version":3,"file":"base.model.js","sourceRoot":"","sources":["../../../../../src/components/static-asset/models/base.model.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,GAGnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEpF,mNAAmN;AAE5M,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,oBAAqD;aAC1E,WAAM,GAAG,OAAO,CAC9B,UAAU,EACV;QACE,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC;QACxE,GAAG,kBAAkB,CAAC,kBAAkB,EAAE;QAC1C,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;QACzC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;QACzC,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;QACtB,QAAQ,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE;QAC1B,IAAI,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE;QACzB,IAAI,EAAE,IAAI,EAAE;QACZ,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,EAA2B;QAClD,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;QAC3C,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QAEvD,+IAA+I;QAC/I,OAAO,EAAE,IAAI,EAAE;QAEf,qJAAqJ;QACrJ,QAAQ,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QAExC,uKAAuK;QACvK,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC;QACrC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC;KAClC,EACD,CAAC,GAAG,EAAE,EAAE,CAAC;QACP,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC;QACnD,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC;QACnD,KAAK,CAAC,0BAA0B,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC;QACrD,KAAK,CAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC/C,8FAA8F;QAC9F,KAAK,CAAC,iCAAiC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,QAAQ,CAAC;KAC9F,CACF,AAjCqB,CAiCpB;aAEc,cAAS,GAAG,GAAG,EAAE,CAAC,EAAE,AAAX,CAAY;;AApC1B,iBAAiB;IAD7B,KAAK,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC;GACxB,iBAAiB,CAqC7B","sourcesContent":["import { model } from '@/base/metadata';\nimport {\n BaseRelationalEntity,\n PostgresIdEnricher,\n PostgresTzEnricher,\n type TTableObject,\n type TTableSchemaWithId,\n} from '@venizia/ignis-connectors/postgres';\nimport { boolean, index, integer, jsonb, pgTable, text } from 'drizzle-orm/pg-core';\n\n/** One row per (object, owner) pairing, NOT per object: one product image attached to the product and to each variant is the common case, so `(bucketName, objectName)` is indexed and deliberately NOT unique. */\n@model({ migration: { use: false } })\nexport class BaseMetaLinkModel extends BaseRelationalEntity<typeof BaseMetaLinkModel.schema> {\n static override schema = pgTable(\n 'MetaLink',\n {\n ...PostgresIdEnricher.generateColumnDefs({ id: { dataType: 'string' } }),\n ...PostgresTzEnricher.generateColumnDefs(),\n bucketName: text('bucket_name').notNull(),\n objectName: text('object_name').notNull(),\n link: text().notNull(),\n mimetype: text().notNull(),\n size: integer().notNull(),\n etag: text(),\n metadata: jsonb().$type<Record<string, unknown>>(),\n storageType: text('storage_type').notNull(),\n isSynced: boolean('is_synced').notNull().default(false),\n\n /** An opaque label the caller chooses - a size, a role, a rendition name. The component stores and returns it and reads no meaning into it. */\n variant: text(),\n\n /** Display order within ONE principal. Defaults to 0 so legacy rows tie and `ORDER BY sequence, createdAt` reproduces the order they already had. */\n sequence: integer().notNull().default(0),\n\n /** A polymorphic owner: the type names the table, the id the row. Both nullable - an object may belong to nothing yet, which is how `recreate-metalink` writes one. */\n principalType: text('principal_type'),\n principalId: text('principal_id'),\n },\n (def) => [\n index(`IDX_MetaLink_bucketName`).on(def.bucketName),\n index(`IDX_MetaLink_objectName`).on(def.objectName),\n index(`IDX_MetaLink_storageType`).on(def.storageType),\n index(`IDX_MetaLink_isSynced`).on(def.isSynced),\n // Ordering runs inside a principal filter, so filter columns lead and the sort column trails.\n index(`IDX_MetaLink_principal_sequence`).on(def.principalType, def.principalId, def.sequence),\n ],\n );\n\n static override relations = () => [];\n}\n\n/** The table schema of `BaseMetaLinkModel`. */\nexport type TMetaLinkSchema = typeof BaseMetaLinkModel.schema;\n/** A MetaLink row as selected from the table. */\nexport type TMetaLink = TTableObject<TMetaLinkSchema>;\n\n/** Any table whose row carries the MetaLink fields. The component reads and writes the ROW, so the table is free to carry another name or to live in another Postgres schema. */\nexport type TMetaLinkCompatibleSchema = TTableSchemaWithId & { $inferSelect: TMetaLink };\n"]}
@@ -0,0 +1,103 @@
1
+ import type { z } from '@hono/zod-openapi';
2
+ import { type IBucketRef, type IObjectLocation, type IObjectRef, type IStorageHelper, type IUploadResult } from '@venizia/ignis-helpers';
3
+ import { type TValueOrAsyncResolver } from '@venizia/ignis-helpers/common';
4
+ import { BaseService } from '@venizia/ignis-kernel';
5
+ import type { IStaticAssetValidation, IStaticAssetValidateResult, TStaticAssetDirectUploadOptions, TMetaLinkConfig, TStaticAssetStorageType, TStaticAssetTokenMetadata, TStaticAssetUploadLabels } from '../common/index.js';
6
+ import type { TMetaLinkCompatibleSchema, TMetaLinkSchema } from '../models/index.js';
7
+ /** What a commit answers. `metaLink` is absent when the entry keeps no MetaLink table. */
8
+ export interface IStaticAssetCommitResult {
9
+ bucket: IBucketRef;
10
+ object: IObjectRef;
11
+ owner: string;
12
+ metadata: TStaticAssetTokenMetadata;
13
+ link: string;
14
+ metaLink?: IUploadResult['metaLink'];
15
+ }
16
+ /** `Schema` is the MetaLink table the application bound, the same type parameter the component carries. */
17
+ export interface IStaticAssetUploadCommitServiceOptions<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> {
18
+ /** Names the logger; the controller's own name is the usual value. */
19
+ scope: string;
20
+ helper: IStorageHelper;
21
+ /** The bucket the entry resolves; a token naming another is refused. */
22
+ bucket: TValueOrAsyncResolver<string>;
23
+ /** The entry's `keyPrefix` as configured; normalized here the way the controller does. */
24
+ keyPrefix: string;
25
+ /** Folders a final key may nest, the scope's own included. */
26
+ objectKeyMaxDepth: number;
27
+ directUpload: Pick<TStaticAssetDirectUploadOptions, 'secretKey' | 'pendingPrefix' | 'resolvers'> & {
28
+ /** Absent, every file is valid. */
29
+ validation?: IStaticAssetValidation<z.ZodType>;
30
+ };
31
+ storage: TStaticAssetStorageType;
32
+ metaLink?: TMetaLinkConfig<Schema>;
33
+ /** The link a commit returns for the committed object: the entry's own, so a commit and an upload agree. */
34
+ link: (opts: IObjectLocation) => string;
35
+ }
36
+ /**
37
+ * Moves a pending upload to its final key and records it: the body of the `upload-commit` route,
38
+ * callable without a request. A service that saves its own record commits the upload in the same
39
+ * call instead of asking the client for a second request.
40
+ *
41
+ * The token proves the key was issued by a policy, to one owner, with the metadata the application
42
+ * chose for the file. A commit is single-use: it refuses a destination that already holds an object.
43
+ */
44
+ export declare class StaticAssetUploadCommitService<Schema extends TMetaLinkCompatibleSchema = TMetaLinkSchema> extends BaseService {
45
+ private readonly options;
46
+ private readonly keyPrefix;
47
+ private readonly pendingPrefix;
48
+ private readonly policyKeyPrefix;
49
+ constructor(opts: IStaticAssetUploadCommitServiceOptions<Schema>);
50
+ /** The signature, the expiry, the owner, the bucket and the pending scope: the checks every stage of a token starts with. */
51
+ private readPayload;
52
+ /**
53
+ * Everything `commit` checks before it touches storage, and nothing else: the signature, the
54
+ * expiry, the owner, the bucket and the pending scope. Returns the PENDING object with the token's
55
+ * owner and metadata, with no storage call and no side effect, so an application can read an
56
+ * uploaded file and report its problems to the user before anything is committed.
57
+ *
58
+ * A token this refuses is refused the same way `commit` refuses it, and every refusal says no more
59
+ * than that the token is no good: a caller learns nothing about which keys exist.
60
+ */
61
+ verify(opts: {
62
+ token: string;
63
+ owner: string;
64
+ }): Promise<IObjectLocation & {
65
+ owner: string;
66
+ metadata: TStaticAssetTokenMetadata;
67
+ }>;
68
+ /**
69
+ * `verify`, then the application's own check of the pending file, read once through a file pinned
70
+ * to the content that is there now. A valid file answers the token `commit` takes: it is bound to
71
+ * that content and dies when the incoming token does. An invalid one answers its issues and no token.
72
+ * A token of either stage may be validated again, which pins whatever is there at that moment.
73
+ */
74
+ validate(opts: {
75
+ token: string;
76
+ owner: string;
77
+ }): Promise<IStaticAssetValidateResult<unknown>>;
78
+ private runValidation;
79
+ /**
80
+ * Moves the pending object to its final key and, when the entry keeps a MetaLink table, writes the
81
+ * row. With a `validation` on it takes the token `validate` returned and never runs the handler; the
82
+ * copy then happens only if the content still matches the pin. The final key is the default one
83
+ * unless `resolvers.commit.destination` names another; either way it must be free, so a token
84
+ * commits once. A MetaLink failure rides the result as a code: the object IS committed by then.
85
+ */
86
+ commit(opts: {
87
+ token: string;
88
+ /** Who is committing: a token commits only for the owner it was issued to. */
89
+ owner: string;
90
+ labels?: TStaticAssetUploadLabels;
91
+ /** The final key for this call. It wins over `resolvers.commit.destination` and passes the same checks. */
92
+ destination?: IObjectRef;
93
+ }): Promise<IStaticAssetCommitResult>;
94
+ /** The default key is the pending one without the pending prefix; the application's resolver may name another, inside the scope. */
95
+ private resolveDestination;
96
+ /** The caller's `destination`, else the resolver's, else none: the default key. */
97
+ private pickDestination;
98
+ /** The token's only commit: a second one, or a re-post to the pending key, must not overwrite what the first one stored. */
99
+ private assertDestinationFree;
100
+ /** A pin makes the copy conditional; a failed condition is a changed upload, and nothing is written. */
101
+ private copyPinned;
102
+ }
103
+ //# sourceMappingURL=commitment.service.d.ts.map