@hot-updater/server 0.36.7 → 1.0.0-rc.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 (291) hide show
  1. package/dist/adapters/databaseConstraintErrors.cjs +23 -0
  2. package/dist/adapters/databaseConstraintErrors.mjs +21 -0
  3. package/dist/adapters/databasePluginUtils.cjs +117 -0
  4. package/dist/adapters/databasePluginUtils.mjs +106 -0
  5. package/dist/adapters/drizzle.cjs +53 -176
  6. package/dist/adapters/drizzle.d.cts +6 -4
  7. package/dist/adapters/drizzle.d.mts +6 -4
  8. package/dist/adapters/drizzle.mjs +54 -177
  9. package/dist/adapters/drizzleCrud.cjs +250 -0
  10. package/dist/adapters/drizzleCrud.mjs +249 -0
  11. package/dist/adapters/drizzleLazyDB.cjs +84 -36
  12. package/dist/adapters/drizzleLazyDB.mjs +84 -36
  13. package/dist/adapters/drizzleQuery.cjs +68 -0
  14. package/dist/adapters/drizzleQuery.mjs +67 -0
  15. package/dist/adapters/kysely.cjs +18 -138
  16. package/dist/adapters/kysely.d.cts +3 -12
  17. package/dist/adapters/kysely.d.mts +3 -12
  18. package/dist/adapters/kysely.mjs +19 -139
  19. package/dist/adapters/kyselyCrud.cjs +254 -0
  20. package/dist/adapters/kyselyCrud.mjs +253 -0
  21. package/dist/adapters/kyselyQuery.cjs +56 -0
  22. package/dist/adapters/kyselyQuery.mjs +55 -0
  23. package/dist/adapters/mongodb.cjs +21 -174
  24. package/dist/adapters/mongodb.d.cts +3 -2
  25. package/dist/adapters/mongodb.d.mts +3 -2
  26. package/dist/adapters/mongodb.mjs +21 -174
  27. package/dist/adapters/mongodbCollections.cjs +36 -0
  28. package/dist/adapters/mongodbCollections.mjs +30 -0
  29. package/dist/adapters/mongodbQuery.cjs +77 -0
  30. package/dist/adapters/mongodbQuery.mjs +70 -0
  31. package/dist/adapters/mongodbReads.cjs +148 -0
  32. package/dist/adapters/mongodbReads.mjs +147 -0
  33. package/dist/adapters/mongodbWrites.cjs +134 -0
  34. package/dist/adapters/mongodbWrites.mjs +133 -0
  35. package/dist/adapters/prisma.cjs +205 -180
  36. package/dist/adapters/prisma.d.cts +3 -3
  37. package/dist/adapters/prisma.d.mts +3 -3
  38. package/dist/adapters/prisma.mjs +206 -181
  39. package/dist/adapters/prismaQuery.cjs +58 -0
  40. package/dist/adapters/prismaQuery.mjs +56 -0
  41. package/dist/adapters/prismaRows.cjs +198 -0
  42. package/dist/adapters/prismaRows.mjs +188 -0
  43. package/dist/apiKeys.cjs +139 -0
  44. package/dist/apiKeys.d.cts +50 -0
  45. package/dist/apiKeys.d.mts +50 -0
  46. package/dist/apiKeys.mjs +133 -0
  47. package/dist/createHotUpdaterCore.cjs +48 -26
  48. package/dist/createHotUpdaterCore.d.cts +49 -17
  49. package/dist/createHotUpdaterCore.d.mts +49 -17
  50. package/dist/createHotUpdaterCore.mjs +51 -29
  51. package/dist/db/createBundleDiff.cjs +45 -68
  52. package/dist/db/createBundleDiff.d.cts +3 -3
  53. package/dist/db/createBundleDiff.d.mts +3 -3
  54. package/dist/db/createBundleDiff.mjs +47 -68
  55. package/dist/db/databasePluginCore.cjs +138 -0
  56. package/dist/db/databasePluginCore.mjs +137 -0
  57. package/dist/db/fixedMigrator.cjs +36 -93
  58. package/dist/db/fixedMigrator.mjs +36 -93
  59. package/dist/db/fixedMigratorMongo.cjs +319 -0
  60. package/dist/db/fixedMigratorMongo.mjs +319 -0
  61. package/dist/db/fixedMigratorShared.cjs +23 -0
  62. package/dist/db/fixedMigratorShared.mjs +18 -0
  63. package/dist/db/mongoMigrationExecution.cjs +11 -0
  64. package/dist/db/mongoMigrationExecution.mjs +11 -0
  65. package/dist/db/releaseCatalog.cjs +66 -0
  66. package/dist/db/releaseCatalog.d.cts +17 -0
  67. package/dist/db/releaseCatalog.d.mts +17 -0
  68. package/dist/db/releaseCatalog.mjs +64 -0
  69. package/dist/db/schema/mongodb.cjs +14 -6
  70. package/dist/db/schema/mongodb.mjs +14 -6
  71. package/dist/db/schema/registry.cjs +0 -2
  72. package/dist/db/schema/registry.mjs +1 -2
  73. package/dist/db/schema/sql.cjs +31 -14
  74. package/dist/db/schema/sql.mjs +32 -13
  75. package/dist/db/schema/sqlOperations.cjs +4 -4
  76. package/dist/db/schema/sqlOperations.mjs +5 -5
  77. package/dist/db/schemaGenerators.cjs +52 -18
  78. package/dist/db/schemaGenerators.mjs +52 -18
  79. package/dist/db/schemaReadiness.cjs +4 -3
  80. package/dist/db/schemaReadiness.mjs +4 -3
  81. package/dist/db/sqlMigrationExecution.cjs +67 -0
  82. package/dist/db/sqlMigrationExecution.mjs +66 -0
  83. package/dist/db/types.cjs +2 -6
  84. package/dist/db/types.d.cts +60 -16
  85. package/dist/db/types.d.mts +60 -16
  86. package/dist/db/types.mjs +3 -6
  87. package/dist/db/updateArtifacts.cjs +114 -60
  88. package/dist/db/updateArtifacts.mjs +117 -62
  89. package/dist/handler.cjs +108 -282
  90. package/dist/handler.d.cts +3 -46
  91. package/dist/handler.d.mts +3 -46
  92. package/dist/handler.mjs +107 -281
  93. package/dist/handlerBundleRoutes.cjs +155 -0
  94. package/dist/handlerBundleRoutes.mjs +155 -0
  95. package/dist/handlerErrors.cjs +9 -0
  96. package/dist/handlerErrors.mjs +9 -0
  97. package/dist/handlerParameters.cjs +39 -0
  98. package/dist/handlerParameters.mjs +34 -0
  99. package/dist/handlerReleaseCatalogRoutes.cjs +111 -0
  100. package/dist/handlerReleaseCatalogRoutes.mjs +110 -0
  101. package/dist/handlerReleaseManagementRoutes.cjs +125 -0
  102. package/dist/handlerReleaseManagementRoutes.mjs +124 -0
  103. package/dist/handlerTypes.d.cts +63 -0
  104. package/dist/handlerTypes.d.mts +63 -0
  105. package/dist/handlerVersionRoutes.cjs +10 -0
  106. package/dist/handlerVersionRoutes.d.cts +4 -0
  107. package/dist/handlerVersionRoutes.d.mts +4 -0
  108. package/dist/handlerVersionRoutes.mjs +9 -0
  109. package/dist/index.cjs +10 -1
  110. package/dist/index.d.cts +9 -3
  111. package/dist/index.d.mts +9 -3
  112. package/dist/index.mjs +5 -2
  113. package/dist/insights/bounded/activeOverview.cjs +87 -0
  114. package/dist/insights/bounded/activeOverview.mjs +85 -0
  115. package/dist/insights/bounded/installationSearch.cjs +42 -0
  116. package/dist/insights/bounded/installationSearch.mjs +42 -0
  117. package/dist/insights/bounded/persistence.cjs +39 -0
  118. package/dist/insights/bounded/persistence.mjs +38 -0
  119. package/dist/insights/bounded/provider.cjs +170 -0
  120. package/dist/insights/bounded/provider.d.cts +7 -0
  121. package/dist/insights/bounded/provider.d.mts +7 -0
  122. package/dist/insights/bounded/provider.mjs +170 -0
  123. package/dist/insights/bounded/scan.cjs +144 -0
  124. package/dist/insights/bounded/scan.mjs +138 -0
  125. package/dist/insights/domain.d.cts +121 -0
  126. package/dist/insights/domain.d.mts +121 -0
  127. package/dist/insights/errors.cjs +22 -0
  128. package/dist/insights/errors.mjs +20 -0
  129. package/dist/insights/eventInput.cjs +111 -0
  130. package/dist/insights/eventInput.mjs +111 -0
  131. package/dist/insights/persistence.d.cts +6 -0
  132. package/dist/insights/persistence.d.mts +6 -0
  133. package/dist/insights/queryInput.cjs +58 -0
  134. package/dist/insights/queryInput.mjs +55 -0
  135. package/dist/insights/routes.cjs +63 -0
  136. package/dist/insights/routes.mjs +61 -0
  137. package/dist/insights/types.d.cts +17 -0
  138. package/dist/insights/types.d.mts +17 -0
  139. package/dist/node.cjs +19 -12
  140. package/dist/node.d.cts +15 -10
  141. package/dist/node.d.mts +15 -10
  142. package/dist/node.mjs +19 -13
  143. package/dist/package.cjs +1 -1
  144. package/dist/package.mjs +1 -1
  145. package/dist/schema/dsl.cjs +19 -2
  146. package/dist/schema/dsl.mjs +17 -3
  147. package/dist/schema/index.cjs +1 -8
  148. package/dist/schema/index.mjs +2 -8
  149. package/dist/schema/types.cjs +3 -1
  150. package/dist/schema/types.mjs +3 -2
  151. package/dist/schema/v1_0_0.cjs +364 -0
  152. package/dist/schema/v1_0_0.mjs +357 -0
  153. package/dist/storageAccess.cjs +69 -25
  154. package/dist/storageAccess.mjs +68 -25
  155. package/dist/types/index.d.cts +4 -3
  156. package/dist/types/index.d.mts +5 -4
  157. package/package.json +8 -7
  158. package/src/adapters/databaseConstraintErrors.ts +25 -0
  159. package/src/adapters/databasePluginTestDatabase.ts +106 -0
  160. package/src/adapters/databasePluginUtils.spec.ts +29 -0
  161. package/src/adapters/databasePluginUtils.ts +214 -0
  162. package/src/adapters/drizzle.spec.ts +208 -47
  163. package/src/adapters/drizzle.ts +106 -293
  164. package/src/adapters/drizzleCrud.ts +419 -0
  165. package/src/adapters/drizzleLazyDB.ts +206 -100
  166. package/src/adapters/drizzleQuery.ts +164 -0
  167. package/src/adapters/kysely.spec.ts +126 -88
  168. package/src/adapters/kysely.ts +76 -334
  169. package/src/adapters/kyselyCrud.ts +588 -0
  170. package/src/adapters/kyselyQuery.ts +128 -0
  171. package/src/adapters/mongodb.spec.ts +141 -0
  172. package/src/adapters/mongodb.ts +60 -288
  173. package/src/adapters/mongodbCollections.ts +62 -0
  174. package/src/adapters/mongodbQuery.ts +226 -0
  175. package/src/adapters/mongodbReads.ts +311 -0
  176. package/src/adapters/mongodbRows.spec.ts +64 -0
  177. package/src/adapters/mongodbRows.ts +118 -0
  178. package/src/adapters/mongodbTestClient.ts +342 -0
  179. package/src/adapters/mongodbTestFilter.ts +166 -0
  180. package/src/adapters/mongodbWrites.ts +260 -0
  181. package/src/adapters/prisma.spec.ts +196 -0
  182. package/src/adapters/prisma.ts +417 -292
  183. package/src/adapters/prismaQuery.ts +129 -0
  184. package/src/adapters/prismaRows.spec.ts +98 -0
  185. package/src/adapters/prismaRows.ts +301 -0
  186. package/src/adapters/prismaTestClient.ts +396 -0
  187. package/src/apiKeys.integration.spec.ts +192 -0
  188. package/src/apiKeys.spec.ts +162 -0
  189. package/src/apiKeys.ts +220 -0
  190. package/src/createHotUpdaterCore.ts +164 -100
  191. package/src/db/bundleRows.spec.ts +164 -0
  192. package/src/db/bundleRows.ts +10 -140
  193. package/src/db/createBundleDiff.spec.ts +172 -127
  194. package/src/db/createBundleDiff.ts +91 -110
  195. package/src/db/databasePluginCore.spec.ts +62 -0
  196. package/src/db/databasePluginCore.testFixtures.ts +76 -0
  197. package/src/db/databasePluginCore.ts +185 -0
  198. package/src/db/databasePluginUpdateCheck.bench.ts +107 -0
  199. package/src/db/fixedMigrator.spec.ts +184 -42
  200. package/src/db/fixedMigrator.ts +64 -205
  201. package/src/db/fixedMigratorMongo.spec.ts +192 -0
  202. package/src/db/fixedMigratorMongo.ts +425 -0
  203. package/src/db/fixedMigratorShared.ts +36 -0
  204. package/src/db/hotUpdaterSchema.ts +0 -1
  205. package/src/db/index.spec.ts +333 -1025
  206. package/src/db/mongoMigrationExecution.ts +23 -0
  207. package/src/db/node-sqlite.d.ts +25 -0
  208. package/src/db/releaseCatalog.ts +148 -0
  209. package/src/db/schema/mongodb.ts +20 -6
  210. package/src/db/schema/sql.ts +52 -11
  211. package/src/db/schema/sqlOperations.ts +5 -4
  212. package/src/db/schemaGenerators.ts +107 -23
  213. package/src/db/schemaReadiness.ts +2 -1
  214. package/src/db/sqlMigrationExecution.spec.ts +65 -0
  215. package/src/db/sqlMigrationExecution.ts +108 -0
  216. package/src/db/types.spec.ts +55 -0
  217. package/src/db/types.ts +129 -65
  218. package/src/db/updateArtifacts.spec.ts +359 -0
  219. package/src/db/updateArtifacts.ts +290 -126
  220. package/src/handler-standalone.integration.spec.ts +401 -364
  221. package/src/handler.spec.ts +137 -582
  222. package/src/handler.testFixtures.ts +30 -0
  223. package/src/handler.ts +218 -616
  224. package/src/handlerAuth.integration.spec.ts +33 -0
  225. package/src/handlerBundleRoutes.ts +259 -0
  226. package/src/handlerErrors.ts +7 -0
  227. package/src/handlerManagement.spec.ts +262 -0
  228. package/src/handlerParameters.ts +105 -0
  229. package/src/handlerReleaseCatalogRoutes.ts +154 -0
  230. package/src/handlerReleaseManagementRoutes.ts +213 -0
  231. package/src/handlerTypes.ts +96 -0
  232. package/src/handlerVersionRoutes.ts +12 -0
  233. package/src/index.ts +22 -2
  234. package/src/insights/bounded/activeOverview.spec.ts +189 -0
  235. package/src/insights/bounded/activeOverview.ts +148 -0
  236. package/src/insights/bounded/installationSearch.spec.ts +130 -0
  237. package/src/insights/bounded/installationSearch.ts +69 -0
  238. package/src/insights/bounded/persistence.ts +43 -0
  239. package/src/insights/bounded/provider.spec.ts +219 -0
  240. package/src/insights/bounded/provider.ts +229 -0
  241. package/src/insights/bounded/scan.ts +235 -0
  242. package/src/insights/domain.ts +139 -0
  243. package/src/insights/errors.ts +18 -0
  244. package/src/insights/eventInput.ts +168 -0
  245. package/src/insights/insights.integration.spec.ts +144 -0
  246. package/src/insights/persistence.ts +10 -0
  247. package/src/insights/queryInput.ts +102 -0
  248. package/src/insights/routes.ts +123 -0
  249. package/src/insights/types.ts +44 -0
  250. package/src/node.spec.ts +79 -10
  251. package/src/node.ts +20 -17
  252. package/src/releaseCatalogRoutes.integration.spec.ts +238 -0
  253. package/src/runtime.spec.ts +126 -959
  254. package/src/runtime.testFixtures.ts +71 -0
  255. package/src/schema/dsl-all-versions.spec.ts +26 -17
  256. package/src/schema/dsl.ts +41 -2
  257. package/src/schema/index.ts +3 -9
  258. package/src/schema/types.ts +9 -3
  259. package/src/schema/v1_0_0.spec.ts +146 -0
  260. package/src/schema/v1_0_0.ts +465 -0
  261. package/src/storageAccess.spec.ts +127 -32
  262. package/src/storageAccess.ts +106 -55
  263. package/src/types/index.ts +2 -1
  264. package/dist/db/bundleRows.cjs +0 -82
  265. package/dist/db/bundleRows.d.cts +0 -33
  266. package/dist/db/bundleRows.d.mts +0 -33
  267. package/dist/db/bundleRows.mjs +0 -79
  268. package/dist/db/pluginCore.cjs +0 -242
  269. package/dist/db/pluginCore.mjs +0 -241
  270. package/dist/db/schema/sqlMigrations.cjs +0 -74
  271. package/dist/db/schema/sqlMigrations.mjs +0 -73
  272. package/dist/db/schemaEnhancements.cjs +0 -20
  273. package/dist/db/schemaEnhancements.mjs +0 -19
  274. package/dist/route.cjs +0 -7
  275. package/dist/route.mjs +0 -7
  276. package/dist/schema/v0_21_0.cjs +0 -38
  277. package/dist/schema/v0_21_0.mjs +0 -37
  278. package/dist/schema/v0_29_0.cjs +0 -45
  279. package/dist/schema/v0_29_0.mjs +0 -44
  280. package/dist/schema/v0_31_0.cjs +0 -82
  281. package/dist/schema/v0_31_0.mjs +0 -80
  282. package/src/db/pluginCore.spec.ts +0 -1095
  283. package/src/db/pluginCore.ts +0 -475
  284. package/src/db/pluginUpdateCheck.bench.ts +0 -254
  285. package/src/db/schema/sqlMigrations.ts +0 -219
  286. package/src/db/schemaEnhancements.ts +0 -55
  287. package/src/route.ts +0 -7
  288. package/src/schema/v0_21_0.ts +0 -52
  289. package/src/schema/v0_29_0.ts +0 -62
  290. package/src/schema/v0_31_0.spec.ts +0 -73
  291. package/src/schema/v0_31_0.ts +0 -120
