From 127340b56191c6d24b4c0b56351ae1a37de6d9df Mon Sep 17 00:00:00 2001 From: skeletonz28 <33682551+skeletonz28@users.noreply.github.com> Date: Mon, 13 Oct 2025 07:40:42 +0200 Subject: [PATCH 1/7] Update index.js Adding update method to offer users the ability to update the secret/path with a new value, without overwriting any existing data --- src/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/index.js b/src/index.js index faccfead..ff24fc9a 100644 --- a/src/index.js +++ b/src/index.js @@ -127,6 +127,15 @@ module.exports = (config = {}) => { return client.request(options); }; + client.update = (path, data, requestOptions) => { + debug('update %o to %s', data, path); + const options = { ...config.requestOptions, ...requestOptions }; + options.path = `/${path}`; + options.json = data; + options.method = 'PATCH'; + return client.request(options); + }; + client.read = (path, requestOptions) => { debug(`read ${path}`); const options = { ...config.requestOptions, ...requestOptions }; From 36f4e6e0aa6023d5fed2034e856902cfb08d7b66 Mon Sep 17 00:00:00 2001 From: skeletonz28 <33682551+skeletonz28@users.noreply.github.com> Date: Mon, 13 Oct 2025 07:44:38 +0200 Subject: [PATCH 2/7] Create update.js Adding script to test update function --- example/update.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 example/update.js diff --git a/example/update.js b/example/update.js new file mode 100644 index 00000000..2ecfdbdd --- /dev/null +++ b/example/update.js @@ -0,0 +1,13 @@ +// file: example/update.js + +process.env.DEBUG = 'node-vault'; // switch on debug mode + +const vault = require('./../src/index')(); + +vault.update('secret/hello', { value: 'world', lease: '1s' }) + .then(() => vault.read('secret/hello')) + .catch((err) => console.error(err.message)); + +vault.update('secret/hello', { value: 'everyone', lease: '1s' }) + .then(() => vault.read('secret/hello')) + .catch((err) => console.error(err.message)); From e4d2ddd2a0d0c32fd63219eac100534c934532e8 Mon Sep 17 00:00:00 2001 From: skeletonz28 <33682551+skeletonz28@users.noreply.github.com> Date: Mon, 13 Oct 2025 10:23:50 +0200 Subject: [PATCH 3/7] Update index.d.ts --- index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/index.d.ts b/index.d.ts index 8385001c..981580b9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -47,6 +47,7 @@ declare namespace NodeVault { read(path: string, requestOptions?: Option): Promise; list(path: string, requestOptions?: Option): Promise; delete(path: string, requestOptions?: Option): Promise; + update(path: string, data: any, requestOptions?: Option): Promise; generateFunction(name: string, conf: functionConf): void; From 9efc562dea2a4219daa67cdbdf0ca16673cf7583 Mon Sep 17 00:00:00 2001 From: skeletonz28 <33682551+skeletonz28@users.noreply.github.com> Date: Mon, 13 Oct 2025 10:26:56 +0200 Subject: [PATCH 4/7] Update package.json Added myself as contributor --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 57907e07..2d0d1ada 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "Sean Gallavan (https://github.com/seangallavan)", "seyfert (https://github.com/seyfert)", "Simon Boulet (https://github.com/siboulet)", + "skeletonz28 (https://github.com/skeletonz28)", "Tim Robinson (https://github.com/timjrobinson)", "Tom Vogel (https://github.com/tavogel)", "Trevor Robinson (https://github.com/trevorr)", From ac4d75bf240a0fad1e93f69d6a9174cd625cf5c9 Mon Sep 17 00:00:00 2001 From: skeletonz28 <33682551+skeletonz28@users.noreply.github.com> Date: Mon, 13 Oct 2025 10:37:35 +0200 Subject: [PATCH 5/7] Update update.js Adding more options for update --- example/update.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example/update.js b/example/update.js index 2ecfdbdd..1d9e2902 100644 --- a/example/update.js +++ b/example/update.js @@ -11,3 +11,7 @@ vault.update('secret/hello', { value: 'world', lease: '1s' }) vault.update('secret/hello', { value: 'everyone', lease: '1s' }) .then(() => vault.read('secret/hello')) .catch((err) => console.error(err.message)); + +vault.update('secret/hello', { value: { 'foo': 'bar', 'world': 'everyone' } }) + .then(() => vault.read('secret/hello')) + .catch((err) => console.error(err.message)); From b9938602887db6c0de0e529223ddf8cb62f88014 Mon Sep 17 00:00:00 2001 From: skeletonz28 <33682551+skeletonz28@users.noreply.github.com> Date: Mon, 13 Oct 2025 10:38:41 +0200 Subject: [PATCH 6/7] Update index.js Adding merge-patch to header --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index ff24fc9a..d868d408 100644 --- a/src/index.js +++ b/src/index.js @@ -133,6 +133,7 @@ module.exports = (config = {}) => { options.path = `/${path}`; options.json = data; options.method = 'PATCH'; + options.headers = { 'Content-Type': 'application/merge-patch+json' }; return client.request(options); }; From 6861272511b66632932058597b7d443da3e6db9e Mon Sep 17 00:00:00 2001 From: skeletonz28 <33682551+skeletonz28@users.noreply.github.com> Date: Mon, 13 Oct 2025 10:39:48 +0200 Subject: [PATCH 7/7] Update unit.js Adding unit test --- test/unit.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/unit.js b/test/unit.js index 51e07ef1..2ac9525b 100644 --- a/test/unit.js +++ b/test/unit.js @@ -217,6 +217,36 @@ describe('node-vault', () => { }); }); + describe('update(path, data, options)', () => { + it('should update data to path', (done) => { + const path = 'secret/hello'; + const data = { + value: 'everyone', + }; + const params = { + method: 'PATCH', + uri: getURI(path), + }; + vault.update(path, data) + .then(assertRequest(request, params, done)) + .catch(done); + }); + + it('should handle undefined options', (done) => { + const path = 'secret/hello'; + const data = { + value: 'everyone', + }; + const params = { + method: 'PATCH', + uri: getURI(path), + }; + vault.update(path, data) + .then(assertRequest(request, params, done)) + .catch(done); + }); + }); + describe('read(path, options)', () => { it('should read data from path', (done) => { const path = 'secret/hello';