@package-broker/core 0.17.4 → 0.19.7

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 (346) hide show
  1. package/dist/cache/index.d.ts +0 -1
  2. package/dist/cache/index.d.ts.map +1 -1
  3. package/dist/cache/index.js +0 -1
  4. package/dist/cache/index.js.map +1 -1
  5. package/dist/cache/memory-driver.d.ts +1 -1
  6. package/dist/cache/memory-driver.d.ts.map +1 -1
  7. package/dist/cache/memory-driver.js +4 -2
  8. package/dist/cache/memory-driver.js.map +1 -1
  9. package/dist/db/create-database.d.ts +8 -0
  10. package/dist/db/create-database.d.ts.map +1 -0
  11. package/dist/db/create-database.js +13 -0
  12. package/dist/db/create-database.js.map +1 -0
  13. package/dist/db/index.d.ts +0 -1
  14. package/dist/db/index.d.ts.map +1 -1
  15. package/dist/db/index.js +0 -1
  16. package/dist/db/index.js.map +1 -1
  17. package/dist/db/schema.d.ts +557 -0
  18. package/dist/db/schema.d.ts.map +1 -1
  19. package/dist/db/schema.js +72 -2
  20. package/dist/db/schema.js.map +1 -1
  21. package/dist/factory.d.ts.map +1 -1
  22. package/dist/factory.js +22 -2
  23. package/dist/factory.js.map +1 -1
  24. package/dist/index.d.ts +2 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/jobs/processor.d.ts.map +1 -1
  29. package/dist/jobs/processor.js +16 -6
  30. package/dist/jobs/processor.js.map +1 -1
  31. package/dist/kernel/container.d.ts +12 -0
  32. package/dist/kernel/container.d.ts.map +1 -0
  33. package/dist/kernel/container.js +43 -0
  34. package/dist/kernel/container.js.map +1 -0
  35. package/dist/kernel/events.d.ts +17 -0
  36. package/dist/kernel/events.d.ts.map +1 -0
  37. package/dist/kernel/events.js +54 -0
  38. package/dist/kernel/events.js.map +1 -0
  39. package/dist/kernel/hooks.d.ts +14 -0
  40. package/dist/kernel/hooks.d.ts.map +1 -0
  41. package/dist/kernel/hooks.js +31 -0
  42. package/dist/kernel/hooks.js.map +1 -0
  43. package/dist/kernel/index.d.ts +5 -0
  44. package/dist/kernel/index.d.ts.map +1 -0
  45. package/dist/kernel/index.js +5 -0
  46. package/dist/kernel/index.js.map +1 -0
  47. package/dist/kernel/plugin.d.ts +21 -0
  48. package/dist/kernel/plugin.d.ts.map +1 -0
  49. package/dist/kernel/plugin.js +30 -0
  50. package/dist/kernel/plugin.js.map +1 -0
  51. package/dist/middleware/auth.d.ts +2 -0
  52. package/dist/middleware/auth.d.ts.map +1 -1
  53. package/dist/middleware/auth.js +20 -5
  54. package/dist/middleware/auth.js.map +1 -1
  55. package/dist/modules/admin/admin.handlers.d.ts +1 -1
  56. package/dist/modules/admin/admin.handlers.d.ts.map +1 -1
  57. package/dist/modules/artifacts/artifacts.handlers.d.ts +1 -1
  58. package/dist/modules/artifacts/artifacts.handlers.d.ts.map +1 -1
  59. package/dist/modules/auth/auth.handlers.js +1 -1
  60. package/dist/modules/auth/auth.handlers.js.map +1 -1
  61. package/dist/modules/composer/index.d.ts.map +1 -1
  62. package/dist/modules/composer/index.js +5 -0
  63. package/dist/modules/composer/index.js.map +1 -1
  64. package/dist/modules/composer/tenant-composer.d.ts +32 -0
  65. package/dist/modules/composer/tenant-composer.d.ts.map +1 -0
  66. package/dist/modules/composer/tenant-composer.js +198 -0
  67. package/dist/modules/composer/tenant-composer.js.map +1 -0
  68. package/dist/modules/import/import.handlers.d.ts +4 -0
  69. package/dist/modules/import/import.handlers.d.ts.map +1 -0
  70. package/dist/modules/import/import.handlers.js +16 -0
  71. package/dist/modules/import/import.handlers.js.map +1 -0
  72. package/dist/{routes/api/openapi/settings.d.ts → modules/import/import.routes.d.ts} +20 -35
  73. package/dist/modules/import/import.routes.d.ts.map +1 -0
  74. package/dist/modules/import/import.routes.js +63 -0
  75. package/dist/modules/import/import.routes.js.map +1 -0
  76. package/dist/modules/import/index.d.ts +8 -0
  77. package/dist/modules/import/index.d.ts.map +1 -0
  78. package/dist/modules/import/index.js +8 -0
  79. package/dist/modules/import/index.js.map +1 -0
  80. package/dist/modules/organizations/index.d.ts +8 -0
  81. package/dist/modules/organizations/index.d.ts.map +1 -0
  82. package/dist/modules/organizations/index.js +22 -0
  83. package/dist/modules/organizations/index.js.map +1 -0
  84. package/dist/modules/organizations/organizations.handlers.d.ts +24 -0
  85. package/dist/modules/organizations/organizations.handlers.d.ts.map +1 -0
  86. package/dist/modules/organizations/organizations.handlers.js +278 -0
  87. package/dist/modules/organizations/organizations.handlers.js.map +1 -0
  88. package/dist/modules/organizations/organizations.routes.d.ts +596 -0
  89. package/dist/modules/organizations/organizations.routes.d.ts.map +1 -0
  90. package/dist/modules/organizations/organizations.routes.js +263 -0
  91. package/dist/modules/organizations/organizations.routes.js.map +1 -0
  92. package/dist/modules/packages/packages.handlers.d.ts +1 -1
  93. package/dist/modules/packages/packages.handlers.d.ts.map +1 -1
  94. package/dist/modules/packages/packages.handlers.js +3 -69
  95. package/dist/modules/packages/packages.handlers.js.map +1 -1
  96. package/dist/modules/repositories/repositories.handlers.d.ts +1 -1
  97. package/dist/modules/repositories/repositories.handlers.d.ts.map +1 -1
  98. package/dist/modules/repositories/repositories.handlers.js +74 -3
  99. package/dist/modules/repositories/repositories.handlers.js.map +1 -1
  100. package/dist/modules/repositories/repositories.routes.d.ts +12 -0
  101. package/dist/modules/repositories/repositories.routes.d.ts.map +1 -1
  102. package/dist/modules/system/index.d.ts.map +1 -1
  103. package/dist/modules/system/index.js +2 -1
  104. package/dist/modules/system/index.js.map +1 -1
  105. package/dist/modules/system/system.handlers.d.ts +11 -1
  106. package/dist/modules/system/system.handlers.d.ts.map +1 -1
  107. package/dist/modules/system/system.handlers.js +31 -1
  108. package/dist/modules/system/system.handlers.js.map +1 -1
  109. package/dist/modules/system/system.routes.d.ts +34 -4
  110. package/dist/modules/system/system.routes.d.ts.map +1 -1
  111. package/dist/modules/system/system.routes.js +21 -1
  112. package/dist/modules/system/system.routes.js.map +1 -1
  113. package/dist/modules/tenants/index.d.ts +8 -0
  114. package/dist/modules/tenants/index.d.ts.map +1 -0
  115. package/dist/modules/tenants/index.js +21 -0
  116. package/dist/modules/tenants/index.js.map +1 -0
  117. package/dist/modules/tenants/tenants.handlers.d.ts +24 -0
  118. package/dist/modules/tenants/tenants.handlers.d.ts.map +1 -0
  119. package/dist/modules/tenants/tenants.handlers.js +268 -0
  120. package/dist/modules/tenants/tenants.handlers.js.map +1 -0
  121. package/dist/modules/tenants/tenants.routes.d.ts +486 -0
  122. package/dist/modules/tenants/tenants.routes.d.ts.map +1 -0
  123. package/dist/modules/tenants/tenants.routes.js +227 -0
  124. package/dist/modules/tenants/tenants.routes.js.map +1 -0
  125. package/dist/modules/tokens/tokens.handlers.d.ts +1 -1
  126. package/dist/modules/tokens/tokens.handlers.d.ts.map +1 -1
  127. package/dist/modules/users/users.handlers.d.ts +1 -1
  128. package/dist/modules/users/users.handlers.d.ts.map +1 -1
  129. package/dist/modules/users/users.handlers.js +1 -1
  130. package/dist/modules/users/users.handlers.js.map +1 -1
  131. package/dist/plugins/security-advisories/advisory-db.d.ts +85 -0
  132. package/dist/plugins/security-advisories/advisory-db.d.ts.map +1 -0
  133. package/dist/plugins/security-advisories/advisory-db.js +161 -0
  134. package/dist/plugins/security-advisories/advisory-db.js.map +1 -0
  135. package/dist/plugins/security-advisories/advisory-service.d.ts +44 -0
  136. package/dist/plugins/security-advisories/advisory-service.d.ts.map +1 -0
  137. package/dist/plugins/security-advisories/advisory-service.js +122 -0
  138. package/dist/plugins/security-advisories/advisory-service.js.map +1 -0
  139. package/dist/plugins/security-advisories/advisory.handlers.d.ts +13 -0
  140. package/dist/plugins/security-advisories/advisory.handlers.d.ts.map +1 -0
  141. package/dist/plugins/security-advisories/advisory.handlers.js +87 -0
  142. package/dist/plugins/security-advisories/advisory.handlers.js.map +1 -0
  143. package/dist/plugins/security-advisories/advisory.module.d.ts +4 -0
  144. package/dist/plugins/security-advisories/advisory.module.d.ts.map +1 -0
  145. package/dist/plugins/security-advisories/advisory.module.js +13 -0
  146. package/dist/plugins/security-advisories/advisory.module.js.map +1 -0
  147. package/dist/plugins/security-advisories/advisory.routes.d.ts +73 -0
  148. package/dist/plugins/security-advisories/advisory.routes.d.ts.map +1 -0
  149. package/dist/plugins/security-advisories/advisory.routes.js +76 -0
  150. package/dist/plugins/security-advisories/advisory.routes.js.map +1 -0
  151. package/dist/plugins/security-advisories/index.d.ts +31 -0
  152. package/dist/plugins/security-advisories/index.d.ts.map +1 -0
  153. package/dist/plugins/security-advisories/index.js +100 -0
  154. package/dist/plugins/security-advisories/index.js.map +1 -0
  155. package/dist/ports.d.ts +39 -21
  156. package/dist/ports.d.ts.map +1 -1
  157. package/dist/queue/consumer.d.ts +0 -8
  158. package/dist/queue/consumer.d.ts.map +1 -1
  159. package/dist/queue/consumer.js +2 -23
  160. package/dist/queue/consumer.js.map +1 -1
  161. package/dist/queue/index.d.ts +2 -0
  162. package/dist/queue/index.d.ts.map +1 -1
  163. package/dist/queue/index.js +2 -0
  164. package/dist/queue/index.js.map +1 -1
  165. package/dist/queue/memory-driver.d.ts +3 -2
  166. package/dist/queue/memory-driver.d.ts.map +1 -1
  167. package/dist/queue/memory-driver.js.map +1 -1
  168. package/dist/routes/composer.d.ts +7 -1
  169. package/dist/routes/composer.d.ts.map +1 -1
  170. package/dist/routes/composer.js +172 -70
  171. package/dist/routes/composer.js.map +1 -1
  172. package/dist/routes/dist.d.ts.map +1 -1
  173. package/dist/routes/dist.js +26 -80
  174. package/dist/routes/dist.js.map +1 -1
  175. package/dist/routes/index.d.ts +0 -1
  176. package/dist/routes/index.d.ts.map +1 -1
  177. package/dist/routes/index.js +0 -1
  178. package/dist/routes/index.js.map +1 -1
  179. package/dist/routes/package-revalidation.d.ts +38 -0
  180. package/dist/routes/package-revalidation.d.ts.map +1 -0
  181. package/dist/routes/package-revalidation.js +66 -0
  182. package/dist/routes/package-revalidation.js.map +1 -0
  183. package/dist/services/GitHubOrgImporter.d.ts +21 -0
  184. package/dist/services/GitHubOrgImporter.d.ts.map +1 -0
  185. package/dist/services/GitHubOrgImporter.js +51 -0
  186. package/dist/services/GitHubOrgImporter.js.map +1 -0
  187. package/dist/services/TokenScopeService.d.ts +15 -0
  188. package/dist/services/TokenScopeService.d.ts.map +1 -0
  189. package/dist/services/TokenScopeService.js +42 -0
  190. package/dist/services/TokenScopeService.js.map +1 -0
  191. package/dist/storage/index.d.ts +0 -1
  192. package/dist/storage/index.d.ts.map +1 -1
  193. package/dist/storage/index.js +0 -1
  194. package/dist/storage/index.js.map +1 -1
  195. package/dist/sync/repository-sync.d.ts.map +1 -1
  196. package/dist/sync/repository-sync.js +35 -23
  197. package/dist/sync/repository-sync.js.map +1 -1
  198. package/dist/sync/strategies/git-ssh.d.ts +17 -0
  199. package/dist/sync/strategies/git-ssh.d.ts.map +1 -0
  200. package/dist/sync/strategies/git-ssh.js +325 -0
  201. package/dist/sync/strategies/git-ssh.js.map +1 -0
  202. package/dist/{routes/api/types.d.ts → types/openapi.d.ts} +3 -4
  203. package/dist/types/openapi.d.ts.map +1 -0
  204. package/dist/{routes/api/types.js → types/openapi.js} +1 -1
  205. package/dist/types/openapi.js.map +1 -0
  206. package/dist/utils/background.d.ts +7 -0
  207. package/dist/utils/background.d.ts.map +1 -0
  208. package/dist/utils/background.js +11 -0
  209. package/dist/utils/background.js.map +1 -0
  210. package/dist/utils/environment.d.ts +15 -0
  211. package/dist/utils/environment.d.ts.map +1 -0
  212. package/dist/utils/environment.js +38 -0
  213. package/dist/utils/environment.js.map +1 -0
  214. package/dist/utils/index.d.ts +1 -0
  215. package/dist/utils/index.d.ts.map +1 -1
  216. package/dist/utils/index.js +1 -0
  217. package/dist/utils/index.js.map +1 -1
  218. package/dist/utils/package-filter.d.ts +7 -0
  219. package/dist/utils/package-filter.d.ts.map +1 -0
  220. package/dist/utils/package-filter.js +23 -0
  221. package/dist/utils/package-filter.js.map +1 -0
  222. package/dist/utils/package-validator.d.ts +3 -3
  223. package/dist/utils/package-validator.d.ts.map +1 -1
  224. package/dist/utils/package-validator.js +4 -37
  225. package/dist/utils/package-validator.js.map +1 -1
  226. package/dist/utils/upstream-fetch.d.ts +18 -0
  227. package/dist/utils/upstream-fetch.d.ts.map +1 -1
  228. package/dist/utils/upstream-fetch.js +76 -5
  229. package/dist/utils/upstream-fetch.js.map +1 -1
  230. package/dist/utils/zip-utils.d.ts +13 -0
  231. package/dist/utils/zip-utils.d.ts.map +1 -0
  232. package/dist/utils/zip-utils.js +66 -0
  233. package/dist/utils/zip-utils.js.map +1 -0
  234. package/dist/vcs/bitbucket-provider.d.ts +19 -0
  235. package/dist/vcs/bitbucket-provider.d.ts.map +1 -0
  236. package/dist/vcs/bitbucket-provider.js +249 -0
  237. package/dist/vcs/bitbucket-provider.js.map +1 -0
  238. package/dist/vcs/github-provider.d.ts +16 -0
  239. package/dist/vcs/github-provider.d.ts.map +1 -0
  240. package/dist/vcs/github-provider.js +117 -0
  241. package/dist/vcs/github-provider.js.map +1 -0
  242. package/dist/vcs/gitlab-provider.d.ts +17 -0
  243. package/dist/vcs/gitlab-provider.d.ts.map +1 -0
  244. package/dist/vcs/gitlab-provider.js +216 -0
  245. package/dist/vcs/gitlab-provider.js.map +1 -0
  246. package/dist/vcs/index.d.ts +10 -0
  247. package/dist/vcs/index.d.ts.map +1 -0
  248. package/dist/vcs/index.js +24 -0
  249. package/dist/vcs/index.js.map +1 -0
  250. package/dist/vcs/registry.d.ts +32 -0
  251. package/dist/vcs/registry.d.ts.map +1 -0
  252. package/dist/vcs/registry.js +47 -0
  253. package/dist/vcs/registry.js.map +1 -0
  254. package/dist/workflows/package-storage.d.ts.map +1 -1
  255. package/dist/workflows/package-storage.js +3 -3
  256. package/dist/workflows/package-storage.js.map +1 -1
  257. package/package.json +11 -8
  258. package/dist/cache/kv-driver.d.ts +0 -16
  259. package/dist/cache/kv-driver.d.ts.map +0 -1
  260. package/dist/cache/kv-driver.js +0 -23
  261. package/dist/cache/kv-driver.js.map +0 -1
  262. package/dist/db/d1-driver.d.ts +0 -3
  263. package/dist/db/d1-driver.d.ts.map +0 -1
  264. package/dist/db/d1-driver.js +0 -7
  265. package/dist/db/d1-driver.js.map +0 -1
  266. package/dist/routes/api/artifacts.d.ts +0 -27
  267. package/dist/routes/api/artifacts.d.ts.map +0 -1
  268. package/dist/routes/api/artifacts.js +0 -57
  269. package/dist/routes/api/artifacts.js.map +0 -1
  270. package/dist/routes/api/auth.d.ts +0 -52
  271. package/dist/routes/api/auth.d.ts.map +0 -1
  272. package/dist/routes/api/auth.js +0 -277
  273. package/dist/routes/api/auth.js.map +0 -1
  274. package/dist/routes/api/index.d.ts +0 -10
  275. package/dist/routes/api/index.d.ts.map +0 -1
  276. package/dist/routes/api/index.js +0 -11
  277. package/dist/routes/api/index.js.map +0 -1
  278. package/dist/routes/api/openapi/artifacts.d.ts +0 -80
  279. package/dist/routes/api/openapi/artifacts.d.ts.map +0 -1
  280. package/dist/routes/api/openapi/artifacts.js +0 -73
  281. package/dist/routes/api/openapi/artifacts.js.map +0 -1
  282. package/dist/routes/api/openapi/auth.d.ts +0 -187
  283. package/dist/routes/api/openapi/auth.d.ts.map +0 -1
  284. package/dist/routes/api/openapi/auth.js +0 -135
  285. package/dist/routes/api/openapi/auth.js.map +0 -1
  286. package/dist/routes/api/openapi/health.d.ts +0 -23
  287. package/dist/routes/api/openapi/health.d.ts.map +0 -1
  288. package/dist/routes/api/openapi/health.js +0 -25
  289. package/dist/routes/api/openapi/health.js.map +0 -1
  290. package/dist/routes/api/openapi/index.d.ts +0 -10
  291. package/dist/routes/api/openapi/index.d.ts.map +0 -1
  292. package/dist/routes/api/openapi/index.js +0 -16
  293. package/dist/routes/api/openapi/index.js.map +0 -1
  294. package/dist/routes/api/openapi/packages.d.ts +0 -172
  295. package/dist/routes/api/openapi/packages.d.ts.map +0 -1
  296. package/dist/routes/api/openapi/packages.js +0 -126
  297. package/dist/routes/api/openapi/packages.js.map +0 -1
  298. package/dist/routes/api/openapi/repositories.d.ts +0 -451
  299. package/dist/routes/api/openapi/repositories.d.ts.map +0 -1
  300. package/dist/routes/api/openapi/repositories.js +0 -238
  301. package/dist/routes/api/openapi/repositories.js.map +0 -1
  302. package/dist/routes/api/openapi/settings.d.ts.map +0 -1
  303. package/dist/routes/api/openapi/settings.js +0 -72
  304. package/dist/routes/api/openapi/settings.js.map +0 -1
  305. package/dist/routes/api/openapi/stats.d.ts +0 -59
  306. package/dist/routes/api/openapi/stats.d.ts.map +0 -1
  307. package/dist/routes/api/openapi/stats.js +0 -53
  308. package/dist/routes/api/openapi/stats.js.map +0 -1
  309. package/dist/routes/api/openapi/tokens.d.ts +0 -202
  310. package/dist/routes/api/openapi/tokens.d.ts.map +0 -1
  311. package/dist/routes/api/openapi/tokens.js +0 -132
  312. package/dist/routes/api/openapi/tokens.js.map +0 -1
  313. package/dist/routes/api/openapi/users.d.ts +0 -190
  314. package/dist/routes/api/openapi/users.d.ts.map +0 -1
  315. package/dist/routes/api/openapi/users.js +0 -126
  316. package/dist/routes/api/openapi/users.js.map +0 -1
  317. package/dist/routes/api/packages.d.ts +0 -50
  318. package/dist/routes/api/packages.d.ts.map +0 -1
  319. package/dist/routes/api/packages.js +0 -708
  320. package/dist/routes/api/packages.js.map +0 -1
  321. package/dist/routes/api/repositories.d.ts +0 -58
  322. package/dist/routes/api/repositories.d.ts.map +0 -1
  323. package/dist/routes/api/repositories.js +0 -321
  324. package/dist/routes/api/repositories.js.map +0 -1
  325. package/dist/routes/api/settings.d.ts +0 -29
  326. package/dist/routes/api/settings.d.ts.map +0 -1
  327. package/dist/routes/api/settings.js +0 -81
  328. package/dist/routes/api/settings.js.map +0 -1
  329. package/dist/routes/api/stats.d.ts +0 -21
  330. package/dist/routes/api/stats.d.ts.map +0 -1
  331. package/dist/routes/api/stats.js +0 -51
  332. package/dist/routes/api/stats.js.map +0 -1
  333. package/dist/routes/api/tokens.d.ts +0 -40
  334. package/dist/routes/api/tokens.d.ts.map +0 -1
  335. package/dist/routes/api/tokens.js +0 -187
  336. package/dist/routes/api/tokens.js.map +0 -1
  337. package/dist/routes/api/types.d.ts.map +0 -1
  338. package/dist/routes/api/types.js.map +0 -1
  339. package/dist/routes/api/users.d.ts +0 -6
  340. package/dist/routes/api/users.d.ts.map +0 -1
  341. package/dist/routes/api/users.js +0 -115
  342. package/dist/routes/api/users.js.map +0 -1
  343. package/dist/storage/r2-driver.d.ts +0 -16
  344. package/dist/storage/r2-driver.d.ts.map +0 -1
  345. package/dist/storage/r2-driver.js +0 -28
  346. package/dist/storage/r2-driver.js.map +0 -1
