@ouro.bot/cli 0.1.0-alpha.1013 → 0.1.0-alpha.1015
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/changelog.json +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/optional-packages.js +71 -0
- package/dist/heart/providers/azure.js +4 -1
- package/dist/mailroom/core.js +2 -1
- package/dist/repertoire/bitwarden-native.js +115 -6
- package/dist/repertoire/bitwarden-store.js +70 -38
- package/dist/repertoire/stripe-client.js +2 -1
- package/dist/senses/mail-entry.js +5 -3
- package/dist/senses/shepherd/owner-notice.js +2 -1
- package/dist/senses/teams-entry.js +5 -3
- package/npm-shrinkwrap.json +174 -34
- package/package.json +14 -12
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1015",
|
|
6
|
+
"changes": [
|
|
7
|
+
"ouro auth, ouro vault config set and every other vault write go through Ouro's own Bitwarden client too: it creates, updates or trashes the login item over HTTPS with Node's crypto, keeps an existing item's own key, folder, custom fields and history as stored, refuses to overwrite a newer copy, and reads the item back to check it. Nothing on the vault path runs bw any more unless the vault needs it (Argon2id, two-step login) or OURO_VAULT_NATIVE_READS=0."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1014",
|
|
12
|
+
"changes": [
|
|
13
|
+
"The Teams, Azure, Stripe and mail SDKs are optional packages. A small host can leave them out with npm config set omit optional (about 97 MB and 138 packages of the 220 MB install); the core harness, providers, vault and other senses run without them, and a feature that needs a missing one says which package and how to restore it. The edge benchmark now measures that install."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1013",
|
|
6
18
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1015</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OptionalPackageMissingError = exports.OPTIONAL_PACKAGES = void 0;
|
|
4
|
+
exports.missingOptionalPackage = missingOptionalPackage;
|
|
5
|
+
exports.importOptional = importOptional;
|
|
6
|
+
exports.describeStartupError = describeStartupError;
|
|
7
|
+
const runtime_1 = require("../nerves/runtime");
|
|
8
|
+
/**
|
|
9
|
+
* Product SDKs listed in package.json optionalDependencies. npm installs them by default; a small
|
|
10
|
+
* host can leave them out with `npm install --omit=optional` (about 97 MB and 138 packages), and
|
|
11
|
+
* only the feature that needs one stops working.
|
|
12
|
+
*/
|
|
13
|
+
exports.OPTIONAL_PACKAGES = [
|
|
14
|
+
"@azure/identity",
|
|
15
|
+
"@azure/storage-blob",
|
|
16
|
+
"@microsoft/teams.api",
|
|
17
|
+
"@microsoft/teams.apps",
|
|
18
|
+
"@microsoft/teams.cards",
|
|
19
|
+
"@microsoft/teams.common",
|
|
20
|
+
"@microsoft/teams.dev",
|
|
21
|
+
"@microsoft/teams.graph",
|
|
22
|
+
"mailparser",
|
|
23
|
+
"smtp-server",
|
|
24
|
+
"stripe",
|
|
25
|
+
];
|
|
26
|
+
class OptionalPackageMissingError extends Error {
|
|
27
|
+
packageName;
|
|
28
|
+
feature;
|
|
29
|
+
constructor(packageName, feature) {
|
|
30
|
+
super(`${feature} needs ${packageName}, an optional package this install left out (npm --omit=optional). ` +
|
|
31
|
+
"Reinstall @ouro.bot/cli without --omit=optional to use it.");
|
|
32
|
+
this.packageName = packageName;
|
|
33
|
+
this.feature = feature;
|
|
34
|
+
this.name = "OptionalPackageMissingError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.OptionalPackageMissingError = OptionalPackageMissingError;
|
|
38
|
+
/** The optional package an error says is missing, or null for any other error (including a missing file inside a package). */
|
|
39
|
+
function missingOptionalPackage(error) {
|
|
40
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
41
|
+
return exports.OPTIONAL_PACKAGES.find((name) => message.includes(`Cannot find module '${name}'`)) ?? null;
|
|
42
|
+
}
|
|
43
|
+
function reportMissing(packageName, feature) {
|
|
44
|
+
const missing = new OptionalPackageMissingError(packageName, feature);
|
|
45
|
+
(0, runtime_1.emitNervesEvent)({
|
|
46
|
+
level: "error",
|
|
47
|
+
component: "engine",
|
|
48
|
+
event: "engine.optional_package_missing",
|
|
49
|
+
message: missing.message,
|
|
50
|
+
meta: { package: packageName, feature },
|
|
51
|
+
});
|
|
52
|
+
return missing;
|
|
53
|
+
}
|
|
54
|
+
/** Load an optional package, turning its absence into an error that names the feature and the fix. */
|
|
55
|
+
async function importOptional(packageName, feature, load) {
|
|
56
|
+
try {
|
|
57
|
+
return await load();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (missingOptionalPackage(error) !== packageName)
|
|
61
|
+
throw error;
|
|
62
|
+
throw reportMissing(packageName, feature);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** The message a sense entry point prints when it fails to start: the plain error, or what to do when an optional package is absent. */
|
|
66
|
+
function describeStartupError(error, feature) {
|
|
67
|
+
const packageName = missingOptionalPackage(error);
|
|
68
|
+
if (packageName)
|
|
69
|
+
return reportMissing(packageName, feature).message;
|
|
70
|
+
return error instanceof Error ? error.message : String(error);
|
|
71
|
+
}
|
|
@@ -42,6 +42,7 @@ const runtime_1 = require("../../nerves/runtime");
|
|
|
42
42
|
const streaming_1 = require("../streaming");
|
|
43
43
|
const model_capabilities_1 = require("../model-capabilities");
|
|
44
44
|
const error_classification_1 = require("./error-classification");
|
|
45
|
+
const optional_packages_1 = require("../optional-packages");
|
|
45
46
|
const COGNITIVE_SERVICES_SCOPE = "https://cognitiveservices.azure.com/.default";
|
|
46
47
|
function classifyAzureError(error) {
|
|
47
48
|
return (0, error_classification_1.classifyHttpError)(error);
|
|
@@ -55,7 +56,7 @@ function createAzureTokenProvider(managedIdentityClientId) {
|
|
|
55
56
|
return async () => {
|
|
56
57
|
try {
|
|
57
58
|
if (!credential) {
|
|
58
|
-
const { DefaultAzureCredential } = await Promise.resolve().then(() => __importStar(require("@azure/identity")));
|
|
59
|
+
const { DefaultAzureCredential } = await (0, optional_packages_1.importOptional)("@azure/identity", "Azure managed-identity sign-in", () => Promise.resolve().then(() => __importStar(require("@azure/identity"))));
|
|
59
60
|
const credentialOptions = managedIdentityClientId
|
|
60
61
|
? { managedIdentityClientId }
|
|
61
62
|
: undefined;
|
|
@@ -65,6 +66,8 @@ function createAzureTokenProvider(managedIdentityClientId) {
|
|
|
65
66
|
return tokenResponse.token;
|
|
66
67
|
}
|
|
67
68
|
catch (err) {
|
|
69
|
+
if (err instanceof optional_packages_1.OptionalPackageMissingError)
|
|
70
|
+
throw err;
|
|
68
71
|
const detail = err instanceof Error ? err.message : String(err);
|
|
69
72
|
throw new Error(`Azure OpenAI authentication failed: ${detail}\n` +
|
|
70
73
|
"To fix this, either:\n" +
|
package/dist/mailroom/core.js
CHANGED
|
@@ -58,6 +58,7 @@ exports.provisionMailboxRegistry = provisionMailboxRegistry;
|
|
|
58
58
|
exports.ensureMailboxRegistry = ensureMailboxRegistry;
|
|
59
59
|
const crypto = __importStar(require("node:crypto"));
|
|
60
60
|
const runtime_1 = require("../nerves/runtime");
|
|
61
|
+
const optional_packages_1 = require("../heart/optional-packages");
|
|
61
62
|
const LOCAL_PART_LIMIT = 64;
|
|
62
63
|
const SNIPPET_LIMIT = 240;
|
|
63
64
|
const RAW_OBJECT_PREFIX = "raw";
|
|
@@ -455,7 +456,7 @@ function privateMailEnvelopeReadableText(privateEnvelope) {
|
|
|
455
456
|
}
|
|
456
457
|
async function parsePrivateMailEnvelope(rawMime) {
|
|
457
458
|
// mailparser and its charset tables cost about 19 MB per process; load it on the first parse.
|
|
458
|
-
const { simpleParser } = await Promise.resolve().then(() => __importStar(require("mailparser")));
|
|
459
|
+
const { simpleParser } = await (0, optional_packages_1.importOptional)("mailparser", "Reading mail", () => Promise.resolve().then(() => __importStar(require("mailparser"))));
|
|
459
460
|
const parsed = await simpleParser(rawMime);
|
|
460
461
|
const html = typeof parsed.html === "string" ? parsed.html : undefined;
|
|
461
462
|
const parsedText = parsed.text ?? "";
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* Protocol (Bitwarden security whitepaper): prelogin for the KDF, PBKDF2-SHA256 master key,
|
|
7
7
|
* a password-grant login with the master password hash, the user key unwrapped with the
|
|
8
8
|
* HKDF-stretched master key, then /api/sync and AES-256-CBC + HMAC-SHA256 decryption of each item.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* It also creates, updates and trashes login items (POST/PUT /api/ciphers), re-encrypting only the
|
|
10
|
+
* name, notes and login and replaying every other encrypted field from the last sync unchanged.
|
|
11
|
+
* Anything this client does not handle (Argon2id, two-step login, other cipher types) raises
|
|
12
|
+
* NativeVaultUnsupportedError so the caller can fall back to `bw`.
|
|
11
13
|
*/
|
|
12
14
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
15
|
if (k2 === undefined) k2 = k;
|
|
@@ -46,6 +48,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
46
48
|
exports.NativeVaultReader = exports.NATIVE_VAULT_LOGIN_FAILURE_RETRY_MS = exports.NATIVE_VAULT_ITEMS_FRESH_MS = exports.NativeVaultUnsupportedError = void 0;
|
|
47
49
|
exports.nodeVaultRequest = nodeVaultRequest;
|
|
48
50
|
exports.decryptCipherString = decryptCipherString;
|
|
51
|
+
exports.encryptCipherString = encryptCipherString;
|
|
49
52
|
exports.decryptSyncItems = decryptSyncItems;
|
|
50
53
|
exports.sharedNativeVaultReader = sharedNativeVaultReader;
|
|
51
54
|
const crypto = __importStar(require("node:crypto"));
|
|
@@ -132,6 +135,14 @@ function decryptCipherString(value, key) {
|
|
|
132
135
|
const decipher = crypto.createDecipheriv("aes-256-cbc", key.subarray(0, 32), iv);
|
|
133
136
|
return Buffer.concat([decipher.update(ct), decipher.final()]);
|
|
134
137
|
}
|
|
138
|
+
/** Encrypt into a type-2 cipher string with a 64-byte key (32 enc + 32 mac). */
|
|
139
|
+
function encryptCipherString(data, key) {
|
|
140
|
+
const iv = crypto.randomBytes(16);
|
|
141
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", key.subarray(0, 32), iv);
|
|
142
|
+
const ct = Buffer.concat([cipher.update(typeof data === "string" ? Buffer.from(data, "utf8") : data), cipher.final()]);
|
|
143
|
+
const mac = crypto.createHmac("sha256", key.subarray(32, 64)).update(iv).update(ct).digest();
|
|
144
|
+
return `2.${iv.toString("base64")}|${ct.toString("base64")}|${mac.toString("base64")}`;
|
|
145
|
+
}
|
|
135
146
|
function decryptText(value, key) {
|
|
136
147
|
return typeof value === "string" && value.length > 0 ? decryptCipherString(value, key).toString("utf8") : undefined;
|
|
137
148
|
}
|
|
@@ -147,6 +158,7 @@ function decryptSyncItems(sync, userKey) {
|
|
|
147
158
|
if (!Array.isArray(ciphers))
|
|
148
159
|
throw new Error("vault sync returned no item list");
|
|
149
160
|
const items = [];
|
|
161
|
+
const raw = new Map();
|
|
150
162
|
let skipped = 0;
|
|
151
163
|
let unreadable = 0;
|
|
152
164
|
for (const cipher of ciphers) {
|
|
@@ -159,6 +171,7 @@ function decryptSyncItems(sync, userKey) {
|
|
|
159
171
|
const key = itemKeyString ? decryptKey(itemKeyString, userKey, "item key") : userKey;
|
|
160
172
|
const login = field(cipher, "login");
|
|
161
173
|
const uris = field(login, "uris");
|
|
174
|
+
raw.set(String(field(cipher, "id")), cipher);
|
|
162
175
|
items.push({
|
|
163
176
|
id: String(field(cipher, "id")),
|
|
164
177
|
name: decryptText(field(cipher, "name"), key) ?? "",
|
|
@@ -183,8 +196,21 @@ function decryptSyncItems(sync, userKey) {
|
|
|
183
196
|
unreadable += 1;
|
|
184
197
|
}
|
|
185
198
|
}
|
|
186
|
-
return { items, skipped, unreadable };
|
|
199
|
+
return { items, skipped, unreadable, raw };
|
|
200
|
+
}
|
|
201
|
+
/** The user id (`sub`) in a JWT access token, or null when the token is not a JWT. */
|
|
202
|
+
function tokenUserId(accessToken) {
|
|
203
|
+
try {
|
|
204
|
+
const payload = JSON.parse(Buffer.from(accessToken.split(".")[1] ?? "", "base64url").toString("utf8"));
|
|
205
|
+
const sub = field(payload, "sub");
|
|
206
|
+
return typeof sub === "string" && sub.length > 0 ? sub : null;
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
187
211
|
}
|
|
212
|
+
/** The fields of an item that a write keeps as they are: still encrypted, so never decrypted here. */
|
|
213
|
+
const PRESERVED_CIPHER_FIELDS = ["folderId", "favorite", "reprompt", "fields", "passwordHistory"];
|
|
188
214
|
class NativeVaultReader {
|
|
189
215
|
email;
|
|
190
216
|
masterPassword;
|
|
@@ -223,8 +249,8 @@ class NativeVaultReader {
|
|
|
223
249
|
if (sync === null)
|
|
224
250
|
throw new Error("vault sync rejected a fresh access token (HTTP 401)");
|
|
225
251
|
}
|
|
226
|
-
const { items, skipped, unreadable } = decryptSyncItems(sync, session.userKey);
|
|
227
|
-
this.cache = { items, at: this.deps.now() };
|
|
252
|
+
const { items, skipped, unreadable, raw } = decryptSyncItems(sync, session.userKey);
|
|
253
|
+
this.cache = { items, raw, at: this.deps.now() };
|
|
228
254
|
(0, runtime_1.emitNervesEvent)({
|
|
229
255
|
component: "repertoire",
|
|
230
256
|
event: "repertoire.native_vault_sync_end",
|
|
@@ -233,6 +259,80 @@ class NativeVaultReader {
|
|
|
233
259
|
});
|
|
234
260
|
return items;
|
|
235
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Create a login item, or update the item `existingId` names. An update needs that item in the
|
|
264
|
+
* latest sync (read items() first): it keeps the item's own key, folder, favorite, custom fields,
|
|
265
|
+
* password history and other login data exactly as stored, and the server refuses it if the item
|
|
266
|
+
* changed since that sync. Returns the item id. Does not retry, so a lost answer never writes twice.
|
|
267
|
+
*/
|
|
268
|
+
async saveLogin(write, existingId) {
|
|
269
|
+
const existing = existingId === undefined ? undefined : this.cache?.raw.get(existingId);
|
|
270
|
+
if (existingId !== undefined && !existing)
|
|
271
|
+
throw new Error(`vault item ${existingId} is not in the latest sync; read the vault before updating it`);
|
|
272
|
+
(0, runtime_1.emitNervesEvent)({
|
|
273
|
+
component: "repertoire",
|
|
274
|
+
event: "repertoire.native_vault_write_start",
|
|
275
|
+
message: existingId ? "updating a vault item natively" : "creating a vault item natively",
|
|
276
|
+
meta: { email: this.email, update: existingId !== undefined },
|
|
277
|
+
});
|
|
278
|
+
const answer = await this.withSession(async (session) => {
|
|
279
|
+
const itemKeyString = existing ? stringField(existing, "key") : undefined;
|
|
280
|
+
const key = itemKeyString ? decryptKey(itemKeyString, session.userKey, "item key") : session.userKey;
|
|
281
|
+
const login = field(existing, "login");
|
|
282
|
+
const body = {
|
|
283
|
+
...(existing ? Object.fromEntries(PRESERVED_CIPHER_FIELDS.map((name) => [name, field(existing, name) ?? null])) : { folderId: null, favorite: false, reprompt: 0, fields: null, passwordHistory: null }),
|
|
284
|
+
type: 1,
|
|
285
|
+
organizationId: null,
|
|
286
|
+
key: itemKeyString ?? null,
|
|
287
|
+
name: encryptCipherString(write.name, key),
|
|
288
|
+
notes: write.notes === null ? null : encryptCipherString(write.notes, key),
|
|
289
|
+
login: {
|
|
290
|
+
...(login && typeof login === "object" ? login : {}),
|
|
291
|
+
username: encryptCipherString(write.username, key),
|
|
292
|
+
password: encryptCipherString(write.password, key),
|
|
293
|
+
uris: [{ uri: encryptCipherString(write.uri, key), match: null }],
|
|
294
|
+
},
|
|
295
|
+
encryptedFor: session.userId,
|
|
296
|
+
lastKnownRevisionDate: existing ? stringField(existing, "revisionDate") ?? null : null,
|
|
297
|
+
};
|
|
298
|
+
return this.request(existingId ? `/api/ciphers/${encodeURIComponent(existingId)}` : "/api/ciphers", {
|
|
299
|
+
method: existingId ? "PUT" : "POST",
|
|
300
|
+
headers: { authorization: `Bearer ${session.accessToken}`, "content-type": "application/json" },
|
|
301
|
+
body: JSON.stringify(body),
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
this.cache = null;
|
|
305
|
+
if (!ok(answer))
|
|
306
|
+
throw new Error(`vault ${existingId ? "update" : "create"} for ${this.email} failed: HTTP ${answer.status}${serverMessage(answer)}`);
|
|
307
|
+
const id = stringField(readJson(answer), "id");
|
|
308
|
+
if (!id)
|
|
309
|
+
throw new Error(`vault ${existingId ? "update" : "create"} for ${this.email} returned no item id`);
|
|
310
|
+
(0, runtime_1.emitNervesEvent)({
|
|
311
|
+
component: "repertoire",
|
|
312
|
+
event: "repertoire.native_vault_write_end",
|
|
313
|
+
message: "wrote a vault item natively",
|
|
314
|
+
meta: { email: this.email, update: existingId !== undefined },
|
|
315
|
+
});
|
|
316
|
+
return id;
|
|
317
|
+
}
|
|
318
|
+
/** Move an item to the trash, as `bw delete item` does. */
|
|
319
|
+
async deleteItem(id) {
|
|
320
|
+
const answer = await this.withSession((session) => this.request(`/api/ciphers/${encodeURIComponent(id)}/delete`, {
|
|
321
|
+
method: "PUT",
|
|
322
|
+
headers: { authorization: `Bearer ${session.accessToken}` },
|
|
323
|
+
}));
|
|
324
|
+
this.cache = null;
|
|
325
|
+
if (!ok(answer))
|
|
326
|
+
throw new Error(`vault delete for ${this.email} failed: HTTP ${answer.status}${serverMessage(answer)}`);
|
|
327
|
+
}
|
|
328
|
+
/** Run one request with a session, logging in once more if the server rejects the access token. */
|
|
329
|
+
async withSession(send) {
|
|
330
|
+
const answer = await send(await this.ensureSession());
|
|
331
|
+
if (answer.status !== 401)
|
|
332
|
+
return answer;
|
|
333
|
+
this.session = null;
|
|
334
|
+
return send(await this.ensureSession());
|
|
335
|
+
}
|
|
236
336
|
async ensureSession() {
|
|
237
337
|
if (this.session && this.deps.now() < this.session.expiresAt - TOKEN_EXPIRY_MARGIN_MS)
|
|
238
338
|
return this.session;
|
|
@@ -278,7 +378,10 @@ class NativeVaultReader {
|
|
|
278
378
|
throw new Error("vault login returned no access token or user key");
|
|
279
379
|
const expiresIn = Number(field(token, "expires_in"));
|
|
280
380
|
const userKey = decryptKey(protectedKey, keys.stretched, "user key");
|
|
281
|
-
|
|
381
|
+
const userId = tokenUserId(accessToken);
|
|
382
|
+
if (!userId)
|
|
383
|
+
throw new NativeVaultUnsupportedError("an access token without a user id");
|
|
384
|
+
this.session = { accessToken, expiresAt: this.deps.now() + (Number.isFinite(expiresIn) && expiresIn > 0 ? expiresIn : 3600) * 1000, userKey, userId };
|
|
282
385
|
return this.session;
|
|
283
386
|
}
|
|
284
387
|
async deriveKeys() {
|
|
@@ -336,6 +439,12 @@ function readJson(response) {
|
|
|
336
439
|
}
|
|
337
440
|
}
|
|
338
441
|
const ok = (response) => response.status >= 200 && response.status < 300;
|
|
442
|
+
/** The server's own explanation of a refused request, when it gave one. */
|
|
443
|
+
function serverMessage(response) {
|
|
444
|
+
const body = readJson(response);
|
|
445
|
+
const message = stringField(field(body, "errorModel"), "message") ?? stringField(body, "message");
|
|
446
|
+
return message ? ` ${message}` : "";
|
|
447
|
+
}
|
|
339
448
|
const sharedReaders = new Map();
|
|
340
449
|
/** One reader per vault account and secret in a process, so its stores share one login and one sync. */
|
|
341
450
|
function sharedNativeVaultReader(serverUrl, email, masterPassword) {
|
|
@@ -1055,39 +1055,40 @@ class BitwardenCredentialStore {
|
|
|
1055
1055
|
message: `storing credential via bw for ${domain}`,
|
|
1056
1056
|
meta: { domain, backend: "bitwarden" },
|
|
1057
1057
|
});
|
|
1058
|
-
await this.
|
|
1059
|
-
|
|
1058
|
+
if (!(await this.storeNatively(domain, data)))
|
|
1059
|
+
await this.withSessionRetry(async (session) => {
|
|
1060
|
+
if (shouldUseStructuredItemLookup(domain)) {
|
|
1061
|
+
this.structuredItemCache = null;
|
|
1062
|
+
}
|
|
1063
|
+
const existing = await this.findItemByDomain(domain, session);
|
|
1064
|
+
const item = {
|
|
1065
|
+
...(existing ?? {}),
|
|
1066
|
+
type: 1, // Login type
|
|
1067
|
+
name: domain,
|
|
1068
|
+
login: {
|
|
1069
|
+
username: data.username ?? "",
|
|
1070
|
+
password: data.password,
|
|
1071
|
+
uris: [{ uri: `https://${domain}` }],
|
|
1072
|
+
},
|
|
1073
|
+
notes: data.notes ?? null,
|
|
1074
|
+
};
|
|
1075
|
+
const encoded = Buffer.from(JSON.stringify(item)).toString("base64");
|
|
1060
1076
|
this.structuredItemCache = null;
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
let savedItem;
|
|
1077
|
-
if (existing) {
|
|
1078
|
-
const stdout = await this.execBw(["edit", "item", existing.id], session, encoded);
|
|
1079
|
-
const savedItemId = parseBwItemId(stdout) ?? existing.id;
|
|
1080
|
-
savedItem = await this.findItemById(savedItemId, session);
|
|
1081
|
-
}
|
|
1082
|
-
else {
|
|
1083
|
-
const stdout = await this.execBw(["create", "item"], session, encoded);
|
|
1084
|
-
const savedItemId = parseBwItemId(stdout);
|
|
1085
|
-
savedItem = savedItemId
|
|
1086
|
-
? await this.findItemById(savedItemId, session)
|
|
1087
|
-
: await this.findItemByDomain(domain, session);
|
|
1088
|
-
}
|
|
1089
|
-
this.assertStoredCredentialMatches(domain, data, savedItem);
|
|
1090
|
-
});
|
|
1077
|
+
let savedItem;
|
|
1078
|
+
if (existing) {
|
|
1079
|
+
const stdout = await this.execBw(["edit", "item", existing.id], session, encoded);
|
|
1080
|
+
const savedItemId = parseBwItemId(stdout) ?? existing.id;
|
|
1081
|
+
savedItem = await this.findItemById(savedItemId, session);
|
|
1082
|
+
}
|
|
1083
|
+
else {
|
|
1084
|
+
const stdout = await this.execBw(["create", "item"], session, encoded);
|
|
1085
|
+
const savedItemId = parseBwItemId(stdout);
|
|
1086
|
+
savedItem = savedItemId
|
|
1087
|
+
? await this.findItemById(savedItemId, session)
|
|
1088
|
+
: await this.findItemByDomain(domain, session);
|
|
1089
|
+
}
|
|
1090
|
+
this.assertStoredCredentialMatches(domain, data, savedItem);
|
|
1091
|
+
});
|
|
1091
1092
|
this.structuredItemCache = null;
|
|
1092
1093
|
this.nativeReader?.invalidate();
|
|
1093
1094
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -1126,7 +1127,8 @@ class BitwardenCredentialStore {
|
|
|
1126
1127
|
message: `deleting credential via bw for ${domain}`,
|
|
1127
1128
|
meta: { domain, backend: "bitwarden" },
|
|
1128
1129
|
});
|
|
1129
|
-
const
|
|
1130
|
+
const native = await this.deleteNatively(domain);
|
|
1131
|
+
const item = native === null ? await this.withSessionRetry((session) => this.findItemByDomain(domain, session)) : native;
|
|
1130
1132
|
if (!item) {
|
|
1131
1133
|
(0, runtime_1.emitNervesEvent)({
|
|
1132
1134
|
event: "repertoire.bw_credential_delete_end",
|
|
@@ -1136,7 +1138,8 @@ class BitwardenCredentialStore {
|
|
|
1136
1138
|
});
|
|
1137
1139
|
return false;
|
|
1138
1140
|
}
|
|
1139
|
-
|
|
1141
|
+
if (native === null)
|
|
1142
|
+
await this.withSessionRetry((session) => this.execBw(["delete", "item", item.id], session));
|
|
1140
1143
|
this.structuredItemCache = null;
|
|
1141
1144
|
this.nativeReader?.invalidate();
|
|
1142
1145
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -1155,13 +1158,42 @@ class BitwardenCredentialStore {
|
|
|
1155
1158
|
return native.find((item) => item.name === domain) ?? null;
|
|
1156
1159
|
return this.withSessionRetry((session) => this.findItemByDomain(domain, session));
|
|
1157
1160
|
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Write one credential through the native client, reading it back to verify. False when this
|
|
1163
|
+
* vault goes through bw instead (no native client, or one that does not support this vault).
|
|
1164
|
+
*/
|
|
1165
|
+
async storeNatively(domain, data) {
|
|
1166
|
+
return this.withNativeClient(async (client) => {
|
|
1167
|
+
client.invalidate();
|
|
1168
|
+
const existing = (await client.items()).find((item) => item.name === domain);
|
|
1169
|
+
await client.saveLogin({ name: domain, username: data.username ?? "", password: data.password, notes: data.notes ?? null, uri: `https://${domain}` }, existing?.id);
|
|
1170
|
+
const saved = (await client.items()).find((item) => item.name === domain) ?? null;
|
|
1171
|
+
this.assertStoredCredentialMatches(domain, data, saved);
|
|
1172
|
+
return true;
|
|
1173
|
+
}, false);
|
|
1174
|
+
}
|
|
1175
|
+
/** Trash one credential through the native client: the item it trashed, false when there was none, null for bw. */
|
|
1176
|
+
async deleteNatively(domain) {
|
|
1177
|
+
return this.withNativeClient(async (client) => {
|
|
1178
|
+
client.invalidate();
|
|
1179
|
+
const existing = (await client.items()).find((item) => item.name === domain);
|
|
1180
|
+
if (!existing)
|
|
1181
|
+
return false;
|
|
1182
|
+
await client.deleteItem(existing.id);
|
|
1183
|
+
return existing;
|
|
1184
|
+
}, null);
|
|
1185
|
+
}
|
|
1158
1186
|
/** Every item through the native reader, or null when reads go through bw. */
|
|
1159
1187
|
async nativeItems() {
|
|
1188
|
+
return this.withNativeClient((client) => client.items(), null);
|
|
1189
|
+
}
|
|
1190
|
+
/** Run with the native client, or return `viaBw` when this vault goes through bw. */
|
|
1191
|
+
async withNativeClient(operation, viaBw) {
|
|
1160
1192
|
const reader = this.nativeReader;
|
|
1161
1193
|
if (!reader)
|
|
1162
|
-
return
|
|
1194
|
+
return viaBw;
|
|
1163
1195
|
try {
|
|
1164
|
-
return await reader
|
|
1196
|
+
return await operation(reader);
|
|
1165
1197
|
}
|
|
1166
1198
|
catch (error) {
|
|
1167
1199
|
/* v8 ignore next -- defensive: the reader always throws Error instances @preserve */
|
|
@@ -1172,10 +1204,10 @@ class BitwardenCredentialStore {
|
|
|
1172
1204
|
level: "warn",
|
|
1173
1205
|
event: "repertoire.native_vault_fallback",
|
|
1174
1206
|
component: "repertoire",
|
|
1175
|
-
message: "
|
|
1207
|
+
message: "using bw for this vault instead",
|
|
1176
1208
|
meta: { email: this.email, serverUrl: this.serverUrl, reason: err.message },
|
|
1177
1209
|
});
|
|
1178
|
-
return
|
|
1210
|
+
return viaBw;
|
|
1179
1211
|
}
|
|
1180
1212
|
if (isBwInvalidUnlockSecretMessage(err.message))
|
|
1181
1213
|
await this.notifyInvalidUnlockSecret(err);
|
|
@@ -43,6 +43,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
43
43
|
})();
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.createStripeClient = createStripeClient;
|
|
46
|
+
const optional_packages_1 = require("../heart/optional-packages");
|
|
46
47
|
const credential_access_1 = require("./credential-access");
|
|
47
48
|
const runtime_1 = require("../nerves/runtime");
|
|
48
49
|
// ---------------------------------------------------------------------------
|
|
@@ -62,7 +63,7 @@ async function createStripeClient() {
|
|
|
62
63
|
const store = (0, credential_access_1.getCredentialStore)();
|
|
63
64
|
const apiKey = await store.getRawSecret("stripe.com", "restrictedKey");
|
|
64
65
|
// Stripe's SDK is about 10 MB and 185 modules; only agents that issue cards load it.
|
|
65
|
-
const { default: StripeConstructor } = await Promise.resolve().then(() => __importStar(require("stripe")));
|
|
66
|
+
const { default: StripeConstructor } = await (0, optional_packages_1.importOptional)("stripe", "Virtual cards", () => Promise.resolve().then(() => __importStar(require("stripe"))));
|
|
66
67
|
const StripeFactory = StripeConstructor;
|
|
67
68
|
const stripe = new StripeFactory(apiKey);
|
|
68
69
|
return {
|
|
@@ -52,15 +52,17 @@ const runtime_1 = require("../nerves/runtime");
|
|
|
52
52
|
Promise.resolve().then(() => __importStar(require("./mail"))).then(async ({ startMailSenseApp }) => {
|
|
53
53
|
await startMailSenseApp({ agentName });
|
|
54
54
|
})
|
|
55
|
-
.catch((error) => {
|
|
55
|
+
.catch(async (error) => {
|
|
56
|
+
const { describeStartupError } = await Promise.resolve().then(() => __importStar(require("../heart/optional-packages")));
|
|
57
|
+
const detail = describeStartupError(error, "the Mail sense");
|
|
56
58
|
(0, runtime_1.emitNervesEvent)({
|
|
57
59
|
level: "error",
|
|
58
60
|
component: "senses",
|
|
59
61
|
event: "senses.entry_error",
|
|
60
62
|
message: "Mail entrypoint failed",
|
|
61
|
-
meta: { entry: "mail", agentName, error:
|
|
63
|
+
meta: { entry: "mail", agentName, error: detail },
|
|
62
64
|
});
|
|
63
65
|
// eslint-disable-next-line no-console -- fatal startup guard for sense process
|
|
64
|
-
console.error(
|
|
66
|
+
console.error(detail);
|
|
65
67
|
process.exit(1);
|
|
66
68
|
});
|
|
@@ -53,6 +53,7 @@ const identity_1 = require("../../heart/identity");
|
|
|
53
53
|
const reach_channel_1 = require("../../heart/reach-channel");
|
|
54
54
|
const runtime_1 = require("../../nerves/runtime");
|
|
55
55
|
const notice_outbox_1 = require("./notice-outbox");
|
|
56
|
+
const optional_packages_1 = require("../../heart/optional-packages");
|
|
56
57
|
/**
|
|
57
58
|
* The owner notice: after a judged return, the agent's owner hears what happened in one short plain message on their
|
|
58
59
|
* own channel. It is deterministic, written here and sent with no model turn, so the owner hears about every return the
|
|
@@ -277,7 +278,7 @@ function chooseTeamsBot(tenantId, primary, secondary) {
|
|
|
277
278
|
}
|
|
278
279
|
/* v8 ignore start -- the live Teams SDK client; its token and REST calls need a real bot registration @preserve */
|
|
279
280
|
async function liveBotApi(config) {
|
|
280
|
-
const { App } = await Promise.resolve().then(() => __importStar(require("@microsoft/teams.apps")));
|
|
281
|
+
const { App } = await (0, optional_packages_1.importOptional)("@microsoft/teams.apps", "Teams owner notices", () => Promise.resolve().then(() => __importStar(require("@microsoft/teams.apps"))));
|
|
281
282
|
const app = new App({
|
|
282
283
|
clientId: config.clientId,
|
|
283
284
|
...(config.clientSecret ? { clientSecret: config.clientSecret } : {}),
|
|
@@ -61,15 +61,17 @@ Promise.resolve().then(() => __importStar(require("../heart/runtime-credentials"
|
|
|
61
61
|
const { startTeamsApp } = await Promise.resolve().then(() => __importStar(require("./teams")));
|
|
62
62
|
startTeamsApp();
|
|
63
63
|
})
|
|
64
|
-
.catch((error) => {
|
|
64
|
+
.catch(async (error) => {
|
|
65
|
+
const { describeStartupError } = await Promise.resolve().then(() => __importStar(require("../heart/optional-packages")));
|
|
66
|
+
const detail = describeStartupError(error, "the Teams sense");
|
|
65
67
|
(0, runtime_1.emitNervesEvent)({
|
|
66
68
|
level: "error",
|
|
67
69
|
component: "senses",
|
|
68
70
|
event: "senses.entry_error",
|
|
69
71
|
message: "Teams entrypoint failed",
|
|
70
|
-
meta: { entry: "teams", agentName, error:
|
|
72
|
+
meta: { entry: "teams", agentName, error: detail },
|
|
71
73
|
});
|
|
72
74
|
// eslint-disable-next-line no-console -- fatal startup guard for sense process
|
|
73
|
-
console.error(
|
|
75
|
+
console.error(detail);
|
|
74
76
|
process.exit(1);
|
|
75
77
|
});
|