favacli 0.0.9 → 0.0.10

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.
@@ -0,0 +1,11 @@
1
+ import type { EntryMeta, EntryMetaWithToken } from 'favalib';
2
+ import BaseCommand from './BaseCommand.mjs';
3
+ import formatters from './formatters/index.mjs';
4
+ import { JsonArray } from 'type-fest';
5
+ export type Formatter = (entries: (EntryMeta | EntryMetaWithToken)[]) => JsonArray;
6
+ declare abstract class BaseListOutputCommand extends BaseCommand {
7
+ abstract getList(): EntryMeta[] | EntryMetaWithToken[];
8
+ format: (typeof formatters)[0]["name"] | undefined;
9
+ exec(): Promise<JsonArray>;
10
+ }
11
+ export default BaseListOutputCommand;
@@ -0,0 +1,33 @@
1
+ import { Option } from 'clipanion';
2
+ import BaseCommand from './BaseCommand.mjs';
3
+ import generateEntriesTable from './utils/generateEntriesTable.mjs';
4
+ import formatters from './formatters/index.mjs';
5
+ const formattersMap = new Map(formatters.map((f) => [f.name, f.formatter]));
6
+ class BaseListOutputCommand extends BaseCommand {
7
+ constructor() {
8
+ super(...arguments);
9
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
10
+ this.format = Option.String('--format', {
11
+ description: 'formatter',
12
+ });
13
+ }
14
+ // eslint-disable-next-line @typescript-eslint/require-await
15
+ async exec() {
16
+ let formatter = (json) => json;
17
+ if (this.format) {
18
+ const selectedFormatter = formattersMap.get(this.format);
19
+ if (!selectedFormatter) {
20
+ throw new Error(`Formatter ${this.format} not found`);
21
+ }
22
+ formatter = selectedFormatter;
23
+ }
24
+ const list = this.getList();
25
+ if (list.length === 0) {
26
+ this.context.stdout.write('No entries\n');
27
+ return formatter([]);
28
+ }
29
+ this.output(generateEntriesTable(list));
30
+ return formatter(list);
31
+ }
32
+ }
33
+ export default BaseListOutputCommand;
@@ -1,9 +1,9 @@
1
- import BaseCommand from '../../BaseCommand.mjs';
2
- declare class EntriesListCommand extends BaseCommand {
1
+ import BaseListOutputCommand from '../../BaseListOutputCommand.mjs';
2
+ declare class EntriesListCommand extends BaseListOutputCommand {
3
3
  static paths: string[][];
4
4
  static usage: import("clipanion").Usage;
5
5
  requireTwoFaLib: boolean;
6
6
  withTokens: boolean | undefined;
7
- exec(): Promise<0 | readonly import("type-fest").JsonValue[]>;
7
+ getList(): import("favalib").EntryMeta[];
8
8
  }
9
9
  export default EntriesListCommand;
@@ -1,7 +1,6 @@
1
1
  import { Option } from 'clipanion';
2
- import BaseCommand from '../../BaseCommand.mjs';
3
- import generateEntriesTable from '../../utils/generateEntriesTable.mjs';
4
- class EntriesListCommand extends BaseCommand {
2
+ import BaseListOutputCommand from '../../BaseListOutputCommand.mjs';
3
+ class EntriesListCommand extends BaseListOutputCommand {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.requireTwoFaLib = true;
@@ -10,12 +9,12 @@ class EntriesListCommand extends BaseCommand {
10
9
  });
11
10
  }
12
11
  static { this.paths = [['entries', 'list']]; }
13
- static { this.usage = BaseCommand.Usage({
12
+ static { this.usage = BaseListOutputCommand.Usage({
14
13
  category: 'Entries',
15
14
  description: 'List all stored 2FA entries',
16
15
  details: `
17
16
  This command displays a table of all stored two-factor authentication entries.
18
-
17
+
19
18
  When used with --withTokens, it will also show the current TOTP codes for each entry.
20
19
  `,
21
20
  examples: [
@@ -23,7 +22,7 @@ class EntriesListCommand extends BaseCommand {
23
22
  ['List entries with current TOTP tokens', 'entries list --withTokens'],
24
23
  ],
25
24
  }); }
26
- async exec() {
25
+ getList() {
27
26
  let entries;
28
27
  if (this.withTokens) {
29
28
  entries = this.twoFaLib.vault.listEntriesMetas(true);
@@ -31,12 +30,7 @@ class EntriesListCommand extends BaseCommand {
31
30
  else {
32
31
  entries = this.twoFaLib.vault.listEntriesMetas(false);
33
32
  }
34
- if (entries.length === 0) {
35
- this.context.stdout.write('No entries\n');
36
- return 0;
37
- }
38
- this.output(generateEntriesTable(entries));
39
- return Promise.resolve(entries);
33
+ return entries;
40
34
  }
41
35
  }
42
36
  export default EntriesListCommand;
@@ -1,11 +1,10 @@
1
- import type { JsonArray } from 'type-fest';
2
- import BaseCommand from '../../BaseCommand.mjs';
3
- declare class EntriesSearchCommand extends BaseCommand {
1
+ import BaseListOutputCommand from '../../BaseListOutputCommand.mjs';
2
+ declare class EntriesSearchCommand extends BaseListOutputCommand {
4
3
  static paths: string[][];
5
4
  static usage: import("clipanion").Usage;
6
5
  requireTwoFaLib: boolean;
7
6
  withTokens: boolean | undefined;
8
7
  query: string;
9
- exec(): Promise<JsonArray>;
8
+ getList(): import("favalib").EntryMeta[];
10
9
  }
11
10
  export default EntriesSearchCommand;
@@ -1,7 +1,6 @@
1
1
  import { Option } from 'clipanion';
2
- import BaseCommand from '../../BaseCommand.mjs';
3
- import generateEntriesTable from '../../utils/generateEntriesTable.mjs';
4
- class EntriesSearchCommand extends BaseCommand {
2
+ import BaseListOutputCommand from '../../BaseListOutputCommand.mjs';
3
+ class EntriesSearchCommand extends BaseListOutputCommand {
5
4
  constructor() {
6
5
  super(...arguments);
7
6
  this.requireTwoFaLib = true;
@@ -11,12 +10,12 @@ class EntriesSearchCommand extends BaseCommand {
11
10
  this.query = Option.String({ required: true });
12
11
  }
13
12
  static { this.paths = [['entries', 'search']]; }
14
- static { this.usage = BaseCommand.Usage({
13
+ static { this.usage = BaseListOutputCommand.Usage({
15
14
  category: 'Entries',
16
15
  description: 'Search for stored 2FA entries',
17
16
  details: `
18
17
  This command searches through all stored two-factor authentication entries.
19
-
18
+
20
19
  The search query will match against entry names and issuers.
21
20
  When used with --withTokens, it will also show the current TOTP codes for matching entries.
22
21
  `,
@@ -28,7 +27,7 @@ class EntriesSearchCommand extends BaseCommand {
28
27
  ],
29
28
  ],
30
29
  }); }
31
- async exec() {
30
+ getList() {
32
31
  let filteredEntries;
33
32
  if (this.withTokens) {
34
33
  filteredEntries = this.twoFaLib.vault.searchEntriesMetas(this.query, true);
@@ -36,13 +35,7 @@ class EntriesSearchCommand extends BaseCommand {
36
35
  else {
37
36
  filteredEntries = this.twoFaLib.vault.searchEntriesMetas(this.query, false);
38
37
  }
39
- if (filteredEntries.length === 0) {
40
- this.output('No matching entries found.\n');
41
- return [];
42
- }
43
- const out = generateEntriesTable(filteredEntries);
44
- this.output(out);
45
- return Promise.resolve(filteredEntries);
38
+ return filteredEntries;
46
39
  }
47
40
  }
48
41
  export default EntriesSearchCommand;
@@ -0,0 +1,6 @@
1
+ import { Formatter } from '../BaseListOutputCommand.mjs';
2
+ declare const _default: {
3
+ name: "alfred";
4
+ formatter: Formatter;
5
+ };
6
+ export default _default;
@@ -0,0 +1,6 @@
1
+ const alfredFormatter = (entries) => entries.map((entry) => ({
2
+ title: entry.issuer,
3
+ subtitle: entry.name,
4
+ arg: entry.token?.otp,
5
+ }));
6
+ export default { name: 'alfred', formatter: alfredFormatter };
@@ -0,0 +1,5 @@
1
+ declare const formatters: {
2
+ name: "alfred";
3
+ formatter: import("../BaseListOutputCommand.mjs").Formatter;
4
+ }[];
5
+ export default formatters;
@@ -0,0 +1,3 @@
1
+ import alfredFormatter from './alfred.mjs';
2
+ const formatters = [alfredFormatter];
3
+ export default formatters;
package/build/main.mjs CHANGED
@@ -16,7 +16,7 @@ const [, , ...args] = process.argv;
16
16
  const cli = new Cli({
17
17
  binaryLabel: 'FavaCli',
18
18
  binaryName: `favacli`,
19
- binaryVersion: '0.0.8',
19
+ binaryVersion: '0.0.10',
20
20
  });
21
21
  cli.register(VaultCreateCommand);
22
22
  cli.register(VaultDeleteCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "favacli",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "author": "",