@@ -0,0 +1,198 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
3
+ //#region src/adapters/prismaRows.ts
4
+ var PrismaAdapterError = class extends Error {
5
+ name = "PrismaAdapterError";
6
+ constructor(reason) {
7
+ super(`Invalid Prisma plugin state: ${reason}`);
8
+ this.reason = reason;
9
+ }
10
+ };
11
+ const isRecord = (value) => typeof value === "object" && value !== null;
12
+ const hasDelegateMethods = (value) => isRecord(value) && typeof value["count"] === "function" && typeof value["create"] === "function" && typeof value["deleteMany"] === "function" && typeof value["findFirst"] === "function" && typeof value["findMany"] === "function" && typeof value["update"] === "function" && typeof value["upsert"] === "function";
13
+ const modelDelegates = {
14
+ bundles: "bundles",
15
+ bundle_patches: "bundle_patches",
16
+ bundle_events: "bundle_events",
17
+ channels: "channels",
18
+ api_keys: "api_keys",
19
+ releases: "releases",
20
+ release_catalogs: "release_catalogs"
21
+ };
22
+ const getPrismaDelegate = (client, model) => {
23
+ const delegate = Object.entries(client).find(([key]) => key === modelDelegates[model])?.[1];
24
+ if (delegate === void 0) throw new PrismaAdapterError(`missing model delegate "${model}"`);
25
+ if (!hasDelegateMethods(delegate)) throw new PrismaAdapterError(`invalid model delegate "${model}"`);
26
+ return delegate;
27
+ };
28
+ const readString = (row, field) => {
29
+ const value = row[field];
30
+ if (typeof value !== "string") throw new PrismaAdapterError(`expected string field "${field}"`);
31
+ return value;
32
+ };
33
+ const readNullableString = (row, field) => {
34
+ const value = row[field];
35
+ if (value === null) return null;
36
+ if (typeof value !== "string") throw new PrismaAdapterError(`expected nullable string field "${field}"`);
37
+ return value;
38
+ };
39
+ const readByteSize = (row, field) => {
40
+ const value = row[field];
41
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new PrismaAdapterError(`expected byte-size field "${field}"`);
42
+ return value;
43
+ };
44
+ const parsePrismaBundleRow = (value) => {
45
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid bundle row");
46
+ const platform = value["platform"];
47
+ if (platform !== "android" && platform !== "ios") throw new PrismaAdapterError("expected platform \"android\" or \"ios\"");
48
+ const metadata = value["metadata"];
49
+ if (!(0, _hot_updater_plugin_core.isDatabaseMetadataObject)(metadata)) throw new PrismaAdapterError("invalid metadata field");
50
+ return {
51
+ id: readString(value, "id"),
52
+ platform,
53
+ file_hash: readString(value, "file_hash"),
54
+ git_commit_hash: readNullableString(value, "git_commit_hash"),
55
+ storage_uri: readString(value, "storage_uri"),
56
+ archive_byte_size: readByteSize(value, "archive_byte_size"),
57
+ metadata,
58
+ manifest_storage_uri: readNullableString(value, "manifest_storage_uri"),
59
+ manifest_file_hash: readNullableString(value, "manifest_file_hash"),
60
+ asset_base_storage_uri: readNullableString(value, "asset_base_storage_uri")
61
+ };
62
+ };
63
+ const parsePrismaChannelRow = (value) => {
64
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid channel row");
65
+ return {
66
+ id: readString(value, "id"),
67
+ name: readString(value, "name")
68
+ };
69
+ };
70
+ const parsePrismaPatchRow = (value) => {
71
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid patch row");
72
+ const orderIndex = value["order_index"];
73
+ if (typeof orderIndex !== "number") throw new PrismaAdapterError("invalid patch order_index field");
74
+ return {
75
+ id: readString(value, "id"),
76
+ bundle_id: readString(value, "bundle_id"),
77
+ base_bundle_id: readString(value, "base_bundle_id"),
78
+ base_file_hash: readString(value, "base_file_hash"),
79
+ patch_file_hash: readString(value, "patch_file_hash"),
80
+ patch_storage_uri: readString(value, "patch_storage_uri"),
81
+ byte_size: readByteSize(value, "byte_size"),
82
+ order_index: orderIndex
83
+ };
84
+ };
85
+ const readNumber = (row, field) => {
86
+ const value = row[field];
87
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new PrismaAdapterError(`expected number field "${field}"`);
88
+ return value;
89
+ };
90
+ const parsePrismaBundleEventRow = (value) => {
91
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid event row");
92
+ const type = readString(value, "type");
93
+ const platform = readString(value, "platform");
94
+ const fromBundleId = readNullableString(value, "from_bundle_id");
95
+ const updateStrategy = readNullableString(value, "update_strategy");
96
+ if (platform !== "ios" && platform !== "android" || !((type === "UPDATE_APPLIED" || type === "RECOVERED" || type === "RELEASE_ADOPTED") && typeof fromBundleId === "string" && (updateStrategy === "fingerprint" || updateStrategy === "appVersion") || type === "UNCHANGED" && fromBundleId === null && updateStrategy === null)) throw new PrismaAdapterError("invalid event shape");
97
+ return {
98
+ id: readString(value, "id"),
99
+ type,
100
+ install_id: readString(value, "install_id"),
101
+ user_id: readNullableString(value, "user_id"),
102
+ username: readNullableString(value, "username"),
103
+ from_release_id: readNullableString(value, "from_release_id"),
104
+ from_bundle_id: fromBundleId,
105
+ to_release_id: readNullableString(value, "to_release_id"),
106
+ to_bundle_id: readString(value, "to_bundle_id"),
107
+ platform,
108
+ app_version: readString(value, "app_version"),
109
+ channel: readString(value, "channel"),
110
+ cohort: readString(value, "cohort"),
111
+ update_strategy: updateStrategy,
112
+ fingerprint_hash: readNullableString(value, "fingerprint_hash"),
113
+ sdk_version: readNullableString(value, "sdk_version"),
114
+ received_at_ms: readNumber(value, "received_at_ms")
115
+ };
116
+ };
117
+ const parsePrismaApiKeyRow = (value) => {
118
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid API key row");
119
+ const role = readString(value, "role");
120
+ if (role !== "client") throw new PrismaAdapterError("invalid API key role");
121
+ const revokedAt = value["revoked_at_ms"];
122
+ return {
123
+ id: readString(value, "id"),
124
+ hash: readString(value, "hash"),
125
+ name: readString(value, "name"),
126
+ prefix: readString(value, "prefix"),
127
+ role,
128
+ created_at_ms: readNumber(value, "created_at_ms"),
129
+ revoked_at_ms: revokedAt === null ? null : readNumber(value, "revoked_at_ms")
130
+ };
131
+ };
132
+ const parsePrismaReleaseRow = (value) => {
133
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid Release row");
134
+ const platform = readString(value, "platform");
135
+ const kind = readString(value, "kind");
136
+ const strategy = readString(value, "strategy");
137
+ const operation = readString(value, "operation");
138
+ const targetCohorts = value["target_cohorts"];
139
+ if (platform !== "ios" && platform !== "android" || kind !== "BUNDLE" && kind !== "EMBEDDED" || strategy !== "APP_VERSION" && strategy !== "FINGERPRINT" || operation !== "DEPLOY" && operation !== "PROMOTE" && operation !== "ROLLBACK" || !Array.isArray(targetCohorts) || !targetCohorts.every((cohort) => typeof cohort === "string")) throw new PrismaAdapterError("invalid Release fields");
140
+ const enabled = value["enabled"];
141
+ const shouldForceUpdate = value["should_force_update"];
142
+ if (typeof enabled !== "boolean" || typeof shouldForceUpdate !== "boolean") throw new PrismaAdapterError("invalid Release policy fields");
143
+ return {
144
+ bundle_id: readNullableString(value, "bundle_id"),
145
+ channel_id: readString(value, "channel_id"),
146
+ created_at_ms: readNumber(value, "created_at_ms"),
147
+ enabled,
148
+ fingerprint_hash: readNullableString(value, "fingerprint_hash"),
149
+ id: readString(value, "id"),
150
+ kind,
151
+ message: readNullableString(value, "message"),
152
+ operation,
153
+ platform,
154
+ revision: readNumber(value, "revision"),
155
+ rollout_cohort_count: readNumber(value, "rollout_cohort_count"),
156
+ scope_key: readString(value, "scope_key"),
157
+ should_force_update: shouldForceUpdate,
158
+ source_release_id: readNullableString(value, "source_release_id"),
159
+ strategy,
160
+ target_app_version: readNullableString(value, "target_app_version"),
161
+ target_cohorts: targetCohorts,
162
+ updated_at_ms: readNumber(value, "updated_at_ms")
163
+ };
164
+ };
165
+ const parsePrismaReleaseCatalogRow = (value) => {
166
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid catalog row");
167
+ const platform = readString(value, "platform");
168
+ const strategy = readString(value, "strategy");
169
+ const isTombstone = value["is_tombstone"];
170
+ if (platform !== "ios" && platform !== "android" || strategy !== "APP_VERSION" && strategy !== "FINGERPRINT" || typeof isTombstone !== "boolean") throw new PrismaAdapterError("invalid catalog fields");
171
+ return {
172
+ catalog_id: readString(value, "catalog_id"),
173
+ byte_size: readNumber(value, "byte_size"),
174
+ catalog_hash: readString(value, "catalog_hash"),
175
+ channel_id: readString(value, "channel_id"),
176
+ channel_key: readString(value, "channel_key"),
177
+ fingerprint_hash: readNullableString(value, "fingerprint_hash"),
178
+ generation: readNumber(value, "generation"),
179
+ is_tombstone: isTombstone,
180
+ payload: readString(value, "payload"),
181
+ platform,
182
+ scope_key: readString(value, "scope_key"),
183
+ strategy,
184
+ updated_at_ms: readNumber(value, "updated_at_ms")
185
+ };
186
+ };
187
+ const parsePrismaRows = (rows, parse) => rows.map(parse);
188
+ //#endregion
189
+ exports.PrismaAdapterError = PrismaAdapterError;
190
+ exports.getPrismaDelegate = getPrismaDelegate;
191
+ exports.parsePrismaApiKeyRow = parsePrismaApiKeyRow;
192
+ exports.parsePrismaBundleEventRow = parsePrismaBundleEventRow;
193
+ exports.parsePrismaBundleRow = parsePrismaBundleRow;
194
+ exports.parsePrismaChannelRow = parsePrismaChannelRow;
195
+ exports.parsePrismaPatchRow = parsePrismaPatchRow;
196
+ exports.parsePrismaReleaseCatalogRow = parsePrismaReleaseCatalogRow;
197
+ exports.parsePrismaReleaseRow = parsePrismaReleaseRow;
198
+ exports.parsePrismaRows = parsePrismaRows;
@@ -0,0 +1,188 @@
1
+ import { isDatabaseMetadataObject } from "@hot-updater/plugin-core";
2
+ //#region src/adapters/prismaRows.ts
3
+ var PrismaAdapterError = class extends Error {
4
+ name = "PrismaAdapterError";
5
+ constructor(reason) {
6
+ super(`Invalid Prisma plugin state: ${reason}`);
7
+ this.reason = reason;
8
+ }
9
+ };
10
+ const isRecord = (value) => typeof value === "object" && value !== null;
11
+ const hasDelegateMethods = (value) => isRecord(value) && typeof value["count"] === "function" && typeof value["create"] === "function" && typeof value["deleteMany"] === "function" && typeof value["findFirst"] === "function" && typeof value["findMany"] === "function" && typeof value["update"] === "function" && typeof value["upsert"] === "function";
12
+ const modelDelegates = {
13
+ bundles: "bundles",
14
+ bundle_patches: "bundle_patches",
15
+ bundle_events: "bundle_events",
16
+ channels: "channels",
17
+ api_keys: "api_keys",
18
+ releases: "releases",
19
+ release_catalogs: "release_catalogs"
20
+ };
21
+ const getPrismaDelegate = (client, model) => {
22
+ const delegate = Object.entries(client).find(([key]) => key === modelDelegates[model])?.[1];
23
+ if (delegate === void 0) throw new PrismaAdapterError(`missing model delegate "${model}"`);
24
+ if (!hasDelegateMethods(delegate)) throw new PrismaAdapterError(`invalid model delegate "${model}"`);
25
+ return delegate;
26
+ };
27
+ const readString = (row, field) => {
28
+ const value = row[field];
29
+ if (typeof value !== "string") throw new PrismaAdapterError(`expected string field "${field}"`);
30
+ return value;
31
+ };
32
+ const readNullableString = (row, field) => {
33
+ const value = row[field];
34
+ if (value === null) return null;
35
+ if (typeof value !== "string") throw new PrismaAdapterError(`expected nullable string field "${field}"`);
36
+ return value;
37
+ };
38
+ const readByteSize = (row, field) => {
39
+ const value = row[field];
40
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new PrismaAdapterError(`expected byte-size field "${field}"`);
41
+ return value;
42
+ };
43
+ const parsePrismaBundleRow = (value) => {
44
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid bundle row");
45
+ const platform = value["platform"];
46
+ if (platform !== "android" && platform !== "ios") throw new PrismaAdapterError("expected platform \"android\" or \"ios\"");
47
+ const metadata = value["metadata"];
48
+ if (!isDatabaseMetadataObject(metadata)) throw new PrismaAdapterError("invalid metadata field");
49
+ return {
50
+ id: readString(value, "id"),
51
+ platform,
52
+ file_hash: readString(value, "file_hash"),
53
+ git_commit_hash: readNullableString(value, "git_commit_hash"),
54
+ storage_uri: readString(value, "storage_uri"),
55
+ archive_byte_size: readByteSize(value, "archive_byte_size"),
56
+ metadata,
57
+ manifest_storage_uri: readNullableString(value, "manifest_storage_uri"),
58
+ manifest_file_hash: readNullableString(value, "manifest_file_hash"),
59
+ asset_base_storage_uri: readNullableString(value, "asset_base_storage_uri")
60
+ };
61
+ };
62
+ const parsePrismaChannelRow = (value) => {
63
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid channel row");
64
+ return {
65
+ id: readString(value, "id"),
66
+ name: readString(value, "name")
67
+ };
68
+ };
69
+ const parsePrismaPatchRow = (value) => {
70
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid patch row");
71
+ const orderIndex = value["order_index"];
72
+ if (typeof orderIndex !== "number") throw new PrismaAdapterError("invalid patch order_index field");
73
+ return {
74
+ id: readString(value, "id"),
75
+ bundle_id: readString(value, "bundle_id"),
76
+ base_bundle_id: readString(value, "base_bundle_id"),
77
+ base_file_hash: readString(value, "base_file_hash"),
78
+ patch_file_hash: readString(value, "patch_file_hash"),
79
+ patch_storage_uri: readString(value, "patch_storage_uri"),
80
+ byte_size: readByteSize(value, "byte_size"),
81
+ order_index: orderIndex
82
+ };
83
+ };
84
+ const readNumber = (row, field) => {
85
+ const value = row[field];
86
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new PrismaAdapterError(`expected number field "${field}"`);
87
+ return value;
88
+ };
89
+ const parsePrismaBundleEventRow = (value) => {
90
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid event row");
91
+ const type = readString(value, "type");
92
+ const platform = readString(value, "platform");
93
+ const fromBundleId = readNullableString(value, "from_bundle_id");
94
+ const updateStrategy = readNullableString(value, "update_strategy");
95
+ if (platform !== "ios" && platform !== "android" || !((type === "UPDATE_APPLIED" || type === "RECOVERED" || type === "RELEASE_ADOPTED") && typeof fromBundleId === "string" && (updateStrategy === "fingerprint" || updateStrategy === "appVersion") || type === "UNCHANGED" && fromBundleId === null && updateStrategy === null)) throw new PrismaAdapterError("invalid event shape");
96
+ return {
97
+ id: readString(value, "id"),
98
+ type,
99
+ install_id: readString(value, "install_id"),
100
+ user_id: readNullableString(value, "user_id"),
101
+ username: readNullableString(value, "username"),
102
+ from_release_id: readNullableString(value, "from_release_id"),
103
+ from_bundle_id: fromBundleId,
104
+ to_release_id: readNullableString(value, "to_release_id"),
105
+ to_bundle_id: readString(value, "to_bundle_id"),
106
+ platform,
107
+ app_version: readString(value, "app_version"),
108
+ channel: readString(value, "channel"),
109
+ cohort: readString(value, "cohort"),
110
+ update_strategy: updateStrategy,
111
+ fingerprint_hash: readNullableString(value, "fingerprint_hash"),
112
+ sdk_version: readNullableString(value, "sdk_version"),
113
+ received_at_ms: readNumber(value, "received_at_ms")
114
+ };
115
+ };
116
+ const parsePrismaApiKeyRow = (value) => {
117
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid API key row");
118
+ const role = readString(value, "role");
119
+ if (role !== "client") throw new PrismaAdapterError("invalid API key role");
120
+ const revokedAt = value["revoked_at_ms"];
121
+ return {
122
+ id: readString(value, "id"),
123
+ hash: readString(value, "hash"),
124
+ name: readString(value, "name"),
125
+ prefix: readString(value, "prefix"),
126
+ role,
127
+ created_at_ms: readNumber(value, "created_at_ms"),
128
+ revoked_at_ms: revokedAt === null ? null : readNumber(value, "revoked_at_ms")
129
+ };
130
+ };
131
+ const parsePrismaReleaseRow = (value) => {
132
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid Release row");
133
+ const platform = readString(value, "platform");
134
+ const kind = readString(value, "kind");
135
+ const strategy = readString(value, "strategy");
136
+ const operation = readString(value, "operation");
137
+ const targetCohorts = value["target_cohorts"];
138
+ if (platform !== "ios" && platform !== "android" || kind !== "BUNDLE" && kind !== "EMBEDDED" || strategy !== "APP_VERSION" && strategy !== "FINGERPRINT" || operation !== "DEPLOY" && operation !== "PROMOTE" && operation !== "ROLLBACK" || !Array.isArray(targetCohorts) || !targetCohorts.every((cohort) => typeof cohort === "string")) throw new PrismaAdapterError("invalid Release fields");
139
+ const enabled = value["enabled"];
140
+ const shouldForceUpdate = value["should_force_update"];
141
+ if (typeof enabled !== "boolean" || typeof shouldForceUpdate !== "boolean") throw new PrismaAdapterError("invalid Release policy fields");
142
+ return {
143
+ bundle_id: readNullableString(value, "bundle_id"),
144
+ channel_id: readString(value, "channel_id"),
145
+ created_at_ms: readNumber(value, "created_at_ms"),
146
+ enabled,
147
+ fingerprint_hash: readNullableString(value, "fingerprint_hash"),
148
+ id: readString(value, "id"),
149
+ kind,
150
+ message: readNullableString(value, "message"),
151
+ operation,
152
+ platform,
153
+ revision: readNumber(value, "revision"),
154
+ rollout_cohort_count: readNumber(value, "rollout_cohort_count"),
155
+ scope_key: readString(value, "scope_key"),
156
+ should_force_update: shouldForceUpdate,
157
+ source_release_id: readNullableString(value, "source_release_id"),
158
+ strategy,
159
+ target_app_version: readNullableString(value, "target_app_version"),
160
+ target_cohorts: targetCohorts,
161
+ updated_at_ms: readNumber(value, "updated_at_ms")
162
+ };
163
+ };
164
+ const parsePrismaReleaseCatalogRow = (value) => {
165
+ if (!isRecord(value)) throw new PrismaAdapterError("invalid catalog row");
166
+ const platform = readString(value, "platform");
167
+ const strategy = readString(value, "strategy");
168
+ const isTombstone = value["is_tombstone"];
169
+ if (platform !== "ios" && platform !== "android" || strategy !== "APP_VERSION" && strategy !== "FINGERPRINT" || typeof isTombstone !== "boolean") throw new PrismaAdapterError("invalid catalog fields");
170
+ return {
171
+ catalog_id: readString(value, "catalog_id"),
172
+ byte_size: readNumber(value, "byte_size"),
173
+ catalog_hash: readString(value, "catalog_hash"),
174
+ channel_id: readString(value, "channel_id"),
175
+ channel_key: readString(value, "channel_key"),
176
+ fingerprint_hash: readNullableString(value, "fingerprint_hash"),
177
+ generation: readNumber(value, "generation"),
178
+ is_tombstone: isTombstone,
179
+ payload: readString(value, "payload"),
180
+ platform,
181
+ scope_key: readString(value, "scope_key"),
182
+ strategy,
183
+ updated_at_ms: readNumber(value, "updated_at_ms")
184
+ };
185
+ };
186
+ const parsePrismaRows = (rows, parse) => rows.map(parse);
187
+ //#endregion
188
+ export { PrismaAdapterError, getPrismaDelegate, parsePrismaApiKeyRow, parsePrismaBundleEventRow, parsePrismaBundleRow, parsePrismaChannelRow, parsePrismaPatchRow, parsePrismaReleaseCatalogRow, parsePrismaReleaseRow, parsePrismaRows };
@@ -0,0 +1,139 @@
1
+ //#region src/apiKeys.ts
2
+ const API_KEY_HEADER_NAME = "x-api-key";
3
+ const BASE64URL_32_PATTERN = /^[A-Za-z0-9_-]{43}$/u;
4
+ const bytesToBase64Url = (bytes) => {
5
+ let binary = "";
6
+ for (const byte of bytes) binary += String.fromCharCode(byte);
7
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
8
+ };
9
+ const isApiKey = (value) => {
10
+ if (!BASE64URL_32_PATTERN.test(value)) return false;
11
+ try {
12
+ const base64 = value.replaceAll("-", "+").replaceAll("_", "/");
13
+ const binary = atob(`${base64}=`);
14
+ const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
15
+ return bytes.byteLength === 32 && bytesToBase64Url(bytes) === value;
16
+ } catch {
17
+ return false;
18
+ }
19
+ };
20
+ const normalizeApiKeyHeaderName = (value = API_KEY_HEADER_NAME) => {
21
+ if (typeof value !== "string" || value.length === 0) throw new TypeError("clientAccess.headerName must be a valid header name.");
22
+ try {
23
+ const headers = new Headers();
24
+ headers.set(value, "");
25
+ return headers.keys().next().value;
26
+ } catch {
27
+ throw new TypeError("clientAccess.headerName must be a valid header name.");
28
+ }
29
+ };
30
+ const hashApiKey = async (apiKey) => {
31
+ if (!isApiKey(apiKey)) throw new TypeError("API key must be a canonical 32-byte base64url value.");
32
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(apiKey));
33
+ return bytesToBase64Url(new Uint8Array(digest));
34
+ };
35
+ const apiKeyId = () => {
36
+ const bytes = new Uint8Array(16);
37
+ crypto.getRandomValues(bytes);
38
+ return `api-${bytesToBase64Url(bytes)}`;
39
+ };
40
+ const normalizeApiKeyName = (name) => {
41
+ const normalized = name.trim();
42
+ if (normalized.length === 0 || normalized.length > 64 || /[\p{Cc}\p{Cf}]/u.test(normalized)) throw new TypeError("API key names must contain 1-64 visible characters.");
43
+ return normalized;
44
+ };
45
+ const toApiKeyMetadata = ({ hash: _hash, ...metadata }) => Object.freeze(metadata);
46
+ const registerApiKey = async (input) => {
47
+ const hash = await hashApiKey(input.apiKey);
48
+ const createdAtMs = input.createdAtMs ?? Date.now();
49
+ if (!Number.isSafeInteger(createdAtMs) || createdAtMs < 0) throw new TypeError("API key creation time must be non-negative.");
50
+ const record = Object.freeze({
51
+ created_at_ms: createdAtMs,
52
+ hash,
53
+ id: apiKeyId(),
54
+ name: normalizeApiKeyName(input.name),
55
+ prefix: input.apiKey.slice(0, 6),
56
+ revoked_at_ms: null,
57
+ role: "client"
58
+ });
59
+ if (await input.apiKeys.create(record) === "existing") {
60
+ const existing = await input.apiKeys.findByHash(hash);
61
+ if (existing === null || existing.revoked_at_ms !== null) throw new Error("The API key has been revoked.");
62
+ return Object.freeze({
63
+ apiKey: input.apiKey,
64
+ record: toApiKeyMetadata(existing)
65
+ });
66
+ }
67
+ return Object.freeze({
68
+ apiKey: input.apiKey,
69
+ record: toApiKeyMetadata(record)
70
+ });
71
+ };
72
+ const createApiKey = (input) => {
73
+ const bytes = new Uint8Array(32);
74
+ crypto.getRandomValues(bytes);
75
+ return registerApiKey({
76
+ apiKey: bytesToBase64Url(bytes),
77
+ apiKeys: input.apiKeys,
78
+ name: input.name
79
+ });
80
+ };
81
+ /**
82
+ * Provisions the client API key used by managed init.
83
+ *
84
+ * A saved plaintext key is registered idempotently; otherwise a new key is
85
+ * created. Callers must persist or display the returned plaintext because the
86
+ * database stores only its hash.
87
+ */
88
+ const provisionApiKey = (input) => {
89
+ const existingApiKey = input.existingApiKey?.trim();
90
+ return existingApiKey ? registerApiKey({
91
+ apiKey: existingApiKey,
92
+ apiKeys: input.apiKeys,
93
+ name: input.name
94
+ }) : createApiKey({
95
+ apiKeys: input.apiKeys,
96
+ name: input.name
97
+ });
98
+ };
99
+ const authenticateApiKey = async (input) => {
100
+ const apiKey = input.request.headers.get(normalizeApiKeyHeaderName(input.headerName));
101
+ if (apiKey === null || !isApiKey(apiKey)) return false;
102
+ const hash = await hashApiKey(apiKey);
103
+ await input.beforeLookup?.();
104
+ const record = await input.apiKeys.findByHash(hash);
105
+ return record !== null && record.hash === hash && record.role === "client" && record.revoked_at_ms === null;
106
+ };
107
+ const createApiKeyManagement = (input) => Object.freeze({
108
+ async create({ name }) {
109
+ await input.beforeOperation();
110
+ const created = await createApiKey({
111
+ apiKeys: input.apiKeys,
112
+ name
113
+ });
114
+ return Object.freeze({
115
+ apiKey: created.apiKey,
116
+ record: created.record
117
+ });
118
+ },
119
+ async list() {
120
+ await input.beforeOperation();
121
+ return Object.freeze((await input.apiKeys.list()).map(toApiKeyMetadata));
122
+ },
123
+ async revoke({ id }) {
124
+ await input.beforeOperation();
125
+ const record = await input.apiKeys.revoke({
126
+ id,
127
+ revokedAtMs: Date.now()
128
+ });
129
+ return record === null ? null : toApiKeyMetadata(record);
130
+ }
131
+ });
132
+ //#endregion
133
+ exports.API_KEY_HEADER_NAME = API_KEY_HEADER_NAME;
134
+ exports.authenticateApiKey = authenticateApiKey;
135
+ exports.createApiKey = createApiKey;
136
+ exports.createApiKeyManagement = createApiKeyManagement;
137
+ exports.normalizeApiKeyHeaderName = normalizeApiKeyHeaderName;
138
+ exports.provisionApiKey = provisionApiKey;
139
+ exports.registerApiKey = registerApiKey;
@@ -0,0 +1,50 @@
1
+ import { ApiKeyModel, ApiKeyRow } from "@hot-updater/plugin-core";
2
+
3
+ //#region src/apiKeys.d.ts
4
+ declare const API_KEY_HEADER_NAME = "x-api-key";
5
+ type ApiKeyMetadata = Omit<ApiKeyRow, "hash">;
6
+ interface CreatedApiKey {
7
+ /** Plaintext credential. It cannot be recovered after this call returns. */
8
+ readonly apiKey: string;
9
+ /** Non-secret metadata. The persisted SHA-256 hash is never exposed. */
10
+ readonly record: ApiKeyMetadata;
11
+ }
12
+ interface ApiKeyManagementAPI {
13
+ /** Creates an API key and returns its plaintext exactly once. */
14
+ create(input: {
15
+ readonly name: string;
16
+ }): Promise<{
17
+ readonly apiKey: string;
18
+ readonly record: ApiKeyMetadata;
19
+ }>;
20
+ /** Lists non-secret API key metadata, including revoked keys. */
21
+ list(): Promise<readonly ApiKeyMetadata[]>;
22
+ /** Revokes an API key immediately and returns only non-secret metadata. */
23
+ revoke(input: {
24
+ readonly id: string;
25
+ }): Promise<ApiKeyMetadata | null>;
26
+ }
27
+ declare const registerApiKey: (input: {
28
+ readonly apiKey: string;
29
+ readonly apiKeys: ApiKeyModel;
30
+ readonly createdAtMs?: number;
31
+ readonly name: string;
32
+ }) => Promise<CreatedApiKey>;
33
+ declare const createApiKey: (input: {
34
+ readonly apiKeys: ApiKeyModel;
35
+ readonly name: string;
36
+ }) => Promise<CreatedApiKey>;
37
+ /**
38
+ * Provisions the client API key used by managed init.
39
+ *
40
+ * A saved plaintext key is registered idempotently; otherwise a new key is
41
+ * created. Callers must persist or display the returned plaintext because the
42
+ * database stores only its hash.
43
+ */
44
+ declare const provisionApiKey: (input: {
45
+ readonly apiKeys: ApiKeyModel;
46
+ readonly existingApiKey?: string;
47
+ readonly name: string;
48
+ }) => Promise<CreatedApiKey>;
49
+ //#endregion
50
+ export { API_KEY_HEADER_NAME, ApiKeyManagementAPI, ApiKeyMetadata, CreatedApiKey, createApiKey, provisionApiKey, registerApiKey };
@@ -0,0 +1,50 @@
1
+ import { ApiKeyModel, ApiKeyRow } from "@hot-updater/plugin-core";
2
+
3
+ //#region src/apiKeys.d.ts
4
+ declare const API_KEY_HEADER_NAME = "x-api-key";
5
+ type ApiKeyMetadata = Omit<ApiKeyRow, "hash">;
6
+ interface CreatedApiKey {
7
+ /** Plaintext credential. It cannot be recovered after this call returns. */
8
+ readonly apiKey: string;
9
+ /** Non-secret metadata. The persisted SHA-256 hash is never exposed. */
10
+ readonly record: ApiKeyMetadata;
11
+ }
12
+ interface ApiKeyManagementAPI {
13
+ /** Creates an API key and returns its plaintext exactly once. */
14
+ create(input: {
15
+ readonly name: string;
16
+ }): Promise<{
17
+ readonly apiKey: string;
18
+ readonly record: ApiKeyMetadata;
19
+ }>;
20
+ /** Lists non-secret API key metadata, including revoked keys. */
21
+ list(): Promise<readonly ApiKeyMetadata[]>;
22
+ /** Revokes an API key immediately and returns only non-secret metadata. */
23
+ revoke(input: {
24
+ readonly id: string;
25
+ }): Promise<ApiKeyMetadata | null>;
26
+ }
27
+ declare const registerApiKey: (input: {
28
+ readonly apiKey: string;
29
+ readonly apiKeys: ApiKeyModel;
30
+ readonly createdAtMs?: number;
31
+ readonly name: string;
32
+ }) => Promise<CreatedApiKey>;
33
+ declare const createApiKey: (input: {
34
+ readonly apiKeys: ApiKeyModel;
35
+ readonly name: string;
36
+ }) => Promise<CreatedApiKey>;
37
+ /**
38
+ * Provisions the client API key used by managed init.
39
+ *
40
+ * A saved plaintext key is registered idempotently; otherwise a new key is
41
+ * created. Callers must persist or display the returned plaintext because the
42
+ * database stores only its hash.
43
+ */
44
+ declare const provisionApiKey: (input: {
45
+ readonly apiKeys: ApiKeyModel;
46
+ readonly existingApiKey?: string;
47
+ readonly name: string;
48
+ }) => Promise<CreatedApiKey>;
49
+ //#endregion
50
+ export { API_KEY_HEADER_NAME, ApiKeyManagementAPI, ApiKeyMetadata, CreatedApiKey, createApiKey, provisionApiKey, registerApiKey };