Add models.ts

This commit is contained in:
aet 2021-07-05 14:19:04 -04:00
parent 97d938a635
commit 490d289330
3 changed files with 49 additions and 7 deletions

View File

@ -53,6 +53,10 @@ export class OnePasswordFileManager {
invariant(fs.existsSync(this.root), `Profile ${profileName} does not exist.`) 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) { async #readFile(path: string) {
return await this.fs.readFile(resolve(this.root, path), "utf-8") return await this.fs.readFile(resolve(this.root, path), "utf-8")
} }
@ -70,9 +74,10 @@ export class OnePasswordFileManager {
} }
async getBand(name: string) { async getBand(name: string) {
try { const fileName = `band_${name.toUpperCase()}.js`
return await this.#readFile(`band_${name.toUpperCase()}.js`) if (this.#hasFile(fileName)) {
} catch {} return await this.#readFile(fileName)
}
} }
setProfile(profile: string) { setProfile(profile: string) {

39
src/models.ts Normal file
View File

@ -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
}

View File

@ -10,11 +10,9 @@
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"strictBindCallApply": true, "strict": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"stripInternal": true, "stripInternal": true,
"target": "es2020", "target": "esnext",
"esModuleInterop": true "esModuleInterop": true
}, },
"ts-node": { "ts-node": {