@@ -1,708 +0,0 @@
1
- // Packages API routes
2
- import { packages, artifacts, repositories } from '../../db/schema';
3
- import { eq, like, and } from 'drizzle-orm';
4
- import { unzipSync, strFromU8 } from 'fflate';
5
- import { buildStorageKey, buildReadmeStorageKey, buildChangelogStorageKey } from '../../storage/driver';
6
- import { downloadFromSource } from '../../utils/download';
7
- import { decryptCredentials } from '../../utils/encryption';
8
- import { nanoid } from 'nanoid';
9
- import { COMPOSER_USER_AGENT } from '@package-broker/shared';
10
- import { isPackagistMirroringEnabled } from '../../modules/admin';
11
- import { fetchPackageFromUpstream } from '../../utils/upstream-fetch.js';
12
- /**
13
- * GET /api/packages
14
- * List all packages (with optional search)
15
- */
16
- export async function listPackages(c) {
17
- const db = c.get('database');
18
- const query = c.req.valid('query');
19
- const search = query?.search;
20
- let allPackages;
21
- if (search) {
22
- allPackages = await db
23
- .select()
24
- .from(packages)
25
- .where(like(packages.name, `%${search}%`))
26
- .orderBy(packages.name);
27
- }
28
- else {
29
- allPackages = await db.select().from(packages).orderBy(packages.name);
30
- }
31
- return c.json(allPackages);
32
- }
33
- /**
34
- * GET /api/packages/:name
35
- * Get a single package with all versions
36
- */
37
- export async function getPackage(c) {
38
- const { name: nameParam } = c.req.valid('param');
39
- // Decode URL-encoded package name (handles slashes like amasty/cron-schedule-list)
40
- const name = decodeURIComponent(nameParam);
41
- const db = c.get('database');
42
- const packageVersions = await db
43
- .select()
44
- .from(packages)
45
- .where(eq(packages.name, name))
46
- .orderBy(packages.released_at);
47
- if (packageVersions.length === 0) {
48
- return c.json({ error: 'Not Found', message: 'Package not found' }, 404);
49
- }
50
- return c.json({
51
- name,
52
- versions: packageVersions,
53
- });
54
- }
55
- /**
56
- * Extract README.md or README.mdown from ZIP archive
57
- */
58
- function extractReadme(zipData) {
59
- try {
60
- const files = unzipSync(zipData);
61
- // Look for README in common locations (case-insensitive)
62
- // Prefer .md over .mdown if both exist
63
- const readmeNames = [
64
- 'README.md', 'readme.md', 'README.MD', 'Readme.md',
65
- 'README.mdown', 'readme.mdown', 'README.MDOWN', 'Readme.mdown'
66
- ];
67
- // First pass: look for .md files
68
- for (const [path, content] of Object.entries(files)) {
69
- const filename = path.split('/').pop() || '';
70
- if (readmeNames.slice(0, 4).includes(filename)) {
71
- return strFromU8(content);
72
- }
73
- }
74
- // Second pass: look for .mdown files
75
- for (const [path, content] of Object.entries(files)) {
76
- const filename = path.split('/').pop() || '';
77
- if (readmeNames.slice(4).includes(filename)) {
78
- return strFromU8(content);
79
- }
80
- }
81
- return null;
82
- }
83
- catch (error) {
84
- console.error('Error extracting README from ZIP:', error);
85
- return null;
86
- }
87
- }
88
- /**
89
- * Extract CHANGELOG.md or CHANGELOG.mdown from ZIP archive
90
- */
91
- function extractChangelog(zipData) {
92
- try {
93
- const files = unzipSync(zipData);
94
- // Look for CHANGELOG in common locations (case-insensitive)
95
- // Prefer .md over .mdown if both exist
96
- const changelogNames = [
97
- 'CHANGELOG.md', 'changelog.md', 'CHANGELOG.MD', 'Changelog.md',
98
- 'CHANGELOG.mdown', 'changelog.mdown', 'CHANGELOG.MDOWN', 'Changelog.mdown'
99
- ];
100
- // First pass: look for .md files
101
- for (const [path, content] of Object.entries(files)) {
102
- const filename = path.split('/').pop() || '';
103
- if (changelogNames.slice(0, 4).includes(filename)) {
104
- return strFromU8(content);
105
- }
106
- }
107
- // Second pass: look for .mdown files
108
- for (const [path, content] of Object.entries(files)) {
109
- const filename = path.split('/').pop() || '';
110
- if (changelogNames.slice(4).includes(filename)) {
111
- return strFromU8(content);
112
- }
113
- }
114
- return null;
115
- }
116
- catch (error) {
117
- console.error('Error extracting CHANGELOG from ZIP:', error);
118
- return null;
119
- }
120
- }
121
- /**
122
- * GET /api/packages/:name/:version/readme
123
- * Get README.md content for a specific package version
124
- * Uses R2/S3 storage instead of KV for better scalability
125
- */
126
- export async function getPackageReadme(c) {
127
- const { name: nameParam, version } = c.req.valid('param');
128
- // Decode URL-encoded package name (handles slashes like amasty/cron-schedule-list)
129
- const name = decodeURIComponent(nameParam);
130
- if (!name || !version) {
131
- return c.json({ error: 'Bad Request', message: 'Missing package name or version' }, 400);
132
- }
133
- // 1. Get package from database to find repo_id
134
- const db = c.get('database');
135
- const [pkg] = await db
136
- .select()
137
- .from(packages)
138
- .where(and(eq(packages.name, name), eq(packages.version, version)))
139
- .limit(1);
140
- if (!pkg) {
141
- return c.json({ error: 'Not Found', message: 'Package version not found' }, 404);
142
- }
143
- // 2. Determine storage type (public for Packagist, private for others)
144
- const storageType = pkg.repo_id === 'packagist' ? 'public' : 'private';
145
- const readmeStorageKey = buildReadmeStorageKey(storageType, pkg.repo_id, name, version);
146
- const storage = c.var.storage;
147
- // 3. Check if README already exists in R2/S3 storage
148
- const existingReadme = await storage.get(readmeStorageKey);
149
- if (existingReadme) {
150
- // Read the stream to check if it's a "NOT_FOUND" marker
151
- const chunks = [];
152
- const reader = existingReadme.getReader();
153
- while (true) {
154
- const { done, value } = await reader.read();
155
- if (done)
156
- break;
157
- if (value) {
158
- chunks.push(value);
159
- }
160
- }
161
- const totalSize = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
162
- const content = new Uint8Array(totalSize);
163
- let offset = 0;
164
- for (const chunk of chunks) {
165
- content.set(chunk, offset);
166
- offset += chunk.length;
167
- }
168
- const textContent = new TextDecoder().decode(content);
169
- // If it's a NOT_FOUND marker, return 404
170
- if (textContent === 'NOT_FOUND') {
171
- return c.json({
172
- error: 'Not Found',
173
- message: 'No README file exists in this package version'
174
- }, 404);
175
- }
176
- // Return cached README with aggressive CDN caching
177
- return new Response(textContent, {
178
- headers: {
179
- 'Content-Type': 'text/markdown; charset=utf-8',
180
- 'Cache-Control': 'public, max-age=31536000, immutable',
181
- 'X-README-Source': 'storage',
182
- },
183
- });
184
- }
185
- // 4. README not in storage - need to extract from ZIP
186
- // Get artifact to find ZIP storage key
187
- let [artifact] = await db
188
- .select()
189
- .from(artifacts)
190
- .where(and(eq(artifacts.repo_id, pkg.repo_id), eq(artifacts.package_name, name), eq(artifacts.version, version)))
191
- .limit(1);
192
- let zipData = null;
193
- // 5. If artifact doesn't exist, try on-demand download
194
- if (!artifact) {
195
- // Check if we can download from source
196
- if (!pkg.source_dist_url) {
197
- return c.json({ error: 'Not Found', message: 'Artifact not found and source URL unavailable. Package may need to be downloaded first.' }, 404);
198
- }
199
- // Validate it's actually a URL
200
- if (!pkg.source_dist_url.startsWith('http://') && !pkg.source_dist_url.startsWith('https://')) {
201
- return c.json({ error: 'Not Found', message: 'Invalid source URL. Please re-sync the repository to update package metadata.' }, 404);
202
- }
203
- // Get repository for credentials
204
- const [repo] = await db
205
- .select()
206
- .from(repositories)
207
- .where(eq(repositories.id, pkg.repo_id))
208
- .limit(1);
209
- if (!repo) {
210
- return c.json({ error: 'Not Found', message: 'Repository not found' }, 404);
211
- }
212
- try {
213
- // Decrypt credentials
214
- const credentialsJson = await decryptCredentials(repo.auth_credentials, c.env.ENCRYPTION_KEY);
215
- const credentials = JSON.parse(credentialsJson);
216
- // Download from source with authentication
217
- const sourceResponse = await downloadFromSource(pkg.source_dist_url, repo.credential_type, credentials);
218
- // Read the response body
219
- const sourceStream = sourceResponse.body;
220
- if (!sourceStream) {
221
- throw new Error('Source response has no body');
222
- }
223
- // Read all chunks into memory
224
- const chunks = [];
225
- const reader = sourceStream.getReader();
226
- let totalSize = 0;
227
- while (true) {
228
- const { done, value } = await reader.read();
229
- if (done)
230
- break;
231
- if (value) {
232
- chunks.push(value);
233
- totalSize += value.length;
234
- }
235
- }
236
- // Combine chunks into a single Uint8Array
237
- zipData = new Uint8Array(totalSize);
238
- let offset = 0;
239
- for (const chunk of chunks) {
240
- zipData.set(chunk, offset);
241
- offset += chunk.length;
242
- }
243
- // Store artifact in storage
244
- const storageType = pkg.repo_id === 'packagist' ? 'public' : 'private';
245
- const storageKey = buildStorageKey(storageType, pkg.repo_id, name, version);
246
- // Convert to ArrayBuffer (not SharedArrayBuffer) for storage
247
- const arrayBuffer = zipData.buffer.slice(zipData.byteOffset, zipData.byteOffset + zipData.byteLength);
248
- try {
249
- await storage.put(storageKey, arrayBuffer);
250
- console.log(`Successfully stored artifact for README extraction: ${storageKey} (${totalSize} bytes)`);
251
- }
252
- catch (err) {
253
- console.error(`Error storing artifact ${storageKey}:`, err);
254
- // Continue - we can still extract README from zipData
255
- }
256
- // Create artifact record (ignore if already exists from concurrent request)
257
- const artifactId = nanoid();
258
- const now = Math.floor(Date.now() / 1000);
259
- try {
260
- await db.insert(artifacts).values({
261
- id: artifactId,
262
- repo_id: pkg.repo_id,
263
- package_name: name,
264
- version: version,
265
- file_key: storageKey,
266
- size: totalSize,
267
- download_count: 0,
268
- created_at: now,
269
- }).onConflictDoNothing();
270
- artifact = {
271
- id: artifactId,
272
- repo_id: pkg.repo_id,
273
- package_name: name,
274
- version: version,
275
- file_key: storageKey,
276
- size: totalSize,
277
- download_count: 0,
278
- created_at: now,
279
- last_downloaded_at: null,
280
- };
281
- }
282
- catch (err) {
283
- console.error(`Error creating artifact record:`, err);
284
- // Continue - we can still extract README from zipData
285
- }
286
- }
287
- catch (error) {
288
- console.error(`Error downloading artifact from source:`, error);
289
- return c.json({
290
- error: 'Internal Server Error',
291
- message: error instanceof Error ? error.message : 'Failed to download artifact',
292
- }, 500);
293
- }
294
- }
295
- // 6. Get ZIP from storage if we don't already have it in memory
296
- if (!zipData) {
297
- if (!artifact) {
298
- return c.json({ error: 'Not Found', message: 'Artifact not found' }, 404);
299
- }
300
- const zipStream = await storage.get(artifact.file_key);
301
- if (!zipStream) {
302
- return c.json({ error: 'Not Found', message: 'Artifact file not found in storage' }, 404);
303
- }
304
- // Read ZIP into memory
305
- const zipChunks = [];
306
- const zipReader = zipStream.getReader();
307
- while (true) {
308
- const { done, value } = await zipReader.read();
309
- if (done)
310
- break;
311
- if (value) {
312
- zipChunks.push(value);
313
- }
314
- }
315
- // Combine chunks
316
- const totalSize = zipChunks.reduce((sum, chunk) => sum + chunk.length, 0);
317
- zipData = new Uint8Array(totalSize);
318
- let offset = 0;
319
- for (const chunk of zipChunks) {
320
- zipData.set(chunk, offset);
321
- offset += chunk.length;
322
- }
323
- }
324
- // 7. Extract README from ZIP
325
- const readmeContent = extractReadme(zipData);
326
- if (!readmeContent) {
327
- // Store NOT_FOUND marker to avoid repeated extraction attempts
328
- const notFoundMarker = new TextEncoder().encode('NOT_FOUND');
329
- await storage.put(readmeStorageKey, notFoundMarker).catch((err) => {
330
- console.error(`Error storing NOT_FOUND marker for ${readmeStorageKey}:`, err);
331
- });
332
- return c.json({
333
- error: 'Not Found',
334
- message: 'No README file exists in this package version'
335
- }, 404);
336
- }
337
- // 8. Store README in R2/S3 for future requests
338
- const readmeBytes = new TextEncoder().encode(readmeContent);
339
- await storage.put(readmeStorageKey, readmeBytes).catch((err) => {
340
- console.error(`Error storing README for ${readmeStorageKey}:`, err);
341
- // Continue even if storage fails - we'll still return the content
342
- });
343
- // 9. Return with aggressive CDN caching headers
344
- return new Response(readmeContent, {
345
- headers: {
346
- 'Content-Type': 'text/markdown; charset=utf-8',
347
- 'Cache-Control': 'public, max-age=31536000, immutable',
348
- 'X-README-Source': 'extracted',
349
- },
350
- });
351
- }
352
- /**
353
- * GET /api/packages/:name/:version/changelog
354
- * Get CHANGELOG.md content for a specific package version
355
- * Uses R2/S3 storage instead of KV for better scalability
356
- */
357
- export async function getPackageChangelog(c) {
358
- const { name: nameParam, version } = c.req.valid('param');
359
- // Decode URL-encoded package name (handles slashes like amasty/cron-schedule-list)
360
- const name = decodeURIComponent(nameParam);
361
- if (!name || !version) {
362
- return c.json({ error: 'Bad Request', message: 'Missing package name or version' }, 400);
363
- }
364
- // 1. Get package from database to find repo_id
365
- const db = c.get('database');
366
- const [pkg] = await db
367
- .select()
368
- .from(packages)
369
- .where(and(eq(packages.name, name), eq(packages.version, version)))
370
- .limit(1);
371
- if (!pkg) {
372
- return c.json({ error: 'Not Found', message: 'Package version not found' }, 404);
373
- }
374
- // 2. Determine storage type (public for Packagist, private for others)
375
- const storageType = pkg.repo_id === 'packagist' ? 'public' : 'private';
376
- const changelogStorageKey = buildChangelogStorageKey(storageType, pkg.repo_id, name, version);
377
- const storage = c.var.storage;
378
- // 3. Check if CHANGELOG already exists in R2/S3 storage
379
- const existingChangelog = await storage.get(changelogStorageKey);
380
- if (existingChangelog) {
381
- // Read the stream to check if it's a "NOT_FOUND" marker
382
- const chunks = [];
383
- const reader = existingChangelog.getReader();
384
- while (true) {
385
- const { done, value } = await reader.read();
386
- if (done)
387
- break;
388
- if (value) {
389
- chunks.push(value);
390
- }
391
- }
392
- const totalSize = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
393
- const content = new Uint8Array(totalSize);
394
- let offset = 0;
395
- for (const chunk of chunks) {
396
- content.set(chunk, offset);
397
- offset += chunk.length;
398
- }
399
- const textContent = new TextDecoder().decode(content);
400
- // If it's a NOT_FOUND marker, return 404
401
- if (textContent === 'NOT_FOUND') {
402
- return c.json({
403
- error: 'Not Found',
404
- message: 'No CHANGELOG file exists in this package version'
405
- }, 404);
406
- }
407
- // Return cached CHANGELOG with aggressive CDN caching
408
- return new Response(textContent, {
409
- headers: {
410
- 'Content-Type': 'text/markdown; charset=utf-8',
411
- 'Cache-Control': 'public, max-age=31536000, immutable',
412
- 'X-CHANGELOG-Source': 'storage',
413
- },
414
- });
415
- }
416
- // 4. CHANGELOG not in storage - need to extract from ZIP
417
- // Get artifact to find ZIP storage key
418
- let [artifact] = await db
419
- .select()
420
- .from(artifacts)
421
- .where(and(eq(artifacts.repo_id, pkg.repo_id), eq(artifacts.package_name, name), eq(artifacts.version, version)))
422
- .limit(1);
423
- let zipData = null;
424
- // 5. If artifact doesn't exist, try on-demand download
425
- if (!artifact) {
426
- // Check if we can download from source
427
- if (!pkg.source_dist_url) {
428
- return c.json({ error: 'Not Found', message: 'Artifact not found and source URL unavailable. Package may need to be downloaded first.' }, 404);
429
- }
430
- // Validate it's actually a URL
431
- if (!pkg.source_dist_url.startsWith('http://') && !pkg.source_dist_url.startsWith('https://')) {
432
- return c.json({ error: 'Not Found', message: 'Invalid source URL. Please re-sync the repository to update package metadata.' }, 404);
433
- }
434
- // Get repository for credentials
435
- const [repo] = await db
436
- .select()
437
- .from(repositories)
438
- .where(eq(repositories.id, pkg.repo_id))
439
- .limit(1);
440
- if (!repo) {
441
- return c.json({ error: 'Not Found', message: 'Repository not found' }, 404);
442
- }
443
- try {
444
- // Decrypt credentials
445
- const credentialsJson = await decryptCredentials(repo.auth_credentials, c.env.ENCRYPTION_KEY);
446
- const credentials = JSON.parse(credentialsJson);
447
- // Download from source with authentication
448
- const sourceResponse = await downloadFromSource(pkg.source_dist_url, repo.credential_type, credentials);
449
- // Read the response body
450
- const sourceStream = sourceResponse.body;
451
- if (!sourceStream) {
452
- throw new Error('Source response has no body');
453
- }
454
- // Read all chunks into memory
455
- const chunks = [];
456
- const reader = sourceStream.getReader();
457
- let totalSize = 0;
458
- while (true) {
459
- const { done, value } = await reader.read();
460
- if (done)
461
- break;
462
- if (value) {
463
- chunks.push(value);
464
- totalSize += value.length;
465
- }
466
- }
467
- // Combine chunks into a single Uint8Array
468
- zipData = new Uint8Array(totalSize);
469
- let offset = 0;
470
- for (const chunk of chunks) {
471
- zipData.set(chunk, offset);
472
- offset += chunk.length;
473
- }
474
- // Store artifact in storage
475
- const storageKey = buildStorageKey(storageType, pkg.repo_id, name, version);
476
- // Convert to ArrayBuffer (not SharedArrayBuffer) for storage
477
- const arrayBuffer = zipData.buffer.slice(zipData.byteOffset, zipData.byteOffset + zipData.byteLength);
478
- try {
479
- await storage.put(storageKey, arrayBuffer);
480
- console.log(`Successfully stored artifact for CHANGELOG extraction: ${storageKey} (${totalSize} bytes)`);
481
- }
482
- catch (err) {
483
- console.error(`Error storing artifact ${storageKey}:`, err);
484
- // Continue - we can still extract CHANGELOG from zipData
485
- }
486
- // Create artifact record (ignore if already exists from concurrent request)
487
- const artifactId = nanoid();
488
- const now = Math.floor(Date.now() / 1000);
489
- try {
490
- await db.insert(artifacts).values({
491
- id: artifactId,
492
- repo_id: pkg.repo_id,
493
- package_name: name,
494
- version: version,
495
- file_key: storageKey,
496
- size: totalSize,
497
- download_count: 0,
498
- created_at: now,
499
- }).onConflictDoNothing();
500
- artifact = {
501
- id: artifactId,
502
- repo_id: pkg.repo_id,
503
- package_name: name,
504
- version: version,
505
- file_key: storageKey,
506
- size: totalSize,
507
- download_count: 0,
508
- created_at: now,
509
- last_downloaded_at: null,
510
- };
511
- }
512
- catch (err) {
513
- console.error(`Error creating artifact record:`, err);
514
- // Continue - we can still extract CHANGELOG from zipData
515
- }
516
- }
517
- catch (error) {
518
- console.error(`Error downloading artifact from source:`, error);
519
- return c.json({
520
- error: 'Internal Server Error',
521
- message: error instanceof Error ? error.message : 'Failed to download artifact',
522
- }, 500);
523
- }
524
- }
525
- // 6. Get ZIP from storage if we don't already have it in memory
526
- if (!zipData) {
527
- if (!artifact) {
528
- return c.json({ error: 'Not Found', message: 'Artifact not found' }, 404);
529
- }
530
- const zipStream = await storage.get(artifact.file_key);
531
- if (!zipStream) {
532
- return c.json({ error: 'Not Found', message: 'Artifact file not found in storage' }, 404);
533
- }
534
- // Read ZIP into memory
535
- const zipChunks = [];
536
- const zipReader = zipStream.getReader();
537
- while (true) {
538
- const { done, value } = await zipReader.read();
539
- if (done)
540
- break;
541
- if (value) {
542
- zipChunks.push(value);
543
- }
544
- }
545
- // Combine chunks
546
- const totalSize = zipChunks.reduce((sum, chunk) => sum + chunk.length, 0);
547
- zipData = new Uint8Array(totalSize);
548
- let offset = 0;
549
- for (const chunk of zipChunks) {
550
- zipData.set(chunk, offset);
551
- offset += chunk.length;
552
- }
553
- }
554
- // 7. Extract CHANGELOG from ZIP
555
- const changelogContent = extractChangelog(zipData);
556
- if (!changelogContent) {
557
- // Store NOT_FOUND marker to avoid repeated extraction attempts
558
- const notFoundMarker = new TextEncoder().encode('NOT_FOUND');
559
- await storage.put(changelogStorageKey, notFoundMarker).catch((err) => {
560
- console.error(`Error storing NOT_FOUND marker for ${changelogStorageKey}:`, err);
561
- });
562
- return c.json({
563
- error: 'Not Found',
564
- message: 'No CHANGELOG file exists in this package version'
565
- }, 404);
566
- }
567
- // 8. Store CHANGELOG in R2/S3 for future requests
568
- const changelogBytes = new TextEncoder().encode(changelogContent);
569
- await storage.put(changelogStorageKey, changelogBytes).catch((err) => {
570
- console.error(`Error storing CHANGELOG for ${changelogStorageKey}:`, err);
571
- // Continue even if storage fails - we'll still return the content
572
- });
573
- // 9. Return with aggressive CDN caching headers
574
- return new Response(changelogContent, {
575
- headers: {
576
- 'Content-Type': 'text/markdown; charset=utf-8',
577
- 'Cache-Control': 'public, max-age=31536000, immutable',
578
- 'X-CHANGELOG-Source': 'extracted',
579
- },
580
- });
581
- }
582
- /**
583
- * POST /api/packages/add-from-mirror
584
- * Manually fetch and store packages from a selected mirror repository
585
- */
586
- export async function addPackagesFromMirror(c) {
587
- const body = await c.req.json();
588
- if (!body.repository_id || !Array.isArray(body.package_names) || body.package_names.length === 0) {
589
- return c.json({ error: 'Bad Request', message: 'repository_id and package_names array are required' }, 400);
590
- }
591
- const db = c.get('database');
592
- const url = new URL(c.req.url);
593
- const baseUrl = `${url.protocol}//${url.host}`;
594
- const results = [];
595
- // Handle Packagist repository
596
- if (body.repository_id === 'packagist') {
597
- const mirroringEnabled = await isPackagistMirroringEnabled(c.env.KV);
598
- if (!mirroringEnabled) {
599
- return c.json({ error: 'Bad Request', message: 'Packagist mirroring is not enabled' }, 400);
600
- }
601
- const { ensurePackagistRepository } = await import('../composer');
602
- await ensurePackagistRepository(db, c.env.ENCRYPTION_KEY, c.env.KV);
603
- // Fetch each package from Packagist
604
- for (const packageName of body.package_names) {
605
- try {
606
- const packagistUrl = `https://repo.packagist.org/p2/${packageName}.json`;
607
- const response = await fetch(packagistUrl, {
608
- headers: {
609
- 'User-Agent': COMPOSER_USER_AGENT,
610
- },
611
- });
612
- if (!response.ok) {
613
- if (response.status === 404) {
614
- results.push({ package: packageName, success: false, error: 'Package not found' });
615
- continue;
616
- }
617
- results.push({ package: packageName, success: false, error: `HTTP ${response.status}` });
618
- continue;
619
- }
620
- const packageData = await response.json();
621
- const { transformPackageDistUrls } = await import('../composer');
622
- const { storedCount, errors } = await transformPackageDistUrls(packageData, 'packagist', baseUrl, db);
623
- if (storedCount > 0) {
624
- results.push({ package: packageName, success: true, versions: storedCount });
625
- }
626
- else {
627
- results.push({ package: packageName, success: false, error: errors.join('; ') || 'No versions stored' });
628
- }
629
- }
630
- catch (error) {
631
- results.push({
632
- package: packageName,
633
- success: false,
634
- error: error instanceof Error ? error.message : 'Unknown error',
635
- });
636
- }
637
- }
638
- }
639
- else {
640
- // Handle other Composer repositories
641
- const [repo] = await db
642
- .select()
643
- .from(repositories)
644
- .where(eq(repositories.id, body.repository_id))
645
- .limit(1);
646
- if (!repo) {
647
- return c.json({ error: 'Not Found', message: 'Repository not found' }, 404);
648
- }
649
- if (repo.vcs_type !== 'composer') {
650
- return c.json({ error: 'Bad Request', message: 'Only Composer repositories can be used for manual package addition' }, 400);
651
- }
652
- if (repo.status !== 'active') {
653
- return c.json({ error: 'Bad Request', message: 'Repository is not active' }, 400);
654
- }
655
- const upstreamRepo = {
656
- id: repo.id,
657
- url: repo.url,
658
- vcs_type: repo.vcs_type,
659
- credential_type: repo.credential_type,
660
- auth_credentials: repo.auth_credentials,
661
- package_filter: repo.package_filter,
662
- };
663
- for (const packageName of body.package_names) {
664
- try {
665
- const packageData = await fetchPackageFromUpstream(upstreamRepo, packageName, c.env.ENCRYPTION_KEY);
666
- if (!packageData) {
667
- results.push({ package: packageName, success: false, error: 'Package not found' });
668
- continue;
669
- }
670
- const { transformPackageDistUrls } = await import('../composer');
671
- const { storedCount, errors } = await transformPackageDistUrls(packageData, repo.id, baseUrl, db);
672
- if (storedCount > 0) {
673
- results.push({ package: packageName, success: true, versions: storedCount });
674
- }
675
- else {
676
- results.push({ package: packageName, success: false, error: errors.join('; ') || 'No versions stored' });
677
- }
678
- }
679
- catch (error) {
680
- results.push({
681
- package: packageName,
682
- success: false,
683
- error: error instanceof Error ? error.message : 'Unknown error',
684
- });
685
- }
686
- }
687
- }
688
- const succeeded = results.filter(r => r.success).length;
689
- const failed = results.filter(r => !r.success).length;
690
- const totalVersions = results.reduce((sum, r) => sum + (r.versions || 0), 0);
691
- return c.json({
692
- results,
693
- summary: {
694
- total: results.length,
695
- succeeded,
696
- failed,
697
- total_versions: totalVersions,
698
- },
699
- });
700
- }
701
- /**
702
- * POST /packages/cleanup-numeric-versions
703
- * Temporary utility to fix versioning issues
704
- */
705
- export async function cleanupNumericVersions(c) {
706
- return c.json({ message: 'Cleanup not implemented in this adapter version' });
707
- }
708
- //# sourceMappingURL=packages.js.map