@better-forge/vault 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 BetterStatusPage contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BetterStatusPage contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # @better-forge/vault
2
-
3
- Local vault crypto, HashiCorp client, secret resolution and vault routes.
4
-
5
- Status: skeleton. Depends on: `@better-forge/db`.
1
+ # @better-forge/vault
2
+
3
+ Local vault crypto, HashiCorp client, secret resolution and vault routes.
4
+
5
+ Status: skeleton. Depends on: `@better-forge/db`.
@@ -1,27 +1,27 @@
1
1
  /** Vaults and the secrets in them. Steps run in this order. */
2
2
  export const vaultMigrations = [
3
- { kind: 'exec', sql: `
4
- CREATE TABLE IF NOT EXISTS vaults (
5
- id INTEGER PRIMARY KEY AUTOINCREMENT,
6
- name TEXT NOT NULL,
7
- type TEXT NOT NULL DEFAULT 'local',
8
- description TEXT,
9
- created_at INTEGER NOT NULL,
10
- updated_at INTEGER NOT NULL
11
- );
3
+ { kind: 'exec', sql: `
4
+ CREATE TABLE IF NOT EXISTS vaults (
5
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6
+ name TEXT NOT NULL,
7
+ type TEXT NOT NULL DEFAULT 'local',
8
+ description TEXT,
9
+ created_at INTEGER NOT NULL,
10
+ updated_at INTEGER NOT NULL
11
+ );
12
12
  ` },
13
- { kind: 'exec', sql: `
14
- CREATE TABLE IF NOT EXISTS vault_secrets (
15
- id INTEGER PRIMARY KEY AUTOINCREMENT,
16
- vault_id INTEGER NOT NULL,
17
- name TEXT NOT NULL,
18
- type TEXT NOT NULL,
19
- encrypted_value TEXT NOT NULL,
20
- created_at INTEGER NOT NULL,
21
- updated_at INTEGER NOT NULL,
22
- FOREIGN KEY (vault_id) REFERENCES vaults(id) ON DELETE CASCADE,
23
- UNIQUE (vault_id, name)
24
- );
13
+ { kind: 'exec', sql: `
14
+ CREATE TABLE IF NOT EXISTS vault_secrets (
15
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
16
+ vault_id INTEGER NOT NULL,
17
+ name TEXT NOT NULL,
18
+ type TEXT NOT NULL,
19
+ encrypted_value TEXT NOT NULL,
20
+ created_at INTEGER NOT NULL,
21
+ updated_at INTEGER NOT NULL,
22
+ FOREIGN KEY (vault_id) REFERENCES vaults(id) ON DELETE CASCADE,
23
+ UNIQUE (vault_id, name)
24
+ );
25
25
  ` },
26
26
  { kind: 'column', sql: `ALTER TABLE vaults ADD COLUMN connection_config TEXT`, desc: 'vaults.connection_config' },
27
27
  ];
package/package.json CHANGED
@@ -1,56 +1,56 @@
1
- {
2
- "name": "@better-forge/vault",
3
- "version": "0.1.0",
4
- "description": "Local vault crypto, HashiCorp client, secret resolution and vault routes.",
5
- "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/BElluu/Better-Forge.git",
9
- "directory": "packages/vault"
10
- },
11
- "homepage": "https://github.com/BElluu/Better-Forge/tree/main/packages/vault#readme",
12
- "bugs": {
13
- "url": "https://github.com/BElluu/Better-Forge/issues"
14
- },
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "type": "module",
19
- "main": "./dist/index.js",
20
- "types": "./dist/index.d.ts",
21
- "exports": {
22
- ".": {
23
- "types": "./dist/index.d.ts",
24
- "import": "./dist/index.js"
25
- },
26
- "./package.json": "./package.json"
27
- },
28
- "files": [
29
- "dist",
30
- "src",
31
- "!src/**/*.test.*"
32
- ],
33
- "scripts": {
34
- "build": "tsc -p tsconfig.json",
35
- "dev": "tsc -p tsconfig.json --watch --preserveWatchOutput"
36
- },
37
- "peerDependencies": {
38
- "drizzle-orm": "^0.45.2",
39
- "fastify": "^5.3.2",
40
- "undici": "^7.4.0"
41
- },
42
- "devDependencies": {
43
- "@types/node": "^26.6.2",
44
- "drizzle-orm": "^0.45.2",
45
- "fastify": "^5.3.2",
46
- "typescript": "^5.7.3",
47
- "undici": "^7.4.0"
48
- },
49
- "dependencies": {
50
- "@better-forge/contracts": "0.1.0",
51
- "@better-forge/db": "0.1.0"
52
- },
53
- "engines": {
54
- "node": ">=26.10.0"
55
- }
56
- }
1
+ {
2
+ "name": "@better-forge/vault",
3
+ "version": "0.1.1",
4
+ "description": "Local vault crypto, HashiCorp client, secret resolution and vault routes.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/BElluu/Better-Forge.git",
9
+ "directory": "packages/vault"
10
+ },
11
+ "homepage": "https://github.com/BElluu/Better-Forge/tree/main/packages/vault#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/BElluu/Better-Forge/issues"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "type": "module",
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "src",
31
+ "!src/**/*.test.*"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsc -p tsconfig.json",
35
+ "dev": "tsc -p tsconfig.json --watch --preserveWatchOutput"
36
+ },
37
+ "peerDependencies": {
38
+ "drizzle-orm": "^0.45.2",
39
+ "fastify": "^5.3.2",
40
+ "undici": "^7.4.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^26.6.2",
44
+ "drizzle-orm": "^0.45.2",
45
+ "fastify": "^5.3.2",
46
+ "typescript": "^5.7.3",
47
+ "undici": "^7.4.0"
48
+ },
49
+ "dependencies": {
50
+ "@better-forge/contracts": "0.1.1",
51
+ "@better-forge/db": "0.1.1"
52
+ },
53
+ "engines": {
54
+ "node": ">=26.10.0"
55
+ }
56
+ }
@@ -1,45 +1,45 @@
1
- import type { FastifyRequest } from 'fastify'
2
- import type { SqliteDatabase } from '@better-forge/db'
3
- import { createHashicorp } from './hashicorp.js'
4
- import { createSecretBox, type SecretBox } from './secretBox.js'
5
- import { createSecretResolver } from './resolveSecret.js'
6
- import { createVaultRoutes, type VaultAudit } from './vaultRoutes.js'
7
-
8
- export interface VaultOptions {
9
- /** The application's database handle. It is used lazily, so it may be opened after this is created. */
10
- db: SqliteDatabase
11
- audit: VaultAudit
12
- /** The signed-in caller of a request; the routes sit behind the application's own guards. */
13
- identity: (req: FastifyRequest) => { userId: number; email: string }
14
- /** Where the encryption key comes from. Defaults to the process environment. */
15
- env?: NodeJS.ProcessEnv
16
- /** A box the application already created, for the tables that seal their own columns; it is made from `env` when absent. */
17
- secretBox?: SecretBox
18
- }
19
-
20
- /**
21
- * Vaults of secrets (kept encrypted here, or read live from HashiCorp Vault), the lookup that turns a reference into
22
- * its value, and the routes that manage them. Everything is built from `options` and kept in the returned closures.
23
- */
24
- export function createVault(options: VaultOptions) {
25
- const secretBox = options.secretBox ?? createSecretBox(options.env ? { env: options.env } : {})
26
- const ctx = { db: options.db, secretBox }
27
- const hashicorp = createHashicorp(ctx)
28
- const resolver = createSecretResolver(ctx, hashicorp)
29
- const routes = createVaultRoutes({ ...ctx, audit: options.audit, identity: options.identity }, { hashicorp, resolver })
30
-
31
- return {
32
- secretBox,
33
- hashicorp,
34
- resolver,
35
- /** Plain plugins, so the hooks of the scope they are registered in apply to them. */
36
- routes: {
37
- /** Read-only catalogue of vault and secret names and types, never values. */
38
- catalogue: routes.vaultCatalogRoutes,
39
- /** Create, change, reveal and delete vaults and secrets. */
40
- manage: routes.vaultRoutes,
41
- },
42
- }
43
- }
44
-
45
- export type Vault = ReturnType<typeof createVault>
1
+ import type { FastifyRequest } from 'fastify'
2
+ import type { SqliteDatabase } from '@better-forge/db'
3
+ import { createHashicorp } from './hashicorp.js'
4
+ import { createSecretBox, type SecretBox } from './secretBox.js'
5
+ import { createSecretResolver } from './resolveSecret.js'
6
+ import { createVaultRoutes, type VaultAudit } from './vaultRoutes.js'
7
+
8
+ export interface VaultOptions {
9
+ /** The application's database handle. It is used lazily, so it may be opened after this is created. */
10
+ db: SqliteDatabase
11
+ audit: VaultAudit
12
+ /** The signed-in caller of a request; the routes sit behind the application's own guards. */
13
+ identity: (req: FastifyRequest) => { userId: number; email: string }
14
+ /** Where the encryption key comes from. Defaults to the process environment. */
15
+ env?: NodeJS.ProcessEnv
16
+ /** A box the application already created, for the tables that seal their own columns; it is made from `env` when absent. */
17
+ secretBox?: SecretBox
18
+ }
19
+
20
+ /**
21
+ * Vaults of secrets (kept encrypted here, or read live from HashiCorp Vault), the lookup that turns a reference into
22
+ * its value, and the routes that manage them. Everything is built from `options` and kept in the returned closures.
23
+ */
24
+ export function createVault(options: VaultOptions) {
25
+ const secretBox = options.secretBox ?? createSecretBox(options.env ? { env: options.env } : {})
26
+ const ctx = { db: options.db, secretBox }
27
+ const hashicorp = createHashicorp(ctx)
28
+ const resolver = createSecretResolver(ctx, hashicorp)
29
+ const routes = createVaultRoutes({ ...ctx, audit: options.audit, identity: options.identity }, { hashicorp, resolver })
30
+
31
+ return {
32
+ secretBox,
33
+ hashicorp,
34
+ resolver,
35
+ /** Plain plugins, so the hooks of the scope they are registered in apply to them. */
36
+ routes: {
37
+ /** Read-only catalogue of vault and secret names and types, never values. */
38
+ catalogue: routes.vaultCatalogRoutes,
39
+ /** Create, change, reveal and delete vaults and secrets. */
40
+ manage: routes.vaultRoutes,
41
+ },
42
+ }
43
+ }
44
+
45
+ export type Vault = ReturnType<typeof createVault>