@mstone6969/vault 0.2.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 +198 -6
  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 -33
  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 -7
  16. package/dist/stores/memory.d.ts.map +1 -1
  17. package/dist/stores/sqlite.d.ts +140 -9
  18. package/dist/stores/sqlite.d.ts.map +1 -1
  19. package/dist/stores/sqlite.js +47 -12
  20. package/dist/stores/sqlite.js.map +3 -3
  21. package/dist/types.d.ts +408 -17
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/vault.d.ts +554 -19
  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,95 @@
1
+ [**@mstone6969/vault**](../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../README.md) / [index](../README.md) / VaultEvent
6
+
7
+ # Type Alias: VaultEvent
8
+
9
+ > **VaultEvent** = `object`
10
+
11
+ Defined in: cron/vault/src/types.ts:410
12
+
13
+ Something a vault did, for whoever is keeping an audit trail.
14
+
15
+ ## Remarks
16
+
17
+ Handed to the vault's `onAccess`, which is never awaited and whose failures
18
+ are ignored — logging must not break a vault. Events carry names, never
19
+ values, so the trail is safe to keep wherever logs go.
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ const vault = new Vault({
25
+ key,
26
+ store,
27
+ onAccess: (event) => {
28
+ if (event.action === "denied") {
29
+ console.warn(`refused ${event.owner}/${event.name}: ${event.detail}`)
30
+ }
31
+ },
32
+ })
33
+ ```
34
+
35
+ ## Properties
36
+
37
+ ### action
38
+
39
+ > **action**: `"put"` \| `"open"` \| `"read"` \| `"remove"` \| `"rotate"` \| `"rekey"` \| `"denied"`
40
+
41
+ Defined in: cron/vault/src/types.ts:418
42
+
43
+ What was attempted. `denied` means the vault refused; see `detail`.
44
+
45
+ #### Remarks
46
+
47
+ `open` is a sealed value coming out, `read` an entry stored in the open.
48
+ A `rotate` is also recorded as the `put` that carries it out.
49
+
50
+ ***
51
+
52
+ ### owner
53
+
54
+ > **owner**: `string`
55
+
56
+ Defined in: cron/vault/src/types.ts:420
57
+
58
+ Whose entry it was. Empty for vault-wide actions.
59
+
60
+ ***
61
+
62
+ ### name
63
+
64
+ > **name**: `string` \| `null`
65
+
66
+ Defined in: cron/vault/src/types.ts:422
67
+
68
+ The entry involved, or null for vault-wide actions like `rekey`.
69
+
70
+ ***
71
+
72
+ ### at
73
+
74
+ > **at**: `Date`
75
+
76
+ Defined in: cron/vault/src/types.ts:424
77
+
78
+ When it happened.
79
+
80
+ ***
81
+
82
+ ### detail?
83
+
84
+ > `optional` **detail?**: `string`
85
+
86
+ Defined in: cron/vault/src/types.ts:434
87
+
88
+ Why a `denied` happened, or what a vault-wide action touched.
89
+
90
+ #### Remarks
91
+
92
+ On a `denied`: `"final"` for a replacement of an entry written once,
93
+ `"sealed"` for a `read` of a value only `open` returns, `"expired"` for
94
+ an entry past `expiresAt`. On a `rekey`, how many entries moved and how
95
+ many would not open.
@@ -0,0 +1,142 @@
1
+ [**@mstone6969/vault**](../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../README.md) / [index](../README.md) / VaultOptions
6
+
7
+ # Type Alias: VaultOptions
8
+
9
+ > **VaultOptions** = `object`
10
+
11
+ Defined in: cron/vault/src/vault.ts:159
12
+
13
+ Everything a [Vault](../classes/Vault.md) is built from.
14
+
15
+ ## Example
16
+
17
+ ```ts
18
+ import { Vault, MemoryStore, envKey } from "@mstone6969/vault"
19
+
20
+ const vault = new Vault({
21
+ key: envKey("VAULT_KEY"),
22
+ store: new MemoryStore(),
23
+ historyLimit: 2,
24
+ onAccess: (event) => console.log(event.action, event.owner, event.name),
25
+ })
26
+ ```
27
+
28
+ ## Properties
29
+
30
+ ### key
31
+
32
+ > **key**: `string` \| `CryptoKey` \| [`KeyProvider`](KeyProvider.md)
33
+
34
+ Defined in: cron/vault/src/vault.ts:161
35
+
36
+ The master key: base64, already imported, or a provider that finds one.
37
+
38
+ ***
39
+
40
+ ### store
41
+
42
+ > **store**: [`VaultStore`](VaultStore.md)
43
+
44
+ Defined in: cron/vault/src/vault.ts:163
45
+
46
+ Where records are kept.
47
+
48
+ ***
49
+
50
+ ### prefix?
51
+
52
+ > `optional` **prefix?**: `string`
53
+
54
+ Defined in: cron/vault/src/vault.ts:169
55
+
56
+ Reference prefix, `@vault:` unless you say otherwise.
57
+
58
+ #### Default Value
59
+
60
+ [DEFAULT\_PREFIX](../variables/DEFAULT_PREFIX.md)
61
+
62
+ ***
63
+
64
+ ### previousKeys?
65
+
66
+ > `optional` **previousKeys?**: (`string` \| `CryptoKey` \| [`KeyProvider`](KeyProvider.md))[]
67
+
68
+ Defined in: cron/vault/src/vault.ts:180
69
+
70
+ Keys this vault will still open values with, but never seal under.
71
+
72
+ Keep the old key here while a `rekey` is in flight, or after one that did
73
+ not finish: values left under it stay readable instead of becoming
74
+ unopenable the moment the primary key changes.
75
+
76
+ #### Default Value
77
+
78
+ ```ts
79
+ none
80
+ ```
81
+
82
+ #### See
83
+
84
+ [Vault.rekey](../classes/Vault.md#rekey)
85
+
86
+ ***
87
+
88
+ ### historyLimit?
89
+
90
+ > `optional` **historyLimit?**: `number`
91
+
92
+ Defined in: cron/vault/src/vault.ts:186
93
+
94
+ How many previous values `rotate` keeps.
95
+
96
+ #### Default Value
97
+
98
+ [DEFAULT\_HISTORY\_LIMIT](../variables/DEFAULT_HISTORY_LIMIT.md)
99
+
100
+ ***
101
+
102
+ ### generators?
103
+
104
+ > `optional` **generators?**: `Record`\<`string`, [`Generator`](Generator.md)\>
105
+
106
+ Defined in: cron/vault/src/vault.ts:196
107
+
108
+ Functions that mint new values, by the name a rotation policy uses.
109
+
110
+ The vault stores the *name*, never the function — so what is written down
111
+ is that an entry can be rotated, not how to impersonate the thing that
112
+ rotates it.
113
+
114
+ #### Default Value
115
+
116
+ none, so a `generator` policy fails with 501
117
+
118
+ ***
119
+
120
+ ### onAccess?
121
+
122
+ > `optional` **onAccess?**: (`event`) => `void`
123
+
124
+ Defined in: cron/vault/src/vault.ts:204
125
+
126
+ Called after everything the vault does, for an audit trail. It is never
127
+ awaited and its failures are ignored — logging must not break a vault.
128
+
129
+ #### Parameters
130
+
131
+ ##### event
132
+
133
+ [`VaultEvent`](VaultEvent.md)
134
+
135
+ #### Returns
136
+
137
+ `void`
138
+
139
+ #### See
140
+
141
+ [VaultEvent](VaultEvent.md) for what it is told, including the refusals,
142
+ which arrive as `denied` with a `detail` saying which rule was hit.
@@ -0,0 +1,156 @@
1
+ [**@mstone6969/vault**](../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../README.md) / [index](../README.md) / VaultStore
6
+
7
+ # Type Alias: VaultStore
8
+
9
+ > **VaultStore** = `object`
10
+
11
+ Defined in: cron/vault/src/types.ts:348
12
+
13
+ Where records live. Implement this to keep secrets in whatever database you
14
+ already run; `MemoryStore`, `SqliteStore` and `FileStore` ship with the
15
+ package.
16
+
17
+ A store persists records as given and enforces nothing: the rules about
18
+ finality, expiry and history are the vault's.
19
+
20
+ ## Example
21
+
22
+ ```ts
23
+ import { Vault, MemoryStore } from "@mstone6969/vault"
24
+
25
+ const vault = new Vault({ key, store: new MemoryStore() })
26
+ ```
27
+
28
+ ## See
29
+
30
+ [SecretRecord](SecretRecord.md)
31
+
32
+ ## Methods
33
+
34
+ ### get()
35
+
36
+ > **get**(`owner`, `name`): `Promise`\<[`SecretRecord`](SecretRecord.md) \| `null`\>
37
+
38
+ Defined in: cron/vault/src/types.ts:356
39
+
40
+ One record, or null when there is none under that name.
41
+
42
+ #### Parameters
43
+
44
+ ##### owner
45
+
46
+ `string`
47
+
48
+ Whose entry to look for.
49
+
50
+ ##### name
51
+
52
+ `string`
53
+
54
+ The entry's name, already checked by the vault.
55
+
56
+ #### Returns
57
+
58
+ `Promise`\<[`SecretRecord`](SecretRecord.md) \| `null`\>
59
+
60
+ The record as it was written, or null.
61
+
62
+ ***
63
+
64
+ ### list()
65
+
66
+ > **list**(`owner`): `Promise`\<[`SecretRecord`](SecretRecord.md)[]\>
67
+
68
+ Defined in: cron/vault/src/types.ts:363
69
+
70
+ Every record one owner holds, in any order.
71
+
72
+ #### Parameters
73
+
74
+ ##### owner
75
+
76
+ `string`
77
+
78
+ Whose entries to return.
79
+
80
+ #### Returns
81
+
82
+ `Promise`\<[`SecretRecord`](SecretRecord.md)[]\>
83
+
84
+ The owner's records; the vault sorts them by name itself.
85
+
86
+ ***
87
+
88
+ ### all()
89
+
90
+ > **all**(): `Promise`\<[`SecretRecord`](SecretRecord.md)[]\>
91
+
92
+ Defined in: cron/vault/src/types.ts:370
93
+
94
+ Every record the store holds, whoever owns it. Only `rekey` and
95
+ `purgeExpired` need this — nothing else reaches across owners.
96
+
97
+ #### Returns
98
+
99
+ `Promise`\<[`SecretRecord`](SecretRecord.md)[]\>
100
+
101
+ Every record, in any order.
102
+
103
+ ***
104
+
105
+ ### put()
106
+
107
+ > **put**(`record`): `Promise`\<[`SecretRecord`](SecretRecord.md)\>
108
+
109
+ Defined in: cron/vault/src/types.ts:378
110
+
111
+ Writes a record, replacing any under the same owner and name.
112
+
113
+ #### Parameters
114
+
115
+ ##### record
116
+
117
+ [`SecretRecord`](SecretRecord.md)
118
+
119
+ The record to write. Store it as given: `isFinal` is the
120
+ vault's rule to enforce, not the store's.
121
+
122
+ #### Returns
123
+
124
+ `Promise`\<[`SecretRecord`](SecretRecord.md)\>
125
+
126
+ The record as stored, which is what the caller sees.
127
+
128
+ ***
129
+
130
+ ### remove()
131
+
132
+ > **remove**(`owner`, `name`): `Promise`\<`boolean`\>
133
+
134
+ Defined in: cron/vault/src/types.ts:386
135
+
136
+ Deletes a record, returning false when there was nothing to delete.
137
+
138
+ #### Parameters
139
+
140
+ ##### owner
141
+
142
+ `string`
143
+
144
+ Whose entry to delete.
145
+
146
+ ##### name
147
+
148
+ `string`
149
+
150
+ The entry to delete.
151
+
152
+ #### Returns
153
+
154
+ `Promise`\<`boolean`\>
155
+
156
+ True when a record went, false when there was none.
@@ -0,0 +1,29 @@
1
+ [**@mstone6969/vault**](../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../README.md) / [index](../README.md) / DEFAULT\_ALPHABET
6
+
7
+ # Variable: DEFAULT\_ALPHABET
8
+
9
+ > `const` **DEFAULT\_ALPHABET**: `"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"` = `"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"`
10
+
11
+ Defined in: cron/vault/src/vault.ts:50
12
+
13
+ What a random rotation draws from unless the policy says otherwise.
14
+
15
+ ## Remarks
16
+
17
+ Letters and digits only, so a generated value survives being pasted into a
18
+ shell command or a connection string without quoting. Set
19
+ [RotationPolicy.alphabet](../type-aliases/RotationPolicy.md#alphabet) for anything narrower or wider.
20
+
21
+ ## Default Value
22
+
23
+ ```ts
24
+ A-Z, a-z and 0-9: 62 characters
25
+ ```
26
+
27
+ ## See
28
+
29
+ [randomValue](../functions/randomValue.md)
@@ -0,0 +1,28 @@
1
+ [**@mstone6969/vault**](../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../README.md) / [index](../README.md) / DEFAULT\_HISTORY\_LIMIT
6
+
7
+ # Variable: DEFAULT\_HISTORY\_LIMIT
8
+
9
+ > `const` **DEFAULT\_HISTORY\_LIMIT**: `5` = `5`
10
+
11
+ Defined in: cron/vault/src/vault.ts:35
12
+
13
+ How many previous values an entry keeps, unless you say otherwise.
14
+
15
+ ## Remarks
16
+
17
+ Only [Vault.rotate](../classes/Vault.md#rotate) adds to history, so this is how many superseded
18
+ values [Vault.versions](../classes/Vault.md#versions) can still hand back.
19
+
20
+ ## Default Value
21
+
22
+ ```ts
23
+ 5
24
+ ```
25
+
26
+ ## See
27
+
28
+ [VaultOptions.historyLimit](../type-aliases/VaultOptions.md#historylimit)
@@ -0,0 +1,23 @@
1
+ [**@mstone6969/vault**](../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../README.md) / [index](../README.md) / DEFAULT\_PREFIX
6
+
7
+ # Variable: DEFAULT\_PREFIX
8
+
9
+ > `const` **DEFAULT\_PREFIX**: `"@vault:"` = `"@vault:"`
10
+
11
+ Defined in: cron/vault/src/vault.ts:23
12
+
13
+ How a stored value is referenced from configuration.
14
+
15
+ ## Remarks
16
+
17
+ [Vault.resolve](../classes/Vault.md#resolve) substitutes any value that starts with this. Give a
18
+ vault its own [VaultOptions.prefix](../type-aliases/VaultOptions.md#prefix) when `@vault:` already means
19
+ something else in the configuration you are resolving.
20
+
21
+ ## Default Value
22
+
23
+ `"@vault:"`
@@ -0,0 +1,11 @@
1
+ [**@mstone6969/vault**](../../README.md)
2
+
3
+ ***
4
+
5
+ [@mstone6969/vault](../../README.md) / stores/sqlite
6
+
7
+ # stores/sqlite
8
+
9
+ ## Classes
10
+
11
+ - [SqliteStore](classes/SqliteStore.md)