@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,219 +0,0 @@
1
- let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
2
- //#region src/adapters/prismaRows.ts
3
- var PrismaAdapterError = class extends Error {
4
- reason;
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
- bundle_installations: "bundle_installations",
18
- channels: "channels",
19
- api_keys: "api_keys",
20
- releases: "releases",
21
- release_catalogs: "release_catalogs"
22
- };
23
- const getPrismaDelegate = (client, model) => {
24
- const delegate = Object.entries(client).find(([key]) => key === modelDelegates[model])?.[1];
25
- if (delegate === void 0) throw new PrismaAdapterError(`missing model delegate "${model}"`);
26
- if (!hasDelegateMethods(delegate)) throw new PrismaAdapterError(`invalid model delegate "${model}"`);
27
- return delegate;
28
- };
29
- const readString = (row, field) => {
30
- const value = row[field];
31
- if (typeof value !== "string") throw new PrismaAdapterError(`expected string field "${field}"`);
32
- return value;
33
- };
34
- const readNullableString = (row, field) => {
35
- const value = row[field];
36
- if (value === null) return null;
37
- if (typeof value !== "string") throw new PrismaAdapterError(`expected nullable string field "${field}"`);
38
- return value;
39
- };
40
- const readByteSize = (row, field) => {
41
- const value = row[field];
42
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new PrismaAdapterError(`expected byte-size field "${field}"`);
43
- return value;
44
- };
45
- const parsePrismaBundleRow = (value) => {
46
- if (!isRecord(value)) throw new PrismaAdapterError("invalid bundle row");
47
- const platform = value["platform"];
48
- if (platform !== "android" && platform !== "ios") throw new PrismaAdapterError("expected platform \"android\" or \"ios\"");
49
- const metadata = value["metadata"];
50
- if (!(0, _hot_updater_plugin_core.isDatabaseMetadataObject)(metadata)) throw new PrismaAdapterError("invalid metadata field");
51
- return {
52
- id: readString(value, "id"),
53
- platform,
54
- file_hash: readString(value, "file_hash"),
55
- git_commit_hash: readNullableString(value, "git_commit_hash"),
56
- storage_uri: readString(value, "storage_uri"),
57
- archive_byte_size: readByteSize(value, "archive_byte_size"),
58
- metadata,
59
- manifest_storage_uri: readNullableString(value, "manifest_storage_uri"),
60
- manifest_file_hash: readNullableString(value, "manifest_file_hash"),
61
- asset_base_storage_uri: readNullableString(value, "asset_base_storage_uri")
62
- };
63
- };
64
- const parsePrismaChannelRow = (value) => {
65
- if (!isRecord(value)) throw new PrismaAdapterError("invalid channel row");
66
- return {
67
- id: readString(value, "id"),
68
- name: readString(value, "name")
69
- };
70
- };
71
- const parsePrismaPatchRow = (value) => {
72
- if (!isRecord(value)) throw new PrismaAdapterError("invalid patch row");
73
- const orderIndex = value["order_index"];
74
- if (typeof orderIndex !== "number") throw new PrismaAdapterError("invalid patch order_index field");
75
- return {
76
- id: readString(value, "id"),
77
- bundle_id: readString(value, "bundle_id"),
78
- base_bundle_id: readString(value, "base_bundle_id"),
79
- base_file_hash: readString(value, "base_file_hash"),
80
- patch_file_hash: readString(value, "patch_file_hash"),
81
- patch_storage_uri: readString(value, "patch_storage_uri"),
82
- byte_size: readByteSize(value, "byte_size"),
83
- order_index: orderIndex
84
- };
85
- };
86
- const readNumber = (row, field) => {
87
- const value = row[field];
88
- if (typeof value !== "number" || !Number.isFinite(value)) throw new PrismaAdapterError(`expected number field "${field}"`);
89
- return value;
90
- };
91
- const parsePrismaBundleEventRow = (value) => {
92
- if (!isRecord(value)) throw new PrismaAdapterError("invalid event row");
93
- const type = readString(value, "type");
94
- const platform = readString(value, "platform");
95
- const fromBundleId = readNullableString(value, "from_bundle_id");
96
- const updateStrategy = readNullableString(value, "update_strategy");
97
- 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");
98
- return {
99
- id: readString(value, "id"),
100
- type,
101
- install_id: readString(value, "install_id"),
102
- user_id: readNullableString(value, "user_id"),
103
- username: readNullableString(value, "username"),
104
- from_release_id: readNullableString(value, "from_release_id"),
105
- from_bundle_id: fromBundleId,
106
- to_release_id: readNullableString(value, "to_release_id"),
107
- to_bundle_id: readString(value, "to_bundle_id"),
108
- platform,
109
- app_version: readString(value, "app_version"),
110
- channel: readString(value, "channel"),
111
- cohort: readString(value, "cohort"),
112
- update_strategy: updateStrategy,
113
- fingerprint_hash: readNullableString(value, "fingerprint_hash"),
114
- sdk_version: readNullableString(value, "sdk_version"),
115
- received_at_ms: readNumber(value, "received_at_ms")
116
- };
117
- };
118
- const parsePrismaInsightsInstallationRow = (value) => {
119
- if (!isRecord(value)) throw new PrismaAdapterError("invalid installation row");
120
- const platform = readString(value, "platform");
121
- const type = readString(value, "type");
122
- if (platform !== "ios" && platform !== "android" || type !== "UPDATE_APPLIED" && type !== "RECOVERED" && type !== "RELEASE_ADOPTED" && type !== "UNCHANGED") throw new PrismaAdapterError("invalid installation fields");
123
- return {
124
- install_id: readString(value, "install_id"),
125
- id: readString(value, "id"),
126
- user_id: readNullableString(value, "user_id"),
127
- username: readNullableString(value, "username"),
128
- to_bundle_id: readString(value, "to_bundle_id"),
129
- type,
130
- platform,
131
- app_version: readString(value, "app_version"),
132
- channel: readString(value, "channel"),
133
- cohort: readString(value, "cohort"),
134
- received_at_ms: readNumber(value, "received_at_ms")
135
- };
136
- };
137
- const parsePrismaApiKeyRow = (value) => {
138
- if (!isRecord(value)) throw new PrismaAdapterError("invalid API key row");
139
- const role = readString(value, "role");
140
- if (role !== "client") throw new PrismaAdapterError("invalid API key role");
141
- const revokedAt = value["revoked_at_ms"];
142
- return {
143
- id: readString(value, "id"),
144
- hash: readString(value, "hash"),
145
- name: readString(value, "name"),
146
- prefix: readString(value, "prefix"),
147
- role,
148
- created_at_ms: readNumber(value, "created_at_ms"),
149
- revoked_at_ms: revokedAt === null ? null : readNumber(value, "revoked_at_ms")
150
- };
151
- };
152
- const parsePrismaReleaseRow = (value) => {
153
- if (!isRecord(value)) throw new PrismaAdapterError("invalid Release row");
154
- const platform = readString(value, "platform");
155
- const kind = readString(value, "kind");
156
- const strategy = readString(value, "strategy");
157
- const operation = readString(value, "operation");
158
- const targetCohorts = value["target_cohorts"];
159
- 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");
160
- const enabled = value["enabled"];
161
- const shouldForceUpdate = value["should_force_update"];
162
- if (typeof enabled !== "boolean" || typeof shouldForceUpdate !== "boolean") throw new PrismaAdapterError("invalid Release policy fields");
163
- return {
164
- bundle_id: readNullableString(value, "bundle_id"),
165
- channel_id: readString(value, "channel_id"),
166
- created_at_ms: readNumber(value, "created_at_ms"),
167
- enabled,
168
- fingerprint_hash: readNullableString(value, "fingerprint_hash"),
169
- id: readString(value, "id"),
170
- kind,
171
- message: readNullableString(value, "message"),
172
- operation,
173
- platform,
174
- revision: readNumber(value, "revision"),
175
- rollout_cohort_count: readNumber(value, "rollout_cohort_count"),
176
- scope_key: readString(value, "scope_key"),
177
- should_force_update: shouldForceUpdate,
178
- source_release_id: readNullableString(value, "source_release_id"),
179
- strategy,
180
- target_app_version: readNullableString(value, "target_app_version"),
181
- target_cohorts: targetCohorts,
182
- updated_at_ms: readNumber(value, "updated_at_ms")
183
- };
184
- };
185
- const parsePrismaReleaseCatalogRow = (value) => {
186
- if (!isRecord(value)) throw new PrismaAdapterError("invalid catalog row");
187
- const platform = readString(value, "platform");
188
- const strategy = readString(value, "strategy");
189
- const isTombstone = value["is_tombstone"];
190
- if (platform !== "ios" && platform !== "android" || strategy !== "APP_VERSION" && strategy !== "FINGERPRINT" || typeof isTombstone !== "boolean") throw new PrismaAdapterError("invalid catalog fields");
191
- return {
192
- catalog_id: readString(value, "catalog_id"),
193
- byte_size: readNumber(value, "byte_size"),
194
- catalog_hash: readString(value, "catalog_hash"),
195
- channel_id: readString(value, "channel_id"),
196
- channel_key: readString(value, "channel_key"),
197
- fingerprint_hash: readNullableString(value, "fingerprint_hash"),
198
- generation: readNumber(value, "generation"),
199
- is_tombstone: isTombstone,
200
- payload: readString(value, "payload"),
201
- platform,
202
- scope_key: readString(value, "scope_key"),
203
- strategy,
204
- updated_at_ms: readNumber(value, "updated_at_ms")
205
- };
206
- };
207
- const parsePrismaRows = (rows, parse) => rows.map(parse);
208
- //#endregion
209
- exports.PrismaAdapterError = PrismaAdapterError;
210
- exports.getPrismaDelegate = getPrismaDelegate;
211
- exports.parsePrismaApiKeyRow = parsePrismaApiKeyRow;
212
- exports.parsePrismaBundleEventRow = parsePrismaBundleEventRow;
213
- exports.parsePrismaBundleRow = parsePrismaBundleRow;
214
- exports.parsePrismaChannelRow = parsePrismaChannelRow;
215
- exports.parsePrismaInsightsInstallationRow = parsePrismaInsightsInstallationRow;
216
- exports.parsePrismaPatchRow = parsePrismaPatchRow;
217
- exports.parsePrismaReleaseCatalogRow = parsePrismaReleaseCatalogRow;
218
- exports.parsePrismaReleaseRow = parsePrismaReleaseRow;
219
- exports.parsePrismaRows = parsePrismaRows;
@@ -1,209 +0,0 @@
1
- import { isDatabaseMetadataObject } from "@hot-updater/plugin-core";
2
- //#region src/adapters/prismaRows.ts
3
- var PrismaAdapterError = class extends Error {
4
- reason;
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
- bundle_installations: "bundle_installations",
18
- channels: "channels",
19
- api_keys: "api_keys",
20
- releases: "releases",
21
- release_catalogs: "release_catalogs"
22
- };
23
- const getPrismaDelegate = (client, model) => {
24
- const delegate = Object.entries(client).find(([key]) => key === modelDelegates[model])?.[1];
25
- if (delegate === void 0) throw new PrismaAdapterError(`missing model delegate "${model}"`);
26
- if (!hasDelegateMethods(delegate)) throw new PrismaAdapterError(`invalid model delegate "${model}"`);
27
- return delegate;
28
- };
29
- const readString = (row, field) => {
30
- const value = row[field];
31
- if (typeof value !== "string") throw new PrismaAdapterError(`expected string field "${field}"`);
32
- return value;
33
- };
34
- const readNullableString = (row, field) => {
35
- const value = row[field];
36
- if (value === null) return null;
37
- if (typeof value !== "string") throw new PrismaAdapterError(`expected nullable string field "${field}"`);
38
- return value;
39
- };
40
- const readByteSize = (row, field) => {
41
- const value = row[field];
42
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new PrismaAdapterError(`expected byte-size field "${field}"`);
43
- return value;
44
- };
45
- const parsePrismaBundleRow = (value) => {
46
- if (!isRecord(value)) throw new PrismaAdapterError("invalid bundle row");
47
- const platform = value["platform"];
48
- if (platform !== "android" && platform !== "ios") throw new PrismaAdapterError("expected platform \"android\" or \"ios\"");
49
- const metadata = value["metadata"];
50
- if (!isDatabaseMetadataObject(metadata)) throw new PrismaAdapterError("invalid metadata field");
51
- return {
52
- id: readString(value, "id"),
53
- platform,
54
- file_hash: readString(value, "file_hash"),
55
- git_commit_hash: readNullableString(value, "git_commit_hash"),
56
- storage_uri: readString(value, "storage_uri"),
57
- archive_byte_size: readByteSize(value, "archive_byte_size"),
58
- metadata,
59
- manifest_storage_uri: readNullableString(value, "manifest_storage_uri"),
60
- manifest_file_hash: readNullableString(value, "manifest_file_hash"),
61
- asset_base_storage_uri: readNullableString(value, "asset_base_storage_uri")
62
- };
63
- };
64
- const parsePrismaChannelRow = (value) => {
65
- if (!isRecord(value)) throw new PrismaAdapterError("invalid channel row");
66
- return {
67
- id: readString(value, "id"),
68
- name: readString(value, "name")
69
- };
70
- };
71
- const parsePrismaPatchRow = (value) => {
72
- if (!isRecord(value)) throw new PrismaAdapterError("invalid patch row");
73
- const orderIndex = value["order_index"];
74
- if (typeof orderIndex !== "number") throw new PrismaAdapterError("invalid patch order_index field");
75
- return {
76
- id: readString(value, "id"),
77
- bundle_id: readString(value, "bundle_id"),
78
- base_bundle_id: readString(value, "base_bundle_id"),
79
- base_file_hash: readString(value, "base_file_hash"),
80
- patch_file_hash: readString(value, "patch_file_hash"),
81
- patch_storage_uri: readString(value, "patch_storage_uri"),
82
- byte_size: readByteSize(value, "byte_size"),
83
- order_index: orderIndex
84
- };
85
- };
86
- const readNumber = (row, field) => {
87
- const value = row[field];
88
- if (typeof value !== "number" || !Number.isFinite(value)) throw new PrismaAdapterError(`expected number field "${field}"`);
89
- return value;
90
- };
91
- const parsePrismaBundleEventRow = (value) => {
92
- if (!isRecord(value)) throw new PrismaAdapterError("invalid event row");
93
- const type = readString(value, "type");
94
- const platform = readString(value, "platform");
95
- const fromBundleId = readNullableString(value, "from_bundle_id");
96
- const updateStrategy = readNullableString(value, "update_strategy");
97
- 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");
98
- return {
99
- id: readString(value, "id"),
100
- type,
101
- install_id: readString(value, "install_id"),
102
- user_id: readNullableString(value, "user_id"),
103
- username: readNullableString(value, "username"),
104
- from_release_id: readNullableString(value, "from_release_id"),
105
- from_bundle_id: fromBundleId,
106
- to_release_id: readNullableString(value, "to_release_id"),
107
- to_bundle_id: readString(value, "to_bundle_id"),
108
- platform,
109
- app_version: readString(value, "app_version"),
110
- channel: readString(value, "channel"),
111
- cohort: readString(value, "cohort"),
112
- update_strategy: updateStrategy,
113
- fingerprint_hash: readNullableString(value, "fingerprint_hash"),
114
- sdk_version: readNullableString(value, "sdk_version"),
115
- received_at_ms: readNumber(value, "received_at_ms")
116
- };
117
- };
118
- const parsePrismaInsightsInstallationRow = (value) => {
119
- if (!isRecord(value)) throw new PrismaAdapterError("invalid installation row");
120
- const platform = readString(value, "platform");
121
- const type = readString(value, "type");
122
- if (platform !== "ios" && platform !== "android" || type !== "UPDATE_APPLIED" && type !== "RECOVERED" && type !== "RELEASE_ADOPTED" && type !== "UNCHANGED") throw new PrismaAdapterError("invalid installation fields");
123
- return {
124
- install_id: readString(value, "install_id"),
125
- id: readString(value, "id"),
126
- user_id: readNullableString(value, "user_id"),
127
- username: readNullableString(value, "username"),
128
- to_bundle_id: readString(value, "to_bundle_id"),
129
- type,
130
- platform,
131
- app_version: readString(value, "app_version"),
132
- channel: readString(value, "channel"),
133
- cohort: readString(value, "cohort"),
134
- received_at_ms: readNumber(value, "received_at_ms")
135
- };
136
- };
137
- const parsePrismaApiKeyRow = (value) => {
138
- if (!isRecord(value)) throw new PrismaAdapterError("invalid API key row");
139
- const role = readString(value, "role");
140
- if (role !== "client") throw new PrismaAdapterError("invalid API key role");
141
- const revokedAt = value["revoked_at_ms"];
142
- return {
143
- id: readString(value, "id"),
144
- hash: readString(value, "hash"),
145
- name: readString(value, "name"),
146
- prefix: readString(value, "prefix"),
147
- role,
148
- created_at_ms: readNumber(value, "created_at_ms"),
149
- revoked_at_ms: revokedAt === null ? null : readNumber(value, "revoked_at_ms")
150
- };
151
- };
152
- const parsePrismaReleaseRow = (value) => {
153
- if (!isRecord(value)) throw new PrismaAdapterError("invalid Release row");
154
- const platform = readString(value, "platform");
155
- const kind = readString(value, "kind");
156
- const strategy = readString(value, "strategy");
157
- const operation = readString(value, "operation");
158
- const targetCohorts = value["target_cohorts"];
159
- 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");
160
- const enabled = value["enabled"];
161
- const shouldForceUpdate = value["should_force_update"];
162
- if (typeof enabled !== "boolean" || typeof shouldForceUpdate !== "boolean") throw new PrismaAdapterError("invalid Release policy fields");
163
- return {
164
- bundle_id: readNullableString(value, "bundle_id"),
165
- channel_id: readString(value, "channel_id"),
166
- created_at_ms: readNumber(value, "created_at_ms"),
167
- enabled,
168
- fingerprint_hash: readNullableString(value, "fingerprint_hash"),
169
- id: readString(value, "id"),
170
- kind,
171
- message: readNullableString(value, "message"),
172
- operation,
173
- platform,
174
- revision: readNumber(value, "revision"),
175
- rollout_cohort_count: readNumber(value, "rollout_cohort_count"),
176
- scope_key: readString(value, "scope_key"),
177
- should_force_update: shouldForceUpdate,
178
- source_release_id: readNullableString(value, "source_release_id"),
179
- strategy,
180
- target_app_version: readNullableString(value, "target_app_version"),
181
- target_cohorts: targetCohorts,
182
- updated_at_ms: readNumber(value, "updated_at_ms")
183
- };
184
- };
185
- const parsePrismaReleaseCatalogRow = (value) => {
186
- if (!isRecord(value)) throw new PrismaAdapterError("invalid catalog row");
187
- const platform = readString(value, "platform");
188
- const strategy = readString(value, "strategy");
189
- const isTombstone = value["is_tombstone"];
190
- if (platform !== "ios" && platform !== "android" || strategy !== "APP_VERSION" && strategy !== "FINGERPRINT" || typeof isTombstone !== "boolean") throw new PrismaAdapterError("invalid catalog fields");
191
- return {
192
- catalog_id: readString(value, "catalog_id"),
193
- byte_size: readNumber(value, "byte_size"),
194
- catalog_hash: readString(value, "catalog_hash"),
195
- channel_id: readString(value, "channel_id"),
196
- channel_key: readString(value, "channel_key"),
197
- fingerprint_hash: readNullableString(value, "fingerprint_hash"),
198
- generation: readNumber(value, "generation"),
199
- is_tombstone: isTombstone,
200
- payload: readString(value, "payload"),
201
- platform,
202
- scope_key: readString(value, "scope_key"),
203
- strategy,
204
- updated_at_ms: readNumber(value, "updated_at_ms")
205
- };
206
- };
207
- const parsePrismaRows = (rows, parse) => rows.map(parse);
208
- //#endregion
209
- export { PrismaAdapterError, getPrismaDelegate, parsePrismaApiKeyRow, parsePrismaBundleEventRow, parsePrismaBundleRow, parsePrismaChannelRow, parsePrismaInsightsInstallationRow, parsePrismaPatchRow, parsePrismaReleaseCatalogRow, parsePrismaReleaseRow, parsePrismaRows };
package/dist/apiKeys.cjs DELETED
@@ -1,143 +0,0 @@
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 = /* @__PURE__ */ 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 = /* @__PURE__ */ 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.apiKeyId = apiKeyId;
135
- exports.authenticateApiKey = authenticateApiKey;
136
- exports.createApiKey = createApiKey;
137
- exports.createApiKeyManagement = createApiKeyManagement;
138
- exports.hashApiKey = hashApiKey;
139
- exports.isApiKey = isApiKey;
140
- exports.normalizeApiKeyHeaderName = normalizeApiKeyHeaderName;
141
- exports.normalizeApiKeyName = normalizeApiKeyName;
142
- exports.provisionApiKey = provisionApiKey;
143
- exports.registerApiKey = registerApiKey;
@@ -1,49 +0,0 @@
1
- import { ApiKeyModel, ApiKeyRow } from "@hot-updater/plugin-core";
2
- //#region src/apiKeys.d.ts
3
- declare const API_KEY_HEADER_NAME = "x-api-key";
4
- type ApiKeyMetadata = Omit<ApiKeyRow, "hash">;
5
- interface CreatedApiKey {
6
- /** Plaintext credential. It cannot be recovered after this call returns. */
7
- readonly apiKey: string;
8
- /** Non-secret metadata. The persisted SHA-256 hash is never exposed. */
9
- readonly record: ApiKeyMetadata;
10
- }
11
- interface ApiKeyManagementAPI {
12
- /** Creates an API key and returns its plaintext exactly once. */
13
- create(input: {
14
- readonly name: string;
15
- }): Promise<{
16
- readonly apiKey: string;
17
- readonly record: ApiKeyMetadata;
18
- }>;
19
- /** Lists non-secret API key metadata, including revoked keys. */
20
- list(): Promise<readonly ApiKeyMetadata[]>;
21
- /** Revokes an API key immediately and returns only non-secret metadata. */
22
- revoke(input: {
23
- readonly id: string;
24
- }): Promise<ApiKeyMetadata | null>;
25
- }
26
- declare const registerApiKey: (input: {
27
- readonly apiKey: string;
28
- readonly apiKeys: ApiKeyModel;
29
- readonly createdAtMs?: number;
30
- readonly name: string;
31
- }) => Promise<CreatedApiKey>;
32
- declare const createApiKey: (input: {
33
- readonly apiKeys: ApiKeyModel;
34
- readonly name: string;
35
- }) => Promise<CreatedApiKey>;
36
- /**
37
- * Provisions the client API key used by managed init.
38
- *
39
- * A saved plaintext key is registered idempotently; otherwise a new key is
40
- * created. Callers must persist or display the returned plaintext because the
41
- * database stores only its hash.
42
- */
43
- declare const provisionApiKey: (input: {
44
- readonly apiKeys: ApiKeyModel;
45
- readonly existingApiKey?: string;
46
- readonly name: string;
47
- }) => Promise<CreatedApiKey>;
48
- //#endregion
49
- export { API_KEY_HEADER_NAME, ApiKeyManagementAPI, ApiKeyMetadata, CreatedApiKey, createApiKey, provisionApiKey, registerApiKey };
@@ -1,49 +0,0 @@
1
- import { ApiKeyModel, ApiKeyRow } from "@hot-updater/plugin-core";
2
- //#region src/apiKeys.d.ts
3
- declare const API_KEY_HEADER_NAME = "x-api-key";
4
- type ApiKeyMetadata = Omit<ApiKeyRow, "hash">;
5
- interface CreatedApiKey {
6
- /** Plaintext credential. It cannot be recovered after this call returns. */
7
- readonly apiKey: string;
8
- /** Non-secret metadata. The persisted SHA-256 hash is never exposed. */
9
- readonly record: ApiKeyMetadata;
10
- }
11
- interface ApiKeyManagementAPI {
12
- /** Creates an API key and returns its plaintext exactly once. */
13
- create(input: {
14
- readonly name: string;
15
- }): Promise<{
16
- readonly apiKey: string;
17
- readonly record: ApiKeyMetadata;
18
- }>;
19
- /** Lists non-secret API key metadata, including revoked keys. */
20
- list(): Promise<readonly ApiKeyMetadata[]>;
21
- /** Revokes an API key immediately and returns only non-secret metadata. */
22
- revoke(input: {
23
- readonly id: string;
24
- }): Promise<ApiKeyMetadata | null>;
25
- }
26
- declare const registerApiKey: (input: {
27
- readonly apiKey: string;
28
- readonly apiKeys: ApiKeyModel;
29
- readonly createdAtMs?: number;
30
- readonly name: string;
31
- }) => Promise<CreatedApiKey>;
32
- declare const createApiKey: (input: {
33
- readonly apiKeys: ApiKeyModel;
34
- readonly name: string;
35
- }) => Promise<CreatedApiKey>;
36
- /**
37
- * Provisions the client API key used by managed init.
38
- *
39
- * A saved plaintext key is registered idempotently; otherwise a new key is
40
- * created. Callers must persist or display the returned plaintext because the
41
- * database stores only its hash.
42
- */
43
- declare const provisionApiKey: (input: {
44
- readonly apiKeys: ApiKeyModel;
45
- readonly existingApiKey?: string;
46
- readonly name: string;
47
- }) => Promise<CreatedApiKey>;
48
- //#endregion
49
- export { API_KEY_HEADER_NAME, ApiKeyManagementAPI, ApiKeyMetadata, CreatedApiKey, createApiKey, provisionApiKey, registerApiKey };