@mstone6969/vault 0.1.0 → 0.5.0

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 (58) hide show
  1. package/README.md +236 -10
  2. package/dist/crypto.d.ts +99 -2
  3. package/dist/crypto.d.ts.map +1 -1
  4. package/dist/errors.d.ts +122 -4
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +447 -32
  9. package/dist/index.js.map +9 -7
  10. package/dist/providers.d.ts +131 -0
  11. package/dist/providers.d.ts.map +1 -0
  12. package/dist/stores/file.d.ts +190 -0
  13. package/dist/stores/file.d.ts.map +1 -0
  14. package/dist/stores/file.js +1 -0
  15. package/dist/stores/memory.d.ts +98 -6
  16. package/dist/stores/memory.d.ts.map +1 -1
  17. package/dist/stores/sqlite.d.ts +140 -8
  18. package/dist/stores/sqlite.d.ts.map +1 -1
  19. package/dist/stores/sqlite.js +49 -7
  20. package/dist/stores/sqlite.js.map +3 -3
  21. package/dist/types.d.ts +411 -13
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/vault.d.ts +561 -20
  24. package/dist/vault.d.ts.map +1 -1
  25. package/docs/README.md +10 -0
  26. package/docs/index/README.md +48 -0
  27. package/docs/index/classes/FileStore.md +341 -0
  28. package/docs/index/classes/MemoryStore.md +240 -0
  29. package/docs/index/classes/Vault.md +805 -0
  30. package/docs/index/classes/VaultError.md +371 -0
  31. package/docs/index/classes/VaultKeyError.md +370 -0
  32. package/docs/index/functions/envKey.md +43 -0
  33. package/docs/index/functions/fileKey.md +46 -0
  34. package/docs/index/functions/generateKey.md +39 -0
  35. package/docs/index/functions/importKey.md +49 -0
  36. package/docs/index/functions/isKeyProvider.md +43 -0
  37. package/docs/index/functions/open.md +67 -0
  38. package/docs/index/functions/randomValue.md +53 -0
  39. package/docs/index/functions/seal.md +56 -0
  40. package/docs/index/functions/staticKey.md +39 -0
  41. package/docs/index/type-aliases/Generator.md +58 -0
  42. package/docs/index/type-aliases/HistoryEntry.md +65 -0
  43. package/docs/index/type-aliases/KeyProvider.md +74 -0
  44. package/docs/index/type-aliases/PutOptions.md +141 -0
  45. package/docs/index/type-aliases/RekeyReport.md +37 -0
  46. package/docs/index/type-aliases/RotationContext.md +49 -0
  47. package/docs/index/type-aliases/RotationPolicy.md +142 -0
  48. package/docs/index/type-aliases/SecretRecord.md +214 -0
  49. package/docs/index/type-aliases/SecretSummary.md +56 -0
  50. package/docs/index/type-aliases/VaultEvent.md +95 -0
  51. package/docs/index/type-aliases/VaultOptions.md +142 -0
  52. package/docs/index/type-aliases/VaultStore.md +156 -0
  53. package/docs/index/variables/DEFAULT_ALPHABET.md +29 -0
  54. package/docs/index/variables/DEFAULT_HISTORY_LIMIT.md +28 -0
  55. package/docs/index/variables/DEFAULT_PREFIX.md +23 -0
  56. package/docs/stores/sqlite/README.md +11 -0
  57. package/docs/stores/sqlite/classes/SqliteStore.md +307 -0
  58. package/package.json +15 -5
@@ -0,0 +1,307 @@
1
+ [**@mstone6969/vault**](../../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../../README.md) / [stores/sqlite](../README.md) / SqliteStore
6
+
7
+ # Class: SqliteStore
8
+
9
+ Defined in: cron/vault/src/stores/sqlite.ts:69
10
+
11
+ Keeps records in SQLite through `bun:sqlite`. Pass a file path, ":memory:",
12
+ or a Database you already opened.
13
+
14
+ Values are sealed, but owners, names and metadata are ordinary columns —
15
+ anyone who can read the file learns what you keep, if not what it says. Use
16
+ `FileStore` when even that should be hidden.
17
+
18
+ ## Remarks
19
+
20
+ `bun:sqlite` makes this store Bun-only: importing it on Node fails at the
21
+ import, not at the first query. That is why it is reached through
22
+ `@mstone6969/vault/stores/sqlite` instead of the package's main entry —
23
+ a Node program that imports the main entry never loads this file, and never
24
+ sees the Bun-only import.
25
+
26
+ Every method is `async` only to satisfy [VaultStore](../../../index/type-aliases/VaultStore.md); `bun:sqlite` is
27
+ synchronous, so nothing here waits on I/O.
28
+
29
+ ## Example
30
+
31
+ ```ts
32
+ import { Vault } from "@mstone6969/vault"
33
+ import { SqliteStore } from "@mstone6969/vault/stores/sqlite"
34
+
35
+ const store = new SqliteStore("./vault.sqlite")
36
+ const vault = new Vault({ key: process.env.VAULT_KEY!, store })
37
+
38
+ await vault.put("alice", "db-password", "hunter2", {
39
+ metadata: { kind: "postgres" },
40
+ })
41
+ console.log(await vault.open("alice", "db-password")) // "hunter2"
42
+ store.close()
43
+ ```
44
+
45
+ ## See
46
+
47
+ [VaultStore](../../../index/type-aliases/VaultStore.md) for what a store owes the vault.
48
+
49
+ ## Implements
50
+
51
+ - [`VaultStore`](../../../index/type-aliases/VaultStore.md)
52
+
53
+ ## Constructors
54
+
55
+ ### Constructor
56
+
57
+ > **new SqliteStore**(`database?`, `table?`): `SqliteStore`
58
+
59
+ Defined in: cron/vault/src/stores/sqlite.ts:106
60
+
61
+ Opens the database if it was given a path, and makes sure the table is
62
+ there and current.
63
+
64
+ The table is created in its 0.1.0 shape if it is missing, and then every
65
+ column added since — `sealed_key`, `plain`, `is_sealed`, `is_final`,
66
+ `expires_at`, `history`, `rotation`, `rotated_at`, `metadata` — is
67
+ ALTERed in if it is absent. So a table written by an older version of
68
+ the package is upgraded the moment a newer one opens it, in place and
69
+ without a migration step of your own, and rows that predate a column
70
+ read back with sensible defaults: no history, no metadata, sealed, not
71
+ final, no expiry.
72
+
73
+ #### Parameters
74
+
75
+ ##### database?
76
+
77
+ `string` \| `Database`
78
+
79
+ A file path to open, ":memory:" for a database that
80
+ lasts as long as the process, or a `Database` you already opened —
81
+ useful for keeping the vault's table beside your own in one file, and
82
+ inside your own transactions.
83
+
84
+ ##### table?
85
+
86
+ `string` = `"vault_secrets"`
87
+
88
+ Which table to keep records in. Give it a name of its own
89
+ when one database holds several vaults.
90
+
91
+ #### Returns
92
+
93
+ `SqliteStore`
94
+
95
+ #### Default Value
96
+
97
+ `":memory:"`
98
+
99
+ #### Default Value
100
+
101
+ `"vault_secrets"`
102
+
103
+ #### Throws
104
+
105
+ Whatever `bun:sqlite` throws when the path cannot be opened, or
106
+ when `table` already exists with an incompatible shape.
107
+
108
+ #### Example
109
+
110
+ **Sharing a database you already opened**
111
+
112
+ ```ts
113
+ import { Database } from "bun:sqlite"
114
+ import { SqliteStore } from "@mstone6969/vault/stores/sqlite"
115
+
116
+ const db = new Database("./app.sqlite")
117
+ const store = new SqliteStore(db, "shared_secrets")
118
+ ```
119
+
120
+ ## Methods
121
+
122
+ ### get()
123
+
124
+ > **get**(`owner`, `name`): `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md) \| `null`\>
125
+
126
+ Defined in: cron/vault/src/stores/sqlite.ts:181
127
+
128
+ One record, or null when there is none under that name.
129
+
130
+ The record carries the sealed value, not the plaintext: use
131
+ `Vault.open` to get a value back out.
132
+
133
+ #### Parameters
134
+
135
+ ##### owner
136
+
137
+ `string`
138
+
139
+ Whose entry to look for.
140
+
141
+ ##### name
142
+
143
+ `string`
144
+
145
+ The entry's name.
146
+
147
+ #### Returns
148
+
149
+ `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md) \| `null`\>
150
+
151
+ The stored record, or null when that owner has nothing under
152
+ that name.
153
+
154
+ #### Implementation of
155
+
156
+ `VaultStore.get`
157
+
158
+ ***
159
+
160
+ ### list()
161
+
162
+ > **list**(`owner`): `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md)[]\>
163
+
164
+ Defined in: cron/vault/src/stores/sqlite.ts:197
165
+
166
+ Every record one owner holds, in whatever order SQLite returns them —
167
+ the vault sorts what it shows.
168
+
169
+ #### Parameters
170
+
171
+ ##### owner
172
+
173
+ `string`
174
+
175
+ Whose entries to return.
176
+
177
+ #### Returns
178
+
179
+ `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md)[]\>
180
+
181
+ That owner's records, empty when they hold none.
182
+
183
+ #### Implementation of
184
+
185
+ `VaultStore.list`
186
+
187
+ ***
188
+
189
+ ### all()
190
+
191
+ > **all**(): `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md)[]\>
192
+
193
+ Defined in: cron/vault/src/stores/sqlite.ts:213
194
+
195
+ Every record, whoever owns it.
196
+
197
+ Only `Vault.rekey` and `Vault.purgeExpired` need this;
198
+ everything else stays inside one owner. It loads the whole table, so it
199
+ is the one method that costs more as the vault grows.
200
+
201
+ #### Returns
202
+
203
+ `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md)[]\>
204
+
205
+ Every record in the table.
206
+
207
+ #### Implementation of
208
+
209
+ `VaultStore.all`
210
+
211
+ ***
212
+
213
+ ### put()
214
+
215
+ > **put**(`record`): `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md)\>
216
+
217
+ Defined in: cron/vault/src/stores/sqlite.ts:235
218
+
219
+ Writes a record, replacing any under the same owner and name.
220
+
221
+ `created_at` is deliberately left out of the conflict update: a
222
+ replacement keeps the moment the entry first appeared. Nothing here
223
+ enforces finality or expiry — those are the vault's rules, and the store
224
+ writes what it is given.
225
+
226
+ #### Parameters
227
+
228
+ ##### record
229
+
230
+ [`SecretRecord`](../../../index/type-aliases/SecretRecord.md)
231
+
232
+ The record to write. `owner` and `name` are its key.
233
+
234
+ #### Returns
235
+
236
+ `Promise`\<[`SecretRecord`](../../../index/type-aliases/SecretRecord.md)\>
237
+
238
+ The record as it reads back out of SQLite, which is what
239
+ callers should keep — dates have been through epoch milliseconds and
240
+ JSON columns through a round trip.
241
+
242
+ #### Throws
243
+
244
+ Error if the row cannot be read back immediately after writing
245
+ it, which means the database is not behaving as SQLite.
246
+
247
+ #### Implementation of
248
+
249
+ `VaultStore.put`
250
+
251
+ ***
252
+
253
+ ### remove()
254
+
255
+ > **remove**(`owner`, `name`): `Promise`\<`boolean`\>
256
+
257
+ Defined in: cron/vault/src/stores/sqlite.ts:289
258
+
259
+ Deletes a record, returning false when there was nothing to delete.
260
+
261
+ History goes with it: the row holds the previous values, so deleting an
262
+ entry deletes every version of it.
263
+
264
+ #### Parameters
265
+
266
+ ##### owner
267
+
268
+ `string`
269
+
270
+ Whose entry to delete.
271
+
272
+ ##### name
273
+
274
+ `string`
275
+
276
+ The entry's name.
277
+
278
+ #### Returns
279
+
280
+ `Promise`\<`boolean`\>
281
+
282
+ True when a record was there and is now gone, false when there
283
+ was nothing under that name.
284
+
285
+ #### Implementation of
286
+
287
+ `VaultStore.remove`
288
+
289
+ ***
290
+
291
+ ### close()
292
+
293
+ > **close**(): `void`
294
+
295
+ Defined in: cron/vault/src/stores/sqlite.ts:305
296
+
297
+ Closes the underlying database.
298
+
299
+ This closes a `Database` you passed to the constructor as well — the
300
+ store does not track who opened it, so anything else using that same
301
+ handle stops working too. Call it on the owner of the connection only.
302
+
303
+ #### Returns
304
+
305
+ `void`
306
+
307
+ Nothing; the store is unusable afterwards.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mstone6969/vault",
3
- "version": "0.1.0",
4
- "description": "A write-only credential vault: AES-256-GCM at rest, per-owner scoping, and @vault: references resolved at use.",
3
+ "version": "0.5.0",
4
+ "description": "A write-only credential vault: envelope encryption, key rotation, expiry, history and an encrypted single-file store.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "Malcolmston",
@@ -29,10 +29,15 @@
29
29
  "types": "./dist/stores/sqlite.d.ts",
30
30
  "import": "./dist/stores/sqlite.js"
31
31
  },
32
- "./package.json": "./package.json"
32
+ "./package.json": "./package.json",
33
+ "./stores/file": {
34
+ "types": "./dist/stores/file.d.ts",
35
+ "import": "./dist/stores/file.js"
36
+ }
33
37
  },
34
38
  "files": [
35
39
  "dist",
40
+ "docs",
36
41
  "README.md"
37
42
  ],
38
43
  "sideEffects": false,
@@ -46,10 +51,15 @@
46
51
  "build": "bun run build.ts",
47
52
  "test": "bun test",
48
53
  "typecheck": "tsc --noEmit",
49
- "prepublishOnly": "bun run typecheck && bun test && bun run build"
54
+ "prepublishOnly": "bun run typecheck && bun run docs:check && bun run test:coverage && bun run build && bun run docs",
55
+ "test:coverage": "bun test --coverage",
56
+ "docs": "typedoc",
57
+ "docs:check": "typedoc --emit none"
50
58
  },
51
59
  "devDependencies": {
52
- "@types/bun": "latest"
60
+ "@types/bun": "latest",
61
+ "typedoc": "^0.28.20",
62
+ "typedoc-plugin-markdown": "^4.12.0"
53
63
  },
54
64
  "peerDependencies": {
55
65
  "typescript": "^5"