@aigne/secrets 0.1.7-beta → 1.74.0-beta.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/_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 -504
- 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/file.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { parse, stringify } from "yaml";
|
|
4
|
-
import { BaseSecretStore } from "./base.js";
|
|
5
|
-
export class FileStore extends BaseSecretStore {
|
|
6
|
-
filepath;
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super();
|
|
9
|
-
this.filepath = options.filepath;
|
|
10
|
-
}
|
|
11
|
-
async available() {
|
|
12
|
-
try {
|
|
13
|
-
await fs.access(path.dirname(this.filepath));
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async load() {
|
|
21
|
-
try {
|
|
22
|
-
const data = await fs.readFile(this.filepath, "utf-8");
|
|
23
|
-
const parsed = parse(data);
|
|
24
|
-
if (!parsed || typeof parsed !== "object") {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
return parsed;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return {};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async save(data) {
|
|
34
|
-
const yaml = stringify(data);
|
|
35
|
-
await fs.mkdir(path.dirname(this.filepath), { recursive: true });
|
|
36
|
-
await fs.writeFile(this.filepath, yaml, "utf-8");
|
|
37
|
-
}
|
|
38
|
-
async setItem(key, value) {
|
|
39
|
-
if (!(await this.available()))
|
|
40
|
-
throw new Error("File store not available");
|
|
41
|
-
const data = await this.load();
|
|
42
|
-
data[key] = value;
|
|
43
|
-
await this.save(data);
|
|
44
|
-
}
|
|
45
|
-
async getItem(key) {
|
|
46
|
-
if (!(await this.available()))
|
|
47
|
-
return null;
|
|
48
|
-
try {
|
|
49
|
-
const data = await this.load();
|
|
50
|
-
return data[key] || null;
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async deleteItem(key) {
|
|
57
|
-
if (!(await this.available()))
|
|
58
|
-
return false;
|
|
59
|
-
try {
|
|
60
|
-
const data = await this.load();
|
|
61
|
-
if (data[key]) {
|
|
62
|
-
delete data[key];
|
|
63
|
-
await this.save(data);
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async listItems() {
|
|
73
|
-
if (!(await this.available()))
|
|
74
|
-
return null;
|
|
75
|
-
try {
|
|
76
|
-
const data = await this.load();
|
|
77
|
-
const entries = [];
|
|
78
|
-
for (const [host, config] of Object.entries(data)) {
|
|
79
|
-
if (host === "default")
|
|
80
|
-
continue;
|
|
81
|
-
entries.push({ account: host, password: JSON.stringify(config) });
|
|
82
|
-
}
|
|
83
|
-
return entries.length > 0 ? entries : null;
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async listEntries() {
|
|
90
|
-
const list = await this.listItems();
|
|
91
|
-
if (!list)
|
|
92
|
-
return [];
|
|
93
|
-
return list.reduce((acc, c) => {
|
|
94
|
-
if (c.password && c.account) {
|
|
95
|
-
acc.push(this.parseKey(c.password));
|
|
96
|
-
}
|
|
97
|
-
return acc;
|
|
98
|
-
}, []);
|
|
99
|
-
}
|
|
100
|
-
async listMap() {
|
|
101
|
-
const list = await this.listItems();
|
|
102
|
-
if (!list)
|
|
103
|
-
return {};
|
|
104
|
-
return list.reduce((acc, host) => {
|
|
105
|
-
if (host.account && host.password) {
|
|
106
|
-
const parsed = this.parseKey(host.password);
|
|
107
|
-
if (parsed)
|
|
108
|
-
acc[host.account] = parsed;
|
|
109
|
-
}
|
|
110
|
-
return acc;
|
|
111
|
-
}, {});
|
|
112
|
-
}
|
|
113
|
-
async setDefaultItem(value) {
|
|
114
|
-
if (!(await this.available()))
|
|
115
|
-
throw new Error("File store not available");
|
|
116
|
-
const data = await this.load();
|
|
117
|
-
data["default"] = value;
|
|
118
|
-
await this.save(data);
|
|
119
|
-
}
|
|
120
|
-
async getDefaultItem() {
|
|
121
|
-
if (!(await this.available()))
|
|
122
|
-
return null;
|
|
123
|
-
try {
|
|
124
|
-
const data = await this.load();
|
|
125
|
-
return data.default ?? null;
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// ignore
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
async deleteDefaultItem() {
|
|
133
|
-
if (!(await this.available()))
|
|
134
|
-
throw new Error("File store not available");
|
|
135
|
-
const data = await this.load();
|
|
136
|
-
delete data.default;
|
|
137
|
-
await this.save(data);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
export default FileStore;
|
package/lib/esm/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import FileStore from "./file.js";
|
|
2
|
-
import KeyringStore from "./keytar.js";
|
|
3
|
-
import type { ISecretStore, StoreOptions } from "./types.js";
|
|
4
|
-
export * from "./types.js";
|
|
5
|
-
export { FileStore, KeyringStore };
|
|
6
|
-
declare function createSecretStore(options: StoreOptions): Promise<ISecretStore>;
|
|
7
|
-
export default createSecretStore;
|
package/lib/esm/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import FileStore from "./file.js";
|
|
2
|
-
import KeyringStore from "./keytar.js";
|
|
3
|
-
export * from "./types.js";
|
|
4
|
-
export { FileStore, KeyringStore };
|
|
5
|
-
async function createSecretStore(options) {
|
|
6
|
-
if (!options.serviceName) {
|
|
7
|
-
throw new Error("Secret store key is required");
|
|
8
|
-
}
|
|
9
|
-
const keyring = new KeyringStore(options);
|
|
10
|
-
if (await keyring.available()) {
|
|
11
|
-
return keyring;
|
|
12
|
-
}
|
|
13
|
-
const filepath = options.filepath;
|
|
14
|
-
if (!filepath)
|
|
15
|
-
throw new Error("Filepath is required");
|
|
16
|
-
return new FileStore({ filepath });
|
|
17
|
-
}
|
|
18
|
-
export default createSecretStore;
|
package/lib/esm/keytar.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BaseSecretStore } from "./base.js";
|
|
2
|
-
import type { CredentialEntry, ItemInfo, StoreOptions } from "./types.js";
|
|
3
|
-
export declare class KeyringStore extends BaseSecretStore {
|
|
4
|
-
private _impl;
|
|
5
|
-
private serviceName;
|
|
6
|
-
private _forceUnavailable;
|
|
7
|
-
private _environmentChecked;
|
|
8
|
-
private _environmentReady;
|
|
9
|
-
constructor(options: StoreOptions);
|
|
10
|
-
available(): Promise<boolean>;
|
|
11
|
-
setItem(key: string, value: ItemInfo): Promise<any>;
|
|
12
|
-
getItem(key: string): Promise<ItemInfo | null>;
|
|
13
|
-
deleteItem(key: string): Promise<boolean>;
|
|
14
|
-
listItems(): Promise<CredentialEntry[] | null>;
|
|
15
|
-
listEntries(): Promise<ItemInfo[]>;
|
|
16
|
-
listMap(): Promise<Record<string, ItemInfo>>;
|
|
17
|
-
setDefaultItem(value: ItemInfo): Promise<void>;
|
|
18
|
-
getDefaultItem(): Promise<ItemInfo | null>;
|
|
19
|
-
deleteDefaultItem(): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
export default KeyringStore;
|
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
|
-
}
|