@hot-updater/server 1.0.0-rc.18 → 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.
- package/LICENSE +12 -14
- package/dist/adapters/drizzle.cjs +6 -8
- package/dist/adapters/drizzle.d.cts +2 -2
- package/dist/adapters/drizzle.d.mts +2 -2
- package/dist/adapters/drizzle.mjs +1 -3
- package/dist/adapters/drizzleExecutor.d.cts +1 -1
- package/dist/adapters/drizzleExecutor.d.mts +1 -1
- package/dist/adapters/kysely.cjs +4 -6
- package/dist/adapters/kysely.d.cts +3 -3
- package/dist/adapters/kysely.d.mts +3 -3
- package/dist/adapters/kysely.mjs +1 -3
- package/dist/adapters/kyselyExecutor.d.cts +1 -2
- package/dist/adapters/kyselyExecutor.d.mts +1 -2
- package/dist/adapters/mongodb.cjs +10 -21
- package/dist/adapters/mongodb.d.cts +1 -1
- package/dist/adapters/mongodb.d.mts +1 -1
- package/dist/adapters/mongodb.mjs +9 -20
- package/dist/adapters/mongodbAdapter.cjs +11 -11
- package/dist/adapters/mongodbAdapter.d.cts +1 -1
- package/dist/adapters/mongodbAdapter.d.mts +1 -1
- package/dist/adapters/mongodbAdapter.mjs +1 -1
- package/dist/adapters/prisma.cjs +7 -9
- package/dist/adapters/prisma.d.cts +1 -1
- package/dist/adapters/prisma.d.mts +1 -1
- package/dist/adapters/prisma.mjs +1 -3
- package/dist/adapters/prismaExecutor.cjs +2 -3
- package/dist/adapters/prismaExecutor.mjs +1 -2
- package/dist/adapters/sqlProviders.cjs +7 -2
- package/dist/adapters/sqlProviders.mjs +6 -1
- package/dist/assembly/assemblePlugins.cjs +26 -48
- package/dist/assembly/assemblePlugins.d.cts +2 -5
- package/dist/assembly/assemblePlugins.d.mts +2 -5
- package/dist/assembly/assemblePlugins.mjs +19 -45
- package/dist/assembly/clientPlugins.cjs +6 -4
- package/dist/assembly/clientPlugins.mjs +2 -0
- package/dist/assembly/configError.d.cts +1 -6
- package/dist/assembly/configError.d.mts +1 -6
- package/dist/assembly/configError.mjs +1 -6
- package/dist/core/api.cjs +0 -40
- package/dist/core/api.d.cts +5 -16
- package/dist/core/api.d.mts +5 -16
- package/dist/core/api.mjs +1 -37
- package/dist/core/baseCandidates.cjs +0 -43
- package/dist/core/baseCandidates.mjs +2 -43
- package/dist/core/operations.cjs +13 -12
- package/dist/core/operations.mjs +6 -5
- package/dist/core/reads.cjs +4 -4
- package/dist/core/reads.d.cts +2 -41
- package/dist/core/reads.d.mts +2 -41
- package/dist/core/reads.mjs +3 -3
- package/dist/core/releases.cjs +6 -6
- package/dist/core/releases.mjs +1 -1
- package/dist/core/writes.cjs +2 -2
- package/dist/core/writes.mjs +1 -1
- package/dist/createHotUpdaterCore.cjs +39 -39
- package/dist/createHotUpdaterCore.d.cts +61 -8
- package/dist/createHotUpdaterCore.d.mts +61 -8
- package/dist/createHotUpdaterCore.mjs +35 -32
- package/dist/db/engineDrizzleSchema.cjs +3 -4
- package/dist/db/engineDrizzleSchema.mjs +1 -2
- package/dist/db/enginePrismaSchema.cjs +4 -5
- package/dist/db/enginePrismaSchema.d.cts +1 -1
- package/dist/db/enginePrismaSchema.d.mts +1 -1
- package/dist/db/enginePrismaSchema.mjs +1 -2
- package/dist/db/releaseCatalog.cjs +6 -6
- package/dist/db/releaseCatalog.mjs +1 -1
- package/dist/db/updateArtifacts.cjs +6 -6
- package/dist/db/updateArtifacts.mjs +1 -1
- package/dist/handler.cjs +3 -4
- package/dist/handler.mjs +1 -1
- package/dist/handlerAdminRoutes.cjs +1 -2
- package/dist/handlerAdminRoutes.mjs +1 -2
- package/dist/handlerVersionRoutes.cjs +2 -2
- package/dist/handlerVersionRoutes.mjs +2 -2
- package/dist/index.cjs +9 -2
- package/dist/index.d.cts +4 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +2 -1
- package/dist/node.cjs +3 -6
- package/dist/node.d.cts +3 -3
- package/dist/node.d.mts +3 -3
- package/dist/node.mjs +4 -4
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/api-keys/index.cjs +8 -52
- package/dist/plugins/api-keys/index.d.cts +1 -84
- package/dist/plugins/api-keys/index.d.mts +1 -84
- package/dist/plugins/api-keys/index.mjs +2 -49
- package/dist/plugins/definePlugin.d.cts +2 -200
- package/dist/plugins/definePlugin.d.mts +2 -200
- package/dist/plugins/insights/index.cjs +7 -126
- package/dist/plugins/insights/index.d.cts +1 -398
- package/dist/plugins/insights/index.d.mts +1 -398
- package/dist/plugins/insights/index.mjs +2 -121
- package/dist/plugins/official.cjs +30 -0
- package/dist/plugins/official.mjs +29 -0
- package/dist/storageAccess.cjs +13 -10
- package/dist/storageAccess.mjs +13 -10
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/package.json +15 -37
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/assembly/clientPlugins.d.cts +0 -16
- package/dist/assembly/clientPlugins.d.mts +0 -16
- package/dist/assembly/configError.cjs +0 -7
- package/dist/assembly/databasePlugins.cjs +0 -27
- package/dist/assembly/databasePlugins.d.cts +0 -43
- package/dist/assembly/databasePlugins.d.mts +0 -43
- package/dist/assembly/databasePlugins.mjs +0 -26
- package/dist/assembly/pluginCli.cjs +0 -125
- package/dist/assembly/pluginCli.d.cts +0 -59
- package/dist/assembly/pluginCli.d.mts +0 -59
- package/dist/assembly/pluginCli.mjs +0 -121
- package/dist/core/baseCandidates.d.cts +0 -17
- package/dist/core/baseCandidates.d.mts +0 -17
- package/dist/core/schema.cjs +0 -279
- package/dist/core/schema.d.cts +0 -307
- package/dist/core/schema.d.mts +0 -307
- package/dist/core/schema.mjs +0 -277
- package/dist/database/aggregateBatching.cjs +0 -626
- package/dist/database/aggregateBatching.d.cts +0 -10
- package/dist/database/aggregateBatching.d.mts +0 -10
- package/dist/database/aggregateBatching.mjs +0 -625
- package/dist/database/busy.cjs +0 -36
- package/dist/database/busy.d.cts +0 -12
- package/dist/database/busy.d.mts +0 -12
- package/dist/database/busy.mjs +0 -36
- package/dist/database/cursor.cjs +0 -44
- package/dist/database/cursor.d.cts +0 -7
- package/dist/database/cursor.d.mts +0 -7
- package/dist/database/cursor.mjs +0 -40
- package/dist/database/database.cjs +0 -63
- package/dist/database/database.d.cts +0 -136
- package/dist/database/database.d.mts +0 -136
- package/dist/database/database.mjs +0 -63
- package/dist/database/definitions.d.cts +0 -78
- package/dist/database/definitions.d.mts +0 -78
- package/dist/database/engine.cjs +0 -37
- package/dist/database/engine.d.cts +0 -41
- package/dist/database/engine.d.mts +0 -41
- package/dist/database/engine.mjs +0 -37
- package/dist/database/engineAggregates.cjs +0 -118
- package/dist/database/engineAggregates.mjs +0 -115
- package/dist/database/engineReads.cjs +0 -182
- package/dist/database/engineReads.d.cts +0 -35
- package/dist/database/engineReads.d.mts +0 -35
- package/dist/database/engineReads.mjs +0 -181
- package/dist/database/engineTransaction.cjs +0 -399
- package/dist/database/engineTransaction.d.cts +0 -26
- package/dist/database/engineTransaction.d.mts +0 -26
- package/dist/database/engineTransaction.mjs +0 -398
- package/dist/database/errors.cjs +0 -27
- package/dist/database/errors.d.cts +0 -21
- package/dist/database/errors.d.mts +0 -21
- package/dist/database/errors.mjs +0 -24
- package/dist/database/fence.cjs +0 -125
- package/dist/database/fence.d.cts +0 -42
- package/dist/database/fence.d.mts +0 -42
- package/dist/database/fence.mjs +0 -117
- package/dist/database/index.cjs +0 -136
- package/dist/database/index.d.cts +0 -18
- package/dist/database/index.d.mts +0 -18
- package/dist/database/index.mjs +0 -16
- package/dist/database/kv/kvAdapter.cjs +0 -285
- package/dist/database/kv/kvAdapter.d.cts +0 -109
- package/dist/database/kv/kvAdapter.d.mts +0 -109
- package/dist/database/kv/kvAdapter.mjs +0 -284
- package/dist/database/resolveSchema.cjs +0 -199
- package/dist/database/resolveSchema.d.cts +0 -42
- package/dist/database/resolveSchema.d.mts +0 -42
- package/dist/database/resolveSchema.mjs +0 -196
- package/dist/database/retention.cjs +0 -92
- package/dist/database/retention.mjs +0 -90
- package/dist/database/schema.cjs +0 -24
- package/dist/database/schema.d.cts +0 -90
- package/dist/database/schema.d.mts +0 -90
- package/dist/database/schema.mjs +0 -23
- package/dist/database/sql/sqlAdapter.cjs +0 -290
- package/dist/database/sql/sqlAdapter.d.cts +0 -46
- package/dist/database/sql/sqlAdapter.d.mts +0 -46
- package/dist/database/sql/sqlAdapter.mjs +0 -287
- package/dist/database/sql/sqlSchema.cjs +0 -171
- package/dist/database/sql/sqlSchema.d.cts +0 -8
- package/dist/database/sql/sqlSchema.d.mts +0 -8
- package/dist/database/sql/sqlSchema.mjs +0 -165
- package/dist/db/coreDatabase.cjs +0 -85
- package/dist/db/coreDatabase.d.cts +0 -57
- package/dist/db/coreDatabase.d.mts +0 -57
- package/dist/db/coreDatabase.mjs +0 -78
- package/dist/db/createBundleDiff.cjs +0 -144
- package/dist/db/createBundleDiff.d.cts +0 -17
- package/dist/db/createBundleDiff.d.mts +0 -17
- package/dist/db/createBundleDiff.mjs +0 -141
- package/dist/db/engineMigrator.cjs +0 -53
- package/dist/db/engineMigrator.mjs +0 -53
- package/dist/db/engineSql.cjs +0 -26
- package/dist/db/engineSql.d.cts +0 -17
- package/dist/db/engineSql.d.mts +0 -17
- package/dist/db/engineSql.mjs +0 -25
- package/dist/db/engineSqlMigrator.cjs +0 -66
- package/dist/db/engineSqlMigrator.mjs +0 -66
- package/dist/db/fixedMigratorShared.cjs +0 -12
- package/dist/db/fixedMigratorShared.mjs +0 -11
- package/dist/db/index.cjs +0 -50
- package/dist/db/index.d.cts +0 -23
- package/dist/db/index.d.mts +0 -23
- package/dist/db/index.mjs +0 -33
- package/dist/db/releaseCatalog.d.cts +0 -16
- package/dist/db/releaseCatalog.d.mts +0 -16
- package/dist/db/schemaSettings.cjs +0 -63
- package/dist/db/schemaSettings.d.cts +0 -12
- package/dist/db/schemaSettings.d.mts +0 -12
- package/dist/db/schemaSettings.mjs +0 -62
- package/dist/db/settingsMigrator.cjs +0 -92
- package/dist/db/settingsMigrator.mjs +0 -89
- package/dist/db/types.cjs +0 -11
- package/dist/db/types.d.cts +0 -78
- package/dist/db/types.d.mts +0 -78
- package/dist/db/types.mjs +0 -10
- package/dist/diff.cjs +0 -3
- package/dist/diff.d.cts +0 -2
- package/dist/diff.d.mts +0 -2
- package/dist/diff.mjs +0 -2
- package/dist/plugins/api-keys/apiKeys.cjs +0 -139
- package/dist/plugins/api-keys/apiKeys.d.cts +0 -27
- package/dist/plugins/api-keys/apiKeys.d.mts +0 -27
- package/dist/plugins/api-keys/apiKeys.mjs +0 -129
- package/dist/plugins/api-keys/cli.cjs +0 -115
- package/dist/plugins/api-keys/cli.mjs +0 -114
- package/dist/plugins/api-keys/model.cjs +0 -58
- package/dist/plugins/api-keys/model.d.cts +0 -26
- package/dist/plugins/api-keys/model.d.mts +0 -26
- package/dist/plugins/api-keys/model.mjs +0 -58
- package/dist/plugins/api-keys/schema.cjs +0 -38
- package/dist/plugins/api-keys/schema.d.cts +0 -44
- package/dist/plugins/api-keys/schema.d.mts +0 -44
- package/dist/plugins/api-keys/schema.mjs +0 -39
- package/dist/plugins/definePlugin.cjs +0 -5
- package/dist/plugins/definePlugin.mjs +0 -5
- package/dist/plugins/index.cjs +0 -38
- package/dist/plugins/index.d.cts +0 -12
- package/dist/plugins/index.d.mts +0 -12
- package/dist/plugins/index.mjs +0 -9
- package/dist/plugins/insights/contract.cjs +0 -193
- package/dist/plugins/insights/contract.mjs +0 -189
- package/dist/plugins/insights/domain.d.cts +0 -149
- package/dist/plugins/insights/domain.d.mts +0 -149
- package/dist/plugins/insights/errors.cjs +0 -15
- package/dist/plugins/insights/errors.mjs +0 -14
- package/dist/plugins/insights/eventInput.cjs +0 -284
- package/dist/plugins/insights/eventInput.mjs +0 -282
- package/dist/plugins/insights/eventRow.cjs +0 -49
- package/dist/plugins/insights/eventRow.d.cts +0 -64
- package/dist/plugins/insights/eventRow.d.mts +0 -64
- package/dist/plugins/insights/eventRow.mjs +0 -47
- package/dist/plugins/insights/model.cjs +0 -17
- package/dist/plugins/insights/model.d.cts +0 -10
- package/dist/plugins/insights/model.d.mts +0 -10
- package/dist/plugins/insights/model.mjs +0 -17
- package/dist/plugins/insights/modelTypes.d.cts +0 -176
- package/dist/plugins/insights/modelTypes.d.mts +0 -176
- package/dist/plugins/insights/overview.cjs +0 -109
- package/dist/plugins/insights/overview.d.cts +0 -15
- package/dist/plugins/insights/overview.d.mts +0 -15
- package/dist/plugins/insights/overview.mjs +0 -107
- package/dist/plugins/insights/provider.cjs +0 -375
- package/dist/plugins/insights/provider.d.cts +0 -6
- package/dist/plugins/insights/provider.d.mts +0 -6
- package/dist/plugins/insights/provider.mjs +0 -374
- package/dist/plugins/insights/queryInput.cjs +0 -93
- package/dist/plugins/insights/queryInput.mjs +0 -91
- package/dist/plugins/insights/reads.cjs +0 -681
- package/dist/plugins/insights/reads.d.cts +0 -61
- package/dist/plugins/insights/reads.d.mts +0 -61
- package/dist/plugins/insights/reads.mjs +0 -674
- package/dist/plugins/insights/recordEvent.cjs +0 -319
- package/dist/plugins/insights/recordEvent.d.cts +0 -18
- package/dist/plugins/insights/recordEvent.d.mts +0 -18
- package/dist/plugins/insights/recordEvent.mjs +0 -316
- package/dist/plugins/insights/routes.cjs +0 -96
- package/dist/plugins/insights/routes.mjs +0 -95
- package/dist/plugins/insights/schema.cjs +0 -489
- package/dist/plugins/insights/schema.d.cts +0 -698
- package/dist/plugins/insights/schema.d.mts +0 -698
- package/dist/plugins/insights/schema.mjs +0 -483
- package/dist/plugins/insights/testing/eventRow.d.mts +0 -64
- package/dist/plugins/insights/testing/expectInsightsIndex.mjs +0 -18
- package/dist/plugins/insights/testing/fixtures.d.mts +0 -8
- package/dist/plugins/insights/testing/fixtures.mjs +0 -25
- package/dist/plugins/insights/testing/index.d.mts +0 -24
- package/dist/plugins/insights/testing/index.mjs +0 -25
- package/dist/plugins/insights/testing/insightsModelTests.mjs +0 -714
- package/dist/plugins/insights/testing/modelTypes.d.mts +0 -176
- package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.d.mts +0 -11
- package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.mjs +0 -107
- package/dist/plugins/insights/testing/setupInsightsModelTestSuite.d.mts +0 -11
- package/dist/plugins/insights/testing/setupInsightsModelTestSuite.mjs +0 -31
- package/dist/plugins/insights/testing/types.d.mts +0 -26
- package/dist/plugins/insights/types.d.cts +0 -33
- package/dist/plugins/insights/types.d.mts +0 -33
- package/src/adapters/drizzle.conformance.integration.spec.ts +0 -34
- package/src/adapters/drizzle.readBudgets.integration.spec.ts +0 -43
- package/src/adapters/drizzle.spec.ts +0 -314
- package/src/adapters/drizzle.ts +0 -64
- package/src/adapters/drizzleExecutor.ts +0 -166
- package/src/adapters/kysely.conformance.integration.spec.ts +0 -36
- package/src/adapters/kysely.readBudgets.integration.spec.ts +0 -44
- package/src/adapters/kysely.spec.ts +0 -244
- package/src/adapters/kysely.ts +0 -46
- package/src/adapters/kyselyExecutor.ts +0 -53
- package/src/adapters/mongodb.integration.spec.ts +0 -271
- package/src/adapters/mongodb.readBudgets.integration.spec.ts +0 -61
- package/src/adapters/mongodb.ts +0 -45
- package/src/adapters/mongodbAdapter.ts +0 -307
- package/src/adapters/prisma.conformance.integration.spec.ts +0 -36
- package/src/adapters/prisma.integration.spec.ts +0 -146
- package/src/adapters/prisma.readBudgets.integration.spec.ts +0 -43
- package/src/adapters/prisma.spec.ts +0 -257
- package/src/adapters/prisma.ts +0 -74
- package/src/adapters/prismaExecutor.ts +0 -107
- package/src/adapters/prismaTestClients.ts +0 -182
- package/src/adapters/sqlProviders.ts +0 -14
- package/src/assembly/assemblePlugins.ts +0 -302
- package/src/assembly/assembly.spec.ts +0 -377
- package/src/assembly/assembly.types.spec.ts +0 -203
- package/src/assembly/clientPlugins.ts +0 -113
- package/src/assembly/configError.ts +0 -4
- package/src/assembly/databasePlugins.spec.ts +0 -71
- package/src/assembly/databasePlugins.ts +0 -102
- package/src/assembly/pluginCli.spec.ts +0 -254
- package/src/assembly/pluginCli.ts +0 -248
- package/src/assembly/pluginRoutes.spec.ts +0 -186
- package/src/core/api.ts +0 -139
- package/src/core/baseCandidates.spec.ts +0 -378
- package/src/core/baseCandidates.ts +0 -136
- package/src/core/index.ts +0 -44
- package/src/core/operations.spec.ts +0 -415
- package/src/core/operations.ts +0 -551
- package/src/core/reads.spec.ts +0 -300
- package/src/core/reads.ts +0 -417
- package/src/core/releases.spec.ts +0 -308
- package/src/core/releases.ts +0 -345
- package/src/core/schema.ts +0 -173
- package/src/core/writes.ts +0 -160
- package/src/createHotUpdaterCore.ts +0 -260
- package/src/database/aggregateBatching.spec.ts +0 -577
- package/src/database/aggregateBatching.ts +0 -803
- package/src/database/busy.spec.ts +0 -45
- package/src/database/busy.ts +0 -50
- package/src/database/cursor.ts +0 -65
- package/src/database/database.ts +0 -366
- package/src/database/database.types.spec.ts +0 -135
- package/src/database/definitions.ts +0 -76
- package/src/database/engine.ts +0 -62
- package/src/database/engineAggregates.spec.ts +0 -536
- package/src/database/engineAggregates.ts +0 -189
- package/src/database/engineReads.spec.ts +0 -219
- package/src/database/engineReads.ts +0 -304
- package/src/database/engineTransaction.spec.ts +0 -710
- package/src/database/engineTransaction.ts +0 -582
- package/src/database/errors.ts +0 -30
- package/src/database/fence.spec.ts +0 -223
- package/src/database/fence.ts +0 -175
- package/src/database/index.ts +0 -160
- package/src/database/kv/kvAdapter.batching.integration.spec.ts +0 -15
- package/src/database/kv/kvAdapter.conformance.integration.spec.ts +0 -19
- package/src/database/kv/kvAdapter.readBudgets.integration.spec.ts +0 -17
- package/src/database/kv/kvAdapter.spec.ts +0 -595
- package/src/database/kv/kvAdapter.ts +0 -479
- package/src/database/kv/kvTestStore.ts +0 -118
- package/src/database/memory.readBudgets.integration.spec.ts +0 -13
- package/src/database/resolveSchema.spec.ts +0 -230
- package/src/database/resolveSchema.ts +0 -375
- package/src/database/retention.spec.ts +0 -314
- package/src/database/retention.ts +0 -129
- package/src/database/schema.ts +0 -213
- package/src/database/schema.types.spec.ts +0 -94
- package/src/database/sql/docker-compose.yml +0 -36
- package/src/database/sql/sqlAdapter.integration.spec.ts +0 -145
- package/src/database/sql/sqlAdapter.readBudgets.integration.spec.ts +0 -123
- package/src/database/sql/sqlAdapter.spec.ts +0 -343
- package/src/database/sql/sqlAdapter.ts +0 -552
- package/src/database/sql/sqlSchema.ts +0 -286
- package/src/database/sql/sqlTestExecutors.ts +0 -183
- package/src/databaseTestSuite.spec.ts +0 -44
- package/src/db/bundleRows.spec.ts +0 -164
- package/src/db/bundleRows.ts +0 -10
- package/src/db/coreDatabase.ts +0 -153
- package/src/db/createBundleDiff.spec.ts +0 -464
- package/src/db/createBundleDiff.ts +0 -370
- package/src/db/engineDrizzleSchema.ts +0 -72
- package/src/db/engineMigrator.ts +0 -105
- package/src/db/enginePrismaSchema.ts +0 -147
- package/src/db/engineSql.spec.ts +0 -130
- package/src/db/engineSql.ts +0 -48
- package/src/db/engineSqlMigrator.ts +0 -116
- package/src/db/fixedMigratorShared.ts +0 -17
- package/src/db/index.spec.ts +0 -554
- package/src/db/index.ts +0 -93
- package/src/db/node-sqlite.d.ts +0 -25
- package/src/db/pluginTables.spec.ts +0 -248
- package/src/db/releaseCatalog.ts +0 -106
- package/src/db/schemaSettings.ts +0 -104
- package/src/db/settingsMigrator.spec.ts +0 -65
- package/src/db/settingsMigrator.ts +0 -152
- package/src/db/types.ts +0 -82
- package/src/db/updateArtifacts.spec.ts +0 -235
- package/src/db/updateArtifacts.ts +0 -473
- package/src/db/updateCheck.bench.ts +0 -47
- package/src/diff.ts +0 -6
- package/src/handler-standalone.integration.spec.ts +0 -321
- package/src/handler.spec.ts +0 -273
- package/src/handler.testFixtures.ts +0 -25
- package/src/handler.ts +0 -302
- package/src/handlerAdminRoutes.spec.ts +0 -183
- package/src/handlerAdminRoutes.ts +0 -536
- package/src/handlerAuth.integration.spec.ts +0 -33
- package/src/handlerErrors.ts +0 -7
- package/src/handlerManagement.spec.ts +0 -202
- package/src/handlerParameters.ts +0 -105
- package/src/handlerReleaseCatalogRoutes.ts +0 -176
- package/src/handlerTypes.ts +0 -19
- package/src/handlerVersionRoutes.ts +0 -25
- package/src/index.ts +0 -13
- package/src/internalRouter.ts +0 -104
- package/src/lintRules.spec.ts +0 -76
- package/src/node.spec.ts +0 -119
- package/src/node.ts +0 -111
- package/src/plugins/api-keys/apiKeys.integration.spec.ts +0 -92
- package/src/plugins/api-keys/apiKeys.spec.ts +0 -166
- package/src/plugins/api-keys/apiKeys.ts +0 -214
- package/src/plugins/api-keys/apiKeysPlugin.spec.ts +0 -168
- package/src/plugins/api-keys/cli.spec.ts +0 -187
- package/src/plugins/api-keys/cli.ts +0 -140
- package/src/plugins/api-keys/index.ts +0 -73
- package/src/plugins/api-keys/model.ts +0 -88
- package/src/plugins/api-keys/schema.ts +0 -22
- package/src/plugins/definePlugin.ts +0 -242
- package/src/plugins/index.ts +0 -73
- package/src/plugins/insights/contract.spec.ts +0 -285
- package/src/plugins/insights/contract.ts +0 -372
- package/src/plugins/insights/domain.ts +0 -176
- package/src/plugins/insights/errors.ts +0 -11
- package/src/plugins/insights/eventInput.ts +0 -381
- package/src/plugins/insights/eventRow.ts +0 -209
- package/src/plugins/insights/index.ts +0 -222
- package/src/plugins/insights/insights.integration.spec.ts +0 -921
- package/src/plugins/insights/insightsRollout.integration.spec.ts +0 -186
- package/src/plugins/insights/model.spec.ts +0 -64
- package/src/plugins/insights/model.ts +0 -18
- package/src/plugins/insights/modelTypes.ts +0 -197
- package/src/plugins/insights/overview.spec.ts +0 -64
- package/src/plugins/insights/overview.ts +0 -214
- package/src/plugins/insights/provider.spec.ts +0 -585
- package/src/plugins/insights/provider.ts +0 -704
- package/src/plugins/insights/queryInput.ts +0 -142
- package/src/plugins/insights/reads.spec.ts +0 -1013
- package/src/plugins/insights/reads.ts +0 -1037
- package/src/plugins/insights/recordEvent.spec.ts +0 -897
- package/src/plugins/insights/recordEvent.ts +0 -476
- package/src/plugins/insights/retention.spec.ts +0 -115
- package/src/plugins/insights/routes.ts +0 -149
- package/src/plugins/insights/schema.ts +0 -409
- package/src/plugins/insights/testing/expectInsightsIndex.spec.ts +0 -42
- package/src/plugins/insights/testing/expectInsightsIndex.ts +0 -20
- package/src/plugins/insights/testing/fixtures.ts +0 -30
- package/src/plugins/insights/testing/index.ts +0 -45
- package/src/plugins/insights/testing/insightsModelTests.ts +0 -860
- package/src/plugins/insights/testing/setupInsightsHttpTestSuite.ts +0 -152
- package/src/plugins/insights/testing/setupInsightsModelTestSuite.ts +0 -36
- package/src/plugins/insights/testing/types.ts +0 -30
- package/src/plugins/insights/types.ts +0 -55
- package/src/plugins/pluginTestHarness.spec.ts +0 -56
- package/src/readBudgets.testFixtures.ts +0 -15
- package/src/releaseCatalogRoutes.integration.spec.ts +0 -200
- package/src/retention.spec.ts +0 -73
- package/src/runtime.spec.ts +0 -207
- package/src/runtime.testFixtures.ts +0 -60
- package/src/runtimeBundles.integration.spec.ts +0 -112
- package/src/storageAccess.spec.ts +0 -152
- package/src/storageAccess.ts +0 -141
- package/src/testUtilsMutation.integration.spec.ts +0 -216
- package/src/testUtilsPackage.integration.spec.ts +0 -180
- package/src/types/index.ts +0 -2
- package/src/version.ts +0 -3
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import type { ApiKeyModel, ApiKeyRow } from "./model";
|
|
2
|
-
|
|
3
|
-
export const API_KEY_HEADER_NAME = "x-api-key";
|
|
4
|
-
|
|
5
|
-
const BASE64URL_32_PATTERN = /^[A-Za-z0-9_-]{43}$/u;
|
|
6
|
-
|
|
7
|
-
const bytesToBase64Url = (bytes: Uint8Array): string => {
|
|
8
|
-
let binary = "";
|
|
9
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
10
|
-
return btoa(binary)
|
|
11
|
-
.replaceAll("+", "-")
|
|
12
|
-
.replaceAll("/", "_")
|
|
13
|
-
.replace(/=+$/u, "");
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const isApiKey = (value: string): boolean => {
|
|
17
|
-
if (!BASE64URL_32_PATTERN.test(value)) return false;
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const base64 = value.replaceAll("-", "+").replaceAll("_", "/");
|
|
21
|
-
const binary = atob(`${base64}=`);
|
|
22
|
-
const bytes = Uint8Array.from(binary, (character) =>
|
|
23
|
-
character.charCodeAt(0),
|
|
24
|
-
);
|
|
25
|
-
return bytes.byteLength === 32 && bytesToBase64Url(bytes) === value;
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const normalizeApiKeyHeaderName = (
|
|
32
|
-
value: unknown = API_KEY_HEADER_NAME,
|
|
33
|
-
): string => {
|
|
34
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
35
|
-
throw new TypeError("apiKeys({ headerName }) must name a valid header.");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const headers = new Headers();
|
|
40
|
-
headers.set(value, "");
|
|
41
|
-
return headers.keys().next().value!;
|
|
42
|
-
} catch {
|
|
43
|
-
throw new TypeError("apiKeys({ headerName }) must name a valid header.");
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const hashApiKey = async (apiKey: string): Promise<string> => {
|
|
48
|
-
if (!isApiKey(apiKey)) {
|
|
49
|
-
throw new TypeError("API key must be a canonical 32-byte base64url value.");
|
|
50
|
-
}
|
|
51
|
-
const digest = await crypto.subtle.digest(
|
|
52
|
-
"SHA-256",
|
|
53
|
-
new TextEncoder().encode(apiKey),
|
|
54
|
-
);
|
|
55
|
-
return bytesToBase64Url(new Uint8Array(digest));
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const apiKeyId = (): string => {
|
|
59
|
-
const bytes = new Uint8Array(16);
|
|
60
|
-
crypto.getRandomValues(bytes);
|
|
61
|
-
return `api-${bytesToBase64Url(bytes)}`;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const normalizeApiKeyName = (name: string): string => {
|
|
65
|
-
const normalized = name.trim();
|
|
66
|
-
if (
|
|
67
|
-
normalized.length === 0 ||
|
|
68
|
-
normalized.length > 64 ||
|
|
69
|
-
/[\p{Cc}\p{Cf}]/u.test(normalized)
|
|
70
|
-
) {
|
|
71
|
-
throw new TypeError("API key names must contain 1-64 visible characters.");
|
|
72
|
-
}
|
|
73
|
-
return normalized;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export type ApiKeyMetadata = Omit<ApiKeyRow, "hash">;
|
|
77
|
-
|
|
78
|
-
export interface CreatedApiKey {
|
|
79
|
-
/** Plaintext credential. It cannot be recovered after this call returns. */
|
|
80
|
-
readonly apiKey: string;
|
|
81
|
-
/** Non-secret metadata. The persisted SHA-256 hash is never exposed. */
|
|
82
|
-
readonly record: ApiKeyMetadata;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface ApiKeyManagementAPI {
|
|
86
|
-
/** Creates an API key and returns its plaintext exactly once. */
|
|
87
|
-
create(input: { readonly name: string }): Promise<{
|
|
88
|
-
readonly apiKey: string;
|
|
89
|
-
readonly record: ApiKeyMetadata;
|
|
90
|
-
}>;
|
|
91
|
-
/** Lists non-secret API key metadata, including revoked keys. */
|
|
92
|
-
list(): Promise<readonly ApiKeyMetadata[]>;
|
|
93
|
-
/** Revokes an API key immediately and returns only non-secret metadata. */
|
|
94
|
-
revoke(input: { readonly id: string }): Promise<ApiKeyMetadata | null>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const toApiKeyMetadata = ({
|
|
98
|
-
hash: _hash,
|
|
99
|
-
...metadata
|
|
100
|
-
}: ApiKeyRow): ApiKeyMetadata => Object.freeze(metadata);
|
|
101
|
-
|
|
102
|
-
export const registerApiKey = async (input: {
|
|
103
|
-
readonly apiKey: string;
|
|
104
|
-
readonly apiKeys: ApiKeyModel;
|
|
105
|
-
readonly createdAtMs?: number;
|
|
106
|
-
readonly name: string;
|
|
107
|
-
}): Promise<CreatedApiKey> => {
|
|
108
|
-
const hash = await hashApiKey(input.apiKey);
|
|
109
|
-
const createdAtMs = input.createdAtMs ?? Date.now();
|
|
110
|
-
if (!Number.isSafeInteger(createdAtMs) || createdAtMs < 0) {
|
|
111
|
-
throw new TypeError("API key creation time must be non-negative.");
|
|
112
|
-
}
|
|
113
|
-
const record = Object.freeze({
|
|
114
|
-
created_at_ms: createdAtMs,
|
|
115
|
-
hash,
|
|
116
|
-
id: apiKeyId(),
|
|
117
|
-
name: normalizeApiKeyName(input.name),
|
|
118
|
-
prefix: input.apiKey.slice(0, 6),
|
|
119
|
-
revoked_at_ms: null,
|
|
120
|
-
role: "client" as const,
|
|
121
|
-
});
|
|
122
|
-
const status = await input.apiKeys.create(record);
|
|
123
|
-
if (status === "existing") {
|
|
124
|
-
const existing = await input.apiKeys.findByHash(hash);
|
|
125
|
-
if (existing === null || existing.revoked_at_ms !== null) {
|
|
126
|
-
throw new Error("The API key has been revoked.");
|
|
127
|
-
}
|
|
128
|
-
return Object.freeze({
|
|
129
|
-
apiKey: input.apiKey,
|
|
130
|
-
record: toApiKeyMetadata(existing),
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return Object.freeze({
|
|
134
|
-
apiKey: input.apiKey,
|
|
135
|
-
record: toApiKeyMetadata(record),
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export const createApiKey = (input: {
|
|
140
|
-
readonly apiKeys: ApiKeyModel;
|
|
141
|
-
readonly name: string;
|
|
142
|
-
}): Promise<CreatedApiKey> => {
|
|
143
|
-
const bytes = new Uint8Array(32);
|
|
144
|
-
crypto.getRandomValues(bytes);
|
|
145
|
-
return registerApiKey({
|
|
146
|
-
apiKey: bytesToBase64Url(bytes),
|
|
147
|
-
apiKeys: input.apiKeys,
|
|
148
|
-
name: input.name,
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Provisions the client API key used by managed init.
|
|
154
|
-
*
|
|
155
|
-
* A saved plaintext key is registered idempotently; otherwise a new key is
|
|
156
|
-
* created. Callers must persist or display the returned plaintext because the
|
|
157
|
-
* database stores only its hash.
|
|
158
|
-
*/
|
|
159
|
-
export const provisionApiKey = (input: {
|
|
160
|
-
readonly apiKeys: ApiKeyModel;
|
|
161
|
-
readonly existingApiKey?: string;
|
|
162
|
-
readonly name: string;
|
|
163
|
-
}): Promise<CreatedApiKey> => {
|
|
164
|
-
const existingApiKey = input.existingApiKey?.trim();
|
|
165
|
-
return existingApiKey
|
|
166
|
-
? registerApiKey({
|
|
167
|
-
apiKey: existingApiKey,
|
|
168
|
-
apiKeys: input.apiKeys,
|
|
169
|
-
name: input.name,
|
|
170
|
-
})
|
|
171
|
-
: createApiKey({ apiKeys: input.apiKeys, name: input.name });
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
export const authenticateApiKey = async (input: {
|
|
175
|
-
readonly apiKeys: ApiKeyModel;
|
|
176
|
-
readonly headerName?: string;
|
|
177
|
-
readonly request: Request;
|
|
178
|
-
}): Promise<boolean> => {
|
|
179
|
-
const apiKey = input.request.headers.get(
|
|
180
|
-
normalizeApiKeyHeaderName(input.headerName),
|
|
181
|
-
);
|
|
182
|
-
if (apiKey === null || !isApiKey(apiKey)) return false;
|
|
183
|
-
const hash = await hashApiKey(apiKey);
|
|
184
|
-
const record = await input.apiKeys.findByHash(hash);
|
|
185
|
-
return (
|
|
186
|
-
record !== null &&
|
|
187
|
-
record.hash === hash &&
|
|
188
|
-
record.role === "client" &&
|
|
189
|
-
record.revoked_at_ms === null
|
|
190
|
-
);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export const createApiKeyManagement = (input: {
|
|
194
|
-
readonly apiKeys: ApiKeyModel;
|
|
195
|
-
}): ApiKeyManagementAPI =>
|
|
196
|
-
Object.freeze({
|
|
197
|
-
async create({ name }: { readonly name: string }) {
|
|
198
|
-
const created = await createApiKey({ apiKeys: input.apiKeys, name });
|
|
199
|
-
return Object.freeze({
|
|
200
|
-
apiKey: created.apiKey,
|
|
201
|
-
record: created.record,
|
|
202
|
-
});
|
|
203
|
-
},
|
|
204
|
-
async list() {
|
|
205
|
-
return Object.freeze((await input.apiKeys.list()).map(toApiKeyMetadata));
|
|
206
|
-
},
|
|
207
|
-
async revoke({ id }: { readonly id: string }) {
|
|
208
|
-
const record = await input.apiKeys.revoke({
|
|
209
|
-
id,
|
|
210
|
-
revokedAtMs: Date.now(),
|
|
211
|
-
});
|
|
212
|
-
return record === null ? null : toApiKeyMetadata(record);
|
|
213
|
-
},
|
|
214
|
-
});
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createMemoryAdapter,
|
|
3
|
-
type DatabaseAdapter,
|
|
4
|
-
} from "@hot-updater/plugin-core/internal";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
|
|
7
|
-
import { createHotUpdater } from "../../createHotUpdaterCore";
|
|
8
|
-
import { definePlugin } from "../definePlugin";
|
|
9
|
-
import { apiKeys } from "./index";
|
|
10
|
-
|
|
11
|
-
const API_KEY = "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE";
|
|
12
|
-
|
|
13
|
-
/** A client endpoint with a cacheable answer, to see the policy's Vary. */
|
|
14
|
-
const cached = definePlugin({
|
|
15
|
-
id: "cached",
|
|
16
|
-
schemaVersion: "1",
|
|
17
|
-
schema: {},
|
|
18
|
-
init: () => ({
|
|
19
|
-
api: {},
|
|
20
|
-
endpoints: [
|
|
21
|
-
{
|
|
22
|
-
method: "GET",
|
|
23
|
-
path: "/cached",
|
|
24
|
-
access: "client",
|
|
25
|
-
handler: async () =>
|
|
26
|
-
new Response("ok", {
|
|
27
|
-
headers: { "cache-control": "public, max-age=60" },
|
|
28
|
-
}),
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const start = (
|
|
35
|
-
options: { headerName?: string; adapter?: DatabaseAdapter } = {},
|
|
36
|
-
) => {
|
|
37
|
-
const hotUpdater = createHotUpdater({
|
|
38
|
-
database: {
|
|
39
|
-
name: "memory",
|
|
40
|
-
adapter: options.adapter ?? createMemoryAdapter(),
|
|
41
|
-
},
|
|
42
|
-
plugins: [
|
|
43
|
-
apiKeys(
|
|
44
|
-
options.headerName === undefined
|
|
45
|
-
? {}
|
|
46
|
-
: { headerName: options.headerName },
|
|
47
|
-
),
|
|
48
|
-
cached,
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
const client = (
|
|
52
|
-
path: string,
|
|
53
|
-
headers: Record<string, string> = {},
|
|
54
|
-
init: RequestInit = {},
|
|
55
|
-
) =>
|
|
56
|
-
hotUpdater.handlers.client(
|
|
57
|
-
new Request(`https://updates.example.com${path}`, { ...init, headers }),
|
|
58
|
-
);
|
|
59
|
-
return { hotUpdater, client };
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
describe("API keys plugin", () => {
|
|
63
|
-
it("protects every client route but /version with a registered, active key", async () => {
|
|
64
|
-
const { hotUpdater, client } = start();
|
|
65
|
-
await hotUpdater.api.apiKeys.register({ apiKey: API_KEY, name: "App" });
|
|
66
|
-
const catalog = "/release-catalogs/app-version/ios/production/1.0.0";
|
|
67
|
-
|
|
68
|
-
expect((await client("/version")).status).toBe(200);
|
|
69
|
-
expect((await client(catalog)).status).toBe(401);
|
|
70
|
-
expect((await client(catalog, { "x-api-key": "not-a-key" })).status).toBe(
|
|
71
|
-
401,
|
|
72
|
-
);
|
|
73
|
-
// No insights() here, so /events is no route, with or without a key.
|
|
74
|
-
const keyed: readonly Record<string, string>[] = [
|
|
75
|
-
{},
|
|
76
|
-
{ "x-api-key": API_KEY },
|
|
77
|
-
];
|
|
78
|
-
for (const headers of keyed) {
|
|
79
|
-
expect(
|
|
80
|
-
(await client("/events", headers, { method: "POST", body: "{" }))
|
|
81
|
-
.status,
|
|
82
|
-
).toBe(404);
|
|
83
|
-
}
|
|
84
|
-
const allowed = await client("/cached", { "x-api-key": API_KEY });
|
|
85
|
-
expect(allowed.status).toBe(200);
|
|
86
|
-
expect(allowed.headers.get("vary")).toBe("x-api-key");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("creates keys once in plaintext, lists and revokes them without hashes", async () => {
|
|
90
|
-
const { hotUpdater, client } = start();
|
|
91
|
-
const created = await hotUpdater.api.apiKeys.create({ name: " Deploy " });
|
|
92
|
-
expect(created.record).toMatchObject({
|
|
93
|
-
name: "Deploy",
|
|
94
|
-
prefix: created.apiKey.slice(0, 6),
|
|
95
|
-
role: "client",
|
|
96
|
-
revoked_at_ms: null,
|
|
97
|
-
});
|
|
98
|
-
const listed = await hotUpdater.api.apiKeys.list();
|
|
99
|
-
expect(listed).toEqual([created.record]);
|
|
100
|
-
expect(JSON.stringify(listed)).not.toContain("hash");
|
|
101
|
-
expect(
|
|
102
|
-
(await client("/cached", { "x-api-key": created.apiKey })).status,
|
|
103
|
-
).toBe(200);
|
|
104
|
-
|
|
105
|
-
await expect(
|
|
106
|
-
hotUpdater.api.apiKeys.revoke({ id: created.record.id }),
|
|
107
|
-
).resolves.toMatchObject({
|
|
108
|
-
id: created.record.id,
|
|
109
|
-
revoked_at_ms: expect.any(Number),
|
|
110
|
-
});
|
|
111
|
-
expect(
|
|
112
|
-
(await client("/cached", { "x-api-key": created.apiKey })).status,
|
|
113
|
-
).toBe(401);
|
|
114
|
-
await expect(
|
|
115
|
-
hotUpdater.api.apiKeys.revoke({ id: "missing" }),
|
|
116
|
-
).resolves.toBeNull();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("provisions a saved key idempotently and a new key otherwise", async () => {
|
|
120
|
-
const { hotUpdater } = start();
|
|
121
|
-
const first = await hotUpdater.api.apiKeys.provision({
|
|
122
|
-
existingApiKey: API_KEY,
|
|
123
|
-
name: "Managed",
|
|
124
|
-
});
|
|
125
|
-
const again = await hotUpdater.api.apiKeys.provision({
|
|
126
|
-
existingApiKey: ` ${API_KEY} `,
|
|
127
|
-
name: "Managed",
|
|
128
|
-
});
|
|
129
|
-
expect(again.record.id).toBe(first.record.id);
|
|
130
|
-
const fresh = await hotUpdater.api.apiKeys.provision({ name: "Managed" });
|
|
131
|
-
expect(fresh.apiKey).not.toBe(API_KEY);
|
|
132
|
-
expect(await hotUpdater.api.apiKeys.list()).toHaveLength(2);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("reads keys only from the configured header and varies by it", async () => {
|
|
136
|
-
const { hotUpdater, client } = start({ headerName: "X-Hot-Updater-Key" });
|
|
137
|
-
await hotUpdater.api.apiKeys.register({ apiKey: API_KEY, name: "App" });
|
|
138
|
-
|
|
139
|
-
expect((await client("/cached", { "x-api-key": API_KEY })).status).toBe(
|
|
140
|
-
401,
|
|
141
|
-
);
|
|
142
|
-
const allowed = await client("/cached", { "x-hot-updater-key": API_KEY });
|
|
143
|
-
expect(allowed.status).toBe(200);
|
|
144
|
-
expect(allowed.headers.get("vary")).toBe("x-hot-updater-key");
|
|
145
|
-
expect(() => apiKeys({ headerName: "invalid header" })).toThrow(
|
|
146
|
-
"must name a valid header",
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("answers 503 when credential storage is unavailable", async () => {
|
|
151
|
-
const memory = createMemoryAdapter();
|
|
152
|
-
const { client } = start({
|
|
153
|
-
adapter: {
|
|
154
|
-
...memory,
|
|
155
|
-
get: async () => {
|
|
156
|
-
throw new Error("storage unavailable");
|
|
157
|
-
},
|
|
158
|
-
query: async () => {
|
|
159
|
-
throw new Error("storage unavailable");
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
expect((await client("/cached", { "x-api-key": API_KEY })).status).toBe(
|
|
164
|
-
503,
|
|
165
|
-
);
|
|
166
|
-
expect((await client("/version")).status).toBe(200);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { createMemoryAdapter } from "@hot-updater/plugin-core/internal";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { createDatabasePluginApis } from "../../assembly/databasePlugins";
|
|
5
|
-
import type { PluginCommand, PluginCommandUi } from "../definePlugin";
|
|
6
|
-
import type { ApiKeyMetadata } from "./apiKeys";
|
|
7
|
-
import { type ApiKeysCliApi, apiKeysCli } from "./cli";
|
|
8
|
-
import { apiKeys } from "./index";
|
|
9
|
-
|
|
10
|
-
/** A UI that keeps what the command writes, unstyled. */
|
|
11
|
-
const createUi = () => {
|
|
12
|
-
const output = { messages: [] as string[], warnings: [] as string[] };
|
|
13
|
-
const printed: string[] = [];
|
|
14
|
-
const ui: PluginCommandUi = {
|
|
15
|
-
block: (heading, lines) => [heading, ...lines].join("\n"),
|
|
16
|
-
kv: (label, value) => `${label}: ${value}`,
|
|
17
|
-
table: (columns, rows) =>
|
|
18
|
-
rows
|
|
19
|
-
.map((row) => columns.map(({ key }) => row[key]).join(" | "))
|
|
20
|
-
.join("\n"),
|
|
21
|
-
id: (value) => value,
|
|
22
|
-
muted: (value) => value,
|
|
23
|
-
success: (value) => value,
|
|
24
|
-
danger: (value) => value,
|
|
25
|
-
warning: (value) => value,
|
|
26
|
-
message: (text) => output.messages.push(text),
|
|
27
|
-
info: (text) => output.messages.push(text),
|
|
28
|
-
warn: (text) => output.warnings.push(text),
|
|
29
|
-
print: (text) => printed.push(text),
|
|
30
|
-
confirm: vi.fn(async () => {}),
|
|
31
|
-
};
|
|
32
|
-
return { ui, output, printed };
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const command = (name: string): PluginCommand<ApiKeysCliApi> => {
|
|
36
|
-
const group = apiKeysCli("x-api-key").commands?.[0];
|
|
37
|
-
const found = group?.commands?.find((candidate) => candidate.name === name);
|
|
38
|
-
if (found?.run === undefined) throw new Error(`No ${name} command.`);
|
|
39
|
-
return found;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/** The apiKeys() plugin's API over a memory adapter, as the CLI assembles it. */
|
|
43
|
-
const assemble = () =>
|
|
44
|
-
createDatabasePluginApis({ name: "memory", adapter: createMemoryAdapter() }, [
|
|
45
|
-
apiKeys(),
|
|
46
|
-
]).apiKeys;
|
|
47
|
-
|
|
48
|
-
describe("apiKeys() CLI commands", () => {
|
|
49
|
-
it("adds `hot-updater api-key` with create, list, and revoke", () => {
|
|
50
|
-
const [group] = apiKeysCli("x-api-key").commands ?? [];
|
|
51
|
-
expect(group?.name).toBe("api-key");
|
|
52
|
-
expect(group?.commands?.map(({ name }) => name)).toEqual([
|
|
53
|
-
"create",
|
|
54
|
-
"list",
|
|
55
|
-
"revoke",
|
|
56
|
-
]);
|
|
57
|
-
expect(apiKeys().cli?.commands?.map(({ name }) => name)).toEqual([
|
|
58
|
-
"api-key",
|
|
59
|
-
]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("creates a key and prints its plaintext exactly once", async () => {
|
|
63
|
-
const api = assemble();
|
|
64
|
-
const { ui, output } = createUi();
|
|
65
|
-
|
|
66
|
-
await command("create").run!({
|
|
67
|
-
api,
|
|
68
|
-
args: {},
|
|
69
|
-
options: { name: "Production app" },
|
|
70
|
-
ui,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const [record] = await api.list();
|
|
74
|
-
expect(record?.name).toBe("Production app");
|
|
75
|
-
const printed = output.messages.join("\n");
|
|
76
|
-
const apiKey = /API key: (\S+)/u.exec(printed)?.[1];
|
|
77
|
-
expect(apiKey).toMatch(/^[A-Za-z0-9_-]{43}$/u);
|
|
78
|
-
expect(printed.split(apiKey!).length - 1).toBe(1);
|
|
79
|
-
expect(JSON.stringify(record)).not.toContain(apiKey);
|
|
80
|
-
expect(output.warnings).toEqual([
|
|
81
|
-
"Save this API key now. It will not be shown again.",
|
|
82
|
-
]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("lists JSON metadata newest first, without hashes or plaintext", async () => {
|
|
86
|
-
const api = assemble();
|
|
87
|
-
const older = await api.create({ name: "Older" });
|
|
88
|
-
await new Promise((resolve) => setTimeout(resolve, 2));
|
|
89
|
-
const newer = await api.create({ name: "Newer" });
|
|
90
|
-
const { ui, printed } = createUi();
|
|
91
|
-
|
|
92
|
-
await command("list").run!({ api, args: {}, options: { json: true }, ui });
|
|
93
|
-
|
|
94
|
-
const json = printed.join("\n");
|
|
95
|
-
const records = JSON.parse(json) as ApiKeyMetadata[];
|
|
96
|
-
expect(records.map(({ id }) => id)).toEqual([
|
|
97
|
-
newer.record.id,
|
|
98
|
-
older.record.id,
|
|
99
|
-
]);
|
|
100
|
-
expect(json).not.toContain("hash");
|
|
101
|
-
expect(json).not.toContain(older.apiKey);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("lists a table, or says there are no keys", async () => {
|
|
105
|
-
const api = assemble();
|
|
106
|
-
const empty = createUi();
|
|
107
|
-
await command("list").run!({
|
|
108
|
-
api,
|
|
109
|
-
args: {},
|
|
110
|
-
options: {},
|
|
111
|
-
ui: empty.ui,
|
|
112
|
-
});
|
|
113
|
-
expect(empty.output.messages).toEqual(["(no API keys)"]);
|
|
114
|
-
|
|
115
|
-
const created = await api.create({ name: "Production app" });
|
|
116
|
-
await api.revoke({ id: created.record.id });
|
|
117
|
-
const listed = createUi();
|
|
118
|
-
await command("list").run!({
|
|
119
|
-
api,
|
|
120
|
-
args: {},
|
|
121
|
-
options: {},
|
|
122
|
-
ui: listed.ui,
|
|
123
|
-
});
|
|
124
|
-
expect(listed.output.messages[0]).toContain(
|
|
125
|
-
`${created.record.id} | Production app | ${created.apiKey.slice(0, 6)} | revoked`,
|
|
126
|
-
);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("confirms before revoking unless --yes is set", async () => {
|
|
130
|
-
const api = assemble();
|
|
131
|
-
const created = await api.create({ name: "Production app" });
|
|
132
|
-
const { ui, output } = createUi();
|
|
133
|
-
|
|
134
|
-
await command("revoke").run!({
|
|
135
|
-
api,
|
|
136
|
-
args: { id: created.record.id },
|
|
137
|
-
options: {},
|
|
138
|
-
ui,
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
expect(ui.confirm).toHaveBeenCalledWith(
|
|
142
|
-
`Revoke API key ${created.record.id}?`,
|
|
143
|
-
);
|
|
144
|
-
await expect(api.list()).resolves.toMatchObject([
|
|
145
|
-
{ id: created.record.id, revoked_at_ms: expect.any(Number) },
|
|
146
|
-
]);
|
|
147
|
-
expect(output.messages[0]).toContain("API key revoked");
|
|
148
|
-
|
|
149
|
-
const skipped = createUi();
|
|
150
|
-
await command("revoke").run!({
|
|
151
|
-
api,
|
|
152
|
-
args: { id: created.record.id },
|
|
153
|
-
options: { yes: true },
|
|
154
|
-
ui: skipped.ui,
|
|
155
|
-
});
|
|
156
|
-
expect(skipped.ui.confirm).not.toHaveBeenCalled();
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("fails to revoke a key it does not have", async () => {
|
|
160
|
-
const { ui } = createUi();
|
|
161
|
-
await expect(
|
|
162
|
-
command("revoke").run!({
|
|
163
|
-
api: assemble(),
|
|
164
|
-
args: { id: "api-missing" },
|
|
165
|
-
options: { yes: true },
|
|
166
|
-
ui,
|
|
167
|
-
}),
|
|
168
|
-
).rejects.toThrow('API key "api-missing" was not found.');
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("gives init the app's key: a saved one again, else a new one", async () => {
|
|
172
|
-
const credential = apiKeys({ headerName: "X-Hot-Updater-Key" }).cli
|
|
173
|
-
?.clientCredential;
|
|
174
|
-
expect(credential).toMatchObject({
|
|
175
|
-
label: "API key",
|
|
176
|
-
header: "x-hot-updater-key",
|
|
177
|
-
env: "HOT_UPDATER_API_KEY",
|
|
178
|
-
});
|
|
179
|
-
const api = assemble();
|
|
180
|
-
const created = await credential!.provision(api, { name: "Init" });
|
|
181
|
-
expect(created).toMatch(/^[A-Za-z0-9_-]{43}$/u);
|
|
182
|
-
await expect(
|
|
183
|
-
credential!.provision(api, { existing: created, name: "Init again" }),
|
|
184
|
-
).resolves.toBe(created);
|
|
185
|
-
await expect(api.list()).resolves.toHaveLength(1);
|
|
186
|
-
});
|
|
187
|
-
});
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import type { PluginCli, PluginCommandUi } from "../definePlugin";
|
|
2
|
-
import type {
|
|
3
|
-
ApiKeyManagementAPI,
|
|
4
|
-
ApiKeyMetadata,
|
|
5
|
-
CreatedApiKey,
|
|
6
|
-
} from "./apiKeys";
|
|
7
|
-
|
|
8
|
-
/** The part of the apiKeys() API the CLI uses. */
|
|
9
|
-
export interface ApiKeysCliApi extends ApiKeyManagementAPI {
|
|
10
|
-
provision(input: {
|
|
11
|
-
readonly existingApiKey?: string;
|
|
12
|
-
readonly name: string;
|
|
13
|
-
}): Promise<CreatedApiKey>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** The environment variable init stores the app's API key in. */
|
|
17
|
-
export const API_KEY_ENV = "HOT_UPDATER_API_KEY";
|
|
18
|
-
|
|
19
|
-
/** A new API key: 32 random bytes, base64url, as the plugin creates them. */
|
|
20
|
-
const generateApiKey = (): string => {
|
|
21
|
-
const bytes = crypto.getRandomValues(new Uint8Array(32));
|
|
22
|
-
return btoa(String.fromCharCode(...bytes))
|
|
23
|
-
.replaceAll("+", "-")
|
|
24
|
-
.replaceAll("/", "_")
|
|
25
|
-
.replace(/=+$/u, "");
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const formatList = (
|
|
29
|
-
ui: PluginCommandUi,
|
|
30
|
-
records: readonly ApiKeyMetadata[],
|
|
31
|
-
): string =>
|
|
32
|
-
records.length === 0
|
|
33
|
-
? ui.muted("(no API keys)")
|
|
34
|
-
: ui.table(
|
|
35
|
-
[
|
|
36
|
-
{ key: "id", label: "ID", format: ui.id },
|
|
37
|
-
{ key: "name", label: "Name" },
|
|
38
|
-
{ key: "prefix", label: "Prefix", format: ui.muted },
|
|
39
|
-
{
|
|
40
|
-
key: "status",
|
|
41
|
-
label: "Status",
|
|
42
|
-
format: (value) =>
|
|
43
|
-
value.trim() === "active" ? ui.success(value) : ui.danger(value),
|
|
44
|
-
},
|
|
45
|
-
{ key: "created", label: "Created", format: ui.muted },
|
|
46
|
-
],
|
|
47
|
-
records.map((record) => ({
|
|
48
|
-
created: new Date(record.created_at_ms).toISOString(),
|
|
49
|
-
id: record.id,
|
|
50
|
-
name: record.name,
|
|
51
|
-
prefix: record.prefix,
|
|
52
|
-
status: record.revoked_at_ms === null ? "active" : "revoked",
|
|
53
|
-
})),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* `hot-updater api-key create|list|revoke`, and the API key that init
|
|
58
|
-
* provisions for an app, sent in `headerName`.
|
|
59
|
-
*/
|
|
60
|
-
export const apiKeysCli = (headerName: string): PluginCli<ApiKeysCliApi> => ({
|
|
61
|
-
commands: [
|
|
62
|
-
{
|
|
63
|
-
name: "api-key",
|
|
64
|
-
description: "Manage API keys",
|
|
65
|
-
commands: [
|
|
66
|
-
{
|
|
67
|
-
name: "create",
|
|
68
|
-
description: "Create an API key",
|
|
69
|
-
options: [
|
|
70
|
-
{
|
|
71
|
-
flags: "--name <name>",
|
|
72
|
-
description: "name used to identify the API key",
|
|
73
|
-
required: true,
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
async run({ api, options, ui }) {
|
|
77
|
-
const created = await api.create({ name: String(options.name) });
|
|
78
|
-
ui.message(
|
|
79
|
-
ui.block("API key created", [
|
|
80
|
-
ui.kv("Name", created.record.name),
|
|
81
|
-
ui.kv("ID", ui.id(created.record.id)),
|
|
82
|
-
ui.kv("API key", ui.warning(created.apiKey)),
|
|
83
|
-
]),
|
|
84
|
-
);
|
|
85
|
-
ui.warn("Save this API key now. It will not be shown again.");
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
name: "list",
|
|
90
|
-
description: "List API keys",
|
|
91
|
-
options: [
|
|
92
|
-
{ flags: "--json", description: "output API key metadata as JSON" },
|
|
93
|
-
],
|
|
94
|
-
async run({ api, options, ui }) {
|
|
95
|
-
const records = [...(await api.list())].sort(
|
|
96
|
-
(left, right) => right.created_at_ms - left.created_at_ms,
|
|
97
|
-
);
|
|
98
|
-
if (options.json) ui.print(JSON.stringify(records, null, 2));
|
|
99
|
-
else ui.message(formatList(ui, records));
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
name: "revoke",
|
|
104
|
-
description: "Revoke an API key",
|
|
105
|
-
arguments: [{ name: "id", description: "API key id" }],
|
|
106
|
-
options: [
|
|
107
|
-
{ flags: "-y, --yes", description: "skip confirmation prompt" },
|
|
108
|
-
],
|
|
109
|
-
async run({ api, args, options, ui }) {
|
|
110
|
-
const id = String(args.id);
|
|
111
|
-
if (!options.yes) await ui.confirm(`Revoke API key ${id}?`);
|
|
112
|
-
const revoked = await api.revoke({ id });
|
|
113
|
-
if (revoked === null) {
|
|
114
|
-
throw new Error(`API key "${id}" was not found.`);
|
|
115
|
-
}
|
|
116
|
-
ui.message(
|
|
117
|
-
ui.block("API key revoked", [
|
|
118
|
-
ui.kv("Name", revoked.name),
|
|
119
|
-
ui.kv("ID", ui.id(revoked.id)),
|
|
120
|
-
]),
|
|
121
|
-
);
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
clientCredential: {
|
|
128
|
-
label: "API key",
|
|
129
|
-
header: headerName,
|
|
130
|
-
env: API_KEY_ENV,
|
|
131
|
-
generate: generateApiKey,
|
|
132
|
-
provision: async (api, { existing, name }) =>
|
|
133
|
-
(
|
|
134
|
-
await api.provision({
|
|
135
|
-
...(existing === undefined ? {} : { existingApiKey: existing }),
|
|
136
|
-
name,
|
|
137
|
-
})
|
|
138
|
-
).apiKey,
|
|
139
|
-
},
|
|
140
|
-
});
|