@vaultkeeper/test-helpers 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Mike North
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/dist/index.cjs ADDED
@@ -0,0 +1,103 @@
1
+ 'use strict';
2
+
3
+ var vaultkeeper = require('vaultkeeper');
4
+
5
+ // src/in-memory-backend.ts
6
+ var InMemoryBackend = class {
7
+ type = "memory";
8
+ displayName = "In-Memory Backend";
9
+ #store = /* @__PURE__ */ new Map();
10
+ /** @public */
11
+ isAvailable() {
12
+ return Promise.resolve(true);
13
+ }
14
+ /** @public */
15
+ store(id, secret) {
16
+ this.#store.set(id, secret);
17
+ return Promise.resolve();
18
+ }
19
+ /** @public */
20
+ retrieve(id) {
21
+ const val = this.#store.get(id);
22
+ if (val === void 0) {
23
+ return Promise.reject(new Error(`Secret not found: ${id}`));
24
+ }
25
+ return Promise.resolve(val);
26
+ }
27
+ /** @public */
28
+ delete(id) {
29
+ this.#store.delete(id);
30
+ return Promise.resolve();
31
+ }
32
+ /** @public */
33
+ exists(id) {
34
+ return Promise.resolve(this.#store.has(id));
35
+ }
36
+ /**
37
+ * Remove all stored secrets. Useful for test teardown.
38
+ * @public
39
+ */
40
+ clear() {
41
+ this.#store.clear();
42
+ }
43
+ /**
44
+ * The number of secrets currently stored.
45
+ * @public
46
+ */
47
+ get size() {
48
+ return this.#store.size;
49
+ }
50
+ };
51
+ var TEST_CONFIG = {
52
+ version: 1,
53
+ backends: [{ type: "memory", enabled: true }],
54
+ keyRotation: { gracePeriodDays: 1 },
55
+ defaults: { ttlMinutes: 5, trustTier: 1 },
56
+ developmentMode: { executables: ["dev"] }
57
+ };
58
+ var TestVault = class _TestVault {
59
+ /** The underlying VaultKeeper instance. */
60
+ keeper;
61
+ /** The in-memory backend used by this test vault. */
62
+ backend;
63
+ constructor(keeper, backend) {
64
+ this.keeper = keeper;
65
+ this.backend = backend;
66
+ }
67
+ /**
68
+ * Create a new TestVault, ready for use.
69
+ *
70
+ * @param options - Optional overrides for TTL and trust tier.
71
+ * @returns A fully-initialized TestVault.
72
+ *
73
+ * @public
74
+ */
75
+ static async create(options) {
76
+ const backend = new InMemoryBackend();
77
+ vaultkeeper.BackendRegistry.register("memory", () => backend);
78
+ const config = {
79
+ ...TEST_CONFIG,
80
+ defaults: {
81
+ ttlMinutes: options?.ttlMinutes ?? TEST_CONFIG.defaults.ttlMinutes,
82
+ trustTier: options?.trustTier ?? TEST_CONFIG.defaults.trustTier
83
+ }
84
+ };
85
+ const keeper = await vaultkeeper.VaultKeeper.init({
86
+ skipDoctor: true,
87
+ config
88
+ });
89
+ return new _TestVault(keeper, backend);
90
+ }
91
+ /**
92
+ * Reset the test vault by clearing all stored secrets.
93
+ * @public
94
+ */
95
+ reset() {
96
+ this.backend.clear();
97
+ }
98
+ };
99
+
100
+ exports.InMemoryBackend = InMemoryBackend;
101
+ exports.TestVault = TestVault;
102
+ //# sourceMappingURL=index.cjs.map
103
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/in-memory-backend.ts","../src/test-vault.ts"],"names":["BackendRegistry","VaultKeeper"],"mappings":";;;;;AAeO,IAAM,kBAAN,MAA+C;AAAA,EAC3C,IAAA,GAAO,QAAA;AAAA,EACP,WAAA,GAAc,mBAAA;AAAA,EACd,MAAA,uBAAa,GAAA,EAAoB;AAAA;AAAA,EAG1C,WAAA,GAAgC;AAC9B,IAAA,OAAO,OAAA,CAAQ,QAAQ,IAAI,CAAA;AAAA,EAC7B;AAAA;AAAA,EAGA,KAAA,CAAM,IAAY,MAAA,EAA+B;AAC/C,IAAA,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,EAAA,EAAI,MAAM,CAAA;AAC1B,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA;AAAA,EAGA,SAAS,EAAA,EAA6B;AACpC,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,EAAE,CAAA;AAC9B,IAAA,IAAI,QAAQ,MAAA,EAAW;AACrB,MAAA,OAAO,QAAQ,MAAA,CAAO,IAAI,MAAM,CAAA,kBAAA,EAAqB,EAAE,EAAE,CAAC,CAAA;AAAA,IAC5D;AACA,IAAA,OAAO,OAAA,CAAQ,QAAQ,GAAG,CAAA;AAAA,EAC5B;AAAA;AAAA,EAGA,OAAO,EAAA,EAA2B;AAChC,IAAA,IAAA,CAAK,MAAA,CAAO,OAAO,EAAE,CAAA;AACrB,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA;AAAA,EAGA,OAAO,EAAA,EAA8B;AACnC,IAAA,OAAO,QAAQ,OAAA,CAAQ,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,EAAE,CAAC,CAAA;AAAA,EAC5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AAEA,IAAA,MAAM,MAAA,GAAS,MAAMC,uBAAA,CAAY,IAAA,CAAK;AAAA,MACpC,UAAA,EAAY,IAAA;AAAA,MACZ;AAAA,KACD,CAAA;AAED,IAAA,OAAO,IAAI,UAAA,CAAU,MAAA,EAAQ,OAAO,CAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,QAAQ,KAAA,EAAM;AAAA,EACrB;AACF","file":"index.cjs","sourcesContent":["/**\n * In-memory secret backend for testing.\n */\n\nimport type { SecretBackend } from 'vaultkeeper'\n\n/**\n * A fully in-memory `SecretBackend` for testing.\n *\n * @remarks\n * This backend stores secrets in a plain `Map` and has no external\n * dependencies. It is suitable for unit, integration, and e2e tests.\n *\n * @public\n */\nexport class InMemoryBackend implements SecretBackend {\n readonly type = 'memory'\n readonly displayName = 'In-Memory Backend'\n readonly #store = new Map<string, string>()\n\n /** @public */\n isAvailable(): Promise<boolean> {\n return Promise.resolve(true)\n }\n\n /** @public */\n store(id: string, secret: string): Promise<void> {\n this.#store.set(id, secret)\n return Promise.resolve()\n }\n\n /** @public */\n retrieve(id: string): Promise<string> {\n const val = this.#store.get(id)\n if (val === undefined) {\n return Promise.reject(new Error(`Secret not found: ${id}`))\n }\n return Promise.resolve(val)\n }\n\n /** @public */\n delete(id: string): Promise<void> {\n this.#store.delete(id)\n return Promise.resolve()\n }\n\n /** @public */\n exists(id: string): Promise<boolean> {\n return Promise.resolve(this.#store.has(id))\n }\n\n /**\n * Remove all stored secrets. Useful for test teardown.\n * @public\n */\n clear(): void {\n this.#store.clear()\n }\n\n /**\n * The number of secrets currently stored.\n * @public\n */\n get size(): number {\n return this.#store.size\n }\n}\n","/**\n * Pre-configured VaultKeeper for consumer tests.\n */\n\nimport type { VaultConfig } from 'vaultkeeper'\nimport { VaultKeeper, BackendRegistry } from 'vaultkeeper'\nimport { InMemoryBackend } from './in-memory-backend.js'\n\n/** Default test configuration with short TTL and dev-mode trust. */\nconst TEST_CONFIG: VaultConfig = {\n version: 1,\n backends: [{ type: 'memory', enabled: true }],\n keyRotation: { gracePeriodDays: 1 },\n defaults: { ttlMinutes: 5, trustTier: 1 },\n developmentMode: { executables: ['dev'] },\n}\n\n/**\n * Options for creating a {@link TestVault}.\n * @public\n */\nexport interface TestVaultOptions {\n /** Override the default TTL in minutes. */\n ttlMinutes?: number | undefined\n /** Override the default trust tier. */\n trustTier?: 1 | 2 | 3 | undefined\n}\n\n/**\n * A pre-configured vault for consumer test workflows.\n *\n * @remarks\n * `TestVault` wraps a real `VaultKeeper` instance backed by an\n * {@link InMemoryBackend}. It skips doctor checks and uses dev-mode\n * identity, making it suitable for fast, hermetic tests.\n *\n * @example\n * ```ts\n * const vault = await TestVault.create()\n * await vault.backend.store('my-secret', 'hunter2')\n * const jwe = await vault.keeper.setup('my-secret')\n * const { token } = await vault.keeper.authorize(jwe)\n * ```\n *\n * @public\n */\nexport class TestVault {\n /** The underlying VaultKeeper instance. */\n readonly keeper: VaultKeeper\n\n /** The in-memory backend used by this test vault. */\n readonly backend: InMemoryBackend\n\n private constructor(keeper: VaultKeeper, backend: InMemoryBackend) {\n this.keeper = keeper\n this.backend = backend\n }\n\n /**\n * Create a new TestVault, ready for use.\n *\n * @param options - Optional overrides for TTL and trust tier.\n * @returns A fully-initialized TestVault.\n *\n * @public\n */\n static async create(options?: TestVaultOptions): Promise<TestVault> {\n const backend = new InMemoryBackend()\n\n // Register the in-memory backend so VaultKeeper can resolve it\n BackendRegistry.register('memory', () => backend)\n\n const config: VaultConfig = {\n ...TEST_CONFIG,\n defaults: {\n ttlMinutes: options?.ttlMinutes ?? TEST_CONFIG.defaults.ttlMinutes,\n trustTier: options?.trustTier ?? TEST_CONFIG.defaults.trustTier,\n },\n }\n\n const keeper = await VaultKeeper.init({\n skipDoctor: true,\n config,\n })\n\n return new TestVault(keeper, backend)\n }\n\n /**\n * Reset the test vault by clearing all stored secrets.\n * @public\n */\n reset(): void {\n this.backend.clear()\n }\n}\n"]}
@@ -0,0 +1,96 @@
1
+ import { SecretBackend, VaultKeeper } from 'vaultkeeper';
2
+
3
+ /**
4
+ * In-memory secret backend for testing.
5
+ */
6
+
7
+ /**
8
+ * A fully in-memory `SecretBackend` for testing.
9
+ *
10
+ * @remarks
11
+ * This backend stores secrets in a plain `Map` and has no external
12
+ * dependencies. It is suitable for unit, integration, and e2e tests.
13
+ *
14
+ * @public
15
+ */
16
+ declare class InMemoryBackend implements SecretBackend {
17
+ #private;
18
+ readonly type = "memory";
19
+ readonly displayName = "In-Memory Backend";
20
+ /** @public */
21
+ isAvailable(): Promise<boolean>;
22
+ /** @public */
23
+ store(id: string, secret: string): Promise<void>;
24
+ /** @public */
25
+ retrieve(id: string): Promise<string>;
26
+ /** @public */
27
+ delete(id: string): Promise<void>;
28
+ /** @public */
29
+ exists(id: string): Promise<boolean>;
30
+ /**
31
+ * Remove all stored secrets. Useful for test teardown.
32
+ * @public
33
+ */
34
+ clear(): void;
35
+ /**
36
+ * The number of secrets currently stored.
37
+ * @public
38
+ */
39
+ get size(): number;
40
+ }
41
+
42
+ /**
43
+ * Pre-configured VaultKeeper for consumer tests.
44
+ */
45
+
46
+ /**
47
+ * Options for creating a {@link TestVault}.
48
+ * @public
49
+ */
50
+ interface TestVaultOptions {
51
+ /** Override the default TTL in minutes. */
52
+ ttlMinutes?: number | undefined;
53
+ /** Override the default trust tier. */
54
+ trustTier?: 1 | 2 | 3 | undefined;
55
+ }
56
+ /**
57
+ * A pre-configured vault for consumer test workflows.
58
+ *
59
+ * @remarks
60
+ * `TestVault` wraps a real `VaultKeeper` instance backed by an
61
+ * {@link InMemoryBackend}. It skips doctor checks and uses dev-mode
62
+ * identity, making it suitable for fast, hermetic tests.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const vault = await TestVault.create()
67
+ * await vault.backend.store('my-secret', 'hunter2')
68
+ * const jwe = await vault.keeper.setup('my-secret')
69
+ * const { token } = await vault.keeper.authorize(jwe)
70
+ * ```
71
+ *
72
+ * @public
73
+ */
74
+ declare class TestVault {
75
+ /** The underlying VaultKeeper instance. */
76
+ readonly keeper: VaultKeeper;
77
+ /** The in-memory backend used by this test vault. */
78
+ readonly backend: InMemoryBackend;
79
+ private constructor();
80
+ /**
81
+ * Create a new TestVault, ready for use.
82
+ *
83
+ * @param options - Optional overrides for TTL and trust tier.
84
+ * @returns A fully-initialized TestVault.
85
+ *
86
+ * @public
87
+ */
88
+ static create(options?: TestVaultOptions): Promise<TestVault>;
89
+ /**
90
+ * Reset the test vault by clearing all stored secrets.
91
+ * @public
92
+ */
93
+ reset(): void;
94
+ }
95
+
96
+ export { InMemoryBackend, TestVault, type TestVaultOptions };
@@ -0,0 +1,96 @@
1
+ import { SecretBackend, VaultKeeper } from 'vaultkeeper';
2
+
3
+ /**
4
+ * In-memory secret backend for testing.
5
+ */
6
+
7
+ /**
8
+ * A fully in-memory `SecretBackend` for testing.
9
+ *
10
+ * @remarks
11
+ * This backend stores secrets in a plain `Map` and has no external
12
+ * dependencies. It is suitable for unit, integration, and e2e tests.
13
+ *
14
+ * @public
15
+ */
16
+ declare class InMemoryBackend implements SecretBackend {
17
+ #private;
18
+ readonly type = "memory";
19
+ readonly displayName = "In-Memory Backend";
20
+ /** @public */
21
+ isAvailable(): Promise<boolean>;
22
+ /** @public */
23
+ store(id: string, secret: string): Promise<void>;
24
+ /** @public */
25
+ retrieve(id: string): Promise<string>;
26
+ /** @public */
27
+ delete(id: string): Promise<void>;
28
+ /** @public */
29
+ exists(id: string): Promise<boolean>;
30
+ /**
31
+ * Remove all stored secrets. Useful for test teardown.
32
+ * @public
33
+ */
34
+ clear(): void;
35
+ /**
36
+ * The number of secrets currently stored.
37
+ * @public
38
+ */
39
+ get size(): number;
40
+ }
41
+
42
+ /**
43
+ * Pre-configured VaultKeeper for consumer tests.
44
+ */
45
+
46
+ /**
47
+ * Options for creating a {@link TestVault}.
48
+ * @public
49
+ */
50
+ interface TestVaultOptions {
51
+ /** Override the default TTL in minutes. */
52
+ ttlMinutes?: number | undefined;
53
+ /** Override the default trust tier. */
54
+ trustTier?: 1 | 2 | 3 | undefined;
55
+ }
56
+ /**
57
+ * A pre-configured vault for consumer test workflows.
58
+ *
59
+ * @remarks
60
+ * `TestVault` wraps a real `VaultKeeper` instance backed by an
61
+ * {@link InMemoryBackend}. It skips doctor checks and uses dev-mode
62
+ * identity, making it suitable for fast, hermetic tests.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const vault = await TestVault.create()
67
+ * await vault.backend.store('my-secret', 'hunter2')
68
+ * const jwe = await vault.keeper.setup('my-secret')
69
+ * const { token } = await vault.keeper.authorize(jwe)
70
+ * ```
71
+ *
72
+ * @public
73
+ */
74
+ declare class TestVault {
75
+ /** The underlying VaultKeeper instance. */
76
+ readonly keeper: VaultKeeper;
77
+ /** The in-memory backend used by this test vault. */
78
+ readonly backend: InMemoryBackend;
79
+ private constructor();
80
+ /**
81
+ * Create a new TestVault, ready for use.
82
+ *
83
+ * @param options - Optional overrides for TTL and trust tier.
84
+ * @returns A fully-initialized TestVault.
85
+ *
86
+ * @public
87
+ */
88
+ static create(options?: TestVaultOptions): Promise<TestVault>;
89
+ /**
90
+ * Reset the test vault by clearing all stored secrets.
91
+ * @public
92
+ */
93
+ reset(): void;
94
+ }
95
+
96
+ export { InMemoryBackend, TestVault, type TestVaultOptions };
package/dist/index.js ADDED
@@ -0,0 +1,100 @@
1
+ import { BackendRegistry, VaultKeeper } from 'vaultkeeper';
2
+
3
+ // src/in-memory-backend.ts
4
+ var InMemoryBackend = class {
5
+ type = "memory";
6
+ displayName = "In-Memory Backend";
7
+ #store = /* @__PURE__ */ new Map();
8
+ /** @public */
9
+ isAvailable() {
10
+ return Promise.resolve(true);
11
+ }
12
+ /** @public */
13
+ store(id, secret) {
14
+ this.#store.set(id, secret);
15
+ return Promise.resolve();
16
+ }
17
+ /** @public */
18
+ retrieve(id) {
19
+ const val = this.#store.get(id);
20
+ if (val === void 0) {
21
+ return Promise.reject(new Error(`Secret not found: ${id}`));
22
+ }
23
+ return Promise.resolve(val);
24
+ }
25
+ /** @public */
26
+ delete(id) {
27
+ this.#store.delete(id);
28
+ return Promise.resolve();
29
+ }
30
+ /** @public */
31
+ exists(id) {
32
+ return Promise.resolve(this.#store.has(id));
33
+ }
34
+ /**
35
+ * Remove all stored secrets. Useful for test teardown.
36
+ * @public
37
+ */
38
+ clear() {
39
+ this.#store.clear();
40
+ }
41
+ /**
42
+ * The number of secrets currently stored.
43
+ * @public
44
+ */
45
+ get size() {
46
+ return this.#store.size;
47
+ }
48
+ };
49
+ var TEST_CONFIG = {
50
+ version: 1,
51
+ backends: [{ type: "memory", enabled: true }],
52
+ keyRotation: { gracePeriodDays: 1 },
53
+ defaults: { ttlMinutes: 5, trustTier: 1 },
54
+ developmentMode: { executables: ["dev"] }
55
+ };
56
+ var TestVault = class _TestVault {
57
+ /** The underlying VaultKeeper instance. */
58
+ keeper;
59
+ /** The in-memory backend used by this test vault. */
60
+ backend;
61
+ constructor(keeper, backend) {
62
+ this.keeper = keeper;
63
+ this.backend = backend;
64
+ }
65
+ /**
66
+ * Create a new TestVault, ready for use.
67
+ *
68
+ * @param options - Optional overrides for TTL and trust tier.
69
+ * @returns A fully-initialized TestVault.
70
+ *
71
+ * @public
72
+ */
73
+ static async create(options) {
74
+ const backend = new InMemoryBackend();
75
+ BackendRegistry.register("memory", () => backend);
76
+ const config = {
77
+ ...TEST_CONFIG,
78
+ defaults: {
79
+ ttlMinutes: options?.ttlMinutes ?? TEST_CONFIG.defaults.ttlMinutes,
80
+ trustTier: options?.trustTier ?? TEST_CONFIG.defaults.trustTier
81
+ }
82
+ };
83
+ const keeper = await VaultKeeper.init({
84
+ skipDoctor: true,
85
+ config
86
+ });
87
+ return new _TestVault(keeper, backend);
88
+ }
89
+ /**
90
+ * Reset the test vault by clearing all stored secrets.
91
+ * @public
92
+ */
93
+ reset() {
94
+ this.backend.clear();
95
+ }
96
+ };
97
+
98
+ export { InMemoryBackend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AAAA,MACZ;AAAA,KACD,CAAA;AAED,IAAA,OAAO,IAAI,UAAA,CAAU,MAAA,EAAQ,OAAO,CAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAA,GAAc;AACZ,IAAA,IAAA,CAAK,QAAQ,KAAA,EAAM;AAAA,EACrB;AACF","file":"index.js","sourcesContent":["/**\n * In-memory secret backend for testing.\n */\n\nimport type { SecretBackend } from 'vaultkeeper'\n\n/**\n * A fully in-memory `SecretBackend` for testing.\n *\n * @remarks\n * This backend stores secrets in a plain `Map` and has no external\n * dependencies. It is suitable for unit, integration, and e2e tests.\n *\n * @public\n */\nexport class InMemoryBackend implements SecretBackend {\n readonly type = 'memory'\n readonly displayName = 'In-Memory Backend'\n readonly #store = new Map<string, string>()\n\n /** @public */\n isAvailable(): Promise<boolean> {\n return Promise.resolve(true)\n }\n\n /** @public */\n store(id: string, secret: string): Promise<void> {\n this.#store.set(id, secret)\n return Promise.resolve()\n }\n\n /** @public */\n retrieve(id: string): Promise<string> {\n const val = this.#store.get(id)\n if (val === undefined) {\n return Promise.reject(new Error(`Secret not found: ${id}`))\n }\n return Promise.resolve(val)\n }\n\n /** @public */\n delete(id: string): Promise<void> {\n this.#store.delete(id)\n return Promise.resolve()\n }\n\n /** @public */\n exists(id: string): Promise<boolean> {\n return Promise.resolve(this.#store.has(id))\n }\n\n /**\n * Remove all stored secrets. Useful for test teardown.\n * @public\n */\n clear(): void {\n this.#store.clear()\n }\n\n /**\n * The number of secrets currently stored.\n * @public\n */\n get size(): number {\n return this.#store.size\n }\n}\n","/**\n * Pre-configured VaultKeeper for consumer tests.\n */\n\nimport type { VaultConfig } from 'vaultkeeper'\nimport { VaultKeeper, BackendRegistry } from 'vaultkeeper'\nimport { InMemoryBackend } from './in-memory-backend.js'\n\n/** Default test configuration with short TTL and dev-mode trust. */\nconst TEST_CONFIG: VaultConfig = {\n version: 1,\n backends: [{ type: 'memory', enabled: true }],\n keyRotation: { gracePeriodDays: 1 },\n defaults: { ttlMinutes: 5, trustTier: 1 },\n developmentMode: { executables: ['dev'] },\n}\n\n/**\n * Options for creating a {@link TestVault}.\n * @public\n */\nexport interface TestVaultOptions {\n /** Override the default TTL in minutes. */\n ttlMinutes?: number | undefined\n /** Override the default trust tier. */\n trustTier?: 1 | 2 | 3 | undefined\n}\n\n/**\n * A pre-configured vault for consumer test workflows.\n *\n * @remarks\n * `TestVault` wraps a real `VaultKeeper` instance backed by an\n * {@link InMemoryBackend}. It skips doctor checks and uses dev-mode\n * identity, making it suitable for fast, hermetic tests.\n *\n * @example\n * ```ts\n * const vault = await TestVault.create()\n * await vault.backend.store('my-secret', 'hunter2')\n * const jwe = await vault.keeper.setup('my-secret')\n * const { token } = await vault.keeper.authorize(jwe)\n * ```\n *\n * @public\n */\nexport class TestVault {\n /** The underlying VaultKeeper instance. */\n readonly keeper: VaultKeeper\n\n /** The in-memory backend used by this test vault. */\n readonly backend: InMemoryBackend\n\n private constructor(keeper: VaultKeeper, backend: InMemoryBackend) {\n this.keeper = keeper\n this.backend = backend\n }\n\n /**\n * Create a new TestVault, ready for use.\n *\n * @param options - Optional overrides for TTL and trust tier.\n * @returns A fully-initialized TestVault.\n *\n * @public\n */\n static async create(options?: TestVaultOptions): Promise<TestVault> {\n const backend = new InMemoryBackend()\n\n // Register the in-memory backend so VaultKeeper can resolve it\n BackendRegistry.register('memory', () => backend)\n\n const config: VaultConfig = {\n ...TEST_CONFIG,\n defaults: {\n ttlMinutes: options?.ttlMinutes ?? TEST_CONFIG.defaults.ttlMinutes,\n trustTier: options?.trustTier ?? TEST_CONFIG.defaults.trustTier,\n },\n }\n\n const keeper = await VaultKeeper.init({\n skipDoctor: true,\n config,\n })\n\n return new TestVault(keeper, backend)\n }\n\n /**\n * Reset the test vault by clearing all stored secrets.\n * @public\n */\n reset(): void {\n this.backend.clear()\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@vaultkeeper/test-helpers",
3
+ "version": "0.1.1",
4
+ "description": "Test utilities for vaultkeeper consumers",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/test-helpers-public.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "engines": {
25
+ "node": ">=20.0.0"
26
+ },
27
+ "keywords": [],
28
+ "author": "Mike North <michael.l.north@gmail.com>",
29
+ "license": "MIT",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "vaultkeeper": "0.2.0"
35
+ },
36
+ "devDependencies": {
37
+ "@microsoft/api-extractor": "^7.57.2",
38
+ "@types/node": "^22.0.0",
39
+ "tsup": "^8.0.0"
40
+ },
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "clean": "node -e \"import('node:fs').then(fs=>fs.rmSync('dist',{recursive:true,force:true}))\"",
44
+ "test": "vitest run",
45
+ "check:typecheck": "tsc --noEmit",
46
+ "check:lint-ts": "eslint .",
47
+ "check:api-report": "api-extractor run",
48
+ "check": "pnpm check:typecheck && pnpm check:lint-ts && pnpm check:api-report",
49
+ "generate:api-report": "api-extractor run --local"
50
+ }
51
+ }