@aigne/secrets 0.1.6 → 1.74.0-beta
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/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/base.cjs +21 -0
- package/dist/base.d.cts +20 -0
- package/dist/base.d.cts.map +1 -0
- package/dist/base.d.mts +20 -0
- package/dist/base.d.mts.map +1 -0
- package/dist/base.mjs +21 -0
- package/dist/base.mjs.map +1 -0
- package/dist/file.cjs +125 -0
- package/dist/file.d.cts +23 -0
- package/dist/file.d.cts.map +1 -0
- package/dist/file.d.mts +23 -0
- package/dist/file.d.mts.map +1 -0
- package/dist/file.mjs +123 -0
- package/dist/file.mjs.map +1 -0
- package/dist/index.cjs +19 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +17 -0
- package/dist/index.mjs.map +1 -0
- package/dist/keytar.cjs +117 -0
- package/dist/keytar.d.cts +25 -0
- package/dist/keytar.d.cts.map +1 -0
- package/dist/keytar.d.mts +25 -0
- package/dist/keytar.d.mts.map +1 -0
- package/dist/keytar.mjs +117 -0
- package/dist/keytar.mjs.map +1 -0
- package/dist/types.d.cts +32 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +32 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/util.cjs +52 -0
- package/dist/util.mjs +52 -0
- package/dist/util.mjs.map +1 -0
- package/package.json +28 -37
- package/CHANGELOG.md +0 -493
- package/lib/cjs/base.d.ts +0 -15
- package/lib/cjs/base.js +0 -23
- package/lib/cjs/file.d.ts +0 -19
- package/lib/cjs/file.js +0 -147
- package/lib/cjs/index.d.ts +0 -7
- package/lib/cjs/index.js +0 -39
- package/lib/cjs/keytar.d.ts +0 -21
- package/lib/cjs/keytar.js +0 -186
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/types.d.ts +0 -28
- package/lib/cjs/types.js +0 -2
- package/lib/cjs/util.d.ts +0 -4
- package/lib/cjs/util.js +0 -57
- package/lib/esm/base.d.ts +0 -15
- package/lib/esm/base.js +0 -19
- package/lib/esm/file.d.ts +0 -19
- package/lib/esm/file.js +0 -140
- package/lib/esm/index.d.ts +0 -7
- package/lib/esm/index.js +0 -18
- package/lib/esm/keytar.d.ts +0 -21
- package/lib/esm/keytar.js +0 -149
- package/lib/esm/package.json +0 -3
- package/lib/esm/types.d.ts +0 -28
- package/lib/esm/types.js +0 -1
- package/lib/esm/util.d.ts +0 -4
- package/lib/esm/util.js +0 -54
package/lib/esm/keytar.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { logger } from "@aigne/core/utils/logger.js";
|
|
2
|
-
import { BaseSecretStore } from "./base.js";
|
|
3
|
-
import { isKeyringEnvironmentReady } from "./util.js";
|
|
4
|
-
const DEFAULT_SERVICE_NAME = "-api-key";
|
|
5
|
-
const DEFAULT_ACCOUNT_NAME_FOR_DEFAULT = "default";
|
|
6
|
-
export class KeyringStore extends BaseSecretStore {
|
|
7
|
-
_impl = null;
|
|
8
|
-
serviceName;
|
|
9
|
-
_forceUnavailable;
|
|
10
|
-
_environmentChecked = false;
|
|
11
|
-
_environmentReady = false;
|
|
12
|
-
constructor(options) {
|
|
13
|
-
super();
|
|
14
|
-
const { serviceName, forceKeytarUnavailable = false } = options;
|
|
15
|
-
this.serviceName = `${serviceName}${DEFAULT_SERVICE_NAME}`;
|
|
16
|
-
this._forceUnavailable = !!forceKeytarUnavailable;
|
|
17
|
-
}
|
|
18
|
-
async available() {
|
|
19
|
-
if (this._forceUnavailable)
|
|
20
|
-
return false;
|
|
21
|
-
// Check environment prerequisites before attempting to load the module
|
|
22
|
-
if (!this._environmentChecked) {
|
|
23
|
-
const { ready, reason } = isKeyringEnvironmentReady();
|
|
24
|
-
this._environmentReady = ready;
|
|
25
|
-
if (!ready) {
|
|
26
|
-
logger.warn(`Keyring environment not ready: ${reason}`);
|
|
27
|
-
}
|
|
28
|
-
this._environmentChecked = true;
|
|
29
|
-
}
|
|
30
|
-
if (!this._environmentReady) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
if (!this._impl) {
|
|
35
|
-
const module = await import("@zowe/secrets-for-zowe-sdk");
|
|
36
|
-
this._impl = module.keyring;
|
|
37
|
-
}
|
|
38
|
-
return !!(this._impl &&
|
|
39
|
-
typeof this._impl.getPassword === "function" &&
|
|
40
|
-
typeof this._impl.setPassword === "function" &&
|
|
41
|
-
typeof this._impl.deletePassword === "function");
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
logger.error(`Failed to load keyring: ${error.message}`);
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async setItem(key, value) {
|
|
49
|
-
if (!(await this.available()))
|
|
50
|
-
throw new Error("Keyring not available");
|
|
51
|
-
if (!this._impl)
|
|
52
|
-
throw new Error("Keyring not loaded");
|
|
53
|
-
return this._impl.setPassword(this.serviceName, key, JSON.stringify(value));
|
|
54
|
-
}
|
|
55
|
-
async getItem(key) {
|
|
56
|
-
if (!(await this.available()))
|
|
57
|
-
return null;
|
|
58
|
-
if (!this._impl)
|
|
59
|
-
return null;
|
|
60
|
-
try {
|
|
61
|
-
const v = await this._impl.getPassword(this.serviceName, key);
|
|
62
|
-
if (!v)
|
|
63
|
-
return null;
|
|
64
|
-
return this.parseKey(v);
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async deleteItem(key) {
|
|
71
|
-
if (!(await this.available()))
|
|
72
|
-
return false;
|
|
73
|
-
if (!this._impl)
|
|
74
|
-
return false;
|
|
75
|
-
try {
|
|
76
|
-
const ok = await this._impl.deletePassword(this.serviceName, key);
|
|
77
|
-
return !!ok;
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async listItems() {
|
|
84
|
-
if (!(await this.available()))
|
|
85
|
-
return null;
|
|
86
|
-
if (!this._impl)
|
|
87
|
-
return null;
|
|
88
|
-
try {
|
|
89
|
-
if (typeof this._impl.findCredentials === "function") {
|
|
90
|
-
const list = await this._impl.findCredentials(this.serviceName);
|
|
91
|
-
return Array.isArray(list) && list.length > 0
|
|
92
|
-
? list.filter((c) => c.account !== DEFAULT_ACCOUNT_NAME_FOR_DEFAULT)
|
|
93
|
-
: null;
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async listEntries() {
|
|
102
|
-
const list = await this.listItems();
|
|
103
|
-
if (!list)
|
|
104
|
-
return [];
|
|
105
|
-
return list.reduce((acc, c) => {
|
|
106
|
-
if (c.password) {
|
|
107
|
-
const parsed = this.parseKey(c.password);
|
|
108
|
-
if (parsed)
|
|
109
|
-
acc.push(parsed);
|
|
110
|
-
}
|
|
111
|
-
return acc;
|
|
112
|
-
}, []);
|
|
113
|
-
}
|
|
114
|
-
async listMap() {
|
|
115
|
-
const list = await this.listItems();
|
|
116
|
-
if (!list)
|
|
117
|
-
return {};
|
|
118
|
-
return list.reduce((acc, host) => {
|
|
119
|
-
if (host.account && host.password) {
|
|
120
|
-
const parsed = this.parseKey(host.password);
|
|
121
|
-
if (parsed)
|
|
122
|
-
acc[host.account] = parsed;
|
|
123
|
-
}
|
|
124
|
-
return acc;
|
|
125
|
-
}, {});
|
|
126
|
-
}
|
|
127
|
-
async setDefaultItem(value) {
|
|
128
|
-
if (!(await this.available()))
|
|
129
|
-
throw new Error("Keyring not available");
|
|
130
|
-
if (!this._impl)
|
|
131
|
-
throw new Error("Keyring not loaded");
|
|
132
|
-
return this.setItem(DEFAULT_ACCOUNT_NAME_FOR_DEFAULT, value);
|
|
133
|
-
}
|
|
134
|
-
async getDefaultItem() {
|
|
135
|
-
if (!(await this.available()))
|
|
136
|
-
return null;
|
|
137
|
-
if (!this._impl)
|
|
138
|
-
return null;
|
|
139
|
-
return this.getItem(DEFAULT_ACCOUNT_NAME_FOR_DEFAULT);
|
|
140
|
-
}
|
|
141
|
-
async deleteDefaultItem() {
|
|
142
|
-
if (!(await this.available()))
|
|
143
|
-
throw new Error("Keyring not available");
|
|
144
|
-
if (!this._impl)
|
|
145
|
-
throw new Error("Keyring not loaded");
|
|
146
|
-
await this.deleteItem(DEFAULT_ACCOUNT_NAME_FOR_DEFAULT);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
export default KeyringStore;
|
package/lib/esm/package.json
DELETED
package/lib/esm/types.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export interface CredentialEntry {
|
|
2
|
-
account: string;
|
|
3
|
-
password: string | null;
|
|
4
|
-
}
|
|
5
|
-
export interface GetDefaultOptions {
|
|
6
|
-
fallbackToFirst?: boolean;
|
|
7
|
-
presetIfFallback?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface StoreOptions {
|
|
10
|
-
filepath?: string;
|
|
11
|
-
serviceName: string;
|
|
12
|
-
forceKeytarUnavailable?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export type ItemInfo = {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
17
|
-
export interface ISecretStore {
|
|
18
|
-
available(): Promise<boolean>;
|
|
19
|
-
setItem(key: string, value: ItemInfo): Promise<void>;
|
|
20
|
-
getItem(key: string): Promise<ItemInfo | null>;
|
|
21
|
-
deleteItem(key: string): Promise<boolean>;
|
|
22
|
-
listItems(): Promise<CredentialEntry[] | null>;
|
|
23
|
-
listEntries(): Promise<ItemInfo[]>;
|
|
24
|
-
listMap(): Promise<Record<string, ItemInfo>>;
|
|
25
|
-
setDefaultItem(value: ItemInfo): Promise<void>;
|
|
26
|
-
getDefaultItem(options?: GetDefaultOptions): Promise<ItemInfo | null>;
|
|
27
|
-
deleteDefaultItem(): Promise<void>;
|
|
28
|
-
}
|
package/lib/esm/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/esm/util.d.ts
DELETED
package/lib/esm/util.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
function isWSL() {
|
|
3
|
-
if (process.platform !== "linux")
|
|
4
|
-
return false;
|
|
5
|
-
// env checks
|
|
6
|
-
if (process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP)
|
|
7
|
-
return true;
|
|
8
|
-
try {
|
|
9
|
-
const v = readFileSync("/proc/version", "utf8").toLowerCase();
|
|
10
|
-
if (v.includes("microsoft") || v.includes("wsl"))
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
catch { }
|
|
14
|
-
try {
|
|
15
|
-
const r = readFileSync("/proc/sys/kernel/osrelease", "utf8").toLowerCase();
|
|
16
|
-
if (r.includes("microsoft") || r.includes("wsl"))
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
catch { }
|
|
20
|
-
// some WSL setups have /run/WSL or other hints
|
|
21
|
-
if (existsSync("/run/WSL") || existsSync("/run/WSL/"))
|
|
22
|
-
return true;
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
function isDBusAvailable() {
|
|
26
|
-
return !!process.env.DBUS_SESSION_BUS_ADDRESS;
|
|
27
|
-
}
|
|
28
|
-
function isDisplayAvailable() {
|
|
29
|
-
return !!(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
|
|
30
|
-
}
|
|
31
|
-
export function isKeyringEnvironmentReady() {
|
|
32
|
-
if (process.platform === "win32")
|
|
33
|
-
return { ready: true };
|
|
34
|
-
if (process.platform === "darwin")
|
|
35
|
-
return { ready: true };
|
|
36
|
-
if (process.platform === "linux") {
|
|
37
|
-
if (!process.env.CI) {
|
|
38
|
-
if (isWSL()) {
|
|
39
|
-
return { ready: false, reason: "Detected WSL (no GNOME keyring by default)" };
|
|
40
|
-
}
|
|
41
|
-
// Check for D-Bus (required for libsecret)
|
|
42
|
-
if (!isDBusAvailable()) {
|
|
43
|
-
return { ready: false, reason: "D-Bus not available" };
|
|
44
|
-
}
|
|
45
|
-
// Check for display server (most keyring services need it)
|
|
46
|
-
if (!isDisplayAvailable()) {
|
|
47
|
-
return { ready: false, reason: "Display not available" };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return { ready: true };
|
|
51
|
-
}
|
|
52
|
-
// Unknown platform
|
|
53
|
-
return { ready: false, reason: `Unsupported platform: ${process.platform}` };
|
|
54
|
-
}
|