diff --git a/src/fs.ts b/src/fs.ts index 0d3311a..9ea5a4e 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -53,6 +53,10 @@ export class OnePasswordFileManager { invariant(fs.existsSync(this.root), `Profile ${profileName} does not exist.`) } + #hasFile(path: string) { + return this.fs.existsSync(resolve(this.root, path)) + } + async #readFile(path: string) { return await this.fs.readFile(resolve(this.root, path), "utf-8") } @@ -70,9 +74,10 @@ export class OnePasswordFileManager { } async getBand(name: string) { - try { - return await this.#readFile(`band_${name.toUpperCase()}.js`) - } catch {} + const fileName = `band_${name.toUpperCase()}.js` + if (this.#hasFile(fileName)) { + return await this.#readFile(fileName) + } } setProfile(profile: string) { diff --git a/src/models.ts b/src/models.ts new file mode 100644 index 0000000..bc6789a --- /dev/null +++ b/src/models.ts @@ -0,0 +1,39 @@ +import invariant from "tiny-invariant" + +export enum Category { + Login = 1, + CreditCard = 2, + SecureNote = 3, + Identity = 4, + Password = 5, + Tombstone = 99, + SoftwareLicense = 100, + BankAccount = 101, + Database = 102, + DriverLicense = 103, + OutdoorLicense = 104, + Membership = 105, + Passport = 106, + Rewards = 107, + SSN = 108, + Router = 109, + Server = 100, + Email = 111, +} + +export enum FieldType { + Password = "P", + Text = "T", + Email = "E", + Number = "N", + Radio = "R", + Telephone = "TEL", + Checkbox = "C", + URL = "U", +} + +export function getCategory(category: string) { + const int = parseInt(category) + invariant(int in Category, `Invalid category: ${category}`) + return int as Category +} diff --git a/tsconfig.json b/tsconfig.json index de6888f..b041711 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,11 +10,9 @@ "noUnusedLocals": true, "noUnusedParameters": true, "resolveJsonModule": true, - "strictBindCallApply": true, - "strictFunctionTypes": true, - "strictNullChecks": true, + "strict": true, "stripInternal": true, - "target": "es2020", + "target": "esnext", "esModuleInterop": true }, "ts-node": {