@nightlybuildgroup/vault 1.7.0 → 1.7.2
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/package.json +1 -1
- package/src/commands/add.js +12 -11
- package/src/commands/items.js +4 -4
package/package.json
CHANGED
package/src/commands/add.js
CHANGED
|
@@ -75,9 +75,10 @@ async function resolveFolderId(bw, session, folderName) {
|
|
|
75
75
|
return created.id;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
// Resolves a collection given by name OR id (and an optional org name/id).
|
|
79
|
+
async function resolveCollection(bw, session, collectionRef, org) {
|
|
79
80
|
const collections = await bw.listCollections({ session });
|
|
80
|
-
let matches = collections.filter((c) => c.name ===
|
|
81
|
+
let matches = collections.filter((c) => c.name === collectionRef || c.id === collectionRef);
|
|
81
82
|
if (org) {
|
|
82
83
|
const orgs = await bw.listOrganizations({ session });
|
|
83
84
|
const match = orgs.find((o) => o.id === org || o.name === org);
|
|
@@ -85,10 +86,10 @@ async function resolveCollection(bw, session, collectionName, org) {
|
|
|
85
86
|
matches = matches.filter((c) => c.organizationId === orgId);
|
|
86
87
|
}
|
|
87
88
|
if (matches.length === 0) {
|
|
88
|
-
throw new Error(`no collection
|
|
89
|
+
throw new Error(`no collection "${collectionRef}"${org ? ` in organization "${org}"` : ''}`);
|
|
89
90
|
}
|
|
90
91
|
if (matches.length > 1) {
|
|
91
|
-
throw new Error(`multiple collections named "${
|
|
92
|
+
throw new Error(`multiple collections named "${collectionRef}"; disambiguate with --organization <name|id>`);
|
|
92
93
|
}
|
|
93
94
|
return matches[0];
|
|
94
95
|
}
|
|
@@ -138,20 +139,20 @@ export async function runAdd(args, deps) {
|
|
|
138
139
|
|
|
139
140
|
if (entry.folder) entry.folderId = await resolveFolderId(bw, session, entry.folder);
|
|
140
141
|
|
|
141
|
-
const
|
|
142
|
+
const item = buildLoginItem(entry);
|
|
142
143
|
|
|
144
|
+
// Create the item DIRECTLY in the org collection (org id + collection ids in
|
|
145
|
+
// the create payload). Creating-then-moving leaves the item in a state that
|
|
146
|
+
// the org collection listing / web vault don't show — direct create does.
|
|
143
147
|
let shared = '';
|
|
144
148
|
if (collectionName) {
|
|
145
149
|
const col = await resolveCollection(bw, session, collectionName, organizationName);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
organizationId: col.organizationId,
|
|
149
|
-
collectionIds: [col.id],
|
|
150
|
-
session,
|
|
151
|
-
});
|
|
150
|
+
item.organizationId = col.organizationId;
|
|
151
|
+
item.collectionIds = [col.id];
|
|
152
152
|
shared = ` → shared to "${col.name}"`;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
const created = await bw.createItem({ item, session });
|
|
155
156
|
out(`Created "${created.name}" (${created.id})${shared}\n`);
|
|
156
157
|
return 0;
|
|
157
158
|
}
|
package/src/commands/items.js
CHANGED
|
@@ -43,16 +43,16 @@ export async function runItems(args, deps) {
|
|
|
43
43
|
let folderId;
|
|
44
44
|
if (folder !== null) {
|
|
45
45
|
const folders = await bw.listFolders({ session });
|
|
46
|
-
const match = folders.find((f) => f.name === folder
|
|
47
|
-
if (!match) throw new Error(`no folder
|
|
46
|
+
const match = folders.find((f) => f.id && (f.name === folder || f.id === folder));
|
|
47
|
+
if (!match) throw new Error(`no folder "${folder}"`);
|
|
48
48
|
folderId = match.id;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
let collectionId;
|
|
52
52
|
if (collection !== null) {
|
|
53
53
|
const collections = await bw.listCollections({ session });
|
|
54
|
-
const match = collections.find((c) => c.name === collection);
|
|
55
|
-
if (!match) throw new Error(`no collection
|
|
54
|
+
const match = collections.find((c) => c.name === collection || c.id === collection);
|
|
55
|
+
if (!match) throw new Error(`no collection "${collection}"`);
|
|
56
56
|
collectionId = match.id;
|
|
57
57
|
}
|
|
58
58
|
|