@nightlybuildgroup/vault 0.1.0 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +21 -7
  2. package/src/bw.js +19 -2
package/package.json CHANGED
@@ -1,19 +1,33 @@
1
1
  {
2
2
  "name": "@nightlybuildgroup/vault",
3
- "version": "0.1.0",
3
+ "version": "1.0.1",
4
4
  "description": "Store Vaultwarden/Bitwarden credentials in the macOS Keychain and read secrets back for local agents.",
5
5
  "type": "module",
6
- "bin": { "nbg-pw": "bin/nbg-pw.js" },
7
- "files": ["bin", "src", "README.md"],
8
- "engines": { "node": ">=18" },
9
- "os": ["darwin"],
6
+ "bin": {
7
+ "nbg-pw": "bin/nbg-pw.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "README.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "os": [
18
+ "darwin"
19
+ ],
10
20
  "scripts": {
11
21
  "test": "node --test \"test/**/*.test.js\"",
12
22
  "prepublishOnly": "npm test",
13
23
  "release": "semantic-release"
14
24
  },
15
- "publishConfig": { "access": "public" },
16
- "dependencies": { "@clack/prompts": "^0.7.0" },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "dependencies": {
29
+ "@clack/prompts": "^0.7.0"
30
+ },
17
31
  "devDependencies": {
18
32
  "@semantic-release/changelog": "^6.0.3",
19
33
  "@semantic-release/commit-analyzer": "^13.0.1",
package/src/bw.js CHANGED
@@ -78,8 +78,25 @@ export async function logout(deps = {}) {
78
78
  }
79
79
  }
80
80
 
81
+ function sameServer(a, b) {
82
+ const norm = (u) => (u ?? '').replace(/\/+$/, '');
83
+ return norm(a) === norm(b);
84
+ }
85
+
81
86
  export async function ensureSession(config, deps = {}) {
82
- await configServer(config.serverUrl, deps);
83
- await loginApiKey({ clientId: config.clientId, clientSecret: config.clientSecret }, deps);
87
+ // `bw config server` refuses to run while logged in ("Logout required before
88
+ // server config update"), so a warm process (already logged in from a prior
89
+ // call) must skip straight to unlock. Only configure + log in when actually
90
+ // logged out, or when logged into a different server than we want.
91
+ const current = await status(deps);
92
+ const wrongServer =
93
+ current.status !== 'unauthenticated' && !sameServer(current.serverUrl, config.serverUrl);
94
+ if (wrongServer) {
95
+ await logout(deps);
96
+ }
97
+ if (current.status === 'unauthenticated' || wrongServer) {
98
+ await configServer(config.serverUrl, deps);
99
+ await loginApiKey({ clientId: config.clientId, clientSecret: config.clientSecret }, deps);
100
+ }
84
101
  return unlock({ masterPassword: config.masterPassword }, deps);
85
102
  }