@push.rocks/smartsecret 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.
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/index.d.ts +5 -0
- package/dist_ts/index.js +5 -0
- package/dist_ts/smartsecret.backends.base.d.ts +9 -0
- package/dist_ts/smartsecret.backends.base.js +2 -0
- package/dist_ts/smartsecret.backends.file.d.ts +17 -0
- package/dist_ts/smartsecret.backends.file.js +121 -0
- package/dist_ts/smartsecret.backends.linux.d.ts +11 -0
- package/dist_ts/smartsecret.backends.linux.js +106 -0
- package/dist_ts/smartsecret.backends.macos.d.ts +11 -0
- package/dist_ts/smartsecret.backends.macos.js +104 -0
- package/dist_ts/smartsecret.classes.smartsecret.d.ts +17 -0
- package/dist_ts/smartsecret.classes.smartsecret.js +49 -0
- package/dist_ts/smartsecret.plugins.d.ts +6 -0
- package/dist_ts/smartsecret.plugins.js +8 -0
- package/license +21 -0
- package/npmextra.json +44 -0
- package/package.json +58 -0
- package/readme.hints.md +12 -0
- package/readme.md +193 -0
- package/ts/00_commitinfo_data.ts +8 -0
- package/ts/index.ts +5 -0
- package/ts/smartsecret.backends.base.ts +10 -0
- package/ts/smartsecret.backends.file.ts +153 -0
- package/ts/smartsecret.backends.linux.ts +109 -0
- package/ts/smartsecret.backends.macos.ts +107 -0
- package/ts/smartsecret.classes.smartsecret.ts +66 -0
- package/ts/smartsecret.plugins.ts +8 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ISecretBackend, TBackendType } from './smartsecret.backends.base.js';
|
|
2
|
+
import { MacosKeychainBackend } from './smartsecret.backends.macos.js';
|
|
3
|
+
import { LinuxSecretServiceBackend } from './smartsecret.backends.linux.js';
|
|
4
|
+
import { FileEncryptedBackend } from './smartsecret.backends.file.js';
|
|
5
|
+
|
|
6
|
+
export interface ISmartSecretOptions {
|
|
7
|
+
service?: string;
|
|
8
|
+
vaultPath?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class SmartSecret {
|
|
12
|
+
private service: string;
|
|
13
|
+
private vaultPath?: string;
|
|
14
|
+
private backend: ISecretBackend | null = null;
|
|
15
|
+
|
|
16
|
+
constructor(options?: ISmartSecretOptions) {
|
|
17
|
+
this.service = options?.service ?? 'smartsecret';
|
|
18
|
+
this.vaultPath = options?.vaultPath;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private async getBackend(): Promise<ISecretBackend> {
|
|
22
|
+
if (this.backend) return this.backend;
|
|
23
|
+
|
|
24
|
+
const candidates: ISecretBackend[] = [
|
|
25
|
+
new MacosKeychainBackend(this.service),
|
|
26
|
+
new LinuxSecretServiceBackend(this.service),
|
|
27
|
+
new FileEncryptedBackend(this.service, this.vaultPath),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
for (const candidate of candidates) {
|
|
31
|
+
if (await candidate.isAvailable()) {
|
|
32
|
+
this.backend = candidate;
|
|
33
|
+
return this.backend;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// File backend is always available, so we should never reach here
|
|
38
|
+
this.backend = candidates[candidates.length - 1];
|
|
39
|
+
return this.backend;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async setSecret(account: string, secret: string): Promise<void> {
|
|
43
|
+
const backend = await this.getBackend();
|
|
44
|
+
await backend.setSecret(account, secret);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getSecret(account: string): Promise<string | null> {
|
|
48
|
+
const backend = await this.getBackend();
|
|
49
|
+
return backend.getSecret(account);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async deleteSecret(account: string): Promise<boolean> {
|
|
53
|
+
const backend = await this.getBackend();
|
|
54
|
+
return backend.deleteSecret(account);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async listAccounts(): Promise<string[]> {
|
|
58
|
+
const backend = await this.getBackend();
|
|
59
|
+
return backend.listAccounts();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getBackendType(): Promise<TBackendType> {
|
|
63
|
+
const backend = await this.getBackend();
|
|
64
|
+
return backend.backendType;
|
|
65
|
+
}
|
|
66
|
+
}
|