@hot-updater/server 1.0.0-rc.2 → 1.0.0-rc.21

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 (328) hide show
  1. package/LICENSE +12 -14
  2. package/dist/adapters/drizzle.cjs +32 -75
  3. package/dist/adapters/drizzle.d.cts +13 -5
  4. package/dist/adapters/drizzle.d.mts +13 -5
  5. package/dist/adapters/drizzle.mjs +32 -77
  6. package/dist/adapters/drizzleExecutor.cjs +114 -0
  7. package/dist/adapters/drizzleExecutor.d.cts +9 -0
  8. package/dist/adapters/drizzleExecutor.d.mts +9 -0
  9. package/dist/adapters/drizzleExecutor.mjs +112 -0
  10. package/dist/adapters/kysely.cjs +22 -31
  11. package/dist/adapters/kysely.d.cts +10 -6
  12. package/dist/adapters/kysely.d.mts +10 -6
  13. package/dist/adapters/kysely.mjs +23 -33
  14. package/dist/adapters/kyselyExecutor.cjs +32 -0
  15. package/dist/adapters/kyselyExecutor.d.cts +11 -0
  16. package/dist/adapters/kyselyExecutor.d.mts +11 -0
  17. package/dist/adapters/kyselyExecutor.mjs +32 -0
  18. package/dist/adapters/mongodb.cjs +18 -54
  19. package/dist/adapters/mongodb.d.cts +10 -5
  20. package/dist/adapters/mongodb.d.mts +10 -5
  21. package/dist/adapters/mongodb.mjs +19 -56
  22. package/dist/adapters/mongodbAdapter.cjs +192 -0
  23. package/dist/adapters/mongodbAdapter.d.cts +9 -0
  24. package/dist/adapters/mongodbAdapter.d.mts +9 -0
  25. package/dist/adapters/mongodbAdapter.mjs +191 -0
  26. package/dist/adapters/prisma.cjs +35 -267
  27. package/dist/adapters/prisma.d.cts +12 -7
  28. package/dist/adapters/prisma.d.mts +12 -7
  29. package/dist/adapters/prisma.mjs +36 -268
  30. package/dist/adapters/prismaExecutor.cjs +63 -0
  31. package/dist/adapters/prismaExecutor.mjs +63 -0
  32. package/dist/adapters/sqlProviders.cjs +14 -0
  33. package/dist/adapters/sqlProviders.mjs +14 -0
  34. package/dist/assembly/assemblePlugins.cjs +144 -0
  35. package/dist/assembly/assemblePlugins.d.cts +5 -0
  36. package/dist/assembly/assemblePlugins.d.mts +5 -0
  37. package/dist/assembly/assemblePlugins.mjs +139 -0
  38. package/dist/assembly/clientPlugins.cjs +88 -0
  39. package/dist/assembly/clientPlugins.mjs +88 -0
  40. package/dist/assembly/configError.d.cts +2 -0
  41. package/dist/assembly/configError.d.mts +2 -0
  42. package/dist/assembly/configError.mjs +2 -0
  43. package/dist/core/api.cjs +51 -0
  44. package/dist/core/api.d.cts +54 -0
  45. package/dist/core/api.d.mts +54 -0
  46. package/dist/core/api.mjs +51 -0
  47. package/dist/core/baseCandidates.cjs +28 -0
  48. package/dist/core/baseCandidates.mjs +28 -0
  49. package/dist/core/operations.cjs +351 -0
  50. package/dist/core/operations.mjs +351 -0
  51. package/dist/core/reads.cjs +273 -0
  52. package/dist/core/reads.d.cts +9 -0
  53. package/dist/core/reads.d.mts +9 -0
  54. package/dist/core/reads.mjs +267 -0
  55. package/dist/core/releases.cjs +193 -0
  56. package/dist/core/releases.mjs +190 -0
  57. package/dist/core/writes.cjs +96 -0
  58. package/dist/core/writes.mjs +91 -0
  59. package/dist/createHotUpdaterCore.cjs +72 -91
  60. package/dist/createHotUpdaterCore.d.cts +106 -38
  61. package/dist/createHotUpdaterCore.d.mts +106 -38
  62. package/dist/createHotUpdaterCore.mjs +74 -89
  63. package/dist/db/engineDrizzleSchema.cjs +53 -0
  64. package/dist/db/engineDrizzleSchema.mjs +53 -0
  65. package/dist/db/enginePrismaSchema.cjs +84 -0
  66. package/dist/db/enginePrismaSchema.d.cts +5 -0
  67. package/dist/db/enginePrismaSchema.d.mts +5 -0
  68. package/dist/db/enginePrismaSchema.mjs +83 -0
  69. package/dist/db/releaseCatalog.cjs +24 -47
  70. package/dist/db/releaseCatalog.mjs +20 -44
  71. package/dist/db/updateArtifacts.cjs +43 -72
  72. package/dist/db/updateArtifacts.mjs +40 -69
  73. package/dist/handler.cjs +59 -43
  74. package/dist/handler.d.cts +3 -5
  75. package/dist/handler.d.mts +3 -5
  76. package/dist/handler.mjs +61 -43
  77. package/dist/handlerAdminRoutes.cjs +374 -0
  78. package/dist/handlerAdminRoutes.mjs +372 -0
  79. package/dist/handlerParameters.cjs +6 -11
  80. package/dist/handlerParameters.mjs +6 -10
  81. package/dist/handlerReleaseCatalogRoutes.cjs +32 -15
  82. package/dist/handlerReleaseCatalogRoutes.mjs +32 -15
  83. package/dist/handlerTypes.d.cts +2 -55
  84. package/dist/handlerTypes.d.mts +2 -55
  85. package/dist/handlerVersionRoutes.cjs +20 -4
  86. package/dist/handlerVersionRoutes.mjs +20 -4
  87. package/dist/index.cjs +9 -9
  88. package/dist/index.d.cts +8 -9
  89. package/dist/index.d.mts +8 -9
  90. package/dist/index.mjs +3 -4
  91. package/dist/node.cjs +3 -6
  92. package/dist/node.d.cts +2 -2
  93. package/dist/node.d.mts +2 -2
  94. package/dist/node.mjs +4 -4
  95. package/dist/package.cjs +1 -1
  96. package/dist/package.mjs +1 -1
  97. package/dist/plugins/api-keys/index.cjs +9 -0
  98. package/dist/plugins/api-keys/index.d.cts +1 -0
  99. package/dist/plugins/api-keys/index.d.mts +1 -0
  100. package/dist/plugins/api-keys/index.mjs +2 -0
  101. package/dist/plugins/definePlugin.d.cts +2 -0
  102. package/dist/plugins/definePlugin.d.mts +2 -0
  103. package/dist/plugins/insights/index.cjs +9 -0
  104. package/dist/plugins/insights/index.d.cts +1 -0
  105. package/dist/plugins/insights/index.d.mts +1 -0
  106. package/dist/plugins/insights/index.mjs +2 -0
  107. package/dist/plugins/official.cjs +30 -0
  108. package/dist/plugins/official.mjs +29 -0
  109. package/dist/storageAccess.cjs +13 -10
  110. package/dist/storageAccess.mjs +13 -10
  111. package/dist/types/index.d.cts +2 -28
  112. package/dist/types/index.d.mts +2 -28
  113. package/package.json +26 -14
  114. package/dist/_virtual/_rolldown/runtime.cjs +0 -23
  115. package/dist/adapters/databaseConstraintErrors.cjs +0 -22
  116. package/dist/adapters/databaseConstraintErrors.mjs +0 -21
  117. package/dist/adapters/databasePluginUtils.cjs +0 -116
  118. package/dist/adapters/databasePluginUtils.mjs +0 -106
  119. package/dist/adapters/drizzleCrud.cjs +0 -311
  120. package/dist/adapters/drizzleCrud.mjs +0 -308
  121. package/dist/adapters/drizzleLazyDB.cjs +0 -106
  122. package/dist/adapters/drizzleLazyDB.mjs +0 -106
  123. package/dist/adapters/drizzleQuery.cjs +0 -69
  124. package/dist/adapters/drizzleQuery.mjs +0 -69
  125. package/dist/adapters/insightsTransaction.cjs +0 -22
  126. package/dist/adapters/insightsTransaction.mjs +0 -22
  127. package/dist/adapters/kyselyCrud.cjs +0 -305
  128. package/dist/adapters/kyselyCrud.mjs +0 -304
  129. package/dist/adapters/kyselyQuery.cjs +0 -56
  130. package/dist/adapters/kyselyQuery.mjs +0 -56
  131. package/dist/adapters/mongodbCollections.cjs +0 -38
  132. package/dist/adapters/mongodbCollections.mjs +0 -32
  133. package/dist/adapters/mongodbQuery.cjs +0 -94
  134. package/dist/adapters/mongodbQuery.mjs +0 -86
  135. package/dist/adapters/mongodbReads.cjs +0 -210
  136. package/dist/adapters/mongodbReads.mjs +0 -210
  137. package/dist/adapters/mongodbWrites.cjs +0 -148
  138. package/dist/adapters/mongodbWrites.mjs +0 -148
  139. package/dist/adapters/prismaQuery.cjs +0 -57
  140. package/dist/adapters/prismaQuery.mjs +0 -56
  141. package/dist/adapters/prismaRows.cjs +0 -219
  142. package/dist/adapters/prismaRows.mjs +0 -209
  143. package/dist/apiKeys.cjs +0 -143
  144. package/dist/apiKeys.d.cts +0 -49
  145. package/dist/apiKeys.d.mts +0 -49
  146. package/dist/apiKeys.mjs +0 -133
  147. package/dist/db/createBundleDiff.cjs +0 -144
  148. package/dist/db/createBundleDiff.d.cts +0 -16
  149. package/dist/db/createBundleDiff.d.mts +0 -16
  150. package/dist/db/createBundleDiff.mjs +0 -141
  151. package/dist/db/databasePluginCore.cjs +0 -137
  152. package/dist/db/databasePluginCore.mjs +0 -137
  153. package/dist/db/fixedMigrator.cjs +0 -79
  154. package/dist/db/fixedMigrator.mjs +0 -78
  155. package/dist/db/fixedMigratorMongo.cjs +0 -321
  156. package/dist/db/fixedMigratorMongo.mjs +0 -321
  157. package/dist/db/fixedMigratorShared.cjs +0 -23
  158. package/dist/db/fixedMigratorShared.mjs +0 -18
  159. package/dist/db/index.cjs +0 -27
  160. package/dist/db/index.d.cts +0 -12
  161. package/dist/db/index.d.mts +0 -12
  162. package/dist/db/index.mjs +0 -22
  163. package/dist/db/mongoMigrationExecution.cjs +0 -11
  164. package/dist/db/mongoMigrationExecution.mjs +0 -11
  165. package/dist/db/releaseCatalog.d.cts +0 -16
  166. package/dist/db/releaseCatalog.d.mts +0 -16
  167. package/dist/db/schema/insightsCollation.cjs +0 -14
  168. package/dist/db/schema/insightsCollation.mjs +0 -14
  169. package/dist/db/schema/mongodb.cjs +0 -25
  170. package/dist/db/schema/mongodb.mjs +0 -25
  171. package/dist/db/schema/registry.cjs +0 -21
  172. package/dist/db/schema/registry.mjs +0 -17
  173. package/dist/db/schema/sql.cjs +0 -105
  174. package/dist/db/schema/sql.mjs +0 -97
  175. package/dist/db/schema/sqlOperations.cjs +0 -27
  176. package/dist/db/schema/sqlOperations.mjs +0 -26
  177. package/dist/db/schemaGenerators.cjs +0 -275
  178. package/dist/db/schemaGenerators.mjs +0 -273
  179. package/dist/db/schemaReadiness.cjs +0 -26
  180. package/dist/db/schemaReadiness.d.cts +0 -9
  181. package/dist/db/schemaReadiness.d.mts +0 -9
  182. package/dist/db/schemaReadiness.mjs +0 -25
  183. package/dist/db/sqlMigrationExecution.cjs +0 -67
  184. package/dist/db/sqlMigrationExecution.mjs +0 -67
  185. package/dist/db/types.cjs +0 -22
  186. package/dist/db/types.d.cts +0 -118
  187. package/dist/db/types.d.mts +0 -118
  188. package/dist/db/types.mjs +0 -19
  189. package/dist/handlerBundleRoutes.cjs +0 -155
  190. package/dist/handlerBundleRoutes.mjs +0 -155
  191. package/dist/handlerReleaseManagementRoutes.cjs +0 -124
  192. package/dist/handlerReleaseManagementRoutes.mjs +0 -124
  193. package/dist/insights/domain.d.cts +0 -89
  194. package/dist/insights/domain.d.mts +0 -89
  195. package/dist/insights/errors.cjs +0 -15
  196. package/dist/insights/errors.mjs +0 -14
  197. package/dist/insights/eventInput.cjs +0 -155
  198. package/dist/insights/eventInput.mjs +0 -153
  199. package/dist/insights/provider.cjs +0 -314
  200. package/dist/insights/provider.d.cts +0 -6
  201. package/dist/insights/provider.d.mts +0 -6
  202. package/dist/insights/provider.mjs +0 -314
  203. package/dist/insights/queryInput.cjs +0 -93
  204. package/dist/insights/queryInput.mjs +0 -91
  205. package/dist/insights/routes.cjs +0 -58
  206. package/dist/insights/routes.mjs +0 -56
  207. package/dist/insights/types.d.cts +0 -32
  208. package/dist/insights/types.d.mts +0 -32
  209. package/dist/schema/dsl.cjs +0 -103
  210. package/dist/schema/dsl.mjs +0 -87
  211. package/dist/schema/index.cjs +0 -20
  212. package/dist/schema/index.mjs +0 -7
  213. package/dist/schema/settings.cjs +0 -9
  214. package/dist/schema/settings.mjs +0 -9
  215. package/dist/schema/types.cjs +0 -8
  216. package/dist/schema/types.mjs +0 -6
  217. package/dist/schema/v1_0_0.cjs +0 -406
  218. package/dist/schema/v1_0_0.mjs +0 -398
  219. package/src/adapters/databaseConstraintErrors.ts +0 -25
  220. package/src/adapters/databasePluginTestDatabase.ts +0 -120
  221. package/src/adapters/databasePluginUtils.spec.ts +0 -29
  222. package/src/adapters/databasePluginUtils.ts +0 -214
  223. package/src/adapters/drizzle.spec.ts +0 -336
  224. package/src/adapters/drizzle.ts +0 -162
  225. package/src/adapters/drizzleCrud.ts +0 -571
  226. package/src/adapters/drizzleLazyDB.ts +0 -271
  227. package/src/adapters/drizzleQuery.ts +0 -164
  228. package/src/adapters/insightsTransaction.ts +0 -32
  229. package/src/adapters/kysely.spec.ts +0 -174
  230. package/src/adapters/kysely.ts +0 -110
  231. package/src/adapters/kyselyCrud.ts +0 -709
  232. package/src/adapters/kyselyQuery.ts +0 -128
  233. package/src/adapters/mongodb.integration.spec.ts +0 -210
  234. package/src/adapters/mongodb.spec.ts +0 -209
  235. package/src/adapters/mongodb.ts +0 -138
  236. package/src/adapters/mongodbCollections.ts +0 -67
  237. package/src/adapters/mongodbQuery.ts +0 -255
  238. package/src/adapters/mongodbReads.ts +0 -380
  239. package/src/adapters/mongodbRows.spec.ts +0 -64
  240. package/src/adapters/mongodbRows.ts +0 -118
  241. package/src/adapters/mongodbTestClient.ts +0 -377
  242. package/src/adapters/mongodbTestFilter.ts +0 -169
  243. package/src/adapters/mongodbWrites.ts +0 -287
  244. package/src/adapters/prisma.spec.ts +0 -293
  245. package/src/adapters/prisma.ts +0 -565
  246. package/src/adapters/prismaQuery.ts +0 -129
  247. package/src/adapters/prismaRows.spec.ts +0 -98
  248. package/src/adapters/prismaRows.ts +0 -337
  249. package/src/adapters/prismaTestClient.ts +0 -413
  250. package/src/apiKeys.integration.spec.ts +0 -192
  251. package/src/apiKeys.spec.ts +0 -162
  252. package/src/apiKeys.ts +0 -220
  253. package/src/calculatePagination.ts +0 -34
  254. package/src/createHotUpdaterCore.ts +0 -246
  255. package/src/db/bundleRows.spec.ts +0 -164
  256. package/src/db/bundleRows.ts +0 -10
  257. package/src/db/createBundleDiff.spec.ts +0 -450
  258. package/src/db/createBundleDiff.ts +0 -364
  259. package/src/db/databasePluginCore.spec.ts +0 -62
  260. package/src/db/databasePluginCore.testFixtures.ts +0 -76
  261. package/src/db/databasePluginCore.ts +0 -185
  262. package/src/db/databasePluginUpdateCheck.bench.ts +0 -110
  263. package/src/db/fixedMigrator.spec.ts +0 -296
  264. package/src/db/fixedMigrator.ts +0 -147
  265. package/src/db/fixedMigratorMongo.spec.ts +0 -239
  266. package/src/db/fixedMigratorMongo.ts +0 -425
  267. package/src/db/fixedMigratorShared.ts +0 -36
  268. package/src/db/hotUpdaterSchema.ts +0 -5
  269. package/src/db/index.spec.ts +0 -1269
  270. package/src/db/index.ts +0 -47
  271. package/src/db/mongoMigrationExecution.ts +0 -23
  272. package/src/db/node-sqlite.d.ts +0 -25
  273. package/src/db/releaseCatalog.ts +0 -148
  274. package/src/db/schema/definitions.ts +0 -1
  275. package/src/db/schema/insightsCollation.ts +0 -21
  276. package/src/db/schema/mongodb.ts +0 -40
  277. package/src/db/schema/registry.ts +0 -55
  278. package/src/db/schema/sql.ts +0 -244
  279. package/src/db/schema/sqlOperations.ts +0 -63
  280. package/src/db/schema/types.ts +0 -1
  281. package/src/db/schemaGenerators.ts +0 -494
  282. package/src/db/schemaReadiness.ts +0 -34
  283. package/src/db/sqlMigrationExecution.spec.ts +0 -65
  284. package/src/db/sqlMigrationExecution.ts +0 -108
  285. package/src/db/types.spec.ts +0 -63
  286. package/src/db/types.ts +0 -228
  287. package/src/db/updateArtifacts.spec.ts +0 -359
  288. package/src/db/updateArtifacts.ts +0 -541
  289. package/src/handler-standalone.integration.spec.ts +0 -528
  290. package/src/handler.spec.ts +0 -190
  291. package/src/handler.testFixtures.ts +0 -30
  292. package/src/handler.ts +0 -245
  293. package/src/handlerAuth.integration.spec.ts +0 -33
  294. package/src/handlerBundleRoutes.ts +0 -259
  295. package/src/handlerErrors.ts +0 -7
  296. package/src/handlerManagement.spec.ts +0 -262
  297. package/src/handlerParameters.ts +0 -105
  298. package/src/handlerReleaseCatalogRoutes.ts +0 -154
  299. package/src/handlerReleaseManagementRoutes.ts +0 -213
  300. package/src/handlerTypes.ts +0 -96
  301. package/src/handlerVersionRoutes.ts +0 -12
  302. package/src/index.ts +0 -30
  303. package/src/insights/domain.ts +0 -103
  304. package/src/insights/errors.ts +0 -11
  305. package/src/insights/eventInput.ts +0 -225
  306. package/src/insights/insights.integration.spec.ts +0 -381
  307. package/src/insights/provider.spec.ts +0 -385
  308. package/src/insights/provider.ts +0 -591
  309. package/src/insights/queryInput.ts +0 -141
  310. package/src/insights/routes.ts +0 -104
  311. package/src/insights/types.ts +0 -55
  312. package/src/internalRouter.ts +0 -104
  313. package/src/node.spec.ts +0 -119
  314. package/src/node.ts +0 -111
  315. package/src/releaseCatalogRoutes.integration.spec.ts +0 -238
  316. package/src/runtime.spec.ts +0 -194
  317. package/src/runtime.testFixtures.ts +0 -71
  318. package/src/schema/dsl-all-versions.spec.ts +0 -37
  319. package/src/schema/dsl.ts +0 -187
  320. package/src/schema/index.ts +0 -10
  321. package/src/schema/settings.ts +0 -15
  322. package/src/schema/types.ts +0 -79
  323. package/src/schema/v1_0_0.spec.ts +0 -220
  324. package/src/schema/v1_0_0.ts +0 -529
  325. package/src/storageAccess.spec.ts +0 -152
  326. package/src/storageAccess.ts +0 -141
  327. package/src/types/index.ts +0 -34
  328. package/src/version.ts +0 -3
@@ -1,259 +0,0 @@
1
- import type { Bundle } from "@hot-updater/core";
2
- import type { ChannelInsertInput } from "@hot-updater/plugin-core";
3
-
4
- import { HandlerBadRequestError } from "./handlerErrors";
5
- import {
6
- decodeMaybe,
7
- isPlatform,
8
- parsePositiveIntegerSearchParam,
9
- parseStringArraySearchParam,
10
- requireRouteParam,
11
- } from "./handlerParameters";
12
- import type { RouteHandler } from "./handlerTypes";
13
- import type { ChannelsResponse } from "./types";
14
-
15
- const BUNDLE_LIST_BOUNDS = { defaultValue: 50, maxValue: 100 } as const;
16
-
17
- const isChannelText = (value: unknown): value is string => {
18
- if (typeof value !== "string" || value.length === 0) return false;
19
- let codePoints = 0;
20
- for (const _codePoint of value) {
21
- codePoints += 1;
22
- if (codePoints > 255) return false;
23
- }
24
- return true;
25
- };
26
-
27
- const requireChannelInsertInput = (value: unknown): ChannelInsertInput => {
28
- if (
29
- !value ||
30
- typeof value !== "object" ||
31
- Array.isArray(value) ||
32
- !("row" in value) ||
33
- !value.row ||
34
- typeof value.row !== "object" ||
35
- Array.isArray(value.row) ||
36
- !("id" in value.row) ||
37
- !isChannelText(value.row.id) ||
38
- !("name" in value.row) ||
39
- !isChannelText(value.row.name) ||
40
- !("onConflict" in value) ||
41
- value.onConflict !== "returnExisting"
42
- ) {
43
- throw new HandlerBadRequestError("Invalid Channel insert payload");
44
- }
45
- return {
46
- row: { id: value.row.id, name: value.row.name },
47
- onConflict: value.onConflict,
48
- };
49
- };
50
-
51
- type BundlePatchPayload = Partial<Bundle> & { readonly id?: string };
52
-
53
- const requireBundlePatchPayload = (
54
- payload: unknown,
55
- bundleId: string,
56
- ): Partial<Bundle> => {
57
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
58
- throw new HandlerBadRequestError("Invalid bundle payload");
59
- }
60
- const bundlePatch = payload as BundlePatchPayload;
61
- if (bundlePatch.id !== undefined && bundlePatch.id !== bundleId) {
62
- throw new HandlerBadRequestError("Bundle id mismatch");
63
- }
64
- const { id: _ignoredId, ...rest } = bundlePatch;
65
- return rest;
66
- };
67
-
68
- export const createBundleRouteHandlers = (): Record<string, RouteHandler> => ({
69
- getBundle: async (params, _request, api) => {
70
- const bundle = await api.getBundleById(requireRouteParam(params, "id"));
71
- if (!bundle) {
72
- return new Response(JSON.stringify({ error: "Bundle not found" }), {
73
- status: 404,
74
- headers: { "Content-Type": "application/json" },
75
- });
76
- }
77
- return new Response(JSON.stringify(bundle), {
78
- status: 200,
79
- headers: { "Content-Type": "application/json" },
80
- });
81
- },
82
-
83
- getBundles: async (_params, request, api) => {
84
- const url = new URL(request.url);
85
- const platform = url.searchParams.get("platform");
86
- const limit = parsePositiveIntegerSearchParam(
87
- url,
88
- "limit",
89
- BUNDLE_LIST_BOUNDS,
90
- );
91
- const pageParam = url.searchParams.get("page");
92
- const offset = url.searchParams.get("offset");
93
- const after = url.searchParams.get("after") ?? undefined;
94
- const before = url.searchParams.get("before") ?? undefined;
95
- const orderDirection = url.searchParams.get("orderDirection");
96
- const idEq = url.searchParams.get("idEq") ?? undefined;
97
- const idGt = url.searchParams.get("idGt") ?? undefined;
98
- const idGte = url.searchParams.get("idGte") ?? undefined;
99
- const idLt = url.searchParams.get("idLt") ?? undefined;
100
- const idLte = url.searchParams.get("idLte") ?? undefined;
101
- const idIn = parseStringArraySearchParam(url, "idIn");
102
- const page =
103
- pageParam === null
104
- ? undefined
105
- : Number.isSafeInteger(Number(pageParam)) &&
106
- Number(pageParam) > 0 &&
107
- Number.isSafeInteger((Number(pageParam) - 1) * limit)
108
- ? Number(pageParam)
109
- : null;
110
- if (offset !== null) {
111
- throw new HandlerBadRequestError(
112
- "The 'offset' query parameter has been removed. Use 'after' or 'before' cursor pagination instead.",
113
- );
114
- }
115
- if (page === null) {
116
- throw new HandlerBadRequestError(
117
- "The 'page' query parameter must be a positive integer.",
118
- );
119
- }
120
- if (after !== undefined && before !== undefined) {
121
- throw new HandlerBadRequestError(
122
- "The 'after' and 'before' query parameters cannot be combined.",
123
- );
124
- }
125
- if (page !== undefined && (after !== undefined || before !== undefined)) {
126
- throw new HandlerBadRequestError(
127
- "The 'page' query parameter cannot be combined with 'after' or 'before'.",
128
- );
129
- }
130
- if (platform !== null && !isPlatform(platform)) {
131
- throw new HandlerBadRequestError(
132
- `Invalid platform: ${platform}. Expected 'ios' or 'android'.`,
133
- );
134
- }
135
- if (
136
- orderDirection !== null &&
137
- orderDirection !== "asc" &&
138
- orderDirection !== "desc"
139
- ) {
140
- throw new HandlerBadRequestError(
141
- "The 'orderDirection' query parameter must be 'asc' or 'desc'.",
142
- );
143
- }
144
- const cursor =
145
- after !== undefined
146
- ? { after }
147
- : before !== undefined
148
- ? { before }
149
- : undefined;
150
- const pagination =
151
- page === undefined
152
- ? { cursor, page: undefined }
153
- : { cursor: undefined, page };
154
- const result = await api.getBundles({
155
- where: {
156
- ...(platform && { platform }),
157
- ...(idEq || idGt || idGte || idLt || idLte || idIn?.length
158
- ? {
159
- id: {
160
- ...(idEq && { eq: idEq }),
161
- ...(idGt && { gt: idGt }),
162
- ...(idGte && { gte: idGte }),
163
- ...(idLt && { lt: idLt }),
164
- ...(idLte && { lte: idLte }),
165
- ...(idIn?.length && { in: idIn }),
166
- },
167
- }
168
- : {}),
169
- },
170
- limit,
171
- ...pagination,
172
- ...(orderDirection && {
173
- orderBy: { field: "id", direction: orderDirection },
174
- }),
175
- });
176
- return new Response(JSON.stringify(result), {
177
- status: 200,
178
- headers: { "Content-Type": "application/json" },
179
- });
180
- },
181
-
182
- createBundles: async (_params, request, api) => {
183
- const body = await request.json();
184
- const bundles = Array.isArray(body) ? body : [body];
185
- if (api.insertBundles) {
186
- await api.insertBundles(bundles as Bundle[]);
187
- } else {
188
- if (bundles.length > 1) {
189
- throw new HandlerBadRequestError(
190
- "This server does not support atomic bundle batches",
191
- );
192
- }
193
- const bundle = bundles[0];
194
- if (bundle !== undefined) {
195
- await api.insertBundle(bundle as Bundle);
196
- }
197
- }
198
- return new Response(JSON.stringify({ success: true }), {
199
- status: 201,
200
- headers: { "Content-Type": "application/json" },
201
- });
202
- },
203
-
204
- updateBundle: async (params, request, api) => {
205
- const bundleId = requireRouteParam(params, "id");
206
- const body = await request.json();
207
- const payload = Array.isArray(body) ? body[0] : body;
208
- await api.updateBundleById(
209
- bundleId,
210
- requireBundlePatchPayload(payload, bundleId),
211
- );
212
- return new Response(JSON.stringify({ success: true }), {
213
- status: 200,
214
- headers: { "Content-Type": "application/json" },
215
- });
216
- },
217
-
218
- deleteBundle: async (params, _request, api) => {
219
- await api.deleteBundleById(requireRouteParam(params, "id"));
220
- return new Response(JSON.stringify({ success: true }), {
221
- status: 200,
222
- headers: { "Content-Type": "application/json" },
223
- });
224
- },
225
-
226
- getChannels: async (_params, _request, api) => {
227
- const response: ChannelsResponse = {
228
- data: { channels: await api.getChannels() },
229
- };
230
- return new Response(JSON.stringify(response), {
231
- status: 200,
232
- headers: { "Content-Type": "application/json" },
233
- });
234
- },
235
-
236
- createChannel: async (_params, request, api) => {
237
- const result = await api.insertChannel(
238
- requireChannelInsertInput(await request.json()),
239
- );
240
- return new Response(JSON.stringify({ data: result }), {
241
- status: result.inserted ? 201 : 200,
242
- headers: { "Content-Type": "application/json" },
243
- });
244
- },
245
-
246
- deleteChannel: async (params, _request, api) => {
247
- const result = await api.deleteChannel({
248
- id: decodeMaybe(requireRouteParam(params, "id")) ?? "",
249
- });
250
- if (result.deleted) {
251
- return new Response(null, { status: 204 });
252
- }
253
- const status = result.reason === "not_found" ? 404 : 409;
254
- return new Response(JSON.stringify({ data: result }), {
255
- status,
256
- headers: { "Content-Type": "application/json" },
257
- });
258
- },
259
- });
@@ -1,7 +0,0 @@
1
- export class HandlerBadRequestError extends Error {
2
- readonly name = "HandlerBadRequestError";
3
-
4
- constructor(message: string) {
5
- super(message);
6
- }
7
- }
@@ -1,262 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import {
4
- createApi,
5
- createAdminHandler,
6
- testBundle,
7
- } from "./handler.testFixtures";
8
-
9
- describe("createHandlers admin routes", () => {
10
- it("does not match client routes", async () => {
11
- const api = createApi();
12
- const handler = createAdminHandler(api);
13
- const response = await handler(new Request("http://localhost/version"));
14
-
15
- expect(response.status).toBe(404);
16
- });
17
-
18
- it("exposes the canonical Channel-row route and removes the legacy path", async () => {
19
- const api = createApi();
20
- const handler = createAdminHandler(api);
21
-
22
- const response = await handler(new Request("http://localhost/channels"));
23
- const legacyResponse = await handler(
24
- new Request("http://localhost/bundles/channels"),
25
- );
26
-
27
- expect(response.status).toBe(200);
28
- await expect(response.json()).resolves.toEqual({
29
- data: {
30
- channels: [{ id: "channel-production", name: "production" }],
31
- },
32
- });
33
- expect(legacyResponse.status).toBe(404);
34
- });
35
-
36
- it("returns 201 when the canonical route inserts a Channel", async () => {
37
- const api = createApi();
38
- api.insertChannel.mockResolvedValueOnce({
39
- row: { id: "candidate-id", name: "preview" },
40
- inserted: true,
41
- });
42
- const handler = createAdminHandler(api);
43
-
44
- const response = await handler(
45
- new Request("http://localhost/channels", {
46
- method: "POST",
47
- headers: { "Content-Type": "application/json" },
48
- body: JSON.stringify({
49
- row: { id: "candidate-id", name: "preview" },
50
- onConflict: "returnExisting",
51
- }),
52
- }),
53
- );
54
-
55
- expect(response.status).toBe(201);
56
- await expect(response.json()).resolves.toEqual({
57
- data: {
58
- row: { id: "candidate-id", name: "preview" },
59
- inserted: true,
60
- },
61
- });
62
- });
63
-
64
- it("returns the canonical row when a Channel already exists", async () => {
65
- const api = createApi();
66
- api.insertChannel.mockResolvedValueOnce({
67
- row: { id: "canonical-id", name: "preview" },
68
- inserted: false,
69
- });
70
- const handler = createAdminHandler(api);
71
-
72
- const response = await handler(
73
- new Request("http://localhost/channels", {
74
- method: "POST",
75
- headers: { "Content-Type": "application/json" },
76
- body: JSON.stringify({
77
- row: { id: "candidate-id", name: "preview" },
78
- onConflict: "returnExisting",
79
- }),
80
- }),
81
- );
82
-
83
- expect(response.status).toBe(200);
84
- await expect(response.json()).resolves.toEqual({
85
- data: {
86
- row: { id: "canonical-id", name: "preview" },
87
- inserted: false,
88
- },
89
- });
90
- expect(api.insertChannel).toHaveBeenCalledWith({
91
- row: { id: "candidate-id", name: "preview" },
92
- onConflict: "returnExisting",
93
- });
94
- });
95
-
96
- it.each([
97
- { row: { name: "preview" } },
98
- { row: { id: "", name: "preview" }, onConflict: "returnExisting" },
99
- { row: { id: "channel-preview", name: "" }, onConflict: "returnExisting" },
100
- {
101
- row: { id: "channel-preview", name: "x".repeat(256) },
102
- onConflict: "returnExisting",
103
- },
104
- ])(
105
- "rejects malformed Channel insert input before persistence",
106
- async (body) => {
107
- const api = createApi();
108
- const handler = createAdminHandler(api);
109
-
110
- const response = await handler(
111
- new Request("http://localhost/channels", {
112
- method: "POST",
113
- headers: { "Content-Type": "application/json" },
114
- body: JSON.stringify(body),
115
- }),
116
- );
117
-
118
- expect(response.status).toBe(400);
119
- expect(api.insertChannel).not.toHaveBeenCalled();
120
- },
121
- );
122
-
123
- it("returns no content after deleting an empty Channel", async () => {
124
- const api = createApi();
125
- api.deleteChannel.mockResolvedValueOnce({ deleted: true });
126
- const handler = createAdminHandler(api);
127
-
128
- const response = await handler(
129
- new Request("http://localhost/channels/channel-preview", {
130
- method: "DELETE",
131
- }),
132
- );
133
-
134
- expect(response.status).toBe(204);
135
- await expect(response.text()).resolves.toBe("");
136
- });
137
-
138
- it.each([
139
- [{ deleted: false, reason: "not_found" } as const, 404],
140
- [{ deleted: false, reason: "not_empty" } as const, 409],
141
- ])("maps Channel deletion result %j to HTTP %i", async (result, status) => {
142
- const api = createApi();
143
- api.deleteChannel.mockResolvedValueOnce(result);
144
- const handler = createAdminHandler(api);
145
-
146
- const response = await handler(
147
- new Request("http://localhost/channels/channel-preview", {
148
- method: "DELETE",
149
- }),
150
- );
151
-
152
- expect(response.status).toBe(status);
153
- await expect(response.json()).resolves.toEqual({ data: result });
154
- expect(api.deleteChannel).toHaveBeenCalledWith({ id: "channel-preview" });
155
- });
156
-
157
- it("mounts bundle routes when explicitly enabled", async () => {
158
- const api = createApi();
159
- api.getBundles.mockResolvedValueOnce({
160
- data: [],
161
- pagination: {
162
- total: 0,
163
- hasNextPage: false,
164
- hasPreviousPage: false,
165
- currentPage: 1,
166
- totalPages: 0,
167
- },
168
- });
169
- const handler = createAdminHandler(api);
170
- const response = await handler(new Request("http://localhost/bundles"));
171
-
172
- expect(response.status).toBe(200);
173
- expect(api.getBundles).toHaveBeenCalledWith({
174
- cursor: undefined,
175
- limit: 50,
176
- page: undefined,
177
- where: {},
178
- });
179
- });
180
-
181
- it("forwards an explicit bundle id order direction", async () => {
182
- const api = createApi();
183
- const handler = createAdminHandler(api);
184
-
185
- const response = await handler(
186
- new Request("http://localhost/bundles?orderDirection=asc"),
187
- );
188
-
189
- expect(response.status).toBe(200);
190
- expect(api.getBundles).toHaveBeenCalledWith({
191
- cursor: undefined,
192
- limit: 50,
193
- orderBy: { field: "id", direction: "asc" },
194
- page: undefined,
195
- where: {},
196
- });
197
- });
198
-
199
- it("does not treat Release policy query parameters as Bundle filters", async () => {
200
- const api = createApi();
201
- const handler = createAdminHandler(api);
202
-
203
- const response = await handler(
204
- new Request(
205
- "http://localhost/bundles?channel=production&enabled=true&targetAppVersion=1.0.0&fingerprintHash=abc",
206
- ),
207
- );
208
-
209
- expect(response.status).toBe(200);
210
- expect(api.getBundles).toHaveBeenCalledWith({
211
- cursor: undefined,
212
- limit: 50,
213
- page: undefined,
214
- where: {},
215
- });
216
- });
217
-
218
- it("rejects an invalid bundle id order direction", async () => {
219
- const api = createApi();
220
- const handler = createAdminHandler(api);
221
-
222
- const response = await handler(
223
- new Request("http://localhost/bundles?orderDirection=random"),
224
- );
225
-
226
- expect(response.status).toBe(400);
227
- expect(api.getBundles).not.toHaveBeenCalled();
228
- });
229
-
230
- it.each([
231
- "after=bundle-2&before=bundle-4",
232
- "page=2&after=bundle-2",
233
- "page=2&before=bundle-4",
234
- `page=${Number.MAX_SAFE_INTEGER}`,
235
- ])("rejects invalid pagination parameters: %s", async (query) => {
236
- const api = createApi();
237
- const handler = createAdminHandler(api);
238
-
239
- const response = await handler(
240
- new Request(`http://localhost/bundles?${query}`),
241
- );
242
-
243
- expect(response.status).toBe(400);
244
- expect(api.getBundles).not.toHaveBeenCalled();
245
- });
246
-
247
- it("rejects a bundle batch before mutation when atomic insertion is unavailable", async () => {
248
- const api = createApi();
249
- const handler = createAdminHandler(api);
250
-
251
- const response = await handler(
252
- new Request("http://localhost/bundles", {
253
- method: "POST",
254
- headers: { "Content-Type": "application/json" },
255
- body: JSON.stringify([testBundle, { ...testBundle, id: "bundle-2" }]),
256
- }),
257
- );
258
-
259
- expect(response.status).toBe(400);
260
- expect(api.insertBundle).not.toHaveBeenCalled();
261
- });
262
- });
@@ -1,105 +0,0 @@
1
- import type { Platform } from "@hot-updater/core";
2
-
3
- import { HandlerBadRequestError } from "./handlerErrors";
4
-
5
- type PositiveIntegerBounds = {
6
- readonly defaultValue: number;
7
- readonly maxValue: number;
8
- };
9
-
10
- export const decodeMaybe = (value: string | undefined): string | undefined => {
11
- if (value === undefined) return undefined;
12
- try {
13
- return decodeURIComponent(value);
14
- } catch {
15
- return value;
16
- }
17
- };
18
-
19
- export const isPlatform = (value: string): value is Platform =>
20
- value === "ios" || value === "android";
21
-
22
- export const requireRouteParam = (
23
- params: Record<string, string>,
24
- key: string,
25
- ): string => {
26
- const value = params[key];
27
- if (!value) {
28
- throw new HandlerBadRequestError(`Missing route parameter: ${key}`);
29
- }
30
- return value;
31
- };
32
-
33
- export const requirePlatformParam = (
34
- params: Record<string, string>,
35
- ): Platform => {
36
- const platform = requireRouteParam(params, "platform");
37
- if (!isPlatform(platform)) {
38
- throw new HandlerBadRequestError(
39
- `Invalid platform: ${platform}. Expected 'ios' or 'android'.`,
40
- );
41
- }
42
- return platform;
43
- };
44
-
45
- export const parseBooleanSearchParam = (
46
- url: URL,
47
- key: string,
48
- ): boolean | undefined => {
49
- const value = url.searchParams.get(key);
50
- if (value === null) return undefined;
51
- if (value === "true") return true;
52
- if (value === "false") return false;
53
- throw new HandlerBadRequestError(
54
- `The '${key}' query parameter must be 'true' or 'false'.`,
55
- );
56
- };
57
-
58
- export const parseNullableStringSearchParam = (
59
- url: URL,
60
- key: string,
61
- ): string | null | undefined => {
62
- const value = url.searchParams.get(key);
63
- if (value === null) return undefined;
64
- return value === "null" ? null : value;
65
- };
66
-
67
- export const parseStringArraySearchParam = (
68
- url: URL,
69
- key: string,
70
- ): string[] | undefined => {
71
- const values = url.searchParams.getAll(key);
72
- return values.length > 0 ? values : undefined;
73
- };
74
-
75
- export const parsePositiveIntegerSearchParam = (
76
- url: URL,
77
- key: string,
78
- bounds: PositiveIntegerBounds,
79
- ): number => {
80
- const value = url.searchParams.get(key);
81
- if (value === null) return bounds.defaultValue;
82
- const parsed = Number(value);
83
- if (!Number.isInteger(parsed) || parsed < 1 || parsed > bounds.maxValue) {
84
- throw new HandlerBadRequestError(
85
- `The '${key}' query parameter must be a positive integer between 1 and ${bounds.maxValue}.`,
86
- );
87
- }
88
- return parsed;
89
- };
90
-
91
- export const parseNonNegativeIntegerSearchParam = (
92
- url: URL,
93
- key: string,
94
- defaultValue: number,
95
- ): number => {
96
- const value = url.searchParams.get(key);
97
- if (value === null) return defaultValue;
98
- const parsed = Number(value);
99
- if (!Number.isSafeInteger(parsed) || parsed < 0) {
100
- throw new HandlerBadRequestError(
101
- `The '${key}' query parameter must be a non-negative integer.`,
102
- );
103
- }
104
- return parsed;
105
- };