+86
-2
@@ -1096,2 +1096,86 @@ #!/usr/bin/env node | ||
| }; | ||
| var InsecureFileCredentialStore = class { | ||
| filePath; | ||
| constructor(options = {}) { | ||
| this.filePath = credentialPath(options.configDir); | ||
| } | ||
| async read() { | ||
| const value = await readJsonFile(this.filePath); | ||
| return value ? { ...value, storage: "insecure" } : null; | ||
| } | ||
| async save(credential) { | ||
| await writeCredentialFile(this.filePath, { | ||
| ...credential, | ||
| storage: "insecure" | ||
| }); | ||
| } | ||
| async clear() { | ||
| await (0, import_promises4.rm)(this.filePath, { force: true }); | ||
| } | ||
| }; | ||
| var KeyringCredentialStore = class { | ||
| filePath; | ||
| keyring; | ||
| constructor(options = {}) { | ||
| this.filePath = credentialPath(options.configDir); | ||
| this.keyring = options.keyring ?? defaultKeyringAdapter(); | ||
| } | ||
| async read() { | ||
| const metadata = await readJsonFile(this.filePath); | ||
| if (!metadata) return null; | ||
| const apiKey = await this.keyring.getPassword(); | ||
| if (!apiKey) return null; | ||
| return { ...metadata, apiKey, storage: "secure" }; | ||
| } | ||
| async save(credential) { | ||
| await this.keyring.setPassword(credential.apiKey); | ||
| const { apiKey: _apiKey, ...metadata } = credential; | ||
| await writeCredentialFile(this.filePath, { | ||
| ...metadata, | ||
| storage: "secure" | ||
| }); | ||
| } | ||
| async clear() { | ||
| await this.keyring.deletePassword(); | ||
| await (0, import_promises4.rm)(this.filePath, { force: true }); | ||
| } | ||
| }; | ||
| function createCredentialStore(options = {}) { | ||
| if (options.insecure) return new InsecureFileCredentialStore(options); | ||
| return new KeyringCredentialStore(options); | ||
| } | ||
| function defaultKeyringAdapter() { | ||
| const entry = new import_keyring.Entry("dropthis", "default"); | ||
| return { | ||
| getPassword: () => entry.getPassword(), | ||
| setPassword: (value) => entry.setPassword(value), | ||
| deletePassword: () => { | ||
| entry.deletePassword(); | ||
| } | ||
| }; | ||
| } | ||
| function credentialPath(configDir) { | ||
| return (0, import_node_path2.join)( | ||
| configDir ?? (0, import_node_path2.join)((0, import_node_os.homedir)(), ".config", "dropthis"), | ||
| "credentials.json" | ||
| ); | ||
| } | ||
| async function readJsonFile(path) { | ||
| try { | ||
| return JSON.parse(await (0, import_promises4.readFile)(path, "utf8")); | ||
| } catch (error) { | ||
| if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") { | ||
| return null; | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
| async function writeCredentialFile(path, credential) { | ||
| await (0, import_promises4.mkdir)((0, import_node_path2.dirname)(path), { recursive: true }); | ||
| await (0, import_promises4.writeFile)(path, `${JSON.stringify(credential, null, 2)} | ||
| `, { | ||
| mode: 384 | ||
| }); | ||
| await (0, import_promises4.chmod)(path, 384); | ||
| } | ||
@@ -1102,3 +1186,3 @@ // src/program.ts | ||
| const store = options.store ?? new MemoryCredentialStore(); | ||
| program.name("dropthis").description("Publish anything online and get a URL back.").version("0.1.3"); | ||
| program.name("dropthis").description("Publish anything online and get a URL back.").version("0.1.4"); | ||
| program.option("--api-key <key>", "Override API key for this invocation"); | ||
@@ -1424,3 +1508,3 @@ program.option("--api-url <url>", "Override API base URL"); | ||
| // src/cli.ts | ||
| buildProgram().parseAsync(process.argv).catch((error) => { | ||
| buildProgram({ store: createCredentialStore() }).parseAsync(process.argv).catch((error) => { | ||
| console.error(error); | ||
@@ -1427,0 +1511,0 @@ process.exitCode = 1; |
+1
-1
| { | ||
| "name": "dropthis", | ||
| "version": "0.1.3", | ||
| "version": "0.1.4", | ||
| "description": "Official CLI for Dropthis.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is too big to display
Potential vulnerability
Supply chain riskInitial human review suggests the presence of a vulnerability in this package. It is pending further analysis and confirmation.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 3 instances
Potential vulnerability
Supply chain riskInitial human review suggests the presence of a vulnerability in this package. It is pending further analysis and confirmation.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 3 instances
1241554
0.37%23013
0.37%