-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcore.ts
70 lines (60 loc) · 1.8 KB
/
core.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { vault } from "@1password/op-js";
import type { ExtensionContext } from "vscode";
import { commands, window } from "vscode";
import { CLI } from "./cli";
import { COMMANDS, INTERNAL_COMMANDS } from "./constants";
import { Editor } from "./editor";
import { Injection } from "./injection";
import { Items } from "./items";
import { logger } from "./logger";
import { Setup } from "./setup";
import { createOpenOPHandler, OpvsUriHandler } from "./url-utils";
import { patterns } from "./secret-detection/patterns";
export class Core {
public cli: CLI;
private setup: Setup;
public items: Items;
public constructor(public context: ExtensionContext) {
this.context.subscriptions.push(
window.registerUriHandler(new OpvsUriHandler()),
commands.registerCommand(
COMMANDS.OPEN_1PASSWORD,
createOpenOPHandler(this),
),
commands.registerCommand(COMMANDS.OPEN_LOGS, () => logger.show()),
commands.registerCommand(INTERNAL_COMMANDS.AUTHENTICATE, async () =>
this.authenticate(),
),
commands.registerCommand(
COMMANDS.IGNORE_PATTERN,
async (id) => await patterns.disablePattern(id),
),
commands.registerCommand(
COMMANDS.CREATE_CUSTOM_PATTERN,
async () => await patterns.addCustomPattern(),
),
);
this.cli = new CLI();
this.setup = new Setup(this);
this.items = new Items(this);
new Editor(this);
new Injection(this);
void this.setup.configure();
}
private async authenticate(): Promise<void> {
if (await this.cli.isInvalid()) {
return;
}
// Hack to get CLI to prompt for biometrics
await this.cli.execute(() => vault.list(), false);
}
public get accountUuid(): string {
return this.setup.accountUuid;
}
public get accountUrl(): string {
return this.setup.accountUrl;
}
public get vaultId(): string {
return this.setup.vaultId;
}
}