@sixthsummit/ship-api 0.0.0-stage → 4.1.1

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 (556) hide show
  1. package/CHANGELOG.md +605 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +4 -0
  4. package/README.md +58 -2
  5. package/cli/commands/add.js +537 -0
  6. package/cli/commands/contract.js +2 -0
  7. package/cli/commands/create.js +250 -0
  8. package/cli/commands/dev.js +227 -0
  9. package/cli/commands/doctor.js +286 -0
  10. package/cli/commands/generate.js +937 -0
  11. package/cli/commands/graph.js +2 -0
  12. package/cli/commands/migrate-orm.js +1171 -0
  13. package/cli/commands/update.js +37 -0
  14. package/cli/ship-api.js +285 -0
  15. package/lib/app/auth/AuthProvider.d.ts +91 -0
  16. package/lib/app/auth/AuthProvider.d.ts.map +1 -0
  17. package/lib/app/auth/AuthProvider.js +13 -0
  18. package/lib/app/auth/AuthProvider.js.map +1 -0
  19. package/lib/app/auth/adapters/firebase.d.ts +79 -0
  20. package/lib/app/auth/adapters/firebase.d.ts.map +1 -0
  21. package/lib/app/auth/adapters/firebase.js +122 -0
  22. package/lib/app/auth/adapters/firebase.js.map +1 -0
  23. package/lib/app/auth/adapters/jwtCookie.d.ts +55 -0
  24. package/lib/app/auth/adapters/jwtCookie.d.ts.map +1 -0
  25. package/lib/app/auth/adapters/jwtCookie.js +120 -0
  26. package/lib/app/auth/adapters/jwtCookie.js.map +1 -0
  27. package/lib/app/auth/index.d.ts +8 -0
  28. package/lib/app/auth/index.d.ts.map +1 -0
  29. package/lib/app/auth/index.js +7 -0
  30. package/lib/app/auth/index.js.map +1 -0
  31. package/lib/app/auth/jwt/AuthFlow.d.ts +94 -0
  32. package/lib/app/auth/jwt/AuthFlow.d.ts.map +1 -0
  33. package/lib/app/auth/jwt/AuthFlow.js +127 -0
  34. package/lib/app/auth/jwt/AuthFlow.js.map +1 -0
  35. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts +80 -0
  36. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts.map +1 -0
  37. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js +134 -0
  38. package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js.map +1 -0
  39. package/lib/app/auth/jwt/JwtSigner.d.ts +123 -0
  40. package/lib/app/auth/jwt/JwtSigner.d.ts.map +1 -0
  41. package/lib/app/auth/jwt/JwtSigner.js +118 -0
  42. package/lib/app/auth/jwt/JwtSigner.js.map +1 -0
  43. package/lib/app/auth/jwt/RefreshTokenStore.d.ts +97 -0
  44. package/lib/app/auth/jwt/RefreshTokenStore.d.ts.map +1 -0
  45. package/lib/app/auth/jwt/RefreshTokenStore.js +122 -0
  46. package/lib/app/auth/jwt/RefreshTokenStore.js.map +1 -0
  47. package/lib/app/auth/permissionDefinition.d.ts +20 -0
  48. package/lib/app/auth/permissionDefinition.d.ts.map +1 -0
  49. package/lib/app/auth/permissionDefinition.js +2 -0
  50. package/lib/app/auth/permissionDefinition.js.map +1 -0
  51. package/lib/app/context/RequestContext.d.ts +59 -0
  52. package/lib/app/context/RequestContext.d.ts.map +1 -0
  53. package/lib/app/context/RequestContext.js +25 -0
  54. package/lib/app/context/RequestContext.js.map +1 -0
  55. package/lib/app/db/QueryOptions.d.ts +82 -0
  56. package/lib/app/db/QueryOptions.d.ts.map +1 -0
  57. package/lib/app/db/QueryOptions.js +37 -0
  58. package/lib/app/db/QueryOptions.js.map +1 -0
  59. package/lib/app/db/baseFields.d.ts +60 -0
  60. package/lib/app/db/baseFields.d.ts.map +1 -0
  61. package/lib/app/db/baseFields.js +54 -0
  62. package/lib/app/db/baseFields.js.map +1 -0
  63. package/lib/app/db/buildWhere.d.ts +22 -0
  64. package/lib/app/db/buildWhere.d.ts.map +1 -0
  65. package/lib/app/db/buildWhere.js +75 -0
  66. package/lib/app/db/buildWhere.js.map +1 -0
  67. package/lib/app/db/client.d.ts +111 -0
  68. package/lib/app/db/client.d.ts.map +1 -0
  69. package/lib/app/db/client.js +99 -0
  70. package/lib/app/db/client.js.map +1 -0
  71. package/lib/app/db/tenantScoped.d.ts +59 -0
  72. package/lib/app/db/tenantScoped.d.ts.map +1 -0
  73. package/lib/app/db/tenantScoped.js +54 -0
  74. package/lib/app/db/tenantScoped.js.map +1 -0
  75. package/lib/app/db/transaction.d.ts +58 -0
  76. package/lib/app/db/transaction.d.ts.map +1 -0
  77. package/lib/app/db/transaction.js +106 -0
  78. package/lib/app/db/transaction.js.map +1 -0
  79. package/lib/app/health/HealthCheck.d.ts +121 -0
  80. package/lib/app/health/HealthCheck.d.ts.map +1 -0
  81. package/lib/app/health/HealthCheck.js +151 -0
  82. package/lib/app/health/HealthCheck.js.map +1 -0
  83. package/lib/app/health/redisHealthCheck.d.ts +14 -0
  84. package/lib/app/health/redisHealthCheck.d.ts.map +1 -0
  85. package/lib/app/health/redisHealthCheck.js +21 -0
  86. package/lib/app/health/redisHealthCheck.js.map +1 -0
  87. package/lib/app/lifecycle/Bootstrapper.d.ts +92 -0
  88. package/lib/app/lifecycle/Bootstrapper.d.ts.map +1 -0
  89. package/lib/app/lifecycle/Bootstrapper.js +99 -0
  90. package/lib/app/lifecycle/Bootstrapper.js.map +1 -0
  91. package/lib/app/registry/routes.d.ts +89 -0
  92. package/lib/app/registry/routes.d.ts.map +1 -0
  93. package/lib/app/registry/routes.js +72 -0
  94. package/lib/app/registry/routes.js.map +1 -0
  95. package/lib/app/services/DrizzleEntityService.d.ts +123 -0
  96. package/lib/app/services/DrizzleEntityService.d.ts.map +1 -0
  97. package/lib/app/services/DrizzleEntityService.js +342 -0
  98. package/lib/app/services/DrizzleEntityService.js.map +1 -0
  99. package/lib/app/services/RedisProvider.d.ts +52 -0
  100. package/lib/app/services/RedisProvider.d.ts.map +1 -0
  101. package/lib/app/services/RedisProvider.js +75 -0
  102. package/lib/app/services/RedisProvider.js.map +1 -0
  103. package/lib/app/services/cache/Cache.d.ts +70 -0
  104. package/lib/app/services/cache/Cache.d.ts.map +1 -0
  105. package/lib/app/services/cache/Cache.js +18 -0
  106. package/lib/app/services/cache/Cache.js.map +1 -0
  107. package/lib/app/services/cache/InMemoryCache.d.ts +35 -0
  108. package/lib/app/services/cache/InMemoryCache.d.ts.map +1 -0
  109. package/lib/app/services/cache/InMemoryCache.js +76 -0
  110. package/lib/app/services/cache/InMemoryCache.js.map +1 -0
  111. package/lib/app/services/cache/RedisCache.d.ts +99 -0
  112. package/lib/app/services/cache/RedisCache.d.ts.map +1 -0
  113. package/lib/app/services/cache/RedisCache.js +150 -0
  114. package/lib/app/services/cache/RedisCache.js.map +1 -0
  115. package/lib/app/services/cache/cached.d.ts +30 -0
  116. package/lib/app/services/cache/cached.d.ts.map +1 -0
  117. package/lib/app/services/cache/cached.js +38 -0
  118. package/lib/app/services/cache/cached.js.map +1 -0
  119. package/lib/app/services/cache/index.d.ts +5 -0
  120. package/lib/app/services/cache/index.d.ts.map +1 -0
  121. package/lib/app/services/cache/index.js +4 -0
  122. package/lib/app/services/cache/index.js.map +1 -0
  123. package/lib/app/services/cron/defineCron.d.ts +57 -0
  124. package/lib/app/services/cron/defineCron.d.ts.map +1 -0
  125. package/lib/app/services/cron/defineCron.js +15 -0
  126. package/lib/app/services/cron/defineCron.js.map +1 -0
  127. package/lib/app/services/cron/index.d.ts +2 -0
  128. package/lib/app/services/cron/index.d.ts.map +1 -0
  129. package/lib/app/services/cron/index.js +2 -0
  130. package/lib/app/services/cron/index.js.map +1 -0
  131. package/lib/app/services/hooks/LifecycleHooks.d.ts +61 -0
  132. package/lib/app/services/hooks/LifecycleHooks.d.ts.map +1 -0
  133. package/lib/app/services/hooks/LifecycleHooks.js +85 -0
  134. package/lib/app/services/hooks/LifecycleHooks.js.map +1 -0
  135. package/lib/app/services/jobs/JobsManager.d.ts +67 -0
  136. package/lib/app/services/jobs/JobsManager.d.ts.map +1 -0
  137. package/lib/app/services/jobs/JobsManager.js +121 -0
  138. package/lib/app/services/jobs/JobsManager.js.map +1 -0
  139. package/lib/app/services/jobs/bullBoard.d.ts +72 -0
  140. package/lib/app/services/jobs/bullBoard.d.ts.map +1 -0
  141. package/lib/app/services/jobs/bullBoard.js +96 -0
  142. package/lib/app/services/jobs/bullBoard.js.map +1 -0
  143. package/lib/app/services/jobs/defineJob.d.ts +81 -0
  144. package/lib/app/services/jobs/defineJob.d.ts.map +1 -0
  145. package/lib/app/services/jobs/defineJob.js +49 -0
  146. package/lib/app/services/jobs/defineJob.js.map +1 -0
  147. package/lib/app/services/jobs/index.d.ts +4 -0
  148. package/lib/app/services/jobs/index.d.ts.map +1 -0
  149. package/lib/app/services/jobs/index.js +4 -0
  150. package/lib/app/services/jobs/index.js.map +1 -0
  151. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts +23 -0
  152. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts.map +1 -0
  153. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js +51 -0
  154. package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js.map +1 -0
  155. package/lib/app/services/rateLimit/RateLimitBackend.d.ts +41 -0
  156. package/lib/app/services/rateLimit/RateLimitBackend.d.ts.map +1 -0
  157. package/lib/app/services/rateLimit/RateLimitBackend.js +19 -0
  158. package/lib/app/services/rateLimit/RateLimitBackend.js.map +1 -0
  159. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts +16 -0
  160. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts.map +1 -0
  161. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js +80 -0
  162. package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js.map +1 -0
  163. package/lib/app/services/rateLimit/index.d.ts +4 -0
  164. package/lib/app/services/rateLimit/index.d.ts.map +1 -0
  165. package/lib/app/services/rateLimit/index.js +3 -0
  166. package/lib/app/services/rateLimit/index.js.map +1 -0
  167. package/lib/app/services/storage/DiskStorageAdapter.d.ts +62 -0
  168. package/lib/app/services/storage/DiskStorageAdapter.d.ts.map +1 -0
  169. package/lib/app/services/storage/DiskStorageAdapter.js +295 -0
  170. package/lib/app/services/storage/DiskStorageAdapter.js.map +1 -0
  171. package/lib/app/services/storage/GCSStorageAdapter.d.ts +44 -0
  172. package/lib/app/services/storage/GCSStorageAdapter.d.ts.map +1 -0
  173. package/lib/app/services/storage/GCSStorageAdapter.js +133 -0
  174. package/lib/app/services/storage/GCSStorageAdapter.js.map +1 -0
  175. package/lib/app/services/storage/S3StorageAdapter.d.ts +57 -0
  176. package/lib/app/services/storage/S3StorageAdapter.d.ts.map +1 -0
  177. package/lib/app/services/storage/S3StorageAdapter.js +162 -0
  178. package/lib/app/services/storage/S3StorageAdapter.js.map +1 -0
  179. package/lib/app/services/storage/StorageService.d.ts +88 -0
  180. package/lib/app/services/storage/StorageService.d.ts.map +1 -0
  181. package/lib/app/services/storage/StorageService.js +18 -0
  182. package/lib/app/services/storage/StorageService.js.map +1 -0
  183. package/lib/app/services/storage/index.d.ts +5 -0
  184. package/lib/app/services/storage/index.d.ts.map +1 -0
  185. package/lib/app/services/storage/index.js +4 -0
  186. package/lib/app/services/storage/index.js.map +1 -0
  187. package/lib/app/utils/ContextValidators.d.ts +46 -0
  188. package/lib/app/utils/ContextValidators.d.ts.map +1 -0
  189. package/lib/app/utils/ContextValidators.js +81 -0
  190. package/lib/app/utils/ContextValidators.js.map +1 -0
  191. package/lib/app/utils/defineEnv.d.ts +80 -0
  192. package/lib/app/utils/defineEnv.d.ts.map +1 -0
  193. package/lib/app/utils/defineEnv.js +95 -0
  194. package/lib/app/utils/defineEnv.js.map +1 -0
  195. package/lib/client.d.ts +139 -0
  196. package/lib/client.d.ts.map +1 -0
  197. package/lib/client.js +98 -0
  198. package/lib/client.js.map +1 -0
  199. package/lib/contract/application.d.ts +3 -0
  200. package/lib/contract/application.d.ts.map +1 -0
  201. package/lib/contract/application.js +2 -0
  202. package/lib/contract/application.js.map +1 -0
  203. package/lib/contract/client.d.ts +3 -0
  204. package/lib/contract/client.d.ts.map +1 -0
  205. package/lib/contract/client.js +3 -0
  206. package/lib/contract/client.js.map +1 -0
  207. package/lib/contract/index.d.ts +3 -0
  208. package/lib/contract/index.d.ts.map +1 -0
  209. package/lib/contract/index.js +3 -0
  210. package/lib/contract/index.js.map +1 -0
  211. package/lib/contract/manifest.d.ts +3 -0
  212. package/lib/contract/manifest.d.ts.map +1 -0
  213. package/lib/contract/manifest.js +2 -0
  214. package/lib/contract/manifest.js.map +1 -0
  215. package/lib/contract/openapi.d.ts +3 -0
  216. package/lib/contract/openapi.d.ts.map +1 -0
  217. package/lib/contract/openapi.js +3 -0
  218. package/lib/contract/openapi.js.map +1 -0
  219. package/lib/contract/project.d.ts +3 -0
  220. package/lib/contract/project.d.ts.map +1 -0
  221. package/lib/contract/project.js +3 -0
  222. package/lib/contract/project.js.map +1 -0
  223. package/lib/contract/schema.d.ts +3 -0
  224. package/lib/contract/schema.d.ts.map +1 -0
  225. package/lib/contract/schema.js +3 -0
  226. package/lib/contract/schema.js.map +1 -0
  227. package/lib/drizzle/index.d.ts +3 -0
  228. package/lib/drizzle/index.d.ts.map +1 -0
  229. package/lib/drizzle/index.js +3 -0
  230. package/lib/drizzle/index.js.map +1 -0
  231. package/lib/hono/auth.d.ts +6 -0
  232. package/lib/hono/auth.d.ts.map +1 -0
  233. package/lib/hono/auth.js +54 -0
  234. package/lib/hono/auth.js.map +1 -0
  235. package/lib/hono/index.d.ts +4 -0
  236. package/lib/hono/index.d.ts.map +1 -0
  237. package/lib/hono/index.js +4 -0
  238. package/lib/hono/index.js.map +1 -0
  239. package/lib/http/app/createApp.d.ts +132 -0
  240. package/lib/http/app/createApp.d.ts.map +1 -0
  241. package/lib/http/app/createApp.js +215 -0
  242. package/lib/http/app/createApp.js.map +1 -0
  243. package/lib/http/app/devRoutes.d.ts +31 -0
  244. package/lib/http/app/devRoutes.d.ts.map +1 -0
  245. package/lib/http/app/devRoutes.js +145 -0
  246. package/lib/http/app/devRoutes.js.map +1 -0
  247. package/lib/http/app/errors.d.ts +45 -0
  248. package/lib/http/app/errors.d.ts.map +1 -0
  249. package/lib/http/app/errors.js +93 -0
  250. package/lib/http/app/errors.js.map +1 -0
  251. package/lib/http/app/health.d.ts +66 -0
  252. package/lib/http/app/health.d.ts.map +1 -0
  253. package/lib/http/app/health.js +104 -0
  254. package/lib/http/app/health.js.map +1 -0
  255. package/lib/http/errors/AppError.d.ts +10 -0
  256. package/lib/http/errors/AppError.d.ts.map +1 -0
  257. package/lib/http/errors/AppError.js +19 -0
  258. package/lib/http/errors/AppError.js.map +1 -0
  259. package/lib/http/errors/AuthenticationError.d.ts +8 -0
  260. package/lib/http/errors/AuthenticationError.d.ts.map +1 -0
  261. package/lib/http/errors/AuthenticationError.js +10 -0
  262. package/lib/http/errors/AuthenticationError.js.map +1 -0
  263. package/lib/http/errors/AuthorizationError.d.ts +8 -0
  264. package/lib/http/errors/AuthorizationError.d.ts.map +1 -0
  265. package/lib/http/errors/AuthorizationError.js +10 -0
  266. package/lib/http/errors/AuthorizationError.js.map +1 -0
  267. package/lib/http/errors/BadRequestError.d.ts +8 -0
  268. package/lib/http/errors/BadRequestError.d.ts.map +1 -0
  269. package/lib/http/errors/BadRequestError.js +10 -0
  270. package/lib/http/errors/BadRequestError.js.map +1 -0
  271. package/lib/http/errors/ConflictError.d.ts +8 -0
  272. package/lib/http/errors/ConflictError.d.ts.map +1 -0
  273. package/lib/http/errors/ConflictError.js +10 -0
  274. package/lib/http/errors/ConflictError.js.map +1 -0
  275. package/lib/http/errors/InternalServerError.d.ts +8 -0
  276. package/lib/http/errors/InternalServerError.d.ts.map +1 -0
  277. package/lib/http/errors/InternalServerError.js +10 -0
  278. package/lib/http/errors/InternalServerError.js.map +1 -0
  279. package/lib/http/errors/NotFoundError.d.ts +8 -0
  280. package/lib/http/errors/NotFoundError.d.ts.map +1 -0
  281. package/lib/http/errors/NotFoundError.js +10 -0
  282. package/lib/http/errors/NotFoundError.js.map +1 -0
  283. package/lib/http/errors/RateLimitError.d.ts +13 -0
  284. package/lib/http/errors/RateLimitError.d.ts.map +1 -0
  285. package/lib/http/errors/RateLimitError.js +16 -0
  286. package/lib/http/errors/RateLimitError.js.map +1 -0
  287. package/lib/http/errors/ServiceUnavailableError.d.ts +8 -0
  288. package/lib/http/errors/ServiceUnavailableError.d.ts.map +1 -0
  289. package/lib/http/errors/ServiceUnavailableError.js +10 -0
  290. package/lib/http/errors/ServiceUnavailableError.js.map +1 -0
  291. package/lib/http/errors/ValidationError.d.ts +9 -0
  292. package/lib/http/errors/ValidationError.d.ts.map +1 -0
  293. package/lib/http/errors/ValidationError.js +12 -0
  294. package/lib/http/errors/ValidationError.js.map +1 -0
  295. package/lib/http/errors/index.d.ts +11 -0
  296. package/lib/http/errors/index.d.ts.map +1 -0
  297. package/lib/http/errors/index.js +12 -0
  298. package/lib/http/errors/index.js.map +1 -0
  299. package/lib/http/middleware/apiKey.d.ts +9 -0
  300. package/lib/http/middleware/apiKey.d.ts.map +1 -0
  301. package/lib/http/middleware/apiKey.js +71 -0
  302. package/lib/http/middleware/apiKey.js.map +1 -0
  303. package/lib/http/middleware/csrf.d.ts +63 -0
  304. package/lib/http/middleware/csrf.d.ts.map +1 -0
  305. package/lib/http/middleware/csrf.js +169 -0
  306. package/lib/http/middleware/csrf.js.map +1 -0
  307. package/lib/http/middleware/httpLogger.d.ts +39 -0
  308. package/lib/http/middleware/httpLogger.d.ts.map +1 -0
  309. package/lib/http/middleware/httpLogger.js +118 -0
  310. package/lib/http/middleware/httpLogger.js.map +1 -0
  311. package/lib/http/middleware/idempotency.d.ts +48 -0
  312. package/lib/http/middleware/idempotency.d.ts.map +1 -0
  313. package/lib/http/middleware/idempotency.js +180 -0
  314. package/lib/http/middleware/idempotency.js.map +1 -0
  315. package/lib/http/middleware/rateLimit.d.ts +105 -0
  316. package/lib/http/middleware/rateLimit.d.ts.map +1 -0
  317. package/lib/http/middleware/rateLimit.js +84 -0
  318. package/lib/http/middleware/rateLimit.js.map +1 -0
  319. package/lib/http/middleware/requireAuth.d.ts +58 -0
  320. package/lib/http/middleware/requireAuth.d.ts.map +1 -0
  321. package/lib/http/middleware/requireAuth.js +63 -0
  322. package/lib/http/middleware/requireAuth.js.map +1 -0
  323. package/lib/http/middleware/requirePermission.d.ts +23 -0
  324. package/lib/http/middleware/requirePermission.d.ts.map +1 -0
  325. package/lib/http/middleware/requirePermission.js +50 -0
  326. package/lib/http/middleware/requirePermission.js.map +1 -0
  327. package/lib/http/middleware/resolveTenant.d.ts +41 -0
  328. package/lib/http/middleware/resolveTenant.d.ts.map +1 -0
  329. package/lib/http/middleware/resolveTenant.js +17 -0
  330. package/lib/http/middleware/resolveTenant.js.map +1 -0
  331. package/lib/http/streaming/sse.d.ts +31 -0
  332. package/lib/http/streaming/sse.d.ts.map +1 -0
  333. package/lib/http/streaming/sse.js +11 -0
  334. package/lib/http/streaming/sse.js.map +1 -0
  335. package/lib/http/streaming/streamLLM.d.ts +94 -0
  336. package/lib/http/streaming/streamLLM.d.ts.map +1 -0
  337. package/lib/http/streaming/streamLLM.js +94 -0
  338. package/lib/http/streaming/streamLLM.js.map +1 -0
  339. package/lib/http/utils/authCookies.d.ts +74 -0
  340. package/lib/http/utils/authCookies.d.ts.map +1 -0
  341. package/lib/http/utils/authCookies.js +102 -0
  342. package/lib/http/utils/authCookies.js.map +1 -0
  343. package/lib/http/utils/clientIp.d.ts +85 -0
  344. package/lib/http/utils/clientIp.d.ts.map +1 -0
  345. package/lib/http/utils/clientIp.js +249 -0
  346. package/lib/http/utils/clientIp.js.map +1 -0
  347. package/lib/http/utils/index.d.ts +4 -0
  348. package/lib/http/utils/index.d.ts.map +1 -0
  349. package/lib/http/utils/index.js +5 -0
  350. package/lib/http/utils/index.js.map +1 -0
  351. package/lib/http/utils/metaTags.d.ts +49 -0
  352. package/lib/http/utils/metaTags.d.ts.map +1 -0
  353. package/lib/http/utils/metaTags.js +32 -0
  354. package/lib/http/utils/metaTags.js.map +1 -0
  355. package/lib/http/utils/publicSuffix.d.ts +34 -0
  356. package/lib/http/utils/publicSuffix.d.ts.map +1 -0
  357. package/lib/http/utils/publicSuffix.js +276 -0
  358. package/lib/http/utils/publicSuffix.js.map +1 -0
  359. package/lib/http/utils/uploads.d.ts +92 -0
  360. package/lib/http/utils/uploads.d.ts.map +1 -0
  361. package/lib/http/utils/uploads.js +126 -0
  362. package/lib/http/utils/uploads.js.map +1 -0
  363. package/lib/http/utils/validate.d.ts +41 -0
  364. package/lib/http/utils/validate.d.ts.map +1 -0
  365. package/lib/http/utils/validate.js +55 -0
  366. package/lib/http/utils/validate.js.map +1 -0
  367. package/lib/http/utils/webhooks.d.ts +63 -0
  368. package/lib/http/utils/webhooks.d.ts.map +1 -0
  369. package/lib/http/utils/webhooks.js +133 -0
  370. package/lib/http/utils/webhooks.js.map +1 -0
  371. package/lib/http/ws/auth.d.ts +46 -0
  372. package/lib/http/ws/auth.d.ts.map +1 -0
  373. package/lib/http/ws/auth.js +123 -0
  374. package/lib/http/ws/auth.js.map +1 -0
  375. package/lib/index.d.ts +80 -0
  376. package/lib/index.d.ts.map +1 -0
  377. package/lib/index.js +61 -0
  378. package/lib/index.js.map +1 -0
  379. package/lib/kernel/index.d.ts +3 -0
  380. package/lib/kernel/index.d.ts.map +1 -0
  381. package/lib/kernel/index.js +3 -0
  382. package/lib/kernel/index.js.map +1 -0
  383. package/lib/libraries/.gitkeep +0 -0
  384. package/lib/libraries/ai/CHANGELOG.md +17 -0
  385. package/lib/libraries/ai/README.md +164 -0
  386. package/lib/libraries/ai/adapters/AnthropicAdapter.ts +382 -0
  387. package/lib/libraries/ai/adapters/LLMProvider.ts +76 -0
  388. package/lib/libraries/ai/adapters/OpenAIAdapter.ts +466 -0
  389. package/lib/libraries/ai/experimental/index.ts +20 -0
  390. package/lib/libraries/ai/index.ts +128 -0
  391. package/lib/libraries/ai/library.json +19 -0
  392. package/lib/libraries/ai/loop/agentLoop.ts +377 -0
  393. package/lib/libraries/ai/prompts/definePrompt.ts +0 -0
  394. package/lib/libraries/ai/rag/retrieveAndAnswer.ts +177 -0
  395. package/lib/libraries/ai/streaming/streamLLM.ts +94 -0
  396. package/lib/libraries/ai/structured/completeStructured.ts +143 -0
  397. package/lib/libraries/ai/tokens/Tokenizer.ts +216 -0
  398. package/lib/libraries/ai/tools/defineTool.ts +208 -0
  399. package/lib/libraries/ai/types.ts +260 -0
  400. package/lib/libraries/chunking/ChunkingService.ts +103 -0
  401. package/lib/libraries/chunking/README.md +104 -0
  402. package/lib/libraries/chunking/docs/api-reference.md +549 -0
  403. package/lib/libraries/chunking/docs/best-practices.md +321 -0
  404. package/lib/libraries/chunking/docs/code-organization.md +538 -0
  405. package/lib/libraries/chunking/docs/configuration.md +418 -0
  406. package/lib/libraries/chunking/docs/index.md +236 -0
  407. package/lib/libraries/chunking/docs/quick-start.md +298 -0
  408. package/lib/libraries/chunking/docs/strategies.md +407 -0
  409. package/lib/libraries/chunking/docs/summary.md +258 -0
  410. package/lib/libraries/chunking/docs/troubleshooting.md +527 -0
  411. package/lib/libraries/chunking/index.ts +17 -0
  412. package/lib/libraries/chunking/library.json +16 -0
  413. package/lib/libraries/chunking/strategies/ChunkingStrategy.ts +13 -0
  414. package/lib/libraries/chunking/strategies/FixedLengthChunkingStrategy.ts +88 -0
  415. package/lib/libraries/chunking/strategies/SemanticChunkingStrategy.ts +389 -0
  416. package/lib/libraries/chunking/strategies/SlidingWindowChunkingStrategy.ts +258 -0
  417. package/lib/libraries/chunking/types/index.ts +63 -0
  418. package/lib/libraries/email/EmailService.ts +591 -0
  419. package/lib/libraries/email/README.md +777 -0
  420. package/lib/libraries/email/TemplateRegistry.ts +148 -0
  421. package/lib/libraries/email/TemplateRenderer.ts +273 -0
  422. package/lib/libraries/email/index.ts +4 -0
  423. package/lib/libraries/email/initializeEmailService.ts +60 -0
  424. package/lib/libraries/email/library.json +12 -0
  425. package/lib/libraries/email/types/EmailAddress.ts +4 -0
  426. package/lib/libraries/email/types/EmailAttachment.ts +11 -0
  427. package/lib/libraries/email/types/EmailTag.ts +9 -0
  428. package/lib/libraries/email/types/EmailTemplate.ts +124 -0
  429. package/lib/libraries/email/types/SendBatchEmailsOptions.ts +9 -0
  430. package/lib/libraries/email/types/SendBatchEmailsResult.ts +9 -0
  431. package/lib/libraries/email/types/SendEmailOptions.ts +33 -0
  432. package/lib/libraries/email/types/SendEmailResult.ts +9 -0
  433. package/lib/libraries/email/types/index.ts +8 -0
  434. package/lib/libraries/weaviate/QueryBuilder.ts +292 -0
  435. package/lib/libraries/weaviate/README.md +284 -0
  436. package/lib/libraries/weaviate/Weaviate.ts +1419 -0
  437. package/lib/libraries/weaviate/WeaviateConfig.ts +268 -0
  438. package/lib/libraries/weaviate/docs/.gitkeep +1 -0
  439. package/lib/libraries/weaviate/docs/API_REFERENCE.md +1067 -0
  440. package/lib/libraries/weaviate/docs/CONFIGURATION.md +320 -0
  441. package/lib/libraries/weaviate/docs/ERROR_HANDLING.md +271 -0
  442. package/lib/libraries/weaviate/docs/MULTI_TENANCY.md +348 -0
  443. package/lib/libraries/weaviate/docs/PERFORMANCE.md +602 -0
  444. package/lib/libraries/weaviate/docs/PLUGIN_DEVELOPMENT.md +547 -0
  445. package/lib/libraries/weaviate/docs/QUICK_START.md +443 -0
  446. package/lib/libraries/weaviate/docs/README.md +269 -0
  447. package/lib/libraries/weaviate/docs/SCHEMA_GUIDE.md +630 -0
  448. package/lib/libraries/weaviate/docs/WEAVIATE_README.md +520 -0
  449. package/lib/libraries/weaviate/errors/WeaviateError.ts +92 -0
  450. package/lib/libraries/weaviate/errors/index.ts +1 -0
  451. package/lib/libraries/weaviate/index.ts +35 -0
  452. package/lib/libraries/weaviate/library.json +26 -0
  453. package/lib/libraries/weaviate/plugins/index.ts +2 -0
  454. package/lib/libraries/weaviate/schemas/SchemaRegistry.ts +284 -0
  455. package/lib/libraries/weaviate/schemas/index.ts +2 -0
  456. package/lib/libraries/weaviate/types/BM25SearchOptions.ts +9 -0
  457. package/lib/libraries/weaviate/types/ExtendedWeaviateClient.ts +7 -0
  458. package/lib/libraries/weaviate/types/HybridSearchOptions.ts +11 -0
  459. package/lib/libraries/weaviate/types/MultiTenancy.ts +81 -0
  460. package/lib/libraries/weaviate/types/Plugin.ts +17 -0
  461. package/lib/libraries/weaviate/types/SchemaConfig.ts +25 -0
  462. package/lib/libraries/weaviate/types/SearchMethod.ts +8 -0
  463. package/lib/libraries/weaviate/types/SearchOptions.ts +16 -0
  464. package/lib/libraries/weaviate/types/SearchRequest.ts +19 -0
  465. package/lib/libraries/weaviate/types/SearchResult.ts +16 -0
  466. package/lib/libraries/weaviate/types/SearchableField.ts +87 -0
  467. package/lib/libraries/weaviate/types/VectorIndexConfig.ts +19 -0
  468. package/lib/libraries/weaviate/types/VectorSearchOptions.ts +18 -0
  469. package/lib/libraries/weaviate/types/VectorizerConfig.ts +8 -0
  470. package/lib/libraries/weaviate/types/index.ts +29 -0
  471. package/lib/libraries/weaviate/utils/TenantContextManager.ts +94 -0
  472. package/lib/modules/accounts/index.ts +47 -0
  473. package/lib/modules/accounts/module.json +15 -0
  474. package/lib/modules/accounts/permissions.ts +33 -0
  475. package/lib/modules/accounts/routes.ts +200 -0
  476. package/lib/modules/accounts/schema.ts +219 -0
  477. package/lib/modules/accounts/services/AccountService.ts +44 -0
  478. package/lib/modules/accounts/validation/schemas.ts +70 -0
  479. package/lib/modules/oauth/adapters/GmailOAuthAdapter.ts +35 -0
  480. package/lib/modules/oauth/adapters/GoogleOAuthAdapter.ts +278 -0
  481. package/lib/modules/oauth/adapters/MicrosoftOAuthAdapter.ts +269 -0
  482. package/lib/modules/oauth/adapters/MockOAuthAdapter.ts +138 -0
  483. package/lib/modules/oauth/adapters/OAuthAdapter.ts +211 -0
  484. package/lib/modules/oauth/adapters/OAuthAdapterRegistry.ts +77 -0
  485. package/lib/modules/oauth/adapters/OutlookOAuthAdapter.ts +38 -0
  486. package/lib/modules/oauth/index.ts +79 -0
  487. package/lib/modules/oauth/module.json +23 -0
  488. package/lib/modules/oauth/permissions.ts +39 -0
  489. package/lib/modules/oauth/routes.ts +497 -0
  490. package/lib/modules/oauth/schema.ts +127 -0
  491. package/lib/modules/oauth/services/OAuthConnectionService.ts +147 -0
  492. package/lib/modules/oauth/state.ts +234 -0
  493. package/lib/modules/oauth/stateJtiCache.ts +85 -0
  494. package/lib/modules/oauth/verifyIdToken.ts +178 -0
  495. package/lib/modules/outbox/EventEmitter.ts +106 -0
  496. package/lib/modules/outbox/OutboxDrainer.ts +163 -0
  497. package/lib/modules/outbox/handlers/EventHandler.ts +115 -0
  498. package/lib/modules/outbox/index.ts +43 -0
  499. package/lib/modules/outbox/module.json +15 -0
  500. package/lib/modules/outbox/permissions.ts +36 -0
  501. package/lib/modules/outbox/routes.ts +219 -0
  502. package/lib/modules/outbox/schema.ts +207 -0
  503. package/lib/modules/outbox/services/OutboxEventService.ts +223 -0
  504. package/lib/observability/logger.d.ts +30 -0
  505. package/lib/observability/logger.d.ts.map +1 -0
  506. package/lib/observability/logger.js +110 -0
  507. package/lib/observability/logger.js.map +1 -0
  508. package/lib/observability/metrics.d.ts +3 -0
  509. package/lib/observability/metrics.d.ts.map +1 -0
  510. package/lib/observability/metrics.js +3 -0
  511. package/lib/observability/metrics.js.map +1 -0
  512. package/lib/observability/otel.d.ts +3 -0
  513. package/lib/observability/otel.d.ts.map +1 -0
  514. package/lib/observability/otel.js +3 -0
  515. package/lib/observability/otel.js.map +1 -0
  516. package/lib/observability/safeErrorFields.d.ts +14 -0
  517. package/lib/observability/safeErrorFields.d.ts.map +1 -0
  518. package/lib/observability/safeErrorFields.js +14 -0
  519. package/lib/observability/safeErrorFields.js.map +1 -0
  520. package/lib/observability/tracing.d.ts +3 -0
  521. package/lib/observability/tracing.d.ts.map +1 -0
  522. package/lib/observability/tracing.js +3 -0
  523. package/lib/observability/tracing.js.map +1 -0
  524. package/lib/package.json +4 -0
  525. package/lib/testing.d.ts +3 -0
  526. package/lib/testing.d.ts.map +1 -0
  527. package/lib/testing.js +3 -0
  528. package/lib/testing.js.map +1 -0
  529. package/package.json +193 -3
  530. package/templates/default/.claude/agents/qa-brief.md +106 -0
  531. package/templates/default/.claude/commands/sherpa-brief.md +23 -0
  532. package/templates/default/.cursor/rules/api.mdc +80 -0
  533. package/templates/default/.cursor/rules/commits.mdc +88 -0
  534. package/templates/default/.cursor/rules/security.mdc +92 -0
  535. package/templates/default/.cursor/rules/testing.mdc +123 -0
  536. package/templates/default/.cursor/rules/typescript.mdc +86 -0
  537. package/templates/default/.env.example +79 -0
  538. package/templates/default/.github/workflows/sherpa-brief.yml +180 -0
  539. package/templates/default/AGENTS.md +166 -0
  540. package/templates/default/CLAUDE.md +17 -0
  541. package/templates/default/README.md +97 -0
  542. package/templates/default/_gitignore +27 -0
  543. package/templates/default/docker-compose.yml +83 -0
  544. package/templates/default/drizzle.config.ts +34 -0
  545. package/templates/default/eslint.config.mjs +106 -0
  546. package/templates/default/package.json +57 -0
  547. package/templates/default/ship-api.config.ts +21 -0
  548. package/templates/default/src/client.ts +34 -0
  549. package/templates/default/src/config/modules.ts +23 -0
  550. package/templates/default/src/db/schema.ts +26 -0
  551. package/templates/default/src/environment.ts +81 -0
  552. package/templates/default/src/index.test.ts +53 -0
  553. package/templates/default/src/index.ts +11 -0
  554. package/templates/default/src/instrumentation.ts +13 -0
  555. package/templates/default/src/server.ts +90 -0
  556. package/templates/default/tsconfig.json +24 -0
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Symbol-keyed metadata tags that middleware factories attach to their
3
+ * returned `MiddlewareHandler` so `createApp` can pick them up at route-
4
+ * registration time and populate the route registry.
5
+ *
6
+ * Each tag has a stable type so the registry-extraction logic is type-safe.
7
+ * Symbol-keyed (rather than string-keyed) so consumer middleware can't
8
+ * accidentally collide with framework tags.
9
+ *
10
+ * Middleware that wants to be discoverable in the registry attaches the tag
11
+ * via `(handler as Tagged<...>)[SCHEMA_META] = { ... }` after construction.
12
+ * Code that reads tags uses `getMetaTag(handler, SCHEMA_META)` to safely
13
+ * extract the value.
14
+ */
15
+ import type { ZodType } from "zod";
16
+ export declare const SCHEMA_META: unique symbol;
17
+ export declare const AUTH_META: unique symbol;
18
+ export declare const PERMISSION_META: unique symbol;
19
+ export declare const RATE_LIMIT_META: unique symbol;
20
+ export declare const IDEMPOTENCY_META: unique symbol;
21
+ export interface SchemaMeta {
22
+ target: "json" | "query" | "param" | "header";
23
+ schema: ZodType;
24
+ description?: string;
25
+ example?: unknown;
26
+ }
27
+ export interface AuthMeta {
28
+ /** `false` when `requireAuth({ optional: true })` was used. */
29
+ required: boolean;
30
+ /** Provider name (`"firebase"`, `"clerk"`, etc.) for documentation/observability. */
31
+ providerName?: string;
32
+ }
33
+ export interface PermissionMeta {
34
+ permissions: string[];
35
+ }
36
+ export interface RateLimitMeta {
37
+ windowMs: number;
38
+ max: number;
39
+ scope?: string;
40
+ }
41
+ export interface IdempotencyMeta {
42
+ ttlSec: number;
43
+ scope?: string;
44
+ }
45
+ /** Type-safe getter for a tag on a middleware handler. */
46
+ export declare function getMetaTag<T>(handler: unknown, tag: symbol): T | undefined;
47
+ /** Type-safe setter — middleware factories use this to tag their result. */
48
+ export declare function setMetaTag<T>(handler: object, tag: symbol, value: T): void;
49
+ //# sourceMappingURL=metaTags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metaTags.d.ts","sourceRoot":"","sources":["../../../src/http/utils/metaTags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,eAAO,MAAM,WAAW,eAAqC,CAAC;AAC9D,eAAO,MAAM,SAAS,eAAmC,CAAC;AAC1D,eAAO,MAAM,eAAe,eAAyC,CAAC;AACtE,eAAO,MAAM,eAAe,eAAyC,CAAC;AACtE,eAAO,MAAM,gBAAgB,eAA0C,CAAC;AAExE,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC9C,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAC;IAClB,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAI1E;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAE1E"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Symbol-keyed metadata tags that middleware factories attach to their
3
+ * returned `MiddlewareHandler` so `createApp` can pick them up at route-
4
+ * registration time and populate the route registry.
5
+ *
6
+ * Each tag has a stable type so the registry-extraction logic is type-safe.
7
+ * Symbol-keyed (rather than string-keyed) so consumer middleware can't
8
+ * accidentally collide with framework tags.
9
+ *
10
+ * Middleware that wants to be discoverable in the registry attaches the tag
11
+ * via `(handler as Tagged<...>)[SCHEMA_META] = { ... }` after construction.
12
+ * Code that reads tags uses `getMetaTag(handler, SCHEMA_META)` to safely
13
+ * extract the value.
14
+ */
15
+ export const SCHEMA_META = Symbol.for("ship-api.schema-meta");
16
+ export const AUTH_META = Symbol.for("ship-api.auth-meta");
17
+ export const PERMISSION_META = Symbol.for("ship-api.permission-meta");
18
+ export const RATE_LIMIT_META = Symbol.for("ship-api.rate-limit-meta");
19
+ export const IDEMPOTENCY_META = Symbol.for("ship-api.idempotency-meta");
20
+ /** Type-safe getter for a tag on a middleware handler. */
21
+ export function getMetaTag(handler, tag) {
22
+ if (handler === null || handler === undefined)
23
+ return undefined;
24
+ if (typeof handler !== "function" && typeof handler !== "object")
25
+ return undefined;
26
+ return handler[tag];
27
+ }
28
+ /** Type-safe setter — middleware factories use this to tag their result. */
29
+ export function setMetaTag(handler, tag, value) {
30
+ handler[tag] = value;
31
+ }
32
+ //# sourceMappingURL=metaTags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metaTags.js","sourceRoot":"","sources":["../../../src/http/utils/metaTags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AA+BxE,0DAA0D;AAC1D,MAAM,UAAU,UAAU,CAAI,OAAgB,EAAE,GAAW;IACzD,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAChE,IAAI,OAAO,OAAO,KAAK,UAAU,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACnF,OAAQ,OAAyC,CAAC,GAAG,CAAC,CAAC;AACzD,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAI,OAAe,EAAE,GAAW,EAAE,KAAQ;IACjE,OAA6B,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `publicSuffix` — defensive eTLD table for cookie-domain validation.
3
+ *
4
+ * A *public suffix* (also called eTLD — "effective TLD") is the level
5
+ * at which independent organizations register subdomains. Setting a
6
+ * cookie `Domain` attribute on a public suffix leaks the cookie to
7
+ * every site registered under that suffix; browsers SHOULD reject it
8
+ * but historically did not, and tools / WAFs that proxy cookies don't
9
+ * always honor the rule.
10
+ *
11
+ * The defense is simple: refuse to set a cookie whose `domain`
12
+ * attribute *is* a known public suffix. `domain: ".com"` rejects;
13
+ * `domain: ".example.com"` accepts.
14
+ *
15
+ * Coverage in this table is **conservative**: it lists the gTLDs and
16
+ * common country-code patterns that real consumer apps interact with.
17
+ * It is not the full Mozilla PSL — that's ~10 000 entries and ships
18
+ * via `tldts` for adopters who want full coverage. Swapping in `tldts`
19
+ * is a one-commit follow-up under P1/P2 if maintenance proves painful.
20
+ * Exotic country TLDs not in this table receive permissive treatment
21
+ * (accepted) — the framework default of "no `domain` attribute set"
22
+ * remains the right secure default, and this validator only fires
23
+ * when the consumer explicitly overrides.
24
+ */
25
+ /**
26
+ * Test whether a cookie-domain configuration value would leak the
27
+ * cookie to every site under a public suffix. Returns `null` when
28
+ * the value is safe (or empty), otherwise an explanatory string the
29
+ * caller folds into the thrown error message.
30
+ */
31
+ export declare function checkCookieDomainAgainstPublicSuffix(domain: string | undefined): string | null;
32
+ /** Exposed for tests; do not depend on this outside the framework. */
33
+ export declare const _publicSuffixSet: ReadonlySet<string>;
34
+ //# sourceMappingURL=publicSuffix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicSuffix.d.ts","sourceRoot":"","sources":["../../../src/http/utils/publicSuffix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA4NH;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAgC9F;AAED,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,qBAAkB,CAAC"}
@@ -0,0 +1,276 @@
1
+ /**
2
+ * `publicSuffix` — defensive eTLD table for cookie-domain validation.
3
+ *
4
+ * A *public suffix* (also called eTLD — "effective TLD") is the level
5
+ * at which independent organizations register subdomains. Setting a
6
+ * cookie `Domain` attribute on a public suffix leaks the cookie to
7
+ * every site registered under that suffix; browsers SHOULD reject it
8
+ * but historically did not, and tools / WAFs that proxy cookies don't
9
+ * always honor the rule.
10
+ *
11
+ * The defense is simple: refuse to set a cookie whose `domain`
12
+ * attribute *is* a known public suffix. `domain: ".com"` rejects;
13
+ * `domain: ".example.com"` accepts.
14
+ *
15
+ * Coverage in this table is **conservative**: it lists the gTLDs and
16
+ * common country-code patterns that real consumer apps interact with.
17
+ * It is not the full Mozilla PSL — that's ~10 000 entries and ships
18
+ * via `tldts` for adopters who want full coverage. Swapping in `tldts`
19
+ * is a one-commit follow-up under P1/P2 if maintenance proves painful.
20
+ * Exotic country TLDs not in this table receive permissive treatment
21
+ * (accepted) — the framework default of "no `domain` attribute set"
22
+ * remains the right secure default, and this validator only fires
23
+ * when the consumer explicitly overrides.
24
+ */
25
+ const PUBLIC_SUFFIXES = new Set([
26
+ // ─── gTLDs (single label) ────────────────────────────────────────
27
+ "com",
28
+ "net",
29
+ "org",
30
+ "edu",
31
+ "gov",
32
+ "mil",
33
+ "int",
34
+ "info",
35
+ "biz",
36
+ "name",
37
+ "pro",
38
+ "cc",
39
+ "io",
40
+ "dev",
41
+ "ai",
42
+ "co",
43
+ "app",
44
+ "me",
45
+ "tv",
46
+ "xyz",
47
+ "tech",
48
+ "online",
49
+ "store",
50
+ "shop",
51
+ "site",
52
+ "top",
53
+ "live",
54
+ "world",
55
+ "today",
56
+ "news",
57
+ "social",
58
+ "digital",
59
+ "cloud",
60
+ "link",
61
+ "ly",
62
+ "to",
63
+ "nu",
64
+ "tk",
65
+ "team",
66
+ "studio",
67
+ "design",
68
+ "page",
69
+ "blog",
70
+ "host",
71
+ "space",
72
+ "fun",
73
+ "agency",
74
+ "club",
75
+ // ─── ccTLDs (single label, 2 letters — the common ones) ─────────
76
+ "us",
77
+ "uk",
78
+ "ca",
79
+ "au",
80
+ "nz",
81
+ "de",
82
+ "fr",
83
+ "es",
84
+ "it",
85
+ "nl",
86
+ "pl",
87
+ "ru",
88
+ "jp",
89
+ "cn",
90
+ "kr",
91
+ "hk",
92
+ "tw",
93
+ "sg",
94
+ "my",
95
+ "th",
96
+ "vn",
97
+ "ph",
98
+ "id",
99
+ "in",
100
+ "br",
101
+ "mx",
102
+ "ar",
103
+ "cl",
104
+ "pe",
105
+ "za",
106
+ "ng",
107
+ "eg",
108
+ "sa",
109
+ "ae",
110
+ "il",
111
+ "tr",
112
+ "gr",
113
+ "pt",
114
+ "ie",
115
+ "dk",
116
+ "no",
117
+ "se",
118
+ "fi",
119
+ "ch",
120
+ "at",
121
+ "be",
122
+ "cz",
123
+ "hu",
124
+ "ro",
125
+ "ua",
126
+ "bg",
127
+ "sk",
128
+ "si",
129
+ "hr",
130
+ "lt",
131
+ "lv",
132
+ "ee",
133
+ "is",
134
+ "lu",
135
+ "mt",
136
+ "cy",
137
+ "li",
138
+ "md",
139
+ "by",
140
+ "rs",
141
+ "ba",
142
+ "mk",
143
+ "al",
144
+ "ge",
145
+ "am",
146
+ "az",
147
+ "kz",
148
+ "uz",
149
+ "kg",
150
+ "ke",
151
+ "tz",
152
+ "ug",
153
+ "zw",
154
+ "ma",
155
+ "tn",
156
+ "dz",
157
+ // ─── Multi-label eTLDs (common public-registration patterns) ────
158
+ "co.uk",
159
+ "co.jp",
160
+ "co.kr",
161
+ "co.nz",
162
+ "co.za",
163
+ "co.in",
164
+ "co.id",
165
+ "co.il",
166
+ "co.th",
167
+ "co.ma",
168
+ "co.ke",
169
+ "co.ug",
170
+ "co.zw",
171
+ "co.tz",
172
+ "com.au",
173
+ "com.br",
174
+ "com.mx",
175
+ "com.ar",
176
+ "com.cn",
177
+ "com.hk",
178
+ "com.sg",
179
+ "com.my",
180
+ "com.ph",
181
+ "com.vn",
182
+ "com.tr",
183
+ "com.tw",
184
+ "com.pl",
185
+ "com.ua",
186
+ "com.ru",
187
+ "com.sa",
188
+ "com.ng",
189
+ "com.eg",
190
+ "com.pe",
191
+ "com.ec",
192
+ "com.uy",
193
+ "com.bo",
194
+ "com.py",
195
+ "com.gt",
196
+ "com.es",
197
+ "com.fr",
198
+ "ac.uk",
199
+ "gov.uk",
200
+ "org.uk",
201
+ "net.uk",
202
+ "sch.uk",
203
+ "mod.uk",
204
+ "plc.uk",
205
+ "ltd.uk",
206
+ "me.uk",
207
+ "ne.jp",
208
+ "or.jp",
209
+ "ad.jp",
210
+ "ac.jp",
211
+ "gov.jp",
212
+ "lg.jp",
213
+ "go.jp",
214
+ "gov.au",
215
+ "edu.au",
216
+ "org.au",
217
+ "asn.au",
218
+ "id.au",
219
+ "net.au",
220
+ "ac.nz",
221
+ "co.nz",
222
+ "gen.nz",
223
+ "geek.nz",
224
+ "kiwi.nz",
225
+ "maori.nz",
226
+ "net.nz",
227
+ "org.nz",
228
+ "school.nz",
229
+ "edu.cn",
230
+ "gov.cn",
231
+ "net.cn",
232
+ "org.cn",
233
+ "ac.cn",
234
+ "edu.hk",
235
+ "gov.hk",
236
+ "net.hk",
237
+ "org.hk",
238
+ "idv.hk",
239
+ ]);
240
+ /**
241
+ * Test whether a cookie-domain configuration value would leak the
242
+ * cookie to every site under a public suffix. Returns `null` when
243
+ * the value is safe (or empty), otherwise an explanatory string the
244
+ * caller folds into the thrown error message.
245
+ */
246
+ export function checkCookieDomainAgainstPublicSuffix(domain) {
247
+ if (domain == null)
248
+ return null;
249
+ const trimmed = domain.trim();
250
+ if (trimmed.length === 0)
251
+ return null;
252
+ // Strip a single leading dot — `.example.com` and `example.com`
253
+ // mean the same thing to modern browsers (the leading-dot syntax is
254
+ // legacy compatibility).
255
+ const noLeadingDot = trimmed.startsWith(".") ? trimmed.slice(1) : trimmed;
256
+ const noTrailingDot = noLeadingDot.endsWith(".") ? noLeadingDot.slice(0, -1) : noLeadingDot;
257
+ if (noTrailingDot.length === 0) {
258
+ return "empty domain after normalization";
259
+ }
260
+ const normalized = noTrailingDot.toLowerCase();
261
+ // Reject if the value is itself a known public suffix — applies to
262
+ // both single-label (`com`, `uk`) and multi-label (`co.uk`, `com.au`)
263
+ // entries. The "single dotless input is a host name" intuition only
264
+ // holds for hosts NOT in the eTLD set; common gTLDs and ccTLDs would
265
+ // otherwise sneak through.
266
+ if (PUBLIC_SUFFIXES.has(normalized)) {
267
+ return (`"${trimmed}" is a public suffix (eTLD). A cookie with this ` +
268
+ `Domain attribute would be sent to every site under it, allowing ` +
269
+ `cross-tenant session leakage. Use a more specific domain — e.g. ` +
270
+ `".your-org.${normalized}" or "tenant.your-org.${normalized}".`);
271
+ }
272
+ return null;
273
+ }
274
+ /** Exposed for tests; do not depend on this outside the framework. */
275
+ export const _publicSuffixSet = PUBLIC_SUFFIXES;
276
+ //# sourceMappingURL=publicSuffix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publicSuffix.js","sourceRoot":"","sources":["../../../src/http/utils/publicSuffix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,oEAAoE;IACpE,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,QAAQ;IACR,OAAO;IACP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CAAC;IAEtC,gEAAgE;IAChE,oEAAoE;IACpE,yBAAyB;IACzB,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC1E,MAAM,aAAa,GAAG,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IAE5F,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,kCAAkC,CAAC;IAC5C,CAAC;IAED,MAAM,UAAU,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAE/C,mEAAmE;IACnE,sEAAsE;IACtE,oEAAoE;IACpE,qEAAqE;IACrE,2BAA2B;IAC3B,IAAI,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QACpC,OAAO,CACL,IAAI,OAAO,kDAAkD;YAC7D,kEAAkE;YAClE,kEAAkE;YAClE,cAAc,UAAU,yBAAyB,UAAU,IAAI,CAChE,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC"}
@@ -0,0 +1,92 @@
1
+ import type { Context } from "hono";
2
+ import { type ZodType, z } from "zod";
3
+ /**
4
+ * `parseUpload(c, schema)` — Web-Standards file-upload helper.
5
+ *
6
+ * Replaces v3's Multer integration. Reads `c.req.parseBody({ all: true })`,
7
+ * validates against a Zod schema, returns the typed result. File fields
8
+ * use `fileSchema({ maxBytes, mimeTypes })` (below) which validates size
9
+ * and MIME via *magic bytes* (not the upload's claimed Content-Type — that
10
+ * can be spoofed).
11
+ *
12
+ * **Memory model — be honest**: Hono's `parseBody()` reads the entire
13
+ * multipart body into memory before this function returns, capped by
14
+ * `app.use(bodyLimit({ maxSize: ... }))` if applied (default Hono is
15
+ * effectively unbounded — *always* configure a body limit for upload
16
+ * routes). For true streaming uploads, drop down to
17
+ * `c.req.raw.body` (a `ReadableStream`) and pipe directly to S3/GCS/disk.
18
+ *
19
+ * Usage:
20
+ * ```ts
21
+ * import { z } from "zod";
22
+ * import { parseUpload, fileSchema } from "@sixthsummit/ship-api/http/utils/uploads";
23
+ *
24
+ * const schema = z.object({
25
+ * avatar: fileSchema({ maxBytes: 5_000_000, mimeTypes: ["image/png", "image/jpeg"] }),
26
+ * description: z.string().max(500),
27
+ * });
28
+ *
29
+ * app.post("/profile", requireAuth({ provider }), async (c) => {
30
+ * const body = await parseUpload(c, schema);
31
+ * await storage.put(`avatars/${user.id}`, body.avatar);
32
+ * await profileService.update(user.id, { description: body.description });
33
+ * return c.json({ ok: true });
34
+ * });
35
+ * ```
36
+ *
37
+ * Validation errors throw `ValidationError` (mapped by `registerErrorHandlers`
38
+ * to 400), preserving the AppError taxonomy.
39
+ */
40
+ export declare function parseUpload<S extends ZodType>(c: Context, schema: S): Promise<z.infer<S>>;
41
+ export interface FileSchemaOptions {
42
+ /** Maximum file size in bytes. Files larger than this fail validation. */
43
+ maxBytes?: number;
44
+ /**
45
+ * Permitted MIME types validated via magic bytes (NOT the client-supplied
46
+ * Content-Type — that's trivially spoofable). Validation uses the
47
+ * `file-type` package. If omitted, MIME is not checked.
48
+ */
49
+ mimeTypes?: readonly string[];
50
+ /**
51
+ * Optional override for the magic-byte detector. Defaults to
52
+ * `file-type`'s `fileTypeFromBuffer`. Useful for tests or to plug in a
53
+ * stricter / different detector.
54
+ */
55
+ detectMime?: (file: File) => Promise<string | undefined>;
56
+ /**
57
+ * **F20 — explicit replacement for `allowUndetectedMime`.** When the
58
+ * magic-byte detector returns `undefined` (the file's bytes don't
59
+ * match any known type), skip the `mimeTypes` allowlist check and
60
+ * accept the file. Same behavior as the legacy `allowUndetectedMime`
61
+ * but the name spells out the permissive semantics — adopters
62
+ * reading "skip MIME validation for undetected files" can't
63
+ * mistake it for "validate everything defensively."
64
+ *
65
+ * Default `false` (fail closed). Set `true` when accepting CSV /
66
+ * JSON / generic binary blobs that lack distinctive magic bytes.
67
+ */
68
+ skipMimeValidationForUndetected?: boolean;
69
+ /**
70
+ * **F20 — default-deny escalation.** When `true`, reject any file
71
+ * whose magic bytes can't be classified, *regardless of whether
72
+ * `mimeTypes` is set*. Without this, a `parseUpload` call with no
73
+ * `mimeTypes` allowlist accepts everything — including files with
74
+ * no detectable signature that an attacker could pass off as
75
+ * legitimate text-but-aren't payloads (SVG-XSS staging, etc.).
76
+ * Default `false` for backwards compatibility.
77
+ */
78
+ requireDetectableMime?: boolean;
79
+ /**
80
+ * @deprecated since v4.0.0-alpha.4 (F20). Renamed to
81
+ * `skipMimeValidationForUndetected` for explicit semantics. Setting
82
+ * this still works for one minor cycle but emits a one-time
83
+ * `console.warn`. Will be removed in v4.1.0.
84
+ */
85
+ allowUndetectedMime?: boolean;
86
+ }
87
+ export declare function fileSchema(opts?: FileSchemaOptions): ZodType<File>;
88
+ /** Exposed for tests; do not depend on this outside the framework. */
89
+ export declare const _F20Internals: {
90
+ emittedDeprecationWarnings: Set<string>;
91
+ };
92
+ //# sourceMappingURL=uploads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../../../src/http/utils/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,KAAK,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,wBAAsB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAW/F;AAMD,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACzD;;;;;;;;;;;OAWG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAC;IAC1C;;;;;;;;OAQG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AA0BD,wBAAgB,UAAU,CAAC,IAAI,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyDtE;AAED,sEAAsE;AACtE,eAAO,MAAM,aAAa;;CAAiC,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { z } from "zod";
2
+ import { ValidationError } from "../errors/ValidationError.js";
3
+ /**
4
+ * `parseUpload(c, schema)` — Web-Standards file-upload helper.
5
+ *
6
+ * Replaces v3's Multer integration. Reads `c.req.parseBody({ all: true })`,
7
+ * validates against a Zod schema, returns the typed result. File fields
8
+ * use `fileSchema({ maxBytes, mimeTypes })` (below) which validates size
9
+ * and MIME via *magic bytes* (not the upload's claimed Content-Type — that
10
+ * can be spoofed).
11
+ *
12
+ * **Memory model — be honest**: Hono's `parseBody()` reads the entire
13
+ * multipart body into memory before this function returns, capped by
14
+ * `app.use(bodyLimit({ maxSize: ... }))` if applied (default Hono is
15
+ * effectively unbounded — *always* configure a body limit for upload
16
+ * routes). For true streaming uploads, drop down to
17
+ * `c.req.raw.body` (a `ReadableStream`) and pipe directly to S3/GCS/disk.
18
+ *
19
+ * Usage:
20
+ * ```ts
21
+ * import { z } from "zod";
22
+ * import { parseUpload, fileSchema } from "@sixthsummit/ship-api/http/utils/uploads";
23
+ *
24
+ * const schema = z.object({
25
+ * avatar: fileSchema({ maxBytes: 5_000_000, mimeTypes: ["image/png", "image/jpeg"] }),
26
+ * description: z.string().max(500),
27
+ * });
28
+ *
29
+ * app.post("/profile", requireAuth({ provider }), async (c) => {
30
+ * const body = await parseUpload(c, schema);
31
+ * await storage.put(`avatars/${user.id}`, body.avatar);
32
+ * await profileService.update(user.id, { description: body.description });
33
+ * return c.json({ ok: true });
34
+ * });
35
+ * ```
36
+ *
37
+ * Validation errors throw `ValidationError` (mapped by `registerErrorHandlers`
38
+ * to 400), preserving the AppError taxonomy.
39
+ */
40
+ export async function parseUpload(c, schema) {
41
+ // `parseBody({ all: true })` is required for fields with multiple values
42
+ // (an upload field with multiple files surfaces as `string | File | (string | File)[]`).
43
+ const raw = await c.req.parseBody({ all: true });
44
+ const result = await schema.safeParseAsync(raw);
45
+ if (!result.success) {
46
+ const first = result.error.issues[0];
47
+ const path = first?.path?.length ? first.path.join(".") : "upload";
48
+ throw new ValidationError(`${path}: ${first?.message ?? "Invalid upload"}`);
49
+ }
50
+ return result.data;
51
+ }
52
+ async function defaultDetectMime(file) {
53
+ // file-type's recommended buffer size is 4100 bytes; the package only
54
+ // looks at the leading bytes for its signatures. Slicing avoids reading
55
+ // the whole file when only the head matters.
56
+ const head = await file.slice(0, 4100).arrayBuffer();
57
+ const { fileTypeFromBuffer } = await import("file-type");
58
+ const result = await fileTypeFromBuffer(new Uint8Array(head));
59
+ return result?.mime;
60
+ }
61
+ /**
62
+ * Tracks deprecation warnings emitted in the current process so the
63
+ * one-time `console.warn` (F20) doesn't spam logs on a hot upload
64
+ * path. Module-level set — wide enough scope to survive multiple
65
+ * `fileSchema` constructions, narrow enough to reset per process.
66
+ */
67
+ const emittedDeprecationWarnings = new Set();
68
+ function warnDeprecatedOnce(key, message) {
69
+ if (emittedDeprecationWarnings.has(key))
70
+ return;
71
+ emittedDeprecationWarnings.add(key);
72
+ console.warn(`[ship-api/uploads] deprecation: ${message}`);
73
+ }
74
+ export function fileSchema(opts = {}) {
75
+ // F20: resolve the rename + deprecation. Either explicit option wins;
76
+ // the legacy `allowUndetectedMime` still works for one minor cycle.
77
+ const skipForUndetected = opts.skipMimeValidationForUndetected ?? opts.allowUndetectedMime ?? false;
78
+ if (opts.allowUndetectedMime !== undefined) {
79
+ warnDeprecatedOnce("allowUndetectedMime", "`allowUndetectedMime` is deprecated — rename to " +
80
+ "`skipMimeValidationForUndetected` (same semantics, clearer name). " +
81
+ "The old name will be removed in v4.1.0.");
82
+ }
83
+ const requireDetectable = opts.requireDetectableMime ?? false;
84
+ return z
85
+ .instanceof(File, { message: "Expected an uploaded file" })
86
+ .superRefine(async (file, ctx) => {
87
+ if (opts.maxBytes !== undefined && file.size > opts.maxBytes) {
88
+ ctx.addIssue({
89
+ code: "custom",
90
+ message: `File exceeds maximum size of ${opts.maxBytes} bytes (got ${file.size})`,
91
+ });
92
+ return;
93
+ }
94
+ const detected = await (opts.detectMime ?? defaultDetectMime)(file);
95
+ // F20: explicit default-deny escalation. Fires regardless of
96
+ // whether `mimeTypes` is set, so a no-allowlist `parseUpload`
97
+ // can still reject magic-byte-undetectable files.
98
+ if (requireDetectable && !detected) {
99
+ ctx.addIssue({
100
+ code: "custom",
101
+ message: "File magic bytes could not be classified (requireDetectableMime: true)",
102
+ });
103
+ return;
104
+ }
105
+ if (opts.mimeTypes && opts.mimeTypes.length > 0) {
106
+ if (!detected) {
107
+ if (!skipForUndetected) {
108
+ ctx.addIssue({
109
+ code: "custom",
110
+ message: "Could not determine file type from contents",
111
+ });
112
+ }
113
+ return;
114
+ }
115
+ if (!opts.mimeTypes.includes(detected)) {
116
+ ctx.addIssue({
117
+ code: "custom",
118
+ message: `MIME type "${detected}" not allowed (permitted: ${opts.mimeTypes.join(", ")})`,
119
+ });
120
+ }
121
+ }
122
+ });
123
+ }
124
+ /** Exposed for tests; do not depend on this outside the framework. */
125
+ export const _F20Internals = { emittedDeprecationWarnings };
126
+ //# sourceMappingURL=uploads.js.map
@@ -0,0 +1 @@
1
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