Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate imports to esm style #249

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"lint": "eslint src",
"format": "prettier --write src && eslint --fix src",
"start": "node dist/index.cjs",
"start:dev": "node build/index.js",
"pkg:linux": "pkg . -t node18-linux-x64 -o bundle/dcli-linux -C GZip --public --public-packages tslib,thirty-two,node-hkdf-sync,vows --no-bytecode",
"pkg:macos": "pkg . -t node18-macos-x64 -o bundle/dcli-macos -C GZip --public --public-packages tslib,thirty-two,node-hkdf-sync,vows --no-bytecode",
"pkg:macos-arm": "pkg . -t node18-macos-arm64 -o bundle/dcli-macos-arm -C GZip --public --public-packages tslib,thirty-two,node-hkdf-sync,vows --no-bytecode",
Expand Down
2 changes: 1 addition & 1 deletion src/cliVersion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CliVersion } from './types';
import { CliVersion } from './types.js';

export const CLI_VERSION: CliVersion = { major: 6, minor: 2421, patch: 0 };
export const breakingChangesVersions: CliVersion[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/command-handlers/backup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import { connectAndPrepare, getDatabasePath } from '../modules/database';
import { logger } from '../logger';
import { connectAndPrepare, getDatabasePath } from '../modules/database/index.js';
import { logger } from '../logger.js';

export const runBackup = async (options: { directory: string; filename: string }) => {
const { db } = await connectAndPrepare({ failIfNoDB: true, forceSync: true });
Expand Down
12 changes: 6 additions & 6 deletions src/command-handlers/configure.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { encryptAesCbcHmac256 } from '../modules/crypto/encrypt';
import { deleteLocalKey, setLocalKey, warnUnreachableKeychainDisabled } from '../modules/crypto/keychainManager';
import { connectAndPrepare } from '../modules/database';
import { parseBooleanString } from '../utils';
import { DeviceConfiguration } from '../types';
import { logger } from '../logger';
import { encryptAesCbcHmac256 } from '../modules/crypto/encrypt.js';
import { deleteLocalKey, setLocalKey, warnUnreachableKeychainDisabled } from '../modules/crypto/keychainManager.js';
import { connectAndPrepare } from '../modules/database/index.js';
import { parseBooleanString } from '../utils/index.js';
import { DeviceConfiguration } from '../types.js';
import { logger } from '../logger.js';

export const configureSaveMasterPassword = async (boolean: string) => {
let shouldNotSaveMasterPassword = !parseBooleanString(boolean);
Expand Down
12 changes: 6 additions & 6 deletions src/command-handlers/devices.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { connectAndPrepare, reset } from '../modules/database';
import { deactivateDevices, listDevices, ListDevicesOutput } from '../endpoints';
import { askConfirmReset, epochTimestampToIso } from '../utils';
import { registerDevice } from '../modules/auth';
import { get2FAStatusUnauthenticated } from '../endpoints/get2FAStatusUnauthenticated';
import { logger } from '../logger';
import { connectAndPrepare, reset } from '../modules/database/index.js';
import { deactivateDevices, listDevices, ListDevicesOutput } from '../endpoints/index.js';
import { askConfirmReset, epochTimestampToIso } from '../utils/index.js';
import { registerDevice } from '../modules/auth/index.js';
import { get2FAStatusUnauthenticated } from '../endpoints/get2FAStatusUnauthenticated.js';
import { logger } from '../logger.js';

type OutputDevice = ListDevicesOutput['devices'][number] & {
isCurrentDevice: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/command-handlers/exec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from 'commander';
import { spawn } from 'child_process';
import { getVaultContent, initVaultContent } from '../modules/database';
import { logger } from '../logger';
import { getVaultContent, initVaultContent } from '../modules/database/index.js';
import { logger } from '../logger.js';

export const runExec = async (_options: unknown, program: Command) => {
const command = program.args.join(' ');
Expand Down
36 changes: 18 additions & 18 deletions src/command-handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export * from './backup';
export * from './configure';
export * from './devices';
export * from './exec';
export * from './inject';
export * from './lock';
export * from './logout';
export * from './passwords';
export * from './read';
export * from './secrets';
export * from './secureNotes';
export * from './sync';
export * from './teamDarkWebInsightsReport';
export * from './teamDevices';
export * from './teamLogs';
export * from './teamMembers';
export * from './teamReport';
export * from './whoami';
export * from './backup.js';
export * from './configure.js';
export * from './devices.js';
export * from './exec.js';
export * from './inject.js';
export * from './lock.js';
export * from './logout.js';
export * from './passwords.js';
export * from './read.js';
export * from './secrets.js';
export * from './secureNotes.js';
export * from './sync.js';
export * from './teamDarkWebInsightsReport.js';
export * from './teamDevices.js';
export * from './teamLogs.js';
export * from './teamMembers.js';
export * from './teamReport.js';
export * from './whoami.js';
4 changes: 2 additions & 2 deletions src/command-handlers/inject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import { getVaultContent, initVaultContent } from '../modules/database';
import { logger } from '../logger';
import { getVaultContent, initVaultContent } from '../modules/database/index.js';
import { logger } from '../logger.js';

interface InjectOpts {
in: string;
Expand Down
4 changes: 2 additions & 2 deletions src/command-handlers/lock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as winston from 'winston';
import { deleteLocalKey } from '../modules/crypto/keychainManager';
import { connectAndPrepare } from '../modules/database';
import { deleteLocalKey } from '../modules/crypto/keychainManager.js';
import { connectAndPrepare } from '../modules/database/index.js';

export const runLock = async () => {
const { db, localConfiguration } = await connectAndPrepare({
Expand Down
10 changes: 5 additions & 5 deletions src/command-handlers/logout.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Database } from 'better-sqlite3';
import { deactivateDevices } from '../endpoints';
import { connectAndPrepare, connect, reset } from '../modules/database';
import { LocalConfiguration, DeviceConfiguration } from '../types';
import { askConfirmReset } from '../utils';
import { logger } from '../logger';
import { deactivateDevices } from '../endpoints/index.js';
import { connectAndPrepare, connect, reset } from '../modules/database/index.js';
import { LocalConfiguration, DeviceConfiguration } from '../types.js';
import { askConfirmReset } from '../utils/index.js';
import { logger } from '../logger.js';

export const runLogout = async (options: { ignoreRevocation: boolean }) => {
if (options.ignoreRevocation) {
Expand Down
15 changes: 10 additions & 5 deletions src/command-handlers/passwords.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import Database from 'better-sqlite3';
import { Clipboard } from '@napi-rs/clipboard';
import { authenticator } from 'otplib';
import { AuthentifiantTransactionContent, BackupEditTransaction, LocalConfiguration, VaultCredential } from '../types';
import { decryptTransactions } from '../modules/crypto';
import { askCredentialChoice, filterMatches } from '../utils';
import { connectAndPrepare } from '../modules/database';
import { logger } from '../logger';
import {
AuthentifiantTransactionContent,
BackupEditTransaction,
LocalConfiguration,
VaultCredential,
} from '../types.js';
import { decryptTransactions } from '../modules/crypto/index.js';
import { askCredentialChoice, filterMatches } from '../utils/index.js';
import { connectAndPrepare } from '../modules/database/index.js';
import { logger } from '../logger.js';

export const runPassword = async (
filters: string[] | null,
Expand Down
10 changes: 5 additions & 5 deletions src/command-handlers/read.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { logger } from '../logger';
import { decryptTransactions } from '../modules/crypto';
import { connectAndPrepare, findVaultContent } from '../modules/database';
import { logger } from '../logger.js';
import { decryptTransactions } from '../modules/crypto/index.js';
import { connectAndPrepare, findVaultContent } from '../modules/database/index.js';
import {
AuthentifiantTransactionContent,
BackupEditTransaction,
SecretTransactionContent,
SecureNoteTransactionContent,
} from '../types';
import { beautifyContent, parsePath } from '../utils';
} from '../types.js';
import { beautifyContent, parsePath } from '../utils/index.js';

export const runRead = async (path: string) => {
const { db, localConfiguration } = await connectAndPrepare({});
Expand Down
10 changes: 5 additions & 5 deletions src/command-handlers/secrets.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Database from 'better-sqlite3';
import { BackupEditTransaction, LocalConfiguration, SecretTransactionContent, VaultSecret } from '../types';
import { decryptTransactions } from '../modules/crypto';
import { askSecretChoice, filterMatches } from '../utils';
import { connectAndPrepare } from '../modules/database';
import { logger } from '../logger';
import { BackupEditTransaction, LocalConfiguration, SecretTransactionContent, VaultSecret } from '../types.js';
import { decryptTransactions } from '../modules/crypto/index.js';
import { askSecretChoice, filterMatches } from '../utils/index.js';
import { connectAndPrepare } from '../modules/database/index.js';
import { logger } from '../logger.js';

export const runSecret = async (filters: string[] | null, options: { output: 'text' | 'json' }) => {
const { db, localConfiguration } = await connectAndPrepare({});
Expand Down
10 changes: 5 additions & 5 deletions src/command-handlers/secureNotes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Database from 'better-sqlite3';
import { BackupEditTransaction, LocalConfiguration, SecureNoteTransactionContent, VaultNote } from '../types';
import { decryptTransactions } from '../modules/crypto';
import { askSecureNoteChoice, filterMatches } from '../utils';
import { connectAndPrepare } from '../modules/database';
import { logger } from '../logger';
import { BackupEditTransaction, LocalConfiguration, SecureNoteTransactionContent, VaultNote } from '../types.js';
import { decryptTransactions } from '../modules/crypto/index.js';
import { askSecureNoteChoice, filterMatches } from '../utils/index.js';
import { connectAndPrepare } from '../modules/database/index.js';
import { logger } from '../logger.js';

export const runSecureNote = async (filters: string[] | null, options: { output: 'text' | 'json' }) => {
const { db, localConfiguration } = await connectAndPrepare({});
Expand Down
18 changes: 9 additions & 9 deletions src/command-handlers/sync.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Database from 'better-sqlite3';
import { connectAndPrepare } from '../modules/database';
import { decrypt } from '../modules/crypto/decrypt';
import { encryptAesCbcHmac256 } from '../modules/crypto/encrypt';
import { replaceMasterPassword } from '../modules/crypto/keychainManager';
import { getLatestContent } from '../endpoints';
import type { DeviceConfiguration, LocalConfiguration } from '../types';
import { notEmpty } from '../utils';
import { askReplaceIncorrectMasterPassword } from '../utils/dialogs';
import { logger } from '../logger';
import { connectAndPrepare } from '../modules/database/index.js';
import { decrypt } from '../modules/crypto/decrypt.js';
import { encryptAesCbcHmac256 } from '../modules/crypto/encrypt.js';
import { replaceMasterPassword } from '../modules/crypto/keychainManager.js';
import { getLatestContent } from '../endpoints/index.js';
import type { DeviceConfiguration, LocalConfiguration } from '../types.js';
import { notEmpty } from '../utils/index.js';
import { askReplaceIncorrectMasterPassword } from '../utils/dialogs.js';
import { logger } from '../logger.js';

export const runSync = async () => {
const { db, localConfiguration, deviceConfiguration } = await connectAndPrepare({ autoSync: false });
Expand Down
6 changes: 3 additions & 3 deletions src/command-handlers/teamDarkWebInsightsReport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getTeamDarkWebInsightsReport } from '../endpoints';
import { logger } from '../logger';
import { getTeamDeviceCredentials } from '../utils';
import { getTeamDarkWebInsightsReport } from '../endpoints/index.js';
import { logger } from '../logger.js';
import { getTeamDeviceCredentials } from '../utils/index.js';

export const runTeamDarkWebInsightsReport = async (
domain: string,
Expand Down
8 changes: 4 additions & 4 deletions src/command-handlers/teamDevices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { connectAndPrepare } from '../modules/database';
import { listTeamDevices, registerTeamDevice } from '../endpoints';
import { epochTimestampToIso } from '../utils';
import { logger } from '../logger';
import { connectAndPrepare } from '../modules/database/index.js';
import { listTeamDevices, registerTeamDevice } from '../endpoints/index.js';
import { epochTimestampToIso } from '../utils/index.js';
import { logger } from '../logger.js';

export const listAllTeamDevices = async (options: { json: boolean }) => {
const { db, localConfiguration } = await connectAndPrepare({ autoSync: false });
Expand Down
8 changes: 4 additions & 4 deletions src/command-handlers/teamLogs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StartAuditLogsQueryParams, startAuditLogsQuery, getAuditLogQueryResults } from '../endpoints';
import { getTeamDeviceCredentials, jsonToCsv, epochTimestampToIso } from '../utils';
import { GenericLog } from '../types/logs';
import { logger } from '../logger';
import { StartAuditLogsQueryParams, startAuditLogsQuery, getAuditLogQueryResults } from '../endpoints/index.js';
import { getTeamDeviceCredentials, jsonToCsv, epochTimestampToIso } from '../utils/index.js';
import { GenericLog } from '../types/logs.js';
import { logger } from '../logger.js';

export const runTeamLogs = async (options: {
start: string;
Expand Down
6 changes: 3 additions & 3 deletions src/command-handlers/teamMembers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getTeamMembers as getTeamMembersRequest } from '../endpoints';
import { logger } from '../logger';
import { getTeamDeviceCredentials, flattenJsonArrayOfObject, jsonToCsv, epochTimestampToIso } from '../utils';
import { getTeamMembers as getTeamMembersRequest } from '../endpoints/index.js';
import { logger } from '../logger.js';
import { getTeamDeviceCredentials, flattenJsonArrayOfObject, jsonToCsv, epochTimestampToIso } from '../utils/index.js';

interface GetTeamMembersOpts {
csv: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/command-handlers/teamReport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getTeamReport as getTeamReportRequest } from '../endpoints';
import { logger } from '../logger';
import { getTeamDeviceCredentials } from '../utils';
import { getTeamReport as getTeamReportRequest } from '../endpoints/index.js';
import { logger } from '../logger.js';
import { getTeamDeviceCredentials } from '../utils/index.js';

interface GetTeamMembersParams {
days: number;
Expand Down
4 changes: 2 additions & 2 deletions src/command-handlers/whoami.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logger } from '../logger';
import { connectAndPrepare } from '../modules/database';
import { logger } from '../logger.js';
import { connectAndPrepare } from '../modules/database/index.js';

export const runWhoami = async (): Promise<void> => {
const { localConfiguration } = await connectAndPrepare({});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from 'commander';
import { runWhoami } from '../command-handlers';
import { runWhoami } from '../command-handlers/index.js';

export const accountsCommands = (params: { program: Command }) => {
const { program } = params;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
configureDisableAutoSync,
configureSaveMasterPassword,
configureUserPresenceVerification,
} from '../command-handlers';
} from '../command-handlers/index.js';

export const configureCommands = (params: { program: Command }) => {
const { program } = params;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/devices.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from 'commander';
import { listAllDevices, registerNonInteractiveDevice, removeAllDevices } from '../command-handlers';
import { listAllDevices, registerNonInteractiveDevice, removeAllDevices } from '../command-handlers/index.js';

export const devicesCommands = (params: { program: Command }) => {
const { program } = params;
Expand Down
10 changes: 5 additions & 5 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Command, Option } from 'commander';
import { devicesCommands } from './devices';
import { teamCommands } from './team';
import { configureCommands } from './configure';
import { accountsCommands } from './accounts';
import { devicesCommands } from './devices.js';
import { teamCommands } from './team/index.js';
import { configureCommands } from './configure.js';
import { accountsCommands } from './accounts.js';
import {
runSync,
runPassword,
Expand All @@ -14,7 +14,7 @@ import {
runExec,
runBackup,
runSecret,
} from '../command-handlers';
} from '../command-handlers/index.js';

export const rootCommands = (params: { program: Command }) => {
const { program } = params;
Expand Down
8 changes: 4 additions & 4 deletions src/commands/team/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Command } from 'commander';
import { createTeamDevice, listAllTeamDevices } from '../../command-handlers';
import { connectAndPrepare } from '../../modules/database';
import { deactivateTeamDevice } from '../../endpoints';
import { logger } from '../../logger';
import { createTeamDevice, listAllTeamDevices } from '../../command-handlers/index.js';
import { connectAndPrepare } from '../../modules/database/index.js';
import { deactivateTeamDevice } from '../../endpoints/index.js';
import { logger } from '../../logger.js';

export const teamCredentialsCommands = (params: { teamGroup: Command }) => {
const { teamGroup } = params;
Expand Down
13 changes: 9 additions & 4 deletions src/commands/team/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Command, Option } from 'commander';
import { teamCredentialsCommands } from './credentials';
import { CouldNotFindTeamCredentialsError } from '../../errors';
import { runTeamDarkWebInsightsReport, runTeamLogs, runTeamMembers, runTeamReport } from '../../command-handlers';
import { customParseInt, customParseTimestampMilliseconds, getTeamDeviceCredentials } from '../../utils';
import { teamCredentialsCommands } from './credentials.js';
import { CouldNotFindTeamCredentialsError } from '../../errors.js';
import {
runTeamDarkWebInsightsReport,
runTeamLogs,
runTeamMembers,
runTeamReport,
} from '../../command-handlers/index.js';
import { customParseInt, customParseTimestampMilliseconds, getTeamDeviceCredentials } from '../../utils/index.js';

export const teamCommands = (params: { program: Command }) => {
const { program } = params;
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/completeDeviceRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CLI_VERSION, cliVersionToString } from '../cliVersion';
import { requestAppApi } from '../requestApi';
import { CLI_VERSION, cliVersionToString } from '../cliVersion.js';
import { requestAppApi } from '../requestApi.js';

interface CompleteDeviceRegistration {
login: string;
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/completeLoginWithAuthTicket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { requestAppApi } from '../requestApi';
import { requestAppApi } from '../requestApi.js';

export interface CompleteLoginWithAuthTicketRequest {
login: string;
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/deactivateDevices.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { requestUserApi } from '../requestApi';
import { LocalConfiguration } from '../types';
import { requestUserApi } from '../requestApi.js';
import { LocalConfiguration } from '../types.js';

interface DeactivateDevicesParams {
localConfiguration: LocalConfiguration;
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/deactivateTeamDevice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LocalConfiguration } from '../types';
import { requestUserApi } from '../requestApi';
import { LocalConfiguration } from '../types.js';
import { requestUserApi } from '../requestApi.js';

export interface DeactivateTeamDeviceParams {
teamDeviceAccessKey: string;
Expand Down
Loading