@spoonly/otpm
Advanced tools
+32
-25
| import { a as parseOTPAuthURI, i as getRemainingSeconds, n as generateOTP } from "./src-CAXJf9Vq.mjs"; | ||
| import crypto from "node:crypto"; | ||
| import os from "node:os"; | ||
| import process from "node:process"; | ||
| import { cac } from "cac"; | ||
| import Conf from "conf"; | ||
| import updateNotifier from "update-notifier"; | ||
| import process from "node:process"; | ||
| import { cancel, confirm, intro, isCancel, outro, password, select, text } from "@clack/prompts"; | ||
@@ -19,3 +19,3 @@ import { consola } from "consola"; | ||
| var name = "@spoonly/otpm"; | ||
| var version = "0.0.7"; | ||
| var version = "0.0.8"; | ||
| var package_default = { | ||
@@ -117,4 +117,4 @@ name, | ||
| if (isCancel(uri)) cancelAndExit$4(); | ||
| const parsed$1 = parseOTPAuthURI(uri); | ||
| if (!parsed$1 || !parsed$1.secret) { | ||
| const parsed = parseOTPAuthURI(uri); | ||
| if (!parsed || !parsed.secret) { | ||
| consola.error("Invalid otpauth URI."); | ||
@@ -124,10 +124,10 @@ process.exit(1); | ||
| account = { | ||
| name: parsed$1.name ?? "", | ||
| issuer: parsed$1.issuer ?? "", | ||
| secret: parsed$1.secret, | ||
| type: parsed$1.type ?? "totp", | ||
| algorithm: parsed$1.algorithm ?? "SHA1", | ||
| digits: parsed$1.digits ?? 6, | ||
| period: parsed$1.period ?? 30, | ||
| counter: parsed$1.counter ?? 0 | ||
| name: parsed.name ?? "", | ||
| issuer: parsed.issuer ?? "", | ||
| secret: parsed.secret, | ||
| type: parsed.type ?? "totp", | ||
| algorithm: parsed.algorithm ?? "SHA1", | ||
| digits: parsed.digits ?? 6, | ||
| period: parsed.period ?? 30, | ||
| counter: parsed.counter ?? 0 | ||
| }; | ||
@@ -407,5 +407,5 @@ } else { | ||
| } | ||
| let parsed$1; | ||
| let parsed; | ||
| try { | ||
| parsed$1 = JSON.parse(jsonStr); | ||
| parsed = JSON.parse(jsonStr); | ||
| } catch { | ||
@@ -415,7 +415,7 @@ consola.error("Failed to parse backup content."); | ||
| } | ||
| if (!parsed$1.accounts || typeof parsed$1.accounts !== "object") { | ||
| if (!parsed.accounts || typeof parsed.accounts !== "object") { | ||
| consola.error("Invalid backup format: missing \"accounts\" field."); | ||
| process.exit(1); | ||
| } | ||
| const incoming = Object.keys(parsed$1.accounts); | ||
| const incoming = Object.keys(parsed.accounts); | ||
| if (incoming.length === 0) { | ||
@@ -430,10 +430,10 @@ consola.info("No accounts found in the file."); | ||
| const overwrite = await confirm({ message: "Overwrite existing accounts?" }); | ||
| if (isCancel(overwrite) || !overwrite) for (const k of conflicts) delete parsed$1.accounts[k]; | ||
| if (isCancel(overwrite) || !overwrite) for (const k of conflicts) delete parsed.accounts[k]; | ||
| } | ||
| const merged = { | ||
| ...existing, | ||
| ...parsed$1.accounts | ||
| ...parsed.accounts | ||
| }; | ||
| config$1.set("accounts", merged); | ||
| const imported = Object.keys(parsed$1.accounts).length; | ||
| const imported = Object.keys(parsed.accounts).length; | ||
| consola.success(`Imported ${pc.green(imported)} account(s).`); | ||
@@ -633,4 +633,4 @@ outro("Done!"); | ||
| cli.command("add", "Add a new OTP account").alias("a").action(() => addHandler(config)); | ||
| cli.command("list", "List all accounts with current OTP codes").alias("ls").option("--watch", "Auto-refresh all TOTP codes every second").action((options) => listHandler(config, options)); | ||
| cli.command("generate [account]", "Generate OTP for an account").alias("g").option("--watch", "Auto-refresh TOTP every period").option("--copy", "Copy the OTP code to clipboard").action((account, options) => generateHandler(config, account, options)); | ||
| cli.command("list", "List all accounts with current OTP codes").alias("ls").option("-w, --watch", "Auto-refresh all TOTP codes every second").action((options) => listHandler(config, options)); | ||
| cli.command("generate [account]", "Generate OTP for an account").alias("g").option("-w, --watch", "Auto-refresh TOTP every period").option("-c, --copy", "Copy the OTP code to clipboard").action((account, options) => generateHandler(config, account, options)); | ||
| cli.command("delete [account]", "Delete an OTP account").alias("del").action((account) => deleteHandler(config, account)); | ||
@@ -662,6 +662,13 @@ cli.command("info [account]", "Show detailed info for an account").alias("i").action((account) => infoHandler(config, account)); | ||
| cli.version(version); | ||
| const parsed = cli.parse(); | ||
| if (!cli.matchedCommand && !parsed.options.help && !parsed.options.version) { | ||
| printLogo(); | ||
| cli.outputHelp(); | ||
| try { | ||
| const parsed = cli.parse(); | ||
| if (!cli.matchedCommand && !parsed.options.help && !parsed.options.version) { | ||
| printLogo(); | ||
| cli.outputHelp(); | ||
| } | ||
| } catch (err) { | ||
| const { consola: consola$1 } = await import("consola"); | ||
| consola$1.error(err.message); | ||
| consola$1.info("Run `otpm --help` to see available commands and options."); | ||
| process.exit(1); | ||
| } | ||
@@ -668,0 +675,0 @@ |
+1
-1
| { | ||
| "name": "@spoonly/otpm", | ||
| "type": "module", | ||
| "version": "0.0.7", | ||
| "version": "0.0.8", | ||
| "description": "OTPm is a lightweight and efficient command-line two-factor authentication passcode generator, focusing on the generation and management of TOTP one-time passcodes.", | ||
@@ -6,0 +6,0 @@ "author": "OSpoon <zxin088@gmail.com>", |
31459
0.59%713
0.99%