diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 83e7e640..07679862 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,5 @@ ## Type of change + - [ ] Bug fix - [ ] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) @@ -6,22 +7,22 @@ - [ ] Other ## Objective + - - ## Code changes + -* **file.ext:** Description of what was changed and why +- **file.ext:** Description of what was changed and why ## Testing requirements + - - ## Before you submit + - [ ] I have checked for **linting** errors (`npm run lint`) (required) - [ ] I have added **unit tests** where it makes sense to do so (encouraged but not required) - [ ] This change requires a **documentation update** (notify the documentation team) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ffc8db18..5ee91f8b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,6 @@ jobs: - name: Print lines of code run: cloc --include-lang TypeScript,JavaScript,HTML,Sass,CSS --vcs git - build: name: Build jslib runs-on: ${{ matrix.os }} @@ -33,7 +32,7 @@ jobs: - name: Set up Node uses: actions/setup-node@46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea with: - node-version: '16' + node-version: "16" - name: Install node-gyp run: | @@ -106,7 +105,7 @@ jobs: secrets: "devops-alerts-slack-webhook-url" - name: Notify Slack on failure - uses: act10ns/slack@e4e71685b9b239384b0f676a63c32367f59c2522 # v1.2.2 + uses: act10ns/slack@e4e71685b9b239384b0f676a63c32367f59c2522 # v1.2.2 if: failure() env: SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }} diff --git a/.vscode/launch.json b/.vscode/launch.json index d9b0460f..e43e2c72 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,18 +1,16 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Jasmine Individual Test", - "program": "${workspaceRoot}\\node_modules\\jasmine\\bin\\jasmine.js", - "preLaunchTask": "npm run build", - "args": [ - "${workspaceFolder}/dist\\spec\\node\\services\\nodeCryptoFunction.service.spec.js" - ] - } - ] -} \ No newline at end of file + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jasmine Individual Test", + "program": "${workspaceRoot}\\node_modules\\jasmine\\bin\\jasmine.js", + "preLaunchTask": "npm run build", + "args": ["${workspaceFolder}/dist\\spec\\node\\services\\nodeCryptoFunction.service.spec.js"] + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index db998c99..924fe71b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,12 +1,12 @@ { - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "npm run build", - "type": "shell", - "command": "npm run build" - } - ] -} \ No newline at end of file + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "npm run build", + "type": "shell", + "command": "npm run build" + } + ] +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4f7780a1..5eb19060 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,15 +6,11 @@ Please visit our [Community Forums](https://community.bitwarden.com/) for genera Here is how you can get involved: -* **Request a new feature:** Go to the [Feature Requests category](https://community.bitwarden.com/c/feature-requests/) of the Community Forums. Please search existing feature requests before making a new one - -* **Write code for a new feature:** Make a new post in the [Github Contributions category](https://community.bitwarden.com/c/github-contributions/) of the Community Forums. Include a description of your proposed contribution, screeshots, and links to any relevant feature requests. This helps get feedback from the community and Bitwarden team members before you start writing code - -* **Report a bug or submit a bugfix:** Use Github issues and pull requests - -* **Write documentation:** Submit a pull request to the [Bitwarden help repository](https://github.com/bitwarden/help) - -* **Help other users:** Go to the [User-to-User Support category](https://community.bitwarden.com/c/support/) on the Community Forums +- **Request a new feature:** Go to the [Feature Requests category](https://community.bitwarden.com/c/feature-requests/) of the Community Forums. Please search existing feature requests before making a new one +- **Write code for a new feature:** Make a new post in the [Github Contributions category](https://community.bitwarden.com/c/github-contributions/) of the Community Forums. Include a description of your proposed contribution, screeshots, and links to any relevant feature requests. This helps get feedback from the community and Bitwarden team members before you start writing code +- **Report a bug or submit a bugfix:** Use Github issues and pull requests +- **Write documentation:** Submit a pull request to the [Bitwarden help repository](https://github.com/bitwarden/help) +- **Help other users:** Go to the [User-to-User Support category](https://community.bitwarden.com/c/support/) on the Community Forums ## Contributor Agreement @@ -22,9 +18,9 @@ Please sign the [Contributor Agreement](https://cla-assistant.io/bitwarden/jslib ## Pull Request Guidelines -* use `npm run lint` and fix any linting suggestions before submitting a pull request -* commit any pull requests against the `master` branch -* include a link to your Community Forums post +- use `npm run lint` and fix any linting suggestions before submitting a pull request +- commit any pull requests against the `master` branch +- include a link to your Community Forums post # Introduction to jslib and git submodules @@ -33,36 +29,39 @@ jslib is a repository that contains shared code for all Bitwarden Typescript/Jav If you haven't worked with submodules before, you should start by reading some basic guides (such as the [git scm chapter](https://git-scm.com/book/en/v2/Git-Tools-Submodules) or the [Atlassian tutorial](https://www.atlassian.com/git/tutorials/git-submodule)). # Setting up your Local Dev environment for jslib + In order to easily develop local changes to jslib across each of the TypeScript/JavaScript clients, we recommend using symlinks for the submodule so that you only have to make the change once for it to be reflected across all your local repos. ## Prerequisites + 1. git bash or other git command line 2. In order for this to work well, you need to use a consistent relative directory structure. Repos should be cloned in the following way: - * `./`; we'll call this `/dev` ('cause why not) - * jslib - `git clone https://github.com/bitwarden/jslib.git` (/dev/jslib) - * web - `git clone --recurse-submodules https://github.com/bitwarden/web.git` (/dev/web) - * desktop - `git clone --recurse-submodules https://github.com/bitwarden/desktop.git` (/dev/desktop) - * browser - `git clone --recurse-submodules https://github.com/bitwarden/browser.git` (/dev/browser) - * cli - `git clone --recurse-submodules https://github.com/bitwarden/cli` (/dev/cli) + - `./`; we'll call this `/dev` ('cause why not) + - jslib - `git clone https://github.com/bitwarden/jslib.git` (/dev/jslib) + - web - `git clone --recurse-submodules https://github.com/bitwarden/web.git` (/dev/web) + - desktop - `git clone --recurse-submodules https://github.com/bitwarden/desktop.git` (/dev/desktop) + - browser - `git clone --recurse-submodules https://github.com/bitwarden/browser.git` (/dev/browser) + - cli - `git clone --recurse-submodules https://github.com/bitwarden/cli` (/dev/cli) - You should notice web, desktop, browser and cli each reference jslib as a git submodule. If you've already cloned the repos but didn't use `--recurse-submodules` then you'll need to init the submodule with `npm run sub:init`. + You should notice web, desktop, browser and cli each reference jslib as a git submodule. If you've already cloned the repos but didn't use `--recurse-submodules` then you'll need to init the submodule with `npm run sub:init`. ## Configure Symlinks + Using `git clone` will make symlinks added to your repo be seen by git as plain text file paths. We need to prevent that. In the project root run, `git config core.symlinks true`. For each project other than jslib, run the following: -* For macOS/Linux: `npm run symlink:mac` -* For Windows: `npm run symlink:win` +- For macOS/Linux: `npm run symlink:mac` +- For Windows: `npm run symlink:win` Your client repos will now be pointing to your local jslib repo. You can now make changes in jslib and they will be immediately shared by the clients (just like they will be in production). ## Committing and pushing jslib changes -* You work on jslib like any other repo. Check out a new branch, make some commits, and push to remote when you're ready to submit a PR. -* Do not commit your jslib changes in the client repo. Your changes to the client and your changes to jslib should stay completely separate. -* When submitting a client PR that depends on a jslib PR, please include a link to the jslib PR so that the reviewer knows there are jslib changes. +- You work on jslib like any other repo. Check out a new branch, make some commits, and push to remote when you're ready to submit a PR. +- Do not commit your jslib changes in the client repo. Your changes to the client and your changes to jslib should stay completely separate. +- When submitting a client PR that depends on a jslib PR, please include a link to the jslib PR so that the reviewer knows there are jslib changes. ### Updating jslib on a feature branch @@ -70,8 +69,8 @@ If you've submitted a client PR and a jslib PR, your jslib PR will be approved a 1. If you've symlinked the client's jslib directory following the steps above, you'll need to delete that symlink and then run `npm run sub:init`. 2. Update the jslib submodule: - * if you're working on your own fork, run `git submodule update --remote --reference upstream`. - * if you're working on a branch on the official repo, run `npm run sub:update` + - if you're working on your own fork, run `git submodule update --remote --reference upstream`. + - if you're working on a branch on the official repo, run `npm run sub:update` 3. To check you've done this correctly, you can `cd` into your jslib directory and run `git log`. You should see your recent changes in the log. This will also show you the most recent commit hash, which should match the most recent commit hash on [Github](https://github.com/bitwarden/jslib). 4. Add your changes: `git add jslib` 5. Commit your changes: `git commit -m "update jslib version"` @@ -89,7 +88,8 @@ If you've made changes to jslib without needing to make any changes to the clien 4. Create a new PR to the client repo. Please include a link to your jslib PR so that reviewers know why you're updating jslib. ## Merge Conflicts -At times when you need to perform a `git merge master` into your feature or local branch, and there are conflicting version references to the *jslib* repo from your other clients, you will not be able to use the traditional merge or stage functions you would normally use for a file. + +At times when you need to perform a `git merge master` into your feature or local branch, and there are conflicting version references to the _jslib_ repo from your other clients, you will not be able to use the traditional merge or stage functions you would normally use for a file. To resolve you must use either `git reset` or update the index directly using `git update-index`. You can use (depending on whether you have symlink'd jslib) one of the following: diff --git a/SECURITY.md b/SECURITY.md index ef94f0b4..7a055501 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,7 +7,7 @@ notify us. We welcome working with you to resolve the issue promptly. Thanks in - Let us know as soon as possible upon discovery of a potential security issue, and we'll make every effort to quickly resolve the issue. - Provide us a reasonable amount of time to resolve the issue before any disclosure to the public or a - third-party. We may publicly disclose the issue before resolving it, if appropriate. + third-party. We may publicly disclose the issue before resolving it, if appropriate. - Make a good faith effort to avoid privacy violations, destruction of data, and interruption or degradation of our service. Only interact with accounts you own or with explicit permission of the account holder. diff --git a/angular/src/components/add-edit-custom-fields.component.ts b/angular/src/components/add-edit-custom-fields.component.ts index 71040ac4..4107bc27 100644 --- a/angular/src/components/add-edit-custom-fields.component.ts +++ b/angular/src/components/add-edit-custom-fields.component.ts @@ -1,124 +1,120 @@ -import { - Directive, - Input, - OnChanges, - SimpleChanges, -} from '@angular/core'; +import { Directive, Input, OnChanges, SimpleChanges } from "@angular/core"; -import { - CdkDragDrop, - moveItemInArray, -} from '@angular/cdk/drag-drop'; +import { CdkDragDrop, moveItemInArray } from "@angular/cdk/drag-drop"; -import { EventService } from 'jslib-common/abstractions/event.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { EventService } from "jslib-common/abstractions/event.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { FieldView } from 'jslib-common/models/view/fieldView'; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { FieldView } from "jslib-common/models/view/fieldView"; -import { CipherType } from 'jslib-common/enums/cipherType'; -import { EventType } from 'jslib-common/enums/eventType'; -import { FieldType } from 'jslib-common/enums/fieldType'; +import { CipherType } from "jslib-common/enums/cipherType"; +import { EventType } from "jslib-common/enums/eventType"; +import { FieldType } from "jslib-common/enums/fieldType"; -import { Utils } from 'jslib-common/misc/utils'; +import { Utils } from "jslib-common/misc/utils"; @Directive() export class AddEditCustomFieldsComponent implements OnChanges { - @Input() cipher: CipherView; - @Input() thisCipherType: CipherType; - @Input() editMode: boolean; + @Input() cipher: CipherView; + @Input() thisCipherType: CipherType; + @Input() editMode: boolean; - addFieldType: FieldType = FieldType.Text; - addFieldTypeOptions: any[]; - addFieldLinkedTypeOption: any; - linkedFieldOptions: any[] = []; + addFieldType: FieldType = FieldType.Text; + addFieldTypeOptions: any[]; + addFieldLinkedTypeOption: any; + linkedFieldOptions: any[] = []; - cipherType = CipherType; - fieldType = FieldType; - eventType = EventType; + cipherType = CipherType; + fieldType = FieldType; + eventType = EventType; - constructor(private i18nService: I18nService, private eventService: EventService) { - this.addFieldTypeOptions = [ - { name: i18nService.t('cfTypeText'), value: FieldType.Text }, - { name: i18nService.t('cfTypeHidden'), value: FieldType.Hidden }, - { name: i18nService.t('cfTypeBoolean'), value: FieldType.Boolean }, - ]; - this.addFieldLinkedTypeOption = { name: this.i18nService.t('cfTypeLinked'), value: FieldType.Linked }; + constructor(private i18nService: I18nService, private eventService: EventService) { + this.addFieldTypeOptions = [ + { name: i18nService.t("cfTypeText"), value: FieldType.Text }, + { name: i18nService.t("cfTypeHidden"), value: FieldType.Hidden }, + { name: i18nService.t("cfTypeBoolean"), value: FieldType.Boolean }, + ]; + this.addFieldLinkedTypeOption = { + name: this.i18nService.t("cfTypeLinked"), + value: FieldType.Linked, + }; + } + + ngOnChanges(changes: SimpleChanges) { + if (changes.thisCipherType != null) { + this.setLinkedFieldOptions(); + + if (!changes.thisCipherType.firstChange) { + this.resetCipherLinkedFields(); + } + } + } + + addField() { + if (this.cipher.fields == null) { + this.cipher.fields = []; } - ngOnChanges(changes: SimpleChanges) { - if (changes.thisCipherType != null) { - this.setLinkedFieldOptions(); + const f = new FieldView(); + f.type = this.addFieldType; + f.newField = true; - if (!changes.thisCipherType.firstChange) { - this.resetCipherLinkedFields(); - } - } + if (f.type === FieldType.Linked) { + f.linkedId = this.linkedFieldOptions[0].value; } - addField() { - if (this.cipher.fields == null) { - this.cipher.fields = []; - } + this.cipher.fields.push(f); + } - const f = new FieldView(); - f.type = this.addFieldType; - f.newField = true; + removeField(field: FieldView) { + const i = this.cipher.fields.indexOf(field); + if (i > -1) { + this.cipher.fields.splice(i, 1); + } + } - if (f.type === FieldType.Linked) { - f.linkedId = this.linkedFieldOptions[0].value; - } + toggleFieldValue(field: FieldView) { + const f = field as any; + f.showValue = !f.showValue; + if (this.editMode && f.showValue) { + this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipher.id); + } + } - this.cipher.fields.push(f); + trackByFunction(index: number, item: any) { + return index; + } + + drop(event: CdkDragDrop) { + moveItemInArray(this.cipher.fields, event.previousIndex, event.currentIndex); + } + + private setLinkedFieldOptions() { + if (this.cipher.linkedFieldOptions == null) { + return; } - removeField(field: FieldView) { - const i = this.cipher.fields.indexOf(field); - if (i > -1) { - this.cipher.fields.splice(i, 1); - } + const options: any = []; + this.cipher.linkedFieldOptions.forEach((linkedFieldOption, id) => + options.push({ name: this.i18nService.t(linkedFieldOption.i18nKey), value: id }) + ); + this.linkedFieldOptions = options.sort(Utils.getSortFunction(this.i18nService, "name")); + } + + private resetCipherLinkedFields() { + if (this.cipher.fields == null || this.cipher.fields.length === 0) { + return; } - toggleFieldValue(field: FieldView) { - const f = (field as any); - f.showValue = !f.showValue; - if (this.editMode && f.showValue) { - this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipher.id); - } + // Delete any Linked custom fields if the item type does not support them + if (this.cipher.linkedFieldOptions == null) { + this.cipher.fields = this.cipher.fields.filter((f) => f.type !== FieldType.Linked); + return; } - trackByFunction(index: number, item: any) { - return index; - } - - drop(event: CdkDragDrop) { - moveItemInArray(this.cipher.fields, event.previousIndex, event.currentIndex); - } - - private setLinkedFieldOptions() { - if (this.cipher.linkedFieldOptions == null) { - return; - } - - const options: any = []; - this.cipher.linkedFieldOptions.forEach((linkedFieldOption, id) => - options.push({ name: this.i18nService.t(linkedFieldOption.i18nKey), value: id })); - this.linkedFieldOptions = options.sort(Utils.getSortFunction(this.i18nService, 'name')); - } - - private resetCipherLinkedFields() { - if (this.cipher.fields == null || this.cipher.fields.length === 0) { - return; - } - - // Delete any Linked custom fields if the item type does not support them - if (this.cipher.linkedFieldOptions == null) { - this.cipher.fields = this.cipher.fields.filter(f => f.type !== FieldType.Linked); - return; - } - - this.cipher.fields - .filter(f => f.type === FieldType.Linked) - .forEach(f => f.linkedId = this.linkedFieldOptions[0].value); - } + this.cipher.fields + .filter((f) => f.type === FieldType.Linked) + .forEach((f) => (f.linkedId = this.linkedFieldOptions[0].value)); + } } diff --git a/angular/src/components/callout.component.html b/angular/src/components/callout.component.html index 53fc6647..dbd19df8 100644 --- a/angular/src/components/callout.component.html +++ b/angular/src/components/callout.component.html @@ -1,27 +1,35 @@ -
-

- - {{title}} -

-
- {{enforcedPolicyMessage}} -
    -
  • - {{'policyInEffectMinComplexity' | i18n : getPasswordScoreAlertDisplay()}} -
  • -
  • - {{'policyInEffectMinLength' | i18n : enforcedPolicyOptions?.minLength.toString()}} -
  • -
  • - {{'policyInEffectUppercase' | i18n}}
  • -
  • - {{'policyInEffectLowercase' | i18n}}
  • -
  • - {{'policyInEffectNumbers' | i18n}}
  • -
  • - {{'policyInEffectSpecial' | i18n : '!@#$%^&*'}}
  • -
-
- +
+

+ + {{ title }} +

+
+ {{ enforcedPolicyMessage }} +
    +
  • + {{ "policyInEffectMinComplexity" | i18n: getPasswordScoreAlertDisplay() }} +
  • +
  • + {{ "policyInEffectMinLength" | i18n: enforcedPolicyOptions?.minLength.toString() }} +
  • +
  • + {{ "policyInEffectUppercase" | i18n }} +
  • +
  • + {{ "policyInEffectLowercase" | i18n }} +
  • +
  • + {{ "policyInEffectNumbers" | i18n }} +
  • +
  • + {{ "policyInEffectSpecial" | i18n: "!@#$%^&*" }} +
  • +
+
+
diff --git a/angular/src/components/callout.component.ts b/angular/src/components/callout.component.ts index 566d017a..98105e82 100644 --- a/angular/src/components/callout.component.ts +++ b/angular/src/components/callout.component.ts @@ -1,83 +1,79 @@ -import { - Component, - Input, - OnInit, -} from '@angular/core'; +import { Component, Input, OnInit } from "@angular/core"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; -import { MasterPasswordPolicyOptions } from 'jslib-common/models/domain/masterPasswordPolicyOptions'; +import { MasterPasswordPolicyOptions } from "jslib-common/models/domain/masterPasswordPolicyOptions"; @Component({ - selector: 'app-callout', - templateUrl: 'callout.component.html', + selector: "app-callout", + templateUrl: "callout.component.html", }) export class CalloutComponent implements OnInit { - @Input() type = 'info'; - @Input() icon: string; - @Input() title: string; - @Input() clickable: boolean; - @Input() enforcedPolicyOptions: MasterPasswordPolicyOptions; - @Input() enforcedPolicyMessage: string; - @Input() useAlertRole = false; + @Input() type = "info"; + @Input() icon: string; + @Input() title: string; + @Input() clickable: boolean; + @Input() enforcedPolicyOptions: MasterPasswordPolicyOptions; + @Input() enforcedPolicyMessage: string; + @Input() useAlertRole = false; - calloutStyle: string; + calloutStyle: string; - constructor(private i18nService: I18nService) { } + constructor(private i18nService: I18nService) {} - ngOnInit() { - this.calloutStyle = this.type; + ngOnInit() { + this.calloutStyle = this.type; - if (this.enforcedPolicyMessage === undefined) { - this.enforcedPolicyMessage = this.i18nService.t('masterPasswordPolicyInEffect'); - } - - if (this.type === 'warning' || this.type === 'danger') { - if (this.type === 'danger') { - this.calloutStyle = 'danger'; - } - if (this.title === undefined) { - this.title = this.i18nService.t('warning'); - } - if (this.icon === undefined) { - this.icon = 'fa-warning'; - } - } else if (this.type === 'error') { - this.calloutStyle = 'danger'; - if (this.title === undefined) { - this.title = this.i18nService.t('error'); - } - if (this.icon === undefined) { - this.icon = 'fa-bolt'; - } - } else if (this.type === 'tip') { - this.calloutStyle = 'success'; - if (this.title === undefined) { - this.title = this.i18nService.t('tip'); - } - if (this.icon === undefined) { - this.icon = 'fa-lightbulb-o'; - } - } + if (this.enforcedPolicyMessage === undefined) { + this.enforcedPolicyMessage = this.i18nService.t("masterPasswordPolicyInEffect"); } - getPasswordScoreAlertDisplay() { - if (this.enforcedPolicyOptions == null) { - return ''; - } - - let str: string; - switch (this.enforcedPolicyOptions.minComplexity) { - case 4: - str = this.i18nService.t('strong'); - break; - case 3: - str = this.i18nService.t('good'); - break; - default: - str = this.i18nService.t('weak'); - break; - } - return str + ' (' + this.enforcedPolicyOptions.minComplexity + ')'; + if (this.type === "warning" || this.type === "danger") { + if (this.type === "danger") { + this.calloutStyle = "danger"; + } + if (this.title === undefined) { + this.title = this.i18nService.t("warning"); + } + if (this.icon === undefined) { + this.icon = "fa-warning"; + } + } else if (this.type === "error") { + this.calloutStyle = "danger"; + if (this.title === undefined) { + this.title = this.i18nService.t("error"); + } + if (this.icon === undefined) { + this.icon = "fa-bolt"; + } + } else if (this.type === "tip") { + this.calloutStyle = "success"; + if (this.title === undefined) { + this.title = this.i18nService.t("tip"); + } + if (this.icon === undefined) { + this.icon = "fa-lightbulb-o"; + } } + } + + getPasswordScoreAlertDisplay() { + if (this.enforcedPolicyOptions == null) { + return ""; + } + + let str: string; + switch (this.enforcedPolicyOptions.minComplexity) { + case 4: + str = this.i18nService.t("strong"); + break; + case 3: + str = this.i18nService.t("good"); + break; + default: + str = this.i18nService.t("weak"); + break; + } + return str + " (" + this.enforcedPolicyOptions.minComplexity + ")"; + } } diff --git a/angular/src/components/captchaProtected.component.ts b/angular/src/components/captchaProtected.component.ts index f2c92d0f..d13f7151 100644 --- a/angular/src/components/captchaProtected.component.ts +++ b/angular/src/components/captchaProtected.component.ts @@ -1,47 +1,55 @@ -import { Directive, Input } from '@angular/core'; +import { Directive, Input } from "@angular/core"; -import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { EnvironmentService } from "jslib-common/abstractions/environment.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { CaptchaIFrame } from 'jslib-common/misc/captcha_iframe'; +import { CaptchaIFrame } from "jslib-common/misc/captcha_iframe"; -import { Utils } from 'jslib-common/misc/utils'; +import { Utils } from "jslib-common/misc/utils"; @Directive() export abstract class CaptchaProtectedComponent { - @Input() captchaSiteKey: string = null; - captchaToken: string = null; - captcha: CaptchaIFrame; + @Input() captchaSiteKey: string = null; + captchaToken: string = null; + captcha: CaptchaIFrame; - constructor(protected environmentService: EnvironmentService, protected i18nService: I18nService, - protected platformUtilsService: PlatformUtilsService) { } + constructor( + protected environmentService: EnvironmentService, + protected i18nService: I18nService, + protected platformUtilsService: PlatformUtilsService + ) {} - async setupCaptcha() { - const webVaultUrl = this.environmentService.getWebVaultUrl(); + async setupCaptcha() { + const webVaultUrl = this.environmentService.getWebVaultUrl(); - this.captcha = new CaptchaIFrame(window, webVaultUrl, - this.i18nService, (token: string) => { - this.captchaToken = token; - }, (error: string) => { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), error); - }, (info: string) => { - this.platformUtilsService.showToast('info', this.i18nService.t('info'), info); - } - ); + this.captcha = new CaptchaIFrame( + window, + webVaultUrl, + this.i18nService, + (token: string) => { + this.captchaToken = token; + }, + (error: string) => { + this.platformUtilsService.showToast("error", this.i18nService.t("errorOccurred"), error); + }, + (info: string) => { + this.platformUtilsService.showToast("info", this.i18nService.t("info"), info); + } + ); + } + + showCaptcha() { + return !Utils.isNullOrWhitespace(this.captchaSiteKey); + } + + protected handleCaptchaRequired(response: { captchaSiteKey: string }): boolean { + if (Utils.isNullOrWhitespace(response.captchaSiteKey)) { + return false; } - showCaptcha() { - return !Utils.isNullOrWhitespace(this.captchaSiteKey); - } - - protected handleCaptchaRequired(response: { captchaSiteKey: string; }): boolean { - if (Utils.isNullOrWhitespace(response.captchaSiteKey)) { - return false; - } - - this.captchaSiteKey = response.captchaSiteKey; - this.captcha.init(response.captchaSiteKey); - return true; - } + this.captchaSiteKey = response.captchaSiteKey; + this.captcha.init(response.captchaSiteKey); + return true; + } } diff --git a/angular/src/components/ciphers.component.ts b/angular/src/components/ciphers.component.ts index 092eef22..3f724bb5 100644 --- a/angular/src/components/ciphers.component.ts +++ b/angular/src/components/ciphers.component.ts @@ -1,95 +1,94 @@ -import { - Directive, - EventEmitter, - Input, - Output, -} from '@angular/core'; +import { Directive, EventEmitter, Input, Output } from "@angular/core"; -import { SearchService } from 'jslib-common/abstractions/search.service'; +import { SearchService } from "jslib-common/abstractions/search.service"; -import { CipherView } from 'jslib-common/models/view/cipherView'; +import { CipherView } from "jslib-common/models/view/cipherView"; @Directive() export class CiphersComponent { - @Input() activeCipherId: string = null; - @Output() onCipherClicked = new EventEmitter(); - @Output() onCipherRightClicked = new EventEmitter(); - @Output() onAddCipher = new EventEmitter(); - @Output() onAddCipherOptions = new EventEmitter(); + @Input() activeCipherId: string = null; + @Output() onCipherClicked = new EventEmitter(); + @Output() onCipherRightClicked = new EventEmitter(); + @Output() onAddCipher = new EventEmitter(); + @Output() onAddCipherOptions = new EventEmitter(); - loaded: boolean = false; - ciphers: CipherView[] = []; - searchText: string; - searchPlaceholder: string = null; - filter: (cipher: CipherView) => boolean = null; - deleted: boolean = false; + loaded: boolean = false; + ciphers: CipherView[] = []; + searchText: string; + searchPlaceholder: string = null; + filter: (cipher: CipherView) => boolean = null; + deleted: boolean = false; - protected searchPending = false; + protected searchPending = false; - private searchTimeout: any = null; + private searchTimeout: any = null; - constructor(protected searchService: SearchService) { } + constructor(protected searchService: SearchService) {} - async load(filter: (cipher: CipherView) => boolean = null, deleted: boolean = false) { - this.deleted = deleted || false; - await this.applyFilter(filter); - this.loaded = true; + async load(filter: (cipher: CipherView) => boolean = null, deleted: boolean = false) { + this.deleted = deleted || false; + await this.applyFilter(filter); + this.loaded = true; + } + + async reload(filter: (cipher: CipherView) => boolean = null, deleted: boolean = false) { + this.loaded = false; + this.ciphers = []; + await this.load(filter, deleted); + } + + async refresh() { + await this.reload(this.filter, this.deleted); + } + + async applyFilter(filter: (cipher: CipherView) => boolean = null) { + this.filter = filter; + await this.search(null); + } + + async search(timeout: number = null, indexedCiphers?: CipherView[]) { + this.searchPending = false; + if (this.searchTimeout != null) { + clearTimeout(this.searchTimeout); } - - async reload(filter: (cipher: CipherView) => boolean = null, deleted: boolean = false) { - this.loaded = false; - this.ciphers = []; - await this.load(filter, deleted); + if (timeout == null) { + await this.doSearch(indexedCiphers); + return; } + this.searchPending = true; + this.searchTimeout = setTimeout(async () => { + await this.doSearch(indexedCiphers); + this.searchPending = false; + }, timeout); + } - async refresh() { - await this.reload(this.filter, this.deleted); - } + selectCipher(cipher: CipherView) { + this.onCipherClicked.emit(cipher); + } - async applyFilter(filter: (cipher: CipherView) => boolean = null) { - this.filter = filter; - await this.search(null); - } + rightClickCipher(cipher: CipherView) { + this.onCipherRightClicked.emit(cipher); + } - async search(timeout: number = null, indexedCiphers?: CipherView[]) { - this.searchPending = false; - if (this.searchTimeout != null) { - clearTimeout(this.searchTimeout); - } - if (timeout == null) { - await this.doSearch(indexedCiphers); - return; - } - this.searchPending = true; - this.searchTimeout = setTimeout(async () => { - await this.doSearch(indexedCiphers); - this.searchPending = false; - }, timeout); - } + addCipher() { + this.onAddCipher.emit(); + } - selectCipher(cipher: CipherView) { - this.onCipherClicked.emit(cipher); - } + addCipherOptions() { + this.onAddCipherOptions.emit(); + } - rightClickCipher(cipher: CipherView) { - this.onCipherRightClicked.emit(cipher); - } + isSearching() { + return !this.searchPending && this.searchService.isSearchable(this.searchText); + } - addCipher() { - this.onAddCipher.emit(); - } + protected deletedFilter: (cipher: CipherView) => boolean = (c) => c.isDeleted === this.deleted; - addCipherOptions() { - this.onAddCipherOptions.emit(); - } - - isSearching() { - return !this.searchPending && this.searchService.isSearchable(this.searchText); - } - - protected deletedFilter: (cipher: CipherView) => boolean = c => c.isDeleted === this.deleted; - - protected async doSearch(indexedCiphers?: CipherView[]) { - this.ciphers = await this.searchService.searchCiphers(this.searchText, [this.filter, this.deletedFilter], indexedCiphers); - } + protected async doSearch(indexedCiphers?: CipherView[]) { + this.ciphers = await this.searchService.searchCiphers( + this.searchText, + [this.filter, this.deletedFilter], + indexedCiphers + ); + } } diff --git a/angular/src/components/collections.component.ts b/angular/src/components/collections.component.ts index 29a846c6..8e55f5e2 100644 --- a/angular/src/components/collections.component.ts +++ b/angular/src/components/collections.component.ts @@ -1,90 +1,94 @@ -import { - Directive, - EventEmitter, - Input, - OnInit, - Output, -} from '@angular/core'; +import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core"; -import { CipherService } from 'jslib-common/abstractions/cipher.service'; -import { CollectionService } from 'jslib-common/abstractions/collection.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { LogService } from 'jslib-common/abstractions/log.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { CipherService } from "jslib-common/abstractions/cipher.service"; +import { CollectionService } from "jslib-common/abstractions/collection.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { LogService } from "jslib-common/abstractions/log.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { CollectionView } from 'jslib-common/models/view/collectionView'; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { CollectionView } from "jslib-common/models/view/collectionView"; -import { Cipher } from 'jslib-common/models/domain/cipher'; +import { Cipher } from "jslib-common/models/domain/cipher"; @Directive() export class CollectionsComponent implements OnInit { - @Input() cipherId: string; - @Input() allowSelectNone = false; - @Output() onSavedCollections = new EventEmitter(); + @Input() cipherId: string; + @Input() allowSelectNone = false; + @Output() onSavedCollections = new EventEmitter(); - formPromise: Promise; - cipher: CipherView; - collectionIds: string[]; - collections: CollectionView[] = []; + formPromise: Promise; + cipher: CipherView; + collectionIds: string[]; + collections: CollectionView[] = []; - protected cipherDomain: Cipher; + protected cipherDomain: Cipher; - constructor(protected collectionService: CollectionService, protected platformUtilsService: PlatformUtilsService, - protected i18nService: I18nService, protected cipherService: CipherService, private logService: LogService) { } + constructor( + protected collectionService: CollectionService, + protected platformUtilsService: PlatformUtilsService, + protected i18nService: I18nService, + protected cipherService: CipherService, + private logService: LogService + ) {} - async ngOnInit() { - await this.load(); + async ngOnInit() { + await this.load(); + } + + async load() { + this.cipherDomain = await this.loadCipher(); + this.collectionIds = this.loadCipherCollections(); + this.cipher = await this.cipherDomain.decrypt(); + this.collections = await this.loadCollections(); + + this.collections.forEach((c) => ((c as any).checked = false)); + if (this.collectionIds != null) { + this.collections.forEach((c) => { + (c as any).checked = this.collectionIds != null && this.collectionIds.indexOf(c.id) > -1; + }); } + } - async load() { - this.cipherDomain = await this.loadCipher(); - this.collectionIds = this.loadCipherCollections(); - this.cipher = await this.cipherDomain.decrypt(); - this.collections = await this.loadCollections(); - - this.collections.forEach(c => (c as any).checked = false); - if (this.collectionIds != null) { - this.collections.forEach(c => { - (c as any).checked = this.collectionIds != null && this.collectionIds.indexOf(c.id) > -1; - }); - } + async submit() { + const selectedCollectionIds = this.collections + .filter((c) => !!(c as any).checked) + .map((c) => c.id); + if (!this.allowSelectNone && selectedCollectionIds.length === 0) { + this.platformUtilsService.showToast( + "error", + this.i18nService.t("errorOccurred"), + this.i18nService.t("selectOneCollection") + ); + return; } - - async submit() { - const selectedCollectionIds = this.collections - .filter(c => !!(c as any).checked) - .map(c => c.id); - if (!this.allowSelectNone && selectedCollectionIds.length === 0) { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), - this.i18nService.t('selectOneCollection')); - return; - } - this.cipherDomain.collectionIds = selectedCollectionIds; - try { - this.formPromise = this.saveCollections(); - await this.formPromise; - this.onSavedCollections.emit(); - this.platformUtilsService.showToast('success', null, this.i18nService.t('editedItem')); - } catch (e) { - this.logService.error(e); - } + this.cipherDomain.collectionIds = selectedCollectionIds; + try { + this.formPromise = this.saveCollections(); + await this.formPromise; + this.onSavedCollections.emit(); + this.platformUtilsService.showToast("success", null, this.i18nService.t("editedItem")); + } catch (e) { + this.logService.error(e); } + } - protected loadCipher() { - return this.cipherService.get(this.cipherId); - } + protected loadCipher() { + return this.cipherService.get(this.cipherId); + } - protected loadCipherCollections() { - return this.cipherDomain.collectionIds; - } + protected loadCipherCollections() { + return this.cipherDomain.collectionIds; + } - protected async loadCollections() { - const allCollections = await this.collectionService.getAllDecrypted(); - return allCollections.filter(c => !c.readOnly && c.organizationId === this.cipher.organizationId); - } + protected async loadCollections() { + const allCollections = await this.collectionService.getAllDecrypted(); + return allCollections.filter( + (c) => !c.readOnly && c.organizationId === this.cipher.organizationId + ); + } - protected saveCollections() { - return this.cipherService.saveCollectionsWithServer(this.cipherDomain); - } + protected saveCollections() { + return this.cipherService.saveCollectionsWithServer(this.cipherDomain); + } } diff --git a/angular/src/components/environment.component.ts b/angular/src/components/environment.component.ts index 6b131ba6..8b7689de 100644 --- a/angular/src/components/environment.component.ts +++ b/angular/src/components/environment.component.ts @@ -1,65 +1,63 @@ -import { - Directive, - EventEmitter, - Output, -} from '@angular/core'; +import { Directive, EventEmitter, Output } from "@angular/core"; -import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { EnvironmentService } from "jslib-common/abstractions/environment.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; @Directive() export class EnvironmentComponent { - @Output() onSaved = new EventEmitter(); + @Output() onSaved = new EventEmitter(); - iconsUrl: string; - identityUrl: string; - apiUrl: string; - webVaultUrl: string; - notificationsUrl: string; - baseUrl: string; - showCustom = false; + iconsUrl: string; + identityUrl: string; + apiUrl: string; + webVaultUrl: string; + notificationsUrl: string; + baseUrl: string; + showCustom = false; - constructor(protected platformUtilsService: PlatformUtilsService, protected environmentService: EnvironmentService, - protected i18nService: I18nService) { + constructor( + protected platformUtilsService: PlatformUtilsService, + protected environmentService: EnvironmentService, + protected i18nService: I18nService + ) { + const urls = this.environmentService.getUrls(); - const urls = this.environmentService.getUrls(); + this.baseUrl = urls.base || ""; + this.webVaultUrl = urls.webVault || ""; + this.apiUrl = urls.api || ""; + this.identityUrl = urls.identity || ""; + this.iconsUrl = urls.icons || ""; + this.notificationsUrl = urls.notifications || ""; + } - this.baseUrl = urls.base || ''; - this.webVaultUrl = urls.webVault || ''; - this.apiUrl = urls.api || ''; - this.identityUrl = urls.identity || ''; - this.iconsUrl = urls.icons || ''; - this.notificationsUrl = urls.notifications || ''; - } + async submit() { + const resUrls = await this.environmentService.setUrls({ + base: this.baseUrl, + api: this.apiUrl, + identity: this.identityUrl, + webVault: this.webVaultUrl, + icons: this.iconsUrl, + notifications: this.notificationsUrl, + }); - async submit() { - const resUrls = await this.environmentService.setUrls({ - base: this.baseUrl, - api: this.apiUrl, - identity: this.identityUrl, - webVault: this.webVaultUrl, - icons: this.iconsUrl, - notifications: this.notificationsUrl, - }); + // re-set urls since service can change them, ex: prefixing https:// + this.baseUrl = resUrls.base; + this.apiUrl = resUrls.api; + this.identityUrl = resUrls.identity; + this.webVaultUrl = resUrls.webVault; + this.iconsUrl = resUrls.icons; + this.notificationsUrl = resUrls.notifications; - // re-set urls since service can change them, ex: prefixing https:// - this.baseUrl = resUrls.base; - this.apiUrl = resUrls.api; - this.identityUrl = resUrls.identity; - this.webVaultUrl = resUrls.webVault; - this.iconsUrl = resUrls.icons; - this.notificationsUrl = resUrls.notifications; + this.platformUtilsService.showToast("success", null, this.i18nService.t("environmentSaved")); + this.saved(); + } - this.platformUtilsService.showToast('success', null, this.i18nService.t('environmentSaved')); - this.saved(); - } + toggleCustom() { + this.showCustom = !this.showCustom; + } - toggleCustom() { - this.showCustom = !this.showCustom; - } - - protected saved() { - this.onSaved.emit(); - } + protected saved() { + this.onSaved.emit(); + } } diff --git a/angular/src/components/export.component.ts b/angular/src/components/export.component.ts index 716f9ef0..f3aba8e2 100644 --- a/angular/src/components/export.component.ts +++ b/angular/src/components/export.component.ts @@ -1,140 +1,156 @@ -import { - Directive, - EventEmitter, - OnInit, - Output, -} from '@angular/core'; -import { FormBuilder } from '@angular/forms'; +import { Directive, EventEmitter, OnInit, Output } from "@angular/core"; +import { FormBuilder } from "@angular/forms"; -import { CryptoService } from 'jslib-common/abstractions/crypto.service'; -import { EventService } from 'jslib-common/abstractions/event.service'; -import { ExportService } from 'jslib-common/abstractions/export.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { LogService } from 'jslib-common/abstractions/log.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { PolicyService } from 'jslib-common/abstractions/policy.service'; -import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service'; +import { CryptoService } from "jslib-common/abstractions/crypto.service"; +import { EventService } from "jslib-common/abstractions/event.service"; +import { ExportService } from "jslib-common/abstractions/export.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { LogService } from "jslib-common/abstractions/log.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; +import { PolicyService } from "jslib-common/abstractions/policy.service"; +import { UserVerificationService } from "jslib-common/abstractions/userVerification.service"; -import { EventType } from 'jslib-common/enums/eventType'; -import { PolicyType } from 'jslib-common/enums/policyType'; +import { EventType } from "jslib-common/enums/eventType"; +import { PolicyType } from "jslib-common/enums/policyType"; @Directive() export class ExportComponent implements OnInit { - @Output() onSaved = new EventEmitter(); + @Output() onSaved = new EventEmitter(); - formPromise: Promise; - disabledByPolicy: boolean = false; + formPromise: Promise; + disabledByPolicy: boolean = false; - exportForm = this.fb.group({ - format: ['json'], - secret: [''], - }); + exportForm = this.fb.group({ + format: ["json"], + secret: [""], + }); - formatOptions = [ - { name: '.json', value: 'json' }, - { name: '.csv', value: 'csv' }, - { name: '.json (Encrypted)', value: 'encrypted_json' }, - ]; + formatOptions = [ + { name: ".json", value: "json" }, + { name: ".csv", value: "csv" }, + { name: ".json (Encrypted)", value: "encrypted_json" }, + ]; - constructor(protected cryptoService: CryptoService, protected i18nService: I18nService, - protected platformUtilsService: PlatformUtilsService, protected exportService: ExportService, - protected eventService: EventService, private policyService: PolicyService, protected win: Window, - private logService: LogService, private userVerificationService: UserVerificationService, - private fb: FormBuilder) { } + constructor( + protected cryptoService: CryptoService, + protected i18nService: I18nService, + protected platformUtilsService: PlatformUtilsService, + protected exportService: ExportService, + protected eventService: EventService, + private policyService: PolicyService, + protected win: Window, + private logService: LogService, + private userVerificationService: UserVerificationService, + private fb: FormBuilder + ) {} - async ngOnInit() { - await this.checkExportDisabled(); + async ngOnInit() { + await this.checkExportDisabled(); + } + + async checkExportDisabled() { + this.disabledByPolicy = await this.policyService.policyAppliesToUser( + PolicyType.DisablePersonalVaultExport + ); + if (this.disabledByPolicy) { + this.exportForm.disable(); + } + } + + get encryptedFormat() { + return this.format === "encrypted_json"; + } + + async submit() { + if (this.disabledByPolicy) { + this.platformUtilsService.showToast( + "error", + null, + this.i18nService.t("personalVaultExportPolicyInEffect") + ); + return; } - async checkExportDisabled() { - this.disabledByPolicy = await this.policyService.policyAppliesToUser(PolicyType.DisablePersonalVaultExport); - if (this.disabledByPolicy) { - this.exportForm.disable(); - } + const acceptedWarning = await this.warningDialog(); + if (!acceptedWarning) { + return; } - get encryptedFormat() { - return this.format === 'encrypted_json'; + const secret = this.exportForm.get("secret").value; + try { + await this.userVerificationService.verifyUser(secret); + } catch (e) { + this.platformUtilsService.showToast("error", this.i18nService.t("errorOccurred"), e.message); + return; } - async submit() { - if (this.disabledByPolicy) { - this.platformUtilsService.showToast('error', null, this.i18nService.t('personalVaultExportPolicyInEffect')); - return; - } - - const acceptedWarning = await this.warningDialog(); - if (!acceptedWarning) { - return; - } - - const secret = this.exportForm.get('secret').value; - try { - await this.userVerificationService.verifyUser(secret); - } catch (e) { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), e.message); - return; - } - - try { - this.formPromise = this.getExportData(); - const data = await this.formPromise; - this.downloadFile(data); - this.saved(); - await this.collectEvent(); - this.exportForm.get('secret').setValue(''); - } catch (e) { - this.logService.error(e); - } + try { + this.formPromise = this.getExportData(); + const data = await this.formPromise; + this.downloadFile(data); + this.saved(); + await this.collectEvent(); + this.exportForm.get("secret").setValue(""); + } catch (e) { + this.logService.error(e); } + } - async warningDialog() { - if (this.encryptedFormat) { - return await this.platformUtilsService.showDialog( - '

' + this.i18nService.t('encExportKeyWarningDesc') + - '

' + this.i18nService.t('encExportAccountWarningDesc'), - this.i18nService.t('confirmVaultExport'), this.i18nService.t('exportVault'), - this.i18nService.t('cancel'), 'warning', - true); - } else { - return await this.platformUtilsService.showDialog( - this.i18nService.t('exportWarningDesc'), - this.i18nService.t('confirmVaultExport'), this.i18nService.t('exportVault'), - this.i18nService.t('cancel'), 'warning'); - } + async warningDialog() { + if (this.encryptedFormat) { + return await this.platformUtilsService.showDialog( + "

" + + this.i18nService.t("encExportKeyWarningDesc") + + "

" + + this.i18nService.t("encExportAccountWarningDesc"), + this.i18nService.t("confirmVaultExport"), + this.i18nService.t("exportVault"), + this.i18nService.t("cancel"), + "warning", + true + ); + } else { + return await this.platformUtilsService.showDialog( + this.i18nService.t("exportWarningDesc"), + this.i18nService.t("confirmVaultExport"), + this.i18nService.t("exportVault"), + this.i18nService.t("cancel"), + "warning" + ); } + } - protected saved() { - this.onSaved.emit(); - } + protected saved() { + this.onSaved.emit(); + } - protected getExportData() { - return this.exportService.getExport(this.format); - } + protected getExportData() { + return this.exportService.getExport(this.format); + } - protected getFileName(prefix?: string) { - let extension = this.format; - if (this.format === 'encrypted_json') { - if (prefix == null) { - prefix = 'encrypted'; - } else { - prefix = 'encrypted_' + prefix; - } - extension = 'json'; - } - return this.exportService.getFileName(prefix, extension); + protected getFileName(prefix?: string) { + let extension = this.format; + if (this.format === "encrypted_json") { + if (prefix == null) { + prefix = "encrypted"; + } else { + prefix = "encrypted_" + prefix; + } + extension = "json"; } + return this.exportService.getFileName(prefix, extension); + } - protected async collectEvent(): Promise { - await this.eventService.collect(EventType.User_ClientExportedVault); - } + protected async collectEvent(): Promise { + await this.eventService.collect(EventType.User_ClientExportedVault); + } - get format() { - return this.exportForm.get('format').value; - } + get format() { + return this.exportForm.get("format").value; + } - private downloadFile(csv: string): void { - const fileName = this.getFileName(); - this.platformUtilsService.saveFile(this.win, csv, { type: 'text/plain' }, fileName); - } + private downloadFile(csv: string): void { + const fileName = this.getFileName(); + this.platformUtilsService.saveFile(this.win, csv, { type: "text/plain" }, fileName); + } } diff --git a/angular/src/components/folder-add-edit.component.ts b/angular/src/components/folder-add-edit.component.ts index 554c743f..a3f0707b 100644 --- a/angular/src/components/folder-add-edit.component.ts +++ b/angular/src/components/folder-add-edit.component.ts @@ -1,89 +1,97 @@ -import { - Directive, - EventEmitter, - Input, - OnInit, - Output, -} from '@angular/core'; +import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core"; -import { FolderService } from 'jslib-common/abstractions/folder.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { LogService } from 'jslib-common/abstractions/log.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { FolderService } from "jslib-common/abstractions/folder.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { LogService } from "jslib-common/abstractions/log.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { FolderView } from 'jslib-common/models/view/folderView'; +import { FolderView } from "jslib-common/models/view/folderView"; @Directive() export class FolderAddEditComponent implements OnInit { - @Input() folderId: string; - @Output() onSavedFolder = new EventEmitter(); - @Output() onDeletedFolder = new EventEmitter(); + @Input() folderId: string; + @Output() onSavedFolder = new EventEmitter(); + @Output() onDeletedFolder = new EventEmitter(); - editMode: boolean = false; - folder: FolderView = new FolderView(); - title: string; - formPromise: Promise; - deletePromise: Promise; + editMode: boolean = false; + folder: FolderView = new FolderView(); + title: string; + formPromise: Promise; + deletePromise: Promise; - constructor(protected folderService: FolderService, protected i18nService: I18nService, - protected platformUtilsService: PlatformUtilsService, private logService: LogService) { } + constructor( + protected folderService: FolderService, + protected i18nService: I18nService, + protected platformUtilsService: PlatformUtilsService, + private logService: LogService + ) {} - async ngOnInit() { - await this.init(); + async ngOnInit() { + await this.init(); + } + + async submit(): Promise { + if (this.folder.name == null || this.folder.name === "") { + this.platformUtilsService.showToast( + "error", + this.i18nService.t("errorOccurred"), + this.i18nService.t("nameRequired") + ); + return false; } - async submit(): Promise { - if (this.folder.name == null || this.folder.name === '') { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), - this.i18nService.t('nameRequired')); - return false; - } - - try { - const folder = await this.folderService.encrypt(this.folder); - this.formPromise = this.folderService.saveWithServer(folder); - await this.formPromise; - this.platformUtilsService.showToast('success', null, - this.i18nService.t(this.editMode ? 'editedFolder' : 'addedFolder')); - this.onSavedFolder.emit(this.folder); - return true; - } catch (e) { - this.logService.error(e); - } - - return false; + try { + const folder = await this.folderService.encrypt(this.folder); + this.formPromise = this.folderService.saveWithServer(folder); + await this.formPromise; + this.platformUtilsService.showToast( + "success", + null, + this.i18nService.t(this.editMode ? "editedFolder" : "addedFolder") + ); + this.onSavedFolder.emit(this.folder); + return true; + } catch (e) { + this.logService.error(e); } - async delete(): Promise { - const confirmed = await this.platformUtilsService.showDialog( - this.i18nService.t('deleteFolderConfirmation'), this.i18nService.t('deleteFolder'), - this.i18nService.t('yes'), this.i18nService.t('no'), 'warning'); - if (!confirmed) { - return false; - } + return false; + } - try { - this.deletePromise = this.folderService.deleteWithServer(this.folder.id); - await this.deletePromise; - this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedFolder')); - this.onDeletedFolder.emit(this.folder); - } catch (e) { - this.logService.error(e); - } - - return true; + async delete(): Promise { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t("deleteFolderConfirmation"), + this.i18nService.t("deleteFolder"), + this.i18nService.t("yes"), + this.i18nService.t("no"), + "warning" + ); + if (!confirmed) { + return false; } - protected async init() { - this.editMode = this.folderId != null; - - if (this.editMode) { - this.editMode = true; - this.title = this.i18nService.t('editFolder'); - const folder = await this.folderService.get(this.folderId); - this.folder = await folder.decrypt(); - } else { - this.title = this.i18nService.t('addFolder'); - } + try { + this.deletePromise = this.folderService.deleteWithServer(this.folder.id); + await this.deletePromise; + this.platformUtilsService.showToast("success", null, this.i18nService.t("deletedFolder")); + this.onDeletedFolder.emit(this.folder); + } catch (e) { + this.logService.error(e); } + + return true; + } + + protected async init() { + this.editMode = this.folderId != null; + + if (this.editMode) { + this.editMode = true; + this.title = this.i18nService.t("editFolder"); + const folder = await this.folderService.get(this.folderId); + this.folder = await folder.decrypt(); + } else { + this.title = this.i18nService.t("addFolder"); + } + } } diff --git a/angular/src/components/hint.component.ts b/angular/src/components/hint.component.ts index 8ed7d6ed..9a3d7b2f 100644 --- a/angular/src/components/hint.component.ts +++ b/angular/src/components/hint.component.ts @@ -1,46 +1,56 @@ -import { Router } from '@angular/router'; +import { Router } from "@angular/router"; -import { PasswordHintRequest } from 'jslib-common/models/request/passwordHintRequest'; +import { PasswordHintRequest } from "jslib-common/models/request/passwordHintRequest"; -import { ApiService } from 'jslib-common/abstractions/api.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { LogService } from 'jslib-common/abstractions/log.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { ApiService } from "jslib-common/abstractions/api.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { LogService } from "jslib-common/abstractions/log.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; export class HintComponent { - email: string = ''; - formPromise: Promise; + email: string = ""; + formPromise: Promise; - protected successRoute = 'login'; - protected onSuccessfulSubmit: () => void; + protected successRoute = "login"; + protected onSuccessfulSubmit: () => void; - constructor(protected router: Router, protected i18nService: I18nService, - protected apiService: ApiService, protected platformUtilsService: PlatformUtilsService, - private logService: LogService) { } + constructor( + protected router: Router, + protected i18nService: I18nService, + protected apiService: ApiService, + protected platformUtilsService: PlatformUtilsService, + private logService: LogService + ) {} - async submit() { - if (this.email == null || this.email === '') { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), - this.i18nService.t('emailRequired')); - return; - } - if (this.email.indexOf('@') === -1) { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), - this.i18nService.t('invalidEmail')); - return; - } - - try { - this.formPromise = this.apiService.postPasswordHint(new PasswordHintRequest(this.email)); - await this.formPromise; - this.platformUtilsService.showToast('success', null, this.i18nService.t('masterPassSent')); - if (this.onSuccessfulSubmit != null) { - this.onSuccessfulSubmit(); - } else if (this.router != null) { - this.router.navigate([this.successRoute]); - } - } catch (e) { - this.logService.error(e); - } + async submit() { + if (this.email == null || this.email === "") { + this.platformUtilsService.showToast( + "error", + this.i18nService.t("errorOccurred"), + this.i18nService.t("emailRequired") + ); + return; } + if (this.email.indexOf("@") === -1) { + this.platformUtilsService.showToast( + "error", + this.i18nService.t("errorOccurred"), + this.i18nService.t("invalidEmail") + ); + return; + } + + try { + this.formPromise = this.apiService.postPasswordHint(new PasswordHintRequest(this.email)); + await this.formPromise; + this.platformUtilsService.showToast("success", null, this.i18nService.t("masterPassSent")); + if (this.onSuccessfulSubmit != null) { + this.onSuccessfulSubmit(); + } else if (this.router != null) { + this.router.navigate([this.successRoute]); + } + } catch (e) { + this.logService.error(e); + } + } } diff --git a/angular/src/components/icon.component.html b/angular/src/components/icon.component.html index 00d2c591..878a0ee9 100644 --- a/angular/src/components/icon.component.html +++ b/angular/src/components/icon.component.html @@ -1,4 +1,4 @@

diff --git a/angular/src/components/modal/dynamic-modal.component.ts b/angular/src/components/modal/dynamic-modal.component.ts index 5194a44f..4d529f34 100644 --- a/angular/src/components/modal/dynamic-modal.component.ts +++ b/angular/src/components/modal/dynamic-modal.component.ts @@ -1,76 +1,80 @@ import { - AfterViewInit, - ChangeDetectorRef, - Component, - ComponentRef, - ElementRef, - OnDestroy, - Type, - ViewChild, - ViewContainerRef -} from '@angular/core'; + AfterViewInit, + ChangeDetectorRef, + Component, + ComponentRef, + ElementRef, + OnDestroy, + Type, + ViewChild, + ViewContainerRef, +} from "@angular/core"; -import { - ConfigurableFocusTrap, - ConfigurableFocusTrapFactory, -} from '@angular/cdk/a11y'; +import { ConfigurableFocusTrap, ConfigurableFocusTrapFactory } from "@angular/cdk/a11y"; -import { ModalService } from '../../services/modal.service'; +import { ModalService } from "../../services/modal.service"; -import { ModalRef } from './modal.ref'; +import { ModalRef } from "./modal.ref"; @Component({ - selector: 'app-modal', - template: '', + selector: "app-modal", + template: "", }) export class DynamicModalComponent implements AfterViewInit, OnDestroy { - componentRef: ComponentRef; + componentRef: ComponentRef; - @ViewChild('modalContent', { read: ViewContainerRef, static: true }) modalContentRef: ViewContainerRef; + @ViewChild("modalContent", { read: ViewContainerRef, static: true }) + modalContentRef: ViewContainerRef; - childComponentType: Type; - setComponentParameters: (component: any) => void; + childComponentType: Type; + setComponentParameters: (component: any) => void; - private focusTrap: ConfigurableFocusTrap; + private focusTrap: ConfigurableFocusTrap; - constructor(private modalService: ModalService, private cd: ChangeDetectorRef, - private el: ElementRef, private focusTrapFactory: ConfigurableFocusTrapFactory, - public modalRef: ModalRef) { } + constructor( + private modalService: ModalService, + private cd: ChangeDetectorRef, + private el: ElementRef, + private focusTrapFactory: ConfigurableFocusTrapFactory, + public modalRef: ModalRef + ) {} - ngAfterViewInit() { - this.loadChildComponent(this.childComponentType); - if (this.setComponentParameters != null) { - this.setComponentParameters(this.componentRef.instance); - } - this.cd.detectChanges(); - - this.modalRef.created(this.el.nativeElement); - this.focusTrap = this.focusTrapFactory.create(this.el.nativeElement.querySelector('.modal-dialog')); - if (this.el.nativeElement.querySelector('[appAutoFocus]') == null) { - this.focusTrap.focusFirstTabbableElementWhenReady(); - } + ngAfterViewInit() { + this.loadChildComponent(this.childComponentType); + if (this.setComponentParameters != null) { + this.setComponentParameters(this.componentRef.instance); } + this.cd.detectChanges(); - loadChildComponent(componentType: Type) { - const componentFactory = this.modalService.resolveComponentFactory(componentType); - - this.modalContentRef.clear(); - this.componentRef = this.modalContentRef.createComponent(componentFactory); + this.modalRef.created(this.el.nativeElement); + this.focusTrap = this.focusTrapFactory.create( + this.el.nativeElement.querySelector(".modal-dialog") + ); + if (this.el.nativeElement.querySelector("[appAutoFocus]") == null) { + this.focusTrap.focusFirstTabbableElementWhenReady(); } + } - ngOnDestroy() { - if (this.componentRef) { - this.componentRef.destroy(); - } - this.focusTrap.destroy(); - } + loadChildComponent(componentType: Type) { + const componentFactory = this.modalService.resolveComponentFactory(componentType); - close() { - this.modalRef.close(); - } + this.modalContentRef.clear(); + this.componentRef = this.modalContentRef.createComponent(componentFactory); + } - getFocus() { - const autoFocusEl = this.el.nativeElement.querySelector('[appAutoFocus]') as HTMLElement; - autoFocusEl?.focus(); + ngOnDestroy() { + if (this.componentRef) { + this.componentRef.destroy(); } + this.focusTrap.destroy(); + } + + close() { + this.modalRef.close(); + } + + getFocus() { + const autoFocusEl = this.el.nativeElement.querySelector("[appAutoFocus]") as HTMLElement; + autoFocusEl?.focus(); + } } diff --git a/angular/src/components/modal/modal-injector.ts b/angular/src/components/modal/modal-injector.ts index 8477608e..188e5584 100644 --- a/angular/src/components/modal/modal-injector.ts +++ b/angular/src/components/modal/modal-injector.ts @@ -1,15 +1,10 @@ -import { - InjectFlags, - InjectionToken, - Injector, - Type -} from '@angular/core'; +import { InjectFlags, InjectionToken, Injector, Type } from "@angular/core"; export class ModalInjector implements Injector { - constructor(private _parentInjector: Injector, private _additionalTokens: WeakMap) {} + constructor(private _parentInjector: Injector, private _additionalTokens: WeakMap) {} - get(token: Type | InjectionToken, notFoundValue?: T, flags?: InjectFlags): T; - get(token: any, notFoundValue?: any, flags?: any) { - return this._additionalTokens.get(token) ?? this._parentInjector.get(token, notFoundValue); - } + get(token: Type | InjectionToken, notFoundValue?: T, flags?: InjectFlags): T; + get(token: any, notFoundValue?: any, flags?: any) { + return this._additionalTokens.get(token) ?? this._parentInjector.get(token, notFoundValue); + } } diff --git a/angular/src/components/password-generator-history.component.ts b/angular/src/components/password-generator-history.component.ts index 67adba56..00f73a9f 100644 --- a/angular/src/components/password-generator-history.component.ts +++ b/angular/src/components/password-generator-history.component.ts @@ -1,32 +1,38 @@ -import { Directive, OnInit } from '@angular/core'; +import { Directive, OnInit } from "@angular/core"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { GeneratedPasswordHistory } from 'jslib-common/models/domain/generatedPasswordHistory'; +import { GeneratedPasswordHistory } from "jslib-common/models/domain/generatedPasswordHistory"; @Directive() export class PasswordGeneratorHistoryComponent implements OnInit { - history: GeneratedPasswordHistory[] = []; + history: GeneratedPasswordHistory[] = []; - constructor(protected passwordGenerationService: PasswordGenerationService, - protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, - private win: Window) { } + constructor( + protected passwordGenerationService: PasswordGenerationService, + protected platformUtilsService: PlatformUtilsService, + protected i18nService: I18nService, + private win: Window + ) {} - async ngOnInit() { - this.history = await this.passwordGenerationService.getHistory(); - } + async ngOnInit() { + this.history = await this.passwordGenerationService.getHistory(); + } - clear() { - this.history = []; - this.passwordGenerationService.clear(); - } + clear() { + this.history = []; + this.passwordGenerationService.clear(); + } - copy(password: string) { - const copyOptions = this.win != null ? { window: this.win } : null; - this.platformUtilsService.copyToClipboard(password, copyOptions); - this.platformUtilsService.showToast('info', null, - this.i18nService.t('valueCopied', this.i18nService.t('password'))); - } + copy(password: string) { + const copyOptions = this.win != null ? { window: this.win } : null; + this.platformUtilsService.copyToClipboard(password, copyOptions); + this.platformUtilsService.showToast( + "info", + null, + this.i18nService.t("valueCopied", this.i18nService.t("password")) + ); + } } diff --git a/angular/src/components/password-generator.component.ts b/angular/src/components/password-generator.component.ts index 6e5a389a..b46cda43 100644 --- a/angular/src/components/password-generator.component.ts +++ b/angular/src/components/password-generator.component.ts @@ -1,101 +1,106 @@ -import { - Directive, - EventEmitter, - Input, - OnInit, - Output, -} from '@angular/core'; +import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { PasswordGeneratorPolicyOptions } from 'jslib-common/models/domain/passwordGeneratorPolicyOptions'; +import { PasswordGeneratorPolicyOptions } from "jslib-common/models/domain/passwordGeneratorPolicyOptions"; @Directive() export class PasswordGeneratorComponent implements OnInit { - @Input() showSelect: boolean = false; - @Output() onSelected = new EventEmitter(); + @Input() showSelect: boolean = false; + @Output() onSelected = new EventEmitter(); - passTypeOptions: any[]; - options: any = {}; - password: string = '-'; - showOptions = false; - avoidAmbiguous = false; - enforcedPolicyOptions: PasswordGeneratorPolicyOptions; + passTypeOptions: any[]; + options: any = {}; + password: string = "-"; + showOptions = false; + avoidAmbiguous = false; + enforcedPolicyOptions: PasswordGeneratorPolicyOptions; - constructor(protected passwordGenerationService: PasswordGenerationService, - protected platformUtilsService: PlatformUtilsService, protected i18nService: I18nService, - private win: Window) { - this.passTypeOptions = [ - { name: i18nService.t('password'), value: 'password' }, - { name: i18nService.t('passphrase'), value: 'passphrase' }, - ]; - } + constructor( + protected passwordGenerationService: PasswordGenerationService, + protected platformUtilsService: PlatformUtilsService, + protected i18nService: I18nService, + private win: Window + ) { + this.passTypeOptions = [ + { name: i18nService.t("password"), value: "password" }, + { name: i18nService.t("passphrase"), value: "passphrase" }, + ]; + } - async ngOnInit() { - const optionsResponse = await this.passwordGenerationService.getOptions(); - this.options = optionsResponse[0]; - this.enforcedPolicyOptions = optionsResponse[1]; - this.avoidAmbiguous = !this.options.ambiguous; - this.options.type = this.options.type === 'passphrase' ? 'passphrase' : 'password'; - this.password = await this.passwordGenerationService.generatePassword(this.options); - await this.passwordGenerationService.addHistory(this.password); + async ngOnInit() { + const optionsResponse = await this.passwordGenerationService.getOptions(); + this.options = optionsResponse[0]; + this.enforcedPolicyOptions = optionsResponse[1]; + this.avoidAmbiguous = !this.options.ambiguous; + this.options.type = this.options.type === "passphrase" ? "passphrase" : "password"; + this.password = await this.passwordGenerationService.generatePassword(this.options); + await this.passwordGenerationService.addHistory(this.password); + } + + async sliderChanged() { + this.saveOptions(false); + await this.passwordGenerationService.addHistory(this.password); + } + + async sliderInput() { + this.normalizeOptions(); + this.password = await this.passwordGenerationService.generatePassword(this.options); + } + + async saveOptions(regenerate: boolean = true) { + this.normalizeOptions(); + await this.passwordGenerationService.saveOptions(this.options); + + if (regenerate) { + await this.regenerate(); } + } - async sliderChanged() { - this.saveOptions(false); - await this.passwordGenerationService.addHistory(this.password); - } + async regenerate() { + this.password = await this.passwordGenerationService.generatePassword(this.options); + await this.passwordGenerationService.addHistory(this.password); + } - async sliderInput() { - this.normalizeOptions(); - this.password = await this.passwordGenerationService.generatePassword(this.options); - } + copy() { + const copyOptions = this.win != null ? { window: this.win } : null; + this.platformUtilsService.copyToClipboard(this.password, copyOptions); + this.platformUtilsService.showToast( + "info", + null, + this.i18nService.t("valueCopied", this.i18nService.t("password")) + ); + } - async saveOptions(regenerate: boolean = true) { - this.normalizeOptions(); - await this.passwordGenerationService.saveOptions(this.options); + select() { + this.onSelected.emit(this.password); + } - if (regenerate) { - await this.regenerate(); + toggleOptions() { + this.showOptions = !this.showOptions; + } + + private normalizeOptions() { + // Application level normalize options depedent on class variables + this.options.ambiguous = !this.avoidAmbiguous; + + if ( + !this.options.uppercase && + !this.options.lowercase && + !this.options.number && + !this.options.special + ) { + this.options.lowercase = true; + if (this.win != null) { + const lowercase = this.win.document.querySelector("#lowercase") as HTMLInputElement; + if (lowercase) { + lowercase.checked = true; } + } } - async regenerate() { - this.password = await this.passwordGenerationService.generatePassword(this.options); - await this.passwordGenerationService.addHistory(this.password); - } - - copy() { - const copyOptions = this.win != null ? { window: this.win } : null; - this.platformUtilsService.copyToClipboard(this.password, copyOptions); - this.platformUtilsService.showToast('info', null, - this.i18nService.t('valueCopied', this.i18nService.t('password'))); - } - - select() { - this.onSelected.emit(this.password); - } - - toggleOptions() { - this.showOptions = !this.showOptions; - } - - private normalizeOptions() { - // Application level normalize options depedent on class variables - this.options.ambiguous = !this.avoidAmbiguous; - - if (!this.options.uppercase && !this.options.lowercase && !this.options.number && !this.options.special) { - this.options.lowercase = true; - if (this.win != null) { - const lowercase = this.win.document.querySelector('#lowercase') as HTMLInputElement; - if (lowercase) { - lowercase.checked = true; - } - } - } - - this.passwordGenerationService.normalizeOptions(this.options, this.enforcedPolicyOptions); - } + this.passwordGenerationService.normalizeOptions(this.options, this.enforcedPolicyOptions); + } } diff --git a/angular/src/components/password-history.component.ts b/angular/src/components/password-history.component.ts index 3134c0a4..d5d83b1c 100644 --- a/angular/src/components/password-history.component.ts +++ b/angular/src/components/password-history.component.ts @@ -1,33 +1,40 @@ -import { Directive, OnInit } from '@angular/core'; +import { Directive, OnInit } from "@angular/core"; -import { CipherService } from 'jslib-common/abstractions/cipher.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { CipherService } from "jslib-common/abstractions/cipher.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { PasswordHistoryView } from 'jslib-common/models/view/passwordHistoryView'; +import { PasswordHistoryView } from "jslib-common/models/view/passwordHistoryView"; @Directive() export class PasswordHistoryComponent implements OnInit { - cipherId: string; - history: PasswordHistoryView[] = []; + cipherId: string; + history: PasswordHistoryView[] = []; - constructor(protected cipherService: CipherService, protected platformUtilsService: PlatformUtilsService, - protected i18nService: I18nService, private win: Window) { } + constructor( + protected cipherService: CipherService, + protected platformUtilsService: PlatformUtilsService, + protected i18nService: I18nService, + private win: Window + ) {} - async ngOnInit() { - await this.init(); - } + async ngOnInit() { + await this.init(); + } - copy(password: string) { - const copyOptions = this.win != null ? { window: this.win } : null; - this.platformUtilsService.copyToClipboard(password, copyOptions); - this.platformUtilsService.showToast('info', null, - this.i18nService.t('valueCopied', this.i18nService.t('password'))); - } + copy(password: string) { + const copyOptions = this.win != null ? { window: this.win } : null; + this.platformUtilsService.copyToClipboard(password, copyOptions); + this.platformUtilsService.showToast( + "info", + null, + this.i18nService.t("valueCopied", this.i18nService.t("password")) + ); + } - protected async init() { - const cipher = await this.cipherService.get(this.cipherId); - const decCipher = await cipher.decrypt(); - this.history = decCipher.passwordHistory == null ? [] : decCipher.passwordHistory; - } + protected async init() { + const cipher = await this.cipherService.get(this.cipherId); + const decCipher = await cipher.decrypt(); + this.history = decCipher.passwordHistory == null ? [] : decCipher.passwordHistory; + } } diff --git a/angular/src/components/password-reprompt.component.ts b/angular/src/components/password-reprompt.component.ts index 68845394..f547aace 100644 --- a/angular/src/components/password-reprompt.component.ts +++ b/angular/src/components/password-reprompt.component.ts @@ -1,30 +1,36 @@ -import { Directive } from '@angular/core'; +import { Directive } from "@angular/core"; -import { CryptoService } from 'jslib-common/abstractions/crypto.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { ModalRef } from './modal/modal.ref'; +import { CryptoService } from "jslib-common/abstractions/crypto.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; +import { ModalRef } from "./modal/modal.ref"; @Directive() export class PasswordRepromptComponent { + showPassword = false; + masterPassword = ""; - showPassword = false; - masterPassword = ''; + constructor( + private modalRef: ModalRef, + private cryptoService: CryptoService, + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService + ) {} - constructor(private modalRef: ModalRef, private cryptoService: CryptoService, private platformUtilsService: PlatformUtilsService, - private i18nService: I18nService) {} + togglePassword() { + this.showPassword = !this.showPassword; + } - togglePassword() { - this.showPassword = !this.showPassword; + async submit() { + if (!(await this.cryptoService.compareAndUpdateKeyHash(this.masterPassword, null))) { + this.platformUtilsService.showToast( + "error", + this.i18nService.t("errorOccurred"), + this.i18nService.t("invalidMasterPassword") + ); + return; } - async submit() { - if (!await this.cryptoService.compareAndUpdateKeyHash(this.masterPassword, null)) { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), - this.i18nService.t('invalidMasterPassword')); - return; - } - - this.modalRef.close(true); - } + this.modalRef.close(true); + } } diff --git a/angular/src/components/send/efflux-dates.component.ts b/angular/src/components/send/efflux-dates.component.ts index b774d3df..5f3aae13 100644 --- a/angular/src/components/send/efflux-dates.component.ts +++ b/angular/src/components/send/efflux-dates.component.ts @@ -1,341 +1,354 @@ -import { DatePipe } from '@angular/common'; -import { - Directive, - EventEmitter, - Input, - OnInit, - Output -} from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; +import { DatePipe } from "@angular/common"; +import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core"; +import { FormControl, FormGroup } from "@angular/forms"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; // Different BrowserPath = different controls. enum BrowserPath { - // Native datetime-locale. - // We are happy. - Default = 'default', + // Native datetime-locale. + // We are happy. + Default = "default", - // Native date and time inputs, but no datetime-locale. - // We use individual date and time inputs and create a datetime programatically on submit. - Firefox = 'firefox', + // Native date and time inputs, but no datetime-locale. + // We use individual date and time inputs and create a datetime programatically on submit. + Firefox = "firefox", - // No native date, time, or datetime-locale inputs. - // We use a polyfill for dates and a dropdown for times. - Safari = 'safari', + // No native date, time, or datetime-locale inputs. + // We use a polyfill for dates and a dropdown for times. + Safari = "safari", } enum DateField { - DeletionDate = 'deletion', - ExpriationDate = 'expiration', + DeletionDate = "deletion", + ExpriationDate = "expiration", } // Value = hours enum DatePreset { - OneHour = 1, - OneDay = 24, - TwoDays = 48, - ThreeDays = 72, - SevenDays = 168, - ThirtyDays = 720, - Custom = 0, - Never = null, + OneHour = 1, + OneDay = 24, + TwoDays = 48, + ThreeDays = 72, + SevenDays = 168, + ThirtyDays = 720, + Custom = 0, + Never = null, } // TimeOption is used for the dropdown implementation of custom times // twelveHour = displayed time; twentyFourHour = time used in logic interface TimeOption { - twelveHour: string; - twentyFourHour: string; + twelveHour: string; + twentyFourHour: string; } @Directive() export class EffluxDatesComponent implements OnInit { - @Input() readonly initialDeletionDate: Date; - @Input() readonly initialExpirationDate: Date; - @Input() readonly editMode: boolean; - @Input() readonly disabled: boolean; + @Input() readonly initialDeletionDate: Date; + @Input() readonly initialExpirationDate: Date; + @Input() readonly editMode: boolean; + @Input() readonly disabled: boolean; - @Output() datesChanged = new EventEmitter<{deletionDate: string, expirationDate: string}>(); + @Output() datesChanged = new EventEmitter<{ deletionDate: string; expirationDate: string }>(); - get browserPath(): BrowserPath { - if (this.platformUtilsService.isFirefox()) { - return BrowserPath.Firefox; - } else if (this.platformUtilsService.isSafari()) { - return BrowserPath.Safari; - } - return BrowserPath.Default; + get browserPath(): BrowserPath { + if (this.platformUtilsService.isFirefox()) { + return BrowserPath.Firefox; + } else if (this.platformUtilsService.isSafari()) { + return BrowserPath.Safari; } + return BrowserPath.Default; + } - datesForm = new FormGroup({ - selectedDeletionDatePreset: new FormControl(), - selectedExpirationDatePreset: new FormControl(), - defaultDeletionDateTime: new FormControl(), - defaultExpirationDateTime: new FormControl(), - fallbackDeletionDate: new FormControl(), - fallbackDeletionTime: new FormControl(), - fallbackExpirationDate: new FormControl(), - fallbackExpirationTime: new FormControl(), - }); + datesForm = new FormGroup({ + selectedDeletionDatePreset: new FormControl(), + selectedExpirationDatePreset: new FormControl(), + defaultDeletionDateTime: new FormControl(), + defaultExpirationDateTime: new FormControl(), + fallbackDeletionDate: new FormControl(), + fallbackDeletionTime: new FormControl(), + fallbackExpirationDate: new FormControl(), + fallbackExpirationTime: new FormControl(), + }); - deletionDatePresets: any[] = [ - { name: this.i18nService.t('oneHour'), value: DatePreset.OneHour }, - { name: this.i18nService.t('oneDay'), value: DatePreset.OneDay }, - { name: this.i18nService.t('days', '2'), value: DatePreset.TwoDays }, - { name: this.i18nService.t('days', '3'), value: DatePreset.ThreeDays }, - { name: this.i18nService.t('days', '7'), value: DatePreset.SevenDays }, - { name: this.i18nService.t('days', '30'), value: DatePreset.ThirtyDays }, - { name: this.i18nService.t('custom'), value: DatePreset.Custom }, - ]; + deletionDatePresets: any[] = [ + { name: this.i18nService.t("oneHour"), value: DatePreset.OneHour }, + { name: this.i18nService.t("oneDay"), value: DatePreset.OneDay }, + { name: this.i18nService.t("days", "2"), value: DatePreset.TwoDays }, + { name: this.i18nService.t("days", "3"), value: DatePreset.ThreeDays }, + { name: this.i18nService.t("days", "7"), value: DatePreset.SevenDays }, + { name: this.i18nService.t("days", "30"), value: DatePreset.ThirtyDays }, + { name: this.i18nService.t("custom"), value: DatePreset.Custom }, + ]; - expirationDatePresets: any[] = [ - { name: this.i18nService.t('never'), value: DatePreset.Never }, - ].concat([...this.deletionDatePresets]); + expirationDatePresets: any[] = [ + { name: this.i18nService.t("never"), value: DatePreset.Never }, + ].concat([...this.deletionDatePresets]); - get selectedDeletionDatePreset(): FormControl { - return this.datesForm.get('selectedDeletionDatePreset') as FormControl; - } + get selectedDeletionDatePreset(): FormControl { + return this.datesForm.get("selectedDeletionDatePreset") as FormControl; + } - get selectedExpirationDatePreset(): FormControl { - return this.datesForm.get('selectedExpirationDatePreset') as FormControl; - } + get selectedExpirationDatePreset(): FormControl { + return this.datesForm.get("selectedExpirationDatePreset") as FormControl; + } - get defaultDeletionDateTime(): FormControl { - return this.datesForm.get('defaultDeletionDateTime') as FormControl; - } + get defaultDeletionDateTime(): FormControl { + return this.datesForm.get("defaultDeletionDateTime") as FormControl; + } - get defaultExpirationDateTime(): FormControl { - return this.datesForm.get('defaultExpirationDateTime') as FormControl; - } + get defaultExpirationDateTime(): FormControl { + return this.datesForm.get("defaultExpirationDateTime") as FormControl; + } - get fallbackDeletionDate(): FormControl { - return this.datesForm.get('fallbackDeletionDate') as FormControl; - } + get fallbackDeletionDate(): FormControl { + return this.datesForm.get("fallbackDeletionDate") as FormControl; + } - get fallbackDeletionTime(): FormControl { - return this.datesForm.get('fallbackDeletionTime') as FormControl; - } + get fallbackDeletionTime(): FormControl { + return this.datesForm.get("fallbackDeletionTime") as FormControl; + } - get fallbackExpirationDate(): FormControl { - return this.datesForm.get('fallbackExpirationDate') as FormControl; - } + get fallbackExpirationDate(): FormControl { + return this.datesForm.get("fallbackExpirationDate") as FormControl; + } - get fallbackExpirationTime(): FormControl { - return this.datesForm.get('fallbackExpirationTime') as FormControl; - } + get fallbackExpirationTime(): FormControl { + return this.datesForm.get("fallbackExpirationTime") as FormControl; + } - // Should be able to call these at any time and compute a submitable value - get formattedDeletionDate(): string { - switch (this.selectedDeletionDatePreset.value as DatePreset) { - case DatePreset.Never: - this.selectedDeletionDatePreset.setValue(DatePreset.SevenDays); - return this.formattedDeletionDate; - case DatePreset.Custom: - switch (this.browserPath) { - case BrowserPath.Safari: - case BrowserPath.Firefox: - return this.fallbackDeletionDate.value + 'T' + this.fallbackDeletionTime.value; - default: - return this.defaultDeletionDateTime.value; - } - default: - const now = new Date(); - const miliseconds = now.setTime(now.getTime() + - (this.selectedDeletionDatePreset.value as number * 60 * 60 * 1000)) ; - return new Date(miliseconds).toString(); - } - } - - get formattedExpirationDate(): string { - switch (this.selectedExpirationDatePreset.value as DatePreset) { - case DatePreset.Never: - return null; - case DatePreset.Custom: - switch (this.browserPath) { - case BrowserPath.Safari: - case BrowserPath.Firefox: - if ((!this.fallbackExpirationDate.value || !this.fallbackExpirationTime.value) && - this.editMode) { - return null; - } - return this.fallbackExpirationDate.value + 'T' + this.fallbackExpirationTime.value; - default: - if (!this.defaultExpirationDateTime.value) { - return null; - } - return this.defaultExpirationDateTime.value; - } - default: - const now = new Date(); - const miliseconds = now.setTime(now.getTime() + - (this.selectedExpirationDatePreset.value as number * 60 * 60 * 1000)); - return new Date(miliseconds).toString(); - } - } - // - - get safariDeletionTimePresetOptions() { - return this.safariTimePresetOptions(DateField.DeletionDate); - } - - get safariExpirationTimePresetOptions() { - return this.safariTimePresetOptions(DateField.ExpriationDate); - } - - private get nextWeek(): Date { - const nextWeek = new Date(); - nextWeek.setDate(nextWeek.getDate() + 7); - return nextWeek; - } - - constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, - protected datePipe: DatePipe) { - } - - ngOnInit(): void { - this.setInitialFormValues(); - this.emitDates(); - this.datesForm.valueChanges.subscribe(() => { - this.emitDates(); - }); - } - - onDeletionDatePresetSelect(value: DatePreset) { - this.selectedDeletionDatePreset.setValue(value); - } - - clearExpiration() { + // Should be able to call these at any time and compute a submitable value + get formattedDeletionDate(): string { + switch (this.selectedDeletionDatePreset.value as DatePreset) { + case DatePreset.Never: + this.selectedDeletionDatePreset.setValue(DatePreset.SevenDays); + return this.formattedDeletionDate; + case DatePreset.Custom: switch (this.browserPath) { - case BrowserPath.Safari: - case BrowserPath.Firefox: - this.fallbackExpirationDate.setValue(null); - this.fallbackExpirationTime.setValue(null); - break; - case BrowserPath.Default: - this.defaultExpirationDateTime.setValue(null); - break; + case BrowserPath.Safari: + case BrowserPath.Firefox: + return this.fallbackDeletionDate.value + "T" + this.fallbackDeletionTime.value; + default: + return this.defaultDeletionDateTime.value; } + default: + const now = new Date(); + const miliseconds = now.setTime( + now.getTime() + (this.selectedDeletionDatePreset.value as number) * 60 * 60 * 1000 + ); + return new Date(miliseconds).toString(); } + } - protected emitDates() { - this.datesChanged.emit({ - deletionDate: this.formattedDeletionDate, - expirationDate: this.formattedExpirationDate, - }); - } - - protected setInitialFormValues() { - if (this.editMode) { - this.selectedDeletionDatePreset.setValue(DatePreset.Custom); - this.selectedExpirationDatePreset.setValue(DatePreset.Custom); - switch (this.browserPath) { - case BrowserPath.Safari: - case BrowserPath.Firefox: - this.fallbackDeletionDate.setValue(this.initialDeletionDate.toISOString().slice(0, 10)); - this.fallbackDeletionTime.setValue(this.initialDeletionDate.toTimeString().slice(0, 5)); - if (this.initialExpirationDate != null) { - this.fallbackExpirationDate.setValue(this.initialExpirationDate.toISOString().slice(0, 10)); - this.fallbackExpirationTime.setValue(this.initialExpirationDate.toTimeString().slice(0, 5)); - } - break; - case BrowserPath.Default: - if (this.initialExpirationDate) { - this.defaultExpirationDateTime.setValue( - this.datePipe.transform(new Date(this.initialExpirationDate), 'yyyy-MM-ddTHH:mm')); - } - this.defaultDeletionDateTime.setValue(this.datePipe.transform(new Date(this.initialDeletionDate), 'yyyy-MM-ddTHH:mm')); - break; + get formattedExpirationDate(): string { + switch (this.selectedExpirationDatePreset.value as DatePreset) { + case DatePreset.Never: + return null; + case DatePreset.Custom: + switch (this.browserPath) { + case BrowserPath.Safari: + case BrowserPath.Firefox: + if ( + (!this.fallbackExpirationDate.value || !this.fallbackExpirationTime.value) && + this.editMode + ) { + return null; } + return this.fallbackExpirationDate.value + "T" + this.fallbackExpirationTime.value; + default: + if (!this.defaultExpirationDateTime.value) { + return null; + } + return this.defaultExpirationDateTime.value; + } + default: + const now = new Date(); + const miliseconds = now.setTime( + now.getTime() + (this.selectedExpirationDatePreset.value as number) * 60 * 60 * 1000 + ); + return new Date(miliseconds).toString(); + } + } + // + + get safariDeletionTimePresetOptions() { + return this.safariTimePresetOptions(DateField.DeletionDate); + } + + get safariExpirationTimePresetOptions() { + return this.safariTimePresetOptions(DateField.ExpriationDate); + } + + private get nextWeek(): Date { + const nextWeek = new Date(); + nextWeek.setDate(nextWeek.getDate() + 7); + return nextWeek; + } + + constructor( + protected i18nService: I18nService, + protected platformUtilsService: PlatformUtilsService, + protected datePipe: DatePipe + ) {} + + ngOnInit(): void { + this.setInitialFormValues(); + this.emitDates(); + this.datesForm.valueChanges.subscribe(() => { + this.emitDates(); + }); + } + + onDeletionDatePresetSelect(value: DatePreset) { + this.selectedDeletionDatePreset.setValue(value); + } + + clearExpiration() { + switch (this.browserPath) { + case BrowserPath.Safari: + case BrowserPath.Firefox: + this.fallbackExpirationDate.setValue(null); + this.fallbackExpirationTime.setValue(null); + break; + case BrowserPath.Default: + this.defaultExpirationDateTime.setValue(null); + break; + } + } + + protected emitDates() { + this.datesChanged.emit({ + deletionDate: this.formattedDeletionDate, + expirationDate: this.formattedExpirationDate, + }); + } + + protected setInitialFormValues() { + if (this.editMode) { + this.selectedDeletionDatePreset.setValue(DatePreset.Custom); + this.selectedExpirationDatePreset.setValue(DatePreset.Custom); + switch (this.browserPath) { + case BrowserPath.Safari: + case BrowserPath.Firefox: + this.fallbackDeletionDate.setValue(this.initialDeletionDate.toISOString().slice(0, 10)); + this.fallbackDeletionTime.setValue(this.initialDeletionDate.toTimeString().slice(0, 5)); + if (this.initialExpirationDate != null) { + this.fallbackExpirationDate.setValue( + this.initialExpirationDate.toISOString().slice(0, 10) + ); + this.fallbackExpirationTime.setValue( + this.initialExpirationDate.toTimeString().slice(0, 5) + ); + } + break; + case BrowserPath.Default: + if (this.initialExpirationDate) { + this.defaultExpirationDateTime.setValue( + this.datePipe.transform(new Date(this.initialExpirationDate), "yyyy-MM-ddTHH:mm") + ); + } + this.defaultDeletionDateTime.setValue( + this.datePipe.transform(new Date(this.initialDeletionDate), "yyyy-MM-ddTHH:mm") + ); + break; + } + } else { + this.selectedDeletionDatePreset.setValue(DatePreset.SevenDays); + this.selectedExpirationDatePreset.setValue(DatePreset.Never); + + switch (this.browserPath) { + case BrowserPath.Safari: + this.fallbackDeletionDate.setValue(this.nextWeek.toISOString().slice(0, 10)); + this.fallbackDeletionTime.setValue( + this.safariTimePresetOptions(DateField.DeletionDate)[1].twentyFourHour + ); + break; + default: + break; + } + } + } + + protected safariTimePresetOptions(field: DateField): TimeOption[] { + // init individual arrays for major sort groups + const noon: TimeOption[] = []; + const midnight: TimeOption[] = []; + const ams: TimeOption[] = []; + const pms: TimeOption[] = []; + + // determine minute skip (5 min, 10 min, 15 min, etc.) + const minuteIncrementer = 15; + + // loop through each hour on a 12 hour system + for (let h = 1; h <= 12; h++) { + // loop through each minute in the hour using the skip to incriment + for (let m = 0; m < 60; m += minuteIncrementer) { + // init the final strings that will be added to the lists + let hour = h.toString(); + let minutes = m.toString(); + + // add prepending 0s to single digit hours/minutes + if (h < 10) { + hour = "0" + hour; + } + if (m < 10) { + minutes = "0" + minutes; + } + + // build time strings and push to relevant sort groups + if (h === 12) { + const midnightOption: TimeOption = { + twelveHour: `${hour}:${minutes} AM`, + twentyFourHour: `00:${minutes}`, + }; + midnight.push(midnightOption); + + const noonOption: TimeOption = { + twelveHour: `${hour}:${minutes} PM`, + twentyFourHour: `${hour}:${minutes}`, + }; + noon.push(noonOption); } else { - this.selectedDeletionDatePreset.setValue(DatePreset.SevenDays); - this.selectedExpirationDatePreset.setValue(DatePreset.Never); + const amOption: TimeOption = { + twelveHour: `${hour}:${minutes} AM`, + twentyFourHour: `${hour}:${minutes}`, + }; + ams.push(amOption); - switch (this.browserPath) { - case BrowserPath.Safari: - this.fallbackDeletionDate.setValue(this.nextWeek.toISOString().slice(0, 10)); - this.fallbackDeletionTime.setValue(this.safariTimePresetOptions(DateField.DeletionDate)[1].twentyFourHour); - break; - default: - break; - } + const pmOption: TimeOption = { + twelveHour: `${hour}:${minutes} PM`, + twentyFourHour: `${h + 12}:${minutes}`, + }; + pms.push(pmOption); } + } } - protected safariTimePresetOptions(field: DateField): TimeOption[] { - // init individual arrays for major sort groups - const noon: TimeOption[] = []; - const midnight: TimeOption[] = []; - const ams: TimeOption[] = []; - const pms: TimeOption[] = []; + // bring all the arrays together in the right order + const validTimes = [...midnight, ...ams, ...noon, ...pms]; - // determine minute skip (5 min, 10 min, 15 min, etc.) - const minuteIncrementer = 15; - - // loop through each hour on a 12 hour system - for (let h = 1; h <= 12; h++) { - // loop through each minute in the hour using the skip to incriment - for (let m = 0; m < 60; m += minuteIncrementer) { - // init the final strings that will be added to the lists - let hour = h.toString(); - let minutes = m.toString(); - - // add prepending 0s to single digit hours/minutes - if (h < 10) { - hour = '0' + hour; - } - if (m < 10) { - minutes = '0' + minutes; - } - - // build time strings and push to relevant sort groups - if (h === 12) { - const midnightOption: TimeOption = { - twelveHour: `${hour}:${minutes} AM`, - twentyFourHour: `00:${minutes}`, - }; - midnight.push(midnightOption); - - const noonOption: TimeOption = { - twelveHour: `${hour}:${minutes} PM`, - twentyFourHour: `${hour}:${minutes}`, - }; - noon.push(noonOption); - } else { - const amOption: TimeOption = { - twelveHour: `${hour}:${minutes} AM`, - twentyFourHour: `${hour}:${minutes}`, - }; - ams.push(amOption); - - const pmOption: TimeOption = { - twelveHour: `${hour}:${minutes} PM`, - twentyFourHour: `${h + 12}:${minutes}`, - }; - pms.push(pmOption); - } - } - } - - // bring all the arrays together in the right order - const validTimes = [...midnight, ...ams, ...noon, ...pms]; - - // determine if an unsupported value already exists on the send & add that to the top of the option list - // example: if the Send was created with a different client - if (field === DateField.ExpriationDate && this.initialExpirationDate != null && this.editMode) { - const previousValue: TimeOption = { - twelveHour: this.datePipe.transform(this.initialExpirationDate, 'hh:mm a'), - twentyFourHour: this.datePipe.transform(this.initialExpirationDate, 'HH:mm'), - }; - return [previousValue, { twelveHour: null, twentyFourHour: null }, ...validTimes]; - } else if (field === DateField.DeletionDate && this.initialDeletionDate != null && this.editMode) { - const previousValue: TimeOption = { - twelveHour: this.datePipe.transform(this.initialDeletionDate, 'hh:mm a'), - twentyFourHour: this.datePipe.transform(this.initialDeletionDate, 'HH:mm'), - }; - return [previousValue, ...validTimes]; - } else { - return [{ twelveHour: null, twentyFourHour: null }, ...validTimes]; - } + // determine if an unsupported value already exists on the send & add that to the top of the option list + // example: if the Send was created with a different client + if (field === DateField.ExpriationDate && this.initialExpirationDate != null && this.editMode) { + const previousValue: TimeOption = { + twelveHour: this.datePipe.transform(this.initialExpirationDate, "hh:mm a"), + twentyFourHour: this.datePipe.transform(this.initialExpirationDate, "HH:mm"), + }; + return [previousValue, { twelveHour: null, twentyFourHour: null }, ...validTimes]; + } else if ( + field === DateField.DeletionDate && + this.initialDeletionDate != null && + this.editMode + ) { + const previousValue: TimeOption = { + twelveHour: this.datePipe.transform(this.initialDeletionDate, "hh:mm a"), + twentyFourHour: this.datePipe.transform(this.initialDeletionDate, "HH:mm"), + }; + return [previousValue, ...validTimes]; + } else { + return [{ twelveHour: null, twentyFourHour: null }, ...validTimes]; } + } } diff --git a/angular/src/components/settings/vault-timeout-input.component.ts b/angular/src/components/settings/vault-timeout-input.component.ts index 749e7595..95180f88 100644 --- a/angular/src/components/settings/vault-timeout-input.component.ts +++ b/angular/src/components/settings/vault-timeout-input.component.ts @@ -1,138 +1,140 @@ +import { Directive, Input, OnInit } from "@angular/core"; import { - Directive, - Input, - OnInit, -} from '@angular/core'; -import { - AbstractControl, - ControlValueAccessor, - FormBuilder, - ValidationErrors, - Validator -} from '@angular/forms'; + AbstractControl, + ControlValueAccessor, + FormBuilder, + ValidationErrors, + Validator, +} from "@angular/forms"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PolicyService } from 'jslib-common/abstractions/policy.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PolicyService } from "jslib-common/abstractions/policy.service"; -import { PolicyType } from 'jslib-common/enums/policyType'; -import { Policy } from 'jslib-common/models/domain/policy'; +import { PolicyType } from "jslib-common/enums/policyType"; +import { Policy } from "jslib-common/models/domain/policy"; @Directive() export class VaultTimeoutInputComponent implements ControlValueAccessor, Validator, OnInit { + get showCustom() { + return this.form.get("vaultTimeout").value === VaultTimeoutInputComponent.CUSTOM_VALUE; + } - get showCustom() { - return this.form.get('vaultTimeout').value === VaultTimeoutInputComponent.CUSTOM_VALUE; + static CUSTOM_VALUE = -100; + + form = this.fb.group({ + vaultTimeout: [null], + custom: this.fb.group({ + hours: [null], + minutes: [null], + }), + }); + + @Input() vaultTimeouts: { name: string; value: number }[]; + vaultTimeoutPolicy: Policy; + vaultTimeoutPolicyHours: number; + vaultTimeoutPolicyMinutes: number; + + private onChange: (vaultTimeout: number) => void; + private validatorChange: () => void; + + constructor( + private fb: FormBuilder, + private policyService: PolicyService, + private i18nService: I18nService + ) {} + + async ngOnInit() { + if (await this.policyService.policyAppliesToUser(PolicyType.MaximumVaultTimeout)) { + const vaultTimeoutPolicy = await this.policyService.getAll(PolicyType.MaximumVaultTimeout); + + this.vaultTimeoutPolicy = vaultTimeoutPolicy[0]; + this.vaultTimeoutPolicyHours = Math.floor(this.vaultTimeoutPolicy.data.minutes / 60); + this.vaultTimeoutPolicyMinutes = this.vaultTimeoutPolicy.data.minutes % 60; + + this.vaultTimeouts = this.vaultTimeouts.filter( + (t) => + t.value <= this.vaultTimeoutPolicy.data.minutes && + (t.value > 0 || t.value === VaultTimeoutInputComponent.CUSTOM_VALUE) && + t.value != null + ); + this.validatorChange(); } - static CUSTOM_VALUE = -100; - - form = this.fb.group({ - vaultTimeout: [null], - custom: this.fb.group({ - hours: [null], - minutes: [null], - }), + this.form.valueChanges.subscribe(async (value) => { + this.onChange(this.getVaultTimeout(value)); }); - @Input() vaultTimeouts: { name: string; value: number; }[]; - vaultTimeoutPolicy: Policy; - vaultTimeoutPolicyHours: number; - vaultTimeoutPolicyMinutes: number; + // Assign the previous value to the custom fields + this.form.get("vaultTimeout").valueChanges.subscribe((value) => { + if (value !== VaultTimeoutInputComponent.CUSTOM_VALUE) { + return; + } - private onChange: (vaultTimeout: number) => void; - private validatorChange: () => void; + const current = Math.max(this.form.value.vaultTimeout, 0); + this.form.patchValue({ + custom: { + hours: Math.floor(current / 60), + minutes: current % 60, + }, + }); + }); + } - constructor(private fb: FormBuilder, private policyService: PolicyService, private i18nService: I18nService) { + ngOnChanges() { + this.vaultTimeouts.push({ + name: this.i18nService.t("custom"), + value: VaultTimeoutInputComponent.CUSTOM_VALUE, + }); + } + + getVaultTimeout(value: any) { + if (value.vaultTimeout !== VaultTimeoutInputComponent.CUSTOM_VALUE) { + return value.vaultTimeout; } - async ngOnInit() { - if (await this.policyService.policyAppliesToUser(PolicyType.MaximumVaultTimeout)) { - const vaultTimeoutPolicy = await this.policyService.getAll(PolicyType.MaximumVaultTimeout); + return value.custom.hours * 60 + value.custom.minutes; + } - this.vaultTimeoutPolicy = vaultTimeoutPolicy[0]; - this.vaultTimeoutPolicyHours = Math.floor(this.vaultTimeoutPolicy.data.minutes / 60); - this.vaultTimeoutPolicyMinutes = this.vaultTimeoutPolicy.data.minutes % 60; - - this.vaultTimeouts = this.vaultTimeouts.filter(t => - t.value <= this.vaultTimeoutPolicy.data.minutes && - (t.value > 0 || t.value === VaultTimeoutInputComponent.CUSTOM_VALUE) && - t.value != null - ); - this.validatorChange(); - } - - this.form.valueChanges.subscribe(async value => { - this.onChange(this.getVaultTimeout(value)); - }); - - // Assign the previous value to the custom fields - this.form.get('vaultTimeout').valueChanges.subscribe(value => { - if (value !== VaultTimeoutInputComponent.CUSTOM_VALUE) { - return; - } - - const current = Math.max(this.form.value.vaultTimeout, 0); - this.form.patchValue({ - custom: { - hours: Math.floor(current / 60), - minutes: current % 60, - }, - }); - }); + writeValue(value: number): void { + if (value == null) { + return; } - ngOnChanges() { - this.vaultTimeouts.push({ name: this.i18nService.t('custom'), value: VaultTimeoutInputComponent.CUSTOM_VALUE }); + if (this.vaultTimeouts.every((p) => p.value !== value)) { + this.form.setValue({ + vaultTimeout: VaultTimeoutInputComponent.CUSTOM_VALUE, + custom: { + hours: Math.floor(value / 60), + minutes: value % 60, + }, + }); + return; } - getVaultTimeout(value: any) { - if (value.vaultTimeout !== VaultTimeoutInputComponent.CUSTOM_VALUE) { - return value.vaultTimeout; - } + this.form.patchValue({ + vaultTimeout: value, + }); + } - return value.custom.hours * 60 + value.custom.minutes; + registerOnChange(onChange: any): void { + this.onChange = onChange; + } + + // tslint:disable-next-line + registerOnTouched(onTouched: any): void {} + + // tslint:disable-next-line + setDisabledState?(isDisabled: boolean): void {} + + validate(control: AbstractControl): ValidationErrors { + if (this.vaultTimeoutPolicy && this.vaultTimeoutPolicy?.data?.minutes < control.value) { + return { policyError: true }; } - writeValue(value: number): void { - if (value == null) { - return; - } + return null; + } - if (this.vaultTimeouts.every(p => p.value !== value)) { - this.form.setValue({ - vaultTimeout: VaultTimeoutInputComponent.CUSTOM_VALUE, - custom: { - hours: Math.floor(value / 60), - minutes: value % 60, - }, - }); - return; - } - - this.form.patchValue({ - vaultTimeout: value, - }); - } - - registerOnChange(onChange: any): void { - this.onChange = onChange; - } - - // tslint:disable-next-line - registerOnTouched(onTouched: any): void {} - - // tslint:disable-next-line - setDisabledState?(isDisabled: boolean): void { } - - validate(control: AbstractControl): ValidationErrors { - if (this.vaultTimeoutPolicy && this.vaultTimeoutPolicy?.data?.minutes < control.value) { - return { policyError: true }; - } - - return null; - } - - registerOnValidatorChange(fn: () => void): void { - this.validatorChange = fn; - } + registerOnValidatorChange(fn: () => void): void { + this.validatorChange = fn; + } } diff --git a/angular/src/components/two-factor-options.component.ts b/angular/src/components/two-factor-options.component.ts index 5f817a9e..4909757f 100644 --- a/angular/src/components/two-factor-options.component.ts +++ b/angular/src/components/two-factor-options.component.ts @@ -1,38 +1,37 @@ -import { - Directive, - EventEmitter, - OnInit, - Output, -} from '@angular/core'; -import { Router } from '@angular/router'; +import { Directive, EventEmitter, OnInit, Output } from "@angular/core"; +import { Router } from "@angular/router"; -import { TwoFactorProviderType } from 'jslib-common/enums/twoFactorProviderType'; +import { TwoFactorProviderType } from "jslib-common/enums/twoFactorProviderType"; -import { AuthService } from 'jslib-common/abstractions/auth.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { AuthService } from "jslib-common/abstractions/auth.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; @Directive() export class TwoFactorOptionsComponent implements OnInit { - @Output() onProviderSelected = new EventEmitter(); - @Output() onRecoverSelected = new EventEmitter(); + @Output() onProviderSelected = new EventEmitter(); + @Output() onRecoverSelected = new EventEmitter(); - providers: any[] = []; + providers: any[] = []; - constructor(protected authService: AuthService, protected router: Router, - protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, - protected win: Window) { } + constructor( + protected authService: AuthService, + protected router: Router, + protected i18nService: I18nService, + protected platformUtilsService: PlatformUtilsService, + protected win: Window + ) {} - ngOnInit() { - this.providers = this.authService.getSupportedTwoFactorProviders(this.win); - } + ngOnInit() { + this.providers = this.authService.getSupportedTwoFactorProviders(this.win); + } - choose(p: any) { - this.onProviderSelected.emit(p.type); - } + choose(p: any) { + this.onProviderSelected.emit(p.type); + } - recover() { - this.platformUtilsService.launchUri('https://help.bitwarden.com/article/lost-two-step-device/'); - this.onRecoverSelected.emit(); - } + recover() { + this.platformUtilsService.launchUri("https://help.bitwarden.com/article/lost-two-step-device/"); + this.onRecoverSelected.emit(); + } } diff --git a/angular/src/components/verify-master-password.component.html b/angular/src/components/verify-master-password.component.html index c4160e97..19330ff6 100644 --- a/angular/src/components/verify-master-password.component.html +++ b/angular/src/components/verify-master-password.component.html @@ -1,25 +1,46 @@ - - - {{'confirmIdentity' | i18n}} + + + {{ "confirmIdentity" | i18n }} -
- - - - - {{'codeSent' | i18n}} - -
+
+ + + + + {{ "codeSent" | i18n }} + +
-
- - - {{'confirmIdentity' | i18n}} -
+
+ + + {{ "confirmIdentity" | i18n }} +
diff --git a/angular/src/components/verify-master-password.component.ts b/angular/src/components/verify-master-password.component.ts index 1975b4e2..43b64eb2 100644 --- a/angular/src/components/verify-master-password.component.ts +++ b/angular/src/components/verify-master-password.component.ts @@ -1,105 +1,92 @@ -import { - animate, - style, - transition, - trigger, -} from '@angular/animations'; -import { - Component, - OnInit, -} from '@angular/core'; -import { - ControlValueAccessor, - FormControl, - NG_VALUE_ACCESSOR, -} from '@angular/forms'; +import { animate, style, transition, trigger } from "@angular/animations"; +import { Component, OnInit } from "@angular/core"; +import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR } from "@angular/forms"; -import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service'; -import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service'; +import { KeyConnectorService } from "jslib-common/abstractions/keyConnector.service"; +import { UserVerificationService } from "jslib-common/abstractions/userVerification.service"; -import { VerificationType } from 'jslib-common/enums/verificationType'; +import { VerificationType } from "jslib-common/enums/verificationType"; -import { Verification } from 'jslib-common/types/verification'; +import { Verification } from "jslib-common/types/verification"; @Component({ - selector: 'app-verify-master-password', - templateUrl: 'verify-master-password.component.html', - providers: [ - { - provide: NG_VALUE_ACCESSOR, - multi: true, - useExisting: VerifyMasterPasswordComponent, - }, - ], - animations: [ - trigger('sent', [ - transition(':enter', [ - style({ opacity: 0 }), - animate('100ms', style({ opacity: 1 })), - ]), - ]), - ], + selector: "app-verify-master-password", + templateUrl: "verify-master-password.component.html", + providers: [ + { + provide: NG_VALUE_ACCESSOR, + multi: true, + useExisting: VerifyMasterPasswordComponent, + }, + ], + animations: [ + trigger("sent", [ + transition(":enter", [style({ opacity: 0 }), animate("100ms", style({ opacity: 1 }))]), + ]), + ], }) export class VerifyMasterPasswordComponent implements ControlValueAccessor, OnInit { - usesKeyConnector: boolean = false; - disableRequestOTP: boolean = false; - sentCode: boolean = false; + usesKeyConnector: boolean = false; + disableRequestOTP: boolean = false; + sentCode: boolean = false; - secret = new FormControl(''); + secret = new FormControl(""); - private onChange: (value: Verification) => void; + private onChange: (value: Verification) => void; - constructor(private keyConnectorService: KeyConnectorService, - private userVerificationService: UserVerificationService) { } + constructor( + private keyConnectorService: KeyConnectorService, + private userVerificationService: UserVerificationService + ) {} - async ngOnInit() { - this.usesKeyConnector = await this.keyConnectorService.getUsesKeyConnector(); - this.processChanges(this.secret.value); + async ngOnInit() { + this.usesKeyConnector = await this.keyConnectorService.getUsesKeyConnector(); + this.processChanges(this.secret.value); - this.secret.valueChanges.subscribe(secret => this.processChanges(secret)); + this.secret.valueChanges.subscribe((secret) => this.processChanges(secret)); + } + + async requestOTP() { + if (this.usesKeyConnector) { + this.disableRequestOTP = true; + try { + await this.userVerificationService.requestOTP(); + this.sentCode = true; + } finally { + this.disableRequestOTP = false; + } + } + } + + writeValue(obj: any): void { + this.secret.setValue(obj); + } + + registerOnChange(fn: any): void { + this.onChange = fn; + } + + registerOnTouched(fn: any): void { + // Not implemented + } + + setDisabledState?(isDisabled: boolean): void { + this.disableRequestOTP = isDisabled; + if (isDisabled) { + this.secret.disable(); + } else { + this.secret.enable(); + } + } + + private processChanges(secret: string) { + if (this.onChange == null) { + return; } - async requestOTP() { - if (this.usesKeyConnector) { - this.disableRequestOTP = true; - try { - await this.userVerificationService.requestOTP(); - this.sentCode = true; - } finally { - this.disableRequestOTP = false; - } - } - } - - writeValue(obj: any): void { - this.secret.setValue(obj); - } - - registerOnChange(fn: any): void { - this.onChange = fn; - } - - registerOnTouched(fn: any): void { - // Not implemented - } - - setDisabledState?(isDisabled: boolean): void { - this.disableRequestOTP = isDisabled; - if (isDisabled) { - this.secret.disable(); - } else { - this.secret.enable(); - } - } - - private processChanges(secret: string) { - if (this.onChange == null) { - return; - } - - this.onChange({ - type: this.usesKeyConnector ? VerificationType.OTP : VerificationType.MasterPassword, - secret: secret, - }); - } + this.onChange({ + type: this.usesKeyConnector ? VerificationType.OTP : VerificationType.MasterPassword, + secret: secret, + }); + } } diff --git a/angular/src/components/view-custom-fields.component.ts b/angular/src/components/view-custom-fields.component.ts index add22691..c955eeb8 100644 --- a/angular/src/components/view-custom-fields.component.ts +++ b/angular/src/components/view-custom-fields.component.ts @@ -1,35 +1,32 @@ -import { - Directive, - Input, -} from '@angular/core'; +import { Directive, Input } from "@angular/core"; -import { EventType } from 'jslib-common/enums/eventType'; -import { FieldType } from 'jslib-common/enums/fieldType'; +import { EventType } from "jslib-common/enums/eventType"; +import { FieldType } from "jslib-common/enums/fieldType"; -import { EventService } from 'jslib-common/abstractions/event.service'; +import { EventService } from "jslib-common/abstractions/event.service"; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { FieldView } from 'jslib-common/models/view/fieldView'; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { FieldView } from "jslib-common/models/view/fieldView"; @Directive() export class ViewCustomFieldsComponent { - @Input() cipher: CipherView; - @Input() promptPassword: () => Promise; - @Input() copy: (value: string, typeI18nKey: string, aType: string) => void; + @Input() cipher: CipherView; + @Input() promptPassword: () => Promise; + @Input() copy: (value: string, typeI18nKey: string, aType: string) => void; - fieldType = FieldType; + fieldType = FieldType; - constructor(private eventService: EventService) { } + constructor(private eventService: EventService) {} - async toggleFieldValue(field: FieldView) { - if (!await this.promptPassword()) { - return; - } - - const f = (field as any); - f.showValue = !f.showValue; - if (f.showValue) { - this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipher.id); - } + async toggleFieldValue(field: FieldView) { + if (!(await this.promptPassword())) { + return; } + + const f = field as any; + f.showValue = !f.showValue; + if (f.showValue) { + this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipher.id); + } + } } diff --git a/angular/src/directives/a11y-title.directive.ts b/angular/src/directives/a11y-title.directive.ts index e8d57669..20e53a55 100644 --- a/angular/src/directives/a11y-title.directive.ts +++ b/angular/src/directives/a11y-title.directive.ts @@ -1,28 +1,23 @@ -import { - Directive, - ElementRef, - Input, - Renderer2, -} from '@angular/core'; +import { Directive, ElementRef, Input, Renderer2 } from "@angular/core"; @Directive({ - selector: '[appA11yTitle]', + selector: "[appA11yTitle]", }) export class A11yTitleDirective { - @Input() set appA11yTitle(title: string) { - this.title = title; + @Input() set appA11yTitle(title: string) { + this.title = title; + } + + private title: string; + + constructor(private el: ElementRef, private renderer: Renderer2) {} + + ngOnInit() { + if (!this.el.nativeElement.hasAttribute("title")) { + this.renderer.setAttribute(this.el.nativeElement, "title", this.title); } - - private title: string; - - constructor(private el: ElementRef, private renderer: Renderer2) { } - - ngOnInit() { - if (!this.el.nativeElement.hasAttribute('title')) { - this.renderer.setAttribute(this.el.nativeElement, 'title', this.title); - } - if (!this.el.nativeElement.hasAttribute('aria-label')) { - this.renderer.setAttribute(this.el.nativeElement, 'aria-label', this.title); - } + if (!this.el.nativeElement.hasAttribute("aria-label")) { + this.renderer.setAttribute(this.el.nativeElement, "aria-label", this.title); } + } } diff --git a/angular/src/directives/api-action.directive.ts b/angular/src/directives/api-action.directive.ts index 049d4b30..64f209c9 100644 --- a/angular/src/directives/api-action.directive.ts +++ b/angular/src/directives/api-action.directive.ts @@ -1,42 +1,46 @@ -import { - Directive, - ElementRef, - Input, - OnChanges, -} from '@angular/core'; -import { LogService } from 'jslib-common/abstractions/log.service'; +import { Directive, ElementRef, Input, OnChanges } from "@angular/core"; +import { LogService } from "jslib-common/abstractions/log.service"; -import { ErrorResponse } from 'jslib-common/models/response/errorResponse'; +import { ErrorResponse } from "jslib-common/models/response/errorResponse"; -import { ValidationService } from '../services/validation.service'; +import { ValidationService } from "../services/validation.service"; @Directive({ - selector: '[appApiAction]', + selector: "[appApiAction]", }) export class ApiActionDirective implements OnChanges { - @Input() appApiAction: Promise; + @Input() appApiAction: Promise; - constructor(private el: ElementRef, private validationService: ValidationService, - private logService: LogService) { } + constructor( + private el: ElementRef, + private validationService: ValidationService, + private logService: LogService + ) {} - ngOnChanges(changes: any) { - if (this.appApiAction == null || this.appApiAction.then == null) { - return; - } - - this.el.nativeElement.loading = true; - - this.appApiAction.then((response: any) => { - this.el.nativeElement.loading = false; - }, (e: any) => { - this.el.nativeElement.loading = false; - - if ((e instanceof ErrorResponse || e.constructor.name === 'ErrorResponse') && (e as ErrorResponse).captchaRequired) { - this.logService.error('Captcha required error response: ' + e.getSingleMessage()); - return; - } - this.logService?.error(`Received API exception: ${e}`); - this.validationService.showError(e); - }); + ngOnChanges(changes: any) { + if (this.appApiAction == null || this.appApiAction.then == null) { + return; } + + this.el.nativeElement.loading = true; + + this.appApiAction.then( + (response: any) => { + this.el.nativeElement.loading = false; + }, + (e: any) => { + this.el.nativeElement.loading = false; + + if ( + (e instanceof ErrorResponse || e.constructor.name === "ErrorResponse") && + (e as ErrorResponse).captchaRequired + ) { + this.logService.error("Captcha required error response: " + e.getSingleMessage()); + return; + } + this.logService?.error(`Received API exception: ${e}`); + this.validationService.showError(e); + } + ); + } } diff --git a/angular/src/directives/autofocus.directive.ts b/angular/src/directives/autofocus.directive.ts index 89b0cfd9..a90a8075 100644 --- a/angular/src/directives/autofocus.directive.ts +++ b/angular/src/directives/autofocus.directive.ts @@ -1,33 +1,28 @@ -import { - Directive, - ElementRef, - Input, - NgZone, -} from '@angular/core'; +import { Directive, ElementRef, Input, NgZone } from "@angular/core"; -import { take } from 'rxjs/operators'; +import { take } from "rxjs/operators"; -import { Utils } from 'jslib-common/misc/utils'; +import { Utils } from "jslib-common/misc/utils"; @Directive({ - selector: '[appAutofocus]', + selector: "[appAutofocus]", }) export class AutofocusDirective { - @Input() set appAutofocus(condition: boolean | string) { - this.autofocus = condition === '' || condition === true; - } - - private autofocus: boolean; - - constructor(private el: ElementRef, private ngZone: NgZone) { } - - ngOnInit() { - if (!Utils.isMobileBrowser && this.autofocus) { - if (this.ngZone.isStable) { - this.el.nativeElement.focus(); - } else { - this.ngZone.onStable.pipe(take(1)).subscribe(() => this.el.nativeElement.focus()); - } - } + @Input() set appAutofocus(condition: boolean | string) { + this.autofocus = condition === "" || condition === true; + } + + private autofocus: boolean; + + constructor(private el: ElementRef, private ngZone: NgZone) {} + + ngOnInit() { + if (!Utils.isMobileBrowser && this.autofocus) { + if (this.ngZone.isStable) { + this.el.nativeElement.focus(); + } else { + this.ngZone.onStable.pipe(take(1)).subscribe(() => this.el.nativeElement.focus()); + } } + } } diff --git a/angular/src/directives/blur-click.directive.ts b/angular/src/directives/blur-click.directive.ts index 48555bb9..2fc1d367 100644 --- a/angular/src/directives/blur-click.directive.ts +++ b/angular/src/directives/blur-click.directive.ts @@ -1,17 +1,12 @@ -import { - Directive, - ElementRef, - HostListener, -} from '@angular/core'; +import { Directive, ElementRef, HostListener } from "@angular/core"; @Directive({ - selector: '[appBlurClick]', + selector: "[appBlurClick]", }) export class BlurClickDirective { - constructor(private el: ElementRef) { - } + constructor(private el: ElementRef) {} - @HostListener('click') onClick() { - this.el.nativeElement.blur(); - } + @HostListener("click") onClick() { + this.el.nativeElement.blur(); + } } diff --git a/angular/src/directives/box-row.directive.ts b/angular/src/directives/box-row.directive.ts index a7dd0bee..049f0434 100644 --- a/angular/src/directives/box-row.directive.ts +++ b/angular/src/directives/box-row.directive.ts @@ -1,51 +1,59 @@ -import { - Directive, - ElementRef, - HostListener, - OnInit, -} from '@angular/core'; +import { Directive, ElementRef, HostListener, OnInit } from "@angular/core"; @Directive({ - selector: '[appBoxRow]', + selector: "[appBoxRow]", }) export class BoxRowDirective implements OnInit { - el: HTMLElement = null; - formEls: Element[]; + el: HTMLElement = null; + formEls: Element[]; - constructor(private elRef: ElementRef) { - this.el = elRef.nativeElement; + constructor(private elRef: ElementRef) { + this.el = elRef.nativeElement; + } + + ngOnInit(): void { + this.formEls = Array.from( + this.el.querySelectorAll('input:not([type="hidden"]), select, textarea') + ); + this.formEls.forEach((formEl) => { + formEl.addEventListener( + "focus", + (event: Event) => { + this.el.classList.add("active"); + }, + false + ); + + formEl.addEventListener( + "blur", + (event: Event) => { + this.el.classList.remove("active"); + }, + false + ); + }); + } + + @HostListener("click", ["$event"]) onClick(event: Event) { + const target = event.target as HTMLElement; + if ( + target !== this.el && + !target.classList.contains("progress") && + !target.classList.contains("progress-bar") + ) { + return; } - ngOnInit(): void { - this.formEls = Array.from(this.el.querySelectorAll('input:not([type="hidden"]), select, textarea')); - this.formEls.forEach(formEl => { - formEl.addEventListener('focus', (event: Event) => { - this.el.classList.add('active'); - }, false); - - formEl.addEventListener('blur', (event: Event) => { - this.el.classList.remove('active'); - }, false); - }); - } - - @HostListener('click', ['$event']) onClick(event: Event) { - const target = event.target as HTMLElement; - if (target !== this.el && !target.classList.contains('progress') && - !target.classList.contains('progress-bar')) { - return; - } - - if (this.formEls.length > 0) { - const formEl = (this.formEls[0] as HTMLElement); - if (formEl.tagName.toLowerCase() === 'input') { - const inputEl = (formEl as HTMLInputElement); - if (inputEl.type != null && inputEl.type.toLowerCase() === 'checkbox') { - inputEl.click(); - return; - } - } - formEl.focus(); + if (this.formEls.length > 0) { + const formEl = this.formEls[0] as HTMLElement; + if (formEl.tagName.toLowerCase() === "input") { + const inputEl = formEl as HTMLInputElement; + if (inputEl.type != null && inputEl.type.toLowerCase() === "checkbox") { + inputEl.click(); + return; } + } + formEl.focus(); } + } } diff --git a/angular/src/directives/cipherListVirtualScroll.directive.ts b/angular/src/directives/cipherListVirtualScroll.directive.ts index a0c8a6f4..7b906b53 100644 --- a/angular/src/directives/cipherListVirtualScroll.directive.ts +++ b/angular/src/directives/cipherListVirtualScroll.directive.ts @@ -1,62 +1,76 @@ import { - CdkFixedSizeVirtualScroll, - FixedSizeVirtualScrollStrategy, - VIRTUAL_SCROLL_STRATEGY, -} from '@angular/cdk/scrolling'; -import { - Directive, - forwardRef, -} from '@angular/core'; + CdkFixedSizeVirtualScroll, + FixedSizeVirtualScrollStrategy, + VIRTUAL_SCROLL_STRATEGY, +} from "@angular/cdk/scrolling"; +import { Directive, forwardRef } from "@angular/core"; // Custom virtual scroll strategy for cdk-virtual-scroll // Uses a sample list item to set the itemSize for FixedSizeVirtualScrollStrategy // The use case is the same as FixedSizeVirtualScrollStrategy, but it avoids locking in pixel sizes in the template. export class CipherListVirtualScrollStrategy extends FixedSizeVirtualScrollStrategy { - private checkItemSizeCallback: any; - private timeout: any; + private checkItemSizeCallback: any; + private timeout: any; - constructor(itemSize: number, minBufferPx: number, maxBufferPx: number, checkItemSizeCallback: any) { - super(itemSize, minBufferPx, maxBufferPx); - this.checkItemSizeCallback = checkItemSizeCallback; + constructor( + itemSize: number, + minBufferPx: number, + maxBufferPx: number, + checkItemSizeCallback: any + ) { + super(itemSize, minBufferPx, maxBufferPx); + this.checkItemSizeCallback = checkItemSizeCallback; + } + + onContentRendered() { + if (this.timeout != null) { + clearTimeout(this.timeout); } - onContentRendered() { - if (this.timeout != null) { - clearTimeout(this.timeout); - } - - this.timeout = setTimeout(this.checkItemSizeCallback, 500); - } + this.timeout = setTimeout(this.checkItemSizeCallback, 500); + } } export function _cipherListVirtualScrollStrategyFactory(cipherListDir: CipherListVirtualScroll) { - return cipherListDir._scrollStrategy; + return cipherListDir._scrollStrategy; } @Directive({ - selector: 'cdk-virtual-scroll-viewport[itemSize]', - providers: [{ - provide: VIRTUAL_SCROLL_STRATEGY, - useFactory: _cipherListVirtualScrollStrategyFactory, - deps: [forwardRef(() => CipherListVirtualScroll)], - }], + selector: "cdk-virtual-scroll-viewport[itemSize]", + providers: [ + { + provide: VIRTUAL_SCROLL_STRATEGY, + useFactory: _cipherListVirtualScrollStrategyFactory, + deps: [forwardRef(() => CipherListVirtualScroll)], + }, + ], }) export class CipherListVirtualScroll extends CdkFixedSizeVirtualScroll { - _scrollStrategy: CipherListVirtualScrollStrategy; + _scrollStrategy: CipherListVirtualScrollStrategy; - constructor() { - super(); - this._scrollStrategy = new CipherListVirtualScrollStrategy(this.itemSize, this.minBufferPx, this.maxBufferPx, - this.checkAndUpdateItemSize); - } - - checkAndUpdateItemSize = () => { - const sampleItem = document.querySelector('cdk-virtual-scroll-viewport .virtual-scroll-item') as HTMLElement; - const newItemSize = sampleItem?.offsetHeight; - - if (newItemSize != null && newItemSize !== this.itemSize) { - this.itemSize = newItemSize; - this._scrollStrategy.updateItemAndBufferSize(this.itemSize, this.minBufferPx, this.maxBufferPx); - } + constructor() { + super(); + this._scrollStrategy = new CipherListVirtualScrollStrategy( + this.itemSize, + this.minBufferPx, + this.maxBufferPx, + this.checkAndUpdateItemSize + ); + } + + checkAndUpdateItemSize = () => { + const sampleItem = document.querySelector( + "cdk-virtual-scroll-viewport .virtual-scroll-item" + ) as HTMLElement; + const newItemSize = sampleItem?.offsetHeight; + + if (newItemSize != null && newItemSize !== this.itemSize) { + this.itemSize = newItemSize; + this._scrollStrategy.updateItemAndBufferSize( + this.itemSize, + this.minBufferPx, + this.maxBufferPx + ); } + }; } diff --git a/angular/src/directives/fallback-src.directive.ts b/angular/src/directives/fallback-src.directive.ts index 3e5e3381..11bce205 100644 --- a/angular/src/directives/fallback-src.directive.ts +++ b/angular/src/directives/fallback-src.directive.ts @@ -1,20 +1,14 @@ -import { - Directive, - ElementRef, - HostListener, - Input, -} from '@angular/core'; +import { Directive, ElementRef, HostListener, Input } from "@angular/core"; @Directive({ - selector: '[appFallbackSrc]', + selector: "[appFallbackSrc]", }) export class FallbackSrcDirective { - @Input('appFallbackSrc') appFallbackSrc: string; + @Input("appFallbackSrc") appFallbackSrc: string; - constructor(private el: ElementRef) { - } + constructor(private el: ElementRef) {} - @HostListener('error') onError() { - this.el.nativeElement.src = this.appFallbackSrc; - } + @HostListener("error") onError() { + this.el.nativeElement.src = this.appFallbackSrc; + } } diff --git a/angular/src/directives/input-verbatim.directive.ts b/angular/src/directives/input-verbatim.directive.ts index 9c94fbcb..3dd1975a 100644 --- a/angular/src/directives/input-verbatim.directive.ts +++ b/angular/src/directives/input-verbatim.directive.ts @@ -1,37 +1,32 @@ -import { - Directive, - ElementRef, - Input, - Renderer2, -} from '@angular/core'; +import { Directive, ElementRef, Input, Renderer2 } from "@angular/core"; @Directive({ - selector: '[appInputVerbatim]', + selector: "[appInputVerbatim]", }) export class InputVerbatimDirective { - @Input() set appInputVerbatim(condition: boolean | string) { - this.disableComplete = condition === '' || condition === true; + @Input() set appInputVerbatim(condition: boolean | string) { + this.disableComplete = condition === "" || condition === true; + } + + private disableComplete: boolean; + + constructor(private el: ElementRef, private renderer: Renderer2) {} + + ngOnInit() { + if (this.disableComplete && !this.el.nativeElement.hasAttribute("autocomplete")) { + this.renderer.setAttribute(this.el.nativeElement, "autocomplete", "off"); } - - private disableComplete: boolean; - - constructor(private el: ElementRef, private renderer: Renderer2) { } - - ngOnInit() { - if (this.disableComplete && !this.el.nativeElement.hasAttribute('autocomplete')) { - this.renderer.setAttribute(this.el.nativeElement, 'autocomplete', 'off'); - } - if (!this.el.nativeElement.hasAttribute('autocapitalize')) { - this.renderer.setAttribute(this.el.nativeElement, 'autocapitalize', 'none'); - } - if (!this.el.nativeElement.hasAttribute('autocorrect')) { - this.renderer.setAttribute(this.el.nativeElement, 'autocorrect', 'none'); - } - if (!this.el.nativeElement.hasAttribute('spellcheck')) { - this.renderer.setAttribute(this.el.nativeElement, 'spellcheck', 'false'); - } - if (!this.el.nativeElement.hasAttribute('inputmode')) { - this.renderer.setAttribute(this.el.nativeElement, 'inputmode', 'verbatim'); - } + if (!this.el.nativeElement.hasAttribute("autocapitalize")) { + this.renderer.setAttribute(this.el.nativeElement, "autocapitalize", "none"); } + if (!this.el.nativeElement.hasAttribute("autocorrect")) { + this.renderer.setAttribute(this.el.nativeElement, "autocorrect", "none"); + } + if (!this.el.nativeElement.hasAttribute("spellcheck")) { + this.renderer.setAttribute(this.el.nativeElement, "spellcheck", "false"); + } + if (!this.el.nativeElement.hasAttribute("inputmode")) { + this.renderer.setAttribute(this.el.nativeElement, "inputmode", "verbatim"); + } + } } diff --git a/angular/src/directives/select-copy.directive.ts b/angular/src/directives/select-copy.directive.ts index 1edc0bdd..81d4928b 100644 --- a/angular/src/directives/select-copy.directive.ts +++ b/angular/src/directives/select-copy.directive.ts @@ -1,41 +1,37 @@ -import { - Directive, - ElementRef, - HostListener, -} from '@angular/core'; +import { Directive, ElementRef, HostListener } from "@angular/core"; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; @Directive({ - selector: '[appSelectCopy]', + selector: "[appSelectCopy]", }) export class SelectCopyDirective { - constructor(private el: ElementRef, private platformUtilsService: PlatformUtilsService) { } + constructor(private el: ElementRef, private platformUtilsService: PlatformUtilsService) {} - @HostListener('copy') onCopy() { - if (window == null) { - return; - } - let copyText = ''; - const selection = window.getSelection(); - for (let i = 0; i < selection.rangeCount; i++) { - const range = selection.getRangeAt(i); - const text = range.toString(); - - // The selection should only contain one line of text. In some cases however, the - // selection contains newlines and space characters from the indentation of following - // sibling nodes. To avoid copying passwords containing trailing newlines and spaces - // that aren't part of the password, the selection has to be trimmed. - let stringEndPos = text.length; - const newLinePos = text.search(/(?:\r\n|\r|\n)/); - if (newLinePos > -1) { - const otherPart = text.substr(newLinePos).trim(); - if (otherPart === '') { - stringEndPos = newLinePos; - } - } - copyText += text.substring(0, stringEndPos); - } - this.platformUtilsService.copyToClipboard(copyText, { window: window }); + @HostListener("copy") onCopy() { + if (window == null) { + return; } + let copyText = ""; + const selection = window.getSelection(); + for (let i = 0; i < selection.rangeCount; i++) { + const range = selection.getRangeAt(i); + const text = range.toString(); + + // The selection should only contain one line of text. In some cases however, the + // selection contains newlines and space characters from the indentation of following + // sibling nodes. To avoid copying passwords containing trailing newlines and spaces + // that aren't part of the password, the selection has to be trimmed. + let stringEndPos = text.length; + const newLinePos = text.search(/(?:\r\n|\r|\n)/); + if (newLinePos > -1) { + const otherPart = text.substr(newLinePos).trim(); + if (otherPart === "") { + stringEndPos = newLinePos; + } + } + copyText += text.substring(0, stringEndPos); + } + this.platformUtilsService.copyToClipboard(copyText, { window: window }); + } } diff --git a/angular/src/directives/stop-click.directive.ts b/angular/src/directives/stop-click.directive.ts index 0529556b..0e88dde3 100644 --- a/angular/src/directives/stop-click.directive.ts +++ b/angular/src/directives/stop-click.directive.ts @@ -1,13 +1,10 @@ -import { - Directive, - HostListener, -} from '@angular/core'; +import { Directive, HostListener } from "@angular/core"; @Directive({ - selector: '[appStopClick]', + selector: "[appStopClick]", }) export class StopClickDirective { - @HostListener('click', ['$event']) onClick($event: MouseEvent) { - $event.preventDefault(); - } + @HostListener("click", ["$event"]) onClick($event: MouseEvent) { + $event.preventDefault(); + } } diff --git a/angular/src/directives/stop-prop.directive.ts b/angular/src/directives/stop-prop.directive.ts index b241f628..8393e799 100644 --- a/angular/src/directives/stop-prop.directive.ts +++ b/angular/src/directives/stop-prop.directive.ts @@ -1,13 +1,10 @@ -import { - Directive, - HostListener, -} from '@angular/core'; +import { Directive, HostListener } from "@angular/core"; @Directive({ - selector: '[appStopProp]', + selector: "[appStopProp]", }) export class StopPropDirective { - @HostListener('click', ['$event']) onClick($event: MouseEvent) { - $event.stopPropagation(); - } + @HostListener("click", ["$event"]) onClick($event: MouseEvent) { + $event.stopPropagation(); + } } diff --git a/angular/src/directives/true-false-value.directive.ts b/angular/src/directives/true-false-value.directive.ts index 6dcf628e..6b553c61 100644 --- a/angular/src/directives/true-false-value.directive.ts +++ b/angular/src/directives/true-false-value.directive.ts @@ -1,54 +1,49 @@ -import { - Directive, - ElementRef, - forwardRef, - HostListener, - Input, - Renderer2, -} from '@angular/core'; -import { - ControlValueAccessor, - NgControl, - NG_VALUE_ACCESSOR, -} from '@angular/forms'; +import { Directive, ElementRef, forwardRef, HostListener, Input, Renderer2 } from "@angular/core"; +import { ControlValueAccessor, NgControl, NG_VALUE_ACCESSOR } from "@angular/forms"; // ref: https://juristr.com/blog/2018/02/ng-true-value-directive/ @Directive({ - selector: 'input[type=checkbox][appTrueFalseValue]', - providers: [ - { - provide: NG_VALUE_ACCESSOR, - useExisting: forwardRef(() => TrueFalseValueDirective), - multi: true, - }, - ], + selector: "input[type=checkbox][appTrueFalseValue]", + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => TrueFalseValueDirective), + multi: true, + }, + ], }) export class TrueFalseValueDirective implements ControlValueAccessor { - @Input() trueValue = true; - @Input() falseValue = false; + @Input() trueValue = true; + @Input() falseValue = false; - constructor(private elementRef: ElementRef, private renderer: Renderer2) { } + constructor(private elementRef: ElementRef, private renderer: Renderer2) {} - @HostListener('change', ['$event']) - onHostChange(ev: any) { - this.propagateChange(ev.target.checked ? this.trueValue : this.falseValue); + @HostListener("change", ["$event"]) + onHostChange(ev: any) { + this.propagateChange(ev.target.checked ? this.trueValue : this.falseValue); + } + + writeValue(obj: any): void { + if (obj === this.trueValue) { + this.renderer.setProperty(this.elementRef.nativeElement, "checked", true); + } else { + this.renderer.setProperty(this.elementRef.nativeElement, "checked", false); } + } - writeValue(obj: any): void { - if (obj === this.trueValue) { - this.renderer.setProperty(this.elementRef.nativeElement, 'checked', true); - } else { - this.renderer.setProperty(this.elementRef.nativeElement, 'checked', false); - } - } + registerOnChange(fn: any): void { + this.propagateChange = fn; + } - registerOnChange(fn: any): void { - this.propagateChange = fn; - } + registerOnTouched(fn: any): void { + /* nothing */ + } - registerOnTouched(fn: any): void { /* nothing */ } + setDisabledState?(isDisabled: boolean): void { + /* nothing */ + } - setDisabledState?(isDisabled: boolean): void { /* nothing */ } - - private propagateChange = (_: any) => { /* nothing */ }; + private propagateChange = (_: any) => { + /* nothing */ + }; } diff --git a/angular/src/pipes/color-password.pipe.ts b/angular/src/pipes/color-password.pipe.ts index a6b4d8ec..f3a87d12 100644 --- a/angular/src/pipes/color-password.pipe.ts +++ b/angular/src/pipes/color-password.pipe.ts @@ -1,53 +1,50 @@ -import { - Pipe, - PipeTransform, -} from '@angular/core'; -import { Utils } from 'jslib-common/misc/utils'; +import { Pipe, PipeTransform } from "@angular/core"; +import { Utils } from "jslib-common/misc/utils"; /* An updated pipe that sanitizes HTML, highlights numbers and special characters (in different colors each) and handles Unicode / Emoji characters correctly. */ -@Pipe({ name: 'colorPassword' }) +@Pipe({ name: "colorPassword" }) export class ColorPasswordPipe implements PipeTransform { - transform(password: string) { - // Convert to an array to handle cases that stings have special characters, ie: emoji. - const passwordArray = Array.from(password); - let colorizedPassword = ''; - for (let i = 0; i < passwordArray.length; i++) { - let character = passwordArray[i]; - let isSpecial = false; - // Sanitize HTML first. - switch (character) { - case '&': - character = '&'; - isSpecial = true; - break; - case '<': - character = '<'; - isSpecial = true; - break; - case '>': - character = '>'; - isSpecial = true; - break; - case ' ': - character = ' '; - isSpecial = true; - break; - default: - break; - } - let type = 'letter'; - if (character.match(Utils.regexpEmojiPresentation)) { - type = 'emoji'; - } else if (isSpecial || character.match(/[^\w ]/)) { - type = 'special'; - } else if (character.match(/\d/)) { - type = 'number'; - } - colorizedPassword += '' + character + ''; - } - return colorizedPassword; + transform(password: string) { + // Convert to an array to handle cases that stings have special characters, ie: emoji. + const passwordArray = Array.from(password); + let colorizedPassword = ""; + for (let i = 0; i < passwordArray.length; i++) { + let character = passwordArray[i]; + let isSpecial = false; + // Sanitize HTML first. + switch (character) { + case "&": + character = "&"; + isSpecial = true; + break; + case "<": + character = "<"; + isSpecial = true; + break; + case ">": + character = ">"; + isSpecial = true; + break; + case " ": + character = " "; + isSpecial = true; + break; + default: + break; + } + let type = "letter"; + if (character.match(Utils.regexpEmojiPresentation)) { + type = "emoji"; + } else if (isSpecial || character.match(/[^\w ]/)) { + type = "special"; + } else if (character.match(/\d/)) { + type = "number"; + } + colorizedPassword += '' + character + ""; } + return colorizedPassword; + } } diff --git a/angular/src/pipes/i18n.pipe.ts b/angular/src/pipes/i18n.pipe.ts index 4f3e470b..8fc09434 100644 --- a/angular/src/pipes/i18n.pipe.ts +++ b/angular/src/pipes/i18n.pipe.ts @@ -1,17 +1,14 @@ -import { - Pipe, - PipeTransform, -} from '@angular/core'; +import { Pipe, PipeTransform } from "@angular/core"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; @Pipe({ - name: 'i18n', + name: "i18n", }) export class I18nPipe implements PipeTransform { - constructor(private i18nService: I18nService) { } + constructor(private i18nService: I18nService) {} - transform(id: string, p1?: string, p2?: string, p3?: string): string { - return this.i18nService.t(id, p1, p2, p3); - } + transform(id: string, p1?: string, p2?: string, p3?: string): string { + return this.i18nService.t(id, p1, p2, p3); + } } diff --git a/angular/src/pipes/search-ciphers.pipe.ts b/angular/src/pipes/search-ciphers.pipe.ts index 92783f32..0842954c 100644 --- a/angular/src/pipes/search-ciphers.pipe.ts +++ b/angular/src/pipes/search-ciphers.pipe.ts @@ -1,44 +1,41 @@ -import { - Pipe, - PipeTransform, -} from '@angular/core'; +import { Pipe, PipeTransform } from "@angular/core"; -import { CipherView } from 'jslib-common/models/view/cipherView'; +import { CipherView } from "jslib-common/models/view/cipherView"; @Pipe({ - name: 'searchCiphers', + name: "searchCiphers", }) export class SearchCiphersPipe implements PipeTransform { - transform(ciphers: CipherView[], searchText: string, deleted: boolean = false): CipherView[] { - if (ciphers == null || ciphers.length === 0) { - return []; - } - - if (searchText == null || searchText.length < 2) { - return ciphers.filter(c => { - return deleted !== c.isDeleted; - }); - } - - searchText = searchText.trim().toLowerCase(); - return ciphers.filter(c => { - if (deleted !== c.isDeleted) { - return false; - } - if (c.name != null && c.name.toLowerCase().indexOf(searchText) > -1) { - return true; - } - if (searchText.length >= 8 && c.id.startsWith(searchText)) { - return true; - } - if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(searchText) > -1) { - return true; - } - if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(searchText) > -1) { - return true; - } - - return false; - }); + transform(ciphers: CipherView[], searchText: string, deleted: boolean = false): CipherView[] { + if (ciphers == null || ciphers.length === 0) { + return []; } + + if (searchText == null || searchText.length < 2) { + return ciphers.filter((c) => { + return deleted !== c.isDeleted; + }); + } + + searchText = searchText.trim().toLowerCase(); + return ciphers.filter((c) => { + if (deleted !== c.isDeleted) { + return false; + } + if (c.name != null && c.name.toLowerCase().indexOf(searchText) > -1) { + return true; + } + if (searchText.length >= 8 && c.id.startsWith(searchText)) { + return true; + } + if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(searchText) > -1) { + return true; + } + if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(searchText) > -1) { + return true; + } + + return false; + }); + } } diff --git a/angular/src/pipes/search.pipe.ts b/angular/src/pipes/search.pipe.ts index 6c9e140b..bf09d2de 100644 --- a/angular/src/pipes/search.pipe.ts +++ b/angular/src/pipes/search.pipe.ts @@ -1,33 +1,48 @@ -import { - Pipe, - PipeTransform, -} from '@angular/core'; +import { Pipe, PipeTransform } from "@angular/core"; @Pipe({ - name: 'search', + name: "search", }) export class SearchPipe implements PipeTransform { - transform(items: any[], searchText: string, prop1?: string, prop2?: string, prop3?: string): any[] { - if (items == null || items.length === 0) { - return []; - } - - if (searchText == null || searchText.length < 2) { - return items; - } - - searchText = searchText.trim().toLowerCase(); - return items.filter(i => { - if (prop1 != null && i[prop1] != null && i[prop1].toString().toLowerCase().indexOf(searchText) > -1) { - return true; - } - if (prop2 != null && i[prop2] != null && i[prop2].toString().toLowerCase().indexOf(searchText) > -1) { - return true; - } - if (prop3 != null && i[prop3] != null && i[prop3].toString().toLowerCase().indexOf(searchText) > -1) { - return true; - } - return false; - }); + transform( + items: any[], + searchText: string, + prop1?: string, + prop2?: string, + prop3?: string + ): any[] { + if (items == null || items.length === 0) { + return []; } + + if (searchText == null || searchText.length < 2) { + return items; + } + + searchText = searchText.trim().toLowerCase(); + return items.filter((i) => { + if ( + prop1 != null && + i[prop1] != null && + i[prop1].toString().toLowerCase().indexOf(searchText) > -1 + ) { + return true; + } + if ( + prop2 != null && + i[prop2] != null && + i[prop2].toString().toLowerCase().indexOf(searchText) > -1 + ) { + return true; + } + if ( + prop3 != null && + i[prop3] != null && + i[prop3].toString().toLowerCase().indexOf(searchText) > -1 + ) { + return true; + } + return false; + }); + } } diff --git a/angular/src/pipes/user-name.pipe.ts b/angular/src/pipes/user-name.pipe.ts index 43397528..22c214e4 100644 --- a/angular/src/pipes/user-name.pipe.ts +++ b/angular/src/pipes/user-name.pipe.ts @@ -1,22 +1,19 @@ -import { - Pipe, - PipeTransform, -} from '@angular/core'; +import { Pipe, PipeTransform } from "@angular/core"; interface User { - name?: string; - email: string; + name?: string; + email: string; } @Pipe({ - name: 'userName', + name: "userName", }) export class UserNamePipe implements PipeTransform { - transform(user?: User): string { - if (user == null) { - return null; - } - - return user.name == null || user.name.trim() === '' ? user.email : user.name; + transform(user?: User): string { + if (user == null) { + return null; } + + return user.name == null || user.name.trim() === "" ? user.email : user.name; + } } diff --git a/angular/src/scss/webfonts.css b/angular/src/scss/webfonts.css index c8a72d4b..fe9bb7e1 100644 --- a/angular/src/scss/webfonts.css +++ b/angular/src/scss/webfonts.css @@ -1,90 +1,89 @@ @font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 300; - font-display: auto; - src: url(webfonts/Open_Sans-italic-300.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: italic; + font-weight: 300; + font-display: auto; + src: url(webfonts/Open_Sans-italic-300.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 400; - font-display: auto; - src: url(webfonts/Open_Sans-italic-400.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: italic; + font-weight: 400; + font-display: auto; + src: url(webfonts/Open_Sans-italic-400.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 600; - font-display: auto; - src: url(webfonts/Open_Sans-italic-600.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: italic; + font-weight: 600; + font-display: auto; + src: url(webfonts/Open_Sans-italic-600.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 700; - font-display: auto; - src: url(webfonts/Open_Sans-italic-700.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: italic; + font-weight: 700; + font-display: auto; + src: url(webfonts/Open_Sans-italic-700.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: italic; - font-weight: 800; - font-display: auto; - src: url(webfonts/Open_Sans-italic-800.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: italic; + font-weight: 800; + font-display: auto; + src: url(webfonts/Open_Sans-italic-800.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 300; - font-display: auto; - src: url(webfonts/Open_Sans-normal-300.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: normal; + font-weight: 300; + font-display: auto; + src: url(webfonts/Open_Sans-normal-300.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 400; - font-display: auto; - src: url(webfonts/Open_Sans-normal-400.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: normal; + font-weight: 400; + font-display: auto; + src: url(webfonts/Open_Sans-normal-400.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 600; - font-display: auto; - src: url(webfonts/Open_Sans-normal-600.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: normal; + font-weight: 600; + font-display: auto; + src: url(webfonts/Open_Sans-normal-600.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 700; - font-display: auto; - src: url(webfonts/Open_Sans-normal-700.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: normal; + font-weight: 700; + font-display: auto; + src: url(webfonts/Open_Sans-normal-700.woff) format("woff"); + unicode-range: U+0-10FFFF; } @font-face { - font-family: 'Open Sans'; - font-style: normal; - font-weight: 800; - font-display: auto; - src: url(webfonts/Open_Sans-normal-800.woff) format('woff'); - unicode-range: U+0-10FFFF; + font-family: "Open Sans"; + font-style: normal; + font-weight: 800; + font-display: auto; + src: url(webfonts/Open_Sans-normal-800.woff) format("woff"); + unicode-range: U+0-10FFFF; } - diff --git a/angular/src/services/broadcaster.service.ts b/angular/src/services/broadcaster.service.ts index 6a9bdf9b..36218405 100644 --- a/angular/src/services/broadcaster.service.ts +++ b/angular/src/services/broadcaster.service.ts @@ -1,7 +1,6 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from "@angular/core"; -import { BroadcasterService as BaseBroadcasterService } from 'jslib-common/services/broadcaster.service'; +import { BroadcasterService as BaseBroadcasterService } from "jslib-common/services/broadcaster.service"; @Injectable() -export class BroadcasterService extends BaseBroadcasterService { -} +export class BroadcasterService extends BaseBroadcasterService {} diff --git a/angular/src/services/modal.service.ts b/angular/src/services/modal.service.ts index 9674cd1a..f487c579 100644 --- a/angular/src/services/modal.service.ts +++ b/angular/src/services/modal.service.ts @@ -1,164 +1,179 @@ import { - ApplicationRef, - ComponentFactory, - ComponentFactoryResolver, - ComponentRef, - EmbeddedViewRef, - Injectable, - Injector, - Type, - ViewContainerRef -} from '@angular/core'; -import { first } from 'rxjs/operators'; + ApplicationRef, + ComponentFactory, + ComponentFactoryResolver, + ComponentRef, + EmbeddedViewRef, + Injectable, + Injector, + Type, + ViewContainerRef, +} from "@angular/core"; +import { first } from "rxjs/operators"; -import { DynamicModalComponent } from '../components/modal/dynamic-modal.component'; -import { ModalInjector } from '../components/modal/modal-injector'; -import { ModalRef } from '../components/modal/modal.ref'; +import { DynamicModalComponent } from "../components/modal/dynamic-modal.component"; +import { ModalInjector } from "../components/modal/modal-injector"; +import { ModalRef } from "../components/modal/modal.ref"; export class ModalConfig { - data?: D; - allowMultipleModals: boolean = false; + data?: D; + allowMultipleModals: boolean = false; } @Injectable() export class ModalService { - protected modalList: ComponentRef[] = []; + protected modalList: ComponentRef[] = []; - // Lazy loaded modules are not available in componentFactoryResolver, - // therefore modules needs to manually initialize their resolvers. - private factoryResolvers: Map, ComponentFactoryResolver> = new Map(); + // Lazy loaded modules are not available in componentFactoryResolver, + // therefore modules needs to manually initialize their resolvers. + private factoryResolvers: Map, ComponentFactoryResolver> = new Map(); - constructor(private componentFactoryResolver: ComponentFactoryResolver, private applicationRef: ApplicationRef, - private injector: Injector) { - document.addEventListener('keyup', event => { - if (event.key === 'Escape' && this.modalCount > 0) { - this.topModal.instance.close(); - } + constructor( + private componentFactoryResolver: ComponentFactoryResolver, + private applicationRef: ApplicationRef, + private injector: Injector + ) { + document.addEventListener("keyup", (event) => { + if (event.key === "Escape" && this.modalCount > 0) { + this.topModal.instance.close(); + } + }); + } + + get modalCount() { + return this.modalList.length; + } + + private get topModal() { + return this.modalList[this.modalCount - 1]; + } + + async openViewRef( + componentType: Type, + viewContainerRef: ViewContainerRef, + setComponentParameters: (component: T) => void = null + ): Promise<[ModalRef, T]> { + const [modalRef, modalComponentRef] = this.openInternal(componentType, null, false); + modalComponentRef.instance.setComponentParameters = setComponentParameters; + + viewContainerRef.insert(modalComponentRef.hostView); + + await modalRef.onCreated.pipe(first()).toPromise(); + + return [modalRef, modalComponentRef.instance.componentRef.instance]; + } + + open(componentType: Type, config?: ModalConfig) { + if (!(config?.allowMultipleModals ?? false) && this.modalCount > 0) { + return; + } + + const [modalRef, _] = this.openInternal(componentType, config, true); + + return modalRef; + } + + registerComponentFactoryResolver( + componentType: Type, + componentFactoryResolver: ComponentFactoryResolver + ): void { + this.factoryResolvers.set(componentType, componentFactoryResolver); + } + + resolveComponentFactory(componentType: Type): ComponentFactory { + if (this.factoryResolvers.has(componentType)) { + return this.factoryResolvers.get(componentType).resolveComponentFactory(componentType); + } + + return this.componentFactoryResolver.resolveComponentFactory(componentType); + } + + protected openInternal( + componentType: Type, + config?: ModalConfig, + attachToDom?: boolean + ): [ModalRef, ComponentRef] { + const [modalRef, componentRef] = this.createModalComponent(config); + componentRef.instance.childComponentType = componentType; + + if (attachToDom) { + this.applicationRef.attachView(componentRef.hostView); + const domElem = (componentRef.hostView as EmbeddedViewRef).rootNodes[0] as HTMLElement; + document.body.appendChild(domElem); + } + + modalRef.onClosed.pipe(first()).subscribe(() => { + if (attachToDom) { + this.applicationRef.detachView(componentRef.hostView); + } + componentRef.destroy(); + + this.modalList.pop(); + if (this.modalCount > 0) { + this.topModal.instance.getFocus(); + } + }); + + this.setupHandlers(modalRef); + + this.modalList.push(componentRef); + + return [modalRef, componentRef]; + } + + protected setupHandlers(modalRef: ModalRef) { + let backdrop: HTMLElement = null; + + // Add backdrop, setup [data-dismiss] handler. + modalRef.onCreated.pipe(first()).subscribe((el) => { + document.body.classList.add("modal-open"); + + const modalEl: HTMLElement = el.querySelector(".modal"); + const dialogEl = modalEl.querySelector(".modal-dialog") as HTMLElement; + + backdrop = document.createElement("div"); + backdrop.className = "modal-backdrop fade"; + backdrop.style.zIndex = `${this.modalCount}040`; + modalEl.prepend(backdrop); + + dialogEl.addEventListener("click", (e: Event) => { + e.stopPropagation(); + }); + dialogEl.style.zIndex = `${this.modalCount}050`; + + const modals = Array.from( + el.querySelectorAll('.modal-backdrop, .modal *[data-dismiss="modal"]') + ); + for (const closeElement of modals) { + closeElement.addEventListener("click", (event) => { + modalRef.close(); }); - } + } + }); - get modalCount() { - return this.modalList.length; - } + // onClose is used in Web to hook into bootstrap. On other projects we pipe it directly to closed. + modalRef.onClose.pipe(first()).subscribe(() => { + modalRef.closed(); - private get topModal() { - return this.modalList[this.modalCount - 1]; - } + if (this.modalCount === 0) { + document.body.classList.remove("modal-open"); + } + }); + } - async openViewRef(componentType: Type, viewContainerRef: ViewContainerRef, - setComponentParameters: (component: T) => void = null): Promise<[ModalRef, T]> { + protected createModalComponent( + config: ModalConfig + ): [ModalRef, ComponentRef] { + const modalRef = new ModalRef(); - const [modalRef, modalComponentRef] = this.openInternal(componentType, null, false); - modalComponentRef.instance.setComponentParameters = setComponentParameters; + const map = new WeakMap(); + map.set(ModalConfig, config); + map.set(ModalRef, modalRef); - viewContainerRef.insert(modalComponentRef.hostView); + const componentFactory = + this.componentFactoryResolver.resolveComponentFactory(DynamicModalComponent); + const componentRef = componentFactory.create(new ModalInjector(this.injector, map)); - await modalRef.onCreated.pipe(first()).toPromise(); - - return [modalRef, modalComponentRef.instance.componentRef.instance]; - } - - open(componentType: Type, config?: ModalConfig) { - if (!(config?.allowMultipleModals ?? false) && this.modalCount > 0) { - return; - } - - const [modalRef, _] = this.openInternal(componentType, config, true); - - return modalRef; - } - - registerComponentFactoryResolver(componentType: Type, componentFactoryResolver: ComponentFactoryResolver): void { - this.factoryResolvers.set(componentType, componentFactoryResolver); - } - - resolveComponentFactory(componentType: Type): ComponentFactory { - if (this.factoryResolvers.has(componentType)) { - return this.factoryResolvers.get(componentType).resolveComponentFactory(componentType); - } - - return this.componentFactoryResolver.resolveComponentFactory(componentType); - } - - protected openInternal(componentType: Type, config?: ModalConfig, attachToDom?: boolean): - [ModalRef, ComponentRef] { - - const [modalRef, componentRef] = this.createModalComponent(config); - componentRef.instance.childComponentType = componentType; - - if (attachToDom) { - this.applicationRef.attachView(componentRef.hostView); - const domElem = (componentRef.hostView as EmbeddedViewRef).rootNodes[0] as HTMLElement; - document.body.appendChild(domElem); - } - - modalRef.onClosed.pipe(first()).subscribe(() => { - if (attachToDom) { - this.applicationRef.detachView(componentRef.hostView); - } - componentRef.destroy(); - - this.modalList.pop(); - if (this.modalCount > 0) { - this.topModal.instance.getFocus(); - } - }); - - this.setupHandlers(modalRef); - - this.modalList.push(componentRef); - - return [modalRef, componentRef]; - } - - protected setupHandlers(modalRef: ModalRef) { - let backdrop: HTMLElement = null; - - // Add backdrop, setup [data-dismiss] handler. - modalRef.onCreated.pipe(first()).subscribe(el => { - document.body.classList.add('modal-open'); - - const modalEl: HTMLElement = el.querySelector('.modal'); - const dialogEl = modalEl.querySelector('.modal-dialog') as HTMLElement; - - backdrop = document.createElement('div'); - backdrop.className = 'modal-backdrop fade'; - backdrop.style.zIndex = `${this.modalCount}040`; - modalEl.prepend(backdrop); - - dialogEl.addEventListener('click', (e: Event) => { - e.stopPropagation(); - }); - dialogEl.style.zIndex = `${this.modalCount}050`; - - const modals = Array.from(el.querySelectorAll('.modal-backdrop, .modal *[data-dismiss="modal"]')); - for (const closeElement of modals) { - closeElement.addEventListener('click', event => { - modalRef.close(); - }); - } - }); - - // onClose is used in Web to hook into bootstrap. On other projects we pipe it directly to closed. - modalRef.onClose.pipe(first()).subscribe(() => { - modalRef.closed(); - - if (this.modalCount === 0) { - document.body.classList.remove('modal-open'); - } - }); - } - - protected createModalComponent(config: ModalConfig): [ModalRef, ComponentRef] { - const modalRef = new ModalRef(); - - const map = new WeakMap(); - map.set(ModalConfig, config); - map.set(ModalRef, modalRef); - - const componentFactory = this.componentFactoryResolver.resolveComponentFactory(DynamicModalComponent); - const componentRef = componentFactory.create(new ModalInjector(this.injector, map)); - - return [modalRef, componentRef]; - } + return [modalRef, componentRef]; + } } diff --git a/angular/src/services/passwordReprompt.service.ts b/angular/src/services/passwordReprompt.service.ts index 03e04531..58ae5190 100644 --- a/angular/src/services/passwordReprompt.service.ts +++ b/angular/src/services/passwordReprompt.service.ts @@ -1,37 +1,40 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from "@angular/core"; -import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service'; -import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from 'jslib-common/abstractions/passwordReprompt.service'; +import { KeyConnectorService } from "jslib-common/abstractions/keyConnector.service"; +import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from "jslib-common/abstractions/passwordReprompt.service"; -import { PasswordRepromptComponent } from '../components/password-reprompt.component'; -import { ModalService } from './modal.service'; +import { PasswordRepromptComponent } from "../components/password-reprompt.component"; +import { ModalService } from "./modal.service"; @Injectable() export class PasswordRepromptService implements PasswordRepromptServiceAbstraction { - protected component = PasswordRepromptComponent; + protected component = PasswordRepromptComponent; - constructor(private modalService: ModalService, private keyConnectorService: KeyConnectorService) { } + constructor( + private modalService: ModalService, + private keyConnectorService: KeyConnectorService + ) {} - protectedFields() { - return ['TOTP', 'Password', 'H_Field', 'Card Number', 'Security Code']; + protectedFields() { + return ["TOTP", "Password", "H_Field", "Card Number", "Security Code"]; + } + + async showPasswordPrompt() { + if (!(await this.enabled())) { + return true; } - async showPasswordPrompt() { - if (!await this.enabled()) { - return true; - } + const ref = this.modalService.open(this.component, { allowMultipleModals: true }); - const ref = this.modalService.open(this.component, {allowMultipleModals: true}); - - if (ref == null) { - return false; - } - - const result = await ref.onClosedPromise(); - return result === true; + if (ref == null) { + return false; } - async enabled() { - return !await this.keyConnectorService.getUsesKeyConnector(); - } + const result = await ref.onClosedPromise(); + return result === true; + } + + async enabled() { + return !(await this.keyConnectorService.getUsesKeyConnector()); + } } diff --git a/angular/src/services/validation.service.ts b/angular/src/services/validation.service.ts index 1fa38119..9cb04b38 100644 --- a/angular/src/services/validation.service.ts +++ b/angular/src/services/validation.service.ts @@ -1,36 +1,39 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from "@angular/core"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { ErrorResponse } from 'jslib-common/models/response/errorResponse'; +import { ErrorResponse } from "jslib-common/models/response/errorResponse"; @Injectable() export class ValidationService { - constructor(private i18nService: I18nService, private platformUtilsService: PlatformUtilsService) { } + constructor( + private i18nService: I18nService, + private platformUtilsService: PlatformUtilsService + ) {} - showError(data: any): string[] { - const defaultErrorMessage = this.i18nService.t('unexpectedError'); - let errors: string[] = []; + showError(data: any): string[] { + const defaultErrorMessage = this.i18nService.t("unexpectedError"); + let errors: string[] = []; - if (data != null && typeof data === 'string') { - errors.push(data); - } else if (data == null || typeof data !== 'object') { - errors.push(defaultErrorMessage); - } else if (data.validationErrors != null) { - errors = errors.concat((data as ErrorResponse).getAllMessages()); - } else { - errors.push(data.message ? data.message : defaultErrorMessage); - } - - if (errors.length === 1) { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), errors[0]); - } else if (errors.length > 1) { - this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), errors, { - timeout: 5000 * errors.length, - }); - } - - return errors; + if (data != null && typeof data === "string") { + errors.push(data); + } else if (data == null || typeof data !== "object") { + errors.push(defaultErrorMessage); + } else if (data.validationErrors != null) { + errors = errors.concat((data as ErrorResponse).getAllMessages()); + } else { + errors.push(data.message ? data.message : defaultErrorMessage); } + + if (errors.length === 1) { + this.platformUtilsService.showToast("error", this.i18nService.t("errorOccurred"), errors[0]); + } else if (errors.length > 1) { + this.platformUtilsService.showToast("error", this.i18nService.t("errorOccurred"), errors, { + timeout: 5000 * errors.length, + }); + } + + return errors; + } } diff --git a/angular/tsconfig.json b/angular/tsconfig.json index 3d41e86c..36dffb93 100644 --- a/angular/tsconfig.json +++ b/angular/tsconfig.json @@ -14,17 +14,9 @@ "declarationDir": "dist/types", "outDir": "dist", "paths": { - "jslib-common/*": [ - "../common/src/*" - ] + "jslib-common/*": ["../common/src/*"] } }, - "include": [ - "src", - "spec" - ], - "exclude": [ - "node_modules", - "dist" - ] + "include": ["src", "spec"], + "exclude": ["node_modules", "dist"] } diff --git a/common/src/abstractions/api.service.ts b/common/src/abstractions/api.service.ts index 1c6aa0ef..ca648f0c 100644 --- a/common/src/abstractions/api.service.ts +++ b/common/src/abstractions/api.service.ts @@ -1,468 +1,677 @@ -import { PolicyType } from '../enums/policyType'; -import { SetKeyConnectorKeyRequest } from '../models/request/account/setKeyConnectorKeyRequest'; -import { VerifyOTPRequest } from '../models/request/account/verifyOTPRequest'; +import { PolicyType } from "../enums/policyType"; +import { SetKeyConnectorKeyRequest } from "../models/request/account/setKeyConnectorKeyRequest"; +import { VerifyOTPRequest } from "../models/request/account/verifyOTPRequest"; -import { AttachmentRequest } from '../models/request/attachmentRequest'; +import { AttachmentRequest } from "../models/request/attachmentRequest"; -import { BitPayInvoiceRequest } from '../models/request/bitPayInvoiceRequest'; -import { CipherBulkDeleteRequest } from '../models/request/cipherBulkDeleteRequest'; -import { CipherBulkMoveRequest } from '../models/request/cipherBulkMoveRequest'; -import { CipherBulkRestoreRequest } from '../models/request/cipherBulkRestoreRequest'; -import { CipherBulkShareRequest } from '../models/request/cipherBulkShareRequest'; -import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest'; -import { CipherCreateRequest } from '../models/request/cipherCreateRequest'; -import { CipherRequest } from '../models/request/cipherRequest'; -import { CipherShareRequest } from '../models/request/cipherShareRequest'; -import { CollectionRequest } from '../models/request/collectionRequest'; -import { DeleteRecoverRequest } from '../models/request/deleteRecoverRequest'; -import { EmailRequest } from '../models/request/emailRequest'; -import { EmailTokenRequest } from '../models/request/emailTokenRequest'; -import { EmergencyAccessAcceptRequest } from '../models/request/emergencyAccessAcceptRequest'; -import { EmergencyAccessConfirmRequest } from '../models/request/emergencyAccessConfirmRequest'; -import { EmergencyAccessInviteRequest } from '../models/request/emergencyAccessInviteRequest'; -import { EmergencyAccessPasswordRequest } from '../models/request/emergencyAccessPasswordRequest'; -import { EmergencyAccessUpdateRequest } from '../models/request/emergencyAccessUpdateRequest'; -import { EventRequest } from '../models/request/eventRequest'; -import { FolderRequest } from '../models/request/folderRequest'; -import { GroupRequest } from '../models/request/groupRequest'; -import { IapCheckRequest } from '../models/request/iapCheckRequest'; -import { ImportCiphersRequest } from '../models/request/importCiphersRequest'; -import { ImportDirectoryRequest } from '../models/request/importDirectoryRequest'; -import { ImportOrganizationCiphersRequest } from '../models/request/importOrganizationCiphersRequest'; -import { KdfRequest } from '../models/request/kdfRequest'; -import { KeyConnectorUserKeyRequest } from '../models/request/keyConnectorUserKeyRequest'; -import { KeysRequest } from '../models/request/keysRequest'; -import { OrganizationSponsorshipCreateRequest } from '../models/request/organization/organizationSponsorshipCreateRequest'; -import { OrganizationSponsorshipRedeemRequest } from '../models/request/organization/organizationSponsorshipRedeemRequest'; -import { OrganizationSsoRequest } from '../models/request/organization/organizationSsoRequest'; -import { OrganizationCreateRequest } from '../models/request/organizationCreateRequest'; -import { OrganizationImportRequest } from '../models/request/organizationImportRequest'; -import { OrganizationKeysRequest } from '../models/request/organizationKeysRequest'; -import { OrganizationSubscriptionUpdateRequest } from '../models/request/organizationSubscriptionUpdateRequest'; -import { OrganizationTaxInfoUpdateRequest } from '../models/request/organizationTaxInfoUpdateRequest'; -import { OrganizationUpdateRequest } from '../models/request/organizationUpdateRequest'; -import { OrganizationUpgradeRequest } from '../models/request/organizationUpgradeRequest'; -import { OrganizationUserAcceptRequest } from '../models/request/organizationUserAcceptRequest'; -import { OrganizationUserBulkConfirmRequest } from '../models/request/organizationUserBulkConfirmRequest'; -import { OrganizationUserBulkRequest } from '../models/request/organizationUserBulkRequest'; -import { OrganizationUserConfirmRequest } from '../models/request/organizationUserConfirmRequest'; -import { OrganizationUserInviteRequest } from '../models/request/organizationUserInviteRequest'; -import { OrganizationUserResetPasswordEnrollmentRequest } from '../models/request/organizationUserResetPasswordEnrollmentRequest'; -import { OrganizationUserResetPasswordRequest } from '../models/request/organizationUserResetPasswordRequest'; -import { OrganizationUserUpdateGroupsRequest } from '../models/request/organizationUserUpdateGroupsRequest'; -import { OrganizationUserUpdateRequest } from '../models/request/organizationUserUpdateRequest'; -import { PasswordHintRequest } from '../models/request/passwordHintRequest'; -import { PasswordRequest } from '../models/request/passwordRequest'; -import { PaymentRequest } from '../models/request/paymentRequest'; -import { PolicyRequest } from '../models/request/policyRequest'; -import { PreloginRequest } from '../models/request/preloginRequest'; -import { ProviderAddOrganizationRequest } from '../models/request/provider/providerAddOrganizationRequest'; -import { ProviderOrganizationCreateRequest } from '../models/request/provider/providerOrganizationCreateRequest'; -import { ProviderSetupRequest } from '../models/request/provider/providerSetupRequest'; -import { ProviderUpdateRequest } from '../models/request/provider/providerUpdateRequest'; -import { ProviderUserAcceptRequest } from '../models/request/provider/providerUserAcceptRequest'; -import { ProviderUserBulkConfirmRequest } from '../models/request/provider/providerUserBulkConfirmRequest'; -import { ProviderUserBulkRequest } from '../models/request/provider/providerUserBulkRequest'; -import { ProviderUserConfirmRequest } from '../models/request/provider/providerUserConfirmRequest'; -import { ProviderUserInviteRequest } from '../models/request/provider/providerUserInviteRequest'; -import { ProviderUserUpdateRequest } from '../models/request/provider/providerUserUpdateRequest'; -import { RegisterRequest } from '../models/request/registerRequest'; -import { SeatRequest } from '../models/request/seatRequest'; -import { SecretVerificationRequest } from '../models/request/secretVerificationRequest'; -import { SelectionReadOnlyRequest } from '../models/request/selectionReadOnlyRequest'; -import { SendAccessRequest } from '../models/request/sendAccessRequest'; -import { SendRequest } from '../models/request/sendRequest'; -import { SetPasswordRequest } from '../models/request/setPasswordRequest'; -import { StorageRequest } from '../models/request/storageRequest'; -import { TaxInfoUpdateRequest } from '../models/request/taxInfoUpdateRequest'; -import { TokenRequest } from '../models/request/tokenRequest'; -import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest'; -import { TwoFactorProviderRequest } from '../models/request/twoFactorProviderRequest'; -import { TwoFactorRecoveryRequest } from '../models/request/twoFactorRecoveryRequest'; -import { UpdateDomainsRequest } from '../models/request/updateDomainsRequest'; -import { UpdateKeyRequest } from '../models/request/updateKeyRequest'; -import { UpdateProfileRequest } from '../models/request/updateProfileRequest'; -import { UpdateTempPasswordRequest } from '../models/request/updateTempPasswordRequest'; -import { UpdateTwoFactorAuthenticatorRequest } from '../models/request/updateTwoFactorAuthenticatorRequest'; -import { UpdateTwoFactorDuoRequest } from '../models/request/updateTwoFactorDuoRequest'; -import { UpdateTwoFactorEmailRequest } from '../models/request/updateTwoFactorEmailRequest'; -import { UpdateTwoFactorWebAuthnDeleteRequest } from '../models/request/updateTwoFactorWebAuthnDeleteRequest'; -import { UpdateTwoFactorWebAuthnRequest } from '../models/request/updateTwoFactorWebAuthnRequest'; -import { UpdateTwoFactorYubioOtpRequest } from '../models/request/updateTwoFactorYubioOtpRequest'; -import { VerifyBankRequest } from '../models/request/verifyBankRequest'; -import { VerifyDeleteRecoverRequest } from '../models/request/verifyDeleteRecoverRequest'; -import { VerifyEmailRequest } from '../models/request/verifyEmailRequest'; +import { BitPayInvoiceRequest } from "../models/request/bitPayInvoiceRequest"; +import { CipherBulkDeleteRequest } from "../models/request/cipherBulkDeleteRequest"; +import { CipherBulkMoveRequest } from "../models/request/cipherBulkMoveRequest"; +import { CipherBulkRestoreRequest } from "../models/request/cipherBulkRestoreRequest"; +import { CipherBulkShareRequest } from "../models/request/cipherBulkShareRequest"; +import { CipherCollectionsRequest } from "../models/request/cipherCollectionsRequest"; +import { CipherCreateRequest } from "../models/request/cipherCreateRequest"; +import { CipherRequest } from "../models/request/cipherRequest"; +import { CipherShareRequest } from "../models/request/cipherShareRequest"; +import { CollectionRequest } from "../models/request/collectionRequest"; +import { DeleteRecoverRequest } from "../models/request/deleteRecoverRequest"; +import { EmailRequest } from "../models/request/emailRequest"; +import { EmailTokenRequest } from "../models/request/emailTokenRequest"; +import { EmergencyAccessAcceptRequest } from "../models/request/emergencyAccessAcceptRequest"; +import { EmergencyAccessConfirmRequest } from "../models/request/emergencyAccessConfirmRequest"; +import { EmergencyAccessInviteRequest } from "../models/request/emergencyAccessInviteRequest"; +import { EmergencyAccessPasswordRequest } from "../models/request/emergencyAccessPasswordRequest"; +import { EmergencyAccessUpdateRequest } from "../models/request/emergencyAccessUpdateRequest"; +import { EventRequest } from "../models/request/eventRequest"; +import { FolderRequest } from "../models/request/folderRequest"; +import { GroupRequest } from "../models/request/groupRequest"; +import { IapCheckRequest } from "../models/request/iapCheckRequest"; +import { ImportCiphersRequest } from "../models/request/importCiphersRequest"; +import { ImportDirectoryRequest } from "../models/request/importDirectoryRequest"; +import { ImportOrganizationCiphersRequest } from "../models/request/importOrganizationCiphersRequest"; +import { KdfRequest } from "../models/request/kdfRequest"; +import { KeyConnectorUserKeyRequest } from "../models/request/keyConnectorUserKeyRequest"; +import { KeysRequest } from "../models/request/keysRequest"; +import { OrganizationSponsorshipCreateRequest } from "../models/request/organization/organizationSponsorshipCreateRequest"; +import { OrganizationSponsorshipRedeemRequest } from "../models/request/organization/organizationSponsorshipRedeemRequest"; +import { OrganizationSsoRequest } from "../models/request/organization/organizationSsoRequest"; +import { OrganizationCreateRequest } from "../models/request/organizationCreateRequest"; +import { OrganizationImportRequest } from "../models/request/organizationImportRequest"; +import { OrganizationKeysRequest } from "../models/request/organizationKeysRequest"; +import { OrganizationSubscriptionUpdateRequest } from "../models/request/organizationSubscriptionUpdateRequest"; +import { OrganizationTaxInfoUpdateRequest } from "../models/request/organizationTaxInfoUpdateRequest"; +import { OrganizationUpdateRequest } from "../models/request/organizationUpdateRequest"; +import { OrganizationUpgradeRequest } from "../models/request/organizationUpgradeRequest"; +import { OrganizationUserAcceptRequest } from "../models/request/organizationUserAcceptRequest"; +import { OrganizationUserBulkConfirmRequest } from "../models/request/organizationUserBulkConfirmRequest"; +import { OrganizationUserBulkRequest } from "../models/request/organizationUserBulkRequest"; +import { OrganizationUserConfirmRequest } from "../models/request/organizationUserConfirmRequest"; +import { OrganizationUserInviteRequest } from "../models/request/organizationUserInviteRequest"; +import { OrganizationUserResetPasswordEnrollmentRequest } from "../models/request/organizationUserResetPasswordEnrollmentRequest"; +import { OrganizationUserResetPasswordRequest } from "../models/request/organizationUserResetPasswordRequest"; +import { OrganizationUserUpdateGroupsRequest } from "../models/request/organizationUserUpdateGroupsRequest"; +import { OrganizationUserUpdateRequest } from "../models/request/organizationUserUpdateRequest"; +import { PasswordHintRequest } from "../models/request/passwordHintRequest"; +import { PasswordRequest } from "../models/request/passwordRequest"; +import { PaymentRequest } from "../models/request/paymentRequest"; +import { PolicyRequest } from "../models/request/policyRequest"; +import { PreloginRequest } from "../models/request/preloginRequest"; +import { ProviderAddOrganizationRequest } from "../models/request/provider/providerAddOrganizationRequest"; +import { ProviderOrganizationCreateRequest } from "../models/request/provider/providerOrganizationCreateRequest"; +import { ProviderSetupRequest } from "../models/request/provider/providerSetupRequest"; +import { ProviderUpdateRequest } from "../models/request/provider/providerUpdateRequest"; +import { ProviderUserAcceptRequest } from "../models/request/provider/providerUserAcceptRequest"; +import { ProviderUserBulkConfirmRequest } from "../models/request/provider/providerUserBulkConfirmRequest"; +import { ProviderUserBulkRequest } from "../models/request/provider/providerUserBulkRequest"; +import { ProviderUserConfirmRequest } from "../models/request/provider/providerUserConfirmRequest"; +import { ProviderUserInviteRequest } from "../models/request/provider/providerUserInviteRequest"; +import { ProviderUserUpdateRequest } from "../models/request/provider/providerUserUpdateRequest"; +import { RegisterRequest } from "../models/request/registerRequest"; +import { SeatRequest } from "../models/request/seatRequest"; +import { SecretVerificationRequest } from "../models/request/secretVerificationRequest"; +import { SelectionReadOnlyRequest } from "../models/request/selectionReadOnlyRequest"; +import { SendAccessRequest } from "../models/request/sendAccessRequest"; +import { SendRequest } from "../models/request/sendRequest"; +import { SetPasswordRequest } from "../models/request/setPasswordRequest"; +import { StorageRequest } from "../models/request/storageRequest"; +import { TaxInfoUpdateRequest } from "../models/request/taxInfoUpdateRequest"; +import { TokenRequest } from "../models/request/tokenRequest"; +import { TwoFactorEmailRequest } from "../models/request/twoFactorEmailRequest"; +import { TwoFactorProviderRequest } from "../models/request/twoFactorProviderRequest"; +import { TwoFactorRecoveryRequest } from "../models/request/twoFactorRecoveryRequest"; +import { UpdateDomainsRequest } from "../models/request/updateDomainsRequest"; +import { UpdateKeyRequest } from "../models/request/updateKeyRequest"; +import { UpdateProfileRequest } from "../models/request/updateProfileRequest"; +import { UpdateTempPasswordRequest } from "../models/request/updateTempPasswordRequest"; +import { UpdateTwoFactorAuthenticatorRequest } from "../models/request/updateTwoFactorAuthenticatorRequest"; +import { UpdateTwoFactorDuoRequest } from "../models/request/updateTwoFactorDuoRequest"; +import { UpdateTwoFactorEmailRequest } from "../models/request/updateTwoFactorEmailRequest"; +import { UpdateTwoFactorWebAuthnDeleteRequest } from "../models/request/updateTwoFactorWebAuthnDeleteRequest"; +import { UpdateTwoFactorWebAuthnRequest } from "../models/request/updateTwoFactorWebAuthnRequest"; +import { UpdateTwoFactorYubioOtpRequest } from "../models/request/updateTwoFactorYubioOtpRequest"; +import { VerifyBankRequest } from "../models/request/verifyBankRequest"; +import { VerifyDeleteRecoverRequest } from "../models/request/verifyDeleteRecoverRequest"; +import { VerifyEmailRequest } from "../models/request/verifyEmailRequest"; -import { ApiKeyResponse } from '../models/response/apiKeyResponse'; -import { AttachmentResponse } from '../models/response/attachmentResponse'; -import { AttachmentUploadDataResponse } from '../models/response/attachmentUploadDataResponse'; -import { BillingResponse } from '../models/response/billingResponse'; -import { BreachAccountResponse } from '../models/response/breachAccountResponse'; -import { CipherResponse } from '../models/response/cipherResponse'; +import { ApiKeyResponse } from "../models/response/apiKeyResponse"; +import { AttachmentResponse } from "../models/response/attachmentResponse"; +import { AttachmentUploadDataResponse } from "../models/response/attachmentUploadDataResponse"; +import { BillingResponse } from "../models/response/billingResponse"; +import { BreachAccountResponse } from "../models/response/breachAccountResponse"; +import { CipherResponse } from "../models/response/cipherResponse"; import { - CollectionGroupDetailsResponse, - CollectionResponse, -} from '../models/response/collectionResponse'; -import { DomainsResponse } from '../models/response/domainsResponse'; + CollectionGroupDetailsResponse, + CollectionResponse, +} from "../models/response/collectionResponse"; +import { DomainsResponse } from "../models/response/domainsResponse"; import { - EmergencyAccessGranteeDetailsResponse, - EmergencyAccessGrantorDetailsResponse, - EmergencyAccessTakeoverResponse, - EmergencyAccessViewResponse -} from '../models/response/emergencyAccessResponse'; -import { EventResponse } from '../models/response/eventResponse'; -import { FolderResponse } from '../models/response/folderResponse'; + EmergencyAccessGranteeDetailsResponse, + EmergencyAccessGrantorDetailsResponse, + EmergencyAccessTakeoverResponse, + EmergencyAccessViewResponse, +} from "../models/response/emergencyAccessResponse"; +import { EventResponse } from "../models/response/eventResponse"; +import { FolderResponse } from "../models/response/folderResponse"; +import { GroupDetailsResponse, GroupResponse } from "../models/response/groupResponse"; +import { IdentityCaptchaResponse } from "../models/response/identityCaptchaResponse"; +import { IdentityTokenResponse } from "../models/response/identityTokenResponse"; +import { IdentityTwoFactorResponse } from "../models/response/identityTwoFactorResponse"; +import { KeyConnectorUserKeyResponse } from "../models/response/keyConnectorUserKeyResponse"; +import { ListResponse } from "../models/response/listResponse"; +import { OrganizationSsoResponse } from "../models/response/organization/organizationSsoResponse"; +import { OrganizationAutoEnrollStatusResponse } from "../models/response/organizationAutoEnrollStatusResponse"; +import { OrganizationKeysResponse } from "../models/response/organizationKeysResponse"; +import { OrganizationResponse } from "../models/response/organizationResponse"; +import { OrganizationSubscriptionResponse } from "../models/response/organizationSubscriptionResponse"; +import { OrganizationUserBulkPublicKeyResponse } from "../models/response/organizationUserBulkPublicKeyResponse"; +import { OrganizationUserBulkResponse } from "../models/response/organizationUserBulkResponse"; import { - GroupDetailsResponse, - GroupResponse, -} from '../models/response/groupResponse'; -import { IdentityCaptchaResponse } from '../models/response/identityCaptchaResponse'; -import { IdentityTokenResponse } from '../models/response/identityTokenResponse'; -import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse'; -import { KeyConnectorUserKeyResponse } from '../models/response/keyConnectorUserKeyResponse'; -import { ListResponse } from '../models/response/listResponse'; -import { OrganizationSsoResponse } from '../models/response/organization/organizationSsoResponse'; -import { OrganizationAutoEnrollStatusResponse } from '../models/response/organizationAutoEnrollStatusResponse'; -import { OrganizationKeysResponse } from '../models/response/organizationKeysResponse'; -import { OrganizationResponse } from '../models/response/organizationResponse'; -import { OrganizationSubscriptionResponse } from '../models/response/organizationSubscriptionResponse'; -import { OrganizationUserBulkPublicKeyResponse } from '../models/response/organizationUserBulkPublicKeyResponse'; -import { OrganizationUserBulkResponse } from '../models/response/organizationUserBulkResponse'; + OrganizationUserDetailsResponse, + OrganizationUserResetPasswordDetailsReponse, + OrganizationUserUserDetailsResponse, +} from "../models/response/organizationUserResponse"; +import { PaymentResponse } from "../models/response/paymentResponse"; +import { PlanResponse } from "../models/response/planResponse"; +import { PolicyResponse } from "../models/response/policyResponse"; +import { PreloginResponse } from "../models/response/preloginResponse"; +import { ProfileResponse } from "../models/response/profileResponse"; import { - OrganizationUserDetailsResponse, - OrganizationUserResetPasswordDetailsReponse, - OrganizationUserUserDetailsResponse, -} from '../models/response/organizationUserResponse'; -import { PaymentResponse } from '../models/response/paymentResponse'; -import { PlanResponse } from '../models/response/planResponse'; -import { PolicyResponse } from '../models/response/policyResponse'; -import { PreloginResponse } from '../models/response/preloginResponse'; -import { ProfileResponse } from '../models/response/profileResponse'; -import { ProviderOrganizationOrganizationDetailsResponse, ProviderOrganizationResponse } from '../models/response/provider/providerOrganizationResponse'; -import { ProviderResponse } from '../models/response/provider/providerResponse'; -import { ProviderUserBulkPublicKeyResponse } from '../models/response/provider/providerUserBulkPublicKeyResponse'; -import { ProviderUserBulkResponse } from '../models/response/provider/providerUserBulkResponse'; -import { ProviderUserResponse, ProviderUserUserDetailsResponse } from '../models/response/provider/providerUserResponse'; -import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse'; -import { SendAccessResponse } from '../models/response/sendAccessResponse'; -import { SendFileDownloadDataResponse } from '../models/response/sendFileDownloadDataResponse'; -import { SendFileUploadDataResponse } from '../models/response/sendFileUploadDataResponse'; -import { SendResponse } from '../models/response/sendResponse'; -import { SubscriptionResponse } from '../models/response/subscriptionResponse'; -import { SyncResponse } from '../models/response/syncResponse'; -import { TaxInfoResponse } from '../models/response/taxInfoResponse'; -import { TaxRateResponse } from '../models/response/taxRateResponse'; -import { TwoFactorAuthenticatorResponse } from '../models/response/twoFactorAuthenticatorResponse'; -import { TwoFactorDuoResponse } from '../models/response/twoFactorDuoResponse'; -import { TwoFactorEmailResponse } from '../models/response/twoFactorEmailResponse'; -import { TwoFactorProviderResponse } from '../models/response/twoFactorProviderResponse'; -import { TwoFactorRecoverResponse } from '../models/response/twoFactorRescoverResponse'; -import { ChallengeResponse, TwoFactorWebAuthnResponse } from '../models/response/twoFactorWebAuthnResponse'; -import { TwoFactorYubiKeyResponse } from '../models/response/twoFactorYubiKeyResponse'; -import { UserKeyResponse } from '../models/response/userKeyResponse'; + ProviderOrganizationOrganizationDetailsResponse, + ProviderOrganizationResponse, +} from "../models/response/provider/providerOrganizationResponse"; +import { ProviderResponse } from "../models/response/provider/providerResponse"; +import { ProviderUserBulkPublicKeyResponse } from "../models/response/provider/providerUserBulkPublicKeyResponse"; +import { ProviderUserBulkResponse } from "../models/response/provider/providerUserBulkResponse"; +import { + ProviderUserResponse, + ProviderUserUserDetailsResponse, +} from "../models/response/provider/providerUserResponse"; +import { SelectionReadOnlyResponse } from "../models/response/selectionReadOnlyResponse"; +import { SendAccessResponse } from "../models/response/sendAccessResponse"; +import { SendFileDownloadDataResponse } from "../models/response/sendFileDownloadDataResponse"; +import { SendFileUploadDataResponse } from "../models/response/sendFileUploadDataResponse"; +import { SendResponse } from "../models/response/sendResponse"; +import { SubscriptionResponse } from "../models/response/subscriptionResponse"; +import { SyncResponse } from "../models/response/syncResponse"; +import { TaxInfoResponse } from "../models/response/taxInfoResponse"; +import { TaxRateResponse } from "../models/response/taxRateResponse"; +import { TwoFactorAuthenticatorResponse } from "../models/response/twoFactorAuthenticatorResponse"; +import { TwoFactorDuoResponse } from "../models/response/twoFactorDuoResponse"; +import { TwoFactorEmailResponse } from "../models/response/twoFactorEmailResponse"; +import { TwoFactorProviderResponse } from "../models/response/twoFactorProviderResponse"; +import { TwoFactorRecoverResponse } from "../models/response/twoFactorRescoverResponse"; +import { + ChallengeResponse, + TwoFactorWebAuthnResponse, +} from "../models/response/twoFactorWebAuthnResponse"; +import { TwoFactorYubiKeyResponse } from "../models/response/twoFactorYubiKeyResponse"; +import { UserKeyResponse } from "../models/response/userKeyResponse"; -import { SendAccessView } from '../models/view/sendAccessView'; +import { SendAccessView } from "../models/view/sendAccessView"; export abstract class ApiService { - postIdentityToken: (request: TokenRequest) => Promise; - refreshIdentityToken: () => Promise; + postIdentityToken: ( + request: TokenRequest + ) => Promise; + refreshIdentityToken: () => Promise; - getProfile: () => Promise; - getUserBilling: () => Promise; - getUserSubscription: () => Promise; - getTaxInfo: () => Promise; - putProfile: (request: UpdateProfileRequest) => Promise; - putTaxInfo: (request: TaxInfoUpdateRequest) => Promise; - postPrelogin: (request: PreloginRequest) => Promise; - postEmailToken: (request: EmailTokenRequest) => Promise; - postEmail: (request: EmailRequest) => Promise; - postPassword: (request: PasswordRequest) => Promise; - setPassword: (request: SetPasswordRequest) => Promise; - postSetKeyConnectorKey: (request: SetKeyConnectorKeyRequest) => Promise; - postSecurityStamp: (request: SecretVerificationRequest) => Promise; - deleteAccount: (request: SecretVerificationRequest) => Promise; - getAccountRevisionDate: () => Promise; - postPasswordHint: (request: PasswordHintRequest) => Promise; - postRegister: (request: RegisterRequest) => Promise; - postPremium: (data: FormData) => Promise; - postIapCheck: (request: IapCheckRequest) => Promise; - postReinstatePremium: () => Promise; - postCancelPremium: () => Promise; - postAccountStorage: (request: StorageRequest) => Promise; - postAccountPayment: (request: PaymentRequest) => Promise; - postAccountLicense: (data: FormData) => Promise; - postAccountKey: (request: UpdateKeyRequest) => Promise; - postAccountKeys: (request: KeysRequest) => Promise; - postAccountVerifyEmail: () => Promise; - postAccountVerifyEmailToken: (request: VerifyEmailRequest) => Promise; - postAccountVerifyPassword: (request: SecretVerificationRequest) => Promise; - postAccountRecoverDelete: (request: DeleteRecoverRequest) => Promise; - postAccountRecoverDeleteToken: (request: VerifyDeleteRecoverRequest) => Promise; - postAccountKdf: (request: KdfRequest) => Promise; - postUserApiKey: (id: string, request: SecretVerificationRequest) => Promise; - postUserRotateApiKey: (id: string, request: SecretVerificationRequest) => Promise; - putUpdateTempPassword: (request: UpdateTempPasswordRequest) => Promise; - postAccountRequestOTP: () => Promise; - postAccountVerifyOTP: (request: VerifyOTPRequest) => Promise; - postConvertToKeyConnector: () => Promise; + getProfile: () => Promise; + getUserBilling: () => Promise; + getUserSubscription: () => Promise; + getTaxInfo: () => Promise; + putProfile: (request: UpdateProfileRequest) => Promise; + putTaxInfo: (request: TaxInfoUpdateRequest) => Promise; + postPrelogin: (request: PreloginRequest) => Promise; + postEmailToken: (request: EmailTokenRequest) => Promise; + postEmail: (request: EmailRequest) => Promise; + postPassword: (request: PasswordRequest) => Promise; + setPassword: (request: SetPasswordRequest) => Promise; + postSetKeyConnectorKey: (request: SetKeyConnectorKeyRequest) => Promise; + postSecurityStamp: (request: SecretVerificationRequest) => Promise; + deleteAccount: (request: SecretVerificationRequest) => Promise; + getAccountRevisionDate: () => Promise; + postPasswordHint: (request: PasswordHintRequest) => Promise; + postRegister: (request: RegisterRequest) => Promise; + postPremium: (data: FormData) => Promise; + postIapCheck: (request: IapCheckRequest) => Promise; + postReinstatePremium: () => Promise; + postCancelPremium: () => Promise; + postAccountStorage: (request: StorageRequest) => Promise; + postAccountPayment: (request: PaymentRequest) => Promise; + postAccountLicense: (data: FormData) => Promise; + postAccountKey: (request: UpdateKeyRequest) => Promise; + postAccountKeys: (request: KeysRequest) => Promise; + postAccountVerifyEmail: () => Promise; + postAccountVerifyEmailToken: (request: VerifyEmailRequest) => Promise; + postAccountVerifyPassword: (request: SecretVerificationRequest) => Promise; + postAccountRecoverDelete: (request: DeleteRecoverRequest) => Promise; + postAccountRecoverDeleteToken: (request: VerifyDeleteRecoverRequest) => Promise; + postAccountKdf: (request: KdfRequest) => Promise; + postUserApiKey: (id: string, request: SecretVerificationRequest) => Promise; + postUserRotateApiKey: (id: string, request: SecretVerificationRequest) => Promise; + putUpdateTempPassword: (request: UpdateTempPasswordRequest) => Promise; + postAccountRequestOTP: () => Promise; + postAccountVerifyOTP: (request: VerifyOTPRequest) => Promise; + postConvertToKeyConnector: () => Promise; - getFolder: (id: string) => Promise; - postFolder: (request: FolderRequest) => Promise; - putFolder: (id: string, request: FolderRequest) => Promise; - deleteFolder: (id: string) => Promise; + getFolder: (id: string) => Promise; + postFolder: (request: FolderRequest) => Promise; + putFolder: (id: string, request: FolderRequest) => Promise; + deleteFolder: (id: string) => Promise; - getSend: (id: string) => Promise; - postSendAccess: (id: string, request: SendAccessRequest, apiUrl?: string) => Promise; - getSends: () => Promise>; - postSend: (request: SendRequest) => Promise; - postFileTypeSend: (request: SendRequest) => Promise; - postSendFile: (sendId: string, fileId: string, data: FormData) => Promise; - /** - * @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads. - * This method still exists for backward compatibility with old server versions. - */ - postSendFileLegacy: (data: FormData) => Promise; - putSend: (id: string, request: SendRequest) => Promise; - putSendRemovePassword: (id: string) => Promise; - deleteSend: (id: string) => Promise; - getSendFileDownloadData: (send: SendAccessView, request: SendAccessRequest, apiUrl?: string) => Promise; - renewSendFileUploadUrl: (sendId: string, fileId: string) => Promise; + getSend: (id: string) => Promise; + postSendAccess: ( + id: string, + request: SendAccessRequest, + apiUrl?: string + ) => Promise; + getSends: () => Promise>; + postSend: (request: SendRequest) => Promise; + postFileTypeSend: (request: SendRequest) => Promise; + postSendFile: (sendId: string, fileId: string, data: FormData) => Promise; + /** + * @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads. + * This method still exists for backward compatibility with old server versions. + */ + postSendFileLegacy: (data: FormData) => Promise; + putSend: (id: string, request: SendRequest) => Promise; + putSendRemovePassword: (id: string) => Promise; + deleteSend: (id: string) => Promise; + getSendFileDownloadData: ( + send: SendAccessView, + request: SendAccessRequest, + apiUrl?: string + ) => Promise; + renewSendFileUploadUrl: (sendId: string, fileId: string) => Promise; - getCipher: (id: string) => Promise; - getCipherAdmin: (id: string) => Promise; - getAttachmentData: (cipherId: string, attachmentId: string, emergencyAccessId?: string) => Promise; - getCiphersOrganization: (organizationId: string) => Promise>; - postCipher: (request: CipherRequest) => Promise; - postCipherCreate: (request: CipherCreateRequest) => Promise; - postCipherAdmin: (request: CipherCreateRequest) => Promise; - putCipher: (id: string, request: CipherRequest) => Promise; - putCipherAdmin: (id: string, request: CipherRequest) => Promise; - deleteCipher: (id: string) => Promise; - deleteCipherAdmin: (id: string) => Promise; - deleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise; - deleteManyCiphersAdmin: (request: CipherBulkDeleteRequest) => Promise; - putMoveCiphers: (request: CipherBulkMoveRequest) => Promise; - putShareCipher: (id: string, request: CipherShareRequest) => Promise; - putShareCiphers: (request: CipherBulkShareRequest) => Promise; - putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise; - putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise; - postPurgeCiphers: (request: SecretVerificationRequest, organizationId?: string) => Promise; - postImportCiphers: (request: ImportCiphersRequest) => Promise; - postImportOrganizationCiphers: (organizationId: string, request: ImportOrganizationCiphersRequest) => Promise; - putDeleteCipher: (id: string) => Promise; - putDeleteCipherAdmin: (id: string) => Promise; - putDeleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise; - putDeleteManyCiphersAdmin: (request: CipherBulkDeleteRequest) => Promise; - putRestoreCipher: (id: string) => Promise; - putRestoreCipherAdmin: (id: string) => Promise; - putRestoreManyCiphers: (request: CipherBulkRestoreRequest) => Promise>; + getCipher: (id: string) => Promise; + getCipherAdmin: (id: string) => Promise; + getAttachmentData: ( + cipherId: string, + attachmentId: string, + emergencyAccessId?: string + ) => Promise; + getCiphersOrganization: (organizationId: string) => Promise>; + postCipher: (request: CipherRequest) => Promise; + postCipherCreate: (request: CipherCreateRequest) => Promise; + postCipherAdmin: (request: CipherCreateRequest) => Promise; + putCipher: (id: string, request: CipherRequest) => Promise; + putCipherAdmin: (id: string, request: CipherRequest) => Promise; + deleteCipher: (id: string) => Promise; + deleteCipherAdmin: (id: string) => Promise; + deleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise; + deleteManyCiphersAdmin: (request: CipherBulkDeleteRequest) => Promise; + putMoveCiphers: (request: CipherBulkMoveRequest) => Promise; + putShareCipher: (id: string, request: CipherShareRequest) => Promise; + putShareCiphers: (request: CipherBulkShareRequest) => Promise; + putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise; + putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise; + postPurgeCiphers: (request: SecretVerificationRequest, organizationId?: string) => Promise; + postImportCiphers: (request: ImportCiphersRequest) => Promise; + postImportOrganizationCiphers: ( + organizationId: string, + request: ImportOrganizationCiphersRequest + ) => Promise; + putDeleteCipher: (id: string) => Promise; + putDeleteCipherAdmin: (id: string) => Promise; + putDeleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise; + putDeleteManyCiphersAdmin: (request: CipherBulkDeleteRequest) => Promise; + putRestoreCipher: (id: string) => Promise; + putRestoreCipherAdmin: (id: string) => Promise; + putRestoreManyCiphers: ( + request: CipherBulkRestoreRequest + ) => Promise>; - /** - * @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads. - * This method still exists for backward compatibility with old server versions. - */ - postCipherAttachmentLegacy: (id: string, data: FormData) => Promise; - /** - * @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads. - * This method still exists for backward compatibility with old server versions. - */ - postCipherAttachmentAdminLegacy: (id: string, data: FormData) => Promise; - postCipherAttachment: (id: string, request: AttachmentRequest) => Promise; - deleteCipherAttachment: (id: string, attachmentId: string) => Promise; - deleteCipherAttachmentAdmin: (id: string, attachmentId: string) => Promise; - postShareCipherAttachment: (id: string, attachmentId: string, data: FormData, - organizationId: string) => Promise; - renewAttachmentUploadUrl: (id: string, attachmentId: string) => Promise; - postAttachmentFile: (id: string, attachmentId: string, data: FormData) => Promise; + /** + * @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads. + * This method still exists for backward compatibility with old server versions. + */ + postCipherAttachmentLegacy: (id: string, data: FormData) => Promise; + /** + * @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads. + * This method still exists for backward compatibility with old server versions. + */ + postCipherAttachmentAdminLegacy: (id: string, data: FormData) => Promise; + postCipherAttachment: ( + id: string, + request: AttachmentRequest + ) => Promise; + deleteCipherAttachment: (id: string, attachmentId: string) => Promise; + deleteCipherAttachmentAdmin: (id: string, attachmentId: string) => Promise; + postShareCipherAttachment: ( + id: string, + attachmentId: string, + data: FormData, + organizationId: string + ) => Promise; + renewAttachmentUploadUrl: ( + id: string, + attachmentId: string + ) => Promise; + postAttachmentFile: (id: string, attachmentId: string, data: FormData) => Promise; - getCollectionDetails: (organizationId: string, id: string) => Promise; - getUserCollections: () => Promise>; - getCollections: (organizationId: string) => Promise>; - getCollectionUsers: (organizationId: string, id: string) => Promise; - postCollection: (organizationId: string, request: CollectionRequest) => Promise; - putCollectionUsers: (organizationId: string, id: string, request: SelectionReadOnlyRequest[]) => Promise; - putCollection: (organizationId: string, id: string, request: CollectionRequest) => Promise; - deleteCollection: (organizationId: string, id: string) => Promise; - deleteCollectionUser: (organizationId: string, id: string, organizationUserId: string) => Promise; + getCollectionDetails: ( + organizationId: string, + id: string + ) => Promise; + getUserCollections: () => Promise>; + getCollections: (organizationId: string) => Promise>; + getCollectionUsers: (organizationId: string, id: string) => Promise; + postCollection: ( + organizationId: string, + request: CollectionRequest + ) => Promise; + putCollectionUsers: ( + organizationId: string, + id: string, + request: SelectionReadOnlyRequest[] + ) => Promise; + putCollection: ( + organizationId: string, + id: string, + request: CollectionRequest + ) => Promise; + deleteCollection: (organizationId: string, id: string) => Promise; + deleteCollectionUser: ( + organizationId: string, + id: string, + organizationUserId: string + ) => Promise; - getGroupDetails: (organizationId: string, id: string) => Promise; - getGroups: (organizationId: string) => Promise>; - getGroupUsers: (organizationId: string, id: string) => Promise; - postGroup: (organizationId: string, request: GroupRequest) => Promise; - putGroup: (organizationId: string, id: string, request: GroupRequest) => Promise; - putGroupUsers: (organizationId: string, id: string, request: string[]) => Promise; - deleteGroup: (organizationId: string, id: string) => Promise; - deleteGroupUser: (organizationId: string, id: string, organizationUserId: string) => Promise; + getGroupDetails: (organizationId: string, id: string) => Promise; + getGroups: (organizationId: string) => Promise>; + getGroupUsers: (organizationId: string, id: string) => Promise; + postGroup: (organizationId: string, request: GroupRequest) => Promise; + putGroup: (organizationId: string, id: string, request: GroupRequest) => Promise; + putGroupUsers: (organizationId: string, id: string, request: string[]) => Promise; + deleteGroup: (organizationId: string, id: string) => Promise; + deleteGroupUser: (organizationId: string, id: string, organizationUserId: string) => Promise; - getPolicy: (organizationId: string, type: PolicyType) => Promise; - getPolicies: (organizationId: string) => Promise>; - getPoliciesByToken: (organizationId: string, token: string, email: string, organizationUserId: string) => - Promise>; - putPolicy: (organizationId: string, type: PolicyType, request: PolicyRequest) => Promise; + getPolicy: (organizationId: string, type: PolicyType) => Promise; + getPolicies: (organizationId: string) => Promise>; + getPoliciesByToken: ( + organizationId: string, + token: string, + email: string, + organizationUserId: string + ) => Promise>; + putPolicy: ( + organizationId: string, + type: PolicyType, + request: PolicyRequest + ) => Promise; - getOrganizationUser: (organizationId: string, id: string) => Promise; - getOrganizationUserGroups: (organizationId: string, id: string) => Promise; - getOrganizationUsers: (organizationId: string) => Promise>; - getOrganizationUserResetPasswordDetails: (organizationId: string, id: string) - => Promise; - postOrganizationUserInvite: (organizationId: string, request: OrganizationUserInviteRequest) => Promise; - postOrganizationUserReinvite: (organizationId: string, id: string) => Promise; - postManyOrganizationUserReinvite: (organizationId: string, request: OrganizationUserBulkRequest) => Promise>; - postOrganizationUserAccept: (organizationId: string, id: string, - request: OrganizationUserAcceptRequest) => Promise; - postOrganizationUserConfirm: (organizationId: string, id: string, - request: OrganizationUserConfirmRequest) => Promise; - postOrganizationUsersPublicKey: (organizationId: string, request: OrganizationUserBulkRequest) => - Promise>; - postOrganizationUserBulkConfirm: (organizationId: string, request: OrganizationUserBulkConfirmRequest) => Promise>; + getOrganizationUser: ( + organizationId: string, + id: string + ) => Promise; + getOrganizationUserGroups: (organizationId: string, id: string) => Promise; + getOrganizationUsers: ( + organizationId: string + ) => Promise>; + getOrganizationUserResetPasswordDetails: ( + organizationId: string, + id: string + ) => Promise; + postOrganizationUserInvite: ( + organizationId: string, + request: OrganizationUserInviteRequest + ) => Promise; + postOrganizationUserReinvite: (organizationId: string, id: string) => Promise; + postManyOrganizationUserReinvite: ( + organizationId: string, + request: OrganizationUserBulkRequest + ) => Promise>; + postOrganizationUserAccept: ( + organizationId: string, + id: string, + request: OrganizationUserAcceptRequest + ) => Promise; + postOrganizationUserConfirm: ( + organizationId: string, + id: string, + request: OrganizationUserConfirmRequest + ) => Promise; + postOrganizationUsersPublicKey: ( + organizationId: string, + request: OrganizationUserBulkRequest + ) => Promise>; + postOrganizationUserBulkConfirm: ( + organizationId: string, + request: OrganizationUserBulkConfirmRequest + ) => Promise>; - putOrganizationUser: (organizationId: string, id: string, request: OrganizationUserUpdateRequest) => Promise; - putOrganizationUserGroups: (organizationId: string, id: string, - request: OrganizationUserUpdateGroupsRequest) => Promise; - putOrganizationUserResetPasswordEnrollment: (organizationId: string, userId: string, - request: OrganizationUserResetPasswordEnrollmentRequest) => Promise; - putOrganizationUserResetPassword: (organizationId: string, id: string, - request: OrganizationUserResetPasswordRequest) => Promise; - deleteOrganizationUser: (organizationId: string, id: string) => Promise; - deleteManyOrganizationUsers: (organizationId: string, request: OrganizationUserBulkRequest) => Promise>; + putOrganizationUser: ( + organizationId: string, + id: string, + request: OrganizationUserUpdateRequest + ) => Promise; + putOrganizationUserGroups: ( + organizationId: string, + id: string, + request: OrganizationUserUpdateGroupsRequest + ) => Promise; + putOrganizationUserResetPasswordEnrollment: ( + organizationId: string, + userId: string, + request: OrganizationUserResetPasswordEnrollmentRequest + ) => Promise; + putOrganizationUserResetPassword: ( + organizationId: string, + id: string, + request: OrganizationUserResetPasswordRequest + ) => Promise; + deleteOrganizationUser: (organizationId: string, id: string) => Promise; + deleteManyOrganizationUsers: ( + organizationId: string, + request: OrganizationUserBulkRequest + ) => Promise>; - getSync: () => Promise; - postImportDirectory: (organizationId: string, request: ImportDirectoryRequest) => Promise; - postPublicImportDirectory: (request: OrganizationImportRequest) => Promise; + getSync: () => Promise; + postImportDirectory: (organizationId: string, request: ImportDirectoryRequest) => Promise; + postPublicImportDirectory: (request: OrganizationImportRequest) => Promise; - getSettingsDomains: () => Promise; - putSettingsDomains: (request: UpdateDomainsRequest) => Promise; + getSettingsDomains: () => Promise; + putSettingsDomains: (request: UpdateDomainsRequest) => Promise; - getTwoFactorProviders: () => Promise>; - getTwoFactorOrganizationProviders: (organizationId: string) => Promise>; - getTwoFactorAuthenticator: (request: SecretVerificationRequest) => Promise; - getTwoFactorEmail: (request: SecretVerificationRequest) => Promise; - getTwoFactorDuo: (request: SecretVerificationRequest) => Promise; - getTwoFactorOrganizationDuo: (organizationId: string, - request: SecretVerificationRequest) => Promise; - getTwoFactorYubiKey: (request: SecretVerificationRequest) => Promise; - getTwoFactorWebAuthn: (request: SecretVerificationRequest) => Promise; - getTwoFactorWebAuthnChallenge: (request: SecretVerificationRequest) => Promise; - getTwoFactorRecover: (request: SecretVerificationRequest) => Promise; - putTwoFactorAuthenticator: ( - request: UpdateTwoFactorAuthenticatorRequest) => Promise; - putTwoFactorEmail: (request: UpdateTwoFactorEmailRequest) => Promise; - putTwoFactorDuo: (request: UpdateTwoFactorDuoRequest) => Promise; - putTwoFactorOrganizationDuo: (organizationId: string, - request: UpdateTwoFactorDuoRequest) => Promise; - putTwoFactorYubiKey: (request: UpdateTwoFactorYubioOtpRequest) => Promise; - putTwoFactorWebAuthn: (request: UpdateTwoFactorWebAuthnRequest) => Promise; - deleteTwoFactorWebAuthn: (request: UpdateTwoFactorWebAuthnDeleteRequest) => Promise; - putTwoFactorDisable: (request: TwoFactorProviderRequest) => Promise; - putTwoFactorOrganizationDisable: (organizationId: string, - request: TwoFactorProviderRequest) => Promise; - postTwoFactorRecover: (request: TwoFactorRecoveryRequest) => Promise; - postTwoFactorEmailSetup: (request: TwoFactorEmailRequest) => Promise; - postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise; + getTwoFactorProviders: () => Promise>; + getTwoFactorOrganizationProviders: ( + organizationId: string + ) => Promise>; + getTwoFactorAuthenticator: ( + request: SecretVerificationRequest + ) => Promise; + getTwoFactorEmail: (request: SecretVerificationRequest) => Promise; + getTwoFactorDuo: (request: SecretVerificationRequest) => Promise; + getTwoFactorOrganizationDuo: ( + organizationId: string, + request: SecretVerificationRequest + ) => Promise; + getTwoFactorYubiKey: (request: SecretVerificationRequest) => Promise; + getTwoFactorWebAuthn: (request: SecretVerificationRequest) => Promise; + getTwoFactorWebAuthnChallenge: (request: SecretVerificationRequest) => Promise; + getTwoFactorRecover: (request: SecretVerificationRequest) => Promise; + putTwoFactorAuthenticator: ( + request: UpdateTwoFactorAuthenticatorRequest + ) => Promise; + putTwoFactorEmail: (request: UpdateTwoFactorEmailRequest) => Promise; + putTwoFactorDuo: (request: UpdateTwoFactorDuoRequest) => Promise; + putTwoFactorOrganizationDuo: ( + organizationId: string, + request: UpdateTwoFactorDuoRequest + ) => Promise; + putTwoFactorYubiKey: ( + request: UpdateTwoFactorYubioOtpRequest + ) => Promise; + putTwoFactorWebAuthn: ( + request: UpdateTwoFactorWebAuthnRequest + ) => Promise; + deleteTwoFactorWebAuthn: ( + request: UpdateTwoFactorWebAuthnDeleteRequest + ) => Promise; + putTwoFactorDisable: (request: TwoFactorProviderRequest) => Promise; + putTwoFactorOrganizationDisable: ( + organizationId: string, + request: TwoFactorProviderRequest + ) => Promise; + postTwoFactorRecover: (request: TwoFactorRecoveryRequest) => Promise; + postTwoFactorEmailSetup: (request: TwoFactorEmailRequest) => Promise; + postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise; - getEmergencyAccessTrusted: () => Promise>; - getEmergencyAccessGranted: () => Promise>; - getEmergencyAccess: (id: string) => Promise; - getEmergencyGrantorPolicies: (id: string) => Promise>; - putEmergencyAccess: (id: string, request: EmergencyAccessUpdateRequest) => Promise; - deleteEmergencyAccess: (id: string) => Promise; - postEmergencyAccessInvite: (request: EmergencyAccessInviteRequest) => Promise; - postEmergencyAccessReinvite: (id: string) => Promise; - postEmergencyAccessAccept: (id: string, request: EmergencyAccessAcceptRequest) => Promise; - postEmergencyAccessConfirm: (id: string, request: EmergencyAccessConfirmRequest) => Promise; - postEmergencyAccessInitiate: (id: string) => Promise; - postEmergencyAccessApprove: (id: string) => Promise; - postEmergencyAccessReject: (id: string) => Promise; - postEmergencyAccessTakeover: (id: string) => Promise; - postEmergencyAccessPassword: (id: string, request: EmergencyAccessPasswordRequest) => Promise; - postEmergencyAccessView: (id: string) => Promise; + getEmergencyAccessTrusted: () => Promise>; + getEmergencyAccessGranted: () => Promise>; + getEmergencyAccess: (id: string) => Promise; + getEmergencyGrantorPolicies: (id: string) => Promise>; + putEmergencyAccess: (id: string, request: EmergencyAccessUpdateRequest) => Promise; + deleteEmergencyAccess: (id: string) => Promise; + postEmergencyAccessInvite: (request: EmergencyAccessInviteRequest) => Promise; + postEmergencyAccessReinvite: (id: string) => Promise; + postEmergencyAccessAccept: (id: string, request: EmergencyAccessAcceptRequest) => Promise; + postEmergencyAccessConfirm: (id: string, request: EmergencyAccessConfirmRequest) => Promise; + postEmergencyAccessInitiate: (id: string) => Promise; + postEmergencyAccessApprove: (id: string) => Promise; + postEmergencyAccessReject: (id: string) => Promise; + postEmergencyAccessTakeover: (id: string) => Promise; + postEmergencyAccessPassword: ( + id: string, + request: EmergencyAccessPasswordRequest + ) => Promise; + postEmergencyAccessView: (id: string) => Promise; - getOrganization: (id: string) => Promise; - getOrganizationBilling: (id: string) => Promise; - getOrganizationSubscription: (id: string) => Promise; - getOrganizationLicense: (id: string, installationId: string) => Promise; - getOrganizationTaxInfo: (id: string) => Promise; - getOrganizationAutoEnrollStatus: (identifier: string) => Promise; - getOrganizationSso: (id: string) => Promise; - postOrganization: (request: OrganizationCreateRequest) => Promise; - putOrganization: (id: string, request: OrganizationUpdateRequest) => Promise; - putOrganizationTaxInfo: (id: string, request: OrganizationTaxInfoUpdateRequest) => Promise; - postLeaveOrganization: (id: string) => Promise; - postOrganizationLicense: (data: FormData) => Promise; - postOrganizationLicenseUpdate: (id: string, data: FormData) => Promise; - postOrganizationApiKey: (id: string, request: SecretVerificationRequest) => Promise; - postOrganizationRotateApiKey: (id: string, request: SecretVerificationRequest) => Promise; - postOrganizationSso: (id: string, request: OrganizationSsoRequest) => Promise; - postOrganizationUpgrade: (id: string, request: OrganizationUpgradeRequest) => Promise; - postOrganizationUpdateSubscription: (id: string, request: OrganizationSubscriptionUpdateRequest) => Promise; - postOrganizationSeat: (id: string, request: SeatRequest) => Promise; - postOrganizationStorage: (id: string, request: StorageRequest) => Promise; - postOrganizationPayment: (id: string, request: PaymentRequest) => Promise; - postOrganizationVerifyBank: (id: string, request: VerifyBankRequest) => Promise; - postOrganizationCancel: (id: string) => Promise; - postOrganizationReinstate: (id: string) => Promise; - deleteOrganization: (id: string, request: SecretVerificationRequest) => Promise; - getPlans: () => Promise>; - getTaxRates: () => Promise>; - getOrganizationKeys: (id: string) => Promise; - postOrganizationKeys: (id: string, request: OrganizationKeysRequest) => Promise; + getOrganization: (id: string) => Promise; + getOrganizationBilling: (id: string) => Promise; + getOrganizationSubscription: (id: string) => Promise; + getOrganizationLicense: (id: string, installationId: string) => Promise; + getOrganizationTaxInfo: (id: string) => Promise; + getOrganizationAutoEnrollStatus: ( + identifier: string + ) => Promise; + getOrganizationSso: (id: string) => Promise; + postOrganization: (request: OrganizationCreateRequest) => Promise; + putOrganization: ( + id: string, + request: OrganizationUpdateRequest + ) => Promise; + putOrganizationTaxInfo: (id: string, request: OrganizationTaxInfoUpdateRequest) => Promise; + postLeaveOrganization: (id: string) => Promise; + postOrganizationLicense: (data: FormData) => Promise; + postOrganizationLicenseUpdate: (id: string, data: FormData) => Promise; + postOrganizationApiKey: ( + id: string, + request: SecretVerificationRequest + ) => Promise; + postOrganizationRotateApiKey: ( + id: string, + request: SecretVerificationRequest + ) => Promise; + postOrganizationSso: ( + id: string, + request: OrganizationSsoRequest + ) => Promise; + postOrganizationUpgrade: ( + id: string, + request: OrganizationUpgradeRequest + ) => Promise; + postOrganizationUpdateSubscription: ( + id: string, + request: OrganizationSubscriptionUpdateRequest + ) => Promise; + postOrganizationSeat: (id: string, request: SeatRequest) => Promise; + postOrganizationStorage: (id: string, request: StorageRequest) => Promise; + postOrganizationPayment: (id: string, request: PaymentRequest) => Promise; + postOrganizationVerifyBank: (id: string, request: VerifyBankRequest) => Promise; + postOrganizationCancel: (id: string) => Promise; + postOrganizationReinstate: (id: string) => Promise; + deleteOrganization: (id: string, request: SecretVerificationRequest) => Promise; + getPlans: () => Promise>; + getTaxRates: () => Promise>; + getOrganizationKeys: (id: string) => Promise; + postOrganizationKeys: ( + id: string, + request: OrganizationKeysRequest + ) => Promise; - postProviderSetup: (id: string, request: ProviderSetupRequest) => Promise; - getProvider: (id: string) => Promise; - putProvider: (id: string, request: ProviderUpdateRequest) => Promise; + postProviderSetup: (id: string, request: ProviderSetupRequest) => Promise; + getProvider: (id: string) => Promise; + putProvider: (id: string, request: ProviderUpdateRequest) => Promise; - getProviderUsers: (providerId: string) => Promise>; - getProviderUser: (providerId: string, id: string) => Promise; - postProviderUserInvite: (providerId: string, request: ProviderUserInviteRequest) => Promise; - postProviderUserReinvite: (providerId: string, id: string) => Promise; - postManyProviderUserReinvite: (providerId: string, request: ProviderUserBulkRequest) => Promise>; - postProviderUserAccept: (providerId: string, id: string, request: ProviderUserAcceptRequest) => Promise; - postProviderUserConfirm: (providerId: string, id: string, request: ProviderUserConfirmRequest) => Promise; - postProviderUsersPublicKey: (providerId: string, request: ProviderUserBulkRequest) => - Promise>; - postProviderUserBulkConfirm: (providerId: string, request: ProviderUserBulkConfirmRequest) => Promise>; - putProviderUser: (providerId: string, id: string, request: ProviderUserUpdateRequest) => Promise; - deleteProviderUser: (organizationId: string, id: string) => Promise; - deleteManyProviderUsers: (providerId: string, request: ProviderUserBulkRequest) => Promise>; - getProviderClients: (providerId: string) => Promise>; - postProviderAddOrganization: (providerId: string, request: ProviderAddOrganizationRequest) => Promise; - postProviderCreateOrganization: (providerId: string, request: ProviderOrganizationCreateRequest) => Promise; - deleteProviderOrganization: (providerId: string, organizationId: string) => Promise; + getProviderUsers: (providerId: string) => Promise>; + getProviderUser: (providerId: string, id: string) => Promise; + postProviderUserInvite: (providerId: string, request: ProviderUserInviteRequest) => Promise; + postProviderUserReinvite: (providerId: string, id: string) => Promise; + postManyProviderUserReinvite: ( + providerId: string, + request: ProviderUserBulkRequest + ) => Promise>; + postProviderUserAccept: ( + providerId: string, + id: string, + request: ProviderUserAcceptRequest + ) => Promise; + postProviderUserConfirm: ( + providerId: string, + id: string, + request: ProviderUserConfirmRequest + ) => Promise; + postProviderUsersPublicKey: ( + providerId: string, + request: ProviderUserBulkRequest + ) => Promise>; + postProviderUserBulkConfirm: ( + providerId: string, + request: ProviderUserBulkConfirmRequest + ) => Promise>; + putProviderUser: ( + providerId: string, + id: string, + request: ProviderUserUpdateRequest + ) => Promise; + deleteProviderUser: (organizationId: string, id: string) => Promise; + deleteManyProviderUsers: ( + providerId: string, + request: ProviderUserBulkRequest + ) => Promise>; + getProviderClients: ( + providerId: string + ) => Promise>; + postProviderAddOrganization: ( + providerId: string, + request: ProviderAddOrganizationRequest + ) => Promise; + postProviderCreateOrganization: ( + providerId: string, + request: ProviderOrganizationCreateRequest + ) => Promise; + deleteProviderOrganization: (providerId: string, organizationId: string) => Promise; - getEvents: (start: string, end: string, token: string) => Promise>; - getEventsCipher: (id: string, start: string, end: string, token: string) => Promise>; - getEventsOrganization: (id: string, start: string, end: string, - token: string) => Promise>; - getEventsOrganizationUser: (organizationId: string, id: string, - start: string, end: string, token: string) => Promise>; - getEventsProvider: (id: string, start: string, end: string, token: string) => Promise>; - getEventsProviderUser: (providerId: string, id: string, start: string, end: string, token: string) => Promise>; - postEventsCollect: (request: EventRequest[]) => Promise; + getEvents: (start: string, end: string, token: string) => Promise>; + getEventsCipher: ( + id: string, + start: string, + end: string, + token: string + ) => Promise>; + getEventsOrganization: ( + id: string, + start: string, + end: string, + token: string + ) => Promise>; + getEventsOrganizationUser: ( + organizationId: string, + id: string, + start: string, + end: string, + token: string + ) => Promise>; + getEventsProvider: ( + id: string, + start: string, + end: string, + token: string + ) => Promise>; + getEventsProviderUser: ( + providerId: string, + id: string, + start: string, + end: string, + token: string + ) => Promise>; + postEventsCollect: (request: EventRequest[]) => Promise; - deleteSsoUser: (organizationId: string) => Promise; - getSsoUserIdentifier: () => Promise; + deleteSsoUser: (organizationId: string) => Promise; + getSsoUserIdentifier: () => Promise; - getUserPublicKey: (id: string) => Promise; + getUserPublicKey: (id: string) => Promise; - getHibpBreach: (username: string) => Promise; + getHibpBreach: (username: string) => Promise; - postBitPayInvoice: (request: BitPayInvoiceRequest) => Promise; - postSetupPayment: () => Promise; + postBitPayInvoice: (request: BitPayInvoiceRequest) => Promise; + postSetupPayment: () => Promise; - getActiveBearerToken: () => Promise; - fetch: (request: Request) => Promise; - nativeFetch: (request: Request) => Promise; + getActiveBearerToken: () => Promise; + fetch: (request: Request) => Promise; + nativeFetch: (request: Request) => Promise; - preValidateSso: (identifier: string) => Promise; + preValidateSso: (identifier: string) => Promise; - postCreateSponsorship: (sponsorshipOrgId: string, request: OrganizationSponsorshipCreateRequest) => Promise; - deleteRevokeSponsorship: (sponsoringOrganizationId: string) => Promise; - deleteRemoveSponsorship: (sponsoringOrgId: string) => Promise; - postPreValidateSponsorshipToken: (sponsorshipToken: string) => Promise; - postRedeemSponsorship: (sponsorshipToken: string, request: OrganizationSponsorshipRedeemRequest) => Promise; - postResendSponsorshipOffer: (sponsoringOrgId: string) => Promise; + postCreateSponsorship: ( + sponsorshipOrgId: string, + request: OrganizationSponsorshipCreateRequest + ) => Promise; + deleteRevokeSponsorship: (sponsoringOrganizationId: string) => Promise; + deleteRemoveSponsorship: (sponsoringOrgId: string) => Promise; + postPreValidateSponsorshipToken: (sponsorshipToken: string) => Promise; + postRedeemSponsorship: ( + sponsorshipToken: string, + request: OrganizationSponsorshipRedeemRequest + ) => Promise; + postResendSponsorshipOffer: (sponsoringOrgId: string) => Promise; - getUserKeyFromKeyConnector: (keyConnectorUrl: string) => Promise; - postUserKeyToKeyConnector: (keyConnectorUrl: string, request: KeyConnectorUserKeyRequest) => Promise; - getKeyConnectorAlive: (keyConnectorUrl: string) => Promise; + getUserKeyFromKeyConnector: (keyConnectorUrl: string) => Promise; + postUserKeyToKeyConnector: ( + keyConnectorUrl: string, + request: KeyConnectorUserKeyRequest + ) => Promise; + getKeyConnectorAlive: (keyConnectorUrl: string) => Promise; } diff --git a/common/src/abstractions/appId.service.ts b/common/src/abstractions/appId.service.ts index d087478a..99bc6c9e 100644 --- a/common/src/abstractions/appId.service.ts +++ b/common/src/abstractions/appId.service.ts @@ -1,4 +1,4 @@ export abstract class AppIdService { - getAppId: () => Promise; - getAnonymousAppId: () => Promise; + getAppId: () => Promise; + getAnonymousAppId: () => Promise; } diff --git a/common/src/abstractions/audit.service.ts b/common/src/abstractions/audit.service.ts index b8c40bc2..6b6b81f6 100644 --- a/common/src/abstractions/audit.service.ts +++ b/common/src/abstractions/audit.service.ts @@ -1,6 +1,6 @@ -import { BreachAccountResponse } from '../models/response/breachAccountResponse'; +import { BreachAccountResponse } from "../models/response/breachAccountResponse"; export abstract class AuditService { - passwordLeaked: (password: string) => Promise; - breachedAccounts: (username: string) => Promise; + passwordLeaked: (password: string) => Promise; + breachedAccounts: (username: string) => Promise; } diff --git a/common/src/abstractions/auth.service.ts b/common/src/abstractions/auth.service.ts index 58f72fc7..10dff3a8 100644 --- a/common/src/abstractions/auth.service.ts +++ b/common/src/abstractions/auth.service.ts @@ -1,35 +1,60 @@ -import { TwoFactorProviderType } from '../enums/twoFactorProviderType'; +import { TwoFactorProviderType } from "../enums/twoFactorProviderType"; -import { AuthResult } from '../models/domain/authResult'; -import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey'; +import { AuthResult } from "../models/domain/authResult"; +import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey"; export abstract class AuthService { - email: string; - masterPasswordHash: string; - code: string; - codeVerifier: string; - ssoRedirectUrl: string; - clientId: string; - clientSecret: string; - twoFactorProvidersData: Map; - selectedTwoFactorProviderType: TwoFactorProviderType; + email: string; + masterPasswordHash: string; + code: string; + codeVerifier: string; + ssoRedirectUrl: string; + clientId: string; + clientSecret: string; + twoFactorProvidersData: Map; + selectedTwoFactorProviderType: TwoFactorProviderType; - logIn: (email: string, masterPassword: string, captchaToken?: string) => Promise; - logInSso: (code: string, codeVerifier: string, redirectUrl: string, orgId: string) => Promise; - logInApiKey: (clientId: string, clientSecret: string) => Promise; - logInTwoFactor: (twoFactorProvider: TwoFactorProviderType, twoFactorToken: string, - remember?: boolean) => Promise; - logInComplete: (email: string, masterPassword: string, twoFactorProvider: TwoFactorProviderType, - twoFactorToken: string, remember?: boolean, captchaToken?: string) => Promise; - logInSsoComplete: (code: string, codeVerifier: string, redirectUrl: string, - twoFactorProvider: TwoFactorProviderType, twoFactorToken: string, remember?: boolean) => Promise; - logInApiKeyComplete: (clientId: string, clientSecret: string, twoFactorProvider: TwoFactorProviderType, - twoFactorToken: string, remember?: boolean) => Promise; - logOut: (callback: Function) => void; - getSupportedTwoFactorProviders: (win: Window) => any[]; - getDefaultTwoFactorProvider: (webAuthnSupported: boolean) => TwoFactorProviderType; - makePreloginKey: (masterPassword: string, email: string) => Promise; - authingWithApiKey: () => boolean; - authingWithSso: () => boolean; - authingWithPassword: () => boolean; + logIn: (email: string, masterPassword: string, captchaToken?: string) => Promise; + logInSso: ( + code: string, + codeVerifier: string, + redirectUrl: string, + orgId: string + ) => Promise; + logInApiKey: (clientId: string, clientSecret: string) => Promise; + logInTwoFactor: ( + twoFactorProvider: TwoFactorProviderType, + twoFactorToken: string, + remember?: boolean + ) => Promise; + logInComplete: ( + email: string, + masterPassword: string, + twoFactorProvider: TwoFactorProviderType, + twoFactorToken: string, + remember?: boolean, + captchaToken?: string + ) => Promise; + logInSsoComplete: ( + code: string, + codeVerifier: string, + redirectUrl: string, + twoFactorProvider: TwoFactorProviderType, + twoFactorToken: string, + remember?: boolean + ) => Promise; + logInApiKeyComplete: ( + clientId: string, + clientSecret: string, + twoFactorProvider: TwoFactorProviderType, + twoFactorToken: string, + remember?: boolean + ) => Promise; + logOut: (callback: Function) => void; + getSupportedTwoFactorProviders: (win: Window) => any[]; + getDefaultTwoFactorProvider: (webAuthnSupported: boolean) => TwoFactorProviderType; + makePreloginKey: (masterPassword: string, email: string) => Promise; + authingWithApiKey: () => boolean; + authingWithSso: () => boolean; + authingWithPassword: () => boolean; } diff --git a/common/src/abstractions/biometric.main.ts b/common/src/abstractions/biometric.main.ts index 65a4eb5c..a8557c40 100644 --- a/common/src/abstractions/biometric.main.ts +++ b/common/src/abstractions/biometric.main.ts @@ -1,6 +1,6 @@ export abstract class BiometricMain { - isError: boolean; - init: () => Promise; - supportsBiometric: () => Promise; - authenticateBiometric: () => Promise; + isError: boolean; + init: () => Promise; + supportsBiometric: () => Promise; + authenticateBiometric: () => Promise; } diff --git a/common/src/abstractions/broadcaster.service.ts b/common/src/abstractions/broadcaster.service.ts index 9d0c8de9..1b9d0899 100644 --- a/common/src/abstractions/broadcaster.service.ts +++ b/common/src/abstractions/broadcaster.service.ts @@ -1,5 +1,5 @@ export abstract class BroadcasterService { - send: (message: any, id?: string) => void; - subscribe: (id: string, messageCallback: (message: any) => any) => void; - unsubscribe: (id: string) => void; + send: (message: any, id?: string) => void; + subscribe: (id: string, messageCallback: (message: any) => any) => void; + unsubscribe: (id: string) => void; } diff --git a/common/src/abstractions/cryptoFunction.service.ts b/common/src/abstractions/cryptoFunction.service.ts index 7573050c..21ed33cb 100644 --- a/common/src/abstractions/cryptoFunction.service.ts +++ b/common/src/abstractions/cryptoFunction.service.ts @@ -1,27 +1,62 @@ -import { DecryptParameters } from '../models/domain/decryptParameters'; -import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey'; +import { DecryptParameters } from "../models/domain/decryptParameters"; +import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey"; export abstract class CryptoFunctionService { - pbkdf2: (password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512', - iterations: number) => Promise; - hkdf: (ikm: ArrayBuffer, salt: string | ArrayBuffer, info: string | ArrayBuffer, - outputByteSize: number, algorithm: 'sha256' | 'sha512') => Promise; - hkdfExpand: (prk: ArrayBuffer, info: string | ArrayBuffer, outputByteSize: number, - algorithm: 'sha256' | 'sha512') => Promise; - hash: (value: string | ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512' | 'md5') => Promise; - hmac: (value: ArrayBuffer, key: ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512') => Promise; - compare: (a: ArrayBuffer, b: ArrayBuffer) => Promise; - hmacFast: (value: ArrayBuffer | string, key: ArrayBuffer | string, algorithm: 'sha1' | 'sha256' | 'sha512') => - Promise; - compareFast: (a: ArrayBuffer | string, b: ArrayBuffer | string) => Promise; - aesEncrypt: (data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer) => Promise; - aesDecryptFastParameters: (data: string, iv: string, mac: string, key: SymmetricCryptoKey) => - DecryptParameters; - aesDecryptFast: (parameters: DecryptParameters) => Promise; - aesDecrypt: (data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer) => Promise; - rsaEncrypt: (data: ArrayBuffer, publicKey: ArrayBuffer, algorithm: 'sha1' | 'sha256') => Promise; - rsaDecrypt: (data: ArrayBuffer, privateKey: ArrayBuffer, algorithm: 'sha1' | 'sha256') => Promise; - rsaExtractPublicKey: (privateKey: ArrayBuffer) => Promise; - rsaGenerateKeyPair: (length: 1024 | 2048 | 4096) => Promise<[ArrayBuffer, ArrayBuffer]>; - randomBytes: (length: number) => Promise; + pbkdf2: ( + password: string | ArrayBuffer, + salt: string | ArrayBuffer, + algorithm: "sha256" | "sha512", + iterations: number + ) => Promise; + hkdf: ( + ikm: ArrayBuffer, + salt: string | ArrayBuffer, + info: string | ArrayBuffer, + outputByteSize: number, + algorithm: "sha256" | "sha512" + ) => Promise; + hkdfExpand: ( + prk: ArrayBuffer, + info: string | ArrayBuffer, + outputByteSize: number, + algorithm: "sha256" | "sha512" + ) => Promise; + hash: ( + value: string | ArrayBuffer, + algorithm: "sha1" | "sha256" | "sha512" | "md5" + ) => Promise; + hmac: ( + value: ArrayBuffer, + key: ArrayBuffer, + algorithm: "sha1" | "sha256" | "sha512" + ) => Promise; + compare: (a: ArrayBuffer, b: ArrayBuffer) => Promise; + hmacFast: ( + value: ArrayBuffer | string, + key: ArrayBuffer | string, + algorithm: "sha1" | "sha256" | "sha512" + ) => Promise; + compareFast: (a: ArrayBuffer | string, b: ArrayBuffer | string) => Promise; + aesEncrypt: (data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer) => Promise; + aesDecryptFastParameters: ( + data: string, + iv: string, + mac: string, + key: SymmetricCryptoKey + ) => DecryptParameters; + aesDecryptFast: (parameters: DecryptParameters) => Promise; + aesDecrypt: (data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer) => Promise; + rsaEncrypt: ( + data: ArrayBuffer, + publicKey: ArrayBuffer, + algorithm: "sha1" | "sha256" + ) => Promise; + rsaDecrypt: ( + data: ArrayBuffer, + privateKey: ArrayBuffer, + algorithm: "sha1" | "sha256" + ) => Promise; + rsaExtractPublicKey: (privateKey: ArrayBuffer) => Promise; + rsaGenerateKeyPair: (length: 1024 | 2048 | 4096) => Promise<[ArrayBuffer, ArrayBuffer]>; + randomBytes: (length: number) => Promise; } diff --git a/common/src/abstractions/environment.service.ts b/common/src/abstractions/environment.service.ts index db335016..97daeba2 100644 --- a/common/src/abstractions/environment.service.ts +++ b/common/src/abstractions/environment.service.ts @@ -1,34 +1,34 @@ -import { Observable } from 'rxjs'; +import { Observable } from "rxjs"; export type Urls = { - base?: string; - webVault?: string; - api?: string; - identity?: string; - icons?: string; - notifications?: string; - events?: string; - keyConnector?: string; + base?: string; + webVault?: string; + api?: string; + identity?: string; + icons?: string; + notifications?: string; + events?: string; + keyConnector?: string; }; export type PayPalConfig = { - businessId?: string; - buttonAction?: string; + businessId?: string; + buttonAction?: string; }; export abstract class EnvironmentService { - urls: Observable; + urls: Observable; - hasBaseUrl: () => boolean; - getNotificationsUrl: () => string; - getWebVaultUrl: () => string; - getSendUrl: () => string; - getIconsUrl: () => string; - getApiUrl: () => string; - getIdentityUrl: () => string; - getEventsUrl: () => string; - getKeyConnectorUrl: () => string; - setUrlsFromStorage: () => Promise; - setUrls: (urls: any, saveSettings?: boolean) => Promise; - getUrls: () => Urls; + hasBaseUrl: () => boolean; + getNotificationsUrl: () => string; + getWebVaultUrl: () => string; + getSendUrl: () => string; + getIconsUrl: () => string; + getApiUrl: () => string; + getIdentityUrl: () => string; + getEventsUrl: () => string; + getKeyConnectorUrl: () => string; + setUrlsFromStorage: () => Promise; + setUrls: (urls: any, saveSettings?: boolean) => Promise; + getUrls: () => Urls; } diff --git a/common/src/abstractions/export.service.ts b/common/src/abstractions/export.service.ts index 4e23823a..fa0b63ff 100644 --- a/common/src/abstractions/export.service.ts +++ b/common/src/abstractions/export.service.ts @@ -1,8 +1,11 @@ -import { EventView } from '../models/view/eventView'; +import { EventView } from "../models/view/eventView"; export abstract class ExportService { - getExport: (format?: 'csv' | 'json' | 'encrypted_json') => Promise; - getOrganizationExport: (organizationId: string, format?: 'csv' | 'json' | 'encrypted_json') => Promise; - getEventExport: (events: EventView[]) => Promise; - getFileName: (prefix?: string, extension?: string) => string; + getExport: (format?: "csv" | "json" | "encrypted_json") => Promise; + getOrganizationExport: ( + organizationId: string, + format?: "csv" | "json" | "encrypted_json" + ) => Promise; + getEventExport: (events: EventView[]) => Promise; + getFileName: (prefix?: string, extension?: string) => string; } diff --git a/common/src/abstractions/fileUpload.service.ts b/common/src/abstractions/fileUpload.service.ts index b24ed9f0..fcd3c22c 100644 --- a/common/src/abstractions/fileUpload.service.ts +++ b/common/src/abstractions/fileUpload.service.ts @@ -1,11 +1,18 @@ -import { EncArrayBuffer } from '../models/domain/encArrayBuffer'; -import { EncString } from '../models/domain/encString'; -import { AttachmentUploadDataResponse } from '../models/response/attachmentUploadDataResponse'; -import { SendFileUploadDataResponse } from '../models/response/sendFileUploadDataResponse'; +import { EncArrayBuffer } from "../models/domain/encArrayBuffer"; +import { EncString } from "../models/domain/encString"; +import { AttachmentUploadDataResponse } from "../models/response/attachmentUploadDataResponse"; +import { SendFileUploadDataResponse } from "../models/response/sendFileUploadDataResponse"; export abstract class FileUploadService { - uploadSendFile: (uploadData: SendFileUploadDataResponse, fileName: EncString, - encryptedFileData: EncArrayBuffer) => Promise; - uploadCipherAttachment: (admin: boolean, uploadData: AttachmentUploadDataResponse, fileName: EncString, - encryptedFileData: EncArrayBuffer) => Promise; + uploadSendFile: ( + uploadData: SendFileUploadDataResponse, + fileName: EncString, + encryptedFileData: EncArrayBuffer + ) => Promise; + uploadCipherAttachment: ( + admin: boolean, + uploadData: AttachmentUploadDataResponse, + fileName: EncString, + encryptedFileData: EncArrayBuffer + ) => Promise; } diff --git a/common/src/abstractions/i18n.service.ts b/common/src/abstractions/i18n.service.ts index d53494dd..4706e0d1 100644 --- a/common/src/abstractions/i18n.service.ts +++ b/common/src/abstractions/i18n.service.ts @@ -1,9 +1,9 @@ export abstract class I18nService { - locale: string; - supportedTranslationLocales: string[]; - translationLocale: string; - collator: Intl.Collator; - localeNames: Map; - t: (id: string, p1?: string, p2?: string, p3?: string) => string; - translate: (id: string, p1?: string, p2?: string, p3?: string) => string; + locale: string; + supportedTranslationLocales: string[]; + translationLocale: string; + collator: Intl.Collator; + localeNames: Map; + t: (id: string, p1?: string, p2?: string, p3?: string) => string; + translate: (id: string, p1?: string, p2?: string, p3?: string) => string; } diff --git a/common/src/abstractions/import.service.ts b/common/src/abstractions/import.service.ts index 8115c2c0..e9c92a18 100644 --- a/common/src/abstractions/import.service.ts +++ b/common/src/abstractions/import.service.ts @@ -1,13 +1,13 @@ -import { Importer } from '../importers/importer'; +import { Importer } from "../importers/importer"; export interface ImportOption { - id: string; - name: string; + id: string; + name: string; } export abstract class ImportService { - featuredImportOptions: ImportOption[]; - regularImportOptions: ImportOption[]; - getImportOptions: () => ImportOption[]; - import: (importer: Importer, fileContents: string, organizationId?: string) => Promise; - getImporter: (format: string, organizationId: string) => Importer; + featuredImportOptions: ImportOption[]; + regularImportOptions: ImportOption[]; + getImportOptions: () => ImportOption[]; + import: (importer: Importer, fileContents: string, organizationId?: string) => Promise; + getImporter: (format: string, organizationId: string) => Importer; } diff --git a/common/src/abstractions/keyConnector.service.ts b/common/src/abstractions/keyConnector.service.ts index a4fbbf5a..ca57bbf6 100644 --- a/common/src/abstractions/keyConnector.service.ts +++ b/common/src/abstractions/keyConnector.service.ts @@ -1,14 +1,14 @@ -import { Organization } from '../models/domain/organization'; +import { Organization } from "../models/domain/organization"; export abstract class KeyConnectorService { - getAndSetKey: (url?: string) => Promise; - getManagingOrganization: () => Promise; - getUsesKeyConnector: () => Promise; - migrateUser: () => Promise; - userNeedsMigration: () => Promise; - setUsesKeyConnector: (enabled: boolean) => Promise; - setConvertAccountRequired: (status: boolean) => Promise; - getConvertAccountRequired: () => Promise; - removeConvertAccountRequired: () => Promise; - clear: () => Promise; + getAndSetKey: (url?: string) => Promise; + getManagingOrganization: () => Promise; + getUsesKeyConnector: () => Promise; + migrateUser: () => Promise; + userNeedsMigration: () => Promise; + setUsesKeyConnector: (enabled: boolean) => Promise; + setConvertAccountRequired: (status: boolean) => Promise; + getConvertAccountRequired: () => Promise; + removeConvertAccountRequired: () => Promise; + clear: () => Promise; } diff --git a/common/src/abstractions/log.service.ts b/common/src/abstractions/log.service.ts index a46284dd..9997e480 100644 --- a/common/src/abstractions/log.service.ts +++ b/common/src/abstractions/log.service.ts @@ -1,11 +1,11 @@ -import { LogLevelType } from '../enums/logLevelType'; +import { LogLevelType } from "../enums/logLevelType"; export abstract class LogService { - debug: (message: string) => void; - info: (message: string) => void; - warning: (message: string) => void; - error: (message: string) => void; - write: (level: LogLevelType, message: string) => void; - time: (label: string) => void; - timeEnd: (label: string) => [number, number]; + debug: (message: string) => void; + info: (message: string) => void; + warning: (message: string) => void; + error: (message: string) => void; + write: (level: LogLevelType, message: string) => void; + time: (label: string) => void; + timeEnd: (label: string) => [number, number]; } diff --git a/common/src/abstractions/messaging.service.ts b/common/src/abstractions/messaging.service.ts index a38b4c7f..7c5f05f9 100644 --- a/common/src/abstractions/messaging.service.ts +++ b/common/src/abstractions/messaging.service.ts @@ -1,3 +1,3 @@ export abstract class MessagingService { - send: (subscriber: string, arg?: any) => void; + send: (subscriber: string, arg?: any) => void; } diff --git a/common/src/abstractions/notifications.service.ts b/common/src/abstractions/notifications.service.ts index 3e4c06e4..921e8e62 100644 --- a/common/src/abstractions/notifications.service.ts +++ b/common/src/abstractions/notifications.service.ts @@ -1,6 +1,6 @@ export abstract class NotificationsService { - init: () => Promise; - updateConnection: (sync?: boolean) => Promise; - reconnectFromActivity: () => Promise; - disconnectFromInactivity: () => Promise; + init: () => Promise; + updateConnection: (sync?: boolean) => Promise; + reconnectFromActivity: () => Promise; + disconnectFromInactivity: () => Promise; } diff --git a/common/src/abstractions/passwordReprompt.service.ts b/common/src/abstractions/passwordReprompt.service.ts index 84ca84f5..6253425b 100644 --- a/common/src/abstractions/passwordReprompt.service.ts +++ b/common/src/abstractions/passwordReprompt.service.ts @@ -1,5 +1,5 @@ export abstract class PasswordRepromptService { - protectedFields: () => string[]; - showPasswordPrompt: () => Promise; - enabled: () => Promise; + protectedFields: () => string[]; + showPasswordPrompt: () => Promise; + enabled: () => Promise; } diff --git a/common/src/abstractions/search.service.ts b/common/src/abstractions/search.service.ts index d95bea41..9c2b0eeb 100644 --- a/common/src/abstractions/search.service.ts +++ b/common/src/abstractions/search.service.ts @@ -1,14 +1,16 @@ -import { CipherView } from '../models/view/cipherView'; -import { SendView } from '../models/view/sendView'; +import { CipherView } from "../models/view/cipherView"; +import { SendView } from "../models/view/sendView"; export abstract class SearchService { - indexedEntityId?: string = null; - clearIndex: () => void; - isSearchable: (query: string) => boolean; - indexCiphers: (indexedEntityGuid?: string, ciphersToIndex?: CipherView[]) => Promise; - searchCiphers: (query: string, - filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]), - ciphers?: CipherView[]) => Promise; - searchCiphersBasic: (ciphers: CipherView[], query: string, deleted?: boolean) => CipherView[]; - searchSends: (sends: SendView[], query: string) => SendView[]; + indexedEntityId?: string = null; + clearIndex: () => void; + isSearchable: (query: string) => boolean; + indexCiphers: (indexedEntityGuid?: string, ciphersToIndex?: CipherView[]) => Promise; + searchCiphers: ( + query: string, + filter?: ((cipher: CipherView) => boolean) | ((cipher: CipherView) => boolean)[], + ciphers?: CipherView[] + ) => Promise; + searchCiphersBasic: (ciphers: CipherView[], query: string, deleted?: boolean) => CipherView[]; + searchSends: (sends: SendView[], query: string) => SendView[]; } diff --git a/common/src/abstractions/totp.service.ts b/common/src/abstractions/totp.service.ts index 608c7d1b..bf143e26 100644 --- a/common/src/abstractions/totp.service.ts +++ b/common/src/abstractions/totp.service.ts @@ -1,5 +1,5 @@ export abstract class TotpService { - getCode: (key: string) => Promise; - getTimeInterval: (key: string) => number; - isAutoCopyEnabled: () => Promise; + getCode: (key: string) => Promise; + getTimeInterval: (key: string) => number; + isAutoCopyEnabled: () => Promise; } diff --git a/common/src/abstractions/userVerification.service.ts b/common/src/abstractions/userVerification.service.ts index 7dcf1d10..42370ae1 100644 --- a/common/src/abstractions/userVerification.service.ts +++ b/common/src/abstractions/userVerification.service.ts @@ -1,10 +1,13 @@ -import { SecretVerificationRequest } from '../models/request/secretVerificationRequest'; +import { SecretVerificationRequest } from "../models/request/secretVerificationRequest"; -import { Verification } from '../types/verification'; +import { Verification } from "../types/verification"; export abstract class UserVerificationService { - buildRequest: (verification: Verification, - requestClass?: new () => T, alreadyHashed?: boolean) => Promise; - verifyUser: (verification: Verification) => Promise; - requestOTP: () => Promise; + buildRequest: ( + verification: Verification, + requestClass?: new () => T, + alreadyHashed?: boolean + ) => Promise; + verifyUser: (verification: Verification) => Promise; + requestOTP: () => Promise; } diff --git a/common/src/enums/cipherRepromptType.ts b/common/src/enums/cipherRepromptType.ts index 5b2a9b2f..1d0a523c 100644 --- a/common/src/enums/cipherRepromptType.ts +++ b/common/src/enums/cipherRepromptType.ts @@ -1,4 +1,4 @@ export enum CipherRepromptType { - None = 0, - Password = 1, + None = 0, + Password = 1, } diff --git a/common/src/enums/cipherType.ts b/common/src/enums/cipherType.ts index c081fb2d..cce7874d 100644 --- a/common/src/enums/cipherType.ts +++ b/common/src/enums/cipherType.ts @@ -1,6 +1,6 @@ export enum CipherType { - Login = 1, - SecureNote = 2, - Card = 3, - Identity = 4, + Login = 1, + SecureNote = 2, + Card = 3, + Identity = 4, } diff --git a/common/src/enums/deviceType.ts b/common/src/enums/deviceType.ts index 6f8ddd21..707f83d8 100644 --- a/common/src/enums/deviceType.ts +++ b/common/src/enums/deviceType.ts @@ -1,23 +1,23 @@ export enum DeviceType { - Android = 0, - iOS = 1, - ChromeExtension = 2, - FirefoxExtension = 3, - OperaExtension = 4, - EdgeExtension = 5, - WindowsDesktop = 6, - MacOsDesktop = 7, - LinuxDesktop = 8, - ChromeBrowser = 9, - FirefoxBrowser = 10, - OperaBrowser = 11, - EdgeBrowser = 12, - IEBrowser = 13, - UnknownBrowser = 14, - AndroidAmazon = 15, - UWP = 16, - SafariBrowser = 17, - VivaldiBrowser = 18, - VivaldiExtension = 19, - SafariExtension = 20, + Android = 0, + iOS = 1, + ChromeExtension = 2, + FirefoxExtension = 3, + OperaExtension = 4, + EdgeExtension = 5, + WindowsDesktop = 6, + MacOsDesktop = 7, + LinuxDesktop = 8, + ChromeBrowser = 9, + FirefoxBrowser = 10, + OperaBrowser = 11, + EdgeBrowser = 12, + IEBrowser = 13, + UnknownBrowser = 14, + AndroidAmazon = 15, + UWP = 16, + SafariBrowser = 17, + VivaldiBrowser = 18, + VivaldiExtension = 19, + SafariExtension = 20, } diff --git a/common/src/enums/emergencyAccessStatusType.ts b/common/src/enums/emergencyAccessStatusType.ts index eb362edf..94400f34 100644 --- a/common/src/enums/emergencyAccessStatusType.ts +++ b/common/src/enums/emergencyAccessStatusType.ts @@ -1,7 +1,7 @@ export enum EmergencyAccessStatusType { - Invited = 0, - Accepted = 1, - Confirmed = 2, - RecoveryInitiated = 3, - RecoveryApproved = 4, + Invited = 0, + Accepted = 1, + Confirmed = 2, + RecoveryInitiated = 3, + RecoveryApproved = 4, } diff --git a/common/src/enums/emergencyAccessType.ts b/common/src/enums/emergencyAccessType.ts index 803634f4..61a366c4 100644 --- a/common/src/enums/emergencyAccessType.ts +++ b/common/src/enums/emergencyAccessType.ts @@ -1,5 +1,4 @@ -export enum EmergencyAccessType -{ - View = 0, - Takeover = 1, +export enum EmergencyAccessType { + View = 0, + Takeover = 1, } diff --git a/common/src/enums/encryptionType.ts b/common/src/enums/encryptionType.ts index 7a0caa66..1c12dba2 100644 --- a/common/src/enums/encryptionType.ts +++ b/common/src/enums/encryptionType.ts @@ -1,9 +1,9 @@ export enum EncryptionType { - AesCbc256_B64 = 0, - AesCbc128_HmacSha256_B64 = 1, - AesCbc256_HmacSha256_B64 = 2, - Rsa2048_OaepSha256_B64 = 3, - Rsa2048_OaepSha1_B64 = 4, - Rsa2048_OaepSha256_HmacSha256_B64 = 5, - Rsa2048_OaepSha1_HmacSha256_B64 = 6, + AesCbc256_B64 = 0, + AesCbc128_HmacSha256_B64 = 1, + AesCbc256_HmacSha256_B64 = 2, + Rsa2048_OaepSha256_B64 = 3, + Rsa2048_OaepSha1_B64 = 4, + Rsa2048_OaepSha256_HmacSha256_B64 = 5, + Rsa2048_OaepSha1_HmacSha256_B64 = 6, } diff --git a/common/src/enums/eventType.ts b/common/src/enums/eventType.ts index b45f45f9..236e73c0 100644 --- a/common/src/enums/eventType.ts +++ b/common/src/enums/eventType.ts @@ -1,72 +1,72 @@ export enum EventType { - User_LoggedIn = 1000, - User_ChangedPassword = 1001, - User_Updated2fa = 1002, - User_Disabled2fa = 1003, - User_Recovered2fa = 1004, - User_FailedLogIn = 1005, - User_FailedLogIn2fa = 1006, - User_ClientExportedVault = 1007, - User_UpdatedTempPassword = 1008, - User_MigratedKeyToKeyConnector = 1009, + User_LoggedIn = 1000, + User_ChangedPassword = 1001, + User_Updated2fa = 1002, + User_Disabled2fa = 1003, + User_Recovered2fa = 1004, + User_FailedLogIn = 1005, + User_FailedLogIn2fa = 1006, + User_ClientExportedVault = 1007, + User_UpdatedTempPassword = 1008, + User_MigratedKeyToKeyConnector = 1009, - Cipher_Created = 1100, - Cipher_Updated = 1101, - Cipher_Deleted = 1102, - Cipher_AttachmentCreated = 1103, - Cipher_AttachmentDeleted = 1104, - Cipher_Shared = 1105, - Cipher_UpdatedCollections = 1106, - Cipher_ClientViewed = 1107, - Cipher_ClientToggledPasswordVisible = 1108, - Cipher_ClientToggledHiddenFieldVisible = 1109, - Cipher_ClientToggledCardCodeVisible = 1110, - Cipher_ClientCopiedPassword = 1111, - Cipher_ClientCopiedHiddenField = 1112, - Cipher_ClientCopiedCardCode = 1113, - Cipher_ClientAutofilled = 1114, - Cipher_SoftDeleted = 1115, - Cipher_Restored = 1116, - Cipher_ClientToggledCardNumberVisible = 1117, + Cipher_Created = 1100, + Cipher_Updated = 1101, + Cipher_Deleted = 1102, + Cipher_AttachmentCreated = 1103, + Cipher_AttachmentDeleted = 1104, + Cipher_Shared = 1105, + Cipher_UpdatedCollections = 1106, + Cipher_ClientViewed = 1107, + Cipher_ClientToggledPasswordVisible = 1108, + Cipher_ClientToggledHiddenFieldVisible = 1109, + Cipher_ClientToggledCardCodeVisible = 1110, + Cipher_ClientCopiedPassword = 1111, + Cipher_ClientCopiedHiddenField = 1112, + Cipher_ClientCopiedCardCode = 1113, + Cipher_ClientAutofilled = 1114, + Cipher_SoftDeleted = 1115, + Cipher_Restored = 1116, + Cipher_ClientToggledCardNumberVisible = 1117, - Collection_Created = 1300, - Collection_Updated = 1301, - Collection_Deleted = 1302, + Collection_Created = 1300, + Collection_Updated = 1301, + Collection_Deleted = 1302, - Group_Created = 1400, - Group_Updated = 1401, - Group_Deleted = 1402, + Group_Created = 1400, + Group_Updated = 1401, + Group_Deleted = 1402, - OrganizationUser_Invited = 1500, - OrganizationUser_Confirmed = 1501, - OrganizationUser_Updated = 1502, - OrganizationUser_Removed = 1503, - OrganizationUser_UpdatedGroups = 1504, - OrganizationUser_UnlinkedSso = 1505, - OrganizationUser_ResetPassword_Enroll = 1506, - OrganizationUser_ResetPassword_Withdraw = 1507, - OrganizationUser_AdminResetPassword = 1508, - OrganizationUser_ResetSsoLink = 1509, - OrganizationUser_FirstSsoLogin = 1510, + OrganizationUser_Invited = 1500, + OrganizationUser_Confirmed = 1501, + OrganizationUser_Updated = 1502, + OrganizationUser_Removed = 1503, + OrganizationUser_UpdatedGroups = 1504, + OrganizationUser_UnlinkedSso = 1505, + OrganizationUser_ResetPassword_Enroll = 1506, + OrganizationUser_ResetPassword_Withdraw = 1507, + OrganizationUser_AdminResetPassword = 1508, + OrganizationUser_ResetSsoLink = 1509, + OrganizationUser_FirstSsoLogin = 1510, - Organization_Updated = 1600, - Organization_PurgedVault = 1601, - // Organization_ClientExportedVault = 1602, - Organization_VaultAccessed = 1603, - Organization_EnabledSso = 1604, - Organization_DisabledSso = 1605, - Organization_EnabledKeyConnector = 1606, - Organization_DisabledKeyConnector = 1607, + Organization_Updated = 1600, + Organization_PurgedVault = 1601, + // Organization_ClientExportedVault = 1602, + Organization_VaultAccessed = 1603, + Organization_EnabledSso = 1604, + Organization_DisabledSso = 1605, + Organization_EnabledKeyConnector = 1606, + Organization_DisabledKeyConnector = 1607, - Policy_Updated = 1700, + Policy_Updated = 1700, - ProviderUser_Invited = 1800, - ProviderUser_Confirmed = 1801, - ProviderUser_Updated = 1802, - ProviderUser_Removed = 1803, + ProviderUser_Invited = 1800, + ProviderUser_Confirmed = 1801, + ProviderUser_Updated = 1802, + ProviderUser_Removed = 1803, - ProviderOrganization_Created = 1900, - ProviderOrganization_Added = 1901, - ProviderOrganization_Removed = 1902, - ProviderOrganization_VaultAccessed = 1903, + ProviderOrganization_Created = 1900, + ProviderOrganization_Added = 1901, + ProviderOrganization_Removed = 1902, + ProviderOrganization_VaultAccessed = 1903, } diff --git a/common/src/enums/fieldType.ts b/common/src/enums/fieldType.ts index 594beba4..d6deb30e 100644 --- a/common/src/enums/fieldType.ts +++ b/common/src/enums/fieldType.ts @@ -1,6 +1,6 @@ export enum FieldType { - Text = 0, - Hidden = 1, - Boolean = 2, - Linked = 3, + Text = 0, + Hidden = 1, + Boolean = 2, + Linked = 3, } diff --git a/common/src/enums/fileUploadType.ts b/common/src/enums/fileUploadType.ts index cbdd88fb..4cf654fd 100644 --- a/common/src/enums/fileUploadType.ts +++ b/common/src/enums/fileUploadType.ts @@ -1,4 +1,4 @@ export enum FileUploadType { - Direct = 0, - Azure = 1, + Direct = 0, + Azure = 1, } diff --git a/common/src/enums/hashPurpose.ts b/common/src/enums/hashPurpose.ts index 90a1db9d..887931b9 100644 --- a/common/src/enums/hashPurpose.ts +++ b/common/src/enums/hashPurpose.ts @@ -1,4 +1,4 @@ export enum HashPurpose { - ServerAuthorization = 1, - LocalAuthorization = 2, + ServerAuthorization = 1, + LocalAuthorization = 2, } diff --git a/common/src/enums/kdfType.ts b/common/src/enums/kdfType.ts index b23ef8e6..bf331fae 100644 --- a/common/src/enums/kdfType.ts +++ b/common/src/enums/kdfType.ts @@ -1,3 +1,3 @@ export enum KdfType { - PBKDF2_SHA256 = 0, + PBKDF2_SHA256 = 0, } diff --git a/common/src/enums/linkedIdType.ts b/common/src/enums/linkedIdType.ts index b2cd2f1c..c38ebc1c 100644 --- a/common/src/enums/linkedIdType.ts +++ b/common/src/enums/linkedIdType.ts @@ -2,39 +2,39 @@ export type LinkedIdType = LoginLinkedId | CardLinkedId | IdentityLinkedId; // LoginView export enum LoginLinkedId { - Username = 100, - Password = 101, + Username = 100, + Password = 101, } // CardView export enum CardLinkedId { - CardholderName = 300, - ExpMonth = 301, - ExpYear = 302, - Code = 303, - Brand = 304, - Number = 305, + CardholderName = 300, + ExpMonth = 301, + ExpYear = 302, + Code = 303, + Brand = 304, + Number = 305, } // IdentityView export enum IdentityLinkedId { - Title = 400, - MiddleName = 401, - Address1 = 402, - Address2 = 403, - Address3 = 404, - City = 405, - State = 406, - PostalCode = 407, - Country = 408, - Company = 409, - Email = 410, - Phone = 411, - Ssn = 412, - Username = 413, - PassportNumber = 414, - LicenseNumber = 415, - FirstName = 416, - LastName = 417, - FullName = 418, + Title = 400, + MiddleName = 401, + Address1 = 402, + Address2 = 403, + Address3 = 404, + City = 405, + State = 406, + PostalCode = 407, + Country = 408, + Company = 409, + Email = 410, + Phone = 411, + Ssn = 412, + Username = 413, + PassportNumber = 414, + LicenseNumber = 415, + FirstName = 416, + LastName = 417, + FullName = 418, } diff --git a/common/src/enums/logLevelType.ts b/common/src/enums/logLevelType.ts index 09f84b80..709871dd 100644 --- a/common/src/enums/logLevelType.ts +++ b/common/src/enums/logLevelType.ts @@ -1,6 +1,6 @@ export enum LogLevelType { - Debug, - Info, - Warning, - Error, + Debug, + Info, + Warning, + Error, } diff --git a/common/src/enums/notificationType.ts b/common/src/enums/notificationType.ts index 5adaac30..77ebde01 100644 --- a/common/src/enums/notificationType.ts +++ b/common/src/enums/notificationType.ts @@ -1,20 +1,20 @@ export enum NotificationType { - SyncCipherUpdate = 0, - SyncCipherCreate = 1, - SyncLoginDelete = 2, - SyncFolderDelete = 3, - SyncCiphers = 4, + SyncCipherUpdate = 0, + SyncCipherCreate = 1, + SyncLoginDelete = 2, + SyncFolderDelete = 3, + SyncCiphers = 4, - SyncVault = 5, - SyncOrgKeys = 6, - SyncFolderCreate = 7, - SyncFolderUpdate = 8, - SyncCipherDelete = 9, - SyncSettings = 10, + SyncVault = 5, + SyncOrgKeys = 6, + SyncFolderCreate = 7, + SyncFolderUpdate = 8, + SyncCipherDelete = 9, + SyncSettings = 10, - LogOut = 11, + LogOut = 11, - SyncSendCreate = 12, - SyncSendUpdate = 13, - SyncSendDelete = 14, + SyncSendCreate = 12, + SyncSendUpdate = 13, + SyncSendDelete = 14, } diff --git a/common/src/enums/organizationUserStatusType.ts b/common/src/enums/organizationUserStatusType.ts index eae4a0a6..33422180 100644 --- a/common/src/enums/organizationUserStatusType.ts +++ b/common/src/enums/organizationUserStatusType.ts @@ -1,5 +1,5 @@ export enum OrganizationUserStatusType { - Invited = 0, - Accepted = 1, - Confirmed = 2, + Invited = 0, + Accepted = 1, + Confirmed = 2, } diff --git a/common/src/enums/organizationUserType.ts b/common/src/enums/organizationUserType.ts index 632d22b0..950fbaae 100644 --- a/common/src/enums/organizationUserType.ts +++ b/common/src/enums/organizationUserType.ts @@ -1,7 +1,7 @@ export enum OrganizationUserType { - Owner = 0, - Admin = 1, - User = 2, - Manager = 3, - Custom = 4, + Owner = 0, + Admin = 1, + User = 2, + Manager = 3, + Custom = 4, } diff --git a/common/src/enums/paymentMethodType.ts b/common/src/enums/paymentMethodType.ts index da3e50f6..701bd886 100644 --- a/common/src/enums/paymentMethodType.ts +++ b/common/src/enums/paymentMethodType.ts @@ -1,11 +1,11 @@ export enum PaymentMethodType { - Card = 0, - BankAccount = 1, - PayPal = 2, - BitPay = 3, - Credit = 4, - WireTransfer = 5, - AppleInApp = 6, - GoogleInApp = 7, - Check = 8, + Card = 0, + BankAccount = 1, + PayPal = 2, + BitPay = 3, + Credit = 4, + WireTransfer = 5, + AppleInApp = 6, + GoogleInApp = 7, + Check = 8, } diff --git a/common/src/enums/permissions.ts b/common/src/enums/permissions.ts index 8dcd9366..46a74455 100644 --- a/common/src/enums/permissions.ts +++ b/common/src/enums/permissions.ts @@ -1,27 +1,27 @@ export enum Permissions { - AccessEventLogs, - AccessImportExport, - AccessReports, - /** - * @deprecated Sep 29 2021: This permission has been split out to `createNewCollections`, `editAnyCollection`, and - * `deleteAnyCollection`. It exists here for backwards compatibility with Server versions <= 1.43.0 - */ - ManageAllCollections, - /** - * @deprecated Sep 29 2021: This permission has been split out to `editAssignedCollections` and - * `deleteAssignedCollections`. It exists here for backwards compatibility with Server versions <= 1.43.0 - */ - ManageAssignedCollections, - ManageGroups, - ManageOrganization , - ManagePolicies, - ManageProvider, - ManageUsers, - ManageUsersPassword, - CreateNewCollections, - EditAnyCollection, - DeleteAnyCollection, - EditAssignedCollections, - DeleteAssignedCollections, - ManageSso, + AccessEventLogs, + AccessImportExport, + AccessReports, + /** + * @deprecated Sep 29 2021: This permission has been split out to `createNewCollections`, `editAnyCollection`, and + * `deleteAnyCollection`. It exists here for backwards compatibility with Server versions <= 1.43.0 + */ + ManageAllCollections, + /** + * @deprecated Sep 29 2021: This permission has been split out to `editAssignedCollections` and + * `deleteAssignedCollections`. It exists here for backwards compatibility with Server versions <= 1.43.0 + */ + ManageAssignedCollections, + ManageGroups, + ManageOrganization, + ManagePolicies, + ManageProvider, + ManageUsers, + ManageUsersPassword, + CreateNewCollections, + EditAnyCollection, + DeleteAnyCollection, + EditAssignedCollections, + DeleteAssignedCollections, + ManageSso, } diff --git a/common/src/enums/planSponsorshipType.ts b/common/src/enums/planSponsorshipType.ts index 330b7ec0..3b4c0046 100644 --- a/common/src/enums/planSponsorshipType.ts +++ b/common/src/enums/planSponsorshipType.ts @@ -1,3 +1,3 @@ export enum PlanSponsorshipType { - FamiliesForEnterprise = 0, + FamiliesForEnterprise = 0, } diff --git a/common/src/enums/planType.ts b/common/src/enums/planType.ts index 1b07c723..f4c89d2c 100644 --- a/common/src/enums/planType.ts +++ b/common/src/enums/planType.ts @@ -1,14 +1,14 @@ export enum PlanType { - Free = 0, - FamiliesAnnually2019 = 1, - TeamsMonthly2019 = 2, - TeamsAnnually2019 = 3, - EnterpriseMonthly2019 = 4, - EnterpriseAnnually2019 = 5, - Custom = 6, - FamiliesAnnually = 7, - TeamsMonthly = 8, - TeamsAnnually = 9, - EnterpriseMonthly = 10, - EnterpriseAnnually = 11, + Free = 0, + FamiliesAnnually2019 = 1, + TeamsMonthly2019 = 2, + TeamsAnnually2019 = 3, + EnterpriseMonthly2019 = 4, + EnterpriseAnnually2019 = 5, + Custom = 6, + FamiliesAnnually = 7, + TeamsMonthly = 8, + TeamsAnnually = 9, + EnterpriseMonthly = 10, + EnterpriseAnnually = 11, } diff --git a/common/src/enums/policyType.ts b/common/src/enums/policyType.ts index 244ed4a1..02dce41e 100644 --- a/common/src/enums/policyType.ts +++ b/common/src/enums/policyType.ts @@ -1,13 +1,13 @@ export enum PolicyType { - TwoFactorAuthentication = 0, // Requires users to have 2fa enabled - MasterPassword = 1, // Sets minimum requirements for master password complexity - PasswordGenerator = 2, // Sets minimum requirements/default type for generated passwords/passphrases - SingleOrg = 3, // Allows users to only be apart of one organization - RequireSso = 4, // Requires users to authenticate with SSO - PersonalOwnership = 5, // Disables personal vault ownership for adding/cloning items - DisableSend = 6, // Disables the ability to create and edit Bitwarden Sends - SendOptions = 7, // Sets restrictions or defaults for Bitwarden Sends - ResetPassword = 8, // Allows orgs to use reset password : also can enable auto-enrollment during invite flow - MaximumVaultTimeout = 9, // Sets the maximum allowed vault timeout - DisablePersonalVaultExport = 10, // Disable personal vault export + TwoFactorAuthentication = 0, // Requires users to have 2fa enabled + MasterPassword = 1, // Sets minimum requirements for master password complexity + PasswordGenerator = 2, // Sets minimum requirements/default type for generated passwords/passphrases + SingleOrg = 3, // Allows users to only be apart of one organization + RequireSso = 4, // Requires users to authenticate with SSO + PersonalOwnership = 5, // Disables personal vault ownership for adding/cloning items + DisableSend = 6, // Disables the ability to create and edit Bitwarden Sends + SendOptions = 7, // Sets restrictions or defaults for Bitwarden Sends + ResetPassword = 8, // Allows orgs to use reset password : also can enable auto-enrollment during invite flow + MaximumVaultTimeout = 9, // Sets the maximum allowed vault timeout + DisablePersonalVaultExport = 10, // Disable personal vault export } diff --git a/common/src/enums/productType.ts b/common/src/enums/productType.ts index d8e2e0ae..50b836d1 100644 --- a/common/src/enums/productType.ts +++ b/common/src/enums/productType.ts @@ -1,6 +1,6 @@ export enum ProductType { - Free = 0, - Families = 1, - Teams = 2, - Enterprise = 3, + Free = 0, + Families = 1, + Teams = 2, + Enterprise = 3, } diff --git a/common/src/enums/providerUserStatusType.ts b/common/src/enums/providerUserStatusType.ts index 8b0e55de..3b845551 100644 --- a/common/src/enums/providerUserStatusType.ts +++ b/common/src/enums/providerUserStatusType.ts @@ -1,5 +1,5 @@ export enum ProviderUserStatusType { - Invited = 0, - Accepted = 1, - Confirmed = 2, + Invited = 0, + Accepted = 1, + Confirmed = 2, } diff --git a/common/src/enums/providerUserType.ts b/common/src/enums/providerUserType.ts index 326fa0aa..00490adc 100644 --- a/common/src/enums/providerUserType.ts +++ b/common/src/enums/providerUserType.ts @@ -1,4 +1,4 @@ export enum ProviderUserType { - ProviderAdmin = 0, - ServiceUser = 1, + ProviderAdmin = 0, + ServiceUser = 1, } diff --git a/common/src/enums/secureNoteType.ts b/common/src/enums/secureNoteType.ts index c7f3e44a..8015236d 100644 --- a/common/src/enums/secureNoteType.ts +++ b/common/src/enums/secureNoteType.ts @@ -1,3 +1,3 @@ export enum SecureNoteType { - Generic = 0, + Generic = 0, } diff --git a/common/src/enums/sendType.ts b/common/src/enums/sendType.ts index f5715d86..487930c9 100644 --- a/common/src/enums/sendType.ts +++ b/common/src/enums/sendType.ts @@ -1,4 +1,4 @@ export enum SendType { - Text = 0, - File = 1, + Text = 0, + File = 1, } diff --git a/common/src/enums/themeType.ts b/common/src/enums/themeType.ts index 40e7c2dd..8afca770 100644 --- a/common/src/enums/themeType.ts +++ b/common/src/enums/themeType.ts @@ -1,7 +1,7 @@ export enum ThemeType { - System = 'system', - Light = 'light', - Dark = 'dark', - Nord = 'nord', - SolarizedDark = 'solarizedDark', + System = "system", + Light = "light", + Dark = "dark", + Nord = "nord", + SolarizedDark = "solarizedDark", } diff --git a/common/src/enums/transactionType.ts b/common/src/enums/transactionType.ts index 68cce632..34731a2e 100644 --- a/common/src/enums/transactionType.ts +++ b/common/src/enums/transactionType.ts @@ -1,7 +1,7 @@ export enum TransactionType { - Charge = 0, - Credit = 1, - PromotionalCredit = 2, - ReferralCredit = 3, - Refund = 4, + Charge = 0, + Credit = 1, + PromotionalCredit = 2, + ReferralCredit = 3, + Refund = 4, } diff --git a/common/src/enums/twoFactorProviderType.ts b/common/src/enums/twoFactorProviderType.ts index c0de3f4a..a1708032 100644 --- a/common/src/enums/twoFactorProviderType.ts +++ b/common/src/enums/twoFactorProviderType.ts @@ -1,10 +1,10 @@ export enum TwoFactorProviderType { - Authenticator = 0, - Email = 1, - Duo = 2, - Yubikey = 3, - U2f = 4, - Remember = 5, - OrganizationDuo = 6, - WebAuthn = 7, + Authenticator = 0, + Email = 1, + Duo = 2, + Yubikey = 3, + U2f = 4, + Remember = 5, + OrganizationDuo = 6, + WebAuthn = 7, } diff --git a/common/src/enums/uriMatchType.ts b/common/src/enums/uriMatchType.ts index e4c0ef48..4a4193ba 100644 --- a/common/src/enums/uriMatchType.ts +++ b/common/src/enums/uriMatchType.ts @@ -1,8 +1,8 @@ export enum UriMatchType { - Domain = 0, - Host = 1, - StartsWith = 2, - Exact = 3, - RegularExpression = 4, - Never = 5, + Domain = 0, + Host = 1, + StartsWith = 2, + Exact = 3, + RegularExpression = 4, + Never = 5, } diff --git a/common/src/enums/verificationType.ts b/common/src/enums/verificationType.ts index 254da418..76a51ab7 100644 --- a/common/src/enums/verificationType.ts +++ b/common/src/enums/verificationType.ts @@ -1,4 +1,4 @@ export enum VerificationType { - MasterPassword = 0, - OTP = 1, + MasterPassword = 0, + OTP = 1, } diff --git a/common/src/importers/ascendoCsvImporter.ts b/common/src/importers/ascendoCsvImporter.ts index c8179dc6..aed1c3ab 100644 --- a/common/src/importers/ascendoCsvImporter.ts +++ b/common/src/importers/ascendoCsvImporter.ts @@ -1,55 +1,59 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class AscendoCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.length < 2) { - return; - } - - const cipher = this.initLoginCipher(); - cipher.notes = this.getValueOrDefault(value[value.length - 1]); - cipher.name = this.getValueOrDefault(value[0], '--'); - - if (value.length > 2 && (value.length % 2) === 0) { - for (let i = 0; i < value.length - 2; i += 2) { - const val: string = value[i + 2]; - const field: string = value[i + 1]; - if (this.isNullOrWhitespace(val) || this.isNullOrWhitespace(field)) { - continue; - } - - const fieldLower = field.toLowerCase(); - if (cipher.login.password == null && this.passwordFieldNames.indexOf(fieldLower) > -1) { - cipher.login.password = this.getValueOrDefault(val); - } else if (cipher.login.username == null && - this.usernameFieldNames.indexOf(fieldLower) > -1) { - cipher.login.username = this.getValueOrDefault(val); - } else if ((cipher.login.uris == null || cipher.login.uris.length === 0) && - this.uriFieldNames.indexOf(fieldLower) > -1) { - cipher.login.uris = this.makeUriArray(val); - } else { - this.processKvp(cipher, field, val); - } - } - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.length < 2) { + return; + } + + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value[value.length - 1]); + cipher.name = this.getValueOrDefault(value[0], "--"); + + if (value.length > 2 && value.length % 2 === 0) { + for (let i = 0; i < value.length - 2; i += 2) { + const val: string = value[i + 2]; + const field: string = value[i + 1]; + if (this.isNullOrWhitespace(val) || this.isNullOrWhitespace(field)) { + continue; + } + + const fieldLower = field.toLowerCase(); + if (cipher.login.password == null && this.passwordFieldNames.indexOf(fieldLower) > -1) { + cipher.login.password = this.getValueOrDefault(val); + } else if ( + cipher.login.username == null && + this.usernameFieldNames.indexOf(fieldLower) > -1 + ) { + cipher.login.username = this.getValueOrDefault(val); + } else if ( + (cipher.login.uris == null || cipher.login.uris.length === 0) && + this.uriFieldNames.indexOf(fieldLower) > -1 + ) { + cipher.login.uris = this.makeUriArray(val); + } else { + this.processKvp(cipher, field, val); + } + } + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/avastCsvImporter.ts b/common/src/importers/avastCsvImporter.ts index 5519b67a..9629fb2f 100644 --- a/common/src/importers/avastCsvImporter.ts +++ b/common/src/importers/avastCsvImporter.ts @@ -1,28 +1,28 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class AvastCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.name); - cipher.login.uris = this.makeUriArray(value.web); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.username = this.getValueOrDefault(value.login); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.name); + cipher.login.uris = this.makeUriArray(value.web); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.username = this.getValueOrDefault(value.login); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/avastJsonImporter.ts b/common/src/importers/avastJsonImporter.ts index 9f8d7752..fe853539 100644 --- a/common/src/importers/avastJsonImporter.ts +++ b/common/src/importers/avastJsonImporter.ts @@ -1,69 +1,69 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; export class AvastJsonImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = JSON.parse(data); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - if (results.logins != null) { - results.logins.forEach((value: any) => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.custName); - cipher.notes = this.getValueOrDefault(value.note); - cipher.login.uris = this.makeUriArray(value.url); - cipher.login.password = this.getValueOrDefault(value.pwd); - cipher.login.username = this.getValueOrDefault(value.loginName); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - } - - if (results.notes != null) { - results.notes.forEach((value: any) => { - const cipher = this.initLoginCipher(); - cipher.type = CipherType.SecureNote; - cipher.secureNote.type = SecureNoteType.Generic; - cipher.name = this.getValueOrDefault(value.label); - cipher.notes = this.getValueOrDefault(value.text); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - } - - if (results.cards != null) { - results.cards.forEach((value: any) => { - const cipher = this.initLoginCipher(); - cipher.type = CipherType.Card; - cipher.name = this.getValueOrDefault(value.custName); - cipher.notes = this.getValueOrDefault(value.note); - cipher.card.cardholderName = this.getValueOrDefault(value.holderName); - cipher.card.number = this.getValueOrDefault(value.cardNumber); - cipher.card.code = this.getValueOrDefault(value.cvv); - cipher.card.brand = this.getCardBrand(cipher.card.number); - if (value.expirationDate != null) { - if (value.expirationDate.month != null) { - cipher.card.expMonth = value.expirationDate.month + ''; - } - if (value.expirationDate.year != null) { - cipher.card.expYear = value.expirationDate.year + ''; - } - } - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = JSON.parse(data); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + if (results.logins != null) { + results.logins.forEach((value: any) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.custName); + cipher.notes = this.getValueOrDefault(value.note); + cipher.login.uris = this.makeUriArray(value.url); + cipher.login.password = this.getValueOrDefault(value.pwd); + cipher.login.username = this.getValueOrDefault(value.loginName); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + } + + if (results.notes != null) { + results.notes.forEach((value: any) => { + const cipher = this.initLoginCipher(); + cipher.type = CipherType.SecureNote; + cipher.secureNote.type = SecureNoteType.Generic; + cipher.name = this.getValueOrDefault(value.label); + cipher.notes = this.getValueOrDefault(value.text); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + } + + if (results.cards != null) { + results.cards.forEach((value: any) => { + const cipher = this.initLoginCipher(); + cipher.type = CipherType.Card; + cipher.name = this.getValueOrDefault(value.custName); + cipher.notes = this.getValueOrDefault(value.note); + cipher.card.cardholderName = this.getValueOrDefault(value.holderName); + cipher.card.number = this.getValueOrDefault(value.cardNumber); + cipher.card.code = this.getValueOrDefault(value.cvv); + cipher.card.brand = this.getCardBrand(cipher.card.number); + if (value.expirationDate != null) { + if (value.expirationDate.month != null) { + cipher.card.expMonth = value.expirationDate.month + ""; + } + if (value.expirationDate.year != null) { + cipher.card.expYear = value.expirationDate.year + ""; + } + } + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/aviraCsvImporter.ts b/common/src/importers/aviraCsvImporter.ts index 1547d7f2..fa983080 100644 --- a/common/src/importers/aviraCsvImporter.ts +++ b/common/src/importers/aviraCsvImporter.ts @@ -1,36 +1,41 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class AviraCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.name, - this.getValueOrDefault(this.nameFromUrl(value.website), '--')); - cipher.login.uris = this.makeUriArray(value.website); - cipher.login.password = this.getValueOrDefault(value.password); - - if (this.isNullOrWhitespace(value.username) && !this.isNullOrWhitespace(value.secondary_username)) { - cipher.login.username = value.secondary_username; - } else { - cipher.login.username = this.getValueOrDefault(value.username); - cipher.notes = this.getValueOrDefault(value.secondary_username); - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault( + value.name, + this.getValueOrDefault(this.nameFromUrl(value.website), "--") + ); + cipher.login.uris = this.makeUriArray(value.website); + cipher.login.password = this.getValueOrDefault(value.password); + + if ( + this.isNullOrWhitespace(value.username) && + !this.isNullOrWhitespace(value.secondary_username) + ) { + cipher.login.username = value.secondary_username; + } else { + cipher.login.username = this.getValueOrDefault(value.username); + cipher.notes = this.getValueOrDefault(value.secondary_username); + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/bitwardenCsvImporter.ts b/common/src/importers/bitwardenCsvImporter.ts index f2ffeae5..b7ec11c3 100644 --- a/common/src/importers/bitwardenCsvImporter.ts +++ b/common/src/importers/bitwardenCsvImporter.ts @@ -1,118 +1,122 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CipherView } from '../models/view/cipherView'; -import { CollectionView } from '../models/view/collectionView'; -import { FieldView } from '../models/view/fieldView'; -import { FolderView } from '../models/view/folderView'; -import { LoginView } from '../models/view/loginView'; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { CipherView } from "../models/view/cipherView"; +import { CollectionView } from "../models/view/collectionView"; +import { FieldView } from "../models/view/fieldView"; +import { FolderView } from "../models/view/folderView"; +import { LoginView } from "../models/view/loginView"; +import { SecureNoteView } from "../models/view/secureNoteView"; -import { CipherRepromptType } from '../enums/cipherRepromptType'; -import { CipherType } from '../enums/cipherType'; -import { FieldType } from '../enums/fieldType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherRepromptType } from "../enums/cipherRepromptType"; +import { CipherType } from "../enums/cipherType"; +import { FieldType } from "../enums/fieldType"; +import { SecureNoteType } from "../enums/secureNoteType"; export class BitwardenCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (this.organization && !this.isNullOrWhitespace(value.collections)) { - const collections = (value.collections as string).split(','); - collections.forEach(col => { - let addCollection = true; - let collectionIndex = result.collections.length; - - for (let i = 0; i < result.collections.length; i++) { - if (result.collections[i].name === col) { - addCollection = false; - collectionIndex = i; - break; - } - } - - if (addCollection) { - const collection = new CollectionView(); - collection.name = col; - result.collections.push(collection); - } - - result.collectionRelationships.push([result.ciphers.length, collectionIndex]); - }); - } else if (!this.organization) { - this.processFolder(result, value.folder); - } - - const cipher = new CipherView(); - cipher.favorite = !this.organization && this.getValueOrDefault(value.favorite, '0') !== '0' ? true : false; - cipher.type = CipherType.Login; - cipher.notes = this.getValueOrDefault(value.notes); - cipher.name = this.getValueOrDefault(value.name, '--'); - try { - cipher.reprompt = parseInt(this.getValueOrDefault(value.reprompt, CipherRepromptType.None.toString()), 10); - } catch (e) { - // tslint:disable-next-line - console.error('Unable to parse reprompt value', e); - cipher.reprompt = CipherRepromptType.None; - } - - if (!this.isNullOrWhitespace(value.fields)) { - const fields = this.splitNewLine(value.fields); - for (let i = 0; i < fields.length; i++) { - if (this.isNullOrWhitespace(fields[i])) { - continue; - } - - const delimPosition = fields[i].lastIndexOf(': '); - if (delimPosition === -1) { - continue; - } - - if (cipher.fields == null) { - cipher.fields = []; - } - - const field = new FieldView(); - field.name = fields[i].substr(0, delimPosition); - field.value = null; - field.type = FieldType.Text; - if (fields[i].length > (delimPosition + 2)) { - field.value = fields[i].substr(delimPosition + 2); - } - cipher.fields.push(field); - } - } - - const valueType = value.type != null ? value.type.toLowerCase() : null; - switch (valueType) { - case 'note': - cipher.type = CipherType.SecureNote; - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - break; - default: - cipher.type = CipherType.Login; - cipher.login = new LoginView(); - cipher.login.totp = this.getValueOrDefault(value.login_totp || value.totp); - cipher.login.username = this.getValueOrDefault(value.login_username || value.username); - cipher.login.password = this.getValueOrDefault(value.login_password || value.password); - const uris = this.parseSingleRowCsv(value.login_uri || value.uri); - cipher.login.uris = this.makeUriArray(uris); - break; - } - - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (this.organization && !this.isNullOrWhitespace(value.collections)) { + const collections = (value.collections as string).split(","); + collections.forEach((col) => { + let addCollection = true; + let collectionIndex = result.collections.length; + + for (let i = 0; i < result.collections.length; i++) { + if (result.collections[i].name === col) { + addCollection = false; + collectionIndex = i; + break; + } + } + + if (addCollection) { + const collection = new CollectionView(); + collection.name = col; + result.collections.push(collection); + } + + result.collectionRelationships.push([result.ciphers.length, collectionIndex]); + }); + } else if (!this.organization) { + this.processFolder(result, value.folder); + } + + const cipher = new CipherView(); + cipher.favorite = + !this.organization && this.getValueOrDefault(value.favorite, "0") !== "0" ? true : false; + cipher.type = CipherType.Login; + cipher.notes = this.getValueOrDefault(value.notes); + cipher.name = this.getValueOrDefault(value.name, "--"); + try { + cipher.reprompt = parseInt( + this.getValueOrDefault(value.reprompt, CipherRepromptType.None.toString()), + 10 + ); + } catch (e) { + // tslint:disable-next-line + console.error("Unable to parse reprompt value", e); + cipher.reprompt = CipherRepromptType.None; + } + + if (!this.isNullOrWhitespace(value.fields)) { + const fields = this.splitNewLine(value.fields); + for (let i = 0; i < fields.length; i++) { + if (this.isNullOrWhitespace(fields[i])) { + continue; + } + + const delimPosition = fields[i].lastIndexOf(": "); + if (delimPosition === -1) { + continue; + } + + if (cipher.fields == null) { + cipher.fields = []; + } + + const field = new FieldView(); + field.name = fields[i].substr(0, delimPosition); + field.value = null; + field.type = FieldType.Text; + if (fields[i].length > delimPosition + 2) { + field.value = fields[i].substr(delimPosition + 2); + } + cipher.fields.push(field); + } + } + + const valueType = value.type != null ? value.type.toLowerCase() : null; + switch (valueType) { + case "note": + cipher.type = CipherType.SecureNote; + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + break; + default: + cipher.type = CipherType.Login; + cipher.login = new LoginView(); + cipher.login.totp = this.getValueOrDefault(value.login_totp || value.totp); + cipher.login.username = this.getValueOrDefault(value.login_username || value.username); + cipher.login.password = this.getValueOrDefault(value.login_password || value.password); + const uris = this.parseSingleRowCsv(value.login_uri || value.uri); + cipher.login.uris = this.makeUriArray(uris); + break; + } + + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/bitwardenJsonImporter.ts b/common/src/importers/bitwardenJsonImporter.ts index 195708c0..bef77860 100644 --- a/common/src/importers/bitwardenJsonImporter.ts +++ b/common/src/importers/bitwardenJsonImporter.ts @@ -1,159 +1,174 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { EncString } from '../models/domain/encString'; -import { ImportResult } from '../models/domain/importResult'; +import { EncString } from "../models/domain/encString"; +import { ImportResult } from "../models/domain/importResult"; -import { CipherWithIds } from '../models/export/cipherWithIds'; -import { CollectionWithId } from '../models/export/collectionWithId'; -import { FolderWithId } from '../models/export/folderWithId'; +import { CipherWithIds } from "../models/export/cipherWithIds"; +import { CollectionWithId } from "../models/export/collectionWithId"; +import { FolderWithId } from "../models/export/folderWithId"; -import { CryptoService } from '../abstractions/crypto.service'; -import { I18nService } from '../abstractions/i18n.service'; +import { CryptoService } from "../abstractions/crypto.service"; +import { I18nService } from "../abstractions/i18n.service"; export class BitwardenJsonImporter extends BaseImporter implements Importer { - private results: any; - private result: ImportResult; + private results: any; + private result: ImportResult; - constructor(private cryptoService: CryptoService, private i18nService: I18nService) { - super(); + constructor(private cryptoService: CryptoService, private i18nService: I18nService) { + super(); + } + + async parse(data: string): Promise { + this.result = new ImportResult(); + this.results = JSON.parse(data); + if (this.results == null || this.results.items == null || this.results.items.length === 0) { + this.result.success = false; + return this.result; } - async parse(data: string): Promise { - this.result = new ImportResult(); - this.results = JSON.parse(data); - if (this.results == null || this.results.items == null || this.results.items.length === 0) { - this.result.success = false; - return this.result; - } - - if (this.results.encrypted) { - await this.parseEncrypted(); - } else { - this.parseDecrypted(); - } - - return this.result; + if (this.results.encrypted) { + await this.parseEncrypted(); + } else { + this.parseDecrypted(); } - private async parseEncrypted() { - if (this.results.encKeyValidation_DO_NOT_EDIT != null) { - const orgKey = await this.cryptoService.getOrgKey(this.organizationId); - const encKeyValidation = new EncString(this.results.encKeyValidation_DO_NOT_EDIT); - const encKeyValidationDecrypt = await this.cryptoService.decryptToUtf8(encKeyValidation, orgKey); - if (encKeyValidationDecrypt === null) { - this.result.success = false; - this.result.errorMessage = this.i18nService.t('importEncKeyError'); - return; - } - } + return this.result; + } - const groupingsMap = new Map(); - - if (this.organization && this.results.collections != null) { - for (const c of this.results.collections as CollectionWithId[]) { - const collection = CollectionWithId.toDomain(c); - if (collection != null) { - collection.id = null; - collection.organizationId = this.organizationId; - const view = await collection.decrypt(); - groupingsMap.set(c.id, this.result.collections.length); - this.result.collections.push(view); - } - } - } else if (!this.organization && this.results.folders != null) { - for (const f of this.results.folders as FolderWithId[]) { - const folder = FolderWithId.toDomain(f); - if (folder != null) { - folder.id = null; - const view = await folder.decrypt(); - groupingsMap.set(f.id, this.result.folders.length); - this.result.folders.push(view); - } - } - } - - for (const c of this.results.items as CipherWithIds[]) { - const cipher = CipherWithIds.toDomain(c); - // reset ids incase they were set for some reason - cipher.id = null; - cipher.folderId = null; - cipher.organizationId = this.organizationId; - cipher.collectionIds = null; - - // make sure password history is limited - if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) { - cipher.passwordHistory = cipher.passwordHistory.slice(0, 5); - } - - if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) { - this.result.folderRelationships.push([this.result.ciphers.length, groupingsMap.get(c.folderId)]); - } else if (this.organization && c.collectionIds != null) { - c.collectionIds.forEach(cId => { - if (groupingsMap.has(cId)) { - this.result.collectionRelationships.push([this.result.ciphers.length, groupingsMap.get(cId)]); - } - }); - } - - const view = await cipher.decrypt(); - this.cleanupCipher(view); - this.result.ciphers.push(view); - } - - this.result.success = true; + private async parseEncrypted() { + if (this.results.encKeyValidation_DO_NOT_EDIT != null) { + const orgKey = await this.cryptoService.getOrgKey(this.organizationId); + const encKeyValidation = new EncString(this.results.encKeyValidation_DO_NOT_EDIT); + const encKeyValidationDecrypt = await this.cryptoService.decryptToUtf8( + encKeyValidation, + orgKey + ); + if (encKeyValidationDecrypt === null) { + this.result.success = false; + this.result.errorMessage = this.i18nService.t("importEncKeyError"); + return; + } } - private parseDecrypted() { - const groupingsMap = new Map(); - if (this.organization && this.results.collections != null) { - this.results.collections.forEach((c: CollectionWithId) => { - const collection = CollectionWithId.toView(c); - if (collection != null) { - collection.id = null; - collection.organizationId = null; - groupingsMap.set(c.id, this.result.collections.length); - this.result.collections.push(collection); - } - }); - } else if (!this.organization && this.results.folders != null) { - this.results.folders.forEach((f: FolderWithId) => { - const folder = FolderWithId.toView(f); - if (folder != null) { - folder.id = null; - groupingsMap.set(f.id, this.result.folders.length); - this.result.folders.push(folder); - } - }); + const groupingsMap = new Map(); + + if (this.organization && this.results.collections != null) { + for (const c of this.results.collections as CollectionWithId[]) { + const collection = CollectionWithId.toDomain(c); + if (collection != null) { + collection.id = null; + collection.organizationId = this.organizationId; + const view = await collection.decrypt(); + groupingsMap.set(c.id, this.result.collections.length); + this.result.collections.push(view); } + } + } else if (!this.organization && this.results.folders != null) { + for (const f of this.results.folders as FolderWithId[]) { + const folder = FolderWithId.toDomain(f); + if (folder != null) { + folder.id = null; + const view = await folder.decrypt(); + groupingsMap.set(f.id, this.result.folders.length); + this.result.folders.push(view); + } + } + } - this.results.items.forEach((c: CipherWithIds) => { - const cipher = CipherWithIds.toView(c); - // reset ids incase they were set for some reason - cipher.id = null; - cipher.folderId = null; - cipher.organizationId = null; - cipher.collectionIds = null; + for (const c of this.results.items as CipherWithIds[]) { + const cipher = CipherWithIds.toDomain(c); + // reset ids incase they were set for some reason + cipher.id = null; + cipher.folderId = null; + cipher.organizationId = this.organizationId; + cipher.collectionIds = null; - // make sure password history is limited - if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) { - cipher.passwordHistory = cipher.passwordHistory.slice(0, 5); - } + // make sure password history is limited + if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) { + cipher.passwordHistory = cipher.passwordHistory.slice(0, 5); + } - if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) { - this.result.folderRelationships.push([this.result.ciphers.length, groupingsMap.get(c.folderId)]); - } else if (this.organization && c.collectionIds != null) { - c.collectionIds.forEach(cId => { - if (groupingsMap.has(cId)) { - this.result.collectionRelationships.push([this.result.ciphers.length, groupingsMap.get(cId)]); - } - }); - } - - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); + if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) { + this.result.folderRelationships.push([ + this.result.ciphers.length, + groupingsMap.get(c.folderId), + ]); + } else if (this.organization && c.collectionIds != null) { + c.collectionIds.forEach((cId) => { + if (groupingsMap.has(cId)) { + this.result.collectionRelationships.push([ + this.result.ciphers.length, + groupingsMap.get(cId), + ]); + } }); + } - this.result.success = true; + const view = await cipher.decrypt(); + this.cleanupCipher(view); + this.result.ciphers.push(view); } + + this.result.success = true; + } + + private parseDecrypted() { + const groupingsMap = new Map(); + if (this.organization && this.results.collections != null) { + this.results.collections.forEach((c: CollectionWithId) => { + const collection = CollectionWithId.toView(c); + if (collection != null) { + collection.id = null; + collection.organizationId = null; + groupingsMap.set(c.id, this.result.collections.length); + this.result.collections.push(collection); + } + }); + } else if (!this.organization && this.results.folders != null) { + this.results.folders.forEach((f: FolderWithId) => { + const folder = FolderWithId.toView(f); + if (folder != null) { + folder.id = null; + groupingsMap.set(f.id, this.result.folders.length); + this.result.folders.push(folder); + } + }); + } + + this.results.items.forEach((c: CipherWithIds) => { + const cipher = CipherWithIds.toView(c); + // reset ids incase they were set for some reason + cipher.id = null; + cipher.folderId = null; + cipher.organizationId = null; + cipher.collectionIds = null; + + // make sure password history is limited + if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) { + cipher.passwordHistory = cipher.passwordHistory.slice(0, 5); + } + + if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) { + this.result.folderRelationships.push([ + this.result.ciphers.length, + groupingsMap.get(c.folderId), + ]); + } else if (this.organization && c.collectionIds != null) { + c.collectionIds.forEach((cId) => { + if (groupingsMap.has(cId)) { + this.result.collectionRelationships.push([ + this.result.ciphers.length, + groupingsMap.get(cId), + ]); + } + }); + } + + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + }); + + this.result.success = true; + } } diff --git a/common/src/importers/blackBerryCsvImporter.ts b/common/src/importers/blackBerryCsvImporter.ts index 1e111348..f54593b0 100644 --- a/common/src/importers/blackBerryCsvImporter.ts +++ b/common/src/importers/blackBerryCsvImporter.ts @@ -1,36 +1,36 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class BlackBerryCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.grouping === 'list') { - return; - } - const cipher = this.initLoginCipher(); - cipher.favorite = value.fav === '1'; - cipher.name = this.getValueOrDefault(value.name); - cipher.notes = this.getValueOrDefault(value.extra); - if (value.grouping !== 'note') { - cipher.login.uris = this.makeUriArray(value.url); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.username = this.getValueOrDefault(value.username); - } - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.grouping === "list") { + return; + } + const cipher = this.initLoginCipher(); + cipher.favorite = value.fav === "1"; + cipher.name = this.getValueOrDefault(value.name); + cipher.notes = this.getValueOrDefault(value.extra); + if (value.grouping !== "note") { + cipher.login.uris = this.makeUriArray(value.url); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.username = this.getValueOrDefault(value.username); + } + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/blurCsvImporter.ts b/common/src/importers/blurCsvImporter.ts index 3f36e166..449ccb32 100644 --- a/common/src/importers/blurCsvImporter.ts +++ b/common/src/importers/blurCsvImporter.ts @@ -1,39 +1,41 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class BlurCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.label === 'null') { - value.label = null; - } - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.label, - this.getValueOrDefault(this.nameFromUrl(value.domain), '--')); - cipher.login.uris = this.makeUriArray(value.domain); - cipher.login.password = this.getValueOrDefault(value.password); - - if (this.isNullOrWhitespace(value.email) && !this.isNullOrWhitespace(value.username)) { - cipher.login.username = value.username; - } else { - cipher.login.username = this.getValueOrDefault(value.email); - cipher.notes = this.getValueOrDefault(value.username); - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.label === "null") { + value.label = null; + } + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault( + value.label, + this.getValueOrDefault(this.nameFromUrl(value.domain), "--") + ); + cipher.login.uris = this.makeUriArray(value.domain); + cipher.login.password = this.getValueOrDefault(value.password); + + if (this.isNullOrWhitespace(value.email) && !this.isNullOrWhitespace(value.username)) { + cipher.login.username = value.username; + } else { + cipher.login.username = this.getValueOrDefault(value.email); + cipher.notes = this.getValueOrDefault(value.username); + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/buttercupCsvImporter.ts b/common/src/importers/buttercupCsvImporter.ts index bd9e5553..4961adbf 100644 --- a/common/src/importers/buttercupCsvImporter.ts +++ b/common/src/importers/buttercupCsvImporter.ts @@ -1,51 +1,49 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -const OfficialProps = [ - '!group_id', '!group_name', 'title', 'username', 'password', 'URL', 'id', -]; +const OfficialProps = ["!group_id", "!group_name", "title", "username", "password", "URL", "id"]; export class ButtercupCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - this.processFolder(result, this.getValueOrDefault(value['!group_name'])); - - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.title, '--'); - cipher.login.username = this.getValueOrDefault(value.username); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.uris = this.makeUriArray(value.URL); - - let processingCustomFields = false; - for (const prop in value) { - if (value.hasOwnProperty(prop)) { - if (!processingCustomFields && OfficialProps.indexOf(prop) === -1) { - processingCustomFields = true; - } - if (processingCustomFields) { - this.processKvp(cipher, prop, value[prop]); - } - } - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + this.processFolder(result, this.getValueOrDefault(value["!group_name"])); + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.title, "--"); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.URL); + + let processingCustomFields = false; + for (const prop in value) { + if (value.hasOwnProperty(prop)) { + if (!processingCustomFields && OfficialProps.indexOf(prop) === -1) { + processingCustomFields = true; + } + if (processingCustomFields) { + this.processKvp(cipher, prop, value[prop]); + } + } + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/chromeCsvImporter.ts b/common/src/importers/chromeCsvImporter.ts index 3580ec5c..41fbc251 100644 --- a/common/src/importers/chromeCsvImporter.ts +++ b/common/src/importers/chromeCsvImporter.ts @@ -1,28 +1,28 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class ChromeCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.name, '--'); - cipher.login.username = this.getValueOrDefault(value.username); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.uris = this.makeUriArray(value.url); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.name, "--"); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.url); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/clipperzHtmlImporter.ts b/common/src/importers/clipperzHtmlImporter.ts index a772ae00..8646b267 100644 --- a/common/src/importers/clipperzHtmlImporter.ts +++ b/common/src/importers/clipperzHtmlImporter.ts @@ -1,79 +1,86 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class ClipperzHtmlImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const doc = this.parseXml(data); - if (doc == null) { - result.success = false; - return Promise.resolve(result); - } - - const textarea = doc.querySelector('textarea'); - if (textarea == null || this.isNullOrWhitespace(textarea.textContent)) { - result.errorMessage = 'Missing textarea.'; - result.success = false; - return Promise.resolve(result); - } - - const entries = JSON.parse(textarea.textContent); - entries.forEach((entry: any) => { - const cipher = this.initLoginCipher(); - if (!this.isNullOrWhitespace(entry.label)) { - cipher.name = entry.label.split(' ')[0]; - } - if (entry.data != null && !this.isNullOrWhitespace(entry.data.notes)) { - cipher.notes = entry.data.notes.split('\\n').join('\n'); - } - - if (entry.currentVersion != null && entry.currentVersion.fields != null) { - for (const property in entry.currentVersion.fields) { - if (!entry.currentVersion.fields.hasOwnProperty(property)) { - continue; - } - - const field = entry.currentVersion.fields[property]; - const actionType = field.actionType != null ? field.actionType.toLowerCase() : null; - switch (actionType) { - case 'password': - cipher.login.password = this.getValueOrDefault(field.value); - break; - case 'email': - case 'username': - case 'user': - case 'name': - cipher.login.username = this.getValueOrDefault(field.value); - break; - case 'url': - cipher.login.uris = this.makeUriArray(field.value); - break; - default: - const labelLower = field.label != null ? field.label.toLowerCase() : null; - if (cipher.login.password == null && this.passwordFieldNames.indexOf(labelLower) > -1) { - cipher.login.password = this.getValueOrDefault(field.value); - } else if (cipher.login.username == null && - this.usernameFieldNames.indexOf(labelLower) > -1) { - cipher.login.username = this.getValueOrDefault(field.value); - } else if ((cipher.login.uris == null || cipher.login.uris.length === 0) && - this.uriFieldNames.indexOf(labelLower) > -1) { - cipher.login.uris = this.makeUriArray(field.value); - } else { - this.processKvp(cipher, field.label, field.value); - } - break; - } - } - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const doc = this.parseXml(data); + if (doc == null) { + result.success = false; + return Promise.resolve(result); } + + const textarea = doc.querySelector("textarea"); + if (textarea == null || this.isNullOrWhitespace(textarea.textContent)) { + result.errorMessage = "Missing textarea."; + result.success = false; + return Promise.resolve(result); + } + + const entries = JSON.parse(textarea.textContent); + entries.forEach((entry: any) => { + const cipher = this.initLoginCipher(); + if (!this.isNullOrWhitespace(entry.label)) { + cipher.name = entry.label.split(" ")[0]; + } + if (entry.data != null && !this.isNullOrWhitespace(entry.data.notes)) { + cipher.notes = entry.data.notes.split("\\n").join("\n"); + } + + if (entry.currentVersion != null && entry.currentVersion.fields != null) { + for (const property in entry.currentVersion.fields) { + if (!entry.currentVersion.fields.hasOwnProperty(property)) { + continue; + } + + const field = entry.currentVersion.fields[property]; + const actionType = field.actionType != null ? field.actionType.toLowerCase() : null; + switch (actionType) { + case "password": + cipher.login.password = this.getValueOrDefault(field.value); + break; + case "email": + case "username": + case "user": + case "name": + cipher.login.username = this.getValueOrDefault(field.value); + break; + case "url": + cipher.login.uris = this.makeUriArray(field.value); + break; + default: + const labelLower = field.label != null ? field.label.toLowerCase() : null; + if ( + cipher.login.password == null && + this.passwordFieldNames.indexOf(labelLower) > -1 + ) { + cipher.login.password = this.getValueOrDefault(field.value); + } else if ( + cipher.login.username == null && + this.usernameFieldNames.indexOf(labelLower) > -1 + ) { + cipher.login.username = this.getValueOrDefault(field.value); + } else if ( + (cipher.login.uris == null || cipher.login.uris.length === 0) && + this.uriFieldNames.indexOf(labelLower) > -1 + ) { + cipher.login.uris = this.makeUriArray(field.value); + } else { + this.processKvp(cipher, field.label, field.value); + } + break; + } + } + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/codebookCsvImporter.ts b/common/src/importers/codebookCsvImporter.ts index fdc563d2..4d7aeab8 100644 --- a/common/src/importers/codebookCsvImporter.ts +++ b/common/src/importers/codebookCsvImporter.ts @@ -1,47 +1,47 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class CodebookCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - this.processFolder(result, this.getValueOrDefault(value.Category)); - - const cipher = this.initLoginCipher(); - cipher.favorite = this.getValueOrDefault(value.Favorite) === 'True'; - cipher.name = this.getValueOrDefault(value.Entry, '--'); - cipher.notes = this.getValueOrDefault(value.Note); - cipher.login.username = this.getValueOrDefault(value.Username, value.Email); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.totp = this.getValueOrDefault(value.TOTP); - cipher.login.uris = this.makeUriArray(value.Website); - - if (!this.isNullOrWhitespace(value.Username)) { - this.processKvp(cipher, 'Email', value.Email); - } - this.processKvp(cipher, 'Phone', value.Phone); - this.processKvp(cipher, 'PIN', value.PIN); - this.processKvp(cipher, 'Account', value.Account); - this.processKvp(cipher, 'Date', value.Date); - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + this.processFolder(result, this.getValueOrDefault(value.Category)); + + const cipher = this.initLoginCipher(); + cipher.favorite = this.getValueOrDefault(value.Favorite) === "True"; + cipher.name = this.getValueOrDefault(value.Entry, "--"); + cipher.notes = this.getValueOrDefault(value.Note); + cipher.login.username = this.getValueOrDefault(value.Username, value.Email); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.totp = this.getValueOrDefault(value.TOTP); + cipher.login.uris = this.makeUriArray(value.Website); + + if (!this.isNullOrWhitespace(value.Username)) { + this.processKvp(cipher, "Email", value.Email); + } + this.processKvp(cipher, "Phone", value.Phone); + this.processKvp(cipher, "PIN", value.PIN); + this.processKvp(cipher, "Account", value.Account); + this.processKvp(cipher, "Date", value.Date); + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/dashlaneJsonImporter.ts b/common/src/importers/dashlaneJsonImporter.ts index dd8d7bb6..b3dff318 100644 --- a/common/src/importers/dashlaneJsonImporter.ts +++ b/common/src/importers/dashlaneJsonImporter.ts @@ -1,162 +1,172 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CardView } from '../models/view/cardView'; -import { CipherView } from '../models/view/cipherView'; -import { IdentityView } from '../models/view/identityView'; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { CardView } from "../models/view/cardView"; +import { CipherView } from "../models/view/cipherView"; +import { IdentityView } from "../models/view/identityView"; +import { SecureNoteView } from "../models/view/secureNoteView"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; -const HandledResults = new Set(['ADDRESS', 'AUTHENTIFIANT', 'BANKSTATEMENT', 'IDCARD', 'IDENTITY', - 'PAYMENTMEANS_CREDITCARD', 'PAYMENTMEAN_PAYPAL', 'EMAIL']); +const HandledResults = new Set([ + "ADDRESS", + "AUTHENTIFIANT", + "BANKSTATEMENT", + "IDCARD", + "IDENTITY", + "PAYMENTMEANS_CREDITCARD", + "PAYMENTMEAN_PAYPAL", + "EMAIL", +]); export class DashlaneJsonImporter extends BaseImporter implements Importer { - private result: ImportResult; + private result: ImportResult; - parse(data: string): Promise { - this.result = new ImportResult(); - const results = JSON.parse(data); - if (results == null || results.length === 0) { - this.result.success = false; - return Promise.resolve(this.result); - } - - if (results.ADDRESS != null) { - this.processAddress(results.ADDRESS); - } - if (results.AUTHENTIFIANT != null) { - this.processAuth(results.AUTHENTIFIANT); - } - if (results.BANKSTATEMENT != null) { - this.processNote(results.BANKSTATEMENT, 'BankAccountName'); - } - if (results.IDCARD != null) { - this.processNote(results.IDCARD, 'Fullname'); - } - if (results.PAYMENTMEANS_CREDITCARD != null) { - this.processCard(results.PAYMENTMEANS_CREDITCARD); - } - if (results.IDENTITY != null) { - this.processIdentity(results.IDENTITY); - } - - for (const key in results) { - if (results.hasOwnProperty(key) && !HandledResults.has(key)) { - this.processNote(results[key], null, 'Generic Note'); - } - } - - this.result.success = true; - return Promise.resolve(this.result); + parse(data: string): Promise { + this.result = new ImportResult(); + const results = JSON.parse(data); + if (results == null || results.length === 0) { + this.result.success = false; + return Promise.resolve(this.result); } - private processAuth(results: any[]) { - results.forEach((credential: any) => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(credential.title); - - cipher.login.username = this.getValueOrDefault(credential.login, - this.getValueOrDefault(credential.secondaryLogin)); - if (this.isNullOrWhitespace(cipher.login.username)) { - cipher.login.username = this.getValueOrDefault(credential.email); - } else if (!this.isNullOrWhitespace(credential.email)) { - cipher.notes = ('Email: ' + credential.email + '\n'); - } - - cipher.login.password = this.getValueOrDefault(credential.password); - cipher.login.uris = this.makeUriArray(credential.domain); - cipher.notes += this.getValueOrDefault(credential.note, ''); - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); - }); + if (results.ADDRESS != null) { + this.processAddress(results.ADDRESS); + } + if (results.AUTHENTIFIANT != null) { + this.processAuth(results.AUTHENTIFIANT); + } + if (results.BANKSTATEMENT != null) { + this.processNote(results.BANKSTATEMENT, "BankAccountName"); + } + if (results.IDCARD != null) { + this.processNote(results.IDCARD, "Fullname"); + } + if (results.PAYMENTMEANS_CREDITCARD != null) { + this.processCard(results.PAYMENTMEANS_CREDITCARD); + } + if (results.IDENTITY != null) { + this.processIdentity(results.IDENTITY); } - private processIdentity(results: any[]) { - results.forEach((obj: any) => { - const cipher = new CipherView(); - cipher.identity = new IdentityView(); - cipher.type = CipherType.Identity; - cipher.name = this.getValueOrDefault(obj.fullName, ''); - const nameParts = cipher.name.split(' '); - if (nameParts.length > 0) { - cipher.identity.firstName = this.getValueOrDefault(nameParts[0]); - } - if (nameParts.length === 2) { - cipher.identity.lastName = this.getValueOrDefault(nameParts[1]); - } else if (nameParts.length === 3) { - cipher.identity.middleName = this.getValueOrDefault(nameParts[1]); - cipher.identity.lastName = this.getValueOrDefault(nameParts[2]); - } - cipher.identity.username = this.getValueOrDefault(obj.pseudo); - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); - }); + for (const key in results) { + if (results.hasOwnProperty(key) && !HandledResults.has(key)) { + this.processNote(results[key], null, "Generic Note"); + } } - private processAddress(results: any[]) { - results.forEach((obj: any) => { - const cipher = new CipherView(); - cipher.identity = new IdentityView(); - cipher.type = CipherType.Identity; - cipher.name = this.getValueOrDefault(obj.addressName); - cipher.identity.address1 = this.getValueOrDefault(obj.addressFull); - cipher.identity.city = this.getValueOrDefault(obj.city); - cipher.identity.state = this.getValueOrDefault(obj.state); - cipher.identity.postalCode = this.getValueOrDefault(obj.zipcode); - cipher.identity.country = this.getValueOrDefault(obj.country); - if (cipher.identity.country != null) { - cipher.identity.country = cipher.identity.country.toUpperCase(); - } - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); - }); - } + this.result.success = true; + return Promise.resolve(this.result); + } - private processCard(results: any[]) { - results.forEach((obj: any) => { - const cipher = new CipherView(); - cipher.card = new CardView(); - cipher.type = CipherType.Card; - cipher.name = this.getValueOrDefault(obj.bank); - cipher.card.number = this.getValueOrDefault(obj.cardNumber); - cipher.card.brand = this.getCardBrand(cipher.card.number); - cipher.card.cardholderName = this.getValueOrDefault(obj.owner); - if (!this.isNullOrWhitespace(cipher.card.brand)) { - if (this.isNullOrWhitespace(cipher.name)) { - cipher.name = cipher.card.brand; - } else { - cipher.name += (' - ' + cipher.card.brand); - } - } - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); - }); - } + private processAuth(results: any[]) { + results.forEach((credential: any) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(credential.title); - private processNote(results: any[], nameProperty: string, name: string = null) { - results.forEach((obj: any) => { - const cipher = new CipherView(); - cipher.secureNote = new SecureNoteView(); - cipher.type = CipherType.SecureNote; - cipher.secureNote.type = SecureNoteType.Generic; - if (name != null) { - cipher.name = name; - } else { - cipher.name = this.getValueOrDefault(obj[nameProperty]); - } - for (const key in obj) { - if (obj.hasOwnProperty(key) && key !== nameProperty) { - this.processKvp(cipher, key, obj[key].toString()); - } - } - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); - }); - } + cipher.login.username = this.getValueOrDefault( + credential.login, + this.getValueOrDefault(credential.secondaryLogin) + ); + if (this.isNullOrWhitespace(cipher.login.username)) { + cipher.login.username = this.getValueOrDefault(credential.email); + } else if (!this.isNullOrWhitespace(credential.email)) { + cipher.notes = "Email: " + credential.email + "\n"; + } + + cipher.login.password = this.getValueOrDefault(credential.password); + cipher.login.uris = this.makeUriArray(credential.domain); + cipher.notes += this.getValueOrDefault(credential.note, ""); + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + }); + } + + private processIdentity(results: any[]) { + results.forEach((obj: any) => { + const cipher = new CipherView(); + cipher.identity = new IdentityView(); + cipher.type = CipherType.Identity; + cipher.name = this.getValueOrDefault(obj.fullName, ""); + const nameParts = cipher.name.split(" "); + if (nameParts.length > 0) { + cipher.identity.firstName = this.getValueOrDefault(nameParts[0]); + } + if (nameParts.length === 2) { + cipher.identity.lastName = this.getValueOrDefault(nameParts[1]); + } else if (nameParts.length === 3) { + cipher.identity.middleName = this.getValueOrDefault(nameParts[1]); + cipher.identity.lastName = this.getValueOrDefault(nameParts[2]); + } + cipher.identity.username = this.getValueOrDefault(obj.pseudo); + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + }); + } + + private processAddress(results: any[]) { + results.forEach((obj: any) => { + const cipher = new CipherView(); + cipher.identity = new IdentityView(); + cipher.type = CipherType.Identity; + cipher.name = this.getValueOrDefault(obj.addressName); + cipher.identity.address1 = this.getValueOrDefault(obj.addressFull); + cipher.identity.city = this.getValueOrDefault(obj.city); + cipher.identity.state = this.getValueOrDefault(obj.state); + cipher.identity.postalCode = this.getValueOrDefault(obj.zipcode); + cipher.identity.country = this.getValueOrDefault(obj.country); + if (cipher.identity.country != null) { + cipher.identity.country = cipher.identity.country.toUpperCase(); + } + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + }); + } + + private processCard(results: any[]) { + results.forEach((obj: any) => { + const cipher = new CipherView(); + cipher.card = new CardView(); + cipher.type = CipherType.Card; + cipher.name = this.getValueOrDefault(obj.bank); + cipher.card.number = this.getValueOrDefault(obj.cardNumber); + cipher.card.brand = this.getCardBrand(cipher.card.number); + cipher.card.cardholderName = this.getValueOrDefault(obj.owner); + if (!this.isNullOrWhitespace(cipher.card.brand)) { + if (this.isNullOrWhitespace(cipher.name)) { + cipher.name = cipher.card.brand; + } else { + cipher.name += " - " + cipher.card.brand; + } + } + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + }); + } + + private processNote(results: any[], nameProperty: string, name: string = null) { + results.forEach((obj: any) => { + const cipher = new CipherView(); + cipher.secureNote = new SecureNoteView(); + cipher.type = CipherType.SecureNote; + cipher.secureNote.type = SecureNoteType.Generic; + if (name != null) { + cipher.name = name; + } else { + cipher.name = this.getValueOrDefault(obj[nameProperty]); + } + for (const key in obj) { + if (obj.hasOwnProperty(key) && key !== nameProperty) { + this.processKvp(cipher, key, obj[key].toString()); + } + } + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + }); + } } diff --git a/common/src/importers/encryptrCsvImporter.ts b/common/src/importers/encryptrCsvImporter.ts index adad9aa7..84f55e09 100644 --- a/common/src/importers/encryptrCsvImporter.ts +++ b/common/src/importers/encryptrCsvImporter.ts @@ -1,62 +1,62 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CardView } from '../models/view/cardView'; +import { CardView } from "../models/view/cardView"; -import { CipherType } from '../enums/cipherType'; +import { CipherType } from "../enums/cipherType"; export class EncryptrCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.Label, '--'); - cipher.notes = this.getValueOrDefault(value.Notes); - const text = this.getValueOrDefault(value.Text); - if (!this.isNullOrWhitespace(text)) { - if (this.isNullOrWhitespace(cipher.notes)) { - cipher.notes = text; - } else { - cipher.notes += ('\n\n' + text); - } - } - - const type = value['Entry Type']; - if (type === 'Password') { - cipher.login.username = this.getValueOrDefault(value.Username); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.uris = this.makeUriArray(value['Site URL']); - } else if (type === 'Credit Card') { - cipher.type = CipherType.Card; - cipher.card = new CardView(); - cipher.card.cardholderName = this.getValueOrDefault(value['Name on card']); - cipher.card.number = this.getValueOrDefault(value['Card Number']); - cipher.card.brand = this.getCardBrand(cipher.card.number); - cipher.card.code = this.getValueOrDefault(value.CVV); - const expiry = this.getValueOrDefault(value.Expiry); - if (!this.isNullOrWhitespace(expiry)) { - const expParts = expiry.split('/'); - if (expParts.length > 1) { - cipher.card.expMonth = parseInt(expParts[0], null).toString(); - cipher.card.expYear = (2000 + parseInt(expParts[1], null)).toString(); - } - } - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.Label, "--"); + cipher.notes = this.getValueOrDefault(value.Notes); + const text = this.getValueOrDefault(value.Text); + if (!this.isNullOrWhitespace(text)) { + if (this.isNullOrWhitespace(cipher.notes)) { + cipher.notes = text; + } else { + cipher.notes += "\n\n" + text; + } + } + + const type = value["Entry Type"]; + if (type === "Password") { + cipher.login.username = this.getValueOrDefault(value.Username); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.uris = this.makeUriArray(value["Site URL"]); + } else if (type === "Credit Card") { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + cipher.card.cardholderName = this.getValueOrDefault(value["Name on card"]); + cipher.card.number = this.getValueOrDefault(value["Card Number"]); + cipher.card.brand = this.getCardBrand(cipher.card.number); + cipher.card.code = this.getValueOrDefault(value.CVV); + const expiry = this.getValueOrDefault(value.Expiry); + if (!this.isNullOrWhitespace(expiry)) { + const expParts = expiry.split("/"); + if (expParts.length > 1) { + cipher.card.expMonth = parseInt(expParts[0], null).toString(); + cipher.card.expYear = (2000 + parseInt(expParts[1], null)).toString(); + } + } + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/enpassCsvImporter.ts b/common/src/importers/enpassCsvImporter.ts index 0b421d96..5f9ad54e 100644 --- a/common/src/importers/enpassCsvImporter.ts +++ b/common/src/importers/enpassCsvImporter.ts @@ -1,112 +1,135 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; -import { CardView } from '../models/view/cardView'; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { CardView } from "../models/view/cardView"; +import { SecureNoteView } from "../models/view/secureNoteView"; export class EnpassCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - let firstRow = true; - results.forEach(value => { - if (value.length < 2 || (firstRow && (value[0] === 'Title' || value[0] === 'title'))) { - firstRow = false; - return; - } - - const cipher = this.initLoginCipher(); - cipher.notes = this.getValueOrDefault(value[value.length - 1]); - cipher.name = this.getValueOrDefault(value[0], '--'); - - if (value.length === 2 || (!this.containsField(value, 'username') && - !this.containsField(value, 'password') && !this.containsField(value, 'email') && - !this.containsField(value, 'url'))) { - cipher.type = CipherType.SecureNote; - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - } - - if (this.containsField(value, 'cardholder') && this.containsField(value, 'number') && - this.containsField(value, 'expiry date')) { - cipher.type = CipherType.Card; - cipher.card = new CardView(); - } - - if (value.length > 2 && (value.length % 2) === 0) { - for (let i = 0; i < value.length - 2; i += 2) { - const fieldValue: string = value[i + 2]; - if (this.isNullOrWhitespace(fieldValue)) { - continue; - } - - const fieldName: string = value[i + 1]; - const fieldNameLower = fieldName.toLowerCase(); - - if (cipher.type === CipherType.Login) { - if (fieldNameLower === 'url' && (cipher.login.uris == null || cipher.login.uris.length === 0)) { - cipher.login.uris = this.makeUriArray(fieldValue); - continue; - } else if ((fieldNameLower === 'username' || fieldNameLower === 'email') && - this.isNullOrWhitespace(cipher.login.username)) { - cipher.login.username = fieldValue; - continue; - } else if (fieldNameLower === 'password' && this.isNullOrWhitespace(cipher.login.password)) { - cipher.login.password = fieldValue; - continue; - } else if (fieldNameLower === 'totp' && this.isNullOrWhitespace(cipher.login.totp)) { - cipher.login.totp = fieldValue; - continue; - } - } else if (cipher.type === CipherType.Card) { - if (fieldNameLower === 'cardholder' && this.isNullOrWhitespace(cipher.card.cardholderName)) { - cipher.card.cardholderName = fieldValue; - continue; - } else if (fieldNameLower === 'number' && this.isNullOrWhitespace(cipher.card.number)) { - cipher.card.number = fieldValue; - cipher.card.brand = this.getCardBrand(fieldValue); - continue; - } else if (fieldNameLower === 'cvc' && this.isNullOrWhitespace(cipher.card.code)) { - cipher.card.code = fieldValue; - continue; - } else if (fieldNameLower === 'expiry date' && this.isNullOrWhitespace(cipher.card.expMonth) && - this.isNullOrWhitespace(cipher.card.expYear)) { - if (this.setCardExpiration(cipher, fieldValue)) { - continue; - } - } else if (fieldNameLower === 'type') { - // Skip since brand was determined from number above - continue; - } - } - - this.processKvp(cipher, fieldName, fieldValue); - } - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } - private containsField(fields: any[], name: string) { - if (fields == null || name == null) { - return false; + let firstRow = true; + results.forEach((value) => { + if (value.length < 2 || (firstRow && (value[0] === "Title" || value[0] === "title"))) { + firstRow = false; + return; + } + + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value[value.length - 1]); + cipher.name = this.getValueOrDefault(value[0], "--"); + + if ( + value.length === 2 || + (!this.containsField(value, "username") && + !this.containsField(value, "password") && + !this.containsField(value, "email") && + !this.containsField(value, "url")) + ) { + cipher.type = CipherType.SecureNote; + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + } + + if ( + this.containsField(value, "cardholder") && + this.containsField(value, "number") && + this.containsField(value, "expiry date") + ) { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + } + + if (value.length > 2 && value.length % 2 === 0) { + for (let i = 0; i < value.length - 2; i += 2) { + const fieldValue: string = value[i + 2]; + if (this.isNullOrWhitespace(fieldValue)) { + continue; + } + + const fieldName: string = value[i + 1]; + const fieldNameLower = fieldName.toLowerCase(); + + if (cipher.type === CipherType.Login) { + if ( + fieldNameLower === "url" && + (cipher.login.uris == null || cipher.login.uris.length === 0) + ) { + cipher.login.uris = this.makeUriArray(fieldValue); + continue; + } else if ( + (fieldNameLower === "username" || fieldNameLower === "email") && + this.isNullOrWhitespace(cipher.login.username) + ) { + cipher.login.username = fieldValue; + continue; + } else if ( + fieldNameLower === "password" && + this.isNullOrWhitespace(cipher.login.password) + ) { + cipher.login.password = fieldValue; + continue; + } else if (fieldNameLower === "totp" && this.isNullOrWhitespace(cipher.login.totp)) { + cipher.login.totp = fieldValue; + continue; + } + } else if (cipher.type === CipherType.Card) { + if ( + fieldNameLower === "cardholder" && + this.isNullOrWhitespace(cipher.card.cardholderName) + ) { + cipher.card.cardholderName = fieldValue; + continue; + } else if (fieldNameLower === "number" && this.isNullOrWhitespace(cipher.card.number)) { + cipher.card.number = fieldValue; + cipher.card.brand = this.getCardBrand(fieldValue); + continue; + } else if (fieldNameLower === "cvc" && this.isNullOrWhitespace(cipher.card.code)) { + cipher.card.code = fieldValue; + continue; + } else if ( + fieldNameLower === "expiry date" && + this.isNullOrWhitespace(cipher.card.expMonth) && + this.isNullOrWhitespace(cipher.card.expYear) + ) { + if (this.setCardExpiration(cipher, fieldValue)) { + continue; + } + } else if (fieldNameLower === "type") { + // Skip since brand was determined from number above + continue; + } + } + + this.processKvp(cipher, fieldName, fieldValue); } - return fields.filter(f => !this.isNullOrWhitespace(f) && - f.toLowerCase() === name.toLowerCase()).length > 0; + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } + + private containsField(fields: any[], name: string) { + if (fields == null || name == null) { + return false; } + return ( + fields.filter((f) => !this.isNullOrWhitespace(f) && f.toLowerCase() === name.toLowerCase()) + .length > 0 + ); + } } diff --git a/common/src/importers/enpassJsonImporter.ts b/common/src/importers/enpassJsonImporter.ts index 1b325224..631fbc51 100644 --- a/common/src/importers/enpassJsonImporter.ts +++ b/common/src/importers/enpassJsonImporter.ts @@ -1,163 +1,193 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CardView } from '../models/view/cardView'; -import { CipherView } from '../models/view/cipherView'; -import { FolderView } from '../models/view/folderView'; +import { CardView } from "../models/view/cardView"; +import { CipherView } from "../models/view/cipherView"; +import { FolderView } from "../models/view/folderView"; -import { CipherType } from '../enums/cipherType'; -import { FieldType } from '../enums/fieldType'; +import { CipherType } from "../enums/cipherType"; +import { FieldType } from "../enums/fieldType"; export class EnpassJsonImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = JSON.parse(data); - if (results == null || results.items == null || results.items.length === 0) { - result.success = false; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = JSON.parse(data); + if (results == null || results.items == null || results.items.length === 0) { + result.success = false; + return Promise.resolve(result); + } + + const foldersMap = new Map(); + const foldersIndexMap = new Map(); + const folderTree = this.buildFolderTree(results.folders); + this.flattenFolderTree(null, folderTree, foldersMap); + foldersMap.forEach((val, key) => { + foldersIndexMap.set(key, result.folders.length); + const f = new FolderView(); + f.name = val; + result.folders.push(f); + }); + + results.items.forEach((item: any) => { + if (item.folders != null && item.folders.length > 0 && foldersIndexMap.has(item.folders[0])) { + result.folderRelationships.push([ + result.ciphers.length, + foldersIndexMap.get(item.folders[0]), + ]); + } + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(item.title); + cipher.favorite = item.favorite > 0; + + if (item.template_type != null && item.fields != null && item.fields.length > 0) { + if ( + item.template_type.indexOf("login.") === 0 || + item.template_type.indexOf("password.") === 0 + ) { + this.processLogin(cipher, item.fields); + } else if (item.template_type.indexOf("creditcard.") === 0) { + this.processCard(cipher, item.fields); + } else if ( + item.template_type.indexOf("identity.") < 0 && + item.fields.some((f: any) => f.type === "password" && !this.isNullOrWhitespace(f.value)) + ) { + this.processLogin(cipher, item.fields); + } else { + this.processNote(cipher, item.fields); } + } - const foldersMap = new Map(); - const foldersIndexMap = new Map(); - const folderTree = this.buildFolderTree(results.folders); - this.flattenFolderTree(null, folderTree, foldersMap); - foldersMap.forEach((val, key) => { - foldersIndexMap.set(key, result.folders.length); - const f = new FolderView(); - f.name = val; - result.folders.push(f); - }); + cipher.notes += "\n" + this.getValueOrDefault(item.note, ""); + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); - results.items.forEach((item: any) => { - if (item.folders != null && item.folders.length > 0 && foldersIndexMap.has(item.folders[0])) { - result.folderRelationships.push([result.ciphers.length, foldersIndexMap.get(item.folders[0])]); - } + result.success = true; + return Promise.resolve(result); + } - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(item.title); - cipher.favorite = item.favorite > 0; + private processLogin(cipher: CipherView, fields: any[]) { + const urls: string[] = []; + fields.forEach((field: any) => { + if (this.isNullOrWhitespace(field.value) || field.type === "section") { + return; + } - if (item.template_type != null && item.fields != null && item.fields.length > 0) { - if (item.template_type.indexOf('login.') === 0 || item.template_type.indexOf('password.') === 0) { - this.processLogin(cipher, item.fields); - } else if (item.template_type.indexOf('creditcard.') === 0) { - this.processCard(cipher, item.fields); - } else if (item.template_type.indexOf('identity.') < 0 && - item.fields.some((f: any) => f.type === 'password' && !this.isNullOrWhitespace(f.value))) { - this.processLogin(cipher, item.fields); - } else { - this.processNote(cipher, item.fields); - } - } + if ( + (field.type === "username" || field.type === "email") && + this.isNullOrWhitespace(cipher.login.username) + ) { + cipher.login.username = field.value; + } else if (field.type === "password" && this.isNullOrWhitespace(cipher.login.password)) { + cipher.login.password = field.value; + } else if (field.type === "totp" && this.isNullOrWhitespace(cipher.login.totp)) { + cipher.login.totp = field.value; + } else if (field.type === "url") { + urls.push(field.value); + } else { + this.processKvp( + cipher, + field.label, + field.value, + field.sensitive === 1 ? FieldType.Hidden : FieldType.Text + ); + } + }); + cipher.login.uris = this.makeUriArray(urls); + } - cipher.notes += ('\n' + this.getValueOrDefault(item.note, '')); - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); + private processCard(cipher: CipherView, fields: any[]) { + cipher.card = new CardView(); + cipher.type = CipherType.Card; + fields.forEach((field: any) => { + if ( + this.isNullOrWhitespace(field.value) || + field.type === "section" || + field.type === "ccType" + ) { + return; + } - result.success = true; - return Promise.resolve(result); - } - - private processLogin(cipher: CipherView, fields: any[]) { - const urls: string[] = []; - fields.forEach((field: any) => { - if (this.isNullOrWhitespace(field.value) || field.type === 'section') { - return; - } - - if ((field.type === 'username' || field.type === 'email') && - this.isNullOrWhitespace(cipher.login.username)) { - cipher.login.username = field.value; - } else if (field.type === 'password' && this.isNullOrWhitespace(cipher.login.password)) { - cipher.login.password = field.value; - } else if (field.type === 'totp' && this.isNullOrWhitespace(cipher.login.totp)) { - cipher.login.totp = field.value; - } else if (field.type === 'url') { - urls.push(field.value); - } else { - this.processKvp(cipher, field.label, field.value, - field.sensitive === 1 ? FieldType.Hidden : FieldType.Text); - } - }); - cipher.login.uris = this.makeUriArray(urls); - } - - private processCard(cipher: CipherView, fields: any[]) { - cipher.card = new CardView(); - cipher.type = CipherType.Card; - fields.forEach((field: any) => { - if (this.isNullOrWhitespace(field.value) || field.type === 'section' || field.type === 'ccType') { - return; - } - - if (field.type === 'ccName' && this.isNullOrWhitespace(cipher.card.cardholderName)) { - cipher.card.cardholderName = field.value; - } else if (field.type === 'ccNumber' && this.isNullOrWhitespace(cipher.card.number)) { - cipher.card.number = field.value; - cipher.card.brand = this.getCardBrand(cipher.card.number); - } else if (field.type === 'ccCvc' && this.isNullOrWhitespace(cipher.card.code)) { - cipher.card.code = field.value; - } else if (field.type === 'ccExpiry' && this.isNullOrWhitespace(cipher.card.expYear)) { - if (!this.setCardExpiration(cipher, field.value)) { - this.processKvp(cipher, field.label, field.value, - field.sensitive === 1 ? FieldType.Hidden : FieldType.Text); - } - } else { - this.processKvp(cipher, field.label, field.value, - field.sensitive === 1 ? FieldType.Hidden : FieldType.Text); - } - }); - } - - private processNote(cipher: CipherView, fields: any[]) { - fields.forEach((field: any) => { - if (this.isNullOrWhitespace(field.value) || field.type === 'section') { - return; - } - this.processKvp(cipher, field.label, field.value, - field.sensitive === 1 ? FieldType.Hidden : FieldType.Text); - }); - } - - private buildFolderTree(folders: any[]): any[] { - if (folders == null) { - return []; + if (field.type === "ccName" && this.isNullOrWhitespace(cipher.card.cardholderName)) { + cipher.card.cardholderName = field.value; + } else if (field.type === "ccNumber" && this.isNullOrWhitespace(cipher.card.number)) { + cipher.card.number = field.value; + cipher.card.brand = this.getCardBrand(cipher.card.number); + } else if (field.type === "ccCvc" && this.isNullOrWhitespace(cipher.card.code)) { + cipher.card.code = field.value; + } else if (field.type === "ccExpiry" && this.isNullOrWhitespace(cipher.card.expYear)) { + if (!this.setCardExpiration(cipher, field.value)) { + this.processKvp( + cipher, + field.label, + field.value, + field.sensitive === 1 ? FieldType.Hidden : FieldType.Text + ); } - const folderTree: any[] = []; - const map = new Map([]); - folders.forEach((obj: any) => { - map.set(obj.uuid, obj); - obj.children = []; - }); - folders.forEach((obj: any) => { - if (obj.parent_uuid != null && obj.parent_uuid !== '' && map.has(obj.parent_uuid)) { - map.get(obj.parent_uuid).children.push(obj); - } else { - folderTree.push(obj); - } - }); - return folderTree; - } + } else { + this.processKvp( + cipher, + field.label, + field.value, + field.sensitive === 1 ? FieldType.Hidden : FieldType.Text + ); + } + }); + } - private flattenFolderTree(titlePrefix: string, tree: any[], map: Map) { - if (tree == null) { - return; - } - tree.forEach((f: any) => { - if (f.title != null && f.title.trim() !== '') { - let title = f.title.trim(); - if (titlePrefix != null && titlePrefix.trim() !== '') { - title = titlePrefix + '/' + title; - } - map.set(f.uuid, title); - if (f.children != null && f.children.length !== 0) { - this.flattenFolderTree(title, f.children, map); - } - } - }); + private processNote(cipher: CipherView, fields: any[]) { + fields.forEach((field: any) => { + if (this.isNullOrWhitespace(field.value) || field.type === "section") { + return; + } + this.processKvp( + cipher, + field.label, + field.value, + field.sensitive === 1 ? FieldType.Hidden : FieldType.Text + ); + }); + } + + private buildFolderTree(folders: any[]): any[] { + if (folders == null) { + return []; } + const folderTree: any[] = []; + const map = new Map([]); + folders.forEach((obj: any) => { + map.set(obj.uuid, obj); + obj.children = []; + }); + folders.forEach((obj: any) => { + if (obj.parent_uuid != null && obj.parent_uuid !== "" && map.has(obj.parent_uuid)) { + map.get(obj.parent_uuid).children.push(obj); + } else { + folderTree.push(obj); + } + }); + return folderTree; + } + + private flattenFolderTree(titlePrefix: string, tree: any[], map: Map) { + if (tree == null) { + return; + } + tree.forEach((f: any) => { + if (f.title != null && f.title.trim() !== "") { + let title = f.title.trim(); + if (titlePrefix != null && titlePrefix.trim() !== "") { + title = titlePrefix + "/" + title; + } + map.set(f.uuid, title); + if (f.children != null && f.children.length !== 0) { + this.flattenFolderTree(title, f.children, map); + } + } + }); + } } diff --git a/common/src/importers/firefoxCsvImporter.ts b/common/src/importers/firefoxCsvImporter.ts index df82cf97..3fc97a63 100644 --- a/common/src/importers/firefoxCsvImporter.ts +++ b/common/src/importers/firefoxCsvImporter.ts @@ -1,31 +1,33 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class FirefoxCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.filter(value => { - return value.url !== 'chrome://FirefoxAccounts'; - }).forEach(value => { - const cipher = this.initLoginCipher(); - const url = this.getValueOrDefault(value.url, this.getValueOrDefault(value.hostname)); - cipher.name = this.getValueOrDefault(this.nameFromUrl(url), '--'); - cipher.login.username = this.getValueOrDefault(value.username); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.uris = this.makeUriArray(url); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results + .filter((value) => { + return value.url !== "chrome://FirefoxAccounts"; + }) + .forEach((value) => { + const cipher = this.initLoginCipher(); + const url = this.getValueOrDefault(value.url, this.getValueOrDefault(value.hostname)); + cipher.name = this.getValueOrDefault(this.nameFromUrl(url), "--"); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(url); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/gnomeJsonImporter.ts b/common/src/importers/gnomeJsonImporter.ts index 23ebfc83..98dc79b5 100644 --- a/common/src/importers/gnomeJsonImporter.ts +++ b/common/src/importers/gnomeJsonImporter.ts @@ -1,60 +1,71 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class GnomeJsonImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = JSON.parse(data); - if (results == null || Object.keys(results).length === 0) { - result.success = false; - return Promise.resolve(result); - } - - for (const keyRing in results) { - if (!results.hasOwnProperty(keyRing) || this.isNullOrWhitespace(keyRing) || - results[keyRing].length === 0) { - continue; - } - - results[keyRing].forEach((value: any) => { - if (this.isNullOrWhitespace(value.display_name) || value.display_name.indexOf('http') !== 0) { - return; - } - - this.processFolder(result, keyRing); - const cipher = this.initLoginCipher(); - cipher.name = value.display_name.replace('http://', '').replace('https://', ''); - if (cipher.name.length > 30) { - cipher.name = cipher.name.substring(0, 30); - } - cipher.login.password = this.getValueOrDefault(value.secret); - cipher.login.uris = this.makeUriArray(value.display_name); - - if (value.attributes != null) { - cipher.login.username = value.attributes != null ? - this.getValueOrDefault(value.attributes.username_value) : null; - for (const attr in value.attributes) { - if (!value.attributes.hasOwnProperty(attr) || attr === 'username_value' || - attr === 'xdg:schema') { - continue; - } - this.processKvp(cipher, attr, value.attributes[attr]); - } - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - } - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = JSON.parse(data); + if (results == null || Object.keys(results).length === 0) { + result.success = false; + return Promise.resolve(result); } + + for (const keyRing in results) { + if ( + !results.hasOwnProperty(keyRing) || + this.isNullOrWhitespace(keyRing) || + results[keyRing].length === 0 + ) { + continue; + } + + results[keyRing].forEach((value: any) => { + if ( + this.isNullOrWhitespace(value.display_name) || + value.display_name.indexOf("http") !== 0 + ) { + return; + } + + this.processFolder(result, keyRing); + const cipher = this.initLoginCipher(); + cipher.name = value.display_name.replace("http://", "").replace("https://", ""); + if (cipher.name.length > 30) { + cipher.name = cipher.name.substring(0, 30); + } + cipher.login.password = this.getValueOrDefault(value.secret); + cipher.login.uris = this.makeUriArray(value.display_name); + + if (value.attributes != null) { + cipher.login.username = + value.attributes != null + ? this.getValueOrDefault(value.attributes.username_value) + : null; + for (const attr in value.attributes) { + if ( + !value.attributes.hasOwnProperty(attr) || + attr === "username_value" || + attr === "xdg:schema" + ) { + continue; + } + this.processKvp(cipher, attr, value.attributes[attr]); + } + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + } + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/importer.ts b/common/src/importers/importer.ts index 487dc184..a62cc6c1 100644 --- a/common/src/importers/importer.ts +++ b/common/src/importers/importer.ts @@ -1,6 +1,6 @@ -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export interface Importer { - organizationId: string; - parse(data: string): Promise; + organizationId: string; + parse(data: string): Promise; } diff --git a/common/src/importers/kasperskyTxtImporter.ts b/common/src/importers/kasperskyTxtImporter.ts index efaf9228..b4745e1d 100644 --- a/common/src/importers/kasperskyTxtImporter.ts +++ b/common/src/importers/kasperskyTxtImporter.ts @@ -1,124 +1,124 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -const NotesHeader = 'Notes\n\n'; -const ApplicationsHeader = 'Applications\n\n'; -const WebsitesHeader = 'Websites\n\n'; -const Delimiter = '\n---\n'; +const NotesHeader = "Notes\n\n"; +const ApplicationsHeader = "Applications\n\n"; +const WebsitesHeader = "Websites\n\n"; +const Delimiter = "\n---\n"; export class KasperskyTxtImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); + parse(data: string): Promise { + const result = new ImportResult(); - let notesData: string; - let applicationsData: string; - let websitesData: string; - let workingData = this.splitNewLine(data).join('\n'); + let notesData: string; + let applicationsData: string; + let websitesData: string; + let workingData = this.splitNewLine(data).join("\n"); - if (workingData.indexOf(NotesHeader) !== -1) { - const parts = workingData.split(NotesHeader); - if (parts.length > 1) { - workingData = parts[0]; - notesData = parts[1]; - } - } - if (workingData.indexOf(ApplicationsHeader) !== -1) { - const parts = workingData.split(ApplicationsHeader); - if (parts.length > 1) { - workingData = parts[0]; - applicationsData = parts[1]; - } - } - if (workingData.indexOf(WebsitesHeader) === 0) { - const parts = workingData.split(WebsitesHeader); - if (parts.length > 1) { - workingData = parts[0]; - websitesData = parts[1]; - } - } - - const notes = this.parseDataCategory(notesData); - const applications = this.parseDataCategory(applicationsData); - const websites = this.parseDataCategory(websitesData); - - notes.forEach(n => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(n.get('Name')); - cipher.notes = this.getValueOrDefault(n.get('Text')); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - websites.concat(applications).forEach(w => { - const cipher = this.initLoginCipher(); - const nameKey = w.has('Website name') ? 'Website name' : 'Application'; - cipher.name = this.getValueOrDefault(w.get(nameKey), ''); - if (!this.isNullOrWhitespace(w.get('Login name'))) { - if (!this.isNullOrWhitespace(cipher.name)) { - cipher.name += ': '; - } - cipher.name += w.get('Login name'); - } - cipher.notes = this.getValueOrDefault(w.get('Comment')); - if (w.has('Website URL')) { - cipher.login.uris = this.makeUriArray(w.get('Website URL')); - } - cipher.login.username = this.getValueOrDefault(w.get('Login')); - cipher.login.password = this.getValueOrDefault(w.get('Password')); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + if (workingData.indexOf(NotesHeader) !== -1) { + const parts = workingData.split(NotesHeader); + if (parts.length > 1) { + workingData = parts[0]; + notesData = parts[1]; + } + } + if (workingData.indexOf(ApplicationsHeader) !== -1) { + const parts = workingData.split(ApplicationsHeader); + if (parts.length > 1) { + workingData = parts[0]; + applicationsData = parts[1]; + } + } + if (workingData.indexOf(WebsitesHeader) === 0) { + const parts = workingData.split(WebsitesHeader); + if (parts.length > 1) { + workingData = parts[0]; + websitesData = parts[1]; + } } - private parseDataCategory(data: string): Map[] { - if (this.isNullOrWhitespace(data) || data.indexOf(Delimiter) === -1) { - return []; + const notes = this.parseDataCategory(notesData); + const applications = this.parseDataCategory(applicationsData); + const websites = this.parseDataCategory(websitesData); + + notes.forEach((n) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(n.get("Name")); + cipher.notes = this.getValueOrDefault(n.get("Text")); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + websites.concat(applications).forEach((w) => { + const cipher = this.initLoginCipher(); + const nameKey = w.has("Website name") ? "Website name" : "Application"; + cipher.name = this.getValueOrDefault(w.get(nameKey), ""); + if (!this.isNullOrWhitespace(w.get("Login name"))) { + if (!this.isNullOrWhitespace(cipher.name)) { + cipher.name += ": "; } - const items: Map[] = []; - data.split(Delimiter).forEach(p => { - if (p.indexOf('\n') === -1) { - return; - } - const item = new Map(); - let itemComment: string; - let itemCommentKey: string; - p.split('\n').forEach(l => { - if (itemComment != null) { - itemComment += ('\n' + l); - return; - } - const colonIndex = l.indexOf(':'); - let key: string; - let val: string; - if (colonIndex === -1) { - return; - } else { - key = l.substring(0, colonIndex); - if (l.length > colonIndex + 1) { - val = l.substring(colonIndex + 2); - } - } - if (key != null) { - item.set(key, val); - } - if (key === 'Comment' || key === 'Text') { - itemComment = val; - itemCommentKey = key; - } - }); - if (itemComment != null && itemCommentKey != null) { - item.set(itemCommentKey, itemComment); - } - if (item.size === 0) { - return; - } - items.push(item); - }); - return items; + cipher.name += w.get("Login name"); + } + cipher.notes = this.getValueOrDefault(w.get("Comment")); + if (w.has("Website URL")) { + cipher.login.uris = this.makeUriArray(w.get("Website URL")); + } + cipher.login.username = this.getValueOrDefault(w.get("Login")); + cipher.login.password = this.getValueOrDefault(w.get("Password")); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } + + private parseDataCategory(data: string): Map[] { + if (this.isNullOrWhitespace(data) || data.indexOf(Delimiter) === -1) { + return []; } + const items: Map[] = []; + data.split(Delimiter).forEach((p) => { + if (p.indexOf("\n") === -1) { + return; + } + const item = new Map(); + let itemComment: string; + let itemCommentKey: string; + p.split("\n").forEach((l) => { + if (itemComment != null) { + itemComment += "\n" + l; + return; + } + const colonIndex = l.indexOf(":"); + let key: string; + let val: string; + if (colonIndex === -1) { + return; + } else { + key = l.substring(0, colonIndex); + if (l.length > colonIndex + 1) { + val = l.substring(colonIndex + 2); + } + } + if (key != null) { + item.set(key, val); + } + if (key === "Comment" || key === "Text") { + itemComment = val; + itemCommentKey = key; + } + }); + if (itemComment != null && itemCommentKey != null) { + item.set(itemCommentKey, itemComment); + } + if (item.size === 0) { + return; + } + items.push(item); + }); + return items; + } } diff --git a/common/src/importers/keepass2XmlImporter.ts b/common/src/importers/keepass2XmlImporter.ts index c91a925f..f6a61cf8 100644 --- a/common/src/importers/keepass2XmlImporter.ts +++ b/common/src/importers/keepass2XmlImporter.ts @@ -1,100 +1,103 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { FieldType } from '../enums/fieldType'; +import { FieldType } from "../enums/fieldType"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { FolderView } from '../models/view/folderView'; +import { FolderView } from "../models/view/folderView"; export class KeePass2XmlImporter extends BaseImporter implements Importer { - result = new ImportResult(); + result = new ImportResult(); - parse(data: string): Promise { - const doc = this.parseXml(data); - if (doc == null) { - this.result.success = false; - return Promise.resolve(this.result); - } - - const rootGroup = doc.querySelector('KeePassFile > Root > Group'); - if (rootGroup == null) { - this.result.errorMessage = 'Missing `KeePassFile > Root > Group` node.'; - this.result.success = false; - return Promise.resolve(this.result); - } - - this.traverse(rootGroup, true, ''); - - if (this.organization) { - this.moveFoldersToCollections(this.result); - } - - this.result.success = true; - return Promise.resolve(this.result); + parse(data: string): Promise { + const doc = this.parseXml(data); + if (doc == null) { + this.result.success = false; + return Promise.resolve(this.result); } - traverse(node: Element, isRootNode: boolean, groupPrefixName: string) { - const folderIndex = this.result.folders.length; - let groupName = groupPrefixName; - - if (!isRootNode) { - if (groupName !== '') { - groupName += '/'; - } - const nameEl = this.querySelectorDirectChild(node, 'Name'); - groupName += nameEl == null ? '-' : nameEl.textContent; - const folder = new FolderView(); - folder.name = groupName; - this.result.folders.push(folder); - } - - this.querySelectorAllDirectChild(node, 'Entry').forEach(entry => { - const cipherIndex = this.result.ciphers.length; - - const cipher = this.initLoginCipher(); - this.querySelectorAllDirectChild(entry, 'String').forEach(entryString => { - const valueEl = this.querySelectorDirectChild(entryString, 'Value'); - const value = valueEl != null ? valueEl.textContent : null; - if (this.isNullOrWhitespace(value)) { - return; - } - const keyEl = this.querySelectorDirectChild(entryString, 'Key'); - const key = keyEl != null ? keyEl.textContent : null; - - if (key === 'URL') { - cipher.login.uris = this.makeUriArray(value); - } else if (key === 'UserName') { - cipher.login.username = value; - } else if (key === 'Password') { - cipher.login.password = value; - } else if (key === 'otp') { - cipher.login.totp = value.replace('key=', ''); - } else if (key === 'Title') { - cipher.name = value; - } else if (key === 'Notes') { - cipher.notes += (value + '\n'); - } else { - let type = FieldType.Text; - const attrs = (valueEl.attributes as any); - if (attrs.length > 0 && attrs.ProtectInMemory != null && - attrs.ProtectInMemory.value === 'True') { - type = FieldType.Hidden; - } - this.processKvp(cipher, key, value, type); - } - }); - - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); - - if (!isRootNode) { - this.result.folderRelationships.push([cipherIndex, folderIndex]); - } - }); - - this.querySelectorAllDirectChild(node, 'Group').forEach(group => { - this.traverse(group, false, groupName); - }); + const rootGroup = doc.querySelector("KeePassFile > Root > Group"); + if (rootGroup == null) { + this.result.errorMessage = "Missing `KeePassFile > Root > Group` node."; + this.result.success = false; + return Promise.resolve(this.result); } + + this.traverse(rootGroup, true, ""); + + if (this.organization) { + this.moveFoldersToCollections(this.result); + } + + this.result.success = true; + return Promise.resolve(this.result); + } + + traverse(node: Element, isRootNode: boolean, groupPrefixName: string) { + const folderIndex = this.result.folders.length; + let groupName = groupPrefixName; + + if (!isRootNode) { + if (groupName !== "") { + groupName += "/"; + } + const nameEl = this.querySelectorDirectChild(node, "Name"); + groupName += nameEl == null ? "-" : nameEl.textContent; + const folder = new FolderView(); + folder.name = groupName; + this.result.folders.push(folder); + } + + this.querySelectorAllDirectChild(node, "Entry").forEach((entry) => { + const cipherIndex = this.result.ciphers.length; + + const cipher = this.initLoginCipher(); + this.querySelectorAllDirectChild(entry, "String").forEach((entryString) => { + const valueEl = this.querySelectorDirectChild(entryString, "Value"); + const value = valueEl != null ? valueEl.textContent : null; + if (this.isNullOrWhitespace(value)) { + return; + } + const keyEl = this.querySelectorDirectChild(entryString, "Key"); + const key = keyEl != null ? keyEl.textContent : null; + + if (key === "URL") { + cipher.login.uris = this.makeUriArray(value); + } else if (key === "UserName") { + cipher.login.username = value; + } else if (key === "Password") { + cipher.login.password = value; + } else if (key === "otp") { + cipher.login.totp = value.replace("key=", ""); + } else if (key === "Title") { + cipher.name = value; + } else if (key === "Notes") { + cipher.notes += value + "\n"; + } else { + let type = FieldType.Text; + const attrs = valueEl.attributes as any; + if ( + attrs.length > 0 && + attrs.ProtectInMemory != null && + attrs.ProtectInMemory.value === "True" + ) { + type = FieldType.Hidden; + } + this.processKvp(cipher, key, value, type); + } + }); + + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + + if (!isRootNode) { + this.result.folderRelationships.push([cipherIndex, folderIndex]); + } + }); + + this.querySelectorAllDirectChild(node, "Group").forEach((group) => { + this.traverse(group, false, groupName); + }); + } } diff --git a/common/src/importers/keepassxCsvImporter.ts b/common/src/importers/keepassxCsvImporter.ts index 6845c8e8..6c5812bd 100644 --- a/common/src/importers/keepassxCsvImporter.ts +++ b/common/src/importers/keepassxCsvImporter.ts @@ -1,42 +1,44 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class KeePassXCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (this.isNullOrWhitespace(value.Title)) { - return; - } - - value.Group = !this.isNullOrWhitespace(value.Group) && value.Group.startsWith('Root/') ? - value.Group.replace('Root/', '') : value.Group; - const groupName = !this.isNullOrWhitespace(value.Group) ? value.Group : null; - this.processFolder(result, groupName); - - const cipher = this.initLoginCipher(); - cipher.notes = this.getValueOrDefault(value.Notes); - cipher.name = this.getValueOrDefault(value.Title, '--'); - cipher.login.username = this.getValueOrDefault(value.Username); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.uris = this.makeUriArray(value.URL); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (this.isNullOrWhitespace(value.Title)) { + return; + } + + value.Group = + !this.isNullOrWhitespace(value.Group) && value.Group.startsWith("Root/") + ? value.Group.replace("Root/", "") + : value.Group; + const groupName = !this.isNullOrWhitespace(value.Group) ? value.Group : null; + this.processFolder(result, groupName); + + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value.Notes); + cipher.name = this.getValueOrDefault(value.Title, "--"); + cipher.login.username = this.getValueOrDefault(value.Username); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.uris = this.makeUriArray(value.URL); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/keeperCsvImporter.ts b/common/src/importers/keeperCsvImporter.ts index e10b8f33..88ed061e 100644 --- a/common/src/importers/keeperCsvImporter.ts +++ b/common/src/importers/keeperCsvImporter.ts @@ -1,48 +1,48 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { FolderView } from '../models/view/folderView'; +import { FolderView } from "../models/view/folderView"; export class KeeperCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.length < 6) { - return; - } - - this.processFolder(result, value[0]); - const cipher = this.initLoginCipher(); - cipher.notes = this.getValueOrDefault(value[5]) + '\n'; - cipher.name = this.getValueOrDefault(value[1], '--'); - cipher.login.username = this.getValueOrDefault(value[2]); - cipher.login.password = this.getValueOrDefault(value[3]); - cipher.login.uris = this.makeUriArray(value[4]); - - if (value.length > 7) { - // we have some custom fields. - for (let i = 7; i < value.length; i = i + 2) { - this.processKvp(cipher, value[i], value[i + 1]); - } - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.length < 6) { + return; + } + + this.processFolder(result, value[0]); + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value[5]) + "\n"; + cipher.name = this.getValueOrDefault(value[1], "--"); + cipher.login.username = this.getValueOrDefault(value[2]); + cipher.login.password = this.getValueOrDefault(value[3]); + cipher.login.uris = this.makeUriArray(value[4]); + + if (value.length > 7) { + // we have some custom fields. + for (let i = 7; i < value.length; i = i + 2) { + this.processKvp(cipher, value[i], value[i + 1]); + } + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/lastpassCsvImporter.ts b/common/src/importers/lastpassCsvImporter.ts index 3f8b2a92..2b8f0a4b 100644 --- a/common/src/importers/lastpassCsvImporter.ts +++ b/common/src/importers/lastpassCsvImporter.ts @@ -1,276 +1,284 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CardView } from '../models/view/cardView'; -import { CipherView } from '../models/view/cipherView'; -import { FolderView } from '../models/view/folderView'; -import { IdentityView } from '../models/view/identityView'; -import { LoginView } from '../models/view/loginView'; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { CardView } from "../models/view/cardView"; +import { CipherView } from "../models/view/cipherView"; +import { FolderView } from "../models/view/folderView"; +import { IdentityView } from "../models/view/identityView"; +import { LoginView } from "../models/view/loginView"; +import { SecureNoteView } from "../models/view/secureNoteView"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; export class LastPassCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach((value, index) => { - const cipherIndex = result.ciphers.length; - let folderIndex = result.folders.length; - let grouping = value.grouping; - if (grouping != null) { - grouping = grouping.replace(/\\/g, '/').replace(/[\x00-\x1F\x7F-\x9F]/g, ''); - } - const hasFolder = this.getValueOrDefault(grouping, '(none)') !== '(none)'; - let addFolder = hasFolder; - - if (hasFolder) { - for (let i = 0; i < result.folders.length; i++) { - if (result.folders[i].name === grouping) { - addFolder = false; - folderIndex = i; - break; - } - } - } - - const cipher = this.buildBaseCipher(value); - if (cipher.type === CipherType.Login) { - cipher.notes = this.getValueOrDefault(value.extra); - cipher.login = new LoginView(); - cipher.login.uris = this.makeUriArray(value.url); - cipher.login.username = this.getValueOrDefault(value.username); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.totp = this.getValueOrDefault(value.totp); - } else if (cipher.type === CipherType.SecureNote) { - this.parseSecureNote(value, cipher); - } else if (cipher.type === CipherType.Card) { - cipher.card = this.parseCard(value); - cipher.notes = this.getValueOrDefault(value.notes); - } else if (cipher.type === CipherType.Identity) { - cipher.identity = this.parseIdentity(value); - cipher.notes = this.getValueOrDefault(value.notes); - if (!this.isNullOrWhitespace(value.ccnum)) { - // there is a card on this identity too - const cardCipher = this.buildBaseCipher(value); - cardCipher.identity = null; - cardCipher.type = CipherType.Card; - cardCipher.card = this.parseCard(value); - result.ciphers.push(cardCipher); - } - } - - result.ciphers.push(cipher); - - if (addFolder) { - const f = new FolderView(); - f.name = grouping; - result.folders.push(f); - } - if (hasFolder) { - result.folderRelationships.push([cipherIndex, folderIndex]); - } - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } - private buildBaseCipher(value: any) { - const cipher = new CipherView(); - if (value.hasOwnProperty('profilename') && value.hasOwnProperty('profilelanguage')) { - // form fill - cipher.favorite = false; - cipher.name = this.getValueOrDefault(value.profilename, '--'); - cipher.type = CipherType.Card; + results.forEach((value, index) => { + const cipherIndex = result.ciphers.length; + let folderIndex = result.folders.length; + let grouping = value.grouping; + if (grouping != null) { + grouping = grouping.replace(/\\/g, "/").replace(/[\x00-\x1F\x7F-\x9F]/g, ""); + } + const hasFolder = this.getValueOrDefault(grouping, "(none)") !== "(none)"; + let addFolder = hasFolder; - if (!this.isNullOrWhitespace(value.title) || !this.isNullOrWhitespace(value.firstname) || - !this.isNullOrWhitespace(value.lastname) || !this.isNullOrWhitespace(value.address1) || - !this.isNullOrWhitespace(value.phone) || !this.isNullOrWhitespace(value.username) || - !this.isNullOrWhitespace(value.email)) { - cipher.type = CipherType.Identity; - } - } else { - // site or secure note - cipher.favorite = !this.organization && this.getValueOrDefault(value.fav, '0') === '1'; - cipher.name = this.getValueOrDefault(value.name, '--'); - cipher.type = value.url === 'http://sn' ? CipherType.SecureNote : CipherType.Login; + if (hasFolder) { + for (let i = 0; i < result.folders.length; i++) { + if (result.folders[i].name === grouping) { + addFolder = false; + folderIndex = i; + break; + } } - return cipher; + } + + const cipher = this.buildBaseCipher(value); + if (cipher.type === CipherType.Login) { + cipher.notes = this.getValueOrDefault(value.extra); + cipher.login = new LoginView(); + cipher.login.uris = this.makeUriArray(value.url); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.totp = this.getValueOrDefault(value.totp); + } else if (cipher.type === CipherType.SecureNote) { + this.parseSecureNote(value, cipher); + } else if (cipher.type === CipherType.Card) { + cipher.card = this.parseCard(value); + cipher.notes = this.getValueOrDefault(value.notes); + } else if (cipher.type === CipherType.Identity) { + cipher.identity = this.parseIdentity(value); + cipher.notes = this.getValueOrDefault(value.notes); + if (!this.isNullOrWhitespace(value.ccnum)) { + // there is a card on this identity too + const cardCipher = this.buildBaseCipher(value); + cardCipher.identity = null; + cardCipher.type = CipherType.Card; + cardCipher.card = this.parseCard(value); + result.ciphers.push(cardCipher); + } + } + + result.ciphers.push(cipher); + + if (addFolder) { + const f = new FolderView(); + f.name = grouping; + result.folders.push(f); + } + if (hasFolder) { + result.folderRelationships.push([cipherIndex, folderIndex]); + } + }); + + if (this.organization) { + this.moveFoldersToCollections(result); } - private parseCard(value: any): CardView { - const card = new CardView(); - card.cardholderName = this.getValueOrDefault(value.ccname); - card.number = this.getValueOrDefault(value.ccnum); - card.code = this.getValueOrDefault(value.cccsc); - card.brand = this.getCardBrand(value.ccnum); + result.success = true; + return Promise.resolve(result); + } - if (!this.isNullOrWhitespace(value.ccexp) && value.ccexp.indexOf('-') > -1) { - const ccexpParts = (value.ccexp as string).split('-'); - if (ccexpParts.length > 1) { - card.expYear = ccexpParts[0]; - card.expMonth = ccexpParts[1]; - if (card.expMonth.length === 2 && card.expMonth[0] === '0') { - card.expMonth = card.expMonth[1]; - } - } + private buildBaseCipher(value: any) { + const cipher = new CipherView(); + if (value.hasOwnProperty("profilename") && value.hasOwnProperty("profilelanguage")) { + // form fill + cipher.favorite = false; + cipher.name = this.getValueOrDefault(value.profilename, "--"); + cipher.type = CipherType.Card; + + if ( + !this.isNullOrWhitespace(value.title) || + !this.isNullOrWhitespace(value.firstname) || + !this.isNullOrWhitespace(value.lastname) || + !this.isNullOrWhitespace(value.address1) || + !this.isNullOrWhitespace(value.phone) || + !this.isNullOrWhitespace(value.username) || + !this.isNullOrWhitespace(value.email) + ) { + cipher.type = CipherType.Identity; + } + } else { + // site or secure note + cipher.favorite = !this.organization && this.getValueOrDefault(value.fav, "0") === "1"; + cipher.name = this.getValueOrDefault(value.name, "--"); + cipher.type = value.url === "http://sn" ? CipherType.SecureNote : CipherType.Login; + } + return cipher; + } + + private parseCard(value: any): CardView { + const card = new CardView(); + card.cardholderName = this.getValueOrDefault(value.ccname); + card.number = this.getValueOrDefault(value.ccnum); + card.code = this.getValueOrDefault(value.cccsc); + card.brand = this.getCardBrand(value.ccnum); + + if (!this.isNullOrWhitespace(value.ccexp) && value.ccexp.indexOf("-") > -1) { + const ccexpParts = (value.ccexp as string).split("-"); + if (ccexpParts.length > 1) { + card.expYear = ccexpParts[0]; + card.expMonth = ccexpParts[1]; + if (card.expMonth.length === 2 && card.expMonth[0] === "0") { + card.expMonth = card.expMonth[1]; } - - return card; + } } - private parseIdentity(value: any): IdentityView { - const identity = new IdentityView(); - identity.title = this.getValueOrDefault(value.title); - identity.firstName = this.getValueOrDefault(value.firstname); - identity.middleName = this.getValueOrDefault(value.middlename); - identity.lastName = this.getValueOrDefault(value.lastname); - identity.username = this.getValueOrDefault(value.username); - identity.company = this.getValueOrDefault(value.company); - identity.ssn = this.getValueOrDefault(value.ssn); - identity.address1 = this.getValueOrDefault(value.address1); - identity.address2 = this.getValueOrDefault(value.address2); - identity.address3 = this.getValueOrDefault(value.address3); - identity.city = this.getValueOrDefault(value.city); - identity.state = this.getValueOrDefault(value.state); - identity.postalCode = this.getValueOrDefault(value.zip); - identity.country = this.getValueOrDefault(value.country); - identity.email = this.getValueOrDefault(value.email); - identity.phone = this.getValueOrDefault(value.phone); + return card; + } - if (!this.isNullOrWhitespace(identity.title)) { - identity.title = identity.title.charAt(0).toUpperCase() + identity.title.slice(1); - } + private parseIdentity(value: any): IdentityView { + const identity = new IdentityView(); + identity.title = this.getValueOrDefault(value.title); + identity.firstName = this.getValueOrDefault(value.firstname); + identity.middleName = this.getValueOrDefault(value.middlename); + identity.lastName = this.getValueOrDefault(value.lastname); + identity.username = this.getValueOrDefault(value.username); + identity.company = this.getValueOrDefault(value.company); + identity.ssn = this.getValueOrDefault(value.ssn); + identity.address1 = this.getValueOrDefault(value.address1); + identity.address2 = this.getValueOrDefault(value.address2); + identity.address3 = this.getValueOrDefault(value.address3); + identity.city = this.getValueOrDefault(value.city); + identity.state = this.getValueOrDefault(value.state); + identity.postalCode = this.getValueOrDefault(value.zip); + identity.country = this.getValueOrDefault(value.country); + identity.email = this.getValueOrDefault(value.email); + identity.phone = this.getValueOrDefault(value.phone); - return identity; + if (!this.isNullOrWhitespace(identity.title)) { + identity.title = identity.title.charAt(0).toUpperCase() + identity.title.slice(1); } - private parseSecureNote(value: any, cipher: CipherView) { - const extraParts = this.splitNewLine(value.extra); - let processedNote = false; + return identity; + } - if (extraParts.length) { - const typeParts = extraParts[0].split(':'); - if (typeParts.length > 1 && typeParts[0] === 'NoteType' && - (typeParts[1] === 'Credit Card' || typeParts[1] === 'Address')) { - if (typeParts[1] === 'Credit Card') { - const mappedData = this.parseSecureNoteMapping(cipher, extraParts, { - 'Number': 'number', - 'Name on Card': 'cardholderName', - 'Security Code': 'code', - // LP provides date in a format like 'June,2020' - // Store in expMonth, then parse and modify - 'Expiration Date': 'expMonth', - }); + private parseSecureNote(value: any, cipher: CipherView) { + const extraParts = this.splitNewLine(value.extra); + let processedNote = false; - if (this.isNullOrWhitespace(mappedData.expMonth) || mappedData.expMonth === ',') { - // No expiration data - mappedData.expMonth = undefined; - } else { - const [monthString, year] = mappedData.expMonth.split(','); - // Parse month name into number - if (!this.isNullOrWhitespace(monthString)) { - const month = new Date(Date.parse(monthString.trim() + ' 1, 2012')).getMonth() + 1; - if (isNaN(month)) { - mappedData.expMonth = undefined; - } else { - mappedData.expMonth = month.toString(); - } - } else { - mappedData.expMonth = undefined; - } - if (!this.isNullOrWhitespace(year)) { - mappedData.expYear = year; - } - } + if (extraParts.length) { + const typeParts = extraParts[0].split(":"); + if ( + typeParts.length > 1 && + typeParts[0] === "NoteType" && + (typeParts[1] === "Credit Card" || typeParts[1] === "Address") + ) { + if (typeParts[1] === "Credit Card") { + const mappedData = this.parseSecureNoteMapping(cipher, extraParts, { + Number: "number", + "Name on Card": "cardholderName", + "Security Code": "code", + // LP provides date in a format like 'June,2020' + // Store in expMonth, then parse and modify + "Expiration Date": "expMonth", + }); - cipher.type = CipherType.Card; - cipher.card = mappedData; - } else if (typeParts[1] === 'Address') { - const mappedData = this.parseSecureNoteMapping(cipher, extraParts, { - 'Title': 'title', - 'First Name': 'firstName', - 'Last Name': 'lastName', - 'Middle Name': 'middleName', - 'Company': 'company', - 'Address 1': 'address1', - 'Address 2': 'address2', - 'Address 3': 'address3', - 'City / Town': 'city', - 'State': 'state', - 'Zip / Postal Code': 'postalCode', - 'Country': 'country', - 'Email Address': 'email', - 'Username': 'username', - }); - cipher.type = CipherType.Identity; - cipher.identity = mappedData; - } - processedNote = true; - } - } - - if (!processedNote) { - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - cipher.notes = this.getValueOrDefault(value.extra); - } - } - - private parseSecureNoteMapping(cipher: CipherView, extraParts: string[], map: any): T { - const dataObj: any = {}; - - let processingNotes = false; - extraParts.forEach(extraPart => { - let key: string = null; - let val: string = null; - if (!processingNotes) { - if (this.isNullOrWhitespace(extraPart)) { - return; - } - const colonIndex = extraPart.indexOf(':'); - if (colonIndex === -1) { - key = extraPart; - } else { - key = extraPart.substring(0, colonIndex); - if (extraPart.length > colonIndex) { - val = extraPart.substring(colonIndex + 1); - } - } - if (this.isNullOrWhitespace(key) || this.isNullOrWhitespace(val) || key === 'NoteType') { - return; - } - } - - if (processingNotes) { - cipher.notes += ('\n' + extraPart); - } else if (key === 'Notes') { - if (!this.isNullOrWhitespace(cipher.notes)) { - cipher.notes += ('\n' + val); - } else { - cipher.notes = val; - } - processingNotes = true; - } else if (map.hasOwnProperty(key)) { - dataObj[map[key]] = val; + if (this.isNullOrWhitespace(mappedData.expMonth) || mappedData.expMonth === ",") { + // No expiration data + mappedData.expMonth = undefined; + } else { + const [monthString, year] = mappedData.expMonth.split(","); + // Parse month name into number + if (!this.isNullOrWhitespace(monthString)) { + const month = new Date(Date.parse(monthString.trim() + " 1, 2012")).getMonth() + 1; + if (isNaN(month)) { + mappedData.expMonth = undefined; + } else { + mappedData.expMonth = month.toString(); + } } else { - this.processKvp(cipher, key, val); + mappedData.expMonth = undefined; } - }); + if (!this.isNullOrWhitespace(year)) { + mappedData.expYear = year; + } + } - return dataObj; + cipher.type = CipherType.Card; + cipher.card = mappedData; + } else if (typeParts[1] === "Address") { + const mappedData = this.parseSecureNoteMapping(cipher, extraParts, { + Title: "title", + "First Name": "firstName", + "Last Name": "lastName", + "Middle Name": "middleName", + Company: "company", + "Address 1": "address1", + "Address 2": "address2", + "Address 3": "address3", + "City / Town": "city", + State: "state", + "Zip / Postal Code": "postalCode", + Country: "country", + "Email Address": "email", + Username: "username", + }); + cipher.type = CipherType.Identity; + cipher.identity = mappedData; + } + processedNote = true; + } } + + if (!processedNote) { + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + cipher.notes = this.getValueOrDefault(value.extra); + } + } + + private parseSecureNoteMapping(cipher: CipherView, extraParts: string[], map: any): T { + const dataObj: any = {}; + + let processingNotes = false; + extraParts.forEach((extraPart) => { + let key: string = null; + let val: string = null; + if (!processingNotes) { + if (this.isNullOrWhitespace(extraPart)) { + return; + } + const colonIndex = extraPart.indexOf(":"); + if (colonIndex === -1) { + key = extraPart; + } else { + key = extraPart.substring(0, colonIndex); + if (extraPart.length > colonIndex) { + val = extraPart.substring(colonIndex + 1); + } + } + if (this.isNullOrWhitespace(key) || this.isNullOrWhitespace(val) || key === "NoteType") { + return; + } + } + + if (processingNotes) { + cipher.notes += "\n" + extraPart; + } else if (key === "Notes") { + if (!this.isNullOrWhitespace(cipher.notes)) { + cipher.notes += "\n" + val; + } else { + cipher.notes = val; + } + processingNotes = true; + } else if (map.hasOwnProperty(key)) { + dataObj[map[key]] = val; + } else { + this.processKvp(cipher, key, val); + } + }); + + return dataObj; + } } diff --git a/common/src/importers/logMeOnceCsvImporter.ts b/common/src/importers/logMeOnceCsvImporter.ts index f6e3c5db..611058a4 100644 --- a/common/src/importers/logMeOnceCsvImporter.ts +++ b/common/src/importers/logMeOnceCsvImporter.ts @@ -1,31 +1,31 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class LogMeOnceCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.length < 4) { - return; - } - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value[0], '--'); - cipher.login.username = this.getValueOrDefault(value[2]); - cipher.login.password = this.getValueOrDefault(value[3]); - cipher.login.uris = this.makeUriArray(value[1]); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.length < 4) { + return; + } + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[0], "--"); + cipher.login.username = this.getValueOrDefault(value[2]); + cipher.login.password = this.getValueOrDefault(value[3]); + cipher.login.uris = this.makeUriArray(value[1]); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/meldiumCsvImporter.ts b/common/src/importers/meldiumCsvImporter.ts index 0b7ed11d..89d2e0bd 100644 --- a/common/src/importers/meldiumCsvImporter.ts +++ b/common/src/importers/meldiumCsvImporter.ts @@ -1,29 +1,29 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class MeldiumCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.DisplayName, '--'); - cipher.notes = this.getValueOrDefault(value.Notes); - cipher.login.username = this.getValueOrDefault(value.UserName); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.uris = this.makeUriArray(value.Url); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.DisplayName, "--"); + cipher.notes = this.getValueOrDefault(value.Notes); + cipher.login.username = this.getValueOrDefault(value.UserName); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.uris = this.makeUriArray(value.Url); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/msecureCsvImporter.ts b/common/src/importers/msecureCsvImporter.ts index 248b5380..4ae3ca90 100644 --- a/common/src/importers/msecureCsvImporter.ts +++ b/common/src/importers/msecureCsvImporter.ts @@ -1,62 +1,63 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { SecureNoteView } from "../models/view/secureNoteView"; export class MSecureCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.length < 3) { - return; - } - - const folderName = this.getValueOrDefault(value[0], 'Unassigned') !== 'Unassigned' ? value[0] : null; - this.processFolder(result, folderName); - - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value[2], '--'); - - if (value[1] === 'Web Logins' || value[1] === 'Login') { - cipher.login.uris = this.makeUriArray(value[4]); - cipher.login.username = this.getValueOrDefault(value[5]); - cipher.login.password = this.getValueOrDefault(value[6]); - cipher.notes = !this.isNullOrWhitespace(value[3]) ? value[3].split('\\n').join('\n') : null; - } else if (value.length > 3) { - cipher.type = CipherType.SecureNote; - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - for (let i = 3; i < value.length; i++) { - if (!this.isNullOrWhitespace(value[i])) { - cipher.notes += (value[i] + '\n'); - } - } - } - - if (!this.isNullOrWhitespace(value[1]) && cipher.type !== CipherType.Login) { - cipher.name = value[1] + ': ' + cipher.name; - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.length < 3) { + return; + } + + const folderName = + this.getValueOrDefault(value[0], "Unassigned") !== "Unassigned" ? value[0] : null; + this.processFolder(result, folderName); + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[2], "--"); + + if (value[1] === "Web Logins" || value[1] === "Login") { + cipher.login.uris = this.makeUriArray(value[4]); + cipher.login.username = this.getValueOrDefault(value[5]); + cipher.login.password = this.getValueOrDefault(value[6]); + cipher.notes = !this.isNullOrWhitespace(value[3]) ? value[3].split("\\n").join("\n") : null; + } else if (value.length > 3) { + cipher.type = CipherType.SecureNote; + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + for (let i = 3; i < value.length; i++) { + if (!this.isNullOrWhitespace(value[i])) { + cipher.notes += value[i] + "\n"; + } + } + } + + if (!this.isNullOrWhitespace(value[1]) && cipher.type !== CipherType.Login) { + cipher.name = value[1] + ": " + cipher.name; + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/mykiCsvImporter.ts b/common/src/importers/mykiCsvImporter.ts index e206ae1a..da440ad6 100644 --- a/common/src/importers/mykiCsvImporter.ts +++ b/common/src/importers/mykiCsvImporter.ts @@ -1,76 +1,76 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; -import { CardView } from '../models/view/cardView'; -import { IdentityView } from '../models/view/identityView'; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { CardView } from "../models/view/cardView"; +import { IdentityView } from "../models/view/identityView"; +import { SecureNoteView } from "../models/view/secureNoteView"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class MykiCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.nickname, '--'); - cipher.notes = this.getValueOrDefault(value.additionalInfo); - - if (value.url !== undefined) { - // Accounts - cipher.login.uris = this.makeUriArray(value.url); - cipher.login.username = this.getValueOrDefault(value.username); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.totp = this.getValueOrDefault(value.twoFactAuthToken); - } else if (value.cardNumber !== undefined) { - // Cards - cipher.card = new CardView(); - cipher.type = CipherType.Card; - cipher.card.cardholderName = this.getValueOrDefault(value.cardName); - cipher.card.number = this.getValueOrDefault(value.cardNumber); - cipher.card.brand = this.getCardBrand(cipher.card.number); - cipher.card.expMonth = this.getValueOrDefault(value.exp_month); - cipher.card.expYear = this.getValueOrDefault(value.exp_year); - cipher.card.code = this.getValueOrDefault(value.cvv); - } else if (value.firstName !== undefined) { - // Identities - cipher.identity = new IdentityView(); - cipher.type = CipherType.Identity; - cipher.identity.title = this.getValueOrDefault(value.title); - cipher.identity.firstName = this.getValueOrDefault(value.firstName); - cipher.identity.middleName = this.getValueOrDefault(value.middleName); - cipher.identity.lastName = this.getValueOrDefault(value.lastName); - cipher.identity.phone = this.getValueOrDefault(value.number); - cipher.identity.email = this.getValueOrDefault(value.email); - cipher.identity.address1 = this.getValueOrDefault(value.firstAddressLine); - cipher.identity.address2 = this.getValueOrDefault(value.secondAddressLine); - cipher.identity.city = this.getValueOrDefault(value.city); - cipher.identity.country = this.getValueOrDefault(value.country); - cipher.identity.postalCode = this.getValueOrDefault(value.zipCode); - } else if (value.content !== undefined) { - // Notes - cipher.secureNote = new SecureNoteView(); - cipher.type = CipherType.SecureNote; - cipher.secureNote.type = SecureNoteType.Generic; - cipher.name = this.getValueOrDefault(value.title, '--'); - cipher.notes = this.getValueOrDefault(value.content); - } else { - return; - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.nickname, "--"); + cipher.notes = this.getValueOrDefault(value.additionalInfo); + + if (value.url !== undefined) { + // Accounts + cipher.login.uris = this.makeUriArray(value.url); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.totp = this.getValueOrDefault(value.twoFactAuthToken); + } else if (value.cardNumber !== undefined) { + // Cards + cipher.card = new CardView(); + cipher.type = CipherType.Card; + cipher.card.cardholderName = this.getValueOrDefault(value.cardName); + cipher.card.number = this.getValueOrDefault(value.cardNumber); + cipher.card.brand = this.getCardBrand(cipher.card.number); + cipher.card.expMonth = this.getValueOrDefault(value.exp_month); + cipher.card.expYear = this.getValueOrDefault(value.exp_year); + cipher.card.code = this.getValueOrDefault(value.cvv); + } else if (value.firstName !== undefined) { + // Identities + cipher.identity = new IdentityView(); + cipher.type = CipherType.Identity; + cipher.identity.title = this.getValueOrDefault(value.title); + cipher.identity.firstName = this.getValueOrDefault(value.firstName); + cipher.identity.middleName = this.getValueOrDefault(value.middleName); + cipher.identity.lastName = this.getValueOrDefault(value.lastName); + cipher.identity.phone = this.getValueOrDefault(value.number); + cipher.identity.email = this.getValueOrDefault(value.email); + cipher.identity.address1 = this.getValueOrDefault(value.firstAddressLine); + cipher.identity.address2 = this.getValueOrDefault(value.secondAddressLine); + cipher.identity.city = this.getValueOrDefault(value.city); + cipher.identity.country = this.getValueOrDefault(value.country); + cipher.identity.postalCode = this.getValueOrDefault(value.zipCode); + } else if (value.content !== undefined) { + // Notes + cipher.secureNote = new SecureNoteView(); + cipher.type = CipherType.SecureNote; + cipher.secureNote.type = SecureNoteType.Generic; + cipher.name = this.getValueOrDefault(value.title, "--"); + cipher.notes = this.getValueOrDefault(value.content); + } else { + return; + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/nordpassCsvImporter.ts b/common/src/importers/nordpassCsvImporter.ts index 39ef4475..45e97edf 100644 --- a/common/src/importers/nordpassCsvImporter.ts +++ b/common/src/importers/nordpassCsvImporter.ts @@ -1,149 +1,146 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CipherView } from '../models/view/cipherView'; -import { LoginView } from '../models/view/loginView'; +import { CipherView } from "../models/view/cipherView"; +import { LoginView } from "../models/view/loginView"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; type nodePassCsvParsed = { - name: string; - url: string; - username: string; - password: string; - note: string; - cardholdername: string; - cardnumber: string; - cvc: string; - expirydate: string; - zipcode: string; - folder: string; - full_name: string; - phone_number: string; - email: string; - address1: string; - address2: string; - city: string; - country: string; - state: string; + name: string; + url: string; + username: string; + password: string; + note: string; + cardholdername: string; + cardnumber: string; + cvc: string; + expirydate: string; + zipcode: string; + folder: string; + full_name: string; + phone_number: string; + email: string; + address1: string; + address2: string; + city: string; + country: string; + state: string; }; export class NordPassCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results: nodePassCsvParsed[] = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(record => { - - const recordType = this.evaluateType(record); - if (recordType === undefined) { - return; - } - - if (!this.organization) { - this.processFolder(result, record.folder); - } - - const cipher = new CipherView(); - cipher.name = this.getValueOrDefault(record.name, '--'); - cipher.notes = this.getValueOrDefault(record.note); - - switch (recordType) { - case CipherType.Login: - cipher.type = CipherType.Login; - cipher.login = new LoginView(); - cipher.login.username = this.getValueOrDefault(record.username); - cipher.login.password = this.getValueOrDefault(record.password); - cipher.login.uris = this.makeUriArray(record.url); - break; - case CipherType.Card: - cipher.type = CipherType.Card; - cipher.card.cardholderName = this.getValueOrDefault(record.cardholdername); - cipher.card.number = this.getValueOrDefault(record.cardnumber); - cipher.card.code = this.getValueOrDefault(record.cvc); - cipher.card.brand = this.getCardBrand(cipher.card.number); - this.setCardExpiration(cipher, record.expirydate); - break; - - case CipherType.Identity: - cipher.type = CipherType.Identity; - - this.processName(cipher, this.getValueOrDefault(record.full_name)); - cipher.identity.address1 = this.getValueOrDefault(record.address1); - cipher.identity.address2 = this.getValueOrDefault(record.address2); - cipher.identity.city = this.getValueOrDefault(record.city); - cipher.identity.state = this.getValueOrDefault(record.state); - cipher.identity.postalCode = this.getValueOrDefault(record.zipcode); - cipher.identity.country = this.getValueOrDefault(record.country); - if (cipher.identity.country != null) { - cipher.identity.country = cipher.identity.country.toUpperCase(); - } - cipher.identity.email = this.getValueOrDefault(record.email); - cipher.identity.phone = this.getValueOrDefault(record.phone_number); - break; - case CipherType.SecureNote: - cipher.type = CipherType.SecureNote; - cipher.secureNote.type = SecureNoteType.Generic; - break; - default: - break; - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results: nodePassCsvParsed[] = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } - private evaluateType(record: nodePassCsvParsed): CipherType { + results.forEach((record) => { + const recordType = this.evaluateType(record); + if (recordType === undefined) { + return; + } - if (!this.isNullOrWhitespace(record.username)) { - return CipherType.Login; - } + if (!this.organization) { + this.processFolder(result, record.folder); + } - if (!this.isNullOrWhitespace(record.cardnumber)) { - return CipherType.Card; - } + const cipher = new CipherView(); + cipher.name = this.getValueOrDefault(record.name, "--"); + cipher.notes = this.getValueOrDefault(record.note); - if (!this.isNullOrWhitespace(record.full_name)) { - return CipherType.Identity; - } + switch (recordType) { + case CipherType.Login: + cipher.type = CipherType.Login; + cipher.login = new LoginView(); + cipher.login.username = this.getValueOrDefault(record.username); + cipher.login.password = this.getValueOrDefault(record.password); + cipher.login.uris = this.makeUriArray(record.url); + break; + case CipherType.Card: + cipher.type = CipherType.Card; + cipher.card.cardholderName = this.getValueOrDefault(record.cardholdername); + cipher.card.number = this.getValueOrDefault(record.cardnumber); + cipher.card.code = this.getValueOrDefault(record.cvc); + cipher.card.brand = this.getCardBrand(cipher.card.number); + this.setCardExpiration(cipher, record.expirydate); + break; - if (!this.isNullOrWhitespace(record.note)) { - return CipherType.SecureNote; - } + case CipherType.Identity: + cipher.type = CipherType.Identity; - return undefined; + this.processName(cipher, this.getValueOrDefault(record.full_name)); + cipher.identity.address1 = this.getValueOrDefault(record.address1); + cipher.identity.address2 = this.getValueOrDefault(record.address2); + cipher.identity.city = this.getValueOrDefault(record.city); + cipher.identity.state = this.getValueOrDefault(record.state); + cipher.identity.postalCode = this.getValueOrDefault(record.zipcode); + cipher.identity.country = this.getValueOrDefault(record.country); + if (cipher.identity.country != null) { + cipher.identity.country = cipher.identity.country.toUpperCase(); + } + cipher.identity.email = this.getValueOrDefault(record.email); + cipher.identity.phone = this.getValueOrDefault(record.phone_number); + break; + case CipherType.SecureNote: + cipher.type = CipherType.SecureNote; + cipher.secureNote.type = SecureNoteType.Generic; + break; + default: + break; + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); } - private processName(cipher: CipherView, fullName: string) { + result.success = true; + return Promise.resolve(result); + } - if (this.isNullOrWhitespace(fullName)) { - return; - } - - const nameParts = fullName.split(' '); - if (nameParts.length > 0) { - cipher.identity.firstName = this.getValueOrDefault(nameParts[0]); - } - if (nameParts.length === 2) { - cipher.identity.lastName = this.getValueOrDefault(nameParts[1]); - } else if (nameParts.length >= 3) { - cipher.identity.middleName = this.getValueOrDefault(nameParts[1]); - cipher.identity.lastName = nameParts.slice(2, nameParts.length).join(' '); - } + private evaluateType(record: nodePassCsvParsed): CipherType { + if (!this.isNullOrWhitespace(record.username)) { + return CipherType.Login; } + + if (!this.isNullOrWhitespace(record.cardnumber)) { + return CipherType.Card; + } + + if (!this.isNullOrWhitespace(record.full_name)) { + return CipherType.Identity; + } + + if (!this.isNullOrWhitespace(record.note)) { + return CipherType.SecureNote; + } + + return undefined; + } + + private processName(cipher: CipherView, fullName: string) { + if (this.isNullOrWhitespace(fullName)) { + return; + } + + const nameParts = fullName.split(" "); + if (nameParts.length > 0) { + cipher.identity.firstName = this.getValueOrDefault(nameParts[0]); + } + if (nameParts.length === 2) { + cipher.identity.lastName = this.getValueOrDefault(nameParts[1]); + } else if (nameParts.length >= 3) { + cipher.identity.middleName = this.getValueOrDefault(nameParts[1]); + cipher.identity.lastName = nameParts.slice(2, nameParts.length).join(" "); + } + } } diff --git a/common/src/importers/onepasswordImporters/cipherImportContext.ts b/common/src/importers/onepasswordImporters/cipherImportContext.ts index 66d82231..560f5c01 100644 --- a/common/src/importers/onepasswordImporters/cipherImportContext.ts +++ b/common/src/importers/onepasswordImporters/cipherImportContext.ts @@ -1,8 +1,8 @@ -import { CipherView } from '../../models/view/cipherView'; +import { CipherView } from "../../models/view/cipherView"; export class CipherImportContext { - lowerProperty: string; - constructor(public importRecord: any, public property: string, public cipher: CipherView) { - this.lowerProperty = property.toLowerCase(); - } + lowerProperty: string; + constructor(public importRecord: any, public property: string, public cipher: CipherView) { + this.lowerProperty = property.toLowerCase(); + } } diff --git a/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts b/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts index e82f3185..01ec4e59 100644 --- a/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts +++ b/common/src/importers/onepasswordImporters/onepassword1PifImporter.ts @@ -1,248 +1,275 @@ -import { BaseImporter } from '../baseImporter'; -import { Importer } from '../importer'; +import { BaseImporter } from "../baseImporter"; +import { Importer } from "../importer"; -import { ImportResult } from '../../models/domain/importResult'; +import { ImportResult } from "../../models/domain/importResult"; -import { CardView } from '../../models/view/cardView'; -import { CipherView } from '../../models/view/cipherView'; -import { IdentityView } from '../../models/view/identityView'; -import { PasswordHistoryView } from '../../models/view/passwordHistoryView'; -import { SecureNoteView } from '../../models/view/secureNoteView'; +import { CardView } from "../../models/view/cardView"; +import { CipherView } from "../../models/view/cipherView"; +import { IdentityView } from "../../models/view/identityView"; +import { PasswordHistoryView } from "../../models/view/passwordHistoryView"; +import { SecureNoteView } from "../../models/view/secureNoteView"; -import { CipherType } from '../../enums/cipherType'; -import { FieldType } from '../../enums/fieldType'; -import { SecureNoteType } from '../../enums/secureNoteType'; +import { CipherType } from "../../enums/cipherType"; +import { FieldType } from "../../enums/fieldType"; +import { SecureNoteType } from "../../enums/secureNoteType"; export class OnePassword1PifImporter extends BaseImporter implements Importer { - result = new ImportResult(); + result = new ImportResult(); - parse(data: string): Promise { - data.split(this.newLineRegex).forEach(line => { - if (this.isNullOrWhitespace(line) || line[0] !== '{') { - return; - } - const item = JSON.parse(line); - if (item.trashed === true) { - return; - } - const cipher = this.initLoginCipher(); + parse(data: string): Promise { + data.split(this.newLineRegex).forEach((line) => { + if (this.isNullOrWhitespace(line) || line[0] !== "{") { + return; + } + const item = JSON.parse(line); + if (item.trashed === true) { + return; + } + const cipher = this.initLoginCipher(); - if (this.isNullOrWhitespace(item.hmac)) { - this.processStandardItem(item, cipher); - } else { - this.processWinOpVaultItem(item, cipher); - } + if (this.isNullOrWhitespace(item.hmac)) { + this.processStandardItem(item, cipher); + } else { + this.processWinOpVaultItem(item, cipher); + } - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - this.result.ciphers.push(cipher); + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + this.result.ciphers.push(cipher); + }); + + this.result.success = true; + return Promise.resolve(this.result); + } + + private processWinOpVaultItem(item: any, cipher: CipherView) { + if (item.overview != null) { + cipher.name = this.getValueOrDefault(item.overview.title); + if (item.overview.URLs != null) { + const urls: string[] = []; + item.overview.URLs.forEach((url: any) => { + if (!this.isNullOrWhitespace(url.u)) { + urls.push(url.u); + } }); - - this.result.success = true; - return Promise.resolve(this.result); + cipher.login.uris = this.makeUriArray(urls); + } } - private processWinOpVaultItem(item: any, cipher: CipherView) { - if (item.overview != null) { - cipher.name = this.getValueOrDefault(item.overview.title); - if (item.overview.URLs != null) { - const urls: string[] = []; - item.overview.URLs.forEach((url: any) => { - if (!this.isNullOrWhitespace(url.u)) { - urls.push(url.u); - } - }); - cipher.login.uris = this.makeUriArray(urls); - } - } - - if (item.details != null) { - if (item.details.passwordHistory != null) { - this.parsePasswordHistory(item.details.passwordHistory, cipher); - } - if (!this.isNullOrWhitespace(item.details.ccnum) || !this.isNullOrWhitespace(item.details.cvv)) { - cipher.type = CipherType.Card; - cipher.card = new CardView(); - } else if (!this.isNullOrWhitespace(item.details.firstname) || - !this.isNullOrWhitespace(item.details.address1)) { - cipher.type = CipherType.Identity; - cipher.identity = new IdentityView(); - } - if (cipher.type === CipherType.Login && !this.isNullOrWhitespace(item.details.password)) { - cipher.login.password = item.details.password; - } - if (!this.isNullOrWhitespace(item.details.notesPlain)) { - cipher.notes = item.details.notesPlain.split(this.newLineRegex).join('\n') + '\n'; - } - if (item.details.fields != null) { - this.parseFields(item.details.fields, cipher, 'designation', 'value', 'name'); - } - if (item.details.sections != null) { - item.details.sections.forEach((section: any) => { - if (section.fields != null) { - this.parseFields(section.fields, cipher, 'n', 'v', 't'); - } - }); - } - } - } - - private processStandardItem(item: any, cipher: CipherView) { - cipher.favorite = item.openContents && item.openContents.faveIndex ? true : false; - cipher.name = this.getValueOrDefault(item.title); - - if (item.typeName === 'securenotes.SecureNote') { - cipher.type = CipherType.SecureNote; - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - } else if (item.typeName === 'wallet.financial.CreditCard') { - cipher.type = CipherType.Card; - cipher.card = new CardView(); - } else if (item.typeName === 'identities.Identity') { - cipher.type = CipherType.Identity; - cipher.identity = new IdentityView(); - } else { - cipher.login.uris = this.makeUriArray(item.location); - } - - if (item.secureContents != null) { - if (item.secureContents.passwordHistory != null) { - this.parsePasswordHistory(item.secureContents.passwordHistory, cipher); - } - if (!this.isNullOrWhitespace(item.secureContents.notesPlain)) { - cipher.notes = item.secureContents.notesPlain.split(this.newLineRegex).join('\n') + '\n'; - } - if (cipher.type === CipherType.Login) { - if (!this.isNullOrWhitespace(item.secureContents.password)) { - cipher.login.password = item.secureContents.password; - } - if (item.secureContents.URLs != null) { - const urls: string[] = []; - item.secureContents.URLs.forEach((u: any) => { - if (!this.isNullOrWhitespace(u.url)) { - urls.push(u.url); - } - }); - if (urls.length > 0) { - cipher.login.uris = this.makeUriArray(urls); - } - } - } - if (item.secureContents.fields != null) { - this.parseFields(item.secureContents.fields, cipher, 'designation', 'value', 'name'); - } - if (item.secureContents.sections != null) { - item.secureContents.sections.forEach((section: any) => { - if (section.fields != null) { - this.parseFields(section.fields, cipher, 'n', 'v', 't'); - } - }); - } - } - } - - private parsePasswordHistory(items: any[], cipher: CipherView) { - const maxSize = items.length > 5 ? 5 : items.length; - cipher.passwordHistory = items - .filter((h: any) => !this.isNullOrWhitespace(h.value) && h.time != null) - .sort((a, b) => b.time - a.time) - .slice(0, maxSize) - .map((h: any) => { - const ph = new PasswordHistoryView(); - ph.password = h.value; - ph.lastUsedDate = new Date(('' + h.time).length >= 13 ? h.time : h.time * 1000); - return ph; - }); - } - - private parseFields(fields: any[], cipher: CipherView, designationKey: string, valueKey: string, nameKey: string) { - fields.forEach((field: any) => { - if (field[valueKey] == null || field[valueKey].toString().trim() === '') { - return; - } - - const fieldValue = field[valueKey].toString(); - const fieldDesignation = field[designationKey] != null ? field[designationKey].toString() : null; - - if (cipher.type === CipherType.Login) { - if (this.isNullOrWhitespace(cipher.login.username) && fieldDesignation === 'username') { - cipher.login.username = fieldValue; - return; - } else if (this.isNullOrWhitespace(cipher.login.password) && fieldDesignation === 'password') { - cipher.login.password = fieldValue; - return; - } else if (this.isNullOrWhitespace(cipher.login.totp) && fieldDesignation != null && - fieldDesignation.startsWith('TOTP_')) { - cipher.login.totp = fieldValue; - return; - } - } else if (cipher.type === CipherType.Card) { - if (this.isNullOrWhitespace(cipher.card.number) && fieldDesignation === 'ccnum') { - cipher.card.number = fieldValue; - cipher.card.brand = this.getCardBrand(fieldValue); - return; - } else if (this.isNullOrWhitespace(cipher.card.code) && fieldDesignation === 'cvv') { - cipher.card.code = fieldValue; - return; - } else if (this.isNullOrWhitespace(cipher.card.cardholderName) && fieldDesignation === 'cardholder') { - cipher.card.cardholderName = fieldValue; - return; - } else if (this.isNullOrWhitespace(cipher.card.expiration) && fieldDesignation === 'expiry' && - fieldValue.length === 6) { - cipher.card.expMonth = (fieldValue as string).substr(4, 2); - if (cipher.card.expMonth[0] === '0') { - cipher.card.expMonth = cipher.card.expMonth.substr(1, 1); - } - cipher.card.expYear = (fieldValue as string).substr(0, 4); - return; - } else if (fieldDesignation === 'type') { - // Skip since brand was determined from number above - return; - } - } else if (cipher.type === CipherType.Identity) { - const identity = cipher.identity; - if (this.isNullOrWhitespace(identity.firstName) && fieldDesignation === 'firstname') { - identity.firstName = fieldValue; - return; - } else if (this.isNullOrWhitespace(identity.lastName) && fieldDesignation === 'lastname') { - identity.lastName = fieldValue; - return; - } else if (this.isNullOrWhitespace(identity.middleName) && fieldDesignation === 'initial') { - identity.middleName = fieldValue; - return; - } else if (this.isNullOrWhitespace(identity.phone) && fieldDesignation === 'defphone') { - identity.phone = fieldValue; - return; - } else if (this.isNullOrWhitespace(identity.company) && fieldDesignation === 'company') { - identity.company = fieldValue; - return; - } else if (this.isNullOrWhitespace(identity.email) && fieldDesignation === 'email') { - identity.email = fieldValue; - return; - } else if (this.isNullOrWhitespace(identity.username) && fieldDesignation === 'username') { - identity.username = fieldValue; - return; - } else if (fieldDesignation === 'address') { - // fieldValue is an object casted into a string, so access the plain value instead - const { street, city, country, zip } = field[valueKey]; - identity.address1 = this.getValueOrDefault(street); - identity.city = this.getValueOrDefault(city); - if (!this.isNullOrWhitespace(country)) { - identity.country = country.toUpperCase(); - } - identity.postalCode = this.getValueOrDefault(zip); - return; - } - } - - const fieldName = this.isNullOrWhitespace(field[nameKey]) ? 'no_name' : field[nameKey]; - if (fieldName === 'password' && cipher.passwordHistory != null && - cipher.passwordHistory.some(h => h.password === fieldValue)) { - return; - } - - const fieldType = field.k === 'concealed' ? FieldType.Hidden : FieldType.Text; - this.processKvp(cipher, fieldName, fieldValue, fieldType); + if (item.details != null) { + if (item.details.passwordHistory != null) { + this.parsePasswordHistory(item.details.passwordHistory, cipher); + } + if ( + !this.isNullOrWhitespace(item.details.ccnum) || + !this.isNullOrWhitespace(item.details.cvv) + ) { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + } else if ( + !this.isNullOrWhitespace(item.details.firstname) || + !this.isNullOrWhitespace(item.details.address1) + ) { + cipher.type = CipherType.Identity; + cipher.identity = new IdentityView(); + } + if (cipher.type === CipherType.Login && !this.isNullOrWhitespace(item.details.password)) { + cipher.login.password = item.details.password; + } + if (!this.isNullOrWhitespace(item.details.notesPlain)) { + cipher.notes = item.details.notesPlain.split(this.newLineRegex).join("\n") + "\n"; + } + if (item.details.fields != null) { + this.parseFields(item.details.fields, cipher, "designation", "value", "name"); + } + if (item.details.sections != null) { + item.details.sections.forEach((section: any) => { + if (section.fields != null) { + this.parseFields(section.fields, cipher, "n", "v", "t"); + } }); + } } + } + + private processStandardItem(item: any, cipher: CipherView) { + cipher.favorite = item.openContents && item.openContents.faveIndex ? true : false; + cipher.name = this.getValueOrDefault(item.title); + + if (item.typeName === "securenotes.SecureNote") { + cipher.type = CipherType.SecureNote; + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + } else if (item.typeName === "wallet.financial.CreditCard") { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + } else if (item.typeName === "identities.Identity") { + cipher.type = CipherType.Identity; + cipher.identity = new IdentityView(); + } else { + cipher.login.uris = this.makeUriArray(item.location); + } + + if (item.secureContents != null) { + if (item.secureContents.passwordHistory != null) { + this.parsePasswordHistory(item.secureContents.passwordHistory, cipher); + } + if (!this.isNullOrWhitespace(item.secureContents.notesPlain)) { + cipher.notes = item.secureContents.notesPlain.split(this.newLineRegex).join("\n") + "\n"; + } + if (cipher.type === CipherType.Login) { + if (!this.isNullOrWhitespace(item.secureContents.password)) { + cipher.login.password = item.secureContents.password; + } + if (item.secureContents.URLs != null) { + const urls: string[] = []; + item.secureContents.URLs.forEach((u: any) => { + if (!this.isNullOrWhitespace(u.url)) { + urls.push(u.url); + } + }); + if (urls.length > 0) { + cipher.login.uris = this.makeUriArray(urls); + } + } + } + if (item.secureContents.fields != null) { + this.parseFields(item.secureContents.fields, cipher, "designation", "value", "name"); + } + if (item.secureContents.sections != null) { + item.secureContents.sections.forEach((section: any) => { + if (section.fields != null) { + this.parseFields(section.fields, cipher, "n", "v", "t"); + } + }); + } + } + } + + private parsePasswordHistory(items: any[], cipher: CipherView) { + const maxSize = items.length > 5 ? 5 : items.length; + cipher.passwordHistory = items + .filter((h: any) => !this.isNullOrWhitespace(h.value) && h.time != null) + .sort((a, b) => b.time - a.time) + .slice(0, maxSize) + .map((h: any) => { + const ph = new PasswordHistoryView(); + ph.password = h.value; + ph.lastUsedDate = new Date(("" + h.time).length >= 13 ? h.time : h.time * 1000); + return ph; + }); + } + + private parseFields( + fields: any[], + cipher: CipherView, + designationKey: string, + valueKey: string, + nameKey: string + ) { + fields.forEach((field: any) => { + if (field[valueKey] == null || field[valueKey].toString().trim() === "") { + return; + } + + const fieldValue = field[valueKey].toString(); + const fieldDesignation = + field[designationKey] != null ? field[designationKey].toString() : null; + + if (cipher.type === CipherType.Login) { + if (this.isNullOrWhitespace(cipher.login.username) && fieldDesignation === "username") { + cipher.login.username = fieldValue; + return; + } else if ( + this.isNullOrWhitespace(cipher.login.password) && + fieldDesignation === "password" + ) { + cipher.login.password = fieldValue; + return; + } else if ( + this.isNullOrWhitespace(cipher.login.totp) && + fieldDesignation != null && + fieldDesignation.startsWith("TOTP_") + ) { + cipher.login.totp = fieldValue; + return; + } + } else if (cipher.type === CipherType.Card) { + if (this.isNullOrWhitespace(cipher.card.number) && fieldDesignation === "ccnum") { + cipher.card.number = fieldValue; + cipher.card.brand = this.getCardBrand(fieldValue); + return; + } else if (this.isNullOrWhitespace(cipher.card.code) && fieldDesignation === "cvv") { + cipher.card.code = fieldValue; + return; + } else if ( + this.isNullOrWhitespace(cipher.card.cardholderName) && + fieldDesignation === "cardholder" + ) { + cipher.card.cardholderName = fieldValue; + return; + } else if ( + this.isNullOrWhitespace(cipher.card.expiration) && + fieldDesignation === "expiry" && + fieldValue.length === 6 + ) { + cipher.card.expMonth = (fieldValue as string).substr(4, 2); + if (cipher.card.expMonth[0] === "0") { + cipher.card.expMonth = cipher.card.expMonth.substr(1, 1); + } + cipher.card.expYear = (fieldValue as string).substr(0, 4); + return; + } else if (fieldDesignation === "type") { + // Skip since brand was determined from number above + return; + } + } else if (cipher.type === CipherType.Identity) { + const identity = cipher.identity; + if (this.isNullOrWhitespace(identity.firstName) && fieldDesignation === "firstname") { + identity.firstName = fieldValue; + return; + } else if (this.isNullOrWhitespace(identity.lastName) && fieldDesignation === "lastname") { + identity.lastName = fieldValue; + return; + } else if (this.isNullOrWhitespace(identity.middleName) && fieldDesignation === "initial") { + identity.middleName = fieldValue; + return; + } else if (this.isNullOrWhitespace(identity.phone) && fieldDesignation === "defphone") { + identity.phone = fieldValue; + return; + } else if (this.isNullOrWhitespace(identity.company) && fieldDesignation === "company") { + identity.company = fieldValue; + return; + } else if (this.isNullOrWhitespace(identity.email) && fieldDesignation === "email") { + identity.email = fieldValue; + return; + } else if (this.isNullOrWhitespace(identity.username) && fieldDesignation === "username") { + identity.username = fieldValue; + return; + } else if (fieldDesignation === "address") { + // fieldValue is an object casted into a string, so access the plain value instead + const { street, city, country, zip } = field[valueKey]; + identity.address1 = this.getValueOrDefault(street); + identity.city = this.getValueOrDefault(city); + if (!this.isNullOrWhitespace(country)) { + identity.country = country.toUpperCase(); + } + identity.postalCode = this.getValueOrDefault(zip); + return; + } + } + + const fieldName = this.isNullOrWhitespace(field[nameKey]) ? "no_name" : field[nameKey]; + if ( + fieldName === "password" && + cipher.passwordHistory != null && + cipher.passwordHistory.some((h) => h.password === fieldValue) + ) { + return; + } + + const fieldType = field.k === "concealed" ? FieldType.Hidden : FieldType.Text; + this.processKvp(cipher, fieldName, fieldValue, fieldType); + }); + } } diff --git a/common/src/importers/onepasswordImporters/onepasswordCsvImporter.ts b/common/src/importers/onepasswordImporters/onepasswordCsvImporter.ts index 8bf5f153..c4234022 100644 --- a/common/src/importers/onepasswordImporters/onepasswordCsvImporter.ts +++ b/common/src/importers/onepasswordImporters/onepasswordCsvImporter.ts @@ -1,288 +1,382 @@ -import { ImportResult } from '../../models/domain/importResult'; -import { BaseImporter } from '../baseImporter'; -import { Importer } from '../importer'; +import { ImportResult } from "../../models/domain/importResult"; +import { BaseImporter } from "../baseImporter"; +import { Importer } from "../importer"; -import { CipherType } from '../../enums/cipherType'; -import { FieldType } from '../../enums/fieldType'; -import { CipherView } from '../../models/view/cipherView'; -import { CipherImportContext } from './cipherImportContext'; +import { CipherType } from "../../enums/cipherType"; +import { FieldType } from "../../enums/fieldType"; +import { CipherView } from "../../models/view/cipherView"; +import { CipherImportContext } from "./cipherImportContext"; -export const IgnoredProperties = ['ainfo', 'autosubmit', 'notesplain', 'ps', 'scope', 'tags', 'title', 'uuid', 'notes']; +export const IgnoredProperties = [ + "ainfo", + "autosubmit", + "notesplain", + "ps", + "scope", + "tags", + "title", + "uuid", + "notes", +]; export abstract class OnePasswordCsvImporter extends BaseImporter implements Importer { - protected loginPropertyParsers = [this.setLoginUsername, this.setLoginPassword, this.setLoginUris]; - protected creditCardPropertyParsers = [this.setCreditCardNumber, this.setCreditCardVerification, this.setCreditCardCardholderName, this.setCreditCardExpiry]; - protected identityPropertyParsers = [this.setIdentityFirstName, this.setIdentityInitial, this.setIdentityLastName, this.setIdentityUserName, this.setIdentityEmail, this.setIdentityPhone, this.setIdentityCompany]; + protected loginPropertyParsers = [ + this.setLoginUsername, + this.setLoginPassword, + this.setLoginUris, + ]; + protected creditCardPropertyParsers = [ + this.setCreditCardNumber, + this.setCreditCardVerification, + this.setCreditCardCardholderName, + this.setCreditCardExpiry, + ]; + protected identityPropertyParsers = [ + this.setIdentityFirstName, + this.setIdentityInitial, + this.setIdentityLastName, + this.setIdentityUserName, + this.setIdentityEmail, + this.setIdentityPhone, + this.setIdentityCompany, + ]; - abstract setCipherType(value: any, cipher: CipherView): void; + abstract setCipherType(value: any, cipher: CipherView): void; - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true, { - quoteChar: '"', - escapeChar: '\\', - }); - if (results == null) { - result.success = false; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true, { + quoteChar: '"', + escapeChar: "\\", + }); + if (results == null) { + result.success = false; + return Promise.resolve(result); + } + + results.forEach((value) => { + if (this.isNullOrWhitespace(this.getProp(value, "title"))) { + return; + } + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(this.getProp(value, "title"), "--"); + + this.setNotes(value, cipher); + + this.setCipherType(value, cipher); + + let altUsername: string = null; + for (const property in value) { + if (!value.hasOwnProperty(property) || this.isNullOrWhitespace(value[property])) { + continue; } - results.forEach(value => { - if (this.isNullOrWhitespace(this.getProp(value, 'title'))) { - return; - } - - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(this.getProp(value, 'title'), '--'); - - this.setNotes(value, cipher); - - this.setCipherType(value, cipher); - - let altUsername: string = null; - for (const property in value) { - if (!value.hasOwnProperty(property) || this.isNullOrWhitespace(value[property])) { - continue; - } - - const context = new CipherImportContext(value, property, cipher); - if (cipher.type === CipherType.Login && this.setKnownLoginValue(context)) { - continue; - } else if (cipher.type === CipherType.Card && this.setKnownCreditCardValue(context)) { - continue; - } else if (cipher.type === CipherType.Identity && this.setKnownIdentityValue(context)) { - continue; - } - - altUsername = this.setUnknownValue(context, altUsername); - } - - if (cipher.type === CipherType.Login && !this.isNullOrWhitespace(altUsername) && - this.isNullOrWhitespace(cipher.login.username) && altUsername.indexOf('://') === -1) { - cipher.login.username = altUsername; - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); - } - - protected getProp(obj: any, name: string): any { - const lowerObj = Object.entries(obj).reduce((agg: any, entry: [string, any]) => { - agg[entry[0].toLowerCase()] = entry[1]; - return agg; - }, {}); - return lowerObj[name.toLowerCase()]; - } - - protected getPropByRegexp(obj: any, regexp: RegExp): any { - const matchingKeys = Object.keys(obj).reduce((agg: string[], key: string) => { - if (key.match(regexp)) { - agg.push(key); - } - return agg; - }, []); - if (matchingKeys.length === 0) { - return null; - } else { - return obj[matchingKeys[0]]; + const context = new CipherImportContext(value, property, cipher); + if (cipher.type === CipherType.Login && this.setKnownLoginValue(context)) { + continue; + } else if (cipher.type === CipherType.Card && this.setKnownCreditCardValue(context)) { + continue; + } else if (cipher.type === CipherType.Identity && this.setKnownIdentityValue(context)) { + continue; } + + altUsername = this.setUnknownValue(context, altUsername); + } + + if ( + cipher.type === CipherType.Login && + !this.isNullOrWhitespace(altUsername) && + this.isNullOrWhitespace(cipher.login.username) && + altUsername.indexOf("://") === -1 + ) { + cipher.login.username = altUsername; + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } + + protected getProp(obj: any, name: string): any { + const lowerObj = Object.entries(obj).reduce((agg: any, entry: [string, any]) => { + agg[entry[0].toLowerCase()] = entry[1]; + return agg; + }, {}); + return lowerObj[name.toLowerCase()]; + } + + protected getPropByRegexp(obj: any, regexp: RegExp): any { + const matchingKeys = Object.keys(obj).reduce((agg: string[], key: string) => { + if (key.match(regexp)) { + agg.push(key); + } + return agg; + }, []); + if (matchingKeys.length === 0) { + return null; + } else { + return obj[matchingKeys[0]]; } + } - protected getPropIncluding(obj: any, name: string): any { - const includesMap = Object.keys(obj).reduce((agg: string[], entry: string) => { - if (entry.toLowerCase().includes(name.toLowerCase())) { - agg.push(entry); - } - return agg; - }, []); - if (includesMap.length === 0) { - return null; - } else { - return obj[includesMap[0]]; - } + protected getPropIncluding(obj: any, name: string): any { + const includesMap = Object.keys(obj).reduce((agg: string[], entry: string) => { + if (entry.toLowerCase().includes(name.toLowerCase())) { + agg.push(entry); + } + return agg; + }, []); + if (includesMap.length === 0) { + return null; + } else { + return obj[includesMap[0]]; } + } - protected setNotes(importRecord: any, cipher: CipherView) { - cipher.notes = this.getValueOrDefault(this.getProp(importRecord, 'notesPlain'), '') + '\n' + - this.getValueOrDefault(this.getProp(importRecord, 'notes'), '') + '\n'; - cipher.notes.trim(); + protected setNotes(importRecord: any, cipher: CipherView) { + cipher.notes = + this.getValueOrDefault(this.getProp(importRecord, "notesPlain"), "") + + "\n" + + this.getValueOrDefault(this.getProp(importRecord, "notes"), "") + + "\n"; + cipher.notes.trim(); + } - } + protected setKnownLoginValue(context: CipherImportContext): boolean { + return this.loginPropertyParsers.reduce((agg: boolean, func) => { + if (!agg) { + agg = func.bind(this)(context); + } + return agg; + }, false); + } - protected setKnownLoginValue(context: CipherImportContext): boolean { - return this.loginPropertyParsers.reduce((agg: boolean, func) => { - if (!agg) { - agg = func.bind(this)(context); - } - return agg; - }, false); - } + protected setKnownCreditCardValue(context: CipherImportContext): boolean { + return this.creditCardPropertyParsers.reduce((agg: boolean, func) => { + if (!agg) { + agg = func.bind(this)(context); + } + return agg; + }, false); + } - protected setKnownCreditCardValue(context: CipherImportContext): boolean { - return this.creditCardPropertyParsers.reduce((agg: boolean, func) => { - if (!agg) { - agg = func.bind(this)(context); - } - return agg; - }, false); - } + protected setKnownIdentityValue(context: CipherImportContext): boolean { + return this.identityPropertyParsers.reduce((agg: boolean, func) => { + if (!agg) { + agg = func.bind(this)(context); + } + return agg; + }, false); + } - protected setKnownIdentityValue(context: CipherImportContext): boolean { - return this.identityPropertyParsers.reduce((agg: boolean, func) => { - if (!agg) { - agg = func.bind(this)(context); - } - return agg; - }, false); - } - - protected setUnknownValue(context: CipherImportContext, altUsername: string): string { - if (IgnoredProperties.indexOf(context.lowerProperty) === -1 && !context.lowerProperty.startsWith('section:') && - !context.lowerProperty.startsWith('section ')) { - if (altUsername == null && context.lowerProperty === 'email') { - return context.importRecord[context.property]; - } - else if (context.lowerProperty === 'created date' || context.lowerProperty === 'modified date') { - const readableDate = new Date(parseInt(context.importRecord[context.property], 10) * 1000).toUTCString(); - this.processKvp(context.cipher, '1Password ' + context.property, readableDate); - return null; - } - if (context.lowerProperty.includes('password') || context.lowerProperty.includes('key') || context.lowerProperty.includes('secret')) { - this.processKvp(context.cipher, context.property, context.importRecord[context.property], FieldType.Hidden); - } else { - this.processKvp(context.cipher, context.property, context.importRecord[context.property]); - } - } + protected setUnknownValue(context: CipherImportContext, altUsername: string): string { + if ( + IgnoredProperties.indexOf(context.lowerProperty) === -1 && + !context.lowerProperty.startsWith("section:") && + !context.lowerProperty.startsWith("section ") + ) { + if (altUsername == null && context.lowerProperty === "email") { + return context.importRecord[context.property]; + } else if ( + context.lowerProperty === "created date" || + context.lowerProperty === "modified date" + ) { + const readableDate = new Date( + parseInt(context.importRecord[context.property], 10) * 1000 + ).toUTCString(); + this.processKvp(context.cipher, "1Password " + context.property, readableDate); return null; + } + if ( + context.lowerProperty.includes("password") || + context.lowerProperty.includes("key") || + context.lowerProperty.includes("secret") + ) { + this.processKvp( + context.cipher, + context.property, + context.importRecord[context.property], + FieldType.Hidden + ); + } else { + this.processKvp(context.cipher, context.property, context.importRecord[context.property]); + } } + return null; + } - protected setIdentityFirstName(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.identity.firstName) && context.lowerProperty.includes('first name')) { - context.cipher.identity.firstName = context.importRecord[context.property]; - return true; - } - return false; + protected setIdentityFirstName(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.identity.firstName) && + context.lowerProperty.includes("first name") + ) { + context.cipher.identity.firstName = context.importRecord[context.property]; + return true; } + return false; + } - protected setIdentityInitial(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.identity.middleName) && context.lowerProperty.includes('initial')) { - context.cipher.identity.middleName = context.importRecord[context.property]; - return true; - } - return false; + protected setIdentityInitial(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.identity.middleName) && + context.lowerProperty.includes("initial") + ) { + context.cipher.identity.middleName = context.importRecord[context.property]; + return true; } + return false; + } - protected setIdentityLastName(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.identity.lastName) && context.lowerProperty.includes('last name')) { - context.cipher.identity.lastName = context.importRecord[context.property]; - return true; - } - return false; + protected setIdentityLastName(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.identity.lastName) && + context.lowerProperty.includes("last name") + ) { + context.cipher.identity.lastName = context.importRecord[context.property]; + return true; } + return false; + } - protected setIdentityUserName(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.identity.username) && context.lowerProperty.includes('username')) { - context.cipher.identity.username = context.importRecord[context.property]; - return true; - } - return false; + protected setIdentityUserName(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.identity.username) && + context.lowerProperty.includes("username") + ) { + context.cipher.identity.username = context.importRecord[context.property]; + return true; } + return false; + } - protected setIdentityCompany(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.identity.company) && context.lowerProperty.includes('company')) { - context.cipher.identity.company = context.importRecord[context.property]; - return true; - } - return false; + protected setIdentityCompany(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.identity.company) && + context.lowerProperty.includes("company") + ) { + context.cipher.identity.company = context.importRecord[context.property]; + return true; } + return false; + } - protected setIdentityPhone(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.identity.phone) && context.lowerProperty.includes('default phone')) { - context.cipher.identity.phone = context.importRecord[context.property]; - return true; - } - return false; + protected setIdentityPhone(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.identity.phone) && + context.lowerProperty.includes("default phone") + ) { + context.cipher.identity.phone = context.importRecord[context.property]; + return true; } + return false; + } - protected setIdentityEmail(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.identity.email) && context.lowerProperty.includes('email')) { - context.cipher.identity.email = context.importRecord[context.property]; - return true; - } - return false; + protected setIdentityEmail(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.identity.email) && + context.lowerProperty.includes("email") + ) { + context.cipher.identity.email = context.importRecord[context.property]; + return true; } + return false; + } - protected setCreditCardNumber(context: CipherImportContext): boolean { - if (this.isNullOrWhitespace(context.cipher.card.number) && context.lowerProperty.includes('number')) { - context.cipher.card.number = context.importRecord[context.property]; - context.cipher.card.brand = this.getCardBrand(context.cipher.card.number); - return true; - } - return false; + protected setCreditCardNumber(context: CipherImportContext): boolean { + if ( + this.isNullOrWhitespace(context.cipher.card.number) && + context.lowerProperty.includes("number") + ) { + context.cipher.card.number = context.importRecord[context.property]; + context.cipher.card.brand = this.getCardBrand(context.cipher.card.number); + return true; } + return false; + } - protected setCreditCardVerification(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.card.code) && context.lowerProperty.includes('verification number')) { - context.cipher.card.code = context.importRecord[context.property]; - return true; - } - return false; + protected setCreditCardVerification(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.card.code) && + context.lowerProperty.includes("verification number") + ) { + context.cipher.card.code = context.importRecord[context.property]; + return true; } + return false; + } - protected setCreditCardCardholderName(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.card.cardholderName) && context.lowerProperty.includes('cardholder name')) { - context.cipher.card.cardholderName = context.importRecord[context.property]; - return true; - } - return false; + protected setCreditCardCardholderName(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.card.cardholderName) && + context.lowerProperty.includes("cardholder name") + ) { + context.cipher.card.cardholderName = context.importRecord[context.property]; + return true; } + return false; + } - protected setCreditCardExpiry(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.card.expiration) && context.lowerProperty.includes('expiry date') && - context.importRecord[context.property].length === 7) { - context.cipher.card.expMonth = (context.importRecord[context.property] as string).substr(0, 2); - if (context.cipher.card.expMonth[0] === '0') { - context.cipher.card.expMonth = context.cipher.card.expMonth.substr(1, 1); - } - context.cipher.card.expYear = (context.importRecord[context.property] as string).substr(3, 4); - return true; - } - return false; + protected setCreditCardExpiry(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.card.expiration) && + context.lowerProperty.includes("expiry date") && + context.importRecord[context.property].length === 7 + ) { + context.cipher.card.expMonth = (context.importRecord[context.property] as string).substr( + 0, + 2 + ); + if (context.cipher.card.expMonth[0] === "0") { + context.cipher.card.expMonth = context.cipher.card.expMonth.substr(1, 1); + } + context.cipher.card.expYear = (context.importRecord[context.property] as string).substr(3, 4); + return true; } + return false; + } - protected setLoginPassword(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.login.password) && context.lowerProperty === 'password') { - context.cipher.login.password = context.importRecord[context.property]; - return true; - } - return false; + protected setLoginPassword(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.login.password) && + context.lowerProperty === "password" + ) { + context.cipher.login.password = context.importRecord[context.property]; + return true; } + return false; + } - protected setLoginUsername(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.login.username) && context.lowerProperty === 'username') { - context.cipher.login.username = context.importRecord[context.property]; - return true; - } - return false; + protected setLoginUsername(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.login.username) && + context.lowerProperty === "username" + ) { + context.cipher.login.username = context.importRecord[context.property]; + return true; } + return false; + } - protected setLoginUris(context: CipherImportContext) { - if ((context.cipher.login.uris == null || context.cipher.login.uris.length === 0) && context.lowerProperty === 'urls') { - const urls = context.importRecord[context.property].split(this.newLineRegex); - context.cipher.login.uris = this.makeUriArray(urls); - return true; - } else if ((context.lowerProperty === 'url')) { - if (context.cipher.login.uris == null) { - context.cipher.login.uris = []; - } - context.cipher.login.uris.concat(this.makeUriArray(context.importRecord[context.property])); - return true; - } - return false; + protected setLoginUris(context: CipherImportContext) { + if ( + (context.cipher.login.uris == null || context.cipher.login.uris.length === 0) && + context.lowerProperty === "urls" + ) { + const urls = context.importRecord[context.property].split(this.newLineRegex); + context.cipher.login.uris = this.makeUriArray(urls); + return true; + } else if (context.lowerProperty === "url") { + if (context.cipher.login.uris == null) { + context.cipher.login.uris = []; + } + context.cipher.login.uris.concat(this.makeUriArray(context.importRecord[context.property])); + return true; } + return false; + } } diff --git a/common/src/importers/onepasswordImporters/onepasswordMacCsvImporter.ts b/common/src/importers/onepasswordImporters/onepasswordMacCsvImporter.ts index 35c602aa..4d91c1c0 100644 --- a/common/src/importers/onepasswordImporters/onepasswordMacCsvImporter.ts +++ b/common/src/importers/onepasswordImporters/onepasswordMacCsvImporter.ts @@ -1,30 +1,30 @@ -import { Importer } from '../importer'; -import { IgnoredProperties, OnePasswordCsvImporter } from './onepasswordCsvImporter'; +import { Importer } from "../importer"; +import { IgnoredProperties, OnePasswordCsvImporter } from "./onepasswordCsvImporter"; -import { CipherType } from '../../enums/cipherType'; -import { CardView } from '../../models/view/cardView'; -import { CipherView } from '../../models/view/cipherView'; -import { IdentityView } from '../../models/view/identityView'; +import { CipherType } from "../../enums/cipherType"; +import { CardView } from "../../models/view/cardView"; +import { CipherView } from "../../models/view/cipherView"; +import { IdentityView } from "../../models/view/identityView"; export class OnePasswordMacCsvImporter extends OnePasswordCsvImporter implements Importer { - setCipherType(value: any, cipher: CipherView) { - const onePassType = this.getValueOrDefault(this.getProp(value, 'type'), 'Login'); - switch (onePassType) { - case 'Credit Card': - cipher.type = CipherType.Card; - cipher.card = new CardView(); - IgnoredProperties.push('type'); - break; - case 'Identity': - cipher.type = CipherType.Identity; - cipher.identity = new IdentityView(); - IgnoredProperties.push('type'); - break; - case 'Login': - case 'Secure Note': - IgnoredProperties.push('type'); - default: - break; - } + setCipherType(value: any, cipher: CipherView) { + const onePassType = this.getValueOrDefault(this.getProp(value, "type"), "Login"); + switch (onePassType) { + case "Credit Card": + cipher.type = CipherType.Card; + cipher.card = new CardView(); + IgnoredProperties.push("type"); + break; + case "Identity": + cipher.type = CipherType.Identity; + cipher.identity = new IdentityView(); + IgnoredProperties.push("type"); + break; + case "Login": + case "Secure Note": + IgnoredProperties.push("type"); + default: + break; } + } } diff --git a/common/src/importers/onepasswordImporters/onepasswordWinCsvImporter.ts b/common/src/importers/onepasswordImporters/onepasswordWinCsvImporter.ts index ef0c1055..ebc96b32 100644 --- a/common/src/importers/onepasswordImporters/onepasswordWinCsvImporter.ts +++ b/common/src/importers/onepasswordImporters/onepasswordWinCsvImporter.ts @@ -1,56 +1,63 @@ -import { Importer } from '../importer'; -import { CipherImportContext } from './cipherImportContext'; -import { OnePasswordCsvImporter } from './onepasswordCsvImporter'; +import { Importer } from "../importer"; +import { CipherImportContext } from "./cipherImportContext"; +import { OnePasswordCsvImporter } from "./onepasswordCsvImporter"; -import { CipherType } from '../../enums/cipherType'; -import { CardView } from '../../models/view/cardView'; -import { CipherView } from '../../models/view/cipherView'; -import { IdentityView } from '../../models/view/identityView'; -import { LoginView } from '../../models/view/loginView'; +import { CipherType } from "../../enums/cipherType"; +import { CardView } from "../../models/view/cardView"; +import { CipherView } from "../../models/view/cipherView"; +import { IdentityView } from "../../models/view/identityView"; +import { LoginView } from "../../models/view/loginView"; export class OnePasswordWinCsvImporter extends OnePasswordCsvImporter implements Importer { - constructor() { - super(); - this.identityPropertyParsers.push(this.setIdentityAddress); + constructor() { + super(); + this.identityPropertyParsers.push(this.setIdentityAddress); + } + + setCipherType(value: any, cipher: CipherView) { + cipher.type = CipherType.Login; + cipher.login = new LoginView(); + + if ( + !this.isNullOrWhitespace(this.getPropByRegexp(value, /\d+: number/i)) && + !this.isNullOrWhitespace(this.getPropByRegexp(value, /\d+: expiry date/i)) + ) { + cipher.type = CipherType.Card; + cipher.card = new CardView(); } - setCipherType(value: any, cipher: CipherView) { - cipher.type = CipherType.Login; - cipher.login = new LoginView(); - - if (!this.isNullOrWhitespace(this.getPropByRegexp(value, /\d+: number/i)) && - !this.isNullOrWhitespace(this.getPropByRegexp(value, /\d+: expiry date/i))) { - cipher.type = CipherType.Card; - cipher.card = new CardView(); - } - - if (!this.isNullOrWhitespace(this.getPropByRegexp(value, /name \d+: first name/i)) || - !this.isNullOrWhitespace(this.getPropByRegexp(value, /name \d+: initial/i)) || - !this.isNullOrWhitespace(this.getPropByRegexp(value, /name \d+: last name/i)) || - !this.isNullOrWhitespace(this.getPropByRegexp(value, /internet \d+: email/i))) { - cipher.type = CipherType.Identity; - cipher.identity = new IdentityView(); - } + if ( + !this.isNullOrWhitespace(this.getPropByRegexp(value, /name \d+: first name/i)) || + !this.isNullOrWhitespace(this.getPropByRegexp(value, /name \d+: initial/i)) || + !this.isNullOrWhitespace(this.getPropByRegexp(value, /name \d+: last name/i)) || + !this.isNullOrWhitespace(this.getPropByRegexp(value, /internet \d+: email/i)) + ) { + cipher.type = CipherType.Identity; + cipher.identity = new IdentityView(); } + } - setIdentityAddress(context: CipherImportContext) { - if (context.lowerProperty.match(/address \d+: address/i)) { - this.processKvp(context.cipher, 'address', context.importRecord[context.property]); - return true; - } - return false; + setIdentityAddress(context: CipherImportContext) { + if (context.lowerProperty.match(/address \d+: address/i)) { + this.processKvp(context.cipher, "address", context.importRecord[context.property]); + return true; } + return false; + } - setCreditCardExpiry(context: CipherImportContext) { - if (this.isNullOrWhitespace(context.cipher.card.expiration) && context.lowerProperty.includes('expiry date')) { - const expSplit = (context.importRecord[context.property] as string).split('/'); - context.cipher.card.expMonth = expSplit[0]; - if (context.cipher.card.expMonth[0] === '0' && context.cipher.card.expMonth.length === 2) { - context.cipher.card.expMonth = context.cipher.card.expMonth.substr(1, 1); - } - context.cipher.card.expYear = expSplit[2].length > 4 ? expSplit[2].substr(0, 4) : expSplit[2]; - return true; - } - return false; + setCreditCardExpiry(context: CipherImportContext) { + if ( + this.isNullOrWhitespace(context.cipher.card.expiration) && + context.lowerProperty.includes("expiry date") + ) { + const expSplit = (context.importRecord[context.property] as string).split("/"); + context.cipher.card.expMonth = expSplit[0]; + if (context.cipher.card.expMonth[0] === "0" && context.cipher.card.expMonth.length === 2) { + context.cipher.card.expMonth = context.cipher.card.expMonth.substr(1, 1); + } + context.cipher.card.expYear = expSplit[2].length > 4 ? expSplit[2].substr(0, 4) : expSplit[2]; + return true; } + return false; + } } diff --git a/common/src/importers/padlockCsvImporter.ts b/common/src/importers/padlockCsvImporter.ts index e106af3e..777d9822 100644 --- a/common/src/importers/padlockCsvImporter.ts +++ b/common/src/importers/padlockCsvImporter.ts @@ -1,87 +1,87 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CollectionView } from '../models/view/collectionView'; -import { FolderView } from '../models/view/folderView'; +import { CollectionView } from "../models/view/collectionView"; +import { FolderView } from "../models/view/folderView"; export class PadlockCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); + } + + let headers: string[] = null; + results.forEach((value) => { + if (headers == null) { + headers = value.map((v: string) => v); + return; + } + + if (value.length < 2 || value.length !== headers.length) { + return; + } + + if (!this.isNullOrWhitespace(value[1])) { + if (this.organization) { + const tags = (value[1] as string).split(","); + tags.forEach((tag) => { + tag = tag.trim(); + let addCollection = true; + let collectionIndex = result.collections.length; + + for (let i = 0; i < result.collections.length; i++) { + if (result.collections[i].name === tag) { + addCollection = false; + collectionIndex = i; + break; + } + } + + if (addCollection) { + const collection = new CollectionView(); + collection.name = tag; + result.collections.push(collection); + } + + result.collectionRelationships.push([result.ciphers.length, collectionIndex]); + }); + } else { + const tags = (value[1] as string).split(","); + const tag = tags.length > 0 ? tags[0].trim() : null; + this.processFolder(result, tag); + } + } + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[0], "--"); + + for (let i = 2; i < value.length; i++) { + const header = headers[i].trim().toLowerCase(); + if (this.isNullOrWhitespace(value[i]) || this.isNullOrWhitespace(header)) { + continue; } - let headers: string[] = null; - results.forEach(value => { - if (headers == null) { - headers = value.map((v: string) => v); - return; - } + if (this.usernameFieldNames.indexOf(header) > -1) { + cipher.login.username = value[i]; + } else if (this.passwordFieldNames.indexOf(header) > -1) { + cipher.login.password = value[i]; + } else if (this.uriFieldNames.indexOf(header) > -1) { + cipher.login.uris = this.makeUriArray(value[i]); + } else { + this.processKvp(cipher, headers[i], value[i]); + } + } - if (value.length < 2 || value.length !== headers.length) { - return; - } + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); - if (!this.isNullOrWhitespace(value[1])) { - if (this.organization) { - const tags = (value[1] as string).split(','); - tags.forEach(tag => { - tag = tag.trim(); - let addCollection = true; - let collectionIndex = result.collections.length; - - for (let i = 0; i < result.collections.length; i++) { - if (result.collections[i].name === tag) { - addCollection = false; - collectionIndex = i; - break; - } - } - - if (addCollection) { - const collection = new CollectionView(); - collection.name = tag; - result.collections.push(collection); - } - - result.collectionRelationships.push([result.ciphers.length, collectionIndex]); - }); - } else { - const tags = (value[1] as string).split(','); - const tag = tags.length > 0 ? tags[0].trim() : null; - this.processFolder(result, tag); - } - } - - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value[0], '--'); - - for (let i = 2; i < value.length; i++) { - const header = headers[i].trim().toLowerCase(); - if (this.isNullOrWhitespace(value[i]) || this.isNullOrWhitespace(header)) { - continue; - } - - if (this.usernameFieldNames.indexOf(header) > -1) { - cipher.login.username = value[i]; - } else if (this.passwordFieldNames.indexOf(header) > -1) { - cipher.login.password = value[i]; - } else if (this.uriFieldNames.indexOf(header) > -1) { - cipher.login.uris = this.makeUriArray(value[i]); - } else { - this.processKvp(cipher, headers[i], value[i]); - } - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); - } + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/passkeepCsvImporter.ts b/common/src/importers/passkeepCsvImporter.ts index a010550c..434f7ded 100644 --- a/common/src/importers/passkeepCsvImporter.ts +++ b/common/src/importers/passkeepCsvImporter.ts @@ -1,39 +1,39 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class PassKeepCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - this.processFolder(result, this.getValue('category', value)); - const cipher = this.initLoginCipher(); - cipher.notes = this.getValue('description', value); - cipher.name = this.getValueOrDefault(this.getValue('title', value), '--'); - cipher.login.username = this.getValue('username', value); - cipher.login.password = this.getValue('password', value); - cipher.login.uris = this.makeUriArray(this.getValue('site', value)); - this.processKvp(cipher, 'Password 2', this.getValue('password2', value)); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } - private getValue(key: string, value: any) { - return this.getValueOrDefault(value[key], this.getValueOrDefault(value[(' ' + key)])); + results.forEach((value) => { + this.processFolder(result, this.getValue("category", value)); + const cipher = this.initLoginCipher(); + cipher.notes = this.getValue("description", value); + cipher.name = this.getValueOrDefault(this.getValue("title", value), "--"); + cipher.login.username = this.getValue("username", value); + cipher.login.password = this.getValue("password", value); + cipher.login.uris = this.makeUriArray(this.getValue("site", value)); + this.processKvp(cipher, "Password 2", this.getValue("password2", value)); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); } + + result.success = true; + return Promise.resolve(result); + } + + private getValue(key: string, value: any) { + return this.getValueOrDefault(value[key], this.getValueOrDefault(value[" " + key])); + } } diff --git a/common/src/importers/passmanJsonImporter.ts b/common/src/importers/passmanJsonImporter.ts index c00eeb1a..22232aba 100644 --- a/common/src/importers/passmanJsonImporter.ts +++ b/common/src/importers/passmanJsonImporter.ts @@ -1,61 +1,61 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class PassmanJsonImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = JSON.parse(data); - if (results == null || results.length === 0) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach((credential: any) => { - if (credential.tags != null && credential.tags.length > 0) { - const folderName = credential.tags[0].text; - this.processFolder(result, folderName); - } - - const cipher = this.initLoginCipher(); - cipher.name = credential.label; - - cipher.login.username = this.getValueOrDefault(credential.username); - if (this.isNullOrWhitespace(cipher.login.username)) { - cipher.login.username = this.getValueOrDefault(credential.email); - } else if (!this.isNullOrWhitespace(credential.email)) { - cipher.notes = ('Email: ' + credential.email + '\n'); - } - - cipher.login.password = this.getValueOrDefault(credential.password); - cipher.login.uris = this.makeUriArray(credential.url); - cipher.notes += this.getValueOrDefault(credential.description, ''); - if (credential.otp != null) { - cipher.login.totp = this.getValueOrDefault(credential.otp.secret); - } - - if (credential.custom_fields != null) { - credential.custom_fields.forEach((customField: any) => { - switch (customField.field_type) { - case 'text': - case 'password': - this.processKvp(cipher, customField.label, customField.value); - break; - } - }); - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = JSON.parse(data); + if (results == null || results.length === 0) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((credential: any) => { + if (credential.tags != null && credential.tags.length > 0) { + const folderName = credential.tags[0].text; + this.processFolder(result, folderName); + } + + const cipher = this.initLoginCipher(); + cipher.name = credential.label; + + cipher.login.username = this.getValueOrDefault(credential.username); + if (this.isNullOrWhitespace(cipher.login.username)) { + cipher.login.username = this.getValueOrDefault(credential.email); + } else if (!this.isNullOrWhitespace(credential.email)) { + cipher.notes = "Email: " + credential.email + "\n"; + } + + cipher.login.password = this.getValueOrDefault(credential.password); + cipher.login.uris = this.makeUriArray(credential.url); + cipher.notes += this.getValueOrDefault(credential.description, ""); + if (credential.otp != null) { + cipher.login.totp = this.getValueOrDefault(credential.otp.secret); + } + + if (credential.custom_fields != null) { + credential.custom_fields.forEach((customField: any) => { + switch (customField.field_type) { + case "text": + case "password": + this.processKvp(cipher, customField.label, customField.value); + break; + } + }); + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/passpackCsvImporter.ts b/common/src/importers/passpackCsvImporter.ts index ba51490f..e1a02707 100644 --- a/common/src/importers/passpackCsvImporter.ts +++ b/common/src/importers/passpackCsvImporter.ts @@ -1,97 +1,104 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CollectionView } from '../models/view/collectionView'; +import { CollectionView } from "../models/view/collectionView"; export class PasspackCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const tagsJson = !this.isNullOrWhitespace(value.Tags) ? JSON.parse(value.Tags) : null; - const tags: string[] = tagsJson != null && tagsJson.tags != null && tagsJson.tags.length > 0 ? - tagsJson.tags.map((tagJson: string) => { - try { - const t = JSON.parse(tagJson); - return this.getValueOrDefault(t.tag); - } catch { - // Ignore error - } - return null; - }).filter((t: string) => !this.isNullOrWhitespace(t)) : null; - - if (this.organization && tags != null && tags.length > 0) { - tags.forEach(tag => { - let addCollection = true; - let collectionIndex = result.collections.length; - - for (let i = 0; i < result.collections.length; i++) { - if (result.collections[i].name === tag) { - addCollection = false; - collectionIndex = i; - break; - } - } - - if (addCollection) { - const collection = new CollectionView(); - collection.name = tag; - result.collections.push(collection); - } - - result.collectionRelationships.push([result.ciphers.length, collectionIndex]); - }); - } else if (!this.organization && tags != null && tags.length > 0) { - this.processFolder(result, tags[0]); - } - - const cipher = this.initLoginCipher(); - cipher.notes = this.getValueOrDefault(value.Notes, ''); - cipher.notes += ('\n\n' + this.getValueOrDefault(value['Shared Notes'], '') + '\n'); - cipher.name = this.getValueOrDefault(value['Entry Name'], '--'); - cipher.login.username = this.getValueOrDefault(value['User ID']); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.uris = this.makeUriArray(value.URL); - - if (value.__parsed_extra != null && value.__parsed_extra.length > 0) { - value.__parsed_extra.forEach((extra: string) => { - if (!this.isNullOrWhitespace(extra)) { - cipher.notes += ('\n' + extra); - } - }); - } - - const fieldsJson = !this.isNullOrWhitespace(value['Extra Fields']) ? - JSON.parse(value['Extra Fields']) : null; - const fields = fieldsJson != null && fieldsJson.extraFields != null && - fieldsJson.extraFields.length > 0 ? fieldsJson.extraFields.map((fieldJson: string) => { - try { - return JSON.parse(fieldJson); - } catch { - // Ignore error - } - return null; - }) : null; - if (fields != null) { - fields.forEach((f: any) => { - if (f != null) { - this.processKvp(cipher, f.name, f.data); - } - }); - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const tagsJson = !this.isNullOrWhitespace(value.Tags) ? JSON.parse(value.Tags) : null; + const tags: string[] = + tagsJson != null && tagsJson.tags != null && tagsJson.tags.length > 0 + ? tagsJson.tags + .map((tagJson: string) => { + try { + const t = JSON.parse(tagJson); + return this.getValueOrDefault(t.tag); + } catch { + // Ignore error + } + return null; + }) + .filter((t: string) => !this.isNullOrWhitespace(t)) + : null; + + if (this.organization && tags != null && tags.length > 0) { + tags.forEach((tag) => { + let addCollection = true; + let collectionIndex = result.collections.length; + + for (let i = 0; i < result.collections.length; i++) { + if (result.collections[i].name === tag) { + addCollection = false; + collectionIndex = i; + break; + } + } + + if (addCollection) { + const collection = new CollectionView(); + collection.name = tag; + result.collections.push(collection); + } + + result.collectionRelationships.push([result.ciphers.length, collectionIndex]); + }); + } else if (!this.organization && tags != null && tags.length > 0) { + this.processFolder(result, tags[0]); + } + + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value.Notes, ""); + cipher.notes += "\n\n" + this.getValueOrDefault(value["Shared Notes"], "") + "\n"; + cipher.name = this.getValueOrDefault(value["Entry Name"], "--"); + cipher.login.username = this.getValueOrDefault(value["User ID"]); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.uris = this.makeUriArray(value.URL); + + if (value.__parsed_extra != null && value.__parsed_extra.length > 0) { + value.__parsed_extra.forEach((extra: string) => { + if (!this.isNullOrWhitespace(extra)) { + cipher.notes += "\n" + extra; + } + }); + } + + const fieldsJson = !this.isNullOrWhitespace(value["Extra Fields"]) + ? JSON.parse(value["Extra Fields"]) + : null; + const fields = + fieldsJson != null && fieldsJson.extraFields != null && fieldsJson.extraFields.length > 0 + ? fieldsJson.extraFields.map((fieldJson: string) => { + try { + return JSON.parse(fieldJson); + } catch { + // Ignore error + } + return null; + }) + : null; + if (fields != null) { + fields.forEach((f: any) => { + if (f != null) { + this.processKvp(cipher, f.name, f.data); + } + }); + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/passwordAgentCsvImporter.ts b/common/src/importers/passwordAgentCsvImporter.ts index b505c633..9b673c3c 100644 --- a/common/src/importers/passwordAgentCsvImporter.ts +++ b/common/src/importers/passwordAgentCsvImporter.ts @@ -1,52 +1,52 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class PasswordAgentCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - let newVersion = true; - results.forEach(value => { - if (value.length !== 5 && value.length < 9) { - return; - } - const altFormat = value.length === 10 && value[0] === '0'; - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value[altFormat ? 1 : 0], '--'); - cipher.login.username = this.getValueOrDefault(value[altFormat ? 2 : 1]); - cipher.login.password = this.getValueOrDefault(value[altFormat ? 3 : 2]); - if (value.length === 5) { - newVersion = false; - cipher.notes = this.getValueOrDefault(value[4]); - cipher.login.uris = this.makeUriArray(value[3]); - } else { - const folder = this.getValueOrDefault(value[altFormat ? 9 : 8], '(None)'); - let folderName = folder !== '(None)' ? folder.split('\\').join('/') : null; - if (folderName != null) { - folderName = folder.split(' > ').join('/'); - folderName = folder.split('>').join('/'); - } - this.processFolder(result, folderName); - cipher.notes = this.getValueOrDefault(value[altFormat ? 5 : 3]); - cipher.login.uris = this.makeUriArray(value[4]); - } - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (newVersion && this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + let newVersion = true; + results.forEach((value) => { + if (value.length !== 5 && value.length < 9) { + return; + } + const altFormat = value.length === 10 && value[0] === "0"; + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[altFormat ? 1 : 0], "--"); + cipher.login.username = this.getValueOrDefault(value[altFormat ? 2 : 1]); + cipher.login.password = this.getValueOrDefault(value[altFormat ? 3 : 2]); + if (value.length === 5) { + newVersion = false; + cipher.notes = this.getValueOrDefault(value[4]); + cipher.login.uris = this.makeUriArray(value[3]); + } else { + const folder = this.getValueOrDefault(value[altFormat ? 9 : 8], "(None)"); + let folderName = folder !== "(None)" ? folder.split("\\").join("/") : null; + if (folderName != null) { + folderName = folder.split(" > ").join("/"); + folderName = folder.split(">").join("/"); + } + this.processFolder(result, folderName); + cipher.notes = this.getValueOrDefault(value[altFormat ? 5 : 3]); + cipher.login.uris = this.makeUriArray(value[4]); + } + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (newVersion && this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/passwordBossJsonImporter.ts b/common/src/importers/passwordBossJsonImporter.ts index 88a70ee6..73f74050 100644 --- a/common/src/importers/passwordBossJsonImporter.ts +++ b/common/src/importers/passwordBossJsonImporter.ts @@ -1,123 +1,131 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CardView } from '../models/view/cardView'; -import { FolderView } from '../models/view/folderView'; +import { CardView } from "../models/view/cardView"; +import { FolderView } from "../models/view/folderView"; -import { CipherType } from '../enums/cipherType'; +import { CipherType } from "../enums/cipherType"; export class PasswordBossJsonImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = JSON.parse(data); - if (results == null || results.items == null) { - result.success = false; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = JSON.parse(data); + if (results == null || results.items == null) { + result.success = false; + return Promise.resolve(result); + } + + const foldersMap = new Map(); + results.folders.forEach((value: any) => { + foldersMap.set(value.id, value.name); + }); + const foldersIndexMap = new Map(); + foldersMap.forEach((val, key) => { + foldersIndexMap.set(key, result.folders.length); + const f = new FolderView(); + f.name = val; + result.folders.push(f); + }); + + results.items.forEach((value: any) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.name, "--"); + cipher.login.uris = this.makeUriArray(value.login_url); + + if (value.folder != null && foldersIndexMap.has(value.folder)) { + result.folderRelationships.push([result.ciphers.length, foldersIndexMap.get(value.folder)]); + } + + if (value.identifiers == null) { + return; + } + + if (!this.isNullOrWhitespace(value.identifiers.notes)) { + cipher.notes = value.identifiers.notes.split("\\r\\n").join("\n").split("\\n").join("\n"); + } + + if (value.type === "CreditCard") { + cipher.card = new CardView(); + cipher.type = CipherType.Card; + } + + for (const property in value.identifiers) { + if (!value.identifiers.hasOwnProperty(property)) { + continue; + } + const valObj = value.identifiers[property]; + const val = valObj != null ? valObj.toString() : null; + if ( + this.isNullOrWhitespace(val) || + property === "notes" || + property === "ignoreItemInSecurityScore" + ) { + continue; } - const foldersMap = new Map(); - results.folders.forEach((value: any) => { - foldersMap.set(value.id, value.name); - }); - const foldersIndexMap = new Map(); - foldersMap.forEach((val, key) => { - foldersIndexMap.set(key, result.folders.length); - const f = new FolderView(); - f.name = val; - result.folders.push(f); - }); + if (property === "custom_fields") { + valObj.forEach((cf: any) => { + this.processKvp(cipher, cf.name, cf.value); + }); + continue; + } - results.items.forEach((value: any) => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.name, '--'); - cipher.login.uris = this.makeUriArray(value.login_url); - - if (value.folder != null && foldersIndexMap.has(value.folder)) { - result.folderRelationships.push([result.ciphers.length, foldersIndexMap.get(value.folder)]); + if (cipher.type === CipherType.Card) { + if (property === "cardNumber") { + cipher.card.number = val; + cipher.card.brand = this.getCardBrand(val); + continue; + } else if (property === "nameOnCard") { + cipher.card.cardholderName = val; + continue; + } else if (property === "security_code") { + cipher.card.code = val; + continue; + } else if (property === "expires") { + try { + const expDate = new Date(val); + cipher.card.expYear = expDate.getFullYear().toString(); + cipher.card.expMonth = (expDate.getMonth() + 1).toString(); + } catch { + // Ignore error } + continue; + } else if (property === "cardType") { + continue; + } + } else { + if ( + (property === "username" || property === "email") && + this.isNullOrWhitespace(cipher.login.username) + ) { + cipher.login.username = val; + continue; + } else if (property === "password") { + cipher.login.password = val; + continue; + } else if (property === "totp") { + cipher.login.totp = val; + continue; + } else if ( + (cipher.login.uris == null || cipher.login.uris.length === 0) && + this.uriFieldNames.indexOf(property) > -1 + ) { + cipher.login.uris = this.makeUriArray(val); + continue; + } + } - if (value.identifiers == null) { - return; - } + this.processKvp(cipher, property, val); + } - if (!this.isNullOrWhitespace(value.identifiers.notes)) { - cipher.notes = value.identifiers.notes.split('\\r\\n').join('\n').split('\\n').join('\n'); - } + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); - if (value.type === 'CreditCard') { - cipher.card = new CardView(); - cipher.type = CipherType.Card; - } - - for (const property in value.identifiers) { - if (!value.identifiers.hasOwnProperty(property)) { - continue; - } - const valObj = value.identifiers[property]; - const val = valObj != null ? valObj.toString() : null; - if (this.isNullOrWhitespace(val) || property === 'notes' || property === 'ignoreItemInSecurityScore') { - continue; - } - - if (property === 'custom_fields') { - valObj.forEach((cf: any) => { - this.processKvp(cipher, cf.name, cf.value); - }); - continue; - } - - if (cipher.type === CipherType.Card) { - if (property === 'cardNumber') { - cipher.card.number = val; - cipher.card.brand = this.getCardBrand(val); - continue; - } else if (property === 'nameOnCard') { - cipher.card.cardholderName = val; - continue; - } else if (property === 'security_code') { - cipher.card.code = val; - continue; - } else if (property === 'expires') { - try { - const expDate = new Date(val); - cipher.card.expYear = expDate.getFullYear().toString(); - cipher.card.expMonth = (expDate.getMonth() + 1).toString(); - } catch { - // Ignore error - } - continue; - } else if (property === 'cardType') { - continue; - } - } else { - if ((property === 'username' || property === 'email') && - this.isNullOrWhitespace(cipher.login.username)) { - cipher.login.username = val; - continue; - } else if (property === 'password') { - cipher.login.password = val; - continue; - } else if (property === 'totp') { - cipher.login.totp = val; - continue; - } else if ((cipher.login.uris == null || cipher.login.uris.length === 0) && - this.uriFieldNames.indexOf(property) > -1) { - cipher.login.uris = this.makeUriArray(val); - continue; - } - } - - this.processKvp(cipher, property, val); - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); - } + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/passwordDragonXmlImporter.ts b/common/src/importers/passwordDragonXmlImporter.ts index 15110b82..74cbe960 100644 --- a/common/src/importers/passwordDragonXmlImporter.ts +++ b/common/src/importers/passwordDragonXmlImporter.ts @@ -1,57 +1,63 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class PasswordDragonXmlImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const doc = this.parseXml(data); - if (doc == null) { - result.success = false; - return Promise.resolve(result); - } - - const records = doc.querySelectorAll('PasswordManager > record'); - Array.from(records).forEach(record => { - const category = this.querySelectorDirectChild(record, 'Category'); - const categoryText = category != null && !this.isNullOrWhitespace(category.textContent) && - category.textContent !== 'Unfiled' ? category.textContent : null; - this.processFolder(result, categoryText); - - const accountName = this.querySelectorDirectChild(record, 'Account-Name'); - const userId = this.querySelectorDirectChild(record, 'User-Id'); - const password = this.querySelectorDirectChild(record, 'Password'); - const url = this.querySelectorDirectChild(record, 'URL'); - const notes = this.querySelectorDirectChild(record, 'Notes'); - const cipher = this.initLoginCipher(); - cipher.name = accountName != null ? this.getValueOrDefault(accountName.textContent, '--') : '--'; - cipher.notes = notes != null ? this.getValueOrDefault(notes.textContent) : ''; - cipher.login.username = userId != null ? this.getValueOrDefault(userId.textContent) : null; - cipher.login.password = password != null ? this.getValueOrDefault(password.textContent) : null; - cipher.login.uris = url != null ? this.makeUriArray(url.textContent) : null; - - const attributes: string[] = []; - for (let i = 1; i <= 10; i++) { - attributes.push('Attribute-' + i); - } - - this.querySelectorAllDirectChild(record, attributes.join(',')).forEach(attr => { - if (this.isNullOrWhitespace(attr.textContent) || attr.textContent === 'null') { - return; - } - this.processKvp(cipher, attr.tagName, attr.textContent); - }); - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const doc = this.parseXml(data); + if (doc == null) { + result.success = false; + return Promise.resolve(result); } + + const records = doc.querySelectorAll("PasswordManager > record"); + Array.from(records).forEach((record) => { + const category = this.querySelectorDirectChild(record, "Category"); + const categoryText = + category != null && + !this.isNullOrWhitespace(category.textContent) && + category.textContent !== "Unfiled" + ? category.textContent + : null; + this.processFolder(result, categoryText); + + const accountName = this.querySelectorDirectChild(record, "Account-Name"); + const userId = this.querySelectorDirectChild(record, "User-Id"); + const password = this.querySelectorDirectChild(record, "Password"); + const url = this.querySelectorDirectChild(record, "URL"); + const notes = this.querySelectorDirectChild(record, "Notes"); + const cipher = this.initLoginCipher(); + cipher.name = + accountName != null ? this.getValueOrDefault(accountName.textContent, "--") : "--"; + cipher.notes = notes != null ? this.getValueOrDefault(notes.textContent) : ""; + cipher.login.username = userId != null ? this.getValueOrDefault(userId.textContent) : null; + cipher.login.password = + password != null ? this.getValueOrDefault(password.textContent) : null; + cipher.login.uris = url != null ? this.makeUriArray(url.textContent) : null; + + const attributes: string[] = []; + for (let i = 1; i <= 10; i++) { + attributes.push("Attribute-" + i); + } + + this.querySelectorAllDirectChild(record, attributes.join(",")).forEach((attr) => { + if (this.isNullOrWhitespace(attr.textContent) || attr.textContent === "null") { + return; + } + this.processKvp(cipher, attr.tagName, attr.textContent); + }); + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/passwordSafeXmlImporter.ts b/common/src/importers/passwordSafeXmlImporter.ts index e8e60731..55ae93ed 100644 --- a/common/src/importers/passwordSafeXmlImporter.ts +++ b/common/src/importers/passwordSafeXmlImporter.ts @@ -1,62 +1,69 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class PasswordSafeXmlImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const doc = this.parseXml(data); - if (doc == null) { - result.success = false; - return Promise.resolve(result); - } - - const passwordSafe = doc.querySelector('passwordsafe'); - if (passwordSafe == null) { - result.errorMessage = 'Missing `passwordsafe` node.'; - result.success = false; - return Promise.resolve(result); - } - - const notesDelimiter = passwordSafe.getAttribute('delimiter'); - const entries = doc.querySelectorAll('passwordsafe > entry'); - Array.from(entries).forEach(entry => { - const group = this.querySelectorDirectChild(entry, 'group'); - const groupText = group != null && !this.isNullOrWhitespace(group.textContent) ? - group.textContent.split('.').join('/') : null; - this.processFolder(result, groupText); - - const title = this.querySelectorDirectChild(entry, 'title'); - const username = this.querySelectorDirectChild(entry, 'username'); - const email = this.querySelectorDirectChild(entry, 'email'); - const password = this.querySelectorDirectChild(entry, 'password'); - const url = this.querySelectorDirectChild(entry, 'url'); - const notes = this.querySelectorDirectChild(entry, 'notes'); - const cipher = this.initLoginCipher(); - cipher.name = title != null ? this.getValueOrDefault(title.textContent, '--') : '--'; - cipher.notes = notes != null ? - this.getValueOrDefault(notes.textContent, '').split(notesDelimiter).join('\n') : null; - cipher.login.username = username != null ? this.getValueOrDefault(username.textContent) : null; - cipher.login.password = password != null ? this.getValueOrDefault(password.textContent) : null; - cipher.login.uris = url != null ? this.makeUriArray(url.textContent) : null; - - if (this.isNullOrWhitespace(cipher.login.username) && email != null) { - cipher.login.username = this.getValueOrDefault(email.textContent); - } else if (email != null && !this.isNullOrWhitespace(email.textContent)) { - cipher.notes = this.isNullOrWhitespace(cipher.notes) ? 'Email: ' + email.textContent - : (cipher.notes + '\n' + 'Email: ' + email.textContent); - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const doc = this.parseXml(data); + if (doc == null) { + result.success = false; + return Promise.resolve(result); } + + const passwordSafe = doc.querySelector("passwordsafe"); + if (passwordSafe == null) { + result.errorMessage = "Missing `passwordsafe` node."; + result.success = false; + return Promise.resolve(result); + } + + const notesDelimiter = passwordSafe.getAttribute("delimiter"); + const entries = doc.querySelectorAll("passwordsafe > entry"); + Array.from(entries).forEach((entry) => { + const group = this.querySelectorDirectChild(entry, "group"); + const groupText = + group != null && !this.isNullOrWhitespace(group.textContent) + ? group.textContent.split(".").join("/") + : null; + this.processFolder(result, groupText); + + const title = this.querySelectorDirectChild(entry, "title"); + const username = this.querySelectorDirectChild(entry, "username"); + const email = this.querySelectorDirectChild(entry, "email"); + const password = this.querySelectorDirectChild(entry, "password"); + const url = this.querySelectorDirectChild(entry, "url"); + const notes = this.querySelectorDirectChild(entry, "notes"); + const cipher = this.initLoginCipher(); + cipher.name = title != null ? this.getValueOrDefault(title.textContent, "--") : "--"; + cipher.notes = + notes != null + ? this.getValueOrDefault(notes.textContent, "").split(notesDelimiter).join("\n") + : null; + cipher.login.username = + username != null ? this.getValueOrDefault(username.textContent) : null; + cipher.login.password = + password != null ? this.getValueOrDefault(password.textContent) : null; + cipher.login.uris = url != null ? this.makeUriArray(url.textContent) : null; + + if (this.isNullOrWhitespace(cipher.login.username) && email != null) { + cipher.login.username = this.getValueOrDefault(email.textContent); + } else if (email != null && !this.isNullOrWhitespace(email.textContent)) { + cipher.notes = this.isNullOrWhitespace(cipher.notes) + ? "Email: " + email.textContent + : cipher.notes + "\n" + "Email: " + email.textContent; + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/passwordWalletTxtImporter.ts b/common/src/importers/passwordWalletTxtImporter.ts index 8a279562..eff71957 100644 --- a/common/src/importers/passwordWalletTxtImporter.ts +++ b/common/src/importers/passwordWalletTxtImporter.ts @@ -1,47 +1,47 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class PasswordWalletTxtImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.length < 1) { - return; - } - if (value.length > 5) { - this.processFolder(result, value[5]); - } - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value[0], '--'); - if (value.length > 4) { - cipher.notes = this.getValueOrDefault(value[4], '').split('¬').join('\n'); - } - if (value.length > 2) { - cipher.login.username = this.getValueOrDefault(value[2]); - } - if (value.length > 3) { - cipher.login.password = this.getValueOrDefault(value[3]); - } - if (value.length > 1) { - cipher.login.uris = this.makeUriArray(value[1]); - } - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.length < 1) { + return; + } + if (value.length > 5) { + this.processFolder(result, value[5]); + } + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[0], "--"); + if (value.length > 4) { + cipher.notes = this.getValueOrDefault(value[4], "").split("¬").join("\n"); + } + if (value.length > 2) { + cipher.login.username = this.getValueOrDefault(value[2]); + } + if (value.length > 3) { + cipher.login.password = this.getValueOrDefault(value[3]); + } + if (value.length > 1) { + cipher.login.uris = this.makeUriArray(value[1]); + } + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/rememBearCsvImporter.ts b/common/src/importers/rememBearCsvImporter.ts index 2388ea0f..2df49cfa 100644 --- a/common/src/importers/rememBearCsvImporter.ts +++ b/common/src/importers/rememBearCsvImporter.ts @@ -1,77 +1,77 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { CipherType } from '../enums/cipherType'; +import { CipherType } from "../enums/cipherType"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CardView } from '../models/view/cardView'; +import { CardView } from "../models/view/cardView"; export class RememBearCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); + } + + results.forEach((value) => { + if (value.trash === "true") { + return; + } + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.name); + cipher.notes = this.getValueOrDefault(value.notes); + if (value.type === "LoginItem") { + cipher.login.uris = this.makeUriArray(value.website); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.username = this.getValueOrDefault(value.username); + } else if (value.type === "CreditCardItem") { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + cipher.card.cardholderName = this.getValueOrDefault(value.cardholder); + cipher.card.number = this.getValueOrDefault(value.number); + cipher.card.brand = this.getCardBrand(cipher.card.number); + cipher.card.code = this.getValueOrDefault(value.verification); + + try { + const expMonth = this.getValueOrDefault(value.expiryMonth); + if (expMonth != null) { + const expMonthNumber = parseInt(expMonth, null); + if (expMonthNumber != null && expMonthNumber >= 1 && expMonthNumber <= 12) { + cipher.card.expMonth = expMonthNumber.toString(); + } + } + } catch { + // Ignore error + } + try { + const expYear = this.getValueOrDefault(value.expiryYear); + if (expYear != null) { + const expYearNumber = parseInt(expYear, null); + if (expYearNumber != null) { + cipher.card.expYear = expYearNumber.toString(); + } + } + } catch { + // Ignore error } - results.forEach(value => { - if (value.trash === 'true') { - return; - } - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.name); - cipher.notes = this.getValueOrDefault(value.notes); - if (value.type === 'LoginItem') { - cipher.login.uris = this.makeUriArray(value.website); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.username = this.getValueOrDefault(value.username); - } else if (value.type === 'CreditCardItem') { - cipher.type = CipherType.Card; - cipher.card = new CardView(); - cipher.card.cardholderName = this.getValueOrDefault(value.cardholder); - cipher.card.number = this.getValueOrDefault(value.number); - cipher.card.brand = this.getCardBrand(cipher.card.number); - cipher.card.code = this.getValueOrDefault(value.verification); + const pin = this.getValueOrDefault(value.pin); + if (pin != null) { + this.processKvp(cipher, "PIN", pin); + } + const zip = this.getValueOrDefault(value.zipCode); + if (zip != null) { + this.processKvp(cipher, "Zip Code", zip); + } + } + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); - try { - const expMonth = this.getValueOrDefault(value.expiryMonth); - if (expMonth != null) { - const expMonthNumber = parseInt(expMonth, null); - if (expMonthNumber != null && expMonthNumber >= 1 && expMonthNumber <= 12) { - cipher.card.expMonth = expMonthNumber.toString(); - } - } - } catch { - // Ignore error - } - try { - const expYear = this.getValueOrDefault(value.expiryYear); - if (expYear != null) { - const expYearNumber = parseInt(expYear, null); - if (expYearNumber != null) { - cipher.card.expYear = expYearNumber.toString(); - } - } - } catch { - // Ignore error - } - - const pin = this.getValueOrDefault(value.pin); - if (pin != null) { - this.processKvp(cipher, 'PIN', pin); - } - const zip = this.getValueOrDefault(value.zipCode); - if (zip != null) { - this.processKvp(cipher, 'Zip Code', zip); - } - } - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); - } + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/roboformCsvImporter.ts b/common/src/importers/roboformCsvImporter.ts index cb0c0de8..6c90dbfd 100644 --- a/common/src/importers/roboformCsvImporter.ts +++ b/common/src/importers/roboformCsvImporter.ts @@ -1,63 +1,69 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class RoboFormCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - let i = 1; - results.forEach(value => { - const folder = !this.isNullOrWhitespace(value.Folder) && value.Folder.startsWith('/') ? - value.Folder.replace('/', '') : value.Folder; - const folderName = !this.isNullOrWhitespace(folder) ? folder : null; - this.processFolder(result, folderName); - - const cipher = this.initLoginCipher(); - cipher.notes = this.getValueOrDefault(value.Note); - cipher.name = this.getValueOrDefault(value.Name, '--'); - cipher.login.username = this.getValueOrDefault(value.Login); - cipher.login.password = this.getValueOrDefault(value.Pwd); - cipher.login.uris = this.makeUriArray(value.Url); - - if (!this.isNullOrWhitespace(value.Rf_fields)) { - let fields: string[] = [value.Rf_fields]; - if (value.__parsed_extra != null && value.__parsed_extra.length > 0) { - fields = fields.concat(value.__parsed_extra); - } - fields.forEach((field: string) => { - const parts = field.split(':'); - if (parts.length < 3) { - return; - } - const key = parts[0] === '-no-name-' ? null : parts[0]; - const val = parts.length === 4 && parts[2] === 'rck' ? parts[1] : parts[2]; - this.processKvp(cipher, key, val); - }); - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - - if (i === results.length && cipher.name === '--' && this.isNullOrWhitespace(cipher.login.password)) { - return; - } - - result.ciphers.push(cipher); - i++; - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + let i = 1; + results.forEach((value) => { + const folder = + !this.isNullOrWhitespace(value.Folder) && value.Folder.startsWith("/") + ? value.Folder.replace("/", "") + : value.Folder; + const folderName = !this.isNullOrWhitespace(folder) ? folder : null; + this.processFolder(result, folderName); + + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value.Note); + cipher.name = this.getValueOrDefault(value.Name, "--"); + cipher.login.username = this.getValueOrDefault(value.Login); + cipher.login.password = this.getValueOrDefault(value.Pwd); + cipher.login.uris = this.makeUriArray(value.Url); + + if (!this.isNullOrWhitespace(value.Rf_fields)) { + let fields: string[] = [value.Rf_fields]; + if (value.__parsed_extra != null && value.__parsed_extra.length > 0) { + fields = fields.concat(value.__parsed_extra); + } + fields.forEach((field: string) => { + const parts = field.split(":"); + if (parts.length < 3) { + return; + } + const key = parts[0] === "-no-name-" ? null : parts[0]; + const val = parts.length === 4 && parts[2] === "rck" ? parts[1] : parts[2]; + this.processKvp(cipher, key, val); + }); + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + + if ( + i === results.length && + cipher.name === "--" && + this.isNullOrWhitespace(cipher.login.password) + ) { + return; + } + + result.ciphers.push(cipher); + i++; + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/safariCsvImporter.ts b/common/src/importers/safariCsvImporter.ts index 64a30b3a..1d32c92a 100644 --- a/common/src/importers/safariCsvImporter.ts +++ b/common/src/importers/safariCsvImporter.ts @@ -1,29 +1,29 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class SafariCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.Title, '--'); - cipher.login.username = this.getValueOrDefault(value.Username); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.uris = this.makeUriArray(value.Url); - cipher.login.totp = this.getValueOrDefault(value.OTPAuth); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.Title, "--"); + cipher.login.username = this.getValueOrDefault(value.Username); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.uris = this.makeUriArray(value.Url); + cipher.login.totp = this.getValueOrDefault(value.OTPAuth); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/safeInCloudXmlImporter.ts b/common/src/importers/safeInCloudXmlImporter.ts index 93339a66..82514e24 100644 --- a/common/src/importers/safeInCloudXmlImporter.ts +++ b/common/src/importers/safeInCloudXmlImporter.ts @@ -1,136 +1,135 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { FolderView } from '../models/view/folderView'; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { FolderView } from "../models/view/folderView"; +import { SecureNoteView } from "../models/view/secureNoteView"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; -import { FieldType } from '../enums/fieldType'; -import { CipherView } from '../models/view/cipherView'; -import { FieldView } from '../models/view/fieldView'; +import { FieldType } from "../enums/fieldType"; +import { CipherView } from "../models/view/cipherView"; +import { FieldView } from "../models/view/fieldView"; export class SafeInCloudXmlImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const doc = this.parseXml(data); - if (doc == null) { - result.success = false; - return Promise.resolve(result); - } - - const db = doc.querySelector('database'); - if (db == null) { - result.errorMessage = 'Missing `database` node.'; - result.success = false; - return Promise.resolve(result); - } - - const foldersMap = new Map(); - - Array.from(doc.querySelectorAll('database > label')).forEach(labelEl => { - const name = labelEl.getAttribute('name'); - const id = labelEl.getAttribute('id'); - if (!this.isNullOrWhitespace(name) && !this.isNullOrWhitespace(id)) { - foldersMap.set(id, result.folders.length); - const folder = new FolderView(); - folder.name = name; - result.folders.push(folder); - } - }); - - Array.from(doc.querySelectorAll('database > card')).forEach(cardEl => { - if (cardEl.getAttribute('template') === 'true' || cardEl.getAttribute('deleted') === 'true') { - return; - } - - const labelIdEl = this.querySelectorDirectChild(cardEl, 'label_id'); - if (labelIdEl != null) { - const labelId = labelIdEl.textContent; - if (!this.isNullOrWhitespace(labelId) && foldersMap.has(labelId)) { - result.folderRelationships.push([result.ciphers.length, foldersMap.get(labelId)]); - } - } - - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(cardEl.getAttribute('title'), '--'); - - if (cardEl.getAttribute('star') === 'true') { - cipher.favorite = true; - } - - const cardType = cardEl.getAttribute('type'); - if (cardType === 'note') { - cipher.type = CipherType.SecureNote; - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - } else { - Array.from(this.querySelectorAllDirectChild(cardEl, 'field')).forEach(fieldEl => { - const text = fieldEl.textContent; - if (this.isNullOrWhitespace(text)) { - return; - } - const name = fieldEl.getAttribute('name'); - const fieldType = this.getValueOrDefault(fieldEl.getAttribute('type'), '').toLowerCase(); - if (fieldType === 'login') { - cipher.login.username = text; - } else if (fieldType === 'password' || fieldType === 'secret') { - // safeInCloud allows for more than one password. we just insert them here and find the one used as password later - this.processKvp(cipher, name, text, FieldType.Hidden); - } else if (fieldType === 'one_time_password') { - cipher.login.totp = text; - } else if (fieldType === 'notes') { - cipher.notes += (text + '\n'); - } else if (fieldType === 'weblogin' || fieldType === 'website') { - cipher.login.uris = this.makeUriArray(text); - } - else { - this.processKvp(cipher, name, text); - } - }); - } - - Array.from(this.querySelectorAllDirectChild(cardEl, 'notes')).forEach(notesEl => { - cipher.notes += (notesEl.textContent + '\n'); - }); - - this.setPassword(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const doc = this.parseXml(data); + if (doc == null) { + result.success = false; + return Promise.resolve(result); } - // Choose a password from all passwords. Take one that has password in its name, or the first one if there is no such entry - // if its name is password, we can safely remove it form the fields. otherwise, it would maybe be best to keep it as a hidden field - setPassword(cipher: CipherView) { - const candidates = cipher.fields.filter(field => field.type === FieldType.Hidden); - if (!candidates.length) { + const db = doc.querySelector("database"); + if (db == null) { + result.errorMessage = "Missing `database` node."; + result.success = false; + return Promise.resolve(result); + } + + const foldersMap = new Map(); + + Array.from(doc.querySelectorAll("database > label")).forEach((labelEl) => { + const name = labelEl.getAttribute("name"); + const id = labelEl.getAttribute("id"); + if (!this.isNullOrWhitespace(name) && !this.isNullOrWhitespace(id)) { + foldersMap.set(id, result.folders.length); + const folder = new FolderView(); + folder.name = name; + result.folders.push(folder); + } + }); + + Array.from(doc.querySelectorAll("database > card")).forEach((cardEl) => { + if (cardEl.getAttribute("template") === "true" || cardEl.getAttribute("deleted") === "true") { + return; + } + + const labelIdEl = this.querySelectorDirectChild(cardEl, "label_id"); + if (labelIdEl != null) { + const labelId = labelIdEl.textContent; + if (!this.isNullOrWhitespace(labelId) && foldersMap.has(labelId)) { + result.folderRelationships.push([result.ciphers.length, foldersMap.get(labelId)]); + } + } + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(cardEl.getAttribute("title"), "--"); + + if (cardEl.getAttribute("star") === "true") { + cipher.favorite = true; + } + + const cardType = cardEl.getAttribute("type"); + if (cardType === "note") { + cipher.type = CipherType.SecureNote; + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + } else { + Array.from(this.querySelectorAllDirectChild(cardEl, "field")).forEach((fieldEl) => { + const text = fieldEl.textContent; + if (this.isNullOrWhitespace(text)) { return; - } + } + const name = fieldEl.getAttribute("name"); + const fieldType = this.getValueOrDefault(fieldEl.getAttribute("type"), "").toLowerCase(); + if (fieldType === "login") { + cipher.login.username = text; + } else if (fieldType === "password" || fieldType === "secret") { + // safeInCloud allows for more than one password. we just insert them here and find the one used as password later + this.processKvp(cipher, name, text, FieldType.Hidden); + } else if (fieldType === "one_time_password") { + cipher.login.totp = text; + } else if (fieldType === "notes") { + cipher.notes += text + "\n"; + } else if (fieldType === "weblogin" || fieldType === "website") { + cipher.login.uris = this.makeUriArray(text); + } else { + this.processKvp(cipher, name, text); + } + }); + } - let choice: FieldView; - for (const field of candidates) { - if (this.passwordFieldNames.includes(field.name.toLowerCase())) { - choice = field; - cipher.fields = cipher.fields.filter(f => f !== choice); - break; - } - } + Array.from(this.querySelectorAllDirectChild(cardEl, "notes")).forEach((notesEl) => { + cipher.notes += notesEl.textContent + "\n"; + }); - if (!choice) { - choice = candidates[0]; - } + this.setPassword(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); - cipher.login.password = choice.value; + if (this.organization) { + this.moveFoldersToCollections(result); } + + result.success = true; + return Promise.resolve(result); + } + + // Choose a password from all passwords. Take one that has password in its name, or the first one if there is no such entry + // if its name is password, we can safely remove it form the fields. otherwise, it would maybe be best to keep it as a hidden field + setPassword(cipher: CipherView) { + const candidates = cipher.fields.filter((field) => field.type === FieldType.Hidden); + if (!candidates.length) { + return; + } + + let choice: FieldView; + for (const field of candidates) { + if (this.passwordFieldNames.includes(field.name.toLowerCase())) { + choice = field; + cipher.fields = cipher.fields.filter((f) => f !== choice); + break; + } + } + + if (!choice) { + choice = candidates[0]; + } + + cipher.login.password = choice.value; + } } diff --git a/common/src/importers/saferpassCsvImport.ts b/common/src/importers/saferpassCsvImport.ts index 1273e741..435a1a37 100644 --- a/common/src/importers/saferpassCsvImport.ts +++ b/common/src/importers/saferpassCsvImport.ts @@ -1,29 +1,29 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class SaferPassCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(this.nameFromUrl(value.url), '--'); - cipher.notes = this.getValueOrDefault(value.notes); - cipher.login.username = this.getValueOrDefault(value.username); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.uris = this.makeUriArray(value.url); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(this.nameFromUrl(value.url), "--"); + cipher.notes = this.getValueOrDefault(value.notes); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.url); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/secureSafeCsvImporter.ts b/common/src/importers/secureSafeCsvImporter.ts index fc15efec..540177a0 100644 --- a/common/src/importers/secureSafeCsvImporter.ts +++ b/common/src/importers/secureSafeCsvImporter.ts @@ -1,29 +1,29 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class SecureSafeCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.Title); - cipher.notes = this.getValueOrDefault(value.Comment); - cipher.login.uris = this.makeUriArray(value.Url); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.username = this.getValueOrDefault(value.Username); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.Title); + cipher.notes = this.getValueOrDefault(value.Comment); + cipher.login.uris = this.makeUriArray(value.Url); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.username = this.getValueOrDefault(value.Username); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/splashIdCsvImporter.ts b/common/src/importers/splashIdCsvImporter.ts index 4e895d55..b38380a9 100644 --- a/common/src/importers/splashIdCsvImporter.ts +++ b/common/src/importers/splashIdCsvImporter.ts @@ -1,57 +1,57 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; -import { CipherView } from '../models/view/cipherView'; +import { ImportResult } from "../models/domain/importResult"; +import { CipherView } from "../models/view/cipherView"; export class SplashIdCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.length < 3) { - return; - } - - this.processFolder(result, this.getValueOrDefault(value[value.length - 1])); - const cipher = this.initLoginCipher(); - cipher.notes = this.getValueOrDefault(value[value.length - 2], ''); - cipher.name = this.getValueOrDefault(value[1], '--'); - - if (value[0] === 'Web Logins' || value[0] === 'Servers' || value[0] === 'Email Accounts') { - cipher.login.username = this.getValueOrDefault(value[2]); - cipher.login.password = this.getValueOrDefault(value[3]); - cipher.login.uris = this.makeUriArray(value[4]); - this.parseFieldsToNotes(cipher, 5, value); - } else { - this.parseFieldsToNotes(cipher, 2, value); - } - - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } - private parseFieldsToNotes(cipher: CipherView, startIndex: number, value: any) { - // last 3 rows do not get parsed - for (let i = startIndex; i < value.length - 3; i++) { - if (this.isNullOrWhitespace(value[i])) { - continue; - } - cipher.notes += (value[i] + '\n'); - } + results.forEach((value) => { + if (value.length < 3) { + return; + } + + this.processFolder(result, this.getValueOrDefault(value[value.length - 1])); + const cipher = this.initLoginCipher(); + cipher.notes = this.getValueOrDefault(value[value.length - 2], ""); + cipher.name = this.getValueOrDefault(value[1], "--"); + + if (value[0] === "Web Logins" || value[0] === "Servers" || value[0] === "Email Accounts") { + cipher.login.username = this.getValueOrDefault(value[2]); + cipher.login.password = this.getValueOrDefault(value[3]); + cipher.login.uris = this.makeUriArray(value[4]); + this.parseFieldsToNotes(cipher, 5, value); + } else { + this.parseFieldsToNotes(cipher, 2, value); + } + + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); } + + result.success = true; + return Promise.resolve(result); + } + + private parseFieldsToNotes(cipher: CipherView, startIndex: number, value: any) { + // last 3 rows do not get parsed + for (let i = startIndex; i < value.length - 3; i++) { + if (this.isNullOrWhitespace(value[i])) { + continue; + } + cipher.notes += value[i] + "\n"; + } + } } diff --git a/common/src/importers/stickyPasswordXmlImporter.ts b/common/src/importers/stickyPasswordXmlImporter.ts index 313ab1fc..1bfba5b6 100644 --- a/common/src/importers/stickyPasswordXmlImporter.ts +++ b/common/src/importers/stickyPasswordXmlImporter.ts @@ -1,79 +1,83 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class StickyPasswordXmlImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const doc = this.parseXml(data); - if (doc == null) { - result.success = false; - return Promise.resolve(result); - } - - const loginNodes = doc.querySelectorAll('root > Database > Logins > Login'); - Array.from(loginNodes).forEach(loginNode => { - const accountId = loginNode.getAttribute('ID'); - if (this.isNullOrWhitespace(accountId)) { - return; - } - - const usernameText = loginNode.getAttribute('Name'); - const passwordText = loginNode.getAttribute('Password'); - let titleText: string = null; - let linkText: string = null; - let notesText: string = null; - let groupId: string = null; - let groupText: string = null; - - const accountLogin = doc.querySelector('root > Database > Accounts > Account > ' + - 'LoginLinks > Login[SourceLoginID="' + accountId + '"]'); - if (accountLogin != null) { - const account = accountLogin.parentElement.parentElement; - if (account != null) { - titleText = account.getAttribute('Name'); - linkText = account.getAttribute('Link'); - groupId = account.getAttribute('ParentID'); - notesText = account.getAttribute('Comments'); - if (!this.isNullOrWhitespace(notesText)) { - notesText = notesText.split('/n').join('\n'); - } - } - } - - if (!this.isNullOrWhitespace(groupId)) { - groupText = this.buildGroupText(doc, groupId, ''); - this.processFolder(result, groupText); - } - - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(titleText, '--'); - cipher.notes = this.getValueOrDefault(notesText); - cipher.login.username = this.getValueOrDefault(usernameText); - cipher.login.password = this.getValueOrDefault(passwordText); - cipher.login.uris = this.makeUriArray(linkText); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const doc = this.parseXml(data); + if (doc == null) { + result.success = false; + return Promise.resolve(result); } - buildGroupText(doc: Document, groupId: string, groupText: string): string { - const group = doc.querySelector('root > Database > Groups > Group[ID="' + groupId + '"]'); - if (group == null) { - return groupText; + const loginNodes = doc.querySelectorAll("root > Database > Logins > Login"); + Array.from(loginNodes).forEach((loginNode) => { + const accountId = loginNode.getAttribute("ID"); + if (this.isNullOrWhitespace(accountId)) { + return; + } + + const usernameText = loginNode.getAttribute("Name"); + const passwordText = loginNode.getAttribute("Password"); + let titleText: string = null; + let linkText: string = null; + let notesText: string = null; + let groupId: string = null; + let groupText: string = null; + + const accountLogin = doc.querySelector( + "root > Database > Accounts > Account > " + + 'LoginLinks > Login[SourceLoginID="' + + accountId + + '"]' + ); + if (accountLogin != null) { + const account = accountLogin.parentElement.parentElement; + if (account != null) { + titleText = account.getAttribute("Name"); + linkText = account.getAttribute("Link"); + groupId = account.getAttribute("ParentID"); + notesText = account.getAttribute("Comments"); + if (!this.isNullOrWhitespace(notesText)) { + notesText = notesText.split("/n").join("\n"); + } } - if (!this.isNullOrWhitespace(groupText)) { - groupText = '/' + groupText; - } - groupText = group.getAttribute('Name') + groupText; - return this.buildGroupText(doc, group.getAttribute('ParentID'), groupText); + } + + if (!this.isNullOrWhitespace(groupId)) { + groupText = this.buildGroupText(doc, groupId, ""); + this.processFolder(result, groupText); + } + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(titleText, "--"); + cipher.notes = this.getValueOrDefault(notesText); + cipher.login.username = this.getValueOrDefault(usernameText); + cipher.login.password = this.getValueOrDefault(passwordText); + cipher.login.uris = this.makeUriArray(linkText); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); } + + result.success = true; + return Promise.resolve(result); + } + + buildGroupText(doc: Document, groupId: string, groupText: string): string { + const group = doc.querySelector('root > Database > Groups > Group[ID="' + groupId + '"]'); + if (group == null) { + return groupText; + } + if (!this.isNullOrWhitespace(groupText)) { + groupText = "/" + groupText; + } + groupText = group.getAttribute("Name") + groupText; + return this.buildGroupText(doc, group.getAttribute("ParentID"), groupText); + } } diff --git a/common/src/importers/truekeyCsvImporter.ts b/common/src/importers/truekeyCsvImporter.ts index aa004b67..622ef89c 100644 --- a/common/src/importers/truekeyCsvImporter.ts +++ b/common/src/importers/truekeyCsvImporter.ts @@ -1,76 +1,89 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CardView } from '../models/view/cardView'; -import { SecureNoteView } from '../models/view/secureNoteView'; +import { CardView } from "../models/view/cardView"; +import { SecureNoteView } from "../models/view/secureNoteView"; -import { CipherType } from '../enums/cipherType'; -import { SecureNoteType } from '../enums/secureNoteType'; +import { CipherType } from "../enums/cipherType"; +import { SecureNoteType } from "../enums/secureNoteType"; -const PropertiesToIgnore = ['kind', 'autologin', 'favorite', 'hexcolor', 'protectedwithpassword', 'subdomainonly', - 'type', 'tk_export_version', 'note', 'title', 'document_content', +const PropertiesToIgnore = [ + "kind", + "autologin", + "favorite", + "hexcolor", + "protectedwithpassword", + "subdomainonly", + "type", + "tk_export_version", + "note", + "title", + "document_content", ]; export class TrueKeyCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.favorite = this.getValueOrDefault(value.favorite, '').toLowerCase() === 'true'; - cipher.name = this.getValueOrDefault(value.name, '--'); - cipher.notes = this.getValueOrDefault(value.memo, ''); - cipher.login.username = this.getValueOrDefault(value.login); - cipher.login.password = this.getValueOrDefault(value.password); - cipher.login.uris = this.makeUriArray(value.url); - - if (value.kind !== 'login') { - cipher.name = this.getValueOrDefault(value.title, '--'); - cipher.notes = this.getValueOrDefault(value.note, ''); - } - - if (value.kind === 'cc') { - cipher.type = CipherType.Card; - cipher.card = new CardView(); - cipher.card.cardholderName = this.getValueOrDefault(value.cardholder); - cipher.card.number = this.getValueOrDefault(value.number); - cipher.card.brand = this.getCardBrand(cipher.card.number); - if (!this.isNullOrWhitespace(value.expiryDate)) { - try { - const expDate = new Date(value.expiryDate); - cipher.card.expYear = expDate.getFullYear().toString(); - cipher.card.expMonth = (expDate.getMonth() + 1).toString(); - } catch { - // Ignore error - } - } - } else if (value.kind !== 'login') { - cipher.type = CipherType.SecureNote; - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - if (!this.isNullOrWhitespace(cipher.notes)) { - cipher.notes = this.getValueOrDefault(value.document_content, ''); - } - for (const property in value) { - if (value.hasOwnProperty(property) && PropertiesToIgnore.indexOf(property.toLowerCase()) < 0 && - !this.isNullOrWhitespace(value[property])) { - this.processKvp(cipher, property, value[property]); - } - } - } - - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.favorite = this.getValueOrDefault(value.favorite, "").toLowerCase() === "true"; + cipher.name = this.getValueOrDefault(value.name, "--"); + cipher.notes = this.getValueOrDefault(value.memo, ""); + cipher.login.username = this.getValueOrDefault(value.login); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.url); + + if (value.kind !== "login") { + cipher.name = this.getValueOrDefault(value.title, "--"); + cipher.notes = this.getValueOrDefault(value.note, ""); + } + + if (value.kind === "cc") { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + cipher.card.cardholderName = this.getValueOrDefault(value.cardholder); + cipher.card.number = this.getValueOrDefault(value.number); + cipher.card.brand = this.getCardBrand(cipher.card.number); + if (!this.isNullOrWhitespace(value.expiryDate)) { + try { + const expDate = new Date(value.expiryDate); + cipher.card.expYear = expDate.getFullYear().toString(); + cipher.card.expMonth = (expDate.getMonth() + 1).toString(); + } catch { + // Ignore error + } + } + } else if (value.kind !== "login") { + cipher.type = CipherType.SecureNote; + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + if (!this.isNullOrWhitespace(cipher.notes)) { + cipher.notes = this.getValueOrDefault(value.document_content, ""); + } + for (const property in value) { + if ( + value.hasOwnProperty(property) && + PropertiesToIgnore.indexOf(property.toLowerCase()) < 0 && + !this.isNullOrWhitespace(value[property]) + ) { + this.processKvp(cipher, property, value[property]); + } + } + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/upmCsvImporter.ts b/common/src/importers/upmCsvImporter.ts index 23e4ece3..a13c5be6 100644 --- a/common/src/importers/upmCsvImporter.ts +++ b/common/src/importers/upmCsvImporter.ts @@ -1,32 +1,32 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class UpmCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, false); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (value.length !== 5) { - return; - } - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value[0], '--'); - cipher.notes = this.getValueOrDefault(value[4]); - cipher.login.username = this.getValueOrDefault(value[1]); - cipher.login.password = this.getValueOrDefault(value[2]); - cipher.login.uris = this.makeUriArray(value[3]); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + if (value.length !== 5) { + return; + } + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[0], "--"); + cipher.notes = this.getValueOrDefault(value[4]); + cipher.login.username = this.getValueOrDefault(value[1]); + cipher.login.password = this.getValueOrDefault(value[2]); + cipher.login.uris = this.makeUriArray(value[3]); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/yotiCsvImporter.ts b/common/src/importers/yotiCsvImporter.ts index 56a80d5d..fedc1c81 100644 --- a/common/src/importers/yotiCsvImporter.ts +++ b/common/src/importers/yotiCsvImporter.ts @@ -1,28 +1,28 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; export class YotiCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - const cipher = this.initLoginCipher(); - cipher.name = this.getValueOrDefault(value.Name, '--'); - cipher.login.username = this.getValueOrDefault(value['User name']); - cipher.login.password = this.getValueOrDefault(value.Password); - cipher.login.uris = this.makeUriArray(value.URL); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.Name, "--"); + cipher.login.username = this.getValueOrDefault(value["User name"]); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.uris = this.makeUriArray(value.URL); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return Promise.resolve(result); + } } diff --git a/common/src/importers/zohoVaultCsvImporter.ts b/common/src/importers/zohoVaultCsvImporter.ts index 536dc8cc..1a3e009c 100644 --- a/common/src/importers/zohoVaultCsvImporter.ts +++ b/common/src/importers/zohoVaultCsvImporter.ts @@ -1,68 +1,81 @@ -import { BaseImporter } from './baseImporter'; -import { Importer } from './importer'; +import { BaseImporter } from "./baseImporter"; +import { Importer } from "./importer"; -import { ImportResult } from '../models/domain/importResult'; -import { CipherView } from '../models/view/cipherView'; +import { ImportResult } from "../models/domain/importResult"; +import { CipherView } from "../models/view/cipherView"; export class ZohoVaultCsvImporter extends BaseImporter implements Importer { - parse(data: string): Promise { - const result = new ImportResult(); - const results = this.parseCsv(data, true); - if (results == null) { - result.success = false; - return Promise.resolve(result); - } - - results.forEach(value => { - if (this.isNullOrWhitespace(value['Password Name']) && this.isNullOrWhitespace(value['Secret Name'])) { - return; - } - this.processFolder(result, this.getValueOrDefault(value.ChamberName)); - const cipher = this.initLoginCipher(); - cipher.favorite = this.getValueOrDefault(value.Favorite, '0') === '1'; - cipher.notes = this.getValueOrDefault(value.Notes); - cipher.name = this.getValueOrDefault( - value['Password Name'], this.getValueOrDefault(value['Secret Name'], '--')); - cipher.login.uris = this.makeUriArray( - this.getValueOrDefault(value['Password URL'], this.getValueOrDefault(value['Secret URL']))); - this.parseData(cipher, value.SecretData); - this.parseData(cipher, value.CustomData); - this.convertToNoteIfNeeded(cipher); - this.cleanupCipher(cipher); - result.ciphers.push(cipher); - }); - - if (this.organization) { - this.moveFoldersToCollections(result); - } - - result.success = true; - return Promise.resolve(result); + parse(data: string): Promise { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return Promise.resolve(result); } - private parseData(cipher: CipherView, data: string) { - if (this.isNullOrWhitespace(data)) { - return; - } - const dataLines = this.splitNewLine(data); - dataLines.forEach(line => { - const delimPosition = line.indexOf(':'); - if (delimPosition < 0) { - return; - } - const field = line.substring(0, delimPosition); - const value = line.length > delimPosition ? line.substring(delimPosition + 1) : null; - if (this.isNullOrWhitespace(field) || this.isNullOrWhitespace(value) || field === 'SecretType') { - return; - } - const fieldLower = field.toLowerCase(); - if (cipher.login.username == null && this.usernameFieldNames.indexOf(fieldLower) > -1) { - cipher.login.username = value; - } else if (cipher.login.password == null && this.passwordFieldNames.indexOf(fieldLower) > -1) { - cipher.login.password = value; - } else { - this.processKvp(cipher, field, value); - } - }); + results.forEach((value) => { + if ( + this.isNullOrWhitespace(value["Password Name"]) && + this.isNullOrWhitespace(value["Secret Name"]) + ) { + return; + } + this.processFolder(result, this.getValueOrDefault(value.ChamberName)); + const cipher = this.initLoginCipher(); + cipher.favorite = this.getValueOrDefault(value.Favorite, "0") === "1"; + cipher.notes = this.getValueOrDefault(value.Notes); + cipher.name = this.getValueOrDefault( + value["Password Name"], + this.getValueOrDefault(value["Secret Name"], "--") + ); + cipher.login.uris = this.makeUriArray( + this.getValueOrDefault(value["Password URL"], this.getValueOrDefault(value["Secret URL"])) + ); + this.parseData(cipher, value.SecretData); + this.parseData(cipher, value.CustomData); + this.convertToNoteIfNeeded(cipher); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); } + + result.success = true; + return Promise.resolve(result); + } + + private parseData(cipher: CipherView, data: string) { + if (this.isNullOrWhitespace(data)) { + return; + } + const dataLines = this.splitNewLine(data); + dataLines.forEach((line) => { + const delimPosition = line.indexOf(":"); + if (delimPosition < 0) { + return; + } + const field = line.substring(0, delimPosition); + const value = line.length > delimPosition ? line.substring(delimPosition + 1) : null; + if ( + this.isNullOrWhitespace(field) || + this.isNullOrWhitespace(value) || + field === "SecretType" + ) { + return; + } + const fieldLower = field.toLowerCase(); + if (cipher.login.username == null && this.usernameFieldNames.indexOf(fieldLower) > -1) { + cipher.login.username = value; + } else if ( + cipher.login.password == null && + this.passwordFieldNames.indexOf(fieldLower) > -1 + ) { + cipher.login.password = value; + } else { + this.processKvp(cipher, field, value); + } + }); + } } diff --git a/common/src/misc/captcha_iframe.ts b/common/src/misc/captcha_iframe.ts index c098288d..b3b1af92 100644 --- a/common/src/misc/captcha_iframe.ts +++ b/common/src/misc/captcha_iframe.ts @@ -1,22 +1,37 @@ -import { I18nService } from '../abstractions/i18n.service'; -import { IFrameComponent } from './iframe_component'; +import { I18nService } from "../abstractions/i18n.service"; +import { IFrameComponent } from "./iframe_component"; export class CaptchaIFrame extends IFrameComponent { - constructor(win: Window, webVaultUrl: string, - private i18nService: I18nService, successCallback: (message: string) => any, errorCallback: (message: string) => any, - infoCallback: (message: string) => any) { - super(win, webVaultUrl, 'captcha-connector.html', 'hcaptcha_iframe', successCallback, errorCallback, (message: string) => { - const parsedMessage = JSON.parse(message); - if (typeof (parsedMessage) !== 'string') { - this.iframe.height = (parsedMessage.height).toString(); - this.iframe.width = (parsedMessage.width).toString(); - } else { - infoCallback(parsedMessage); - } - }); - } + constructor( + win: Window, + webVaultUrl: string, + private i18nService: I18nService, + successCallback: (message: string) => any, + errorCallback: (message: string) => any, + infoCallback: (message: string) => any + ) { + super( + win, + webVaultUrl, + "captcha-connector.html", + "hcaptcha_iframe", + successCallback, + errorCallback, + (message: string) => { + const parsedMessage = JSON.parse(message); + if (typeof parsedMessage !== "string") { + this.iframe.height = parsedMessage.height.toString(); + this.iframe.width = parsedMessage.width.toString(); + } else { + infoCallback(parsedMessage); + } + } + ); + } - init(siteKey: string): void { - super.initComponent(this.createParams({ siteKey: siteKey, locale: this.i18nService.translationLocale }, 1)); - } + init(siteKey: string): void { + super.initComponent( + this.createParams({ siteKey: siteKey, locale: this.i18nService.translationLocale }, 1) + ); + } } diff --git a/common/src/misc/iframe_component.ts b/common/src/misc/iframe_component.ts index 0e04dee0..7315e11b 100644 --- a/common/src/misc/iframe_component.ts +++ b/common/src/misc/iframe_component.ts @@ -1,80 +1,96 @@ -import { I18nService } from '../abstractions/i18n.service'; +import { I18nService } from "../abstractions/i18n.service"; export abstract class IFrameComponent { - iframe: HTMLIFrameElement; - private connectorLink: HTMLAnchorElement; - private parseFunction = this.parseMessage.bind(this); + iframe: HTMLIFrameElement; + private connectorLink: HTMLAnchorElement; + private parseFunction = this.parseMessage.bind(this); - constructor(private win: Window, protected webVaultUrl: string, private path: string, private iframeId: string, - public successCallback?: (message: string) => any, - public errorCallback?: (message: string) => any, public infoCallback?: (message: string) => any) { - this.connectorLink = win.document.createElement('a'); + constructor( + private win: Window, + protected webVaultUrl: string, + private path: string, + private iframeId: string, + public successCallback?: (message: string) => any, + public errorCallback?: (message: string) => any, + public infoCallback?: (message: string) => any + ) { + this.connectorLink = win.document.createElement("a"); + } + + stop() { + this.sendMessage("stop"); + } + + start() { + this.sendMessage("start"); + } + + sendMessage(message: any) { + if (!this.iframe || !this.iframe.src || !this.iframe.contentWindow) { + return; } - stop() { - this.sendMessage('stop'); + this.iframe.contentWindow.postMessage(message, this.iframe.src); + } + + base64Encode(str: string): string { + return btoa( + encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => { + return String.fromCharCode(("0x" + p1) as any); + }) + ); + } + + cleanup() { + this.win.removeEventListener("message", this.parseFunction, false); + } + + protected createParams(data: any, version: number) { + return new URLSearchParams({ + data: this.base64Encode(JSON.stringify(data)), + parent: encodeURIComponent(this.win.document.location.href), + v: version.toString(), + }); + } + + protected initComponent(params: URLSearchParams): void { + this.connectorLink.href = `${this.webVaultUrl}/${this.path}?${params}`; + this.iframe = this.win.document.getElementById(this.iframeId) as HTMLIFrameElement; + this.iframe.src = this.connectorLink.href; + + this.win.addEventListener("message", this.parseFunction, false); + } + + private parseMessage(event: MessageEvent) { + if (!this.validMessage(event)) { + return; } - start() { - this.sendMessage('start'); + const parts: string[] = event.data.split("|"); + if (parts[0] === "success" && this.successCallback) { + this.successCallback(parts[1]); + } else if (parts[0] === "error" && this.errorCallback) { + this.errorCallback(parts[1]); + } else if (parts[0] === "info" && this.infoCallback) { + this.infoCallback(parts[1]); + } + } + + private validMessage(event: MessageEvent) { + if ( + event.origin == null || + event.origin === "" || + event.origin !== (this.connectorLink as any).origin || + event.data == null || + typeof event.data !== "string" + ) { + return false; } - sendMessage(message: any) { - if (!this.iframe || !this.iframe.src || !this.iframe.contentWindow) { - return; - } - - this.iframe.contentWindow.postMessage(message, this.iframe.src); - } - - base64Encode(str: string): string { - return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => { - return String.fromCharCode(('0x' + p1) as any); - })); - } - - cleanup() { - this.win.removeEventListener('message', this.parseFunction, false); - } - - protected createParams(data: any, version: number) { - return new URLSearchParams({ - data: this.base64Encode(JSON.stringify(data)), - parent: encodeURIComponent(this.win.document.location.href), - v: version.toString(), - }); - } - - protected initComponent(params: URLSearchParams): void { - this.connectorLink.href = `${this.webVaultUrl}/${this.path}?${params}`; - this.iframe = this.win.document.getElementById(this.iframeId) as HTMLIFrameElement; - this.iframe.src = this.connectorLink.href; - - this.win.addEventListener('message', this.parseFunction, false); - } - - private parseMessage(event: MessageEvent) { - if (!this.validMessage(event)) { - return; - } - - const parts: string[] = event.data.split('|'); - if (parts[0] === 'success' && this.successCallback) { - this.successCallback(parts[1]); - } else if (parts[0] === 'error' && this.errorCallback) { - this.errorCallback(parts[1]); - } else if (parts[0] === 'info' && this.infoCallback) { - this.infoCallback(parts[1]); - } - } - - private validMessage(event: MessageEvent) { - if (event.origin == null || event.origin === '' || event.origin !== (this.connectorLink as any).origin || - event.data == null || typeof (event.data) !== 'string') { - return false; - } - - return event.data.indexOf('success|') === 0 || event.data.indexOf('error|') === 0 || - event.data.indexOf('info|') === 0; - } + return ( + event.data.indexOf("success|") === 0 || + event.data.indexOf("error|") === 0 || + event.data.indexOf("info|") === 0 + ); + } } diff --git a/common/src/misc/linkedFieldOption.decorator.ts b/common/src/misc/linkedFieldOption.decorator.ts index 5bf05275..8f10709c 100644 --- a/common/src/misc/linkedFieldOption.decorator.ts +++ b/common/src/misc/linkedFieldOption.decorator.ts @@ -1,13 +1,13 @@ -import { ItemView } from '../models/view/itemView'; +import { ItemView } from "../models/view/itemView"; -import { LinkedIdType } from '../enums/linkedIdType'; +import { LinkedIdType } from "../enums/linkedIdType"; export class LinkedMetadata { - constructor(readonly propertyKey: string, private readonly _i18nKey?: string) { } + constructor(readonly propertyKey: string, private readonly _i18nKey?: string) {} - get i18nKey() { - return this._i18nKey ?? this.propertyKey; - } + get i18nKey() { + return this._i18nKey ?? this.propertyKey; + } } /** @@ -18,11 +18,11 @@ export class LinkedMetadata { * of the class property will be used as the i18n key. */ export function linkedFieldOption(id: LinkedIdType, i18nKey?: string) { - return (prototype: ItemView, propertyKey: string) => { - if (prototype.linkedFieldOptions == null) { - prototype.linkedFieldOptions = new Map(); - } + return (prototype: ItemView, propertyKey: string) => { + if (prototype.linkedFieldOptions == null) { + prototype.linkedFieldOptions = new Map(); + } - prototype.linkedFieldOptions.set(id, new LinkedMetadata(propertyKey, i18nKey)); - }; + prototype.linkedFieldOptions.set(id, new LinkedMetadata(propertyKey, i18nKey)); + }; } diff --git a/common/src/misc/nodeUtils.ts b/common/src/misc/nodeUtils.ts index d3864fe5..5b5ba27b 100644 --- a/common/src/misc/nodeUtils.ts +++ b/common/src/misc/nodeUtils.ts @@ -1,34 +1,34 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import * as readline from 'readline'; +import * as fs from "fs"; +import * as path from "path"; +import * as readline from "readline"; export class NodeUtils { - static mkdirpSync(targetDir: string, mode = '700', relative = false, relativeDir: string = null) { - const initialDir = path.isAbsolute(targetDir) ? path.sep : ''; - const baseDir = relative ? (relativeDir != null ? relativeDir : __dirname) : '.'; - targetDir.split(path.sep).reduce((parentDir, childDir) => { - const dir = path.resolve(baseDir, parentDir, childDir); - if (!fs.existsSync(dir)) { - fs.mkdirSync(dir, mode); - } - return dir; - }, initialDir); - } - static readFirstLine(fileName: string) { - return new Promise((resolve, reject) => { - const readStream = fs.createReadStream(fileName, {encoding: 'utf8'}); - const readInterface = readline.createInterface(readStream); - readInterface - .on('line', line => { - readStream.close(); - resolve(line); - }) - .on('error', err => reject(err)); - }); - } + static mkdirpSync(targetDir: string, mode = "700", relative = false, relativeDir: string = null) { + const initialDir = path.isAbsolute(targetDir) ? path.sep : ""; + const baseDir = relative ? (relativeDir != null ? relativeDir : __dirname) : "."; + targetDir.split(path.sep).reduce((parentDir, childDir) => { + const dir = path.resolve(baseDir, parentDir, childDir); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, mode); + } + return dir; + }, initialDir); + } + static readFirstLine(fileName: string) { + return new Promise((resolve, reject) => { + const readStream = fs.createReadStream(fileName, { encoding: "utf8" }); + const readInterface = readline.createInterface(readStream); + readInterface + .on("line", (line) => { + readStream.close(); + resolve(line); + }) + .on("error", (err) => reject(err)); + }); + } - // https://stackoverflow.com/a/31394257 - static bufferToArrayBuffer(buf: Buffer): ArrayBuffer { - return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); - } + // https://stackoverflow.com/a/31394257 + static bufferToArrayBuffer(buf: Buffer): ArrayBuffer { + return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); + } } diff --git a/common/src/misc/sequentialize.ts b/common/src/misc/sequentialize.ts index ff8c4856..c2421147 100644 --- a/common/src/misc/sequentialize.ts +++ b/common/src/misc/sequentialize.ts @@ -9,46 +9,49 @@ * Read more at https://github.com/bitwarden/jslib/pull/7 */ export function sequentialize(cacheKey: (args: any[]) => string) { - return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => { - const originalMethod: () => Promise = descriptor.value; - const caches = new Map>>(); + return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => { + const originalMethod: () => Promise = descriptor.value; + const caches = new Map>>(); - const getCache = (obj: any) => { - let cache = caches.get(obj); - if (cache != null) { - return cache; - } - cache = new Map>(); - caches.set(obj, cache); - return cache; - }; - - return { - value: function(...args: any[]) { - const cache = getCache(this); - const argsCacheKey = cacheKey(args); - let response = cache.get(argsCacheKey); - if (response != null) { - return response; - } - - const onFinally = () => { - cache.delete(argsCacheKey); - if (cache.size === 0) { - caches.delete(this); - } - }; - response = originalMethod.apply(this, args).then((val: any) => { - onFinally(); - return val; - }).catch((err: any) => { - onFinally(); - throw err; - }); - - cache.set(argsCacheKey, response); - return response; - }, - }; + const getCache = (obj: any) => { + let cache = caches.get(obj); + if (cache != null) { + return cache; + } + cache = new Map>(); + caches.set(obj, cache); + return cache; }; + + return { + value: function (...args: any[]) { + const cache = getCache(this); + const argsCacheKey = cacheKey(args); + let response = cache.get(argsCacheKey); + if (response != null) { + return response; + } + + const onFinally = () => { + cache.delete(argsCacheKey); + if (cache.size === 0) { + caches.delete(this); + } + }; + response = originalMethod + .apply(this, args) + .then((val: any) => { + onFinally(); + return val; + }) + .catch((err: any) => { + onFinally(); + throw err; + }); + + cache.set(argsCacheKey, response); + return response; + }, + }; + }; } diff --git a/common/src/misc/serviceUtils.ts b/common/src/misc/serviceUtils.ts index f8cb5257..b6c05092 100644 --- a/common/src/misc/serviceUtils.ts +++ b/common/src/misc/serviceUtils.ts @@ -1,54 +1,72 @@ -import { - ITreeNodeObject, - TreeNode, -} from '../models/domain/treeNode'; +import { ITreeNodeObject, TreeNode } from "../models/domain/treeNode"; export class ServiceUtils { - static nestedTraverse(nodeTree: TreeNode[], partIndex: number, parts: string[], - obj: ITreeNodeObject, parent: ITreeNodeObject, delimiter: string) { - if (parts.length <= partIndex) { - return; - } - - const end = partIndex === parts.length - 1; - const partName = parts[partIndex]; - - for (let i = 0; i < nodeTree.length; i++) { - if (nodeTree[i].node.name !== parts[partIndex]) { - continue; - } - if (end && nodeTree[i].node.id !== obj.id) { - // Another node with the same name. - nodeTree.push(new TreeNode(obj, partName, parent)); - return; - } - ServiceUtils.nestedTraverse(nodeTree[i].children, partIndex + 1, parts, - obj, nodeTree[i].node, delimiter); - return; - } - - if (nodeTree.filter(n => n.node.name === partName).length === 0) { - if (end) { - nodeTree.push(new TreeNode(obj, partName, parent)); - return; - } - const newPartName = parts[partIndex] + delimiter + parts[partIndex + 1]; - ServiceUtils.nestedTraverse(nodeTree, 0, [newPartName, ...parts.slice(partIndex + 2)], - obj, parent, delimiter); - } + static nestedTraverse( + nodeTree: TreeNode[], + partIndex: number, + parts: string[], + obj: ITreeNodeObject, + parent: ITreeNodeObject, + delimiter: string + ) { + if (parts.length <= partIndex) { + return; } - static getTreeNodeObject(nodeTree: TreeNode[], id: string): TreeNode { - for (let i = 0; i < nodeTree.length; i++) { - if (nodeTree[i].node.id === id) { - return nodeTree[i]; - } else if (nodeTree[i].children != null) { - const node = ServiceUtils.getTreeNodeObject(nodeTree[i].children, id); - if (node !== null) { - return node; - } - } - } - return null; + const end = partIndex === parts.length - 1; + const partName = parts[partIndex]; + + for (let i = 0; i < nodeTree.length; i++) { + if (nodeTree[i].node.name !== parts[partIndex]) { + continue; + } + if (end && nodeTree[i].node.id !== obj.id) { + // Another node with the same name. + nodeTree.push(new TreeNode(obj, partName, parent)); + return; + } + ServiceUtils.nestedTraverse( + nodeTree[i].children, + partIndex + 1, + parts, + obj, + nodeTree[i].node, + delimiter + ); + return; } + + if (nodeTree.filter((n) => n.node.name === partName).length === 0) { + if (end) { + nodeTree.push(new TreeNode(obj, partName, parent)); + return; + } + const newPartName = parts[partIndex] + delimiter + parts[partIndex + 1]; + ServiceUtils.nestedTraverse( + nodeTree, + 0, + [newPartName, ...parts.slice(partIndex + 2)], + obj, + parent, + delimiter + ); + } + } + + static getTreeNodeObject( + nodeTree: TreeNode[], + id: string + ): TreeNode { + for (let i = 0; i < nodeTree.length; i++) { + if (nodeTree[i].node.id === id) { + return nodeTree[i]; + } else if (nodeTree[i].children != null) { + const node = ServiceUtils.getTreeNodeObject(nodeTree[i].children, id); + if (node !== null) { + return node; + } + } + } + return null; + } } diff --git a/common/src/misc/throttle.ts b/common/src/misc/throttle.ts index 5455db72..852ee999 100644 --- a/common/src/misc/throttle.ts +++ b/common/src/misc/throttle.ts @@ -5,58 +5,65 @@ * Calls beyond the limit will be queued, and run when one of the active calls finishes */ export function throttle(limit: number, throttleKey: (args: any[]) => string) { - return (target: any, propertyKey: string | symbol, - descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>) => { - const originalMethod: () => Promise = descriptor.value; - const allThrottles = new Map void)[]>>(); + return ( + target: any, + propertyKey: string | symbol, + descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise> + ) => { + const originalMethod: () => Promise = descriptor.value; + const allThrottles = new Map void)[]>>(); - const getThrottles = (obj: any) => { - let throttles = allThrottles.get(obj); - if (throttles != null) { - return throttles; - } - throttles = new Map void)[]>(); - allThrottles.set(obj, throttles); - return throttles; - }; - - return { - value: function(...args: any[]) { - const throttles = getThrottles(this); - const argsThrottleKey = throttleKey(args); - let queue = throttles.get(argsThrottleKey); - if (queue == null) { - queue = []; - throttles.set(argsThrottleKey, queue); - } - - return new Promise((resolve, reject) => { - const exec = () => { - const onFinally = () => { - queue.splice(queue.indexOf(exec), 1); - if (queue.length >= limit) { - queue[limit - 1](); - } else if (queue.length === 0) { - throttles.delete(argsThrottleKey); - if (throttles.size === 0) { - allThrottles.delete(this); - } - } - }; - originalMethod.apply(this, args).then((val: any) => { - onFinally(); - return val; - }).catch((err: any) => { - onFinally(); - throw err; - }).then(resolve, reject); - }; - queue.push(exec); - if (queue.length <= limit) { - exec(); - } - }); - }, - }; + const getThrottles = (obj: any) => { + let throttles = allThrottles.get(obj); + if (throttles != null) { + return throttles; + } + throttles = new Map void)[]>(); + allThrottles.set(obj, throttles); + return throttles; }; + + return { + value: function (...args: any[]) { + const throttles = getThrottles(this); + const argsThrottleKey = throttleKey(args); + let queue = throttles.get(argsThrottleKey); + if (queue == null) { + queue = []; + throttles.set(argsThrottleKey, queue); + } + + return new Promise((resolve, reject) => { + const exec = () => { + const onFinally = () => { + queue.splice(queue.indexOf(exec), 1); + if (queue.length >= limit) { + queue[limit - 1](); + } else if (queue.length === 0) { + throttles.delete(argsThrottleKey); + if (throttles.size === 0) { + allThrottles.delete(this); + } + } + }; + originalMethod + .apply(this, args) + .then((val: any) => { + onFinally(); + return val; + }) + .catch((err: any) => { + onFinally(); + throw err; + }) + .then(resolve, reject); + }; + queue.push(exec); + if (queue.length <= limit) { + exec(); + } + }); + }, + }; + }; } diff --git a/common/src/misc/utils.ts b/common/src/misc/utils.ts index 5d578dce..932a98b1 100644 --- a/common/src/misc/utils.ts +++ b/common/src/misc/utils.ts @@ -1,371 +1,400 @@ -import * as tldts from 'tldts'; +import * as tldts from "tldts"; -import { I18nService } from '../abstractions/i18n.service'; +import { I18nService } from "../abstractions/i18n.service"; // tslint:disable-next-line -const nodeURL = typeof window === 'undefined' ? require('url') : null; +const nodeURL = typeof window === "undefined" ? require("url") : null; export class Utils { - static inited = false; - static isNativeScript = false; - static isNode = false; - static isBrowser = true; - static isMobileBrowser = false; - static isAppleMobileBrowser = false; - static global: any = null; - static tldEndingRegex = /.*\.(com|net|org|edu|uk|gov|ca|de|jp|fr|au|ru|ch|io|es|us|co|xyz|info|ly|mil)$/; - // Transpiled version of /\p{Emoji_Presentation}/gu using https://mothereff.in/regexpu. Used for compatability in older browsers. - static regexpEmojiPresentation = /(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])/g; - static readonly validHosts: string[] = ['localhost']; + static inited = false; + static isNativeScript = false; + static isNode = false; + static isBrowser = true; + static isMobileBrowser = false; + static isAppleMobileBrowser = false; + static global: any = null; + static tldEndingRegex = + /.*\.(com|net|org|edu|uk|gov|ca|de|jp|fr|au|ru|ch|io|es|us|co|xyz|info|ly|mil)$/; + // Transpiled version of /\p{Emoji_Presentation}/gu using https://mothereff.in/regexpu. Used for compatability in older browsers. + static regexpEmojiPresentation = + /(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])/g; + static readonly validHosts: string[] = ["localhost"]; - static init() { - if (Utils.inited) { - return; + static init() { + if (Utils.inited) { + return; + } + + Utils.inited = true; + Utils.isNode = + typeof process !== "undefined" && + (process as any).release != null && + (process as any).release.name === "node"; + Utils.isBrowser = typeof window !== "undefined"; + Utils.isNativeScript = !Utils.isNode && !Utils.isBrowser; + Utils.isMobileBrowser = Utils.isBrowser && this.isMobile(window); + Utils.isAppleMobileBrowser = Utils.isBrowser && this.isAppleMobile(window); + Utils.global = Utils.isNativeScript + ? global + : Utils.isNode && !Utils.isBrowser + ? global + : window; + } + + static fromB64ToArray(str: string): Uint8Array { + if (Utils.isNode || Utils.isNativeScript) { + return new Uint8Array(Buffer.from(str, "base64")); + } else { + const binaryString = window.atob(str); + const bytes = new Uint8Array(binaryString.length); + for (let i = 0; i < binaryString.length; i++) { + bytes[i] = binaryString.charCodeAt(i); + } + return bytes; + } + } + + static fromUrlB64ToArray(str: string): Uint8Array { + return Utils.fromB64ToArray(Utils.fromUrlB64ToB64(str)); + } + + static fromHexToArray(str: string): Uint8Array { + if (Utils.isNode || Utils.isNativeScript) { + return new Uint8Array(Buffer.from(str, "hex")); + } else { + const bytes = new Uint8Array(str.length / 2); + for (let i = 0; i < str.length; i += 2) { + bytes[i / 2] = parseInt(str.substr(i, 2), 16); + } + return bytes; + } + } + + static fromUtf8ToArray(str: string): Uint8Array { + if (Utils.isNode || Utils.isNativeScript) { + return new Uint8Array(Buffer.from(str, "utf8")); + } else { + const strUtf8 = unescape(encodeURIComponent(str)); + const arr = new Uint8Array(strUtf8.length); + for (let i = 0; i < strUtf8.length; i++) { + arr[i] = strUtf8.charCodeAt(i); + } + return arr; + } + } + + static fromByteStringToArray(str: string): Uint8Array { + const arr = new Uint8Array(str.length); + for (let i = 0; i < str.length; i++) { + arr[i] = str.charCodeAt(i); + } + return arr; + } + + static fromBufferToB64(buffer: ArrayBuffer): string { + if (Utils.isNode || Utils.isNativeScript) { + return Buffer.from(buffer).toString("base64"); + } else { + let binary = ""; + const bytes = new Uint8Array(buffer); + for (let i = 0; i < bytes.byteLength; i++) { + binary += String.fromCharCode(bytes[i]); + } + return window.btoa(binary); + } + } + + static fromBufferToUrlB64(buffer: ArrayBuffer): string { + return Utils.fromB64toUrlB64(Utils.fromBufferToB64(buffer)); + } + + static fromB64toUrlB64(b64Str: string) { + return b64Str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""); + } + + static fromBufferToUtf8(buffer: ArrayBuffer): string { + if (Utils.isNode || Utils.isNativeScript) { + return Buffer.from(buffer).toString("utf8"); + } else { + const bytes = new Uint8Array(buffer); + const encodedString = String.fromCharCode.apply(null, bytes); + return decodeURIComponent(escape(encodedString)); + } + } + + static fromBufferToByteString(buffer: ArrayBuffer): string { + return String.fromCharCode.apply(null, new Uint8Array(buffer)); + } + + // ref: https://stackoverflow.com/a/40031979/1090359 + static fromBufferToHex(buffer: ArrayBuffer): string { + if (Utils.isNode || Utils.isNativeScript) { + return Buffer.from(buffer).toString("hex"); + } else { + const bytes = new Uint8Array(buffer); + return Array.prototype.map + .call(bytes, (x: number) => ("00" + x.toString(16)).slice(-2)) + .join(""); + } + } + + static fromUrlB64ToB64(urlB64Str: string): string { + let output = urlB64Str.replace(/-/g, "+").replace(/_/g, "/"); + switch (output.length % 4) { + case 0: + break; + case 2: + output += "=="; + break; + case 3: + output += "="; + break; + default: + throw new Error("Illegal base64url string!"); + } + + return output; + } + + static fromUrlB64ToUtf8(urlB64Str: string): string { + return Utils.fromB64ToUtf8(Utils.fromUrlB64ToB64(urlB64Str)); + } + + static fromUtf8ToB64(utfStr: string): string { + if (Utils.isNode || Utils.isNativeScript) { + return Buffer.from(utfStr, "utf8").toString("base64"); + } else { + return decodeURIComponent(escape(window.btoa(utfStr))); + } + } + + static fromUtf8ToUrlB64(utfStr: string): string { + return Utils.fromBufferToUrlB64(Utils.fromUtf8ToArray(utfStr)); + } + + static fromB64ToUtf8(b64Str: string): string { + if (Utils.isNode || Utils.isNativeScript) { + return Buffer.from(b64Str, "base64").toString("utf8"); + } else { + return decodeURIComponent(escape(window.atob(b64Str))); + } + } + + // ref: http://stackoverflow.com/a/2117523/1090359 + static newGuid(): string { + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { + // tslint:disable-next-line + const r = (Math.random() * 16) | 0; + // tslint:disable-next-line + const v = c === "x" ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); + } + + static isGuid(id: string) { + return RegExp( + /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, + "i" + ).test(id); + } + + static getHostname(uriString: string): string { + if (Utils.isNullOrWhitespace(uriString)) { + return null; + } + + uriString = uriString.trim(); + + // Does uriString contain invalid characters + // TODO Needs to possibly be extended, although '!' is a reserved character + if (uriString.indexOf("!") > 0) { + return null; + } + + try { + const hostname = tldts.getHostname(uriString, { validHosts: this.validHosts }); + if (hostname != null) { + return hostname; + } + } catch { + return null; + } + return null; + } + + static getHost(uriString: string): string { + const url = Utils.getUrl(uriString); + try { + return url != null && url.host !== "" ? url.host : null; + } catch { + return null; + } + } + + static getDomain(uriString: string): string { + if (Utils.isNullOrWhitespace(uriString)) { + return null; + } + + uriString = uriString.trim(); + + if (uriString.startsWith("data:")) { + return null; + } + + let httpUrl = uriString.startsWith("http://") || uriString.startsWith("https://"); + if ( + !httpUrl && + uriString.indexOf("://") < 0 && + Utils.tldEndingRegex.test(uriString) && + uriString.indexOf("@") < 0 + ) { + uriString = "http://" + uriString; + httpUrl = true; + } + + try { + const parseResult = tldts.parse(uriString, { validHosts: this.validHosts }); + if (parseResult != null && parseResult.hostname != null) { + if (parseResult.hostname === "localhost" || parseResult.isIp) { + return parseResult.hostname; } - Utils.inited = true; - Utils.isNode = typeof process !== 'undefined' && (process as any).release != null && - (process as any).release.name === 'node'; - Utils.isBrowser = typeof window !== 'undefined'; - Utils.isNativeScript = !Utils.isNode && !Utils.isBrowser; - Utils.isMobileBrowser = Utils.isBrowser && this.isMobile(window); - Utils.isAppleMobileBrowser = Utils.isBrowser && this.isAppleMobile(window); - Utils.global = Utils.isNativeScript ? global : (Utils.isNode && !Utils.isBrowser ? global : window); - } - - static fromB64ToArray(str: string): Uint8Array { - if (Utils.isNode || Utils.isNativeScript) { - return new Uint8Array(Buffer.from(str, 'base64')); - } else { - const binaryString = window.atob(str); - const bytes = new Uint8Array(binaryString.length); - for (let i = 0; i < binaryString.length; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - return bytes; - } - } - - static fromUrlB64ToArray(str: string): Uint8Array { - return Utils.fromB64ToArray(Utils.fromUrlB64ToB64(str)); - } - - static fromHexToArray(str: string): Uint8Array { - if (Utils.isNode || Utils.isNativeScript) { - return new Uint8Array(Buffer.from(str, 'hex')); - } else { - const bytes = new Uint8Array(str.length / 2); - for (let i = 0; i < str.length; i += 2) { - bytes[i / 2] = parseInt(str.substr(i, 2), 16); - } - return bytes; - } - } - - static fromUtf8ToArray(str: string): Uint8Array { - if (Utils.isNode || Utils.isNativeScript) { - return new Uint8Array(Buffer.from(str, 'utf8')); - } else { - const strUtf8 = unescape(encodeURIComponent(str)); - const arr = new Uint8Array(strUtf8.length); - for (let i = 0; i < strUtf8.length; i++) { - arr[i] = strUtf8.charCodeAt(i); - } - return arr; - } - } - - static fromByteStringToArray(str: string): Uint8Array { - const arr = new Uint8Array(str.length); - for (let i = 0; i < str.length; i++) { - arr[i] = str.charCodeAt(i); - } - return arr; - } - - static fromBufferToB64(buffer: ArrayBuffer): string { - if (Utils.isNode || Utils.isNativeScript) { - return Buffer.from(buffer).toString('base64'); - } else { - let binary = ''; - const bytes = new Uint8Array(buffer); - for (let i = 0; i < bytes.byteLength; i++) { - binary += String.fromCharCode(bytes[i]); - } - return window.btoa(binary); - } - } - - static fromBufferToUrlB64(buffer: ArrayBuffer): string { - return Utils.fromB64toUrlB64(Utils.fromBufferToB64(buffer)); - } - - static fromB64toUrlB64(b64Str: string) { - return b64Str.replace(/\+/g, '-') - .replace(/\//g, '_') - .replace(/=/g, ''); - } - - static fromBufferToUtf8(buffer: ArrayBuffer): string { - if (Utils.isNode || Utils.isNativeScript) { - return Buffer.from(buffer).toString('utf8'); - } else { - const bytes = new Uint8Array(buffer); - const encodedString = String.fromCharCode.apply(null, bytes); - return decodeURIComponent(escape(encodedString)); - } - } - - static fromBufferToByteString(buffer: ArrayBuffer): string { - return String.fromCharCode.apply(null, new Uint8Array(buffer)); - } - - // ref: https://stackoverflow.com/a/40031979/1090359 - static fromBufferToHex(buffer: ArrayBuffer): string { - if (Utils.isNode || Utils.isNativeScript) { - return Buffer.from(buffer).toString('hex'); - } else { - const bytes = new Uint8Array(buffer); - return Array.prototype.map.call(bytes, (x: number) => ('00' + x.toString(16)).slice(-2)).join(''); - } - } - - static fromUrlB64ToB64(urlB64Str: string): string { - let output = urlB64Str.replace(/-/g, '+').replace(/_/g, '/'); - switch (output.length % 4) { - case 0: - break; - case 2: - output += '=='; - break; - case 3: - output += '='; - break; - default: - throw new Error('Illegal base64url string!'); - } - - return output; - } - - static fromUrlB64ToUtf8(urlB64Str: string): string { - return Utils.fromB64ToUtf8(Utils.fromUrlB64ToB64(urlB64Str)); - } - - static fromUtf8ToB64(utfStr: string): string { - if (Utils.isNode || Utils.isNativeScript) { - return Buffer.from(utfStr, 'utf8').toString('base64'); - } else { - return decodeURIComponent(escape(window.btoa(utfStr))); - } - } - - static fromUtf8ToUrlB64(utfStr: string): string { - return Utils.fromBufferToUrlB64(Utils.fromUtf8ToArray(utfStr)); - } - - static fromB64ToUtf8(b64Str: string): string { - if (Utils.isNode || Utils.isNativeScript) { - return Buffer.from(b64Str, 'base64').toString('utf8'); - } else { - return decodeURIComponent(escape(window.atob(b64Str))); - } - } - - // ref: http://stackoverflow.com/a/2117523/1090359 - static newGuid(): string { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { - // tslint:disable-next-line - const r = Math.random() * 16 | 0; - // tslint:disable-next-line - const v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); - } - - static isGuid(id: string) { - return RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, 'i').test(id); - } - - static getHostname(uriString: string): string { - if (Utils.isNullOrWhitespace(uriString)) { - return null; - } - - uriString = uriString.trim(); - - // Does uriString contain invalid characters - // TODO Needs to possibly be extended, although '!' is a reserved character - if (uriString.indexOf('!') > 0) { - return null; - } - - try { - const hostname = tldts.getHostname(uriString, { validHosts: this.validHosts }); - if (hostname != null) { - return hostname; - } - } catch { - return null; + if (parseResult.domain != null) { + return parseResult.domain; } return null; + } + } catch { + return null; + } + return null; + } + + static getQueryParams(uriString: string): Map { + const url = Utils.getUrl(uriString); + if (url == null || url.search == null || url.search === "") { + return null; + } + const map = new Map(); + const pairs = (url.search[0] === "?" ? url.search.substr(1) : url.search).split("&"); + pairs.forEach((pair) => { + const parts = pair.split("="); + if (parts.length < 1) { + return; + } + map.set( + decodeURIComponent(parts[0]).toLowerCase(), + parts[1] == null ? "" : decodeURIComponent(parts[1]) + ); + }); + return map; + } + + static getSortFunction(i18nService: I18nService, prop: string) { + return (a: any, b: any) => { + if (a[prop] == null && b[prop] != null) { + return -1; + } + if (a[prop] != null && b[prop] == null) { + return 1; + } + if (a[prop] == null && b[prop] == null) { + return 0; + } + + return i18nService.collator + ? i18nService.collator.compare(a[prop], b[prop]) + : a[prop].localeCompare(b[prop]); + }; + } + + static isNullOrWhitespace(str: string): boolean { + return str == null || typeof str !== "string" || str.trim() === ""; + } + + static nameOf(name: string & keyof T) { + return name; + } + + static assign(target: T, source: Partial): T { + return Object.assign(target, source); + } + + static iterateEnum(obj: O) { + return (Object.keys(obj).filter((k) => Number.isNaN(+k)) as K[]).map((k) => obj[k]); + } + + static getUrl(uriString: string): URL { + if (this.isNullOrWhitespace(uriString)) { + return null; } - static getHost(uriString: string): string { - const url = Utils.getUrl(uriString); - try { - return url != null && url.host !== '' ? url.host : null; - } catch { - return null; + uriString = uriString.trim(); + + let url = Utils.getUrlObject(uriString); + if (url == null) { + const hasHttpProtocol = + uriString.indexOf("http://") === 0 || uriString.indexOf("https://") === 0; + if (!hasHttpProtocol && uriString.indexOf(".") > -1) { + url = Utils.getUrlObject("http://" + uriString); + } + } + return url; + } + + static camelToPascalCase(s: string) { + return s.charAt(0).toUpperCase() + s.slice(1); + } + + private static isMobile(win: Window) { + let mobile = false; + ((a) => { + // tslint:disable-next-line + if ( + /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test( + a + ) || + /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( + a.substr(0, 4) + ) + ) { + mobile = true; + } + })(win.navigator.userAgent || win.navigator.vendor || (win as any).opera); + return mobile || win.navigator.userAgent.match(/iPad/i) != null; + } + + private static isAppleMobile(win: Window) { + return ( + win.navigator.userAgent.match(/iPhone/i) != null || + win.navigator.userAgent.match(/iPad/i) != null + ); + } + + private static getUrlObject(uriString: string): URL { + try { + if (nodeURL != null) { + return nodeURL.URL ? new nodeURL.URL(uriString) : nodeURL.parse(uriString); + } else if (typeof URL === "function") { + return new URL(uriString); + } else if (window != null) { + const hasProtocol = uriString.indexOf("://") > -1; + if (!hasProtocol && uriString.indexOf(".") > -1) { + uriString = "http://" + uriString; + } else if (!hasProtocol) { + return null; } + const anchor = window.document.createElement("a"); + anchor.href = uriString; + return anchor as any; + } + } catch (e) { + // Ignore error } - static getDomain(uriString: string): string { - if (Utils.isNullOrWhitespace(uriString)) { - return null; - } - - uriString = uriString.trim(); - - if (uriString.startsWith('data:')) { - return null; - } - - let httpUrl = uriString.startsWith('http://') || uriString.startsWith('https://'); - if (!httpUrl && uriString.indexOf('://') < 0 && Utils.tldEndingRegex.test(uriString) && - uriString.indexOf('@') < 0) { - uriString = 'http://' + uriString; - httpUrl = true; - } - - try { - const parseResult = tldts.parse(uriString, { validHosts: this.validHosts }); - if (parseResult != null && parseResult.hostname != null) { - if (parseResult.hostname === 'localhost' || parseResult.isIp) { - return parseResult.hostname; - } - - if (parseResult.domain != null) { - return parseResult.domain; - } - return null; - } - } catch { - return null; - } - return null; - } - - static getQueryParams(uriString: string): Map { - const url = Utils.getUrl(uriString); - if (url == null || url.search == null || url.search === '') { - return null; - } - const map = new Map(); - const pairs = (url.search[0] === '?' ? url.search.substr(1) : url.search).split('&'); - pairs.forEach(pair => { - const parts = pair.split('='); - if (parts.length < 1) { - return; - } - map.set(decodeURIComponent(parts[0]).toLowerCase(), parts[1] == null ? '' : decodeURIComponent(parts[1])); - }); - return map; - } - - static getSortFunction(i18nService: I18nService, prop: string) { - return (a: any, b: any) => { - if (a[prop] == null && b[prop] != null) { - return -1; - } - if (a[prop] != null && b[prop] == null) { - return 1; - } - if (a[prop] == null && b[prop] == null) { - return 0; - } - - return i18nService.collator ? i18nService.collator.compare(a[prop], b[prop]) : - a[prop].localeCompare(b[prop]); - }; - } - - static isNullOrWhitespace(str: string): boolean { - return str == null || typeof str !== 'string' || str.trim() === ''; - } - - static nameOf(name: string & keyof T) { - return name; - } - - static assign(target: T, source: Partial): T { - return Object.assign(target, source); - } - - static iterateEnum(obj: O) { - return (Object.keys(obj).filter(k => Number.isNaN(+k)) as K[]).map(k => obj[k]); - } - - - static getUrl(uriString: string): URL { - if (this.isNullOrWhitespace(uriString)) { - return null; - } - - uriString = uriString.trim(); - - let url = Utils.getUrlObject(uriString); - if (url == null) { - const hasHttpProtocol = uriString.indexOf('http://') === 0 || uriString.indexOf('https://') === 0; - if (!hasHttpProtocol && uriString.indexOf('.') > -1) { - url = Utils.getUrlObject('http://' + uriString); - } - } - return url; - } - - static camelToPascalCase(s: string) { - return s.charAt(0).toUpperCase() + s.slice(1); - } - - private static isMobile(win: Window) { - let mobile = false; - (a => { - // tslint:disable-next-line - if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) { - mobile = true; - } - })(win.navigator.userAgent || win.navigator.vendor || (win as any).opera); - return mobile || win.navigator.userAgent.match(/iPad/i) != null; - } - - private static isAppleMobile(win: Window) { - return win.navigator.userAgent.match(/iPhone/i) != null || win.navigator.userAgent.match(/iPad/i) != null; - } - - private static getUrlObject(uriString: string): URL { - try { - if (nodeURL != null) { - return nodeURL.URL ? new nodeURL.URL(uriString) : nodeURL.parse(uriString); - } else if (typeof URL === 'function') { - return new URL(uriString); - } else if (window != null) { - const hasProtocol = uriString.indexOf('://') > -1; - if (!hasProtocol && uriString.indexOf('.') > -1) { - uriString = 'http://' + uriString; - } else if (!hasProtocol) { - return null; - } - const anchor = window.document.createElement('a'); - anchor.href = uriString; - return anchor as any; - } - } catch (e) { - // Ignore error - } - - return null; - } + return null; + } } Utils.init(); diff --git a/common/src/misc/webauthn_iframe.ts b/common/src/misc/webauthn_iframe.ts index 54dbdc45..712594ba 100644 --- a/common/src/misc/webauthn_iframe.ts +++ b/common/src/misc/webauthn_iframe.ts @@ -1,87 +1,106 @@ -import { I18nService } from '../abstractions/i18n.service'; -import { PlatformUtilsService } from '../abstractions/platformUtils.service'; +import { I18nService } from "../abstractions/i18n.service"; +import { PlatformUtilsService } from "../abstractions/platformUtils.service"; export class WebAuthnIFrame { - private iframe: HTMLIFrameElement = null; - private connectorLink: HTMLAnchorElement; - private parseFunction = this.parseMessage.bind(this); + private iframe: HTMLIFrameElement = null; + private connectorLink: HTMLAnchorElement; + private parseFunction = this.parseMessage.bind(this); - constructor(private win: Window, private webVaultUrl: string, private webAuthnNewTab: boolean, - private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private successCallback: Function, private errorCallback: Function, private infoCallback: Function) { - this.connectorLink = win.document.createElement('a'); + constructor( + private win: Window, + private webVaultUrl: string, + private webAuthnNewTab: boolean, + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService, + private successCallback: Function, + private errorCallback: Function, + private infoCallback: Function + ) { + this.connectorLink = win.document.createElement("a"); + } + + init(data: any): void { + const params = new URLSearchParams({ + data: this.base64Encode(JSON.stringify(data)), + parent: encodeURIComponent(this.win.document.location.href), + btnText: encodeURIComponent(this.i18nService.t("webAuthnAuthenticate")), + v: "1", + }); + + if (this.webAuthnNewTab) { + // Firefox fallback which opens the webauthn page in a new tab + params.append("locale", this.i18nService.translationLocale); + this.platformUtilsService.launchUri( + `${this.webVaultUrl}/webauthn-fallback-connector.html?${params}` + ); + } else { + this.connectorLink.href = `${this.webVaultUrl}/webauthn-connector.html?${params}`; + this.iframe = this.win.document.getElementById("webauthn_iframe") as HTMLIFrameElement; + this.iframe.allow = "publickey-credentials-get " + new URL(this.webVaultUrl).origin; + this.iframe.src = this.connectorLink.href; + + this.win.addEventListener("message", this.parseFunction, false); + } + } + + stop() { + this.sendMessage("stop"); + } + + start() { + this.sendMessage("start"); + } + + sendMessage(message: any) { + if (!this.iframe || !this.iframe.src || !this.iframe.contentWindow) { + return; } - init(data: any): void { - const params = new URLSearchParams({ - data: this.base64Encode(JSON.stringify(data)), - parent: encodeURIComponent(this.win.document.location.href), - btnText: encodeURIComponent(this.i18nService.t('webAuthnAuthenticate')), - v: '1', - }); + this.iframe.contentWindow.postMessage(message, this.iframe.src); + } - if (this.webAuthnNewTab) { - // Firefox fallback which opens the webauthn page in a new tab - params.append('locale', this.i18nService.translationLocale); - this.platformUtilsService.launchUri(`${this.webVaultUrl}/webauthn-fallback-connector.html?${params}`); - } else { - this.connectorLink.href = `${this.webVaultUrl}/webauthn-connector.html?${params}`; - this.iframe = this.win.document.getElementById('webauthn_iframe') as HTMLIFrameElement; - this.iframe.allow = 'publickey-credentials-get ' + new URL(this.webVaultUrl).origin; - this.iframe.src = this.connectorLink.href; + base64Encode(str: string): string { + return btoa( + encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => { + return String.fromCharCode(("0x" + p1) as any); + }) + ); + } - this.win.addEventListener('message', this.parseFunction, false); - } + cleanup() { + this.win.removeEventListener("message", this.parseFunction, false); + } + + private parseMessage(event: MessageEvent) { + if (!this.validMessage(event)) { + return; } - stop() { - this.sendMessage('stop'); + const parts: string[] = event.data.split("|"); + if (parts[0] === "success" && this.successCallback) { + this.successCallback(parts[1]); + } else if (parts[0] === "error" && this.errorCallback) { + this.errorCallback(parts[1]); + } else if (parts[0] === "info" && this.infoCallback) { + this.infoCallback(parts[1]); + } + } + + private validMessage(event: MessageEvent) { + if ( + event.origin == null || + event.origin === "" || + event.origin !== (this.connectorLink as any).origin || + event.data == null || + typeof event.data !== "string" + ) { + return false; } - start() { - this.sendMessage('start'); - } - - sendMessage(message: any) { - if (!this.iframe || !this.iframe.src || !this.iframe.contentWindow) { - return; - } - - this.iframe.contentWindow.postMessage(message, this.iframe.src); - } - - base64Encode(str: string): string { - return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => { - return String.fromCharCode(('0x' + p1) as any); - })); - } - - cleanup() { - this.win.removeEventListener('message', this.parseFunction, false); - } - - private parseMessage(event: MessageEvent) { - if (!this.validMessage(event)) { - return; - } - - const parts: string[] = event.data.split('|'); - if (parts[0] === 'success' && this.successCallback) { - this.successCallback(parts[1]); - } else if (parts[0] === 'error' && this.errorCallback) { - this.errorCallback(parts[1]); - } else if (parts[0] === 'info' && this.infoCallback) { - this.infoCallback(parts[1]); - } - } - - private validMessage(event: MessageEvent) { - if (event.origin == null || event.origin === '' || event.origin !== (this.connectorLink as any).origin || - event.data == null || typeof (event.data) !== 'string') { - return false; - } - - return event.data.indexOf('success|') === 0 || event.data.indexOf('error|') === 0 || - event.data.indexOf('info|') === 0; - } + return ( + event.data.indexOf("success|") === 0 || + event.data.indexOf("error|") === 0 || + event.data.indexOf("info|") === 0 + ); + } } diff --git a/common/src/misc/wordlist.ts b/common/src/misc/wordlist.ts index fdbfa5ad..cdd30110 100644 --- a/common/src/misc/wordlist.ts +++ b/common/src/misc/wordlist.ts @@ -1,7779 +1,7779 @@ // EFF's Long Wordlist from https://www.eff.org/dice export const EEFLongWordList = [ - 'abacus', - 'abdomen', - 'abdominal', - 'abide', - 'abiding', - 'ability', - 'ablaze', - 'able', - 'abnormal', - 'abrasion', - 'abrasive', - 'abreast', - 'abridge', - 'abroad', - 'abruptly', - 'absence', - 'absentee', - 'absently', - 'absinthe', - 'absolute', - 'absolve', - 'abstain', - 'abstract', - 'absurd', - 'accent', - 'acclaim', - 'acclimate', - 'accompany', - 'account', - 'accuracy', - 'accurate', - 'accustom', - 'acetone', - 'achiness', - 'aching', - 'acid', - 'acorn', - 'acquaint', - 'acquire', - 'acre', - 'acrobat', - 'acronym', - 'acting', - 'action', - 'activate', - 'activator', - 'active', - 'activism', - 'activist', - 'activity', - 'actress', - 'acts', - 'acutely', - 'acuteness', - 'aeration', - 'aerobics', - 'aerosol', - 'aerospace', - 'afar', - 'affair', - 'affected', - 'affecting', - 'affection', - 'affidavit', - 'affiliate', - 'affirm', - 'affix', - 'afflicted', - 'affluent', - 'afford', - 'affront', - 'aflame', - 'afloat', - 'aflutter', - 'afoot', - 'afraid', - 'afterglow', - 'afterlife', - 'aftermath', - 'aftermost', - 'afternoon', - 'aged', - 'ageless', - 'agency', - 'agenda', - 'agent', - 'aggregate', - 'aghast', - 'agile', - 'agility', - 'aging', - 'agnostic', - 'agonize', - 'agonizing', - 'agony', - 'agreeable', - 'agreeably', - 'agreed', - 'agreeing', - 'agreement', - 'aground', - 'ahead', - 'ahoy', - 'aide', - 'aids', - 'aim', - 'ajar', - 'alabaster', - 'alarm', - 'albatross', - 'album', - 'alfalfa', - 'algebra', - 'algorithm', - 'alias', - 'alibi', - 'alienable', - 'alienate', - 'aliens', - 'alike', - 'alive', - 'alkaline', - 'alkalize', - 'almanac', - 'almighty', - 'almost', - 'aloe', - 'aloft', - 'aloha', - 'alone', - 'alongside', - 'aloof', - 'alphabet', - 'alright', - 'although', - 'altitude', - 'alto', - 'aluminum', - 'alumni', - 'always', - 'amaretto', - 'amaze', - 'amazingly', - 'amber', - 'ambiance', - 'ambiguity', - 'ambiguous', - 'ambition', - 'ambitious', - 'ambulance', - 'ambush', - 'amendable', - 'amendment', - 'amends', - 'amenity', - 'amiable', - 'amicably', - 'amid', - 'amigo', - 'amino', - 'amiss', - 'ammonia', - 'ammonium', - 'amnesty', - 'amniotic', - 'among', - 'amount', - 'amperage', - 'ample', - 'amplifier', - 'amplify', - 'amply', - 'amuck', - 'amulet', - 'amusable', - 'amused', - 'amusement', - 'amuser', - 'amusing', - 'anaconda', - 'anaerobic', - 'anagram', - 'anatomist', - 'anatomy', - 'anchor', - 'anchovy', - 'ancient', - 'android', - 'anemia', - 'anemic', - 'aneurism', - 'anew', - 'angelfish', - 'angelic', - 'anger', - 'angled', - 'angler', - 'angles', - 'angling', - 'angrily', - 'angriness', - 'anguished', - 'angular', - 'animal', - 'animate', - 'animating', - 'animation', - 'animator', - 'anime', - 'animosity', - 'ankle', - 'annex', - 'annotate', - 'announcer', - 'annoying', - 'annually', - 'annuity', - 'anointer', - 'another', - 'answering', - 'antacid', - 'antarctic', - 'anteater', - 'antelope', - 'antennae', - 'anthem', - 'anthill', - 'anthology', - 'antibody', - 'antics', - 'antidote', - 'antihero', - 'antiquely', - 'antiques', - 'antiquity', - 'antirust', - 'antitoxic', - 'antitrust', - 'antiviral', - 'antivirus', - 'antler', - 'antonym', - 'antsy', - 'anvil', - 'anybody', - 'anyhow', - 'anymore', - 'anyone', - 'anyplace', - 'anything', - 'anytime', - 'anyway', - 'anywhere', - 'aorta', - 'apache', - 'apostle', - 'appealing', - 'appear', - 'appease', - 'appeasing', - 'appendage', - 'appendix', - 'appetite', - 'appetizer', - 'applaud', - 'applause', - 'apple', - 'appliance', - 'applicant', - 'applied', - 'apply', - 'appointee', - 'appraisal', - 'appraiser', - 'apprehend', - 'approach', - 'approval', - 'approve', - 'apricot', - 'april', - 'apron', - 'aptitude', - 'aptly', - 'aqua', - 'aqueduct', - 'arbitrary', - 'arbitrate', - 'ardently', - 'area', - 'arena', - 'arguable', - 'arguably', - 'argue', - 'arise', - 'armadillo', - 'armband', - 'armchair', - 'armed', - 'armful', - 'armhole', - 'arming', - 'armless', - 'armoire', - 'armored', - 'armory', - 'armrest', - 'army', - 'aroma', - 'arose', - 'around', - 'arousal', - 'arrange', - 'array', - 'arrest', - 'arrival', - 'arrive', - 'arrogance', - 'arrogant', - 'arson', - 'art', - 'ascend', - 'ascension', - 'ascent', - 'ascertain', - 'ashamed', - 'ashen', - 'ashes', - 'ashy', - 'aside', - 'askew', - 'asleep', - 'asparagus', - 'aspect', - 'aspirate', - 'aspire', - 'aspirin', - 'astonish', - 'astound', - 'astride', - 'astrology', - 'astronaut', - 'astronomy', - 'astute', - 'atlantic', - 'atlas', - 'atom', - 'atonable', - 'atop', - 'atrium', - 'atrocious', - 'atrophy', - 'attach', - 'attain', - 'attempt', - 'attendant', - 'attendee', - 'attention', - 'attentive', - 'attest', - 'attic', - 'attire', - 'attitude', - 'attractor', - 'attribute', - 'atypical', - 'auction', - 'audacious', - 'audacity', - 'audible', - 'audibly', - 'audience', - 'audio', - 'audition', - 'augmented', - 'august', - 'authentic', - 'author', - 'autism', - 'autistic', - 'autograph', - 'automaker', - 'automated', - 'automatic', - 'autopilot', - 'available', - 'avalanche', - 'avatar', - 'avenge', - 'avenging', - 'avenue', - 'average', - 'aversion', - 'avert', - 'aviation', - 'aviator', - 'avid', - 'avoid', - 'await', - 'awaken', - 'award', - 'aware', - 'awhile', - 'awkward', - 'awning', - 'awoke', - 'awry', - 'axis', - 'babble', - 'babbling', - 'babied', - 'baboon', - 'backache', - 'backboard', - 'backboned', - 'backdrop', - 'backed', - 'backer', - 'backfield', - 'backfire', - 'backhand', - 'backing', - 'backlands', - 'backlash', - 'backless', - 'backlight', - 'backlit', - 'backlog', - 'backpack', - 'backpedal', - 'backrest', - 'backroom', - 'backshift', - 'backside', - 'backslid', - 'backspace', - 'backspin', - 'backstab', - 'backstage', - 'backtalk', - 'backtrack', - 'backup', - 'backward', - 'backwash', - 'backwater', - 'backyard', - 'bacon', - 'bacteria', - 'bacterium', - 'badass', - 'badge', - 'badland', - 'badly', - 'badness', - 'baffle', - 'baffling', - 'bagel', - 'bagful', - 'baggage', - 'bagged', - 'baggie', - 'bagginess', - 'bagging', - 'baggy', - 'bagpipe', - 'baguette', - 'baked', - 'bakery', - 'bakeshop', - 'baking', - 'balance', - 'balancing', - 'balcony', - 'balmy', - 'balsamic', - 'bamboo', - 'banana', - 'banish', - 'banister', - 'banjo', - 'bankable', - 'bankbook', - 'banked', - 'banker', - 'banking', - 'banknote', - 'bankroll', - 'banner', - 'bannister', - 'banshee', - 'banter', - 'barbecue', - 'barbed', - 'barbell', - 'barber', - 'barcode', - 'barge', - 'bargraph', - 'barista', - 'baritone', - 'barley', - 'barmaid', - 'barman', - 'barn', - 'barometer', - 'barrack', - 'barracuda', - 'barrel', - 'barrette', - 'barricade', - 'barrier', - 'barstool', - 'bartender', - 'barterer', - 'bash', - 'basically', - 'basics', - 'basil', - 'basin', - 'basis', - 'basket', - 'batboy', - 'batch', - 'bath', - 'baton', - 'bats', - 'battalion', - 'battered', - 'battering', - 'battery', - 'batting', - 'battle', - 'bauble', - 'bazooka', - 'blabber', - 'bladder', - 'blade', - 'blah', - 'blame', - 'blaming', - 'blanching', - 'blandness', - 'blank', - 'blaspheme', - 'blasphemy', - 'blast', - 'blatancy', - 'blatantly', - 'blazer', - 'blazing', - 'bleach', - 'bleak', - 'bleep', - 'blemish', - 'blend', - 'bless', - 'blighted', - 'blimp', - 'bling', - 'blinked', - 'blinker', - 'blinking', - 'blinks', - 'blip', - 'blissful', - 'blitz', - 'blizzard', - 'bloated', - 'bloating', - 'blob', - 'blog', - 'bloomers', - 'blooming', - 'blooper', - 'blot', - 'blouse', - 'blubber', - 'bluff', - 'bluish', - 'blunderer', - 'blunt', - 'blurb', - 'blurred', - 'blurry', - 'blurt', - 'blush', - 'blustery', - 'boaster', - 'boastful', - 'boasting', - 'boat', - 'bobbed', - 'bobbing', - 'bobble', - 'bobcat', - 'bobsled', - 'bobtail', - 'bodacious', - 'body', - 'bogged', - 'boggle', - 'bogus', - 'boil', - 'bok', - 'bolster', - 'bolt', - 'bonanza', - 'bonded', - 'bonding', - 'bondless', - 'boned', - 'bonehead', - 'boneless', - 'bonelike', - 'boney', - 'bonfire', - 'bonnet', - 'bonsai', - 'bonus', - 'bony', - 'boogeyman', - 'boogieman', - 'book', - 'boondocks', - 'booted', - 'booth', - 'bootie', - 'booting', - 'bootlace', - 'bootleg', - 'boots', - 'boozy', - 'borax', - 'boring', - 'borough', - 'borrower', - 'borrowing', - 'boss', - 'botanical', - 'botanist', - 'botany', - 'botch', - 'both', - 'bottle', - 'bottling', - 'bottom', - 'bounce', - 'bouncing', - 'bouncy', - 'bounding', - 'boundless', - 'bountiful', - 'bovine', - 'boxcar', - 'boxer', - 'boxing', - 'boxlike', - 'boxy', - 'breach', - 'breath', - 'breeches', - 'breeching', - 'breeder', - 'breeding', - 'breeze', - 'breezy', - 'brethren', - 'brewery', - 'brewing', - 'briar', - 'bribe', - 'brick', - 'bride', - 'bridged', - 'brigade', - 'bright', - 'brilliant', - 'brim', - 'bring', - 'brink', - 'brisket', - 'briskly', - 'briskness', - 'bristle', - 'brittle', - 'broadband', - 'broadcast', - 'broaden', - 'broadly', - 'broadness', - 'broadside', - 'broadways', - 'broiler', - 'broiling', - 'broken', - 'broker', - 'bronchial', - 'bronco', - 'bronze', - 'bronzing', - 'brook', - 'broom', - 'brought', - 'browbeat', - 'brownnose', - 'browse', - 'browsing', - 'bruising', - 'brunch', - 'brunette', - 'brunt', - 'brush', - 'brussels', - 'brute', - 'brutishly', - 'bubble', - 'bubbling', - 'bubbly', - 'buccaneer', - 'bucked', - 'bucket', - 'buckle', - 'buckshot', - 'buckskin', - 'bucktooth', - 'buckwheat', - 'buddhism', - 'buddhist', - 'budding', - 'buddy', - 'budget', - 'buffalo', - 'buffed', - 'buffer', - 'buffing', - 'buffoon', - 'buggy', - 'bulb', - 'bulge', - 'bulginess', - 'bulgur', - 'bulk', - 'bulldog', - 'bulldozer', - 'bullfight', - 'bullfrog', - 'bullhorn', - 'bullion', - 'bullish', - 'bullpen', - 'bullring', - 'bullseye', - 'bullwhip', - 'bully', - 'bunch', - 'bundle', - 'bungee', - 'bunion', - 'bunkbed', - 'bunkhouse', - 'bunkmate', - 'bunny', - 'bunt', - 'busboy', - 'bush', - 'busily', - 'busload', - 'bust', - 'busybody', - 'buzz', - 'cabana', - 'cabbage', - 'cabbie', - 'cabdriver', - 'cable', - 'caboose', - 'cache', - 'cackle', - 'cacti', - 'cactus', - 'caddie', - 'caddy', - 'cadet', - 'cadillac', - 'cadmium', - 'cage', - 'cahoots', - 'cake', - 'calamari', - 'calamity', - 'calcium', - 'calculate', - 'calculus', - 'caliber', - 'calibrate', - 'calm', - 'caloric', - 'calorie', - 'calzone', - 'camcorder', - 'cameo', - 'camera', - 'camisole', - 'camper', - 'campfire', - 'camping', - 'campsite', - 'campus', - 'canal', - 'canary', - 'cancel', - 'candied', - 'candle', - 'candy', - 'cane', - 'canine', - 'canister', - 'cannabis', - 'canned', - 'canning', - 'cannon', - 'cannot', - 'canola', - 'canon', - 'canopener', - 'canopy', - 'canteen', - 'canyon', - 'capable', - 'capably', - 'capacity', - 'cape', - 'capillary', - 'capital', - 'capitol', - 'capped', - 'capricorn', - 'capsize', - 'capsule', - 'caption', - 'captivate', - 'captive', - 'captivity', - 'capture', - 'caramel', - 'carat', - 'caravan', - 'carbon', - 'cardboard', - 'carded', - 'cardiac', - 'cardigan', - 'cardinal', - 'cardstock', - 'carefully', - 'caregiver', - 'careless', - 'caress', - 'caretaker', - 'cargo', - 'caring', - 'carless', - 'carload', - 'carmaker', - 'carnage', - 'carnation', - 'carnival', - 'carnivore', - 'carol', - 'carpenter', - 'carpentry', - 'carpool', - 'carport', - 'carried', - 'carrot', - 'carrousel', - 'carry', - 'cartel', - 'cartload', - 'carton', - 'cartoon', - 'cartridge', - 'cartwheel', - 'carve', - 'carving', - 'carwash', - 'cascade', - 'case', - 'cash', - 'casing', - 'casino', - 'casket', - 'cassette', - 'casually', - 'casualty', - 'catacomb', - 'catalog', - 'catalyst', - 'catalyze', - 'catapult', - 'cataract', - 'catatonic', - 'catcall', - 'catchable', - 'catcher', - 'catching', - 'catchy', - 'caterer', - 'catering', - 'catfight', - 'catfish', - 'cathedral', - 'cathouse', - 'catlike', - 'catnap', - 'catnip', - 'catsup', - 'cattail', - 'cattishly', - 'cattle', - 'catty', - 'catwalk', - 'caucasian', - 'caucus', - 'causal', - 'causation', - 'cause', - 'causing', - 'cauterize', - 'caution', - 'cautious', - 'cavalier', - 'cavalry', - 'caviar', - 'cavity', - 'cedar', - 'celery', - 'celestial', - 'celibacy', - 'celibate', - 'celtic', - 'cement', - 'census', - 'ceramics', - 'ceremony', - 'certainly', - 'certainty', - 'certified', - 'certify', - 'cesarean', - 'cesspool', - 'chafe', - 'chaffing', - 'chain', - 'chair', - 'chalice', - 'challenge', - 'chamber', - 'chamomile', - 'champion', - 'chance', - 'change', - 'channel', - 'chant', - 'chaos', - 'chaperone', - 'chaplain', - 'chapped', - 'chaps', - 'chapter', - 'character', - 'charbroil', - 'charcoal', - 'charger', - 'charging', - 'chariot', - 'charity', - 'charm', - 'charred', - 'charter', - 'charting', - 'chase', - 'chasing', - 'chaste', - 'chastise', - 'chastity', - 'chatroom', - 'chatter', - 'chatting', - 'chatty', - 'cheating', - 'cheddar', - 'cheek', - 'cheer', - 'cheese', - 'cheesy', - 'chef', - 'chemicals', - 'chemist', - 'chemo', - 'cherisher', - 'cherub', - 'chess', - 'chest', - 'chevron', - 'chevy', - 'chewable', - 'chewer', - 'chewing', - 'chewy', - 'chief', - 'chihuahua', - 'childcare', - 'childhood', - 'childish', - 'childless', - 'childlike', - 'chili', - 'chill', - 'chimp', - 'chip', - 'chirping', - 'chirpy', - 'chitchat', - 'chivalry', - 'chive', - 'chloride', - 'chlorine', - 'choice', - 'chokehold', - 'choking', - 'chomp', - 'chooser', - 'choosing', - 'choosy', - 'chop', - 'chosen', - 'chowder', - 'chowtime', - 'chrome', - 'chubby', - 'chuck', - 'chug', - 'chummy', - 'chump', - 'chunk', - 'churn', - 'chute', - 'cider', - 'cilantro', - 'cinch', - 'cinema', - 'cinnamon', - 'circle', - 'circling', - 'circular', - 'circulate', - 'circus', - 'citable', - 'citadel', - 'citation', - 'citizen', - 'citric', - 'citrus', - 'city', - 'civic', - 'civil', - 'clad', - 'claim', - 'clambake', - 'clammy', - 'clamor', - 'clamp', - 'clamshell', - 'clang', - 'clanking', - 'clapped', - 'clapper', - 'clapping', - 'clarify', - 'clarinet', - 'clarity', - 'clash', - 'clasp', - 'class', - 'clatter', - 'clause', - 'clavicle', - 'claw', - 'clay', - 'clean', - 'clear', - 'cleat', - 'cleaver', - 'cleft', - 'clench', - 'clergyman', - 'clerical', - 'clerk', - 'clever', - 'clicker', - 'client', - 'climate', - 'climatic', - 'cling', - 'clinic', - 'clinking', - 'clip', - 'clique', - 'cloak', - 'clobber', - 'clock', - 'clone', - 'cloning', - 'closable', - 'closure', - 'clothes', - 'clothing', - 'cloud', - 'clover', - 'clubbed', - 'clubbing', - 'clubhouse', - 'clump', - 'clumsily', - 'clumsy', - 'clunky', - 'clustered', - 'clutch', - 'clutter', - 'coach', - 'coagulant', - 'coastal', - 'coaster', - 'coasting', - 'coastland', - 'coastline', - 'coat', - 'coauthor', - 'cobalt', - 'cobbler', - 'cobweb', - 'cocoa', - 'coconut', - 'cod', - 'coeditor', - 'coerce', - 'coexist', - 'coffee', - 'cofounder', - 'cognition', - 'cognitive', - 'cogwheel', - 'coherence', - 'coherent', - 'cohesive', - 'coil', - 'coke', - 'cola', - 'cold', - 'coleslaw', - 'coliseum', - 'collage', - 'collapse', - 'collar', - 'collected', - 'collector', - 'collide', - 'collie', - 'collision', - 'colonial', - 'colonist', - 'colonize', - 'colony', - 'colossal', - 'colt', - 'coma', - 'come', - 'comfort', - 'comfy', - 'comic', - 'coming', - 'comma', - 'commence', - 'commend', - 'comment', - 'commerce', - 'commode', - 'commodity', - 'commodore', - 'common', - 'commotion', - 'commute', - 'commuting', - 'compacted', - 'compacter', - 'compactly', - 'compactor', - 'companion', - 'company', - 'compare', - 'compel', - 'compile', - 'comply', - 'component', - 'composed', - 'composer', - 'composite', - 'compost', - 'composure', - 'compound', - 'compress', - 'comprised', - 'computer', - 'computing', - 'comrade', - 'concave', - 'conceal', - 'conceded', - 'concept', - 'concerned', - 'concert', - 'conch', - 'concierge', - 'concise', - 'conclude', - 'concrete', - 'concur', - 'condense', - 'condiment', - 'condition', - 'condone', - 'conducive', - 'conductor', - 'conduit', - 'cone', - 'confess', - 'confetti', - 'confidant', - 'confident', - 'confider', - 'confiding', - 'configure', - 'confined', - 'confining', - 'confirm', - 'conflict', - 'conform', - 'confound', - 'confront', - 'confused', - 'confusing', - 'confusion', - 'congenial', - 'congested', - 'congrats', - 'congress', - 'conical', - 'conjoined', - 'conjure', - 'conjuror', - 'connected', - 'connector', - 'consensus', - 'consent', - 'console', - 'consoling', - 'consonant', - 'constable', - 'constant', - 'constrain', - 'constrict', - 'construct', - 'consult', - 'consumer', - 'consuming', - 'contact', - 'container', - 'contempt', - 'contend', - 'contented', - 'contently', - 'contents', - 'contest', - 'context', - 'contort', - 'contour', - 'contrite', - 'control', - 'contusion', - 'convene', - 'convent', - 'copartner', - 'cope', - 'copied', - 'copier', - 'copilot', - 'coping', - 'copious', - 'copper', - 'copy', - 'coral', - 'cork', - 'cornball', - 'cornbread', - 'corncob', - 'cornea', - 'corned', - 'corner', - 'cornfield', - 'cornflake', - 'cornhusk', - 'cornmeal', - 'cornstalk', - 'corny', - 'coronary', - 'coroner', - 'corporal', - 'corporate', - 'corral', - 'correct', - 'corridor', - 'corrode', - 'corroding', - 'corrosive', - 'corsage', - 'corset', - 'cortex', - 'cosigner', - 'cosmetics', - 'cosmic', - 'cosmos', - 'cosponsor', - 'cost', - 'cottage', - 'cotton', - 'couch', - 'cough', - 'could', - 'countable', - 'countdown', - 'counting', - 'countless', - 'country', - 'county', - 'courier', - 'covenant', - 'cover', - 'coveted', - 'coveting', - 'coyness', - 'cozily', - 'coziness', - 'cozy', - 'crabbing', - 'crabgrass', - 'crablike', - 'crabmeat', - 'cradle', - 'cradling', - 'crafter', - 'craftily', - 'craftsman', - 'craftwork', - 'crafty', - 'cramp', - 'cranberry', - 'crane', - 'cranial', - 'cranium', - 'crank', - 'crate', - 'crave', - 'craving', - 'crawfish', - 'crawlers', - 'crawling', - 'crayfish', - 'crayon', - 'crazed', - 'crazily', - 'craziness', - 'crazy', - 'creamed', - 'creamer', - 'creamlike', - 'crease', - 'creasing', - 'creatable', - 'create', - 'creation', - 'creative', - 'creature', - 'credible', - 'credibly', - 'credit', - 'creed', - 'creme', - 'creole', - 'crepe', - 'crept', - 'crescent', - 'crested', - 'cresting', - 'crestless', - 'crevice', - 'crewless', - 'crewman', - 'crewmate', - 'crib', - 'cricket', - 'cried', - 'crier', - 'crimp', - 'crimson', - 'cringe', - 'cringing', - 'crinkle', - 'crinkly', - 'crisped', - 'crisping', - 'crisply', - 'crispness', - 'crispy', - 'criteria', - 'critter', - 'croak', - 'crock', - 'crook', - 'croon', - 'crop', - 'cross', - 'crouch', - 'crouton', - 'crowbar', - 'crowd', - 'crown', - 'crucial', - 'crudely', - 'crudeness', - 'cruelly', - 'cruelness', - 'cruelty', - 'crumb', - 'crummiest', - 'crummy', - 'crumpet', - 'crumpled', - 'cruncher', - 'crunching', - 'crunchy', - 'crusader', - 'crushable', - 'crushed', - 'crusher', - 'crushing', - 'crust', - 'crux', - 'crying', - 'cryptic', - 'crystal', - 'cubbyhole', - 'cube', - 'cubical', - 'cubicle', - 'cucumber', - 'cuddle', - 'cuddly', - 'cufflink', - 'culinary', - 'culminate', - 'culpable', - 'culprit', - 'cultivate', - 'cultural', - 'culture', - 'cupbearer', - 'cupcake', - 'cupid', - 'cupped', - 'cupping', - 'curable', - 'curator', - 'curdle', - 'cure', - 'curfew', - 'curing', - 'curled', - 'curler', - 'curliness', - 'curling', - 'curly', - 'curry', - 'curse', - 'cursive', - 'cursor', - 'curtain', - 'curtly', - 'curtsy', - 'curvature', - 'curve', - 'curvy', - 'cushy', - 'cusp', - 'cussed', - 'custard', - 'custodian', - 'custody', - 'customary', - 'customer', - 'customize', - 'customs', - 'cut', - 'cycle', - 'cyclic', - 'cycling', - 'cyclist', - 'cylinder', - 'cymbal', - 'cytoplasm', - 'cytoplast', - 'dab', - 'dad', - 'daffodil', - 'dagger', - 'daily', - 'daintily', - 'dainty', - 'dairy', - 'daisy', - 'dallying', - 'dance', - 'dancing', - 'dandelion', - 'dander', - 'dandruff', - 'dandy', - 'danger', - 'dangle', - 'dangling', - 'daredevil', - 'dares', - 'daringly', - 'darkened', - 'darkening', - 'darkish', - 'darkness', - 'darkroom', - 'darling', - 'darn', - 'dart', - 'darwinism', - 'dash', - 'dastardly', - 'data', - 'datebook', - 'dating', - 'daughter', - 'daunting', - 'dawdler', - 'dawn', - 'daybed', - 'daybreak', - 'daycare', - 'daydream', - 'daylight', - 'daylong', - 'dayroom', - 'daytime', - 'dazzler', - 'dazzling', - 'deacon', - 'deafening', - 'deafness', - 'dealer', - 'dealing', - 'dealmaker', - 'dealt', - 'dean', - 'debatable', - 'debate', - 'debating', - 'debit', - 'debrief', - 'debtless', - 'debtor', - 'debug', - 'debunk', - 'decade', - 'decaf', - 'decal', - 'decathlon', - 'decay', - 'deceased', - 'deceit', - 'deceiver', - 'deceiving', - 'december', - 'decency', - 'decent', - 'deception', - 'deceptive', - 'decibel', - 'decidable', - 'decimal', - 'decimeter', - 'decipher', - 'deck', - 'declared', - 'decline', - 'decode', - 'decompose', - 'decorated', - 'decorator', - 'decoy', - 'decrease', - 'decree', - 'dedicate', - 'dedicator', - 'deduce', - 'deduct', - 'deed', - 'deem', - 'deepen', - 'deeply', - 'deepness', - 'deface', - 'defacing', - 'defame', - 'default', - 'defeat', - 'defection', - 'defective', - 'defendant', - 'defender', - 'defense', - 'defensive', - 'deferral', - 'deferred', - 'defiance', - 'defiant', - 'defile', - 'defiling', - 'define', - 'definite', - 'deflate', - 'deflation', - 'deflator', - 'deflected', - 'deflector', - 'defog', - 'deforest', - 'defraud', - 'defrost', - 'deftly', - 'defuse', - 'defy', - 'degraded', - 'degrading', - 'degrease', - 'degree', - 'dehydrate', - 'deity', - 'dejected', - 'delay', - 'delegate', - 'delegator', - 'delete', - 'deletion', - 'delicacy', - 'delicate', - 'delicious', - 'delighted', - 'delirious', - 'delirium', - 'deliverer', - 'delivery', - 'delouse', - 'delta', - 'deluge', - 'delusion', - 'deluxe', - 'demanding', - 'demeaning', - 'demeanor', - 'demise', - 'democracy', - 'democrat', - 'demote', - 'demotion', - 'demystify', - 'denatured', - 'deniable', - 'denial', - 'denim', - 'denote', - 'dense', - 'density', - 'dental', - 'dentist', - 'denture', - 'deny', - 'deodorant', - 'deodorize', - 'departed', - 'departure', - 'depict', - 'deplete', - 'depletion', - 'deplored', - 'deploy', - 'deport', - 'depose', - 'depraved', - 'depravity', - 'deprecate', - 'depress', - 'deprive', - 'depth', - 'deputize', - 'deputy', - 'derail', - 'deranged', - 'derby', - 'derived', - 'desecrate', - 'deserve', - 'deserving', - 'designate', - 'designed', - 'designer', - 'designing', - 'deskbound', - 'desktop', - 'deskwork', - 'desolate', - 'despair', - 'despise', - 'despite', - 'destiny', - 'destitute', - 'destruct', - 'detached', - 'detail', - 'detection', - 'detective', - 'detector', - 'detention', - 'detergent', - 'detest', - 'detonate', - 'detonator', - 'detoxify', - 'detract', - 'deuce', - 'devalue', - 'deviancy', - 'deviant', - 'deviate', - 'deviation', - 'deviator', - 'device', - 'devious', - 'devotedly', - 'devotee', - 'devotion', - 'devourer', - 'devouring', - 'devoutly', - 'dexterity', - 'dexterous', - 'diabetes', - 'diabetic', - 'diabolic', - 'diagnoses', - 'diagnosis', - 'diagram', - 'dial', - 'diameter', - 'diaper', - 'diaphragm', - 'diary', - 'dice', - 'dicing', - 'dictate', - 'dictation', - 'dictator', - 'difficult', - 'diffused', - 'diffuser', - 'diffusion', - 'diffusive', - 'dig', - 'dilation', - 'diligence', - 'diligent', - 'dill', - 'dilute', - 'dime', - 'diminish', - 'dimly', - 'dimmed', - 'dimmer', - 'dimness', - 'dimple', - 'diner', - 'dingbat', - 'dinghy', - 'dinginess', - 'dingo', - 'dingy', - 'dining', - 'dinner', - 'diocese', - 'dioxide', - 'diploma', - 'dipped', - 'dipper', - 'dipping', - 'directed', - 'direction', - 'directive', - 'directly', - 'directory', - 'direness', - 'dirtiness', - 'disabled', - 'disagree', - 'disallow', - 'disarm', - 'disarray', - 'disaster', - 'disband', - 'disbelief', - 'disburse', - 'discard', - 'discern', - 'discharge', - 'disclose', - 'discolor', - 'discount', - 'discourse', - 'discover', - 'discuss', - 'disdain', - 'disengage', - 'disfigure', - 'disgrace', - 'dish', - 'disinfect', - 'disjoin', - 'disk', - 'dislike', - 'disliking', - 'dislocate', - 'dislodge', - 'disloyal', - 'dismantle', - 'dismay', - 'dismiss', - 'dismount', - 'disobey', - 'disorder', - 'disown', - 'disparate', - 'disparity', - 'dispatch', - 'dispense', - 'dispersal', - 'dispersed', - 'disperser', - 'displace', - 'display', - 'displease', - 'disposal', - 'dispose', - 'disprove', - 'dispute', - 'disregard', - 'disrupt', - 'dissuade', - 'distance', - 'distant', - 'distaste', - 'distill', - 'distinct', - 'distort', - 'distract', - 'distress', - 'district', - 'distrust', - 'ditch', - 'ditto', - 'ditzy', - 'dividable', - 'divided', - 'dividend', - 'dividers', - 'dividing', - 'divinely', - 'diving', - 'divinity', - 'divisible', - 'divisibly', - 'division', - 'divisive', - 'divorcee', - 'dizziness', - 'dizzy', - 'doable', - 'docile', - 'dock', - 'doctrine', - 'document', - 'dodge', - 'dodgy', - 'doily', - 'doing', - 'dole', - 'dollar', - 'dollhouse', - 'dollop', - 'dolly', - 'dolphin', - 'domain', - 'domelike', - 'domestic', - 'dominion', - 'dominoes', - 'donated', - 'donation', - 'donator', - 'donor', - 'donut', - 'doodle', - 'doorbell', - 'doorframe', - 'doorknob', - 'doorman', - 'doormat', - 'doornail', - 'doorpost', - 'doorstep', - 'doorstop', - 'doorway', - 'doozy', - 'dork', - 'dormitory', - 'dorsal', - 'dosage', - 'dose', - 'dotted', - 'doubling', - 'douche', - 'dove', - 'down', - 'dowry', - 'doze', - 'drab', - 'dragging', - 'dragonfly', - 'dragonish', - 'dragster', - 'drainable', - 'drainage', - 'drained', - 'drainer', - 'drainpipe', - 'dramatic', - 'dramatize', - 'drank', - 'drapery', - 'drastic', - 'draw', - 'dreaded', - 'dreadful', - 'dreadlock', - 'dreamboat', - 'dreamily', - 'dreamland', - 'dreamless', - 'dreamlike', - 'dreamt', - 'dreamy', - 'drearily', - 'dreary', - 'drench', - 'dress', - 'drew', - 'dribble', - 'dried', - 'drier', - 'drift', - 'driller', - 'drilling', - 'drinkable', - 'drinking', - 'dripping', - 'drippy', - 'drivable', - 'driven', - 'driver', - 'driveway', - 'driving', - 'drizzle', - 'drizzly', - 'drone', - 'drool', - 'droop', - 'drop-down', - 'dropbox', - 'dropkick', - 'droplet', - 'dropout', - 'dropper', - 'drove', - 'drown', - 'drowsily', - 'drudge', - 'drum', - 'dry', - 'dubbed', - 'dubiously', - 'duchess', - 'duckbill', - 'ducking', - 'duckling', - 'ducktail', - 'ducky', - 'duct', - 'dude', - 'duffel', - 'dugout', - 'duh', - 'duke', - 'duller', - 'dullness', - 'duly', - 'dumping', - 'dumpling', - 'dumpster', - 'duo', - 'dupe', - 'duplex', - 'duplicate', - 'duplicity', - 'durable', - 'durably', - 'duration', - 'duress', - 'during', - 'dusk', - 'dust', - 'dutiful', - 'duty', - 'duvet', - 'dwarf', - 'dweeb', - 'dwelled', - 'dweller', - 'dwelling', - 'dwindle', - 'dwindling', - 'dynamic', - 'dynamite', - 'dynasty', - 'dyslexia', - 'dyslexic', - 'each', - 'eagle', - 'earache', - 'eardrum', - 'earflap', - 'earful', - 'earlobe', - 'early', - 'earmark', - 'earmuff', - 'earphone', - 'earpiece', - 'earplugs', - 'earring', - 'earshot', - 'earthen', - 'earthlike', - 'earthling', - 'earthly', - 'earthworm', - 'earthy', - 'earwig', - 'easeful', - 'easel', - 'easiest', - 'easily', - 'easiness', - 'easing', - 'eastbound', - 'eastcoast', - 'easter', - 'eastward', - 'eatable', - 'eaten', - 'eatery', - 'eating', - 'eats', - 'ebay', - 'ebony', - 'ebook', - 'ecard', - 'eccentric', - 'echo', - 'eclair', - 'eclipse', - 'ecologist', - 'ecology', - 'economic', - 'economist', - 'economy', - 'ecosphere', - 'ecosystem', - 'edge', - 'edginess', - 'edging', - 'edgy', - 'edition', - 'editor', - 'educated', - 'education', - 'educator', - 'eel', - 'effective', - 'effects', - 'efficient', - 'effort', - 'eggbeater', - 'egging', - 'eggnog', - 'eggplant', - 'eggshell', - 'egomaniac', - 'egotism', - 'egotistic', - 'either', - 'eject', - 'elaborate', - 'elastic', - 'elated', - 'elbow', - 'eldercare', - 'elderly', - 'eldest', - 'electable', - 'election', - 'elective', - 'elephant', - 'elevate', - 'elevating', - 'elevation', - 'elevator', - 'eleven', - 'elf', - 'eligible', - 'eligibly', - 'eliminate', - 'elite', - 'elitism', - 'elixir', - 'elk', - 'ellipse', - 'elliptic', - 'elm', - 'elongated', - 'elope', - 'eloquence', - 'eloquent', - 'elsewhere', - 'elude', - 'elusive', - 'elves', - 'email', - 'embargo', - 'embark', - 'embassy', - 'embattled', - 'embellish', - 'ember', - 'embezzle', - 'emblaze', - 'emblem', - 'embody', - 'embolism', - 'emboss', - 'embroider', - 'emcee', - 'emerald', - 'emergency', - 'emission', - 'emit', - 'emote', - 'emoticon', - 'emotion', - 'empathic', - 'empathy', - 'emperor', - 'emphases', - 'emphasis', - 'emphasize', - 'emphatic', - 'empirical', - 'employed', - 'employee', - 'employer', - 'emporium', - 'empower', - 'emptier', - 'emptiness', - 'empty', - 'emu', - 'enable', - 'enactment', - 'enamel', - 'enchanted', - 'enchilada', - 'encircle', - 'enclose', - 'enclosure', - 'encode', - 'encore', - 'encounter', - 'encourage', - 'encroach', - 'encrust', - 'encrypt', - 'endanger', - 'endeared', - 'endearing', - 'ended', - 'ending', - 'endless', - 'endnote', - 'endocrine', - 'endorphin', - 'endorse', - 'endowment', - 'endpoint', - 'endurable', - 'endurance', - 'enduring', - 'energetic', - 'energize', - 'energy', - 'enforced', - 'enforcer', - 'engaged', - 'engaging', - 'engine', - 'engorge', - 'engraved', - 'engraver', - 'engraving', - 'engross', - 'engulf', - 'enhance', - 'enigmatic', - 'enjoyable', - 'enjoyably', - 'enjoyer', - 'enjoying', - 'enjoyment', - 'enlarged', - 'enlarging', - 'enlighten', - 'enlisted', - 'enquirer', - 'enrage', - 'enrich', - 'enroll', - 'enslave', - 'ensnare', - 'ensure', - 'entail', - 'entangled', - 'entering', - 'entertain', - 'enticing', - 'entire', - 'entitle', - 'entity', - 'entomb', - 'entourage', - 'entrap', - 'entree', - 'entrench', - 'entrust', - 'entryway', - 'entwine', - 'enunciate', - 'envelope', - 'enviable', - 'enviably', - 'envious', - 'envision', - 'envoy', - 'envy', - 'enzyme', - 'epic', - 'epidemic', - 'epidermal', - 'epidermis', - 'epidural', - 'epilepsy', - 'epileptic', - 'epilogue', - 'epiphany', - 'episode', - 'equal', - 'equate', - 'equation', - 'equator', - 'equinox', - 'equipment', - 'equity', - 'equivocal', - 'eradicate', - 'erasable', - 'erased', - 'eraser', - 'erasure', - 'ergonomic', - 'errand', - 'errant', - 'erratic', - 'error', - 'erupt', - 'escalate', - 'escalator', - 'escapable', - 'escapade', - 'escapist', - 'escargot', - 'eskimo', - 'esophagus', - 'espionage', - 'espresso', - 'esquire', - 'essay', - 'essence', - 'essential', - 'establish', - 'estate', - 'esteemed', - 'estimate', - 'estimator', - 'estranged', - 'estrogen', - 'etching', - 'eternal', - 'eternity', - 'ethanol', - 'ether', - 'ethically', - 'ethics', - 'euphemism', - 'evacuate', - 'evacuee', - 'evade', - 'evaluate', - 'evaluator', - 'evaporate', - 'evasion', - 'evasive', - 'even', - 'everglade', - 'evergreen', - 'everybody', - 'everyday', - 'everyone', - 'evict', - 'evidence', - 'evident', - 'evil', - 'evoke', - 'evolution', - 'evolve', - 'exact', - 'exalted', - 'example', - 'excavate', - 'excavator', - 'exceeding', - 'exception', - 'excess', - 'exchange', - 'excitable', - 'exciting', - 'exclaim', - 'exclude', - 'excluding', - 'exclusion', - 'exclusive', - 'excretion', - 'excretory', - 'excursion', - 'excusable', - 'excusably', - 'excuse', - 'exemplary', - 'exemplify', - 'exemption', - 'exerciser', - 'exert', - 'exes', - 'exfoliate', - 'exhale', - 'exhaust', - 'exhume', - 'exile', - 'existing', - 'exit', - 'exodus', - 'exonerate', - 'exorcism', - 'exorcist', - 'expand', - 'expanse', - 'expansion', - 'expansive', - 'expectant', - 'expedited', - 'expediter', - 'expel', - 'expend', - 'expenses', - 'expensive', - 'expert', - 'expire', - 'expiring', - 'explain', - 'expletive', - 'explicit', - 'explode', - 'exploit', - 'explore', - 'exploring', - 'exponent', - 'exporter', - 'exposable', - 'expose', - 'exposure', - 'express', - 'expulsion', - 'exquisite', - 'extended', - 'extending', - 'extent', - 'extenuate', - 'exterior', - 'external', - 'extinct', - 'extortion', - 'extradite', - 'extras', - 'extrovert', - 'extrude', - 'extruding', - 'exuberant', - 'fable', - 'fabric', - 'fabulous', - 'facebook', - 'facecloth', - 'facedown', - 'faceless', - 'facelift', - 'faceplate', - 'faceted', - 'facial', - 'facility', - 'facing', - 'facsimile', - 'faction', - 'factoid', - 'factor', - 'factsheet', - 'factual', - 'faculty', - 'fade', - 'fading', - 'failing', - 'falcon', - 'fall', - 'false', - 'falsify', - 'fame', - 'familiar', - 'family', - 'famine', - 'famished', - 'fanatic', - 'fancied', - 'fanciness', - 'fancy', - 'fanfare', - 'fang', - 'fanning', - 'fantasize', - 'fantastic', - 'fantasy', - 'fascism', - 'fastball', - 'faster', - 'fasting', - 'fastness', - 'faucet', - 'favorable', - 'favorably', - 'favored', - 'favoring', - 'favorite', - 'fax', - 'feast', - 'federal', - 'fedora', - 'feeble', - 'feed', - 'feel', - 'feisty', - 'feline', - 'felt-tip', - 'feminine', - 'feminism', - 'feminist', - 'feminize', - 'femur', - 'fence', - 'fencing', - 'fender', - 'ferment', - 'fernlike', - 'ferocious', - 'ferocity', - 'ferret', - 'ferris', - 'ferry', - 'fervor', - 'fester', - 'festival', - 'festive', - 'festivity', - 'fetal', - 'fetch', - 'fever', - 'fiber', - 'fiction', - 'fiddle', - 'fiddling', - 'fidelity', - 'fidgeting', - 'fidgety', - 'fifteen', - 'fifth', - 'fiftieth', - 'fifty', - 'figment', - 'figure', - 'figurine', - 'filing', - 'filled', - 'filler', - 'filling', - 'film', - 'filter', - 'filth', - 'filtrate', - 'finale', - 'finalist', - 'finalize', - 'finally', - 'finance', - 'financial', - 'finch', - 'fineness', - 'finer', - 'finicky', - 'finished', - 'finisher', - 'finishing', - 'finite', - 'finless', - 'finlike', - 'fiscally', - 'fit', - 'five', - 'flaccid', - 'flagman', - 'flagpole', - 'flagship', - 'flagstick', - 'flagstone', - 'flail', - 'flakily', - 'flaky', - 'flame', - 'flammable', - 'flanked', - 'flanking', - 'flannels', - 'flap', - 'flaring', - 'flashback', - 'flashbulb', - 'flashcard', - 'flashily', - 'flashing', - 'flashy', - 'flask', - 'flatbed', - 'flatfoot', - 'flatly', - 'flatness', - 'flatten', - 'flattered', - 'flatterer', - 'flattery', - 'flattop', - 'flatware', - 'flatworm', - 'flavored', - 'flavorful', - 'flavoring', - 'flaxseed', - 'fled', - 'fleshed', - 'fleshy', - 'flick', - 'flier', - 'flight', - 'flinch', - 'fling', - 'flint', - 'flip', - 'flirt', - 'float', - 'flock', - 'flogging', - 'flop', - 'floral', - 'florist', - 'floss', - 'flounder', - 'flyable', - 'flyaway', - 'flyer', - 'flying', - 'flyover', - 'flypaper', - 'foam', - 'foe', - 'fog', - 'foil', - 'folic', - 'folk', - 'follicle', - 'follow', - 'fondling', - 'fondly', - 'fondness', - 'fondue', - 'font', - 'food', - 'fool', - 'footage', - 'football', - 'footbath', - 'footboard', - 'footer', - 'footgear', - 'foothill', - 'foothold', - 'footing', - 'footless', - 'footman', - 'footnote', - 'footpad', - 'footpath', - 'footprint', - 'footrest', - 'footsie', - 'footsore', - 'footwear', - 'footwork', - 'fossil', - 'foster', - 'founder', - 'founding', - 'fountain', - 'fox', - 'foyer', - 'fraction', - 'fracture', - 'fragile', - 'fragility', - 'fragment', - 'fragrance', - 'fragrant', - 'frail', - 'frame', - 'framing', - 'frantic', - 'fraternal', - 'frayed', - 'fraying', - 'frays', - 'freckled', - 'freckles', - 'freebase', - 'freebee', - 'freebie', - 'freedom', - 'freefall', - 'freehand', - 'freeing', - 'freeload', - 'freely', - 'freemason', - 'freeness', - 'freestyle', - 'freeware', - 'freeway', - 'freewill', - 'freezable', - 'freezing', - 'freight', - 'french', - 'frenzied', - 'frenzy', - 'frequency', - 'frequent', - 'fresh', - 'fretful', - 'fretted', - 'friction', - 'friday', - 'fridge', - 'fried', - 'friend', - 'frighten', - 'frightful', - 'frigidity', - 'frigidly', - 'frill', - 'fringe', - 'frisbee', - 'frisk', - 'fritter', - 'frivolous', - 'frolic', - 'from', - 'front', - 'frostbite', - 'frosted', - 'frostily', - 'frosting', - 'frostlike', - 'frosty', - 'froth', - 'frown', - 'frozen', - 'fructose', - 'frugality', - 'frugally', - 'fruit', - 'frustrate', - 'frying', - 'gab', - 'gaffe', - 'gag', - 'gainfully', - 'gaining', - 'gains', - 'gala', - 'gallantly', - 'galleria', - 'gallery', - 'galley', - 'gallon', - 'gallows', - 'gallstone', - 'galore', - 'galvanize', - 'gambling', - 'game', - 'gaming', - 'gamma', - 'gander', - 'gangly', - 'gangrene', - 'gangway', - 'gap', - 'garage', - 'garbage', - 'garden', - 'gargle', - 'garland', - 'garlic', - 'garment', - 'garnet', - 'garnish', - 'garter', - 'gas', - 'gatherer', - 'gathering', - 'gating', - 'gauging', - 'gauntlet', - 'gauze', - 'gave', - 'gawk', - 'gazing', - 'gear', - 'gecko', - 'geek', - 'geiger', - 'gem', - 'gender', - 'generic', - 'generous', - 'genetics', - 'genre', - 'gentile', - 'gentleman', - 'gently', - 'gents', - 'geography', - 'geologic', - 'geologist', - 'geology', - 'geometric', - 'geometry', - 'geranium', - 'gerbil', - 'geriatric', - 'germicide', - 'germinate', - 'germless', - 'germproof', - 'gestate', - 'gestation', - 'gesture', - 'getaway', - 'getting', - 'getup', - 'giant', - 'gibberish', - 'giblet', - 'giddily', - 'giddiness', - 'giddy', - 'gift', - 'gigabyte', - 'gigahertz', - 'gigantic', - 'giggle', - 'giggling', - 'giggly', - 'gigolo', - 'gilled', - 'gills', - 'gimmick', - 'girdle', - 'giveaway', - 'given', - 'giver', - 'giving', - 'gizmo', - 'gizzard', - 'glacial', - 'glacier', - 'glade', - 'gladiator', - 'gladly', - 'glamorous', - 'glamour', - 'glance', - 'glancing', - 'glandular', - 'glare', - 'glaring', - 'glass', - 'glaucoma', - 'glazing', - 'gleaming', - 'gleeful', - 'glider', - 'gliding', - 'glimmer', - 'glimpse', - 'glisten', - 'glitch', - 'glitter', - 'glitzy', - 'gloater', - 'gloating', - 'gloomily', - 'gloomy', - 'glorified', - 'glorifier', - 'glorify', - 'glorious', - 'glory', - 'gloss', - 'glove', - 'glowing', - 'glowworm', - 'glucose', - 'glue', - 'gluten', - 'glutinous', - 'glutton', - 'gnarly', - 'gnat', - 'goal', - 'goatskin', - 'goes', - 'goggles', - 'going', - 'goldfish', - 'goldmine', - 'goldsmith', - 'golf', - 'goliath', - 'gonad', - 'gondola', - 'gone', - 'gong', - 'good', - 'gooey', - 'goofball', - 'goofiness', - 'goofy', - 'google', - 'goon', - 'gopher', - 'gore', - 'gorged', - 'gorgeous', - 'gory', - 'gosling', - 'gossip', - 'gothic', - 'gotten', - 'gout', - 'gown', - 'grab', - 'graceful', - 'graceless', - 'gracious', - 'gradation', - 'graded', - 'grader', - 'gradient', - 'grading', - 'gradually', - 'graduate', - 'graffiti', - 'grafted', - 'grafting', - 'grain', - 'granddad', - 'grandkid', - 'grandly', - 'grandma', - 'grandpa', - 'grandson', - 'granite', - 'granny', - 'granola', - 'grant', - 'granular', - 'grape', - 'graph', - 'grapple', - 'grappling', - 'grasp', - 'grass', - 'gratified', - 'gratify', - 'grating', - 'gratitude', - 'gratuity', - 'gravel', - 'graveness', - 'graves', - 'graveyard', - 'gravitate', - 'gravity', - 'gravy', - 'gray', - 'grazing', - 'greasily', - 'greedily', - 'greedless', - 'greedy', - 'green', - 'greeter', - 'greeting', - 'grew', - 'greyhound', - 'grid', - 'grief', - 'grievance', - 'grieving', - 'grievous', - 'grill', - 'grimace', - 'grimacing', - 'grime', - 'griminess', - 'grimy', - 'grinch', - 'grinning', - 'grip', - 'gristle', - 'grit', - 'groggily', - 'groggy', - 'groin', - 'groom', - 'groove', - 'grooving', - 'groovy', - 'grope', - 'ground', - 'grouped', - 'grout', - 'grove', - 'grower', - 'growing', - 'growl', - 'grub', - 'grudge', - 'grudging', - 'grueling', - 'gruffly', - 'grumble', - 'grumbling', - 'grumbly', - 'grumpily', - 'grunge', - 'grunt', - 'guacamole', - 'guidable', - 'guidance', - 'guide', - 'guiding', - 'guileless', - 'guise', - 'gulf', - 'gullible', - 'gully', - 'gulp', - 'gumball', - 'gumdrop', - 'gumminess', - 'gumming', - 'gummy', - 'gurgle', - 'gurgling', - 'guru', - 'gush', - 'gusto', - 'gusty', - 'gutless', - 'guts', - 'gutter', - 'guy', - 'guzzler', - 'gyration', - 'habitable', - 'habitant', - 'habitat', - 'habitual', - 'hacked', - 'hacker', - 'hacking', - 'hacksaw', - 'had', - 'haggler', - 'haiku', - 'half', - 'halogen', - 'halt', - 'halved', - 'halves', - 'hamburger', - 'hamlet', - 'hammock', - 'hamper', - 'hamster', - 'hamstring', - 'handbag', - 'handball', - 'handbook', - 'handbrake', - 'handcart', - 'handclap', - 'handclasp', - 'handcraft', - 'handcuff', - 'handed', - 'handful', - 'handgrip', - 'handgun', - 'handheld', - 'handiness', - 'handiwork', - 'handlebar', - 'handled', - 'handler', - 'handling', - 'handmade', - 'handoff', - 'handpick', - 'handprint', - 'handrail', - 'handsaw', - 'handset', - 'handsfree', - 'handshake', - 'handstand', - 'handwash', - 'handwork', - 'handwoven', - 'handwrite', - 'handyman', - 'hangnail', - 'hangout', - 'hangover', - 'hangup', - 'hankering', - 'hankie', - 'hanky', - 'haphazard', - 'happening', - 'happier', - 'happiest', - 'happily', - 'happiness', - 'happy', - 'harbor', - 'hardcopy', - 'hardcore', - 'hardcover', - 'harddisk', - 'hardened', - 'hardener', - 'hardening', - 'hardhat', - 'hardhead', - 'hardiness', - 'hardly', - 'hardness', - 'hardship', - 'hardware', - 'hardwired', - 'hardwood', - 'hardy', - 'harmful', - 'harmless', - 'harmonica', - 'harmonics', - 'harmonize', - 'harmony', - 'harness', - 'harpist', - 'harsh', - 'harvest', - 'hash', - 'hassle', - 'haste', - 'hastily', - 'hastiness', - 'hasty', - 'hatbox', - 'hatchback', - 'hatchery', - 'hatchet', - 'hatching', - 'hatchling', - 'hate', - 'hatless', - 'hatred', - 'haunt', - 'haven', - 'hazard', - 'hazelnut', - 'hazily', - 'haziness', - 'hazing', - 'hazy', - 'headache', - 'headband', - 'headboard', - 'headcount', - 'headdress', - 'headed', - 'header', - 'headfirst', - 'headgear', - 'heading', - 'headlamp', - 'headless', - 'headlock', - 'headphone', - 'headpiece', - 'headrest', - 'headroom', - 'headscarf', - 'headset', - 'headsman', - 'headstand', - 'headstone', - 'headway', - 'headwear', - 'heap', - 'heat', - 'heave', - 'heavily', - 'heaviness', - 'heaving', - 'hedge', - 'hedging', - 'heftiness', - 'hefty', - 'helium', - 'helmet', - 'helper', - 'helpful', - 'helping', - 'helpless', - 'helpline', - 'hemlock', - 'hemstitch', - 'hence', - 'henchman', - 'henna', - 'herald', - 'herbal', - 'herbicide', - 'herbs', - 'heritage', - 'hermit', - 'heroics', - 'heroism', - 'herring', - 'herself', - 'hertz', - 'hesitancy', - 'hesitant', - 'hesitate', - 'hexagon', - 'hexagram', - 'hubcap', - 'huddle', - 'huddling', - 'huff', - 'hug', - 'hula', - 'hulk', - 'hull', - 'human', - 'humble', - 'humbling', - 'humbly', - 'humid', - 'humiliate', - 'humility', - 'humming', - 'hummus', - 'humongous', - 'humorist', - 'humorless', - 'humorous', - 'humpback', - 'humped', - 'humvee', - 'hunchback', - 'hundredth', - 'hunger', - 'hungrily', - 'hungry', - 'hunk', - 'hunter', - 'hunting', - 'huntress', - 'huntsman', - 'hurdle', - 'hurled', - 'hurler', - 'hurling', - 'hurray', - 'hurricane', - 'hurried', - 'hurry', - 'hurt', - 'husband', - 'hush', - 'husked', - 'huskiness', - 'hut', - 'hybrid', - 'hydrant', - 'hydrated', - 'hydration', - 'hydrogen', - 'hydroxide', - 'hyperlink', - 'hypertext', - 'hyphen', - 'hypnoses', - 'hypnosis', - 'hypnotic', - 'hypnotism', - 'hypnotist', - 'hypnotize', - 'hypocrisy', - 'hypocrite', - 'ibuprofen', - 'ice', - 'iciness', - 'icing', - 'icky', - 'icon', - 'icy', - 'idealism', - 'idealist', - 'idealize', - 'ideally', - 'idealness', - 'identical', - 'identify', - 'identity', - 'ideology', - 'idiocy', - 'idiom', - 'idly', - 'igloo', - 'ignition', - 'ignore', - 'iguana', - 'illicitly', - 'illusion', - 'illusive', - 'image', - 'imaginary', - 'imagines', - 'imaging', - 'imbecile', - 'imitate', - 'imitation', - 'immature', - 'immerse', - 'immersion', - 'imminent', - 'immobile', - 'immodest', - 'immorally', - 'immortal', - 'immovable', - 'immovably', - 'immunity', - 'immunize', - 'impaired', - 'impale', - 'impart', - 'impatient', - 'impeach', - 'impeding', - 'impending', - 'imperfect', - 'imperial', - 'impish', - 'implant', - 'implement', - 'implicate', - 'implicit', - 'implode', - 'implosion', - 'implosive', - 'imply', - 'impolite', - 'important', - 'importer', - 'impose', - 'imposing', - 'impotence', - 'impotency', - 'impotent', - 'impound', - 'imprecise', - 'imprint', - 'imprison', - 'impromptu', - 'improper', - 'improve', - 'improving', - 'improvise', - 'imprudent', - 'impulse', - 'impulsive', - 'impure', - 'impurity', - 'iodine', - 'iodize', - 'ion', - 'ipad', - 'iphone', - 'ipod', - 'irate', - 'irk', - 'iron', - 'irregular', - 'irrigate', - 'irritable', - 'irritably', - 'irritant', - 'irritate', - 'islamic', - 'islamist', - 'isolated', - 'isolating', - 'isolation', - 'isotope', - 'issue', - 'issuing', - 'italicize', - 'italics', - 'item', - 'itinerary', - 'itunes', - 'ivory', - 'ivy', - 'jab', - 'jackal', - 'jacket', - 'jackknife', - 'jackpot', - 'jailbird', - 'jailbreak', - 'jailer', - 'jailhouse', - 'jalapeno', - 'jam', - 'janitor', - 'january', - 'jargon', - 'jarring', - 'jasmine', - 'jaundice', - 'jaunt', - 'java', - 'jawed', - 'jawless', - 'jawline', - 'jaws', - 'jaybird', - 'jaywalker', - 'jazz', - 'jeep', - 'jeeringly', - 'jellied', - 'jelly', - 'jersey', - 'jester', - 'jet', - 'jiffy', - 'jigsaw', - 'jimmy', - 'jingle', - 'jingling', - 'jinx', - 'jitters', - 'jittery', - 'job', - 'jockey', - 'jockstrap', - 'jogger', - 'jogging', - 'john', - 'joining', - 'jokester', - 'jokingly', - 'jolliness', - 'jolly', - 'jolt', - 'jot', - 'jovial', - 'joyfully', - 'joylessly', - 'joyous', - 'joyride', - 'joystick', - 'jubilance', - 'jubilant', - 'judge', - 'judgingly', - 'judicial', - 'judiciary', - 'judo', - 'juggle', - 'juggling', - 'jugular', - 'juice', - 'juiciness', - 'juicy', - 'jujitsu', - 'jukebox', - 'july', - 'jumble', - 'jumbo', - 'jump', - 'junction', - 'juncture', - 'june', - 'junior', - 'juniper', - 'junkie', - 'junkman', - 'junkyard', - 'jurist', - 'juror', - 'jury', - 'justice', - 'justifier', - 'justify', - 'justly', - 'justness', - 'juvenile', - 'kabob', - 'kangaroo', - 'karaoke', - 'karate', - 'karma', - 'kebab', - 'keenly', - 'keenness', - 'keep', - 'keg', - 'kelp', - 'kennel', - 'kept', - 'kerchief', - 'kerosene', - 'kettle', - 'kick', - 'kiln', - 'kilobyte', - 'kilogram', - 'kilometer', - 'kilowatt', - 'kilt', - 'kimono', - 'kindle', - 'kindling', - 'kindly', - 'kindness', - 'kindred', - 'kinetic', - 'kinfolk', - 'king', - 'kinship', - 'kinsman', - 'kinswoman', - 'kissable', - 'kisser', - 'kissing', - 'kitchen', - 'kite', - 'kitten', - 'kitty', - 'kiwi', - 'kleenex', - 'knapsack', - 'knee', - 'knelt', - 'knickers', - 'knoll', - 'koala', - 'kooky', - 'kosher', - 'krypton', - 'kudos', - 'kung', - 'labored', - 'laborer', - 'laboring', - 'laborious', - 'labrador', - 'ladder', - 'ladies', - 'ladle', - 'ladybug', - 'ladylike', - 'lagged', - 'lagging', - 'lagoon', - 'lair', - 'lake', - 'lance', - 'landed', - 'landfall', - 'landfill', - 'landing', - 'landlady', - 'landless', - 'landline', - 'landlord', - 'landmark', - 'landmass', - 'landmine', - 'landowner', - 'landscape', - 'landside', - 'landslide', - 'language', - 'lankiness', - 'lanky', - 'lantern', - 'lapdog', - 'lapel', - 'lapped', - 'lapping', - 'laptop', - 'lard', - 'large', - 'lark', - 'lash', - 'lasso', - 'last', - 'latch', - 'late', - 'lather', - 'latitude', - 'latrine', - 'latter', - 'latticed', - 'launch', - 'launder', - 'laundry', - 'laurel', - 'lavender', - 'lavish', - 'laxative', - 'lazily', - 'laziness', - 'lazy', - 'lecturer', - 'left', - 'legacy', - 'legal', - 'legend', - 'legged', - 'leggings', - 'legible', - 'legibly', - 'legislate', - 'lego', - 'legroom', - 'legume', - 'legwarmer', - 'legwork', - 'lemon', - 'lend', - 'length', - 'lens', - 'lent', - 'leotard', - 'lesser', - 'letdown', - 'lethargic', - 'lethargy', - 'letter', - 'lettuce', - 'level', - 'leverage', - 'levers', - 'levitate', - 'levitator', - 'liability', - 'liable', - 'liberty', - 'librarian', - 'library', - 'licking', - 'licorice', - 'lid', - 'life', - 'lifter', - 'lifting', - 'liftoff', - 'ligament', - 'likely', - 'likeness', - 'likewise', - 'liking', - 'lilac', - 'lilly', - 'lily', - 'limb', - 'limeade', - 'limelight', - 'limes', - 'limit', - 'limping', - 'limpness', - 'line', - 'lingo', - 'linguini', - 'linguist', - 'lining', - 'linked', - 'linoleum', - 'linseed', - 'lint', - 'lion', - 'lip', - 'liquefy', - 'liqueur', - 'liquid', - 'lisp', - 'list', - 'litigate', - 'litigator', - 'litmus', - 'litter', - 'little', - 'livable', - 'lived', - 'lively', - 'liver', - 'livestock', - 'lividly', - 'living', - 'lizard', - 'lubricant', - 'lubricate', - 'lucid', - 'luckily', - 'luckiness', - 'luckless', - 'lucrative', - 'ludicrous', - 'lugged', - 'lukewarm', - 'lullaby', - 'lumber', - 'luminance', - 'luminous', - 'lumpiness', - 'lumping', - 'lumpish', - 'lunacy', - 'lunar', - 'lunchbox', - 'luncheon', - 'lunchroom', - 'lunchtime', - 'lung', - 'lurch', - 'lure', - 'luridness', - 'lurk', - 'lushly', - 'lushness', - 'luster', - 'lustfully', - 'lustily', - 'lustiness', - 'lustrous', - 'lusty', - 'luxurious', - 'luxury', - 'lying', - 'lyrically', - 'lyricism', - 'lyricist', - 'lyrics', - 'macarena', - 'macaroni', - 'macaw', - 'mace', - 'machine', - 'machinist', - 'magazine', - 'magenta', - 'maggot', - 'magical', - 'magician', - 'magma', - 'magnesium', - 'magnetic', - 'magnetism', - 'magnetize', - 'magnifier', - 'magnify', - 'magnitude', - 'magnolia', - 'mahogany', - 'maimed', - 'majestic', - 'majesty', - 'majorette', - 'majority', - 'makeover', - 'maker', - 'makeshift', - 'making', - 'malformed', - 'malt', - 'mama', - 'mammal', - 'mammary', - 'mammogram', - 'manager', - 'managing', - 'manatee', - 'mandarin', - 'mandate', - 'mandatory', - 'mandolin', - 'manger', - 'mangle', - 'mango', - 'mangy', - 'manhandle', - 'manhole', - 'manhood', - 'manhunt', - 'manicotti', - 'manicure', - 'manifesto', - 'manila', - 'mankind', - 'manlike', - 'manliness', - 'manly', - 'manmade', - 'manned', - 'mannish', - 'manor', - 'manpower', - 'mantis', - 'mantra', - 'manual', - 'many', - 'map', - 'marathon', - 'marauding', - 'marbled', - 'marbles', - 'marbling', - 'march', - 'mardi', - 'margarine', - 'margarita', - 'margin', - 'marigold', - 'marina', - 'marine', - 'marital', - 'maritime', - 'marlin', - 'marmalade', - 'maroon', - 'married', - 'marrow', - 'marry', - 'marshland', - 'marshy', - 'marsupial', - 'marvelous', - 'marxism', - 'mascot', - 'masculine', - 'mashed', - 'mashing', - 'massager', - 'masses', - 'massive', - 'mastiff', - 'matador', - 'matchbook', - 'matchbox', - 'matcher', - 'matching', - 'matchless', - 'material', - 'maternal', - 'maternity', - 'math', - 'mating', - 'matriarch', - 'matrimony', - 'matrix', - 'matron', - 'matted', - 'matter', - 'maturely', - 'maturing', - 'maturity', - 'mauve', - 'maverick', - 'maximize', - 'maximum', - 'maybe', - 'mayday', - 'mayflower', - 'moaner', - 'moaning', - 'mobile', - 'mobility', - 'mobilize', - 'mobster', - 'mocha', - 'mocker', - 'mockup', - 'modified', - 'modify', - 'modular', - 'modulator', - 'module', - 'moisten', - 'moistness', - 'moisture', - 'molar', - 'molasses', - 'mold', - 'molecular', - 'molecule', - 'molehill', - 'mollusk', - 'mom', - 'monastery', - 'monday', - 'monetary', - 'monetize', - 'moneybags', - 'moneyless', - 'moneywise', - 'mongoose', - 'mongrel', - 'monitor', - 'monkhood', - 'monogamy', - 'monogram', - 'monologue', - 'monopoly', - 'monorail', - 'monotone', - 'monotype', - 'monoxide', - 'monsieur', - 'monsoon', - 'monstrous', - 'monthly', - 'monument', - 'moocher', - 'moodiness', - 'moody', - 'mooing', - 'moonbeam', - 'mooned', - 'moonlight', - 'moonlike', - 'moonlit', - 'moonrise', - 'moonscape', - 'moonshine', - 'moonstone', - 'moonwalk', - 'mop', - 'morale', - 'morality', - 'morally', - 'morbidity', - 'morbidly', - 'morphine', - 'morphing', - 'morse', - 'mortality', - 'mortally', - 'mortician', - 'mortified', - 'mortify', - 'mortuary', - 'mosaic', - 'mossy', - 'most', - 'mothball', - 'mothproof', - 'motion', - 'motivate', - 'motivator', - 'motive', - 'motocross', - 'motor', - 'motto', - 'mountable', - 'mountain', - 'mounted', - 'mounting', - 'mourner', - 'mournful', - 'mouse', - 'mousiness', - 'moustache', - 'mousy', - 'mouth', - 'movable', - 'move', - 'movie', - 'moving', - 'mower', - 'mowing', - 'much', - 'muck', - 'mud', - 'mug', - 'mulberry', - 'mulch', - 'mule', - 'mulled', - 'mullets', - 'multiple', - 'multiply', - 'multitask', - 'multitude', - 'mumble', - 'mumbling', - 'mumbo', - 'mummified', - 'mummify', - 'mummy', - 'mumps', - 'munchkin', - 'mundane', - 'municipal', - 'muppet', - 'mural', - 'murkiness', - 'murky', - 'murmuring', - 'muscular', - 'museum', - 'mushily', - 'mushiness', - 'mushroom', - 'mushy', - 'music', - 'musket', - 'muskiness', - 'musky', - 'mustang', - 'mustard', - 'muster', - 'mustiness', - 'musty', - 'mutable', - 'mutate', - 'mutation', - 'mute', - 'mutilated', - 'mutilator', - 'mutiny', - 'mutt', - 'mutual', - 'muzzle', - 'myself', - 'myspace', - 'mystified', - 'mystify', - 'myth', - 'nacho', - 'nag', - 'nail', - 'name', - 'naming', - 'nanny', - 'nanometer', - 'nape', - 'napkin', - 'napped', - 'napping', - 'nappy', - 'narrow', - 'nastily', - 'nastiness', - 'national', - 'native', - 'nativity', - 'natural', - 'nature', - 'naturist', - 'nautical', - 'navigate', - 'navigator', - 'navy', - 'nearby', - 'nearest', - 'nearly', - 'nearness', - 'neatly', - 'neatness', - 'nebula', - 'nebulizer', - 'nectar', - 'negate', - 'negation', - 'negative', - 'neglector', - 'negligee', - 'negligent', - 'negotiate', - 'nemeses', - 'nemesis', - 'neon', - 'nephew', - 'nerd', - 'nervous', - 'nervy', - 'nest', - 'net', - 'neurology', - 'neuron', - 'neurosis', - 'neurotic', - 'neuter', - 'neutron', - 'never', - 'next', - 'nibble', - 'nickname', - 'nicotine', - 'niece', - 'nifty', - 'nimble', - 'nimbly', - 'nineteen', - 'ninetieth', - 'ninja', - 'nintendo', - 'ninth', - 'nuclear', - 'nuclei', - 'nucleus', - 'nugget', - 'nullify', - 'number', - 'numbing', - 'numbly', - 'numbness', - 'numeral', - 'numerate', - 'numerator', - 'numeric', - 'numerous', - 'nuptials', - 'nursery', - 'nursing', - 'nurture', - 'nutcase', - 'nutlike', - 'nutmeg', - 'nutrient', - 'nutshell', - 'nuttiness', - 'nutty', - 'nuzzle', - 'nylon', - 'oaf', - 'oak', - 'oasis', - 'oat', - 'obedience', - 'obedient', - 'obituary', - 'object', - 'obligate', - 'obliged', - 'oblivion', - 'oblivious', - 'oblong', - 'obnoxious', - 'oboe', - 'obscure', - 'obscurity', - 'observant', - 'observer', - 'observing', - 'obsessed', - 'obsession', - 'obsessive', - 'obsolete', - 'obstacle', - 'obstinate', - 'obstruct', - 'obtain', - 'obtrusive', - 'obtuse', - 'obvious', - 'occultist', - 'occupancy', - 'occupant', - 'occupier', - 'occupy', - 'ocean', - 'ocelot', - 'octagon', - 'octane', - 'october', - 'octopus', - 'ogle', - 'oil', - 'oink', - 'ointment', - 'okay', - 'old', - 'olive', - 'olympics', - 'omega', - 'omen', - 'ominous', - 'omission', - 'omit', - 'omnivore', - 'onboard', - 'oncoming', - 'ongoing', - 'onion', - 'online', - 'onlooker', - 'only', - 'onscreen', - 'onset', - 'onshore', - 'onslaught', - 'onstage', - 'onto', - 'onward', - 'onyx', - 'oops', - 'ooze', - 'oozy', - 'opacity', - 'opal', - 'open', - 'operable', - 'operate', - 'operating', - 'operation', - 'operative', - 'operator', - 'opium', - 'opossum', - 'opponent', - 'oppose', - 'opposing', - 'opposite', - 'oppressed', - 'oppressor', - 'opt', - 'opulently', - 'osmosis', - 'other', - 'otter', - 'ouch', - 'ought', - 'ounce', - 'outage', - 'outback', - 'outbid', - 'outboard', - 'outbound', - 'outbreak', - 'outburst', - 'outcast', - 'outclass', - 'outcome', - 'outdated', - 'outdoors', - 'outer', - 'outfield', - 'outfit', - 'outflank', - 'outgoing', - 'outgrow', - 'outhouse', - 'outing', - 'outlast', - 'outlet', - 'outline', - 'outlook', - 'outlying', - 'outmatch', - 'outmost', - 'outnumber', - 'outplayed', - 'outpost', - 'outpour', - 'output', - 'outrage', - 'outrank', - 'outreach', - 'outright', - 'outscore', - 'outsell', - 'outshine', - 'outshoot', - 'outsider', - 'outskirts', - 'outsmart', - 'outsource', - 'outspoken', - 'outtakes', - 'outthink', - 'outward', - 'outweigh', - 'outwit', - 'oval', - 'ovary', - 'oven', - 'overact', - 'overall', - 'overarch', - 'overbid', - 'overbill', - 'overbite', - 'overblown', - 'overboard', - 'overbook', - 'overbuilt', - 'overcast', - 'overcoat', - 'overcome', - 'overcook', - 'overcrowd', - 'overdraft', - 'overdrawn', - 'overdress', - 'overdrive', - 'overdue', - 'overeager', - 'overeater', - 'overexert', - 'overfed', - 'overfeed', - 'overfill', - 'overflow', - 'overfull', - 'overgrown', - 'overhand', - 'overhang', - 'overhaul', - 'overhead', - 'overhear', - 'overheat', - 'overhung', - 'overjoyed', - 'overkill', - 'overlabor', - 'overlaid', - 'overlap', - 'overlay', - 'overload', - 'overlook', - 'overlord', - 'overlying', - 'overnight', - 'overpass', - 'overpay', - 'overplant', - 'overplay', - 'overpower', - 'overprice', - 'overrate', - 'overreach', - 'overreact', - 'override', - 'overripe', - 'overrule', - 'overrun', - 'overshoot', - 'overshot', - 'oversight', - 'oversized', - 'oversleep', - 'oversold', - 'overspend', - 'overstate', - 'overstay', - 'overstep', - 'overstock', - 'overstuff', - 'oversweet', - 'overtake', - 'overthrow', - 'overtime', - 'overtly', - 'overtone', - 'overture', - 'overturn', - 'overuse', - 'overvalue', - 'overview', - 'overwrite', - 'owl', - 'oxford', - 'oxidant', - 'oxidation', - 'oxidize', - 'oxidizing', - 'oxygen', - 'oxymoron', - 'oyster', - 'ozone', - 'paced', - 'pacemaker', - 'pacific', - 'pacifier', - 'pacifism', - 'pacifist', - 'pacify', - 'padded', - 'padding', - 'paddle', - 'paddling', - 'padlock', - 'pagan', - 'pager', - 'paging', - 'pajamas', - 'palace', - 'palatable', - 'palm', - 'palpable', - 'palpitate', - 'paltry', - 'pampered', - 'pamperer', - 'pampers', - 'pamphlet', - 'panama', - 'pancake', - 'pancreas', - 'panda', - 'pandemic', - 'pang', - 'panhandle', - 'panic', - 'panning', - 'panorama', - 'panoramic', - 'panther', - 'pantomime', - 'pantry', - 'pants', - 'pantyhose', - 'paparazzi', - 'papaya', - 'paper', - 'paprika', - 'papyrus', - 'parabola', - 'parachute', - 'parade', - 'paradox', - 'paragraph', - 'parakeet', - 'paralegal', - 'paralyses', - 'paralysis', - 'paralyze', - 'paramedic', - 'parameter', - 'paramount', - 'parasail', - 'parasite', - 'parasitic', - 'parcel', - 'parched', - 'parchment', - 'pardon', - 'parish', - 'parka', - 'parking', - 'parkway', - 'parlor', - 'parmesan', - 'parole', - 'parrot', - 'parsley', - 'parsnip', - 'partake', - 'parted', - 'parting', - 'partition', - 'partly', - 'partner', - 'partridge', - 'party', - 'passable', - 'passably', - 'passage', - 'passcode', - 'passenger', - 'passerby', - 'passing', - 'passion', - 'passive', - 'passivism', - 'passover', - 'passport', - 'password', - 'pasta', - 'pasted', - 'pastel', - 'pastime', - 'pastor', - 'pastrami', - 'pasture', - 'pasty', - 'patchwork', - 'patchy', - 'paternal', - 'paternity', - 'path', - 'patience', - 'patient', - 'patio', - 'patriarch', - 'patriot', - 'patrol', - 'patronage', - 'patronize', - 'pauper', - 'pavement', - 'paver', - 'pavestone', - 'pavilion', - 'paving', - 'pawing', - 'payable', - 'payback', - 'paycheck', - 'payday', - 'payee', - 'payer', - 'paying', - 'payment', - 'payphone', - 'payroll', - 'pebble', - 'pebbly', - 'pecan', - 'pectin', - 'peculiar', - 'peddling', - 'pediatric', - 'pedicure', - 'pedigree', - 'pedometer', - 'pegboard', - 'pelican', - 'pellet', - 'pelt', - 'pelvis', - 'penalize', - 'penalty', - 'pencil', - 'pendant', - 'pending', - 'penholder', - 'penknife', - 'pennant', - 'penniless', - 'penny', - 'penpal', - 'pension', - 'pentagon', - 'pentagram', - 'pep', - 'perceive', - 'percent', - 'perch', - 'percolate', - 'perennial', - 'perfected', - 'perfectly', - 'perfume', - 'periscope', - 'perish', - 'perjurer', - 'perjury', - 'perkiness', - 'perky', - 'perm', - 'peroxide', - 'perpetual', - 'perplexed', - 'persecute', - 'persevere', - 'persuaded', - 'persuader', - 'pesky', - 'peso', - 'pessimism', - 'pessimist', - 'pester', - 'pesticide', - 'petal', - 'petite', - 'petition', - 'petri', - 'petroleum', - 'petted', - 'petticoat', - 'pettiness', - 'petty', - 'petunia', - 'phantom', - 'phobia', - 'phoenix', - 'phonebook', - 'phoney', - 'phonics', - 'phoniness', - 'phony', - 'phosphate', - 'photo', - 'phrase', - 'phrasing', - 'placard', - 'placate', - 'placidly', - 'plank', - 'planner', - 'plant', - 'plasma', - 'plaster', - 'plastic', - 'plated', - 'platform', - 'plating', - 'platinum', - 'platonic', - 'platter', - 'platypus', - 'plausible', - 'plausibly', - 'playable', - 'playback', - 'player', - 'playful', - 'playgroup', - 'playhouse', - 'playing', - 'playlist', - 'playmaker', - 'playmate', - 'playoff', - 'playpen', - 'playroom', - 'playset', - 'plaything', - 'playtime', - 'plaza', - 'pleading', - 'pleat', - 'pledge', - 'plentiful', - 'plenty', - 'plethora', - 'plexiglas', - 'pliable', - 'plod', - 'plop', - 'plot', - 'plow', - 'ploy', - 'pluck', - 'plug', - 'plunder', - 'plunging', - 'plural', - 'plus', - 'plutonium', - 'plywood', - 'poach', - 'pod', - 'poem', - 'poet', - 'pogo', - 'pointed', - 'pointer', - 'pointing', - 'pointless', - 'pointy', - 'poise', - 'poison', - 'poker', - 'poking', - 'polar', - 'police', - 'policy', - 'polio', - 'polish', - 'politely', - 'polka', - 'polo', - 'polyester', - 'polygon', - 'polygraph', - 'polymer', - 'poncho', - 'pond', - 'pony', - 'popcorn', - 'pope', - 'poplar', - 'popper', - 'poppy', - 'popsicle', - 'populace', - 'popular', - 'populate', - 'porcupine', - 'pork', - 'porous', - 'porridge', - 'portable', - 'portal', - 'portfolio', - 'porthole', - 'portion', - 'portly', - 'portside', - 'poser', - 'posh', - 'posing', - 'possible', - 'possibly', - 'possum', - 'postage', - 'postal', - 'postbox', - 'postcard', - 'posted', - 'poster', - 'posting', - 'postnasal', - 'posture', - 'postwar', - 'pouch', - 'pounce', - 'pouncing', - 'pound', - 'pouring', - 'pout', - 'powdered', - 'powdering', - 'powdery', - 'power', - 'powwow', - 'pox', - 'praising', - 'prance', - 'prancing', - 'pranker', - 'prankish', - 'prankster', - 'prayer', - 'praying', - 'preacher', - 'preaching', - 'preachy', - 'preamble', - 'precinct', - 'precise', - 'precision', - 'precook', - 'precut', - 'predator', - 'predefine', - 'predict', - 'preface', - 'prefix', - 'preflight', - 'preformed', - 'pregame', - 'pregnancy', - 'pregnant', - 'preheated', - 'prelaunch', - 'prelaw', - 'prelude', - 'premiere', - 'premises', - 'premium', - 'prenatal', - 'preoccupy', - 'preorder', - 'prepaid', - 'prepay', - 'preplan', - 'preppy', - 'preschool', - 'prescribe', - 'preseason', - 'preset', - 'preshow', - 'president', - 'presoak', - 'press', - 'presume', - 'presuming', - 'preteen', - 'pretended', - 'pretender', - 'pretense', - 'pretext', - 'pretty', - 'pretzel', - 'prevail', - 'prevalent', - 'prevent', - 'preview', - 'previous', - 'prewar', - 'prewashed', - 'prideful', - 'pried', - 'primal', - 'primarily', - 'primary', - 'primate', - 'primer', - 'primp', - 'princess', - 'print', - 'prior', - 'prism', - 'prison', - 'prissy', - 'pristine', - 'privacy', - 'private', - 'privatize', - 'prize', - 'proactive', - 'probable', - 'probably', - 'probation', - 'probe', - 'probing', - 'probiotic', - 'problem', - 'procedure', - 'process', - 'proclaim', - 'procreate', - 'procurer', - 'prodigal', - 'prodigy', - 'produce', - 'product', - 'profane', - 'profanity', - 'professed', - 'professor', - 'profile', - 'profound', - 'profusely', - 'progeny', - 'prognosis', - 'program', - 'progress', - 'projector', - 'prologue', - 'prolonged', - 'promenade', - 'prominent', - 'promoter', - 'promotion', - 'prompter', - 'promptly', - 'prone', - 'prong', - 'pronounce', - 'pronto', - 'proofing', - 'proofread', - 'proofs', - 'propeller', - 'properly', - 'property', - 'proponent', - 'proposal', - 'propose', - 'props', - 'prorate', - 'protector', - 'protegee', - 'proton', - 'prototype', - 'protozoan', - 'protract', - 'protrude', - 'proud', - 'provable', - 'proved', - 'proven', - 'provided', - 'provider', - 'providing', - 'province', - 'proving', - 'provoke', - 'provoking', - 'provolone', - 'prowess', - 'prowler', - 'prowling', - 'proximity', - 'proxy', - 'prozac', - 'prude', - 'prudishly', - 'prune', - 'pruning', - 'pry', - 'psychic', - 'public', - 'publisher', - 'pucker', - 'pueblo', - 'pug', - 'pull', - 'pulmonary', - 'pulp', - 'pulsate', - 'pulse', - 'pulverize', - 'puma', - 'pumice', - 'pummel', - 'punch', - 'punctual', - 'punctuate', - 'punctured', - 'pungent', - 'punisher', - 'punk', - 'pupil', - 'puppet', - 'puppy', - 'purchase', - 'pureblood', - 'purebred', - 'purely', - 'pureness', - 'purgatory', - 'purge', - 'purging', - 'purifier', - 'purify', - 'purist', - 'puritan', - 'purity', - 'purple', - 'purplish', - 'purposely', - 'purr', - 'purse', - 'pursuable', - 'pursuant', - 'pursuit', - 'purveyor', - 'pushcart', - 'pushchair', - 'pusher', - 'pushiness', - 'pushing', - 'pushover', - 'pushpin', - 'pushup', - 'pushy', - 'putdown', - 'putt', - 'puzzle', - 'puzzling', - 'pyramid', - 'pyromania', - 'python', - 'quack', - 'quadrant', - 'quail', - 'quaintly', - 'quake', - 'quaking', - 'qualified', - 'qualifier', - 'qualify', - 'quality', - 'qualm', - 'quantum', - 'quarrel', - 'quarry', - 'quartered', - 'quarterly', - 'quarters', - 'quartet', - 'quench', - 'query', - 'quicken', - 'quickly', - 'quickness', - 'quicksand', - 'quickstep', - 'quiet', - 'quill', - 'quilt', - 'quintet', - 'quintuple', - 'quirk', - 'quit', - 'quiver', - 'quizzical', - 'quotable', - 'quotation', - 'quote', - 'rabid', - 'race', - 'racing', - 'racism', - 'rack', - 'racoon', - 'radar', - 'radial', - 'radiance', - 'radiantly', - 'radiated', - 'radiation', - 'radiator', - 'radio', - 'radish', - 'raffle', - 'raft', - 'rage', - 'ragged', - 'raging', - 'ragweed', - 'raider', - 'railcar', - 'railing', - 'railroad', - 'railway', - 'raisin', - 'rake', - 'raking', - 'rally', - 'ramble', - 'rambling', - 'ramp', - 'ramrod', - 'ranch', - 'rancidity', - 'random', - 'ranged', - 'ranger', - 'ranging', - 'ranked', - 'ranking', - 'ransack', - 'ranting', - 'rants', - 'rare', - 'rarity', - 'rascal', - 'rash', - 'rasping', - 'ravage', - 'raven', - 'ravine', - 'raving', - 'ravioli', - 'ravishing', - 'reabsorb', - 'reach', - 'reacquire', - 'reaction', - 'reactive', - 'reactor', - 'reaffirm', - 'ream', - 'reanalyze', - 'reappear', - 'reapply', - 'reappoint', - 'reapprove', - 'rearrange', - 'rearview', - 'reason', - 'reassign', - 'reassure', - 'reattach', - 'reawake', - 'rebalance', - 'rebate', - 'rebel', - 'rebirth', - 'reboot', - 'reborn', - 'rebound', - 'rebuff', - 'rebuild', - 'rebuilt', - 'reburial', - 'rebuttal', - 'recall', - 'recant', - 'recapture', - 'recast', - 'recede', - 'recent', - 'recess', - 'recharger', - 'recipient', - 'recital', - 'recite', - 'reckless', - 'reclaim', - 'recliner', - 'reclining', - 'recluse', - 'reclusive', - 'recognize', - 'recoil', - 'recollect', - 'recolor', - 'reconcile', - 'reconfirm', - 'reconvene', - 'recopy', - 'record', - 'recount', - 'recoup', - 'recovery', - 'recreate', - 'rectal', - 'rectangle', - 'rectified', - 'rectify', - 'recycled', - 'recycler', - 'recycling', - 'reemerge', - 'reenact', - 'reenter', - 'reentry', - 'reexamine', - 'referable', - 'referee', - 'reference', - 'refill', - 'refinance', - 'refined', - 'refinery', - 'refining', - 'refinish', - 'reflected', - 'reflector', - 'reflex', - 'reflux', - 'refocus', - 'refold', - 'reforest', - 'reformat', - 'reformed', - 'reformer', - 'reformist', - 'refract', - 'refrain', - 'refreeze', - 'refresh', - 'refried', - 'refueling', - 'refund', - 'refurbish', - 'refurnish', - 'refusal', - 'refuse', - 'refusing', - 'refutable', - 'refute', - 'regain', - 'regalia', - 'regally', - 'reggae', - 'regime', - 'region', - 'register', - 'registrar', - 'registry', - 'regress', - 'regretful', - 'regroup', - 'regular', - 'regulate', - 'regulator', - 'rehab', - 'reheat', - 'rehire', - 'rehydrate', - 'reimburse', - 'reissue', - 'reiterate', - 'rejoice', - 'rejoicing', - 'rejoin', - 'rekindle', - 'relapse', - 'relapsing', - 'relatable', - 'related', - 'relation', - 'relative', - 'relax', - 'relay', - 'relearn', - 'release', - 'relenting', - 'reliable', - 'reliably', - 'reliance', - 'reliant', - 'relic', - 'relieve', - 'relieving', - 'relight', - 'relish', - 'relive', - 'reload', - 'relocate', - 'relock', - 'reluctant', - 'rely', - 'remake', - 'remark', - 'remarry', - 'rematch', - 'remedial', - 'remedy', - 'remember', - 'reminder', - 'remindful', - 'remission', - 'remix', - 'remnant', - 'remodeler', - 'remold', - 'remorse', - 'remote', - 'removable', - 'removal', - 'removed', - 'remover', - 'removing', - 'rename', - 'renderer', - 'rendering', - 'rendition', - 'renegade', - 'renewable', - 'renewably', - 'renewal', - 'renewed', - 'renounce', - 'renovate', - 'renovator', - 'rentable', - 'rental', - 'rented', - 'renter', - 'reoccupy', - 'reoccur', - 'reopen', - 'reorder', - 'repackage', - 'repacking', - 'repaint', - 'repair', - 'repave', - 'repaying', - 'repayment', - 'repeal', - 'repeated', - 'repeater', - 'repent', - 'rephrase', - 'replace', - 'replay', - 'replica', - 'reply', - 'reporter', - 'repose', - 'repossess', - 'repost', - 'repressed', - 'reprimand', - 'reprint', - 'reprise', - 'reproach', - 'reprocess', - 'reproduce', - 'reprogram', - 'reps', - 'reptile', - 'reptilian', - 'repugnant', - 'repulsion', - 'repulsive', - 'repurpose', - 'reputable', - 'reputably', - 'request', - 'require', - 'requisite', - 'reroute', - 'rerun', - 'resale', - 'resample', - 'rescuer', - 'reseal', - 'research', - 'reselect', - 'reseller', - 'resemble', - 'resend', - 'resent', - 'reset', - 'reshape', - 'reshoot', - 'reshuffle', - 'residence', - 'residency', - 'resident', - 'residual', - 'residue', - 'resigned', - 'resilient', - 'resistant', - 'resisting', - 'resize', - 'resolute', - 'resolved', - 'resonant', - 'resonate', - 'resort', - 'resource', - 'respect', - 'resubmit', - 'result', - 'resume', - 'resupply', - 'resurface', - 'resurrect', - 'retail', - 'retainer', - 'retaining', - 'retake', - 'retaliate', - 'retention', - 'rethink', - 'retinal', - 'retired', - 'retiree', - 'retiring', - 'retold', - 'retool', - 'retorted', - 'retouch', - 'retrace', - 'retract', - 'retrain', - 'retread', - 'retreat', - 'retrial', - 'retrieval', - 'retriever', - 'retry', - 'return', - 'retying', - 'retype', - 'reunion', - 'reunite', - 'reusable', - 'reuse', - 'reveal', - 'reveler', - 'revenge', - 'revenue', - 'reverb', - 'revered', - 'reverence', - 'reverend', - 'reversal', - 'reverse', - 'reversing', - 'reversion', - 'revert', - 'revisable', - 'revise', - 'revision', - 'revisit', - 'revivable', - 'revival', - 'reviver', - 'reviving', - 'revocable', - 'revoke', - 'revolt', - 'revolver', - 'revolving', - 'reward', - 'rewash', - 'rewind', - 'rewire', - 'reword', - 'rework', - 'rewrap', - 'rewrite', - 'rhyme', - 'ribbon', - 'ribcage', - 'rice', - 'riches', - 'richly', - 'richness', - 'rickety', - 'ricotta', - 'riddance', - 'ridden', - 'ride', - 'riding', - 'rifling', - 'rift', - 'rigging', - 'rigid', - 'rigor', - 'rimless', - 'rimmed', - 'rind', - 'rink', - 'rinse', - 'rinsing', - 'riot', - 'ripcord', - 'ripeness', - 'ripening', - 'ripping', - 'ripple', - 'rippling', - 'riptide', - 'rise', - 'rising', - 'risk', - 'risotto', - 'ritalin', - 'ritzy', - 'rival', - 'riverbank', - 'riverbed', - 'riverboat', - 'riverside', - 'riveter', - 'riveting', - 'roamer', - 'roaming', - 'roast', - 'robbing', - 'robe', - 'robin', - 'robotics', - 'robust', - 'rockband', - 'rocker', - 'rocket', - 'rockfish', - 'rockiness', - 'rocking', - 'rocklike', - 'rockslide', - 'rockstar', - 'rocky', - 'rogue', - 'roman', - 'romp', - 'rope', - 'roping', - 'roster', - 'rosy', - 'rotten', - 'rotting', - 'rotunda', - 'roulette', - 'rounding', - 'roundish', - 'roundness', - 'roundup', - 'roundworm', - 'routine', - 'routing', - 'rover', - 'roving', - 'royal', - 'rubbed', - 'rubber', - 'rubbing', - 'rubble', - 'rubdown', - 'ruby', - 'ruckus', - 'rudder', - 'rug', - 'ruined', - 'rule', - 'rumble', - 'rumbling', - 'rummage', - 'rumor', - 'runaround', - 'rundown', - 'runner', - 'running', - 'runny', - 'runt', - 'runway', - 'rupture', - 'rural', - 'ruse', - 'rush', - 'rust', - 'rut', - 'sabbath', - 'sabotage', - 'sacrament', - 'sacred', - 'sacrifice', - 'sadden', - 'saddlebag', - 'saddled', - 'saddling', - 'sadly', - 'sadness', - 'safari', - 'safeguard', - 'safehouse', - 'safely', - 'safeness', - 'saffron', - 'saga', - 'sage', - 'sagging', - 'saggy', - 'said', - 'saint', - 'sake', - 'salad', - 'salami', - 'salaried', - 'salary', - 'saline', - 'salon', - 'saloon', - 'salsa', - 'salt', - 'salutary', - 'salute', - 'salvage', - 'salvaging', - 'salvation', - 'same', - 'sample', - 'sampling', - 'sanction', - 'sanctity', - 'sanctuary', - 'sandal', - 'sandbag', - 'sandbank', - 'sandbar', - 'sandblast', - 'sandbox', - 'sanded', - 'sandfish', - 'sanding', - 'sandlot', - 'sandpaper', - 'sandpit', - 'sandstone', - 'sandstorm', - 'sandworm', - 'sandy', - 'sanitary', - 'sanitizer', - 'sank', - 'santa', - 'sapling', - 'sappiness', - 'sappy', - 'sarcasm', - 'sarcastic', - 'sardine', - 'sash', - 'sasquatch', - 'sassy', - 'satchel', - 'satiable', - 'satin', - 'satirical', - 'satisfied', - 'satisfy', - 'saturate', - 'saturday', - 'sauciness', - 'saucy', - 'sauna', - 'savage', - 'savanna', - 'saved', - 'savings', - 'savior', - 'savor', - 'saxophone', - 'say', - 'scabbed', - 'scabby', - 'scalded', - 'scalding', - 'scale', - 'scaling', - 'scallion', - 'scallop', - 'scalping', - 'scam', - 'scandal', - 'scanner', - 'scanning', - 'scant', - 'scapegoat', - 'scarce', - 'scarcity', - 'scarecrow', - 'scared', - 'scarf', - 'scarily', - 'scariness', - 'scarring', - 'scary', - 'scavenger', - 'scenic', - 'schedule', - 'schematic', - 'scheme', - 'scheming', - 'schilling', - 'schnapps', - 'scholar', - 'science', - 'scientist', - 'scion', - 'scoff', - 'scolding', - 'scone', - 'scoop', - 'scooter', - 'scope', - 'scorch', - 'scorebook', - 'scorecard', - 'scored', - 'scoreless', - 'scorer', - 'scoring', - 'scorn', - 'scorpion', - 'scotch', - 'scoundrel', - 'scoured', - 'scouring', - 'scouting', - 'scouts', - 'scowling', - 'scrabble', - 'scraggly', - 'scrambled', - 'scrambler', - 'scrap', - 'scratch', - 'scrawny', - 'screen', - 'scribble', - 'scribe', - 'scribing', - 'scrimmage', - 'script', - 'scroll', - 'scrooge', - 'scrounger', - 'scrubbed', - 'scrubber', - 'scruffy', - 'scrunch', - 'scrutiny', - 'scuba', - 'scuff', - 'sculptor', - 'sculpture', - 'scurvy', - 'scuttle', - 'secluded', - 'secluding', - 'seclusion', - 'second', - 'secrecy', - 'secret', - 'sectional', - 'sector', - 'secular', - 'securely', - 'security', - 'sedan', - 'sedate', - 'sedation', - 'sedative', - 'sediment', - 'seduce', - 'seducing', - 'segment', - 'seismic', - 'seizing', - 'seldom', - 'selected', - 'selection', - 'selective', - 'selector', - 'self', - 'seltzer', - 'semantic', - 'semester', - 'semicolon', - 'semifinal', - 'seminar', - 'semisoft', - 'semisweet', - 'senate', - 'senator', - 'send', - 'senior', - 'senorita', - 'sensation', - 'sensitive', - 'sensitize', - 'sensually', - 'sensuous', - 'sepia', - 'september', - 'septic', - 'septum', - 'sequel', - 'sequence', - 'sequester', - 'series', - 'sermon', - 'serotonin', - 'serpent', - 'serrated', - 'serve', - 'service', - 'serving', - 'sesame', - 'sessions', - 'setback', - 'setting', - 'settle', - 'settling', - 'setup', - 'sevenfold', - 'seventeen', - 'seventh', - 'seventy', - 'severity', - 'shabby', - 'shack', - 'shaded', - 'shadily', - 'shadiness', - 'shading', - 'shadow', - 'shady', - 'shaft', - 'shakable', - 'shakily', - 'shakiness', - 'shaking', - 'shaky', - 'shale', - 'shallot', - 'shallow', - 'shame', - 'shampoo', - 'shamrock', - 'shank', - 'shanty', - 'shape', - 'shaping', - 'share', - 'sharpener', - 'sharper', - 'sharpie', - 'sharply', - 'sharpness', - 'shawl', - 'sheath', - 'shed', - 'sheep', - 'sheet', - 'shelf', - 'shell', - 'shelter', - 'shelve', - 'shelving', - 'sherry', - 'shield', - 'shifter', - 'shifting', - 'shiftless', - 'shifty', - 'shimmer', - 'shimmy', - 'shindig', - 'shine', - 'shingle', - 'shininess', - 'shining', - 'shiny', - 'ship', - 'shirt', - 'shivering', - 'shock', - 'shone', - 'shoplift', - 'shopper', - 'shopping', - 'shoptalk', - 'shore', - 'shortage', - 'shortcake', - 'shortcut', - 'shorten', - 'shorter', - 'shorthand', - 'shortlist', - 'shortly', - 'shortness', - 'shorts', - 'shortwave', - 'shorty', - 'shout', - 'shove', - 'showbiz', - 'showcase', - 'showdown', - 'shower', - 'showgirl', - 'showing', - 'showman', - 'shown', - 'showoff', - 'showpiece', - 'showplace', - 'showroom', - 'showy', - 'shrank', - 'shrapnel', - 'shredder', - 'shredding', - 'shrewdly', - 'shriek', - 'shrill', - 'shrimp', - 'shrine', - 'shrink', - 'shrivel', - 'shrouded', - 'shrubbery', - 'shrubs', - 'shrug', - 'shrunk', - 'shucking', - 'shudder', - 'shuffle', - 'shuffling', - 'shun', - 'shush', - 'shut', - 'shy', - 'siamese', - 'siberian', - 'sibling', - 'siding', - 'sierra', - 'siesta', - 'sift', - 'sighing', - 'silenced', - 'silencer', - 'silent', - 'silica', - 'silicon', - 'silk', - 'silliness', - 'silly', - 'silo', - 'silt', - 'silver', - 'similarly', - 'simile', - 'simmering', - 'simple', - 'simplify', - 'simply', - 'sincere', - 'sincerity', - 'singer', - 'singing', - 'single', - 'singular', - 'sinister', - 'sinless', - 'sinner', - 'sinuous', - 'sip', - 'siren', - 'sister', - 'sitcom', - 'sitter', - 'sitting', - 'situated', - 'situation', - 'sixfold', - 'sixteen', - 'sixth', - 'sixties', - 'sixtieth', - 'sixtyfold', - 'sizable', - 'sizably', - 'size', - 'sizing', - 'sizzle', - 'sizzling', - 'skater', - 'skating', - 'skedaddle', - 'skeletal', - 'skeleton', - 'skeptic', - 'sketch', - 'skewed', - 'skewer', - 'skid', - 'skied', - 'skier', - 'skies', - 'skiing', - 'skilled', - 'skillet', - 'skillful', - 'skimmed', - 'skimmer', - 'skimming', - 'skimpily', - 'skincare', - 'skinhead', - 'skinless', - 'skinning', - 'skinny', - 'skintight', - 'skipper', - 'skipping', - 'skirmish', - 'skirt', - 'skittle', - 'skydiver', - 'skylight', - 'skyline', - 'skype', - 'skyrocket', - 'skyward', - 'slab', - 'slacked', - 'slacker', - 'slacking', - 'slackness', - 'slacks', - 'slain', - 'slam', - 'slander', - 'slang', - 'slapping', - 'slapstick', - 'slashed', - 'slashing', - 'slate', - 'slather', - 'slaw', - 'sled', - 'sleek', - 'sleep', - 'sleet', - 'sleeve', - 'slept', - 'sliceable', - 'sliced', - 'slicer', - 'slicing', - 'slick', - 'slider', - 'slideshow', - 'sliding', - 'slighted', - 'slighting', - 'slightly', - 'slimness', - 'slimy', - 'slinging', - 'slingshot', - 'slinky', - 'slip', - 'slit', - 'sliver', - 'slobbery', - 'slogan', - 'sloped', - 'sloping', - 'sloppily', - 'sloppy', - 'slot', - 'slouching', - 'slouchy', - 'sludge', - 'slug', - 'slum', - 'slurp', - 'slush', - 'sly', - 'small', - 'smartly', - 'smartness', - 'smasher', - 'smashing', - 'smashup', - 'smell', - 'smelting', - 'smile', - 'smilingly', - 'smirk', - 'smite', - 'smith', - 'smitten', - 'smock', - 'smog', - 'smoked', - 'smokeless', - 'smokiness', - 'smoking', - 'smoky', - 'smolder', - 'smooth', - 'smother', - 'smudge', - 'smudgy', - 'smuggler', - 'smuggling', - 'smugly', - 'smugness', - 'snack', - 'snagged', - 'snaking', - 'snap', - 'snare', - 'snarl', - 'snazzy', - 'sneak', - 'sneer', - 'sneeze', - 'sneezing', - 'snide', - 'sniff', - 'snippet', - 'snipping', - 'snitch', - 'snooper', - 'snooze', - 'snore', - 'snoring', - 'snorkel', - 'snort', - 'snout', - 'snowbird', - 'snowboard', - 'snowbound', - 'snowcap', - 'snowdrift', - 'snowdrop', - 'snowfall', - 'snowfield', - 'snowflake', - 'snowiness', - 'snowless', - 'snowman', - 'snowplow', - 'snowshoe', - 'snowstorm', - 'snowsuit', - 'snowy', - 'snub', - 'snuff', - 'snuggle', - 'snugly', - 'snugness', - 'speak', - 'spearfish', - 'spearhead', - 'spearman', - 'spearmint', - 'species', - 'specimen', - 'specked', - 'speckled', - 'specks', - 'spectacle', - 'spectator', - 'spectrum', - 'speculate', - 'speech', - 'speed', - 'spellbind', - 'speller', - 'spelling', - 'spendable', - 'spender', - 'spending', - 'spent', - 'spew', - 'sphere', - 'spherical', - 'sphinx', - 'spider', - 'spied', - 'spiffy', - 'spill', - 'spilt', - 'spinach', - 'spinal', - 'spindle', - 'spinner', - 'spinning', - 'spinout', - 'spinster', - 'spiny', - 'spiral', - 'spirited', - 'spiritism', - 'spirits', - 'spiritual', - 'splashed', - 'splashing', - 'splashy', - 'splatter', - 'spleen', - 'splendid', - 'splendor', - 'splice', - 'splicing', - 'splinter', - 'splotchy', - 'splurge', - 'spoilage', - 'spoiled', - 'spoiler', - 'spoiling', - 'spoils', - 'spoken', - 'spokesman', - 'sponge', - 'spongy', - 'sponsor', - 'spoof', - 'spookily', - 'spooky', - 'spool', - 'spoon', - 'spore', - 'sporting', - 'sports', - 'sporty', - 'spotless', - 'spotlight', - 'spotted', - 'spotter', - 'spotting', - 'spotty', - 'spousal', - 'spouse', - 'spout', - 'sprain', - 'sprang', - 'sprawl', - 'spray', - 'spree', - 'sprig', - 'spring', - 'sprinkled', - 'sprinkler', - 'sprint', - 'sprite', - 'sprout', - 'spruce', - 'sprung', - 'spry', - 'spud', - 'spur', - 'sputter', - 'spyglass', - 'squabble', - 'squad', - 'squall', - 'squander', - 'squash', - 'squatted', - 'squatter', - 'squatting', - 'squeak', - 'squealer', - 'squealing', - 'squeamish', - 'squeegee', - 'squeeze', - 'squeezing', - 'squid', - 'squiggle', - 'squiggly', - 'squint', - 'squire', - 'squirt', - 'squishier', - 'squishy', - 'stability', - 'stabilize', - 'stable', - 'stack', - 'stadium', - 'staff', - 'stage', - 'staging', - 'stagnant', - 'stagnate', - 'stainable', - 'stained', - 'staining', - 'stainless', - 'stalemate', - 'staleness', - 'stalling', - 'stallion', - 'stamina', - 'stammer', - 'stamp', - 'stand', - 'stank', - 'staple', - 'stapling', - 'starboard', - 'starch', - 'stardom', - 'stardust', - 'starfish', - 'stargazer', - 'staring', - 'stark', - 'starless', - 'starlet', - 'starlight', - 'starlit', - 'starring', - 'starry', - 'starship', - 'starter', - 'starting', - 'startle', - 'startling', - 'startup', - 'starved', - 'starving', - 'stash', - 'state', - 'static', - 'statistic', - 'statue', - 'stature', - 'status', - 'statute', - 'statutory', - 'staunch', - 'stays', - 'steadfast', - 'steadier', - 'steadily', - 'steadying', - 'steam', - 'steed', - 'steep', - 'steerable', - 'steering', - 'steersman', - 'stegosaur', - 'stellar', - 'stem', - 'stench', - 'stencil', - 'step', - 'stereo', - 'sterile', - 'sterility', - 'sterilize', - 'sterling', - 'sternness', - 'sternum', - 'stew', - 'stick', - 'stiffen', - 'stiffly', - 'stiffness', - 'stifle', - 'stifling', - 'stillness', - 'stilt', - 'stimulant', - 'stimulate', - 'stimuli', - 'stimulus', - 'stinger', - 'stingily', - 'stinging', - 'stingray', - 'stingy', - 'stinking', - 'stinky', - 'stipend', - 'stipulate', - 'stir', - 'stitch', - 'stock', - 'stoic', - 'stoke', - 'stole', - 'stomp', - 'stonewall', - 'stoneware', - 'stonework', - 'stoning', - 'stony', - 'stood', - 'stooge', - 'stool', - 'stoop', - 'stoplight', - 'stoppable', - 'stoppage', - 'stopped', - 'stopper', - 'stopping', - 'stopwatch', - 'storable', - 'storage', - 'storeroom', - 'storewide', - 'storm', - 'stout', - 'stove', - 'stowaway', - 'stowing', - 'straddle', - 'straggler', - 'strained', - 'strainer', - 'straining', - 'strangely', - 'stranger', - 'strangle', - 'strategic', - 'strategy', - 'stratus', - 'straw', - 'stray', - 'streak', - 'stream', - 'street', - 'strength', - 'strenuous', - 'strep', - 'stress', - 'stretch', - 'strewn', - 'stricken', - 'strict', - 'stride', - 'strife', - 'strike', - 'striking', - 'strive', - 'striving', - 'strobe', - 'strode', - 'stroller', - 'strongbox', - 'strongly', - 'strongman', - 'struck', - 'structure', - 'strudel', - 'struggle', - 'strum', - 'strung', - 'strut', - 'stubbed', - 'stubble', - 'stubbly', - 'stubborn', - 'stucco', - 'stuck', - 'student', - 'studied', - 'studio', - 'study', - 'stuffed', - 'stuffing', - 'stuffy', - 'stumble', - 'stumbling', - 'stump', - 'stung', - 'stunned', - 'stunner', - 'stunning', - 'stunt', - 'stupor', - 'sturdily', - 'sturdy', - 'styling', - 'stylishly', - 'stylist', - 'stylized', - 'stylus', - 'suave', - 'subarctic', - 'subatomic', - 'subdivide', - 'subdued', - 'subduing', - 'subfloor', - 'subgroup', - 'subheader', - 'subject', - 'sublease', - 'sublet', - 'sublevel', - 'sublime', - 'submarine', - 'submerge', - 'submersed', - 'submitter', - 'subpanel', - 'subpar', - 'subplot', - 'subprime', - 'subscribe', - 'subscript', - 'subsector', - 'subside', - 'subsiding', - 'subsidize', - 'subsidy', - 'subsoil', - 'subsonic', - 'substance', - 'subsystem', - 'subtext', - 'subtitle', - 'subtly', - 'subtotal', - 'subtract', - 'subtype', - 'suburb', - 'subway', - 'subwoofer', - 'subzero', - 'succulent', - 'such', - 'suction', - 'sudden', - 'sudoku', - 'suds', - 'sufferer', - 'suffering', - 'suffice', - 'suffix', - 'suffocate', - 'suffrage', - 'sugar', - 'suggest', - 'suing', - 'suitable', - 'suitably', - 'suitcase', - 'suitor', - 'sulfate', - 'sulfide', - 'sulfite', - 'sulfur', - 'sulk', - 'sullen', - 'sulphate', - 'sulphuric', - 'sultry', - 'superbowl', - 'superglue', - 'superhero', - 'superior', - 'superjet', - 'superman', - 'supermom', - 'supernova', - 'supervise', - 'supper', - 'supplier', - 'supply', - 'support', - 'supremacy', - 'supreme', - 'surcharge', - 'surely', - 'sureness', - 'surface', - 'surfacing', - 'surfboard', - 'surfer', - 'surgery', - 'surgical', - 'surging', - 'surname', - 'surpass', - 'surplus', - 'surprise', - 'surreal', - 'surrender', - 'surrogate', - 'surround', - 'survey', - 'survival', - 'survive', - 'surviving', - 'survivor', - 'sushi', - 'suspect', - 'suspend', - 'suspense', - 'sustained', - 'sustainer', - 'swab', - 'swaddling', - 'swagger', - 'swampland', - 'swan', - 'swapping', - 'swarm', - 'sway', - 'swear', - 'sweat', - 'sweep', - 'swell', - 'swept', - 'swerve', - 'swifter', - 'swiftly', - 'swiftness', - 'swimmable', - 'swimmer', - 'swimming', - 'swimsuit', - 'swimwear', - 'swinger', - 'swinging', - 'swipe', - 'swirl', - 'switch', - 'swivel', - 'swizzle', - 'swooned', - 'swoop', - 'swoosh', - 'swore', - 'sworn', - 'swung', - 'sycamore', - 'sympathy', - 'symphonic', - 'symphony', - 'symptom', - 'synapse', - 'syndrome', - 'synergy', - 'synopses', - 'synopsis', - 'synthesis', - 'synthetic', - 'syrup', - 'system', - 't-shirt', - 'tabasco', - 'tabby', - 'tableful', - 'tables', - 'tablet', - 'tableware', - 'tabloid', - 'tackiness', - 'tacking', - 'tackle', - 'tackling', - 'tacky', - 'taco', - 'tactful', - 'tactical', - 'tactics', - 'tactile', - 'tactless', - 'tadpole', - 'taekwondo', - 'tag', - 'tainted', - 'take', - 'taking', - 'talcum', - 'talisman', - 'tall', - 'talon', - 'tamale', - 'tameness', - 'tamer', - 'tamper', - 'tank', - 'tanned', - 'tannery', - 'tanning', - 'tantrum', - 'tapeless', - 'tapered', - 'tapering', - 'tapestry', - 'tapioca', - 'tapping', - 'taps', - 'tarantula', - 'target', - 'tarmac', - 'tarnish', - 'tarot', - 'tartar', - 'tartly', - 'tartness', - 'task', - 'tassel', - 'taste', - 'tastiness', - 'tasting', - 'tasty', - 'tattered', - 'tattle', - 'tattling', - 'tattoo', - 'taunt', - 'tavern', - 'thank', - 'that', - 'thaw', - 'theater', - 'theatrics', - 'thee', - 'theft', - 'theme', - 'theology', - 'theorize', - 'thermal', - 'thermos', - 'thesaurus', - 'these', - 'thesis', - 'thespian', - 'thicken', - 'thicket', - 'thickness', - 'thieving', - 'thievish', - 'thigh', - 'thimble', - 'thing', - 'think', - 'thinly', - 'thinner', - 'thinness', - 'thinning', - 'thirstily', - 'thirsting', - 'thirsty', - 'thirteen', - 'thirty', - 'thong', - 'thorn', - 'those', - 'thousand', - 'thrash', - 'thread', - 'threaten', - 'threefold', - 'thrift', - 'thrill', - 'thrive', - 'thriving', - 'throat', - 'throbbing', - 'throng', - 'throttle', - 'throwaway', - 'throwback', - 'thrower', - 'throwing', - 'thud', - 'thumb', - 'thumping', - 'thursday', - 'thus', - 'thwarting', - 'thyself', - 'tiara', - 'tibia', - 'tidal', - 'tidbit', - 'tidiness', - 'tidings', - 'tidy', - 'tiger', - 'tighten', - 'tightly', - 'tightness', - 'tightrope', - 'tightwad', - 'tigress', - 'tile', - 'tiling', - 'till', - 'tilt', - 'timid', - 'timing', - 'timothy', - 'tinderbox', - 'tinfoil', - 'tingle', - 'tingling', - 'tingly', - 'tinker', - 'tinkling', - 'tinsel', - 'tinsmith', - 'tint', - 'tinwork', - 'tiny', - 'tipoff', - 'tipped', - 'tipper', - 'tipping', - 'tiptoeing', - 'tiptop', - 'tiring', - 'tissue', - 'trace', - 'tracing', - 'track', - 'traction', - 'tractor', - 'trade', - 'trading', - 'tradition', - 'traffic', - 'tragedy', - 'trailing', - 'trailside', - 'train', - 'traitor', - 'trance', - 'tranquil', - 'transfer', - 'transform', - 'translate', - 'transpire', - 'transport', - 'transpose', - 'trapdoor', - 'trapeze', - 'trapezoid', - 'trapped', - 'trapper', - 'trapping', - 'traps', - 'trash', - 'travel', - 'traverse', - 'travesty', - 'tray', - 'treachery', - 'treading', - 'treadmill', - 'treason', - 'treat', - 'treble', - 'tree', - 'trekker', - 'tremble', - 'trembling', - 'tremor', - 'trench', - 'trend', - 'trespass', - 'triage', - 'trial', - 'triangle', - 'tribesman', - 'tribunal', - 'tribune', - 'tributary', - 'tribute', - 'triceps', - 'trickery', - 'trickily', - 'tricking', - 'trickle', - 'trickster', - 'tricky', - 'tricolor', - 'tricycle', - 'trident', - 'tried', - 'trifle', - 'trifocals', - 'trillion', - 'trilogy', - 'trimester', - 'trimmer', - 'trimming', - 'trimness', - 'trinity', - 'trio', - 'tripod', - 'tripping', - 'triumph', - 'trivial', - 'trodden', - 'trolling', - 'trombone', - 'trophy', - 'tropical', - 'tropics', - 'trouble', - 'troubling', - 'trough', - 'trousers', - 'trout', - 'trowel', - 'truce', - 'truck', - 'truffle', - 'trump', - 'trunks', - 'trustable', - 'trustee', - 'trustful', - 'trusting', - 'trustless', - 'truth', - 'try', - 'tubby', - 'tubeless', - 'tubular', - 'tucking', - 'tuesday', - 'tug', - 'tuition', - 'tulip', - 'tumble', - 'tumbling', - 'tummy', - 'turban', - 'turbine', - 'turbofan', - 'turbojet', - 'turbulent', - 'turf', - 'turkey', - 'turmoil', - 'turret', - 'turtle', - 'tusk', - 'tutor', - 'tutu', - 'tux', - 'tweak', - 'tweed', - 'tweet', - 'tweezers', - 'twelve', - 'twentieth', - 'twenty', - 'twerp', - 'twice', - 'twiddle', - 'twiddling', - 'twig', - 'twilight', - 'twine', - 'twins', - 'twirl', - 'twistable', - 'twisted', - 'twister', - 'twisting', - 'twisty', - 'twitch', - 'twitter', - 'tycoon', - 'tying', - 'tyke', - 'udder', - 'ultimate', - 'ultimatum', - 'ultra', - 'umbilical', - 'umbrella', - 'umpire', - 'unabashed', - 'unable', - 'unadorned', - 'unadvised', - 'unafraid', - 'unaired', - 'unaligned', - 'unaltered', - 'unarmored', - 'unashamed', - 'unaudited', - 'unawake', - 'unaware', - 'unbaked', - 'unbalance', - 'unbeaten', - 'unbend', - 'unbent', - 'unbiased', - 'unbitten', - 'unblended', - 'unblessed', - 'unblock', - 'unbolted', - 'unbounded', - 'unboxed', - 'unbraided', - 'unbridle', - 'unbroken', - 'unbuckled', - 'unbundle', - 'unburned', - 'unbutton', - 'uncanny', - 'uncapped', - 'uncaring', - 'uncertain', - 'unchain', - 'unchanged', - 'uncharted', - 'uncheck', - 'uncivil', - 'unclad', - 'unclaimed', - 'unclamped', - 'unclasp', - 'uncle', - 'unclip', - 'uncloak', - 'unclog', - 'unclothed', - 'uncoated', - 'uncoiled', - 'uncolored', - 'uncombed', - 'uncommon', - 'uncooked', - 'uncork', - 'uncorrupt', - 'uncounted', - 'uncouple', - 'uncouth', - 'uncover', - 'uncross', - 'uncrown', - 'uncrushed', - 'uncured', - 'uncurious', - 'uncurled', - 'uncut', - 'undamaged', - 'undated', - 'undaunted', - 'undead', - 'undecided', - 'undefined', - 'underage', - 'underarm', - 'undercoat', - 'undercook', - 'undercut', - 'underdog', - 'underdone', - 'underfed', - 'underfeed', - 'underfoot', - 'undergo', - 'undergrad', - 'underhand', - 'underline', - 'underling', - 'undermine', - 'undermost', - 'underpaid', - 'underpass', - 'underpay', - 'underrate', - 'undertake', - 'undertone', - 'undertook', - 'undertow', - 'underuse', - 'underwear', - 'underwent', - 'underwire', - 'undesired', - 'undiluted', - 'undivided', - 'undocked', - 'undoing', - 'undone', - 'undrafted', - 'undress', - 'undrilled', - 'undusted', - 'undying', - 'unearned', - 'unearth', - 'unease', - 'uneasily', - 'uneasy', - 'uneatable', - 'uneaten', - 'unedited', - 'unelected', - 'unending', - 'unengaged', - 'unenvied', - 'unequal', - 'unethical', - 'uneven', - 'unexpired', - 'unexposed', - 'unfailing', - 'unfair', - 'unfasten', - 'unfazed', - 'unfeeling', - 'unfiled', - 'unfilled', - 'unfitted', - 'unfitting', - 'unfixable', - 'unfixed', - 'unflawed', - 'unfocused', - 'unfold', - 'unfounded', - 'unframed', - 'unfreeze', - 'unfrosted', - 'unfrozen', - 'unfunded', - 'unglazed', - 'ungloved', - 'unglue', - 'ungodly', - 'ungraded', - 'ungreased', - 'unguarded', - 'unguided', - 'unhappily', - 'unhappy', - 'unharmed', - 'unhealthy', - 'unheard', - 'unhearing', - 'unheated', - 'unhelpful', - 'unhidden', - 'unhinge', - 'unhitched', - 'unholy', - 'unhook', - 'unicorn', - 'unicycle', - 'unified', - 'unifier', - 'uniformed', - 'uniformly', - 'unify', - 'unimpeded', - 'uninjured', - 'uninstall', - 'uninsured', - 'uninvited', - 'union', - 'uniquely', - 'unisexual', - 'unison', - 'unissued', - 'unit', - 'universal', - 'universe', - 'unjustly', - 'unkempt', - 'unkind', - 'unknotted', - 'unknowing', - 'unknown', - 'unlaced', - 'unlatch', - 'unlawful', - 'unleaded', - 'unlearned', - 'unleash', - 'unless', - 'unleveled', - 'unlighted', - 'unlikable', - 'unlimited', - 'unlined', - 'unlinked', - 'unlisted', - 'unlit', - 'unlivable', - 'unloaded', - 'unloader', - 'unlocked', - 'unlocking', - 'unlovable', - 'unloved', - 'unlovely', - 'unloving', - 'unluckily', - 'unlucky', - 'unmade', - 'unmanaged', - 'unmanned', - 'unmapped', - 'unmarked', - 'unmasked', - 'unmasking', - 'unmatched', - 'unmindful', - 'unmixable', - 'unmixed', - 'unmolded', - 'unmoral', - 'unmovable', - 'unmoved', - 'unmoving', - 'unnamable', - 'unnamed', - 'unnatural', - 'unneeded', - 'unnerve', - 'unnerving', - 'unnoticed', - 'unopened', - 'unopposed', - 'unpack', - 'unpadded', - 'unpaid', - 'unpainted', - 'unpaired', - 'unpaved', - 'unpeeled', - 'unpicked', - 'unpiloted', - 'unpinned', - 'unplanned', - 'unplanted', - 'unpleased', - 'unpledged', - 'unplowed', - 'unplug', - 'unpopular', - 'unproven', - 'unquote', - 'unranked', - 'unrated', - 'unraveled', - 'unreached', - 'unread', - 'unreal', - 'unreeling', - 'unrefined', - 'unrelated', - 'unrented', - 'unrest', - 'unretired', - 'unrevised', - 'unrigged', - 'unripe', - 'unrivaled', - 'unroasted', - 'unrobed', - 'unroll', - 'unruffled', - 'unruly', - 'unrushed', - 'unsaddle', - 'unsafe', - 'unsaid', - 'unsalted', - 'unsaved', - 'unsavory', - 'unscathed', - 'unscented', - 'unscrew', - 'unsealed', - 'unseated', - 'unsecured', - 'unseeing', - 'unseemly', - 'unseen', - 'unselect', - 'unselfish', - 'unsent', - 'unsettled', - 'unshackle', - 'unshaken', - 'unshaved', - 'unshaven', - 'unsheathe', - 'unshipped', - 'unsightly', - 'unsigned', - 'unskilled', - 'unsliced', - 'unsmooth', - 'unsnap', - 'unsocial', - 'unsoiled', - 'unsold', - 'unsolved', - 'unsorted', - 'unspoiled', - 'unspoken', - 'unstable', - 'unstaffed', - 'unstamped', - 'unsteady', - 'unsterile', - 'unstirred', - 'unstitch', - 'unstopped', - 'unstuck', - 'unstuffed', - 'unstylish', - 'unsubtle', - 'unsubtly', - 'unsuited', - 'unsure', - 'unsworn', - 'untagged', - 'untainted', - 'untaken', - 'untamed', - 'untangled', - 'untapped', - 'untaxed', - 'unthawed', - 'unthread', - 'untidy', - 'untie', - 'until', - 'untimed', - 'untimely', - 'untitled', - 'untoasted', - 'untold', - 'untouched', - 'untracked', - 'untrained', - 'untreated', - 'untried', - 'untrimmed', - 'untrue', - 'untruth', - 'unturned', - 'untwist', - 'untying', - 'unusable', - 'unused', - 'unusual', - 'unvalued', - 'unvaried', - 'unvarying', - 'unveiled', - 'unveiling', - 'unvented', - 'unviable', - 'unvisited', - 'unvocal', - 'unwanted', - 'unwarlike', - 'unwary', - 'unwashed', - 'unwatched', - 'unweave', - 'unwed', - 'unwelcome', - 'unwell', - 'unwieldy', - 'unwilling', - 'unwind', - 'unwired', - 'unwitting', - 'unwomanly', - 'unworldly', - 'unworn', - 'unworried', - 'unworthy', - 'unwound', - 'unwoven', - 'unwrapped', - 'unwritten', - 'unzip', - 'upbeat', - 'upchuck', - 'upcoming', - 'upcountry', - 'update', - 'upfront', - 'upgrade', - 'upheaval', - 'upheld', - 'uphill', - 'uphold', - 'uplifted', - 'uplifting', - 'upload', - 'upon', - 'upper', - 'upright', - 'uprising', - 'upriver', - 'uproar', - 'uproot', - 'upscale', - 'upside', - 'upstage', - 'upstairs', - 'upstart', - 'upstate', - 'upstream', - 'upstroke', - 'upswing', - 'uptake', - 'uptight', - 'uptown', - 'upturned', - 'upward', - 'upwind', - 'uranium', - 'urban', - 'urchin', - 'urethane', - 'urgency', - 'urgent', - 'urging', - 'urologist', - 'urology', - 'usable', - 'usage', - 'useable', - 'used', - 'uselessly', - 'user', - 'usher', - 'usual', - 'utensil', - 'utility', - 'utilize', - 'utmost', - 'utopia', - 'utter', - 'vacancy', - 'vacant', - 'vacate', - 'vacation', - 'vagabond', - 'vagrancy', - 'vagrantly', - 'vaguely', - 'vagueness', - 'valiant', - 'valid', - 'valium', - 'valley', - 'valuables', - 'value', - 'vanilla', - 'vanish', - 'vanity', - 'vanquish', - 'vantage', - 'vaporizer', - 'variable', - 'variably', - 'varied', - 'variety', - 'various', - 'varmint', - 'varnish', - 'varsity', - 'varying', - 'vascular', - 'vaseline', - 'vastly', - 'vastness', - 'veal', - 'vegan', - 'veggie', - 'vehicular', - 'velcro', - 'velocity', - 'velvet', - 'vendetta', - 'vending', - 'vendor', - 'veneering', - 'vengeful', - 'venomous', - 'ventricle', - 'venture', - 'venue', - 'venus', - 'verbalize', - 'verbally', - 'verbose', - 'verdict', - 'verify', - 'verse', - 'version', - 'versus', - 'vertebrae', - 'vertical', - 'vertigo', - 'very', - 'vessel', - 'vest', - 'veteran', - 'veto', - 'vexingly', - 'viability', - 'viable', - 'vibes', - 'vice', - 'vicinity', - 'victory', - 'video', - 'viewable', - 'viewer', - 'viewing', - 'viewless', - 'viewpoint', - 'vigorous', - 'village', - 'villain', - 'vindicate', - 'vineyard', - 'vintage', - 'violate', - 'violation', - 'violator', - 'violet', - 'violin', - 'viper', - 'viral', - 'virtual', - 'virtuous', - 'virus', - 'visa', - 'viscosity', - 'viscous', - 'viselike', - 'visible', - 'visibly', - 'vision', - 'visiting', - 'visitor', - 'visor', - 'vista', - 'vitality', - 'vitalize', - 'vitally', - 'vitamins', - 'vivacious', - 'vividly', - 'vividness', - 'vixen', - 'vocalist', - 'vocalize', - 'vocally', - 'vocation', - 'voice', - 'voicing', - 'void', - 'volatile', - 'volley', - 'voltage', - 'volumes', - 'voter', - 'voting', - 'voucher', - 'vowed', - 'vowel', - 'voyage', - 'wackiness', - 'wad', - 'wafer', - 'waffle', - 'waged', - 'wager', - 'wages', - 'waggle', - 'wagon', - 'wake', - 'waking', - 'walk', - 'walmart', - 'walnut', - 'walrus', - 'waltz', - 'wand', - 'wannabe', - 'wanted', - 'wanting', - 'wasabi', - 'washable', - 'washbasin', - 'washboard', - 'washbowl', - 'washcloth', - 'washday', - 'washed', - 'washer', - 'washhouse', - 'washing', - 'washout', - 'washroom', - 'washstand', - 'washtub', - 'wasp', - 'wasting', - 'watch', - 'water', - 'waviness', - 'waving', - 'wavy', - 'whacking', - 'whacky', - 'wham', - 'wharf', - 'wheat', - 'whenever', - 'whiff', - 'whimsical', - 'whinny', - 'whiny', - 'whisking', - 'whoever', - 'whole', - 'whomever', - 'whoopee', - 'whooping', - 'whoops', - 'why', - 'wick', - 'widely', - 'widen', - 'widget', - 'widow', - 'width', - 'wieldable', - 'wielder', - 'wife', - 'wifi', - 'wikipedia', - 'wildcard', - 'wildcat', - 'wilder', - 'wildfire', - 'wildfowl', - 'wildland', - 'wildlife', - 'wildly', - 'wildness', - 'willed', - 'willfully', - 'willing', - 'willow', - 'willpower', - 'wilt', - 'wimp', - 'wince', - 'wincing', - 'wind', - 'wing', - 'winking', - 'winner', - 'winnings', - 'winter', - 'wipe', - 'wired', - 'wireless', - 'wiring', - 'wiry', - 'wisdom', - 'wise', - 'wish', - 'wisplike', - 'wispy', - 'wistful', - 'wizard', - 'wobble', - 'wobbling', - 'wobbly', - 'wok', - 'wolf', - 'wolverine', - 'womanhood', - 'womankind', - 'womanless', - 'womanlike', - 'womanly', - 'womb', - 'woof', - 'wooing', - 'wool', - 'woozy', - 'word', - 'work', - 'worried', - 'worrier', - 'worrisome', - 'worry', - 'worsening', - 'worshiper', - 'worst', - 'wound', - 'woven', - 'wow', - 'wrangle', - 'wrath', - 'wreath', - 'wreckage', - 'wrecker', - 'wrecking', - 'wrench', - 'wriggle', - 'wriggly', - 'wrinkle', - 'wrinkly', - 'wrist', - 'writing', - 'written', - 'wrongdoer', - 'wronged', - 'wrongful', - 'wrongly', - 'wrongness', - 'wrought', - 'xbox', - 'xerox', - 'yahoo', - 'yam', - 'yanking', - 'yapping', - 'yard', - 'yarn', - 'yeah', - 'yearbook', - 'yearling', - 'yearly', - 'yearning', - 'yeast', - 'yelling', - 'yelp', - 'yen', - 'yesterday', - 'yiddish', - 'yield', - 'yin', - 'yippee', - 'yo-yo', - 'yodel', - 'yoga', - 'yogurt', - 'yonder', - 'yoyo', - 'yummy', - 'zap', - 'zealous', - 'zebra', - 'zen', - 'zeppelin', - 'zero', - 'zestfully', - 'zesty', - 'zigzagged', - 'zipfile', - 'zipping', - 'zippy', - 'zips', - 'zit', - 'zodiac', - 'zombie', - 'zone', - 'zoning', - 'zookeeper', - 'zoologist', - 'zoology', - 'zoom', + "abacus", + "abdomen", + "abdominal", + "abide", + "abiding", + "ability", + "ablaze", + "able", + "abnormal", + "abrasion", + "abrasive", + "abreast", + "abridge", + "abroad", + "abruptly", + "absence", + "absentee", + "absently", + "absinthe", + "absolute", + "absolve", + "abstain", + "abstract", + "absurd", + "accent", + "acclaim", + "acclimate", + "accompany", + "account", + "accuracy", + "accurate", + "accustom", + "acetone", + "achiness", + "aching", + "acid", + "acorn", + "acquaint", + "acquire", + "acre", + "acrobat", + "acronym", + "acting", + "action", + "activate", + "activator", + "active", + "activism", + "activist", + "activity", + "actress", + "acts", + "acutely", + "acuteness", + "aeration", + "aerobics", + "aerosol", + "aerospace", + "afar", + "affair", + "affected", + "affecting", + "affection", + "affidavit", + "affiliate", + "affirm", + "affix", + "afflicted", + "affluent", + "afford", + "affront", + "aflame", + "afloat", + "aflutter", + "afoot", + "afraid", + "afterglow", + "afterlife", + "aftermath", + "aftermost", + "afternoon", + "aged", + "ageless", + "agency", + "agenda", + "agent", + "aggregate", + "aghast", + "agile", + "agility", + "aging", + "agnostic", + "agonize", + "agonizing", + "agony", + "agreeable", + "agreeably", + "agreed", + "agreeing", + "agreement", + "aground", + "ahead", + "ahoy", + "aide", + "aids", + "aim", + "ajar", + "alabaster", + "alarm", + "albatross", + "album", + "alfalfa", + "algebra", + "algorithm", + "alias", + "alibi", + "alienable", + "alienate", + "aliens", + "alike", + "alive", + "alkaline", + "alkalize", + "almanac", + "almighty", + "almost", + "aloe", + "aloft", + "aloha", + "alone", + "alongside", + "aloof", + "alphabet", + "alright", + "although", + "altitude", + "alto", + "aluminum", + "alumni", + "always", + "amaretto", + "amaze", + "amazingly", + "amber", + "ambiance", + "ambiguity", + "ambiguous", + "ambition", + "ambitious", + "ambulance", + "ambush", + "amendable", + "amendment", + "amends", + "amenity", + "amiable", + "amicably", + "amid", + "amigo", + "amino", + "amiss", + "ammonia", + "ammonium", + "amnesty", + "amniotic", + "among", + "amount", + "amperage", + "ample", + "amplifier", + "amplify", + "amply", + "amuck", + "amulet", + "amusable", + "amused", + "amusement", + "amuser", + "amusing", + "anaconda", + "anaerobic", + "anagram", + "anatomist", + "anatomy", + "anchor", + "anchovy", + "ancient", + "android", + "anemia", + "anemic", + "aneurism", + "anew", + "angelfish", + "angelic", + "anger", + "angled", + "angler", + "angles", + "angling", + "angrily", + "angriness", + "anguished", + "angular", + "animal", + "animate", + "animating", + "animation", + "animator", + "anime", + "animosity", + "ankle", + "annex", + "annotate", + "announcer", + "annoying", + "annually", + "annuity", + "anointer", + "another", + "answering", + "antacid", + "antarctic", + "anteater", + "antelope", + "antennae", + "anthem", + "anthill", + "anthology", + "antibody", + "antics", + "antidote", + "antihero", + "antiquely", + "antiques", + "antiquity", + "antirust", + "antitoxic", + "antitrust", + "antiviral", + "antivirus", + "antler", + "antonym", + "antsy", + "anvil", + "anybody", + "anyhow", + "anymore", + "anyone", + "anyplace", + "anything", + "anytime", + "anyway", + "anywhere", + "aorta", + "apache", + "apostle", + "appealing", + "appear", + "appease", + "appeasing", + "appendage", + "appendix", + "appetite", + "appetizer", + "applaud", + "applause", + "apple", + "appliance", + "applicant", + "applied", + "apply", + "appointee", + "appraisal", + "appraiser", + "apprehend", + "approach", + "approval", + "approve", + "apricot", + "april", + "apron", + "aptitude", + "aptly", + "aqua", + "aqueduct", + "arbitrary", + "arbitrate", + "ardently", + "area", + "arena", + "arguable", + "arguably", + "argue", + "arise", + "armadillo", + "armband", + "armchair", + "armed", + "armful", + "armhole", + "arming", + "armless", + "armoire", + "armored", + "armory", + "armrest", + "army", + "aroma", + "arose", + "around", + "arousal", + "arrange", + "array", + "arrest", + "arrival", + "arrive", + "arrogance", + "arrogant", + "arson", + "art", + "ascend", + "ascension", + "ascent", + "ascertain", + "ashamed", + "ashen", + "ashes", + "ashy", + "aside", + "askew", + "asleep", + "asparagus", + "aspect", + "aspirate", + "aspire", + "aspirin", + "astonish", + "astound", + "astride", + "astrology", + "astronaut", + "astronomy", + "astute", + "atlantic", + "atlas", + "atom", + "atonable", + "atop", + "atrium", + "atrocious", + "atrophy", + "attach", + "attain", + "attempt", + "attendant", + "attendee", + "attention", + "attentive", + "attest", + "attic", + "attire", + "attitude", + "attractor", + "attribute", + "atypical", + "auction", + "audacious", + "audacity", + "audible", + "audibly", + "audience", + "audio", + "audition", + "augmented", + "august", + "authentic", + "author", + "autism", + "autistic", + "autograph", + "automaker", + "automated", + "automatic", + "autopilot", + "available", + "avalanche", + "avatar", + "avenge", + "avenging", + "avenue", + "average", + "aversion", + "avert", + "aviation", + "aviator", + "avid", + "avoid", + "await", + "awaken", + "award", + "aware", + "awhile", + "awkward", + "awning", + "awoke", + "awry", + "axis", + "babble", + "babbling", + "babied", + "baboon", + "backache", + "backboard", + "backboned", + "backdrop", + "backed", + "backer", + "backfield", + "backfire", + "backhand", + "backing", + "backlands", + "backlash", + "backless", + "backlight", + "backlit", + "backlog", + "backpack", + "backpedal", + "backrest", + "backroom", + "backshift", + "backside", + "backslid", + "backspace", + "backspin", + "backstab", + "backstage", + "backtalk", + "backtrack", + "backup", + "backward", + "backwash", + "backwater", + "backyard", + "bacon", + "bacteria", + "bacterium", + "badass", + "badge", + "badland", + "badly", + "badness", + "baffle", + "baffling", + "bagel", + "bagful", + "baggage", + "bagged", + "baggie", + "bagginess", + "bagging", + "baggy", + "bagpipe", + "baguette", + "baked", + "bakery", + "bakeshop", + "baking", + "balance", + "balancing", + "balcony", + "balmy", + "balsamic", + "bamboo", + "banana", + "banish", + "banister", + "banjo", + "bankable", + "bankbook", + "banked", + "banker", + "banking", + "banknote", + "bankroll", + "banner", + "bannister", + "banshee", + "banter", + "barbecue", + "barbed", + "barbell", + "barber", + "barcode", + "barge", + "bargraph", + "barista", + "baritone", + "barley", + "barmaid", + "barman", + "barn", + "barometer", + "barrack", + "barracuda", + "barrel", + "barrette", + "barricade", + "barrier", + "barstool", + "bartender", + "barterer", + "bash", + "basically", + "basics", + "basil", + "basin", + "basis", + "basket", + "batboy", + "batch", + "bath", + "baton", + "bats", + "battalion", + "battered", + "battering", + "battery", + "batting", + "battle", + "bauble", + "bazooka", + "blabber", + "bladder", + "blade", + "blah", + "blame", + "blaming", + "blanching", + "blandness", + "blank", + "blaspheme", + "blasphemy", + "blast", + "blatancy", + "blatantly", + "blazer", + "blazing", + "bleach", + "bleak", + "bleep", + "blemish", + "blend", + "bless", + "blighted", + "blimp", + "bling", + "blinked", + "blinker", + "blinking", + "blinks", + "blip", + "blissful", + "blitz", + "blizzard", + "bloated", + "bloating", + "blob", + "blog", + "bloomers", + "blooming", + "blooper", + "blot", + "blouse", + "blubber", + "bluff", + "bluish", + "blunderer", + "blunt", + "blurb", + "blurred", + "blurry", + "blurt", + "blush", + "blustery", + "boaster", + "boastful", + "boasting", + "boat", + "bobbed", + "bobbing", + "bobble", + "bobcat", + "bobsled", + "bobtail", + "bodacious", + "body", + "bogged", + "boggle", + "bogus", + "boil", + "bok", + "bolster", + "bolt", + "bonanza", + "bonded", + "bonding", + "bondless", + "boned", + "bonehead", + "boneless", + "bonelike", + "boney", + "bonfire", + "bonnet", + "bonsai", + "bonus", + "bony", + "boogeyman", + "boogieman", + "book", + "boondocks", + "booted", + "booth", + "bootie", + "booting", + "bootlace", + "bootleg", + "boots", + "boozy", + "borax", + "boring", + "borough", + "borrower", + "borrowing", + "boss", + "botanical", + "botanist", + "botany", + "botch", + "both", + "bottle", + "bottling", + "bottom", + "bounce", + "bouncing", + "bouncy", + "bounding", + "boundless", + "bountiful", + "bovine", + "boxcar", + "boxer", + "boxing", + "boxlike", + "boxy", + "breach", + "breath", + "breeches", + "breeching", + "breeder", + "breeding", + "breeze", + "breezy", + "brethren", + "brewery", + "brewing", + "briar", + "bribe", + "brick", + "bride", + "bridged", + "brigade", + "bright", + "brilliant", + "brim", + "bring", + "brink", + "brisket", + "briskly", + "briskness", + "bristle", + "brittle", + "broadband", + "broadcast", + "broaden", + "broadly", + "broadness", + "broadside", + "broadways", + "broiler", + "broiling", + "broken", + "broker", + "bronchial", + "bronco", + "bronze", + "bronzing", + "brook", + "broom", + "brought", + "browbeat", + "brownnose", + "browse", + "browsing", + "bruising", + "brunch", + "brunette", + "brunt", + "brush", + "brussels", + "brute", + "brutishly", + "bubble", + "bubbling", + "bubbly", + "buccaneer", + "bucked", + "bucket", + "buckle", + "buckshot", + "buckskin", + "bucktooth", + "buckwheat", + "buddhism", + "buddhist", + "budding", + "buddy", + "budget", + "buffalo", + "buffed", + "buffer", + "buffing", + "buffoon", + "buggy", + "bulb", + "bulge", + "bulginess", + "bulgur", + "bulk", + "bulldog", + "bulldozer", + "bullfight", + "bullfrog", + "bullhorn", + "bullion", + "bullish", + "bullpen", + "bullring", + "bullseye", + "bullwhip", + "bully", + "bunch", + "bundle", + "bungee", + "bunion", + "bunkbed", + "bunkhouse", + "bunkmate", + "bunny", + "bunt", + "busboy", + "bush", + "busily", + "busload", + "bust", + "busybody", + "buzz", + "cabana", + "cabbage", + "cabbie", + "cabdriver", + "cable", + "caboose", + "cache", + "cackle", + "cacti", + "cactus", + "caddie", + "caddy", + "cadet", + "cadillac", + "cadmium", + "cage", + "cahoots", + "cake", + "calamari", + "calamity", + "calcium", + "calculate", + "calculus", + "caliber", + "calibrate", + "calm", + "caloric", + "calorie", + "calzone", + "camcorder", + "cameo", + "camera", + "camisole", + "camper", + "campfire", + "camping", + "campsite", + "campus", + "canal", + "canary", + "cancel", + "candied", + "candle", + "candy", + "cane", + "canine", + "canister", + "cannabis", + "canned", + "canning", + "cannon", + "cannot", + "canola", + "canon", + "canopener", + "canopy", + "canteen", + "canyon", + "capable", + "capably", + "capacity", + "cape", + "capillary", + "capital", + "capitol", + "capped", + "capricorn", + "capsize", + "capsule", + "caption", + "captivate", + "captive", + "captivity", + "capture", + "caramel", + "carat", + "caravan", + "carbon", + "cardboard", + "carded", + "cardiac", + "cardigan", + "cardinal", + "cardstock", + "carefully", + "caregiver", + "careless", + "caress", + "caretaker", + "cargo", + "caring", + "carless", + "carload", + "carmaker", + "carnage", + "carnation", + "carnival", + "carnivore", + "carol", + "carpenter", + "carpentry", + "carpool", + "carport", + "carried", + "carrot", + "carrousel", + "carry", + "cartel", + "cartload", + "carton", + "cartoon", + "cartridge", + "cartwheel", + "carve", + "carving", + "carwash", + "cascade", + "case", + "cash", + "casing", + "casino", + "casket", + "cassette", + "casually", + "casualty", + "catacomb", + "catalog", + "catalyst", + "catalyze", + "catapult", + "cataract", + "catatonic", + "catcall", + "catchable", + "catcher", + "catching", + "catchy", + "caterer", + "catering", + "catfight", + "catfish", + "cathedral", + "cathouse", + "catlike", + "catnap", + "catnip", + "catsup", + "cattail", + "cattishly", + "cattle", + "catty", + "catwalk", + "caucasian", + "caucus", + "causal", + "causation", + "cause", + "causing", + "cauterize", + "caution", + "cautious", + "cavalier", + "cavalry", + "caviar", + "cavity", + "cedar", + "celery", + "celestial", + "celibacy", + "celibate", + "celtic", + "cement", + "census", + "ceramics", + "ceremony", + "certainly", + "certainty", + "certified", + "certify", + "cesarean", + "cesspool", + "chafe", + "chaffing", + "chain", + "chair", + "chalice", + "challenge", + "chamber", + "chamomile", + "champion", + "chance", + "change", + "channel", + "chant", + "chaos", + "chaperone", + "chaplain", + "chapped", + "chaps", + "chapter", + "character", + "charbroil", + "charcoal", + "charger", + "charging", + "chariot", + "charity", + "charm", + "charred", + "charter", + "charting", + "chase", + "chasing", + "chaste", + "chastise", + "chastity", + "chatroom", + "chatter", + "chatting", + "chatty", + "cheating", + "cheddar", + "cheek", + "cheer", + "cheese", + "cheesy", + "chef", + "chemicals", + "chemist", + "chemo", + "cherisher", + "cherub", + "chess", + "chest", + "chevron", + "chevy", + "chewable", + "chewer", + "chewing", + "chewy", + "chief", + "chihuahua", + "childcare", + "childhood", + "childish", + "childless", + "childlike", + "chili", + "chill", + "chimp", + "chip", + "chirping", + "chirpy", + "chitchat", + "chivalry", + "chive", + "chloride", + "chlorine", + "choice", + "chokehold", + "choking", + "chomp", + "chooser", + "choosing", + "choosy", + "chop", + "chosen", + "chowder", + "chowtime", + "chrome", + "chubby", + "chuck", + "chug", + "chummy", + "chump", + "chunk", + "churn", + "chute", + "cider", + "cilantro", + "cinch", + "cinema", + "cinnamon", + "circle", + "circling", + "circular", + "circulate", + "circus", + "citable", + "citadel", + "citation", + "citizen", + "citric", + "citrus", + "city", + "civic", + "civil", + "clad", + "claim", + "clambake", + "clammy", + "clamor", + "clamp", + "clamshell", + "clang", + "clanking", + "clapped", + "clapper", + "clapping", + "clarify", + "clarinet", + "clarity", + "clash", + "clasp", + "class", + "clatter", + "clause", + "clavicle", + "claw", + "clay", + "clean", + "clear", + "cleat", + "cleaver", + "cleft", + "clench", + "clergyman", + "clerical", + "clerk", + "clever", + "clicker", + "client", + "climate", + "climatic", + "cling", + "clinic", + "clinking", + "clip", + "clique", + "cloak", + "clobber", + "clock", + "clone", + "cloning", + "closable", + "closure", + "clothes", + "clothing", + "cloud", + "clover", + "clubbed", + "clubbing", + "clubhouse", + "clump", + "clumsily", + "clumsy", + "clunky", + "clustered", + "clutch", + "clutter", + "coach", + "coagulant", + "coastal", + "coaster", + "coasting", + "coastland", + "coastline", + "coat", + "coauthor", + "cobalt", + "cobbler", + "cobweb", + "cocoa", + "coconut", + "cod", + "coeditor", + "coerce", + "coexist", + "coffee", + "cofounder", + "cognition", + "cognitive", + "cogwheel", + "coherence", + "coherent", + "cohesive", + "coil", + "coke", + "cola", + "cold", + "coleslaw", + "coliseum", + "collage", + "collapse", + "collar", + "collected", + "collector", + "collide", + "collie", + "collision", + "colonial", + "colonist", + "colonize", + "colony", + "colossal", + "colt", + "coma", + "come", + "comfort", + "comfy", + "comic", + "coming", + "comma", + "commence", + "commend", + "comment", + "commerce", + "commode", + "commodity", + "commodore", + "common", + "commotion", + "commute", + "commuting", + "compacted", + "compacter", + "compactly", + "compactor", + "companion", + "company", + "compare", + "compel", + "compile", + "comply", + "component", + "composed", + "composer", + "composite", + "compost", + "composure", + "compound", + "compress", + "comprised", + "computer", + "computing", + "comrade", + "concave", + "conceal", + "conceded", + "concept", + "concerned", + "concert", + "conch", + "concierge", + "concise", + "conclude", + "concrete", + "concur", + "condense", + "condiment", + "condition", + "condone", + "conducive", + "conductor", + "conduit", + "cone", + "confess", + "confetti", + "confidant", + "confident", + "confider", + "confiding", + "configure", + "confined", + "confining", + "confirm", + "conflict", + "conform", + "confound", + "confront", + "confused", + "confusing", + "confusion", + "congenial", + "congested", + "congrats", + "congress", + "conical", + "conjoined", + "conjure", + "conjuror", + "connected", + "connector", + "consensus", + "consent", + "console", + "consoling", + "consonant", + "constable", + "constant", + "constrain", + "constrict", + "construct", + "consult", + "consumer", + "consuming", + "contact", + "container", + "contempt", + "contend", + "contented", + "contently", + "contents", + "contest", + "context", + "contort", + "contour", + "contrite", + "control", + "contusion", + "convene", + "convent", + "copartner", + "cope", + "copied", + "copier", + "copilot", + "coping", + "copious", + "copper", + "copy", + "coral", + "cork", + "cornball", + "cornbread", + "corncob", + "cornea", + "corned", + "corner", + "cornfield", + "cornflake", + "cornhusk", + "cornmeal", + "cornstalk", + "corny", + "coronary", + "coroner", + "corporal", + "corporate", + "corral", + "correct", + "corridor", + "corrode", + "corroding", + "corrosive", + "corsage", + "corset", + "cortex", + "cosigner", + "cosmetics", + "cosmic", + "cosmos", + "cosponsor", + "cost", + "cottage", + "cotton", + "couch", + "cough", + "could", + "countable", + "countdown", + "counting", + "countless", + "country", + "county", + "courier", + "covenant", + "cover", + "coveted", + "coveting", + "coyness", + "cozily", + "coziness", + "cozy", + "crabbing", + "crabgrass", + "crablike", + "crabmeat", + "cradle", + "cradling", + "crafter", + "craftily", + "craftsman", + "craftwork", + "crafty", + "cramp", + "cranberry", + "crane", + "cranial", + "cranium", + "crank", + "crate", + "crave", + "craving", + "crawfish", + "crawlers", + "crawling", + "crayfish", + "crayon", + "crazed", + "crazily", + "craziness", + "crazy", + "creamed", + "creamer", + "creamlike", + "crease", + "creasing", + "creatable", + "create", + "creation", + "creative", + "creature", + "credible", + "credibly", + "credit", + "creed", + "creme", + "creole", + "crepe", + "crept", + "crescent", + "crested", + "cresting", + "crestless", + "crevice", + "crewless", + "crewman", + "crewmate", + "crib", + "cricket", + "cried", + "crier", + "crimp", + "crimson", + "cringe", + "cringing", + "crinkle", + "crinkly", + "crisped", + "crisping", + "crisply", + "crispness", + "crispy", + "criteria", + "critter", + "croak", + "crock", + "crook", + "croon", + "crop", + "cross", + "crouch", + "crouton", + "crowbar", + "crowd", + "crown", + "crucial", + "crudely", + "crudeness", + "cruelly", + "cruelness", + "cruelty", + "crumb", + "crummiest", + "crummy", + "crumpet", + "crumpled", + "cruncher", + "crunching", + "crunchy", + "crusader", + "crushable", + "crushed", + "crusher", + "crushing", + "crust", + "crux", + "crying", + "cryptic", + "crystal", + "cubbyhole", + "cube", + "cubical", + "cubicle", + "cucumber", + "cuddle", + "cuddly", + "cufflink", + "culinary", + "culminate", + "culpable", + "culprit", + "cultivate", + "cultural", + "culture", + "cupbearer", + "cupcake", + "cupid", + "cupped", + "cupping", + "curable", + "curator", + "curdle", + "cure", + "curfew", + "curing", + "curled", + "curler", + "curliness", + "curling", + "curly", + "curry", + "curse", + "cursive", + "cursor", + "curtain", + "curtly", + "curtsy", + "curvature", + "curve", + "curvy", + "cushy", + "cusp", + "cussed", + "custard", + "custodian", + "custody", + "customary", + "customer", + "customize", + "customs", + "cut", + "cycle", + "cyclic", + "cycling", + "cyclist", + "cylinder", + "cymbal", + "cytoplasm", + "cytoplast", + "dab", + "dad", + "daffodil", + "dagger", + "daily", + "daintily", + "dainty", + "dairy", + "daisy", + "dallying", + "dance", + "dancing", + "dandelion", + "dander", + "dandruff", + "dandy", + "danger", + "dangle", + "dangling", + "daredevil", + "dares", + "daringly", + "darkened", + "darkening", + "darkish", + "darkness", + "darkroom", + "darling", + "darn", + "dart", + "darwinism", + "dash", + "dastardly", + "data", + "datebook", + "dating", + "daughter", + "daunting", + "dawdler", + "dawn", + "daybed", + "daybreak", + "daycare", + "daydream", + "daylight", + "daylong", + "dayroom", + "daytime", + "dazzler", + "dazzling", + "deacon", + "deafening", + "deafness", + "dealer", + "dealing", + "dealmaker", + "dealt", + "dean", + "debatable", + "debate", + "debating", + "debit", + "debrief", + "debtless", + "debtor", + "debug", + "debunk", + "decade", + "decaf", + "decal", + "decathlon", + "decay", + "deceased", + "deceit", + "deceiver", + "deceiving", + "december", + "decency", + "decent", + "deception", + "deceptive", + "decibel", + "decidable", + "decimal", + "decimeter", + "decipher", + "deck", + "declared", + "decline", + "decode", + "decompose", + "decorated", + "decorator", + "decoy", + "decrease", + "decree", + "dedicate", + "dedicator", + "deduce", + "deduct", + "deed", + "deem", + "deepen", + "deeply", + "deepness", + "deface", + "defacing", + "defame", + "default", + "defeat", + "defection", + "defective", + "defendant", + "defender", + "defense", + "defensive", + "deferral", + "deferred", + "defiance", + "defiant", + "defile", + "defiling", + "define", + "definite", + "deflate", + "deflation", + "deflator", + "deflected", + "deflector", + "defog", + "deforest", + "defraud", + "defrost", + "deftly", + "defuse", + "defy", + "degraded", + "degrading", + "degrease", + "degree", + "dehydrate", + "deity", + "dejected", + "delay", + "delegate", + "delegator", + "delete", + "deletion", + "delicacy", + "delicate", + "delicious", + "delighted", + "delirious", + "delirium", + "deliverer", + "delivery", + "delouse", + "delta", + "deluge", + "delusion", + "deluxe", + "demanding", + "demeaning", + "demeanor", + "demise", + "democracy", + "democrat", + "demote", + "demotion", + "demystify", + "denatured", + "deniable", + "denial", + "denim", + "denote", + "dense", + "density", + "dental", + "dentist", + "denture", + "deny", + "deodorant", + "deodorize", + "departed", + "departure", + "depict", + "deplete", + "depletion", + "deplored", + "deploy", + "deport", + "depose", + "depraved", + "depravity", + "deprecate", + "depress", + "deprive", + "depth", + "deputize", + "deputy", + "derail", + "deranged", + "derby", + "derived", + "desecrate", + "deserve", + "deserving", + "designate", + "designed", + "designer", + "designing", + "deskbound", + "desktop", + "deskwork", + "desolate", + "despair", + "despise", + "despite", + "destiny", + "destitute", + "destruct", + "detached", + "detail", + "detection", + "detective", + "detector", + "detention", + "detergent", + "detest", + "detonate", + "detonator", + "detoxify", + "detract", + "deuce", + "devalue", + "deviancy", + "deviant", + "deviate", + "deviation", + "deviator", + "device", + "devious", + "devotedly", + "devotee", + "devotion", + "devourer", + "devouring", + "devoutly", + "dexterity", + "dexterous", + "diabetes", + "diabetic", + "diabolic", + "diagnoses", + "diagnosis", + "diagram", + "dial", + "diameter", + "diaper", + "diaphragm", + "diary", + "dice", + "dicing", + "dictate", + "dictation", + "dictator", + "difficult", + "diffused", + "diffuser", + "diffusion", + "diffusive", + "dig", + "dilation", + "diligence", + "diligent", + "dill", + "dilute", + "dime", + "diminish", + "dimly", + "dimmed", + "dimmer", + "dimness", + "dimple", + "diner", + "dingbat", + "dinghy", + "dinginess", + "dingo", + "dingy", + "dining", + "dinner", + "diocese", + "dioxide", + "diploma", + "dipped", + "dipper", + "dipping", + "directed", + "direction", + "directive", + "directly", + "directory", + "direness", + "dirtiness", + "disabled", + "disagree", + "disallow", + "disarm", + "disarray", + "disaster", + "disband", + "disbelief", + "disburse", + "discard", + "discern", + "discharge", + "disclose", + "discolor", + "discount", + "discourse", + "discover", + "discuss", + "disdain", + "disengage", + "disfigure", + "disgrace", + "dish", + "disinfect", + "disjoin", + "disk", + "dislike", + "disliking", + "dislocate", + "dislodge", + "disloyal", + "dismantle", + "dismay", + "dismiss", + "dismount", + "disobey", + "disorder", + "disown", + "disparate", + "disparity", + "dispatch", + "dispense", + "dispersal", + "dispersed", + "disperser", + "displace", + "display", + "displease", + "disposal", + "dispose", + "disprove", + "dispute", + "disregard", + "disrupt", + "dissuade", + "distance", + "distant", + "distaste", + "distill", + "distinct", + "distort", + "distract", + "distress", + "district", + "distrust", + "ditch", + "ditto", + "ditzy", + "dividable", + "divided", + "dividend", + "dividers", + "dividing", + "divinely", + "diving", + "divinity", + "divisible", + "divisibly", + "division", + "divisive", + "divorcee", + "dizziness", + "dizzy", + "doable", + "docile", + "dock", + "doctrine", + "document", + "dodge", + "dodgy", + "doily", + "doing", + "dole", + "dollar", + "dollhouse", + "dollop", + "dolly", + "dolphin", + "domain", + "domelike", + "domestic", + "dominion", + "dominoes", + "donated", + "donation", + "donator", + "donor", + "donut", + "doodle", + "doorbell", + "doorframe", + "doorknob", + "doorman", + "doormat", + "doornail", + "doorpost", + "doorstep", + "doorstop", + "doorway", + "doozy", + "dork", + "dormitory", + "dorsal", + "dosage", + "dose", + "dotted", + "doubling", + "douche", + "dove", + "down", + "dowry", + "doze", + "drab", + "dragging", + "dragonfly", + "dragonish", + "dragster", + "drainable", + "drainage", + "drained", + "drainer", + "drainpipe", + "dramatic", + "dramatize", + "drank", + "drapery", + "drastic", + "draw", + "dreaded", + "dreadful", + "dreadlock", + "dreamboat", + "dreamily", + "dreamland", + "dreamless", + "dreamlike", + "dreamt", + "dreamy", + "drearily", + "dreary", + "drench", + "dress", + "drew", + "dribble", + "dried", + "drier", + "drift", + "driller", + "drilling", + "drinkable", + "drinking", + "dripping", + "drippy", + "drivable", + "driven", + "driver", + "driveway", + "driving", + "drizzle", + "drizzly", + "drone", + "drool", + "droop", + "drop-down", + "dropbox", + "dropkick", + "droplet", + "dropout", + "dropper", + "drove", + "drown", + "drowsily", + "drudge", + "drum", + "dry", + "dubbed", + "dubiously", + "duchess", + "duckbill", + "ducking", + "duckling", + "ducktail", + "ducky", + "duct", + "dude", + "duffel", + "dugout", + "duh", + "duke", + "duller", + "dullness", + "duly", + "dumping", + "dumpling", + "dumpster", + "duo", + "dupe", + "duplex", + "duplicate", + "duplicity", + "durable", + "durably", + "duration", + "duress", + "during", + "dusk", + "dust", + "dutiful", + "duty", + "duvet", + "dwarf", + "dweeb", + "dwelled", + "dweller", + "dwelling", + "dwindle", + "dwindling", + "dynamic", + "dynamite", + "dynasty", + "dyslexia", + "dyslexic", + "each", + "eagle", + "earache", + "eardrum", + "earflap", + "earful", + "earlobe", + "early", + "earmark", + "earmuff", + "earphone", + "earpiece", + "earplugs", + "earring", + "earshot", + "earthen", + "earthlike", + "earthling", + "earthly", + "earthworm", + "earthy", + "earwig", + "easeful", + "easel", + "easiest", + "easily", + "easiness", + "easing", + "eastbound", + "eastcoast", + "easter", + "eastward", + "eatable", + "eaten", + "eatery", + "eating", + "eats", + "ebay", + "ebony", + "ebook", + "ecard", + "eccentric", + "echo", + "eclair", + "eclipse", + "ecologist", + "ecology", + "economic", + "economist", + "economy", + "ecosphere", + "ecosystem", + "edge", + "edginess", + "edging", + "edgy", + "edition", + "editor", + "educated", + "education", + "educator", + "eel", + "effective", + "effects", + "efficient", + "effort", + "eggbeater", + "egging", + "eggnog", + "eggplant", + "eggshell", + "egomaniac", + "egotism", + "egotistic", + "either", + "eject", + "elaborate", + "elastic", + "elated", + "elbow", + "eldercare", + "elderly", + "eldest", + "electable", + "election", + "elective", + "elephant", + "elevate", + "elevating", + "elevation", + "elevator", + "eleven", + "elf", + "eligible", + "eligibly", + "eliminate", + "elite", + "elitism", + "elixir", + "elk", + "ellipse", + "elliptic", + "elm", + "elongated", + "elope", + "eloquence", + "eloquent", + "elsewhere", + "elude", + "elusive", + "elves", + "email", + "embargo", + "embark", + "embassy", + "embattled", + "embellish", + "ember", + "embezzle", + "emblaze", + "emblem", + "embody", + "embolism", + "emboss", + "embroider", + "emcee", + "emerald", + "emergency", + "emission", + "emit", + "emote", + "emoticon", + "emotion", + "empathic", + "empathy", + "emperor", + "emphases", + "emphasis", + "emphasize", + "emphatic", + "empirical", + "employed", + "employee", + "employer", + "emporium", + "empower", + "emptier", + "emptiness", + "empty", + "emu", + "enable", + "enactment", + "enamel", + "enchanted", + "enchilada", + "encircle", + "enclose", + "enclosure", + "encode", + "encore", + "encounter", + "encourage", + "encroach", + "encrust", + "encrypt", + "endanger", + "endeared", + "endearing", + "ended", + "ending", + "endless", + "endnote", + "endocrine", + "endorphin", + "endorse", + "endowment", + "endpoint", + "endurable", + "endurance", + "enduring", + "energetic", + "energize", + "energy", + "enforced", + "enforcer", + "engaged", + "engaging", + "engine", + "engorge", + "engraved", + "engraver", + "engraving", + "engross", + "engulf", + "enhance", + "enigmatic", + "enjoyable", + "enjoyably", + "enjoyer", + "enjoying", + "enjoyment", + "enlarged", + "enlarging", + "enlighten", + "enlisted", + "enquirer", + "enrage", + "enrich", + "enroll", + "enslave", + "ensnare", + "ensure", + "entail", + "entangled", + "entering", + "entertain", + "enticing", + "entire", + "entitle", + "entity", + "entomb", + "entourage", + "entrap", + "entree", + "entrench", + "entrust", + "entryway", + "entwine", + "enunciate", + "envelope", + "enviable", + "enviably", + "envious", + "envision", + "envoy", + "envy", + "enzyme", + "epic", + "epidemic", + "epidermal", + "epidermis", + "epidural", + "epilepsy", + "epileptic", + "epilogue", + "epiphany", + "episode", + "equal", + "equate", + "equation", + "equator", + "equinox", + "equipment", + "equity", + "equivocal", + "eradicate", + "erasable", + "erased", + "eraser", + "erasure", + "ergonomic", + "errand", + "errant", + "erratic", + "error", + "erupt", + "escalate", + "escalator", + "escapable", + "escapade", + "escapist", + "escargot", + "eskimo", + "esophagus", + "espionage", + "espresso", + "esquire", + "essay", + "essence", + "essential", + "establish", + "estate", + "esteemed", + "estimate", + "estimator", + "estranged", + "estrogen", + "etching", + "eternal", + "eternity", + "ethanol", + "ether", + "ethically", + "ethics", + "euphemism", + "evacuate", + "evacuee", + "evade", + "evaluate", + "evaluator", + "evaporate", + "evasion", + "evasive", + "even", + "everglade", + "evergreen", + "everybody", + "everyday", + "everyone", + "evict", + "evidence", + "evident", + "evil", + "evoke", + "evolution", + "evolve", + "exact", + "exalted", + "example", + "excavate", + "excavator", + "exceeding", + "exception", + "excess", + "exchange", + "excitable", + "exciting", + "exclaim", + "exclude", + "excluding", + "exclusion", + "exclusive", + "excretion", + "excretory", + "excursion", + "excusable", + "excusably", + "excuse", + "exemplary", + "exemplify", + "exemption", + "exerciser", + "exert", + "exes", + "exfoliate", + "exhale", + "exhaust", + "exhume", + "exile", + "existing", + "exit", + "exodus", + "exonerate", + "exorcism", + "exorcist", + "expand", + "expanse", + "expansion", + "expansive", + "expectant", + "expedited", + "expediter", + "expel", + "expend", + "expenses", + "expensive", + "expert", + "expire", + "expiring", + "explain", + "expletive", + "explicit", + "explode", + "exploit", + "explore", + "exploring", + "exponent", + "exporter", + "exposable", + "expose", + "exposure", + "express", + "expulsion", + "exquisite", + "extended", + "extending", + "extent", + "extenuate", + "exterior", + "external", + "extinct", + "extortion", + "extradite", + "extras", + "extrovert", + "extrude", + "extruding", + "exuberant", + "fable", + "fabric", + "fabulous", + "facebook", + "facecloth", + "facedown", + "faceless", + "facelift", + "faceplate", + "faceted", + "facial", + "facility", + "facing", + "facsimile", + "faction", + "factoid", + "factor", + "factsheet", + "factual", + "faculty", + "fade", + "fading", + "failing", + "falcon", + "fall", + "false", + "falsify", + "fame", + "familiar", + "family", + "famine", + "famished", + "fanatic", + "fancied", + "fanciness", + "fancy", + "fanfare", + "fang", + "fanning", + "fantasize", + "fantastic", + "fantasy", + "fascism", + "fastball", + "faster", + "fasting", + "fastness", + "faucet", + "favorable", + "favorably", + "favored", + "favoring", + "favorite", + "fax", + "feast", + "federal", + "fedora", + "feeble", + "feed", + "feel", + "feisty", + "feline", + "felt-tip", + "feminine", + "feminism", + "feminist", + "feminize", + "femur", + "fence", + "fencing", + "fender", + "ferment", + "fernlike", + "ferocious", + "ferocity", + "ferret", + "ferris", + "ferry", + "fervor", + "fester", + "festival", + "festive", + "festivity", + "fetal", + "fetch", + "fever", + "fiber", + "fiction", + "fiddle", + "fiddling", + "fidelity", + "fidgeting", + "fidgety", + "fifteen", + "fifth", + "fiftieth", + "fifty", + "figment", + "figure", + "figurine", + "filing", + "filled", + "filler", + "filling", + "film", + "filter", + "filth", + "filtrate", + "finale", + "finalist", + "finalize", + "finally", + "finance", + "financial", + "finch", + "fineness", + "finer", + "finicky", + "finished", + "finisher", + "finishing", + "finite", + "finless", + "finlike", + "fiscally", + "fit", + "five", + "flaccid", + "flagman", + "flagpole", + "flagship", + "flagstick", + "flagstone", + "flail", + "flakily", + "flaky", + "flame", + "flammable", + "flanked", + "flanking", + "flannels", + "flap", + "flaring", + "flashback", + "flashbulb", + "flashcard", + "flashily", + "flashing", + "flashy", + "flask", + "flatbed", + "flatfoot", + "flatly", + "flatness", + "flatten", + "flattered", + "flatterer", + "flattery", + "flattop", + "flatware", + "flatworm", + "flavored", + "flavorful", + "flavoring", + "flaxseed", + "fled", + "fleshed", + "fleshy", + "flick", + "flier", + "flight", + "flinch", + "fling", + "flint", + "flip", + "flirt", + "float", + "flock", + "flogging", + "flop", + "floral", + "florist", + "floss", + "flounder", + "flyable", + "flyaway", + "flyer", + "flying", + "flyover", + "flypaper", + "foam", + "foe", + "fog", + "foil", + "folic", + "folk", + "follicle", + "follow", + "fondling", + "fondly", + "fondness", + "fondue", + "font", + "food", + "fool", + "footage", + "football", + "footbath", + "footboard", + "footer", + "footgear", + "foothill", + "foothold", + "footing", + "footless", + "footman", + "footnote", + "footpad", + "footpath", + "footprint", + "footrest", + "footsie", + "footsore", + "footwear", + "footwork", + "fossil", + "foster", + "founder", + "founding", + "fountain", + "fox", + "foyer", + "fraction", + "fracture", + "fragile", + "fragility", + "fragment", + "fragrance", + "fragrant", + "frail", + "frame", + "framing", + "frantic", + "fraternal", + "frayed", + "fraying", + "frays", + "freckled", + "freckles", + "freebase", + "freebee", + "freebie", + "freedom", + "freefall", + "freehand", + "freeing", + "freeload", + "freely", + "freemason", + "freeness", + "freestyle", + "freeware", + "freeway", + "freewill", + "freezable", + "freezing", + "freight", + "french", + "frenzied", + "frenzy", + "frequency", + "frequent", + "fresh", + "fretful", + "fretted", + "friction", + "friday", + "fridge", + "fried", + "friend", + "frighten", + "frightful", + "frigidity", + "frigidly", + "frill", + "fringe", + "frisbee", + "frisk", + "fritter", + "frivolous", + "frolic", + "from", + "front", + "frostbite", + "frosted", + "frostily", + "frosting", + "frostlike", + "frosty", + "froth", + "frown", + "frozen", + "fructose", + "frugality", + "frugally", + "fruit", + "frustrate", + "frying", + "gab", + "gaffe", + "gag", + "gainfully", + "gaining", + "gains", + "gala", + "gallantly", + "galleria", + "gallery", + "galley", + "gallon", + "gallows", + "gallstone", + "galore", + "galvanize", + "gambling", + "game", + "gaming", + "gamma", + "gander", + "gangly", + "gangrene", + "gangway", + "gap", + "garage", + "garbage", + "garden", + "gargle", + "garland", + "garlic", + "garment", + "garnet", + "garnish", + "garter", + "gas", + "gatherer", + "gathering", + "gating", + "gauging", + "gauntlet", + "gauze", + "gave", + "gawk", + "gazing", + "gear", + "gecko", + "geek", + "geiger", + "gem", + "gender", + "generic", + "generous", + "genetics", + "genre", + "gentile", + "gentleman", + "gently", + "gents", + "geography", + "geologic", + "geologist", + "geology", + "geometric", + "geometry", + "geranium", + "gerbil", + "geriatric", + "germicide", + "germinate", + "germless", + "germproof", + "gestate", + "gestation", + "gesture", + "getaway", + "getting", + "getup", + "giant", + "gibberish", + "giblet", + "giddily", + "giddiness", + "giddy", + "gift", + "gigabyte", + "gigahertz", + "gigantic", + "giggle", + "giggling", + "giggly", + "gigolo", + "gilled", + "gills", + "gimmick", + "girdle", + "giveaway", + "given", + "giver", + "giving", + "gizmo", + "gizzard", + "glacial", + "glacier", + "glade", + "gladiator", + "gladly", + "glamorous", + "glamour", + "glance", + "glancing", + "glandular", + "glare", + "glaring", + "glass", + "glaucoma", + "glazing", + "gleaming", + "gleeful", + "glider", + "gliding", + "glimmer", + "glimpse", + "glisten", + "glitch", + "glitter", + "glitzy", + "gloater", + "gloating", + "gloomily", + "gloomy", + "glorified", + "glorifier", + "glorify", + "glorious", + "glory", + "gloss", + "glove", + "glowing", + "glowworm", + "glucose", + "glue", + "gluten", + "glutinous", + "glutton", + "gnarly", + "gnat", + "goal", + "goatskin", + "goes", + "goggles", + "going", + "goldfish", + "goldmine", + "goldsmith", + "golf", + "goliath", + "gonad", + "gondola", + "gone", + "gong", + "good", + "gooey", + "goofball", + "goofiness", + "goofy", + "google", + "goon", + "gopher", + "gore", + "gorged", + "gorgeous", + "gory", + "gosling", + "gossip", + "gothic", + "gotten", + "gout", + "gown", + "grab", + "graceful", + "graceless", + "gracious", + "gradation", + "graded", + "grader", + "gradient", + "grading", + "gradually", + "graduate", + "graffiti", + "grafted", + "grafting", + "grain", + "granddad", + "grandkid", + "grandly", + "grandma", + "grandpa", + "grandson", + "granite", + "granny", + "granola", + "grant", + "granular", + "grape", + "graph", + "grapple", + "grappling", + "grasp", + "grass", + "gratified", + "gratify", + "grating", + "gratitude", + "gratuity", + "gravel", + "graveness", + "graves", + "graveyard", + "gravitate", + "gravity", + "gravy", + "gray", + "grazing", + "greasily", + "greedily", + "greedless", + "greedy", + "green", + "greeter", + "greeting", + "grew", + "greyhound", + "grid", + "grief", + "grievance", + "grieving", + "grievous", + "grill", + "grimace", + "grimacing", + "grime", + "griminess", + "grimy", + "grinch", + "grinning", + "grip", + "gristle", + "grit", + "groggily", + "groggy", + "groin", + "groom", + "groove", + "grooving", + "groovy", + "grope", + "ground", + "grouped", + "grout", + "grove", + "grower", + "growing", + "growl", + "grub", + "grudge", + "grudging", + "grueling", + "gruffly", + "grumble", + "grumbling", + "grumbly", + "grumpily", + "grunge", + "grunt", + "guacamole", + "guidable", + "guidance", + "guide", + "guiding", + "guileless", + "guise", + "gulf", + "gullible", + "gully", + "gulp", + "gumball", + "gumdrop", + "gumminess", + "gumming", + "gummy", + "gurgle", + "gurgling", + "guru", + "gush", + "gusto", + "gusty", + "gutless", + "guts", + "gutter", + "guy", + "guzzler", + "gyration", + "habitable", + "habitant", + "habitat", + "habitual", + "hacked", + "hacker", + "hacking", + "hacksaw", + "had", + "haggler", + "haiku", + "half", + "halogen", + "halt", + "halved", + "halves", + "hamburger", + "hamlet", + "hammock", + "hamper", + "hamster", + "hamstring", + "handbag", + "handball", + "handbook", + "handbrake", + "handcart", + "handclap", + "handclasp", + "handcraft", + "handcuff", + "handed", + "handful", + "handgrip", + "handgun", + "handheld", + "handiness", + "handiwork", + "handlebar", + "handled", + "handler", + "handling", + "handmade", + "handoff", + "handpick", + "handprint", + "handrail", + "handsaw", + "handset", + "handsfree", + "handshake", + "handstand", + "handwash", + "handwork", + "handwoven", + "handwrite", + "handyman", + "hangnail", + "hangout", + "hangover", + "hangup", + "hankering", + "hankie", + "hanky", + "haphazard", + "happening", + "happier", + "happiest", + "happily", + "happiness", + "happy", + "harbor", + "hardcopy", + "hardcore", + "hardcover", + "harddisk", + "hardened", + "hardener", + "hardening", + "hardhat", + "hardhead", + "hardiness", + "hardly", + "hardness", + "hardship", + "hardware", + "hardwired", + "hardwood", + "hardy", + "harmful", + "harmless", + "harmonica", + "harmonics", + "harmonize", + "harmony", + "harness", + "harpist", + "harsh", + "harvest", + "hash", + "hassle", + "haste", + "hastily", + "hastiness", + "hasty", + "hatbox", + "hatchback", + "hatchery", + "hatchet", + "hatching", + "hatchling", + "hate", + "hatless", + "hatred", + "haunt", + "haven", + "hazard", + "hazelnut", + "hazily", + "haziness", + "hazing", + "hazy", + "headache", + "headband", + "headboard", + "headcount", + "headdress", + "headed", + "header", + "headfirst", + "headgear", + "heading", + "headlamp", + "headless", + "headlock", + "headphone", + "headpiece", + "headrest", + "headroom", + "headscarf", + "headset", + "headsman", + "headstand", + "headstone", + "headway", + "headwear", + "heap", + "heat", + "heave", + "heavily", + "heaviness", + "heaving", + "hedge", + "hedging", + "heftiness", + "hefty", + "helium", + "helmet", + "helper", + "helpful", + "helping", + "helpless", + "helpline", + "hemlock", + "hemstitch", + "hence", + "henchman", + "henna", + "herald", + "herbal", + "herbicide", + "herbs", + "heritage", + "hermit", + "heroics", + "heroism", + "herring", + "herself", + "hertz", + "hesitancy", + "hesitant", + "hesitate", + "hexagon", + "hexagram", + "hubcap", + "huddle", + "huddling", + "huff", + "hug", + "hula", + "hulk", + "hull", + "human", + "humble", + "humbling", + "humbly", + "humid", + "humiliate", + "humility", + "humming", + "hummus", + "humongous", + "humorist", + "humorless", + "humorous", + "humpback", + "humped", + "humvee", + "hunchback", + "hundredth", + "hunger", + "hungrily", + "hungry", + "hunk", + "hunter", + "hunting", + "huntress", + "huntsman", + "hurdle", + "hurled", + "hurler", + "hurling", + "hurray", + "hurricane", + "hurried", + "hurry", + "hurt", + "husband", + "hush", + "husked", + "huskiness", + "hut", + "hybrid", + "hydrant", + "hydrated", + "hydration", + "hydrogen", + "hydroxide", + "hyperlink", + "hypertext", + "hyphen", + "hypnoses", + "hypnosis", + "hypnotic", + "hypnotism", + "hypnotist", + "hypnotize", + "hypocrisy", + "hypocrite", + "ibuprofen", + "ice", + "iciness", + "icing", + "icky", + "icon", + "icy", + "idealism", + "idealist", + "idealize", + "ideally", + "idealness", + "identical", + "identify", + "identity", + "ideology", + "idiocy", + "idiom", + "idly", + "igloo", + "ignition", + "ignore", + "iguana", + "illicitly", + "illusion", + "illusive", + "image", + "imaginary", + "imagines", + "imaging", + "imbecile", + "imitate", + "imitation", + "immature", + "immerse", + "immersion", + "imminent", + "immobile", + "immodest", + "immorally", + "immortal", + "immovable", + "immovably", + "immunity", + "immunize", + "impaired", + "impale", + "impart", + "impatient", + "impeach", + "impeding", + "impending", + "imperfect", + "imperial", + "impish", + "implant", + "implement", + "implicate", + "implicit", + "implode", + "implosion", + "implosive", + "imply", + "impolite", + "important", + "importer", + "impose", + "imposing", + "impotence", + "impotency", + "impotent", + "impound", + "imprecise", + "imprint", + "imprison", + "impromptu", + "improper", + "improve", + "improving", + "improvise", + "imprudent", + "impulse", + "impulsive", + "impure", + "impurity", + "iodine", + "iodize", + "ion", + "ipad", + "iphone", + "ipod", + "irate", + "irk", + "iron", + "irregular", + "irrigate", + "irritable", + "irritably", + "irritant", + "irritate", + "islamic", + "islamist", + "isolated", + "isolating", + "isolation", + "isotope", + "issue", + "issuing", + "italicize", + "italics", + "item", + "itinerary", + "itunes", + "ivory", + "ivy", + "jab", + "jackal", + "jacket", + "jackknife", + "jackpot", + "jailbird", + "jailbreak", + "jailer", + "jailhouse", + "jalapeno", + "jam", + "janitor", + "january", + "jargon", + "jarring", + "jasmine", + "jaundice", + "jaunt", + "java", + "jawed", + "jawless", + "jawline", + "jaws", + "jaybird", + "jaywalker", + "jazz", + "jeep", + "jeeringly", + "jellied", + "jelly", + "jersey", + "jester", + "jet", + "jiffy", + "jigsaw", + "jimmy", + "jingle", + "jingling", + "jinx", + "jitters", + "jittery", + "job", + "jockey", + "jockstrap", + "jogger", + "jogging", + "john", + "joining", + "jokester", + "jokingly", + "jolliness", + "jolly", + "jolt", + "jot", + "jovial", + "joyfully", + "joylessly", + "joyous", + "joyride", + "joystick", + "jubilance", + "jubilant", + "judge", + "judgingly", + "judicial", + "judiciary", + "judo", + "juggle", + "juggling", + "jugular", + "juice", + "juiciness", + "juicy", + "jujitsu", + "jukebox", + "july", + "jumble", + "jumbo", + "jump", + "junction", + "juncture", + "june", + "junior", + "juniper", + "junkie", + "junkman", + "junkyard", + "jurist", + "juror", + "jury", + "justice", + "justifier", + "justify", + "justly", + "justness", + "juvenile", + "kabob", + "kangaroo", + "karaoke", + "karate", + "karma", + "kebab", + "keenly", + "keenness", + "keep", + "keg", + "kelp", + "kennel", + "kept", + "kerchief", + "kerosene", + "kettle", + "kick", + "kiln", + "kilobyte", + "kilogram", + "kilometer", + "kilowatt", + "kilt", + "kimono", + "kindle", + "kindling", + "kindly", + "kindness", + "kindred", + "kinetic", + "kinfolk", + "king", + "kinship", + "kinsman", + "kinswoman", + "kissable", + "kisser", + "kissing", + "kitchen", + "kite", + "kitten", + "kitty", + "kiwi", + "kleenex", + "knapsack", + "knee", + "knelt", + "knickers", + "knoll", + "koala", + "kooky", + "kosher", + "krypton", + "kudos", + "kung", + "labored", + "laborer", + "laboring", + "laborious", + "labrador", + "ladder", + "ladies", + "ladle", + "ladybug", + "ladylike", + "lagged", + "lagging", + "lagoon", + "lair", + "lake", + "lance", + "landed", + "landfall", + "landfill", + "landing", + "landlady", + "landless", + "landline", + "landlord", + "landmark", + "landmass", + "landmine", + "landowner", + "landscape", + "landside", + "landslide", + "language", + "lankiness", + "lanky", + "lantern", + "lapdog", + "lapel", + "lapped", + "lapping", + "laptop", + "lard", + "large", + "lark", + "lash", + "lasso", + "last", + "latch", + "late", + "lather", + "latitude", + "latrine", + "latter", + "latticed", + "launch", + "launder", + "laundry", + "laurel", + "lavender", + "lavish", + "laxative", + "lazily", + "laziness", + "lazy", + "lecturer", + "left", + "legacy", + "legal", + "legend", + "legged", + "leggings", + "legible", + "legibly", + "legislate", + "lego", + "legroom", + "legume", + "legwarmer", + "legwork", + "lemon", + "lend", + "length", + "lens", + "lent", + "leotard", + "lesser", + "letdown", + "lethargic", + "lethargy", + "letter", + "lettuce", + "level", + "leverage", + "levers", + "levitate", + "levitator", + "liability", + "liable", + "liberty", + "librarian", + "library", + "licking", + "licorice", + "lid", + "life", + "lifter", + "lifting", + "liftoff", + "ligament", + "likely", + "likeness", + "likewise", + "liking", + "lilac", + "lilly", + "lily", + "limb", + "limeade", + "limelight", + "limes", + "limit", + "limping", + "limpness", + "line", + "lingo", + "linguini", + "linguist", + "lining", + "linked", + "linoleum", + "linseed", + "lint", + "lion", + "lip", + "liquefy", + "liqueur", + "liquid", + "lisp", + "list", + "litigate", + "litigator", + "litmus", + "litter", + "little", + "livable", + "lived", + "lively", + "liver", + "livestock", + "lividly", + "living", + "lizard", + "lubricant", + "lubricate", + "lucid", + "luckily", + "luckiness", + "luckless", + "lucrative", + "ludicrous", + "lugged", + "lukewarm", + "lullaby", + "lumber", + "luminance", + "luminous", + "lumpiness", + "lumping", + "lumpish", + "lunacy", + "lunar", + "lunchbox", + "luncheon", + "lunchroom", + "lunchtime", + "lung", + "lurch", + "lure", + "luridness", + "lurk", + "lushly", + "lushness", + "luster", + "lustfully", + "lustily", + "lustiness", + "lustrous", + "lusty", + "luxurious", + "luxury", + "lying", + "lyrically", + "lyricism", + "lyricist", + "lyrics", + "macarena", + "macaroni", + "macaw", + "mace", + "machine", + "machinist", + "magazine", + "magenta", + "maggot", + "magical", + "magician", + "magma", + "magnesium", + "magnetic", + "magnetism", + "magnetize", + "magnifier", + "magnify", + "magnitude", + "magnolia", + "mahogany", + "maimed", + "majestic", + "majesty", + "majorette", + "majority", + "makeover", + "maker", + "makeshift", + "making", + "malformed", + "malt", + "mama", + "mammal", + "mammary", + "mammogram", + "manager", + "managing", + "manatee", + "mandarin", + "mandate", + "mandatory", + "mandolin", + "manger", + "mangle", + "mango", + "mangy", + "manhandle", + "manhole", + "manhood", + "manhunt", + "manicotti", + "manicure", + "manifesto", + "manila", + "mankind", + "manlike", + "manliness", + "manly", + "manmade", + "manned", + "mannish", + "manor", + "manpower", + "mantis", + "mantra", + "manual", + "many", + "map", + "marathon", + "marauding", + "marbled", + "marbles", + "marbling", + "march", + "mardi", + "margarine", + "margarita", + "margin", + "marigold", + "marina", + "marine", + "marital", + "maritime", + "marlin", + "marmalade", + "maroon", + "married", + "marrow", + "marry", + "marshland", + "marshy", + "marsupial", + "marvelous", + "marxism", + "mascot", + "masculine", + "mashed", + "mashing", + "massager", + "masses", + "massive", + "mastiff", + "matador", + "matchbook", + "matchbox", + "matcher", + "matching", + "matchless", + "material", + "maternal", + "maternity", + "math", + "mating", + "matriarch", + "matrimony", + "matrix", + "matron", + "matted", + "matter", + "maturely", + "maturing", + "maturity", + "mauve", + "maverick", + "maximize", + "maximum", + "maybe", + "mayday", + "mayflower", + "moaner", + "moaning", + "mobile", + "mobility", + "mobilize", + "mobster", + "mocha", + "mocker", + "mockup", + "modified", + "modify", + "modular", + "modulator", + "module", + "moisten", + "moistness", + "moisture", + "molar", + "molasses", + "mold", + "molecular", + "molecule", + "molehill", + "mollusk", + "mom", + "monastery", + "monday", + "monetary", + "monetize", + "moneybags", + "moneyless", + "moneywise", + "mongoose", + "mongrel", + "monitor", + "monkhood", + "monogamy", + "monogram", + "monologue", + "monopoly", + "monorail", + "monotone", + "monotype", + "monoxide", + "monsieur", + "monsoon", + "monstrous", + "monthly", + "monument", + "moocher", + "moodiness", + "moody", + "mooing", + "moonbeam", + "mooned", + "moonlight", + "moonlike", + "moonlit", + "moonrise", + "moonscape", + "moonshine", + "moonstone", + "moonwalk", + "mop", + "morale", + "morality", + "morally", + "morbidity", + "morbidly", + "morphine", + "morphing", + "morse", + "mortality", + "mortally", + "mortician", + "mortified", + "mortify", + "mortuary", + "mosaic", + "mossy", + "most", + "mothball", + "mothproof", + "motion", + "motivate", + "motivator", + "motive", + "motocross", + "motor", + "motto", + "mountable", + "mountain", + "mounted", + "mounting", + "mourner", + "mournful", + "mouse", + "mousiness", + "moustache", + "mousy", + "mouth", + "movable", + "move", + "movie", + "moving", + "mower", + "mowing", + "much", + "muck", + "mud", + "mug", + "mulberry", + "mulch", + "mule", + "mulled", + "mullets", + "multiple", + "multiply", + "multitask", + "multitude", + "mumble", + "mumbling", + "mumbo", + "mummified", + "mummify", + "mummy", + "mumps", + "munchkin", + "mundane", + "municipal", + "muppet", + "mural", + "murkiness", + "murky", + "murmuring", + "muscular", + "museum", + "mushily", + "mushiness", + "mushroom", + "mushy", + "music", + "musket", + "muskiness", + "musky", + "mustang", + "mustard", + "muster", + "mustiness", + "musty", + "mutable", + "mutate", + "mutation", + "mute", + "mutilated", + "mutilator", + "mutiny", + "mutt", + "mutual", + "muzzle", + "myself", + "myspace", + "mystified", + "mystify", + "myth", + "nacho", + "nag", + "nail", + "name", + "naming", + "nanny", + "nanometer", + "nape", + "napkin", + "napped", + "napping", + "nappy", + "narrow", + "nastily", + "nastiness", + "national", + "native", + "nativity", + "natural", + "nature", + "naturist", + "nautical", + "navigate", + "navigator", + "navy", + "nearby", + "nearest", + "nearly", + "nearness", + "neatly", + "neatness", + "nebula", + "nebulizer", + "nectar", + "negate", + "negation", + "negative", + "neglector", + "negligee", + "negligent", + "negotiate", + "nemeses", + "nemesis", + "neon", + "nephew", + "nerd", + "nervous", + "nervy", + "nest", + "net", + "neurology", + "neuron", + "neurosis", + "neurotic", + "neuter", + "neutron", + "never", + "next", + "nibble", + "nickname", + "nicotine", + "niece", + "nifty", + "nimble", + "nimbly", + "nineteen", + "ninetieth", + "ninja", + "nintendo", + "ninth", + "nuclear", + "nuclei", + "nucleus", + "nugget", + "nullify", + "number", + "numbing", + "numbly", + "numbness", + "numeral", + "numerate", + "numerator", + "numeric", + "numerous", + "nuptials", + "nursery", + "nursing", + "nurture", + "nutcase", + "nutlike", + "nutmeg", + "nutrient", + "nutshell", + "nuttiness", + "nutty", + "nuzzle", + "nylon", + "oaf", + "oak", + "oasis", + "oat", + "obedience", + "obedient", + "obituary", + "object", + "obligate", + "obliged", + "oblivion", + "oblivious", + "oblong", + "obnoxious", + "oboe", + "obscure", + "obscurity", + "observant", + "observer", + "observing", + "obsessed", + "obsession", + "obsessive", + "obsolete", + "obstacle", + "obstinate", + "obstruct", + "obtain", + "obtrusive", + "obtuse", + "obvious", + "occultist", + "occupancy", + "occupant", + "occupier", + "occupy", + "ocean", + "ocelot", + "octagon", + "octane", + "october", + "octopus", + "ogle", + "oil", + "oink", + "ointment", + "okay", + "old", + "olive", + "olympics", + "omega", + "omen", + "ominous", + "omission", + "omit", + "omnivore", + "onboard", + "oncoming", + "ongoing", + "onion", + "online", + "onlooker", + "only", + "onscreen", + "onset", + "onshore", + "onslaught", + "onstage", + "onto", + "onward", + "onyx", + "oops", + "ooze", + "oozy", + "opacity", + "opal", + "open", + "operable", + "operate", + "operating", + "operation", + "operative", + "operator", + "opium", + "opossum", + "opponent", + "oppose", + "opposing", + "opposite", + "oppressed", + "oppressor", + "opt", + "opulently", + "osmosis", + "other", + "otter", + "ouch", + "ought", + "ounce", + "outage", + "outback", + "outbid", + "outboard", + "outbound", + "outbreak", + "outburst", + "outcast", + "outclass", + "outcome", + "outdated", + "outdoors", + "outer", + "outfield", + "outfit", + "outflank", + "outgoing", + "outgrow", + "outhouse", + "outing", + "outlast", + "outlet", + "outline", + "outlook", + "outlying", + "outmatch", + "outmost", + "outnumber", + "outplayed", + "outpost", + "outpour", + "output", + "outrage", + "outrank", + "outreach", + "outright", + "outscore", + "outsell", + "outshine", + "outshoot", + "outsider", + "outskirts", + "outsmart", + "outsource", + "outspoken", + "outtakes", + "outthink", + "outward", + "outweigh", + "outwit", + "oval", + "ovary", + "oven", + "overact", + "overall", + "overarch", + "overbid", + "overbill", + "overbite", + "overblown", + "overboard", + "overbook", + "overbuilt", + "overcast", + "overcoat", + "overcome", + "overcook", + "overcrowd", + "overdraft", + "overdrawn", + "overdress", + "overdrive", + "overdue", + "overeager", + "overeater", + "overexert", + "overfed", + "overfeed", + "overfill", + "overflow", + "overfull", + "overgrown", + "overhand", + "overhang", + "overhaul", + "overhead", + "overhear", + "overheat", + "overhung", + "overjoyed", + "overkill", + "overlabor", + "overlaid", + "overlap", + "overlay", + "overload", + "overlook", + "overlord", + "overlying", + "overnight", + "overpass", + "overpay", + "overplant", + "overplay", + "overpower", + "overprice", + "overrate", + "overreach", + "overreact", + "override", + "overripe", + "overrule", + "overrun", + "overshoot", + "overshot", + "oversight", + "oversized", + "oversleep", + "oversold", + "overspend", + "overstate", + "overstay", + "overstep", + "overstock", + "overstuff", + "oversweet", + "overtake", + "overthrow", + "overtime", + "overtly", + "overtone", + "overture", + "overturn", + "overuse", + "overvalue", + "overview", + "overwrite", + "owl", + "oxford", + "oxidant", + "oxidation", + "oxidize", + "oxidizing", + "oxygen", + "oxymoron", + "oyster", + "ozone", + "paced", + "pacemaker", + "pacific", + "pacifier", + "pacifism", + "pacifist", + "pacify", + "padded", + "padding", + "paddle", + "paddling", + "padlock", + "pagan", + "pager", + "paging", + "pajamas", + "palace", + "palatable", + "palm", + "palpable", + "palpitate", + "paltry", + "pampered", + "pamperer", + "pampers", + "pamphlet", + "panama", + "pancake", + "pancreas", + "panda", + "pandemic", + "pang", + "panhandle", + "panic", + "panning", + "panorama", + "panoramic", + "panther", + "pantomime", + "pantry", + "pants", + "pantyhose", + "paparazzi", + "papaya", + "paper", + "paprika", + "papyrus", + "parabola", + "parachute", + "parade", + "paradox", + "paragraph", + "parakeet", + "paralegal", + "paralyses", + "paralysis", + "paralyze", + "paramedic", + "parameter", + "paramount", + "parasail", + "parasite", + "parasitic", + "parcel", + "parched", + "parchment", + "pardon", + "parish", + "parka", + "parking", + "parkway", + "parlor", + "parmesan", + "parole", + "parrot", + "parsley", + "parsnip", + "partake", + "parted", + "parting", + "partition", + "partly", + "partner", + "partridge", + "party", + "passable", + "passably", + "passage", + "passcode", + "passenger", + "passerby", + "passing", + "passion", + "passive", + "passivism", + "passover", + "passport", + "password", + "pasta", + "pasted", + "pastel", + "pastime", + "pastor", + "pastrami", + "pasture", + "pasty", + "patchwork", + "patchy", + "paternal", + "paternity", + "path", + "patience", + "patient", + "patio", + "patriarch", + "patriot", + "patrol", + "patronage", + "patronize", + "pauper", + "pavement", + "paver", + "pavestone", + "pavilion", + "paving", + "pawing", + "payable", + "payback", + "paycheck", + "payday", + "payee", + "payer", + "paying", + "payment", + "payphone", + "payroll", + "pebble", + "pebbly", + "pecan", + "pectin", + "peculiar", + "peddling", + "pediatric", + "pedicure", + "pedigree", + "pedometer", + "pegboard", + "pelican", + "pellet", + "pelt", + "pelvis", + "penalize", + "penalty", + "pencil", + "pendant", + "pending", + "penholder", + "penknife", + "pennant", + "penniless", + "penny", + "penpal", + "pension", + "pentagon", + "pentagram", + "pep", + "perceive", + "percent", + "perch", + "percolate", + "perennial", + "perfected", + "perfectly", + "perfume", + "periscope", + "perish", + "perjurer", + "perjury", + "perkiness", + "perky", + "perm", + "peroxide", + "perpetual", + "perplexed", + "persecute", + "persevere", + "persuaded", + "persuader", + "pesky", + "peso", + "pessimism", + "pessimist", + "pester", + "pesticide", + "petal", + "petite", + "petition", + "petri", + "petroleum", + "petted", + "petticoat", + "pettiness", + "petty", + "petunia", + "phantom", + "phobia", + "phoenix", + "phonebook", + "phoney", + "phonics", + "phoniness", + "phony", + "phosphate", + "photo", + "phrase", + "phrasing", + "placard", + "placate", + "placidly", + "plank", + "planner", + "plant", + "plasma", + "plaster", + "plastic", + "plated", + "platform", + "plating", + "platinum", + "platonic", + "platter", + "platypus", + "plausible", + "plausibly", + "playable", + "playback", + "player", + "playful", + "playgroup", + "playhouse", + "playing", + "playlist", + "playmaker", + "playmate", + "playoff", + "playpen", + "playroom", + "playset", + "plaything", + "playtime", + "plaza", + "pleading", + "pleat", + "pledge", + "plentiful", + "plenty", + "plethora", + "plexiglas", + "pliable", + "plod", + "plop", + "plot", + "plow", + "ploy", + "pluck", + "plug", + "plunder", + "plunging", + "plural", + "plus", + "plutonium", + "plywood", + "poach", + "pod", + "poem", + "poet", + "pogo", + "pointed", + "pointer", + "pointing", + "pointless", + "pointy", + "poise", + "poison", + "poker", + "poking", + "polar", + "police", + "policy", + "polio", + "polish", + "politely", + "polka", + "polo", + "polyester", + "polygon", + "polygraph", + "polymer", + "poncho", + "pond", + "pony", + "popcorn", + "pope", + "poplar", + "popper", + "poppy", + "popsicle", + "populace", + "popular", + "populate", + "porcupine", + "pork", + "porous", + "porridge", + "portable", + "portal", + "portfolio", + "porthole", + "portion", + "portly", + "portside", + "poser", + "posh", + "posing", + "possible", + "possibly", + "possum", + "postage", + "postal", + "postbox", + "postcard", + "posted", + "poster", + "posting", + "postnasal", + "posture", + "postwar", + "pouch", + "pounce", + "pouncing", + "pound", + "pouring", + "pout", + "powdered", + "powdering", + "powdery", + "power", + "powwow", + "pox", + "praising", + "prance", + "prancing", + "pranker", + "prankish", + "prankster", + "prayer", + "praying", + "preacher", + "preaching", + "preachy", + "preamble", + "precinct", + "precise", + "precision", + "precook", + "precut", + "predator", + "predefine", + "predict", + "preface", + "prefix", + "preflight", + "preformed", + "pregame", + "pregnancy", + "pregnant", + "preheated", + "prelaunch", + "prelaw", + "prelude", + "premiere", + "premises", + "premium", + "prenatal", + "preoccupy", + "preorder", + "prepaid", + "prepay", + "preplan", + "preppy", + "preschool", + "prescribe", + "preseason", + "preset", + "preshow", + "president", + "presoak", + "press", + "presume", + "presuming", + "preteen", + "pretended", + "pretender", + "pretense", + "pretext", + "pretty", + "pretzel", + "prevail", + "prevalent", + "prevent", + "preview", + "previous", + "prewar", + "prewashed", + "prideful", + "pried", + "primal", + "primarily", + "primary", + "primate", + "primer", + "primp", + "princess", + "print", + "prior", + "prism", + "prison", + "prissy", + "pristine", + "privacy", + "private", + "privatize", + "prize", + "proactive", + "probable", + "probably", + "probation", + "probe", + "probing", + "probiotic", + "problem", + "procedure", + "process", + "proclaim", + "procreate", + "procurer", + "prodigal", + "prodigy", + "produce", + "product", + "profane", + "profanity", + "professed", + "professor", + "profile", + "profound", + "profusely", + "progeny", + "prognosis", + "program", + "progress", + "projector", + "prologue", + "prolonged", + "promenade", + "prominent", + "promoter", + "promotion", + "prompter", + "promptly", + "prone", + "prong", + "pronounce", + "pronto", + "proofing", + "proofread", + "proofs", + "propeller", + "properly", + "property", + "proponent", + "proposal", + "propose", + "props", + "prorate", + "protector", + "protegee", + "proton", + "prototype", + "protozoan", + "protract", + "protrude", + "proud", + "provable", + "proved", + "proven", + "provided", + "provider", + "providing", + "province", + "proving", + "provoke", + "provoking", + "provolone", + "prowess", + "prowler", + "prowling", + "proximity", + "proxy", + "prozac", + "prude", + "prudishly", + "prune", + "pruning", + "pry", + "psychic", + "public", + "publisher", + "pucker", + "pueblo", + "pug", + "pull", + "pulmonary", + "pulp", + "pulsate", + "pulse", + "pulverize", + "puma", + "pumice", + "pummel", + "punch", + "punctual", + "punctuate", + "punctured", + "pungent", + "punisher", + "punk", + "pupil", + "puppet", + "puppy", + "purchase", + "pureblood", + "purebred", + "purely", + "pureness", + "purgatory", + "purge", + "purging", + "purifier", + "purify", + "purist", + "puritan", + "purity", + "purple", + "purplish", + "purposely", + "purr", + "purse", + "pursuable", + "pursuant", + "pursuit", + "purveyor", + "pushcart", + "pushchair", + "pusher", + "pushiness", + "pushing", + "pushover", + "pushpin", + "pushup", + "pushy", + "putdown", + "putt", + "puzzle", + "puzzling", + "pyramid", + "pyromania", + "python", + "quack", + "quadrant", + "quail", + "quaintly", + "quake", + "quaking", + "qualified", + "qualifier", + "qualify", + "quality", + "qualm", + "quantum", + "quarrel", + "quarry", + "quartered", + "quarterly", + "quarters", + "quartet", + "quench", + "query", + "quicken", + "quickly", + "quickness", + "quicksand", + "quickstep", + "quiet", + "quill", + "quilt", + "quintet", + "quintuple", + "quirk", + "quit", + "quiver", + "quizzical", + "quotable", + "quotation", + "quote", + "rabid", + "race", + "racing", + "racism", + "rack", + "racoon", + "radar", + "radial", + "radiance", + "radiantly", + "radiated", + "radiation", + "radiator", + "radio", + "radish", + "raffle", + "raft", + "rage", + "ragged", + "raging", + "ragweed", + "raider", + "railcar", + "railing", + "railroad", + "railway", + "raisin", + "rake", + "raking", + "rally", + "ramble", + "rambling", + "ramp", + "ramrod", + "ranch", + "rancidity", + "random", + "ranged", + "ranger", + "ranging", + "ranked", + "ranking", + "ransack", + "ranting", + "rants", + "rare", + "rarity", + "rascal", + "rash", + "rasping", + "ravage", + "raven", + "ravine", + "raving", + "ravioli", + "ravishing", + "reabsorb", + "reach", + "reacquire", + "reaction", + "reactive", + "reactor", + "reaffirm", + "ream", + "reanalyze", + "reappear", + "reapply", + "reappoint", + "reapprove", + "rearrange", + "rearview", + "reason", + "reassign", + "reassure", + "reattach", + "reawake", + "rebalance", + "rebate", + "rebel", + "rebirth", + "reboot", + "reborn", + "rebound", + "rebuff", + "rebuild", + "rebuilt", + "reburial", + "rebuttal", + "recall", + "recant", + "recapture", + "recast", + "recede", + "recent", + "recess", + "recharger", + "recipient", + "recital", + "recite", + "reckless", + "reclaim", + "recliner", + "reclining", + "recluse", + "reclusive", + "recognize", + "recoil", + "recollect", + "recolor", + "reconcile", + "reconfirm", + "reconvene", + "recopy", + "record", + "recount", + "recoup", + "recovery", + "recreate", + "rectal", + "rectangle", + "rectified", + "rectify", + "recycled", + "recycler", + "recycling", + "reemerge", + "reenact", + "reenter", + "reentry", + "reexamine", + "referable", + "referee", + "reference", + "refill", + "refinance", + "refined", + "refinery", + "refining", + "refinish", + "reflected", + "reflector", + "reflex", + "reflux", + "refocus", + "refold", + "reforest", + "reformat", + "reformed", + "reformer", + "reformist", + "refract", + "refrain", + "refreeze", + "refresh", + "refried", + "refueling", + "refund", + "refurbish", + "refurnish", + "refusal", + "refuse", + "refusing", + "refutable", + "refute", + "regain", + "regalia", + "regally", + "reggae", + "regime", + "region", + "register", + "registrar", + "registry", + "regress", + "regretful", + "regroup", + "regular", + "regulate", + "regulator", + "rehab", + "reheat", + "rehire", + "rehydrate", + "reimburse", + "reissue", + "reiterate", + "rejoice", + "rejoicing", + "rejoin", + "rekindle", + "relapse", + "relapsing", + "relatable", + "related", + "relation", + "relative", + "relax", + "relay", + "relearn", + "release", + "relenting", + "reliable", + "reliably", + "reliance", + "reliant", + "relic", + "relieve", + "relieving", + "relight", + "relish", + "relive", + "reload", + "relocate", + "relock", + "reluctant", + "rely", + "remake", + "remark", + "remarry", + "rematch", + "remedial", + "remedy", + "remember", + "reminder", + "remindful", + "remission", + "remix", + "remnant", + "remodeler", + "remold", + "remorse", + "remote", + "removable", + "removal", + "removed", + "remover", + "removing", + "rename", + "renderer", + "rendering", + "rendition", + "renegade", + "renewable", + "renewably", + "renewal", + "renewed", + "renounce", + "renovate", + "renovator", + "rentable", + "rental", + "rented", + "renter", + "reoccupy", + "reoccur", + "reopen", + "reorder", + "repackage", + "repacking", + "repaint", + "repair", + "repave", + "repaying", + "repayment", + "repeal", + "repeated", + "repeater", + "repent", + "rephrase", + "replace", + "replay", + "replica", + "reply", + "reporter", + "repose", + "repossess", + "repost", + "repressed", + "reprimand", + "reprint", + "reprise", + "reproach", + "reprocess", + "reproduce", + "reprogram", + "reps", + "reptile", + "reptilian", + "repugnant", + "repulsion", + "repulsive", + "repurpose", + "reputable", + "reputably", + "request", + "require", + "requisite", + "reroute", + "rerun", + "resale", + "resample", + "rescuer", + "reseal", + "research", + "reselect", + "reseller", + "resemble", + "resend", + "resent", + "reset", + "reshape", + "reshoot", + "reshuffle", + "residence", + "residency", + "resident", + "residual", + "residue", + "resigned", + "resilient", + "resistant", + "resisting", + "resize", + "resolute", + "resolved", + "resonant", + "resonate", + "resort", + "resource", + "respect", + "resubmit", + "result", + "resume", + "resupply", + "resurface", + "resurrect", + "retail", + "retainer", + "retaining", + "retake", + "retaliate", + "retention", + "rethink", + "retinal", + "retired", + "retiree", + "retiring", + "retold", + "retool", + "retorted", + "retouch", + "retrace", + "retract", + "retrain", + "retread", + "retreat", + "retrial", + "retrieval", + "retriever", + "retry", + "return", + "retying", + "retype", + "reunion", + "reunite", + "reusable", + "reuse", + "reveal", + "reveler", + "revenge", + "revenue", + "reverb", + "revered", + "reverence", + "reverend", + "reversal", + "reverse", + "reversing", + "reversion", + "revert", + "revisable", + "revise", + "revision", + "revisit", + "revivable", + "revival", + "reviver", + "reviving", + "revocable", + "revoke", + "revolt", + "revolver", + "revolving", + "reward", + "rewash", + "rewind", + "rewire", + "reword", + "rework", + "rewrap", + "rewrite", + "rhyme", + "ribbon", + "ribcage", + "rice", + "riches", + "richly", + "richness", + "rickety", + "ricotta", + "riddance", + "ridden", + "ride", + "riding", + "rifling", + "rift", + "rigging", + "rigid", + "rigor", + "rimless", + "rimmed", + "rind", + "rink", + "rinse", + "rinsing", + "riot", + "ripcord", + "ripeness", + "ripening", + "ripping", + "ripple", + "rippling", + "riptide", + "rise", + "rising", + "risk", + "risotto", + "ritalin", + "ritzy", + "rival", + "riverbank", + "riverbed", + "riverboat", + "riverside", + "riveter", + "riveting", + "roamer", + "roaming", + "roast", + "robbing", + "robe", + "robin", + "robotics", + "robust", + "rockband", + "rocker", + "rocket", + "rockfish", + "rockiness", + "rocking", + "rocklike", + "rockslide", + "rockstar", + "rocky", + "rogue", + "roman", + "romp", + "rope", + "roping", + "roster", + "rosy", + "rotten", + "rotting", + "rotunda", + "roulette", + "rounding", + "roundish", + "roundness", + "roundup", + "roundworm", + "routine", + "routing", + "rover", + "roving", + "royal", + "rubbed", + "rubber", + "rubbing", + "rubble", + "rubdown", + "ruby", + "ruckus", + "rudder", + "rug", + "ruined", + "rule", + "rumble", + "rumbling", + "rummage", + "rumor", + "runaround", + "rundown", + "runner", + "running", + "runny", + "runt", + "runway", + "rupture", + "rural", + "ruse", + "rush", + "rust", + "rut", + "sabbath", + "sabotage", + "sacrament", + "sacred", + "sacrifice", + "sadden", + "saddlebag", + "saddled", + "saddling", + "sadly", + "sadness", + "safari", + "safeguard", + "safehouse", + "safely", + "safeness", + "saffron", + "saga", + "sage", + "sagging", + "saggy", + "said", + "saint", + "sake", + "salad", + "salami", + "salaried", + "salary", + "saline", + "salon", + "saloon", + "salsa", + "salt", + "salutary", + "salute", + "salvage", + "salvaging", + "salvation", + "same", + "sample", + "sampling", + "sanction", + "sanctity", + "sanctuary", + "sandal", + "sandbag", + "sandbank", + "sandbar", + "sandblast", + "sandbox", + "sanded", + "sandfish", + "sanding", + "sandlot", + "sandpaper", + "sandpit", + "sandstone", + "sandstorm", + "sandworm", + "sandy", + "sanitary", + "sanitizer", + "sank", + "santa", + "sapling", + "sappiness", + "sappy", + "sarcasm", + "sarcastic", + "sardine", + "sash", + "sasquatch", + "sassy", + "satchel", + "satiable", + "satin", + "satirical", + "satisfied", + "satisfy", + "saturate", + "saturday", + "sauciness", + "saucy", + "sauna", + "savage", + "savanna", + "saved", + "savings", + "savior", + "savor", + "saxophone", + "say", + "scabbed", + "scabby", + "scalded", + "scalding", + "scale", + "scaling", + "scallion", + "scallop", + "scalping", + "scam", + "scandal", + "scanner", + "scanning", + "scant", + "scapegoat", + "scarce", + "scarcity", + "scarecrow", + "scared", + "scarf", + "scarily", + "scariness", + "scarring", + "scary", + "scavenger", + "scenic", + "schedule", + "schematic", + "scheme", + "scheming", + "schilling", + "schnapps", + "scholar", + "science", + "scientist", + "scion", + "scoff", + "scolding", + "scone", + "scoop", + "scooter", + "scope", + "scorch", + "scorebook", + "scorecard", + "scored", + "scoreless", + "scorer", + "scoring", + "scorn", + "scorpion", + "scotch", + "scoundrel", + "scoured", + "scouring", + "scouting", + "scouts", + "scowling", + "scrabble", + "scraggly", + "scrambled", + "scrambler", + "scrap", + "scratch", + "scrawny", + "screen", + "scribble", + "scribe", + "scribing", + "scrimmage", + "script", + "scroll", + "scrooge", + "scrounger", + "scrubbed", + "scrubber", + "scruffy", + "scrunch", + "scrutiny", + "scuba", + "scuff", + "sculptor", + "sculpture", + "scurvy", + "scuttle", + "secluded", + "secluding", + "seclusion", + "second", + "secrecy", + "secret", + "sectional", + "sector", + "secular", + "securely", + "security", + "sedan", + "sedate", + "sedation", + "sedative", + "sediment", + "seduce", + "seducing", + "segment", + "seismic", + "seizing", + "seldom", + "selected", + "selection", + "selective", + "selector", + "self", + "seltzer", + "semantic", + "semester", + "semicolon", + "semifinal", + "seminar", + "semisoft", + "semisweet", + "senate", + "senator", + "send", + "senior", + "senorita", + "sensation", + "sensitive", + "sensitize", + "sensually", + "sensuous", + "sepia", + "september", + "septic", + "septum", + "sequel", + "sequence", + "sequester", + "series", + "sermon", + "serotonin", + "serpent", + "serrated", + "serve", + "service", + "serving", + "sesame", + "sessions", + "setback", + "setting", + "settle", + "settling", + "setup", + "sevenfold", + "seventeen", + "seventh", + "seventy", + "severity", + "shabby", + "shack", + "shaded", + "shadily", + "shadiness", + "shading", + "shadow", + "shady", + "shaft", + "shakable", + "shakily", + "shakiness", + "shaking", + "shaky", + "shale", + "shallot", + "shallow", + "shame", + "shampoo", + "shamrock", + "shank", + "shanty", + "shape", + "shaping", + "share", + "sharpener", + "sharper", + "sharpie", + "sharply", + "sharpness", + "shawl", + "sheath", + "shed", + "sheep", + "sheet", + "shelf", + "shell", + "shelter", + "shelve", + "shelving", + "sherry", + "shield", + "shifter", + "shifting", + "shiftless", + "shifty", + "shimmer", + "shimmy", + "shindig", + "shine", + "shingle", + "shininess", + "shining", + "shiny", + "ship", + "shirt", + "shivering", + "shock", + "shone", + "shoplift", + "shopper", + "shopping", + "shoptalk", + "shore", + "shortage", + "shortcake", + "shortcut", + "shorten", + "shorter", + "shorthand", + "shortlist", + "shortly", + "shortness", + "shorts", + "shortwave", + "shorty", + "shout", + "shove", + "showbiz", + "showcase", + "showdown", + "shower", + "showgirl", + "showing", + "showman", + "shown", + "showoff", + "showpiece", + "showplace", + "showroom", + "showy", + "shrank", + "shrapnel", + "shredder", + "shredding", + "shrewdly", + "shriek", + "shrill", + "shrimp", + "shrine", + "shrink", + "shrivel", + "shrouded", + "shrubbery", + "shrubs", + "shrug", + "shrunk", + "shucking", + "shudder", + "shuffle", + "shuffling", + "shun", + "shush", + "shut", + "shy", + "siamese", + "siberian", + "sibling", + "siding", + "sierra", + "siesta", + "sift", + "sighing", + "silenced", + "silencer", + "silent", + "silica", + "silicon", + "silk", + "silliness", + "silly", + "silo", + "silt", + "silver", + "similarly", + "simile", + "simmering", + "simple", + "simplify", + "simply", + "sincere", + "sincerity", + "singer", + "singing", + "single", + "singular", + "sinister", + "sinless", + "sinner", + "sinuous", + "sip", + "siren", + "sister", + "sitcom", + "sitter", + "sitting", + "situated", + "situation", + "sixfold", + "sixteen", + "sixth", + "sixties", + "sixtieth", + "sixtyfold", + "sizable", + "sizably", + "size", + "sizing", + "sizzle", + "sizzling", + "skater", + "skating", + "skedaddle", + "skeletal", + "skeleton", + "skeptic", + "sketch", + "skewed", + "skewer", + "skid", + "skied", + "skier", + "skies", + "skiing", + "skilled", + "skillet", + "skillful", + "skimmed", + "skimmer", + "skimming", + "skimpily", + "skincare", + "skinhead", + "skinless", + "skinning", + "skinny", + "skintight", + "skipper", + "skipping", + "skirmish", + "skirt", + "skittle", + "skydiver", + "skylight", + "skyline", + "skype", + "skyrocket", + "skyward", + "slab", + "slacked", + "slacker", + "slacking", + "slackness", + "slacks", + "slain", + "slam", + "slander", + "slang", + "slapping", + "slapstick", + "slashed", + "slashing", + "slate", + "slather", + "slaw", + "sled", + "sleek", + "sleep", + "sleet", + "sleeve", + "slept", + "sliceable", + "sliced", + "slicer", + "slicing", + "slick", + "slider", + "slideshow", + "sliding", + "slighted", + "slighting", + "slightly", + "slimness", + "slimy", + "slinging", + "slingshot", + "slinky", + "slip", + "slit", + "sliver", + "slobbery", + "slogan", + "sloped", + "sloping", + "sloppily", + "sloppy", + "slot", + "slouching", + "slouchy", + "sludge", + "slug", + "slum", + "slurp", + "slush", + "sly", + "small", + "smartly", + "smartness", + "smasher", + "smashing", + "smashup", + "smell", + "smelting", + "smile", + "smilingly", + "smirk", + "smite", + "smith", + "smitten", + "smock", + "smog", + "smoked", + "smokeless", + "smokiness", + "smoking", + "smoky", + "smolder", + "smooth", + "smother", + "smudge", + "smudgy", + "smuggler", + "smuggling", + "smugly", + "smugness", + "snack", + "snagged", + "snaking", + "snap", + "snare", + "snarl", + "snazzy", + "sneak", + "sneer", + "sneeze", + "sneezing", + "snide", + "sniff", + "snippet", + "snipping", + "snitch", + "snooper", + "snooze", + "snore", + "snoring", + "snorkel", + "snort", + "snout", + "snowbird", + "snowboard", + "snowbound", + "snowcap", + "snowdrift", + "snowdrop", + "snowfall", + "snowfield", + "snowflake", + "snowiness", + "snowless", + "snowman", + "snowplow", + "snowshoe", + "snowstorm", + "snowsuit", + "snowy", + "snub", + "snuff", + "snuggle", + "snugly", + "snugness", + "speak", + "spearfish", + "spearhead", + "spearman", + "spearmint", + "species", + "specimen", + "specked", + "speckled", + "specks", + "spectacle", + "spectator", + "spectrum", + "speculate", + "speech", + "speed", + "spellbind", + "speller", + "spelling", + "spendable", + "spender", + "spending", + "spent", + "spew", + "sphere", + "spherical", + "sphinx", + "spider", + "spied", + "spiffy", + "spill", + "spilt", + "spinach", + "spinal", + "spindle", + "spinner", + "spinning", + "spinout", + "spinster", + "spiny", + "spiral", + "spirited", + "spiritism", + "spirits", + "spiritual", + "splashed", + "splashing", + "splashy", + "splatter", + "spleen", + "splendid", + "splendor", + "splice", + "splicing", + "splinter", + "splotchy", + "splurge", + "spoilage", + "spoiled", + "spoiler", + "spoiling", + "spoils", + "spoken", + "spokesman", + "sponge", + "spongy", + "sponsor", + "spoof", + "spookily", + "spooky", + "spool", + "spoon", + "spore", + "sporting", + "sports", + "sporty", + "spotless", + "spotlight", + "spotted", + "spotter", + "spotting", + "spotty", + "spousal", + "spouse", + "spout", + "sprain", + "sprang", + "sprawl", + "spray", + "spree", + "sprig", + "spring", + "sprinkled", + "sprinkler", + "sprint", + "sprite", + "sprout", + "spruce", + "sprung", + "spry", + "spud", + "spur", + "sputter", + "spyglass", + "squabble", + "squad", + "squall", + "squander", + "squash", + "squatted", + "squatter", + "squatting", + "squeak", + "squealer", + "squealing", + "squeamish", + "squeegee", + "squeeze", + "squeezing", + "squid", + "squiggle", + "squiggly", + "squint", + "squire", + "squirt", + "squishier", + "squishy", + "stability", + "stabilize", + "stable", + "stack", + "stadium", + "staff", + "stage", + "staging", + "stagnant", + "stagnate", + "stainable", + "stained", + "staining", + "stainless", + "stalemate", + "staleness", + "stalling", + "stallion", + "stamina", + "stammer", + "stamp", + "stand", + "stank", + "staple", + "stapling", + "starboard", + "starch", + "stardom", + "stardust", + "starfish", + "stargazer", + "staring", + "stark", + "starless", + "starlet", + "starlight", + "starlit", + "starring", + "starry", + "starship", + "starter", + "starting", + "startle", + "startling", + "startup", + "starved", + "starving", + "stash", + "state", + "static", + "statistic", + "statue", + "stature", + "status", + "statute", + "statutory", + "staunch", + "stays", + "steadfast", + "steadier", + "steadily", + "steadying", + "steam", + "steed", + "steep", + "steerable", + "steering", + "steersman", + "stegosaur", + "stellar", + "stem", + "stench", + "stencil", + "step", + "stereo", + "sterile", + "sterility", + "sterilize", + "sterling", + "sternness", + "sternum", + "stew", + "stick", + "stiffen", + "stiffly", + "stiffness", + "stifle", + "stifling", + "stillness", + "stilt", + "stimulant", + "stimulate", + "stimuli", + "stimulus", + "stinger", + "stingily", + "stinging", + "stingray", + "stingy", + "stinking", + "stinky", + "stipend", + "stipulate", + "stir", + "stitch", + "stock", + "stoic", + "stoke", + "stole", + "stomp", + "stonewall", + "stoneware", + "stonework", + "stoning", + "stony", + "stood", + "stooge", + "stool", + "stoop", + "stoplight", + "stoppable", + "stoppage", + "stopped", + "stopper", + "stopping", + "stopwatch", + "storable", + "storage", + "storeroom", + "storewide", + "storm", + "stout", + "stove", + "stowaway", + "stowing", + "straddle", + "straggler", + "strained", + "strainer", + "straining", + "strangely", + "stranger", + "strangle", + "strategic", + "strategy", + "stratus", + "straw", + "stray", + "streak", + "stream", + "street", + "strength", + "strenuous", + "strep", + "stress", + "stretch", + "strewn", + "stricken", + "strict", + "stride", + "strife", + "strike", + "striking", + "strive", + "striving", + "strobe", + "strode", + "stroller", + "strongbox", + "strongly", + "strongman", + "struck", + "structure", + "strudel", + "struggle", + "strum", + "strung", + "strut", + "stubbed", + "stubble", + "stubbly", + "stubborn", + "stucco", + "stuck", + "student", + "studied", + "studio", + "study", + "stuffed", + "stuffing", + "stuffy", + "stumble", + "stumbling", + "stump", + "stung", + "stunned", + "stunner", + "stunning", + "stunt", + "stupor", + "sturdily", + "sturdy", + "styling", + "stylishly", + "stylist", + "stylized", + "stylus", + "suave", + "subarctic", + "subatomic", + "subdivide", + "subdued", + "subduing", + "subfloor", + "subgroup", + "subheader", + "subject", + "sublease", + "sublet", + "sublevel", + "sublime", + "submarine", + "submerge", + "submersed", + "submitter", + "subpanel", + "subpar", + "subplot", + "subprime", + "subscribe", + "subscript", + "subsector", + "subside", + "subsiding", + "subsidize", + "subsidy", + "subsoil", + "subsonic", + "substance", + "subsystem", + "subtext", + "subtitle", + "subtly", + "subtotal", + "subtract", + "subtype", + "suburb", + "subway", + "subwoofer", + "subzero", + "succulent", + "such", + "suction", + "sudden", + "sudoku", + "suds", + "sufferer", + "suffering", + "suffice", + "suffix", + "suffocate", + "suffrage", + "sugar", + "suggest", + "suing", + "suitable", + "suitably", + "suitcase", + "suitor", + "sulfate", + "sulfide", + "sulfite", + "sulfur", + "sulk", + "sullen", + "sulphate", + "sulphuric", + "sultry", + "superbowl", + "superglue", + "superhero", + "superior", + "superjet", + "superman", + "supermom", + "supernova", + "supervise", + "supper", + "supplier", + "supply", + "support", + "supremacy", + "supreme", + "surcharge", + "surely", + "sureness", + "surface", + "surfacing", + "surfboard", + "surfer", + "surgery", + "surgical", + "surging", + "surname", + "surpass", + "surplus", + "surprise", + "surreal", + "surrender", + "surrogate", + "surround", + "survey", + "survival", + "survive", + "surviving", + "survivor", + "sushi", + "suspect", + "suspend", + "suspense", + "sustained", + "sustainer", + "swab", + "swaddling", + "swagger", + "swampland", + "swan", + "swapping", + "swarm", + "sway", + "swear", + "sweat", + "sweep", + "swell", + "swept", + "swerve", + "swifter", + "swiftly", + "swiftness", + "swimmable", + "swimmer", + "swimming", + "swimsuit", + "swimwear", + "swinger", + "swinging", + "swipe", + "swirl", + "switch", + "swivel", + "swizzle", + "swooned", + "swoop", + "swoosh", + "swore", + "sworn", + "swung", + "sycamore", + "sympathy", + "symphonic", + "symphony", + "symptom", + "synapse", + "syndrome", + "synergy", + "synopses", + "synopsis", + "synthesis", + "synthetic", + "syrup", + "system", + "t-shirt", + "tabasco", + "tabby", + "tableful", + "tables", + "tablet", + "tableware", + "tabloid", + "tackiness", + "tacking", + "tackle", + "tackling", + "tacky", + "taco", + "tactful", + "tactical", + "tactics", + "tactile", + "tactless", + "tadpole", + "taekwondo", + "tag", + "tainted", + "take", + "taking", + "talcum", + "talisman", + "tall", + "talon", + "tamale", + "tameness", + "tamer", + "tamper", + "tank", + "tanned", + "tannery", + "tanning", + "tantrum", + "tapeless", + "tapered", + "tapering", + "tapestry", + "tapioca", + "tapping", + "taps", + "tarantula", + "target", + "tarmac", + "tarnish", + "tarot", + "tartar", + "tartly", + "tartness", + "task", + "tassel", + "taste", + "tastiness", + "tasting", + "tasty", + "tattered", + "tattle", + "tattling", + "tattoo", + "taunt", + "tavern", + "thank", + "that", + "thaw", + "theater", + "theatrics", + "thee", + "theft", + "theme", + "theology", + "theorize", + "thermal", + "thermos", + "thesaurus", + "these", + "thesis", + "thespian", + "thicken", + "thicket", + "thickness", + "thieving", + "thievish", + "thigh", + "thimble", + "thing", + "think", + "thinly", + "thinner", + "thinness", + "thinning", + "thirstily", + "thirsting", + "thirsty", + "thirteen", + "thirty", + "thong", + "thorn", + "those", + "thousand", + "thrash", + "thread", + "threaten", + "threefold", + "thrift", + "thrill", + "thrive", + "thriving", + "throat", + "throbbing", + "throng", + "throttle", + "throwaway", + "throwback", + "thrower", + "throwing", + "thud", + "thumb", + "thumping", + "thursday", + "thus", + "thwarting", + "thyself", + "tiara", + "tibia", + "tidal", + "tidbit", + "tidiness", + "tidings", + "tidy", + "tiger", + "tighten", + "tightly", + "tightness", + "tightrope", + "tightwad", + "tigress", + "tile", + "tiling", + "till", + "tilt", + "timid", + "timing", + "timothy", + "tinderbox", + "tinfoil", + "tingle", + "tingling", + "tingly", + "tinker", + "tinkling", + "tinsel", + "tinsmith", + "tint", + "tinwork", + "tiny", + "tipoff", + "tipped", + "tipper", + "tipping", + "tiptoeing", + "tiptop", + "tiring", + "tissue", + "trace", + "tracing", + "track", + "traction", + "tractor", + "trade", + "trading", + "tradition", + "traffic", + "tragedy", + "trailing", + "trailside", + "train", + "traitor", + "trance", + "tranquil", + "transfer", + "transform", + "translate", + "transpire", + "transport", + "transpose", + "trapdoor", + "trapeze", + "trapezoid", + "trapped", + "trapper", + "trapping", + "traps", + "trash", + "travel", + "traverse", + "travesty", + "tray", + "treachery", + "treading", + "treadmill", + "treason", + "treat", + "treble", + "tree", + "trekker", + "tremble", + "trembling", + "tremor", + "trench", + "trend", + "trespass", + "triage", + "trial", + "triangle", + "tribesman", + "tribunal", + "tribune", + "tributary", + "tribute", + "triceps", + "trickery", + "trickily", + "tricking", + "trickle", + "trickster", + "tricky", + "tricolor", + "tricycle", + "trident", + "tried", + "trifle", + "trifocals", + "trillion", + "trilogy", + "trimester", + "trimmer", + "trimming", + "trimness", + "trinity", + "trio", + "tripod", + "tripping", + "triumph", + "trivial", + "trodden", + "trolling", + "trombone", + "trophy", + "tropical", + "tropics", + "trouble", + "troubling", + "trough", + "trousers", + "trout", + "trowel", + "truce", + "truck", + "truffle", + "trump", + "trunks", + "trustable", + "trustee", + "trustful", + "trusting", + "trustless", + "truth", + "try", + "tubby", + "tubeless", + "tubular", + "tucking", + "tuesday", + "tug", + "tuition", + "tulip", + "tumble", + "tumbling", + "tummy", + "turban", + "turbine", + "turbofan", + "turbojet", + "turbulent", + "turf", + "turkey", + "turmoil", + "turret", + "turtle", + "tusk", + "tutor", + "tutu", + "tux", + "tweak", + "tweed", + "tweet", + "tweezers", + "twelve", + "twentieth", + "twenty", + "twerp", + "twice", + "twiddle", + "twiddling", + "twig", + "twilight", + "twine", + "twins", + "twirl", + "twistable", + "twisted", + "twister", + "twisting", + "twisty", + "twitch", + "twitter", + "tycoon", + "tying", + "tyke", + "udder", + "ultimate", + "ultimatum", + "ultra", + "umbilical", + "umbrella", + "umpire", + "unabashed", + "unable", + "unadorned", + "unadvised", + "unafraid", + "unaired", + "unaligned", + "unaltered", + "unarmored", + "unashamed", + "unaudited", + "unawake", + "unaware", + "unbaked", + "unbalance", + "unbeaten", + "unbend", + "unbent", + "unbiased", + "unbitten", + "unblended", + "unblessed", + "unblock", + "unbolted", + "unbounded", + "unboxed", + "unbraided", + "unbridle", + "unbroken", + "unbuckled", + "unbundle", + "unburned", + "unbutton", + "uncanny", + "uncapped", + "uncaring", + "uncertain", + "unchain", + "unchanged", + "uncharted", + "uncheck", + "uncivil", + "unclad", + "unclaimed", + "unclamped", + "unclasp", + "uncle", + "unclip", + "uncloak", + "unclog", + "unclothed", + "uncoated", + "uncoiled", + "uncolored", + "uncombed", + "uncommon", + "uncooked", + "uncork", + "uncorrupt", + "uncounted", + "uncouple", + "uncouth", + "uncover", + "uncross", + "uncrown", + "uncrushed", + "uncured", + "uncurious", + "uncurled", + "uncut", + "undamaged", + "undated", + "undaunted", + "undead", + "undecided", + "undefined", + "underage", + "underarm", + "undercoat", + "undercook", + "undercut", + "underdog", + "underdone", + "underfed", + "underfeed", + "underfoot", + "undergo", + "undergrad", + "underhand", + "underline", + "underling", + "undermine", + "undermost", + "underpaid", + "underpass", + "underpay", + "underrate", + "undertake", + "undertone", + "undertook", + "undertow", + "underuse", + "underwear", + "underwent", + "underwire", + "undesired", + "undiluted", + "undivided", + "undocked", + "undoing", + "undone", + "undrafted", + "undress", + "undrilled", + "undusted", + "undying", + "unearned", + "unearth", + "unease", + "uneasily", + "uneasy", + "uneatable", + "uneaten", + "unedited", + "unelected", + "unending", + "unengaged", + "unenvied", + "unequal", + "unethical", + "uneven", + "unexpired", + "unexposed", + "unfailing", + "unfair", + "unfasten", + "unfazed", + "unfeeling", + "unfiled", + "unfilled", + "unfitted", + "unfitting", + "unfixable", + "unfixed", + "unflawed", + "unfocused", + "unfold", + "unfounded", + "unframed", + "unfreeze", + "unfrosted", + "unfrozen", + "unfunded", + "unglazed", + "ungloved", + "unglue", + "ungodly", + "ungraded", + "ungreased", + "unguarded", + "unguided", + "unhappily", + "unhappy", + "unharmed", + "unhealthy", + "unheard", + "unhearing", + "unheated", + "unhelpful", + "unhidden", + "unhinge", + "unhitched", + "unholy", + "unhook", + "unicorn", + "unicycle", + "unified", + "unifier", + "uniformed", + "uniformly", + "unify", + "unimpeded", + "uninjured", + "uninstall", + "uninsured", + "uninvited", + "union", + "uniquely", + "unisexual", + "unison", + "unissued", + "unit", + "universal", + "universe", + "unjustly", + "unkempt", + "unkind", + "unknotted", + "unknowing", + "unknown", + "unlaced", + "unlatch", + "unlawful", + "unleaded", + "unlearned", + "unleash", + "unless", + "unleveled", + "unlighted", + "unlikable", + "unlimited", + "unlined", + "unlinked", + "unlisted", + "unlit", + "unlivable", + "unloaded", + "unloader", + "unlocked", + "unlocking", + "unlovable", + "unloved", + "unlovely", + "unloving", + "unluckily", + "unlucky", + "unmade", + "unmanaged", + "unmanned", + "unmapped", + "unmarked", + "unmasked", + "unmasking", + "unmatched", + "unmindful", + "unmixable", + "unmixed", + "unmolded", + "unmoral", + "unmovable", + "unmoved", + "unmoving", + "unnamable", + "unnamed", + "unnatural", + "unneeded", + "unnerve", + "unnerving", + "unnoticed", + "unopened", + "unopposed", + "unpack", + "unpadded", + "unpaid", + "unpainted", + "unpaired", + "unpaved", + "unpeeled", + "unpicked", + "unpiloted", + "unpinned", + "unplanned", + "unplanted", + "unpleased", + "unpledged", + "unplowed", + "unplug", + "unpopular", + "unproven", + "unquote", + "unranked", + "unrated", + "unraveled", + "unreached", + "unread", + "unreal", + "unreeling", + "unrefined", + "unrelated", + "unrented", + "unrest", + "unretired", + "unrevised", + "unrigged", + "unripe", + "unrivaled", + "unroasted", + "unrobed", + "unroll", + "unruffled", + "unruly", + "unrushed", + "unsaddle", + "unsafe", + "unsaid", + "unsalted", + "unsaved", + "unsavory", + "unscathed", + "unscented", + "unscrew", + "unsealed", + "unseated", + "unsecured", + "unseeing", + "unseemly", + "unseen", + "unselect", + "unselfish", + "unsent", + "unsettled", + "unshackle", + "unshaken", + "unshaved", + "unshaven", + "unsheathe", + "unshipped", + "unsightly", + "unsigned", + "unskilled", + "unsliced", + "unsmooth", + "unsnap", + "unsocial", + "unsoiled", + "unsold", + "unsolved", + "unsorted", + "unspoiled", + "unspoken", + "unstable", + "unstaffed", + "unstamped", + "unsteady", + "unsterile", + "unstirred", + "unstitch", + "unstopped", + "unstuck", + "unstuffed", + "unstylish", + "unsubtle", + "unsubtly", + "unsuited", + "unsure", + "unsworn", + "untagged", + "untainted", + "untaken", + "untamed", + "untangled", + "untapped", + "untaxed", + "unthawed", + "unthread", + "untidy", + "untie", + "until", + "untimed", + "untimely", + "untitled", + "untoasted", + "untold", + "untouched", + "untracked", + "untrained", + "untreated", + "untried", + "untrimmed", + "untrue", + "untruth", + "unturned", + "untwist", + "untying", + "unusable", + "unused", + "unusual", + "unvalued", + "unvaried", + "unvarying", + "unveiled", + "unveiling", + "unvented", + "unviable", + "unvisited", + "unvocal", + "unwanted", + "unwarlike", + "unwary", + "unwashed", + "unwatched", + "unweave", + "unwed", + "unwelcome", + "unwell", + "unwieldy", + "unwilling", + "unwind", + "unwired", + "unwitting", + "unwomanly", + "unworldly", + "unworn", + "unworried", + "unworthy", + "unwound", + "unwoven", + "unwrapped", + "unwritten", + "unzip", + "upbeat", + "upchuck", + "upcoming", + "upcountry", + "update", + "upfront", + "upgrade", + "upheaval", + "upheld", + "uphill", + "uphold", + "uplifted", + "uplifting", + "upload", + "upon", + "upper", + "upright", + "uprising", + "upriver", + "uproar", + "uproot", + "upscale", + "upside", + "upstage", + "upstairs", + "upstart", + "upstate", + "upstream", + "upstroke", + "upswing", + "uptake", + "uptight", + "uptown", + "upturned", + "upward", + "upwind", + "uranium", + "urban", + "urchin", + "urethane", + "urgency", + "urgent", + "urging", + "urologist", + "urology", + "usable", + "usage", + "useable", + "used", + "uselessly", + "user", + "usher", + "usual", + "utensil", + "utility", + "utilize", + "utmost", + "utopia", + "utter", + "vacancy", + "vacant", + "vacate", + "vacation", + "vagabond", + "vagrancy", + "vagrantly", + "vaguely", + "vagueness", + "valiant", + "valid", + "valium", + "valley", + "valuables", + "value", + "vanilla", + "vanish", + "vanity", + "vanquish", + "vantage", + "vaporizer", + "variable", + "variably", + "varied", + "variety", + "various", + "varmint", + "varnish", + "varsity", + "varying", + "vascular", + "vaseline", + "vastly", + "vastness", + "veal", + "vegan", + "veggie", + "vehicular", + "velcro", + "velocity", + "velvet", + "vendetta", + "vending", + "vendor", + "veneering", + "vengeful", + "venomous", + "ventricle", + "venture", + "venue", + "venus", + "verbalize", + "verbally", + "verbose", + "verdict", + "verify", + "verse", + "version", + "versus", + "vertebrae", + "vertical", + "vertigo", + "very", + "vessel", + "vest", + "veteran", + "veto", + "vexingly", + "viability", + "viable", + "vibes", + "vice", + "vicinity", + "victory", + "video", + "viewable", + "viewer", + "viewing", + "viewless", + "viewpoint", + "vigorous", + "village", + "villain", + "vindicate", + "vineyard", + "vintage", + "violate", + "violation", + "violator", + "violet", + "violin", + "viper", + "viral", + "virtual", + "virtuous", + "virus", + "visa", + "viscosity", + "viscous", + "viselike", + "visible", + "visibly", + "vision", + "visiting", + "visitor", + "visor", + "vista", + "vitality", + "vitalize", + "vitally", + "vitamins", + "vivacious", + "vividly", + "vividness", + "vixen", + "vocalist", + "vocalize", + "vocally", + "vocation", + "voice", + "voicing", + "void", + "volatile", + "volley", + "voltage", + "volumes", + "voter", + "voting", + "voucher", + "vowed", + "vowel", + "voyage", + "wackiness", + "wad", + "wafer", + "waffle", + "waged", + "wager", + "wages", + "waggle", + "wagon", + "wake", + "waking", + "walk", + "walmart", + "walnut", + "walrus", + "waltz", + "wand", + "wannabe", + "wanted", + "wanting", + "wasabi", + "washable", + "washbasin", + "washboard", + "washbowl", + "washcloth", + "washday", + "washed", + "washer", + "washhouse", + "washing", + "washout", + "washroom", + "washstand", + "washtub", + "wasp", + "wasting", + "watch", + "water", + "waviness", + "waving", + "wavy", + "whacking", + "whacky", + "wham", + "wharf", + "wheat", + "whenever", + "whiff", + "whimsical", + "whinny", + "whiny", + "whisking", + "whoever", + "whole", + "whomever", + "whoopee", + "whooping", + "whoops", + "why", + "wick", + "widely", + "widen", + "widget", + "widow", + "width", + "wieldable", + "wielder", + "wife", + "wifi", + "wikipedia", + "wildcard", + "wildcat", + "wilder", + "wildfire", + "wildfowl", + "wildland", + "wildlife", + "wildly", + "wildness", + "willed", + "willfully", + "willing", + "willow", + "willpower", + "wilt", + "wimp", + "wince", + "wincing", + "wind", + "wing", + "winking", + "winner", + "winnings", + "winter", + "wipe", + "wired", + "wireless", + "wiring", + "wiry", + "wisdom", + "wise", + "wish", + "wisplike", + "wispy", + "wistful", + "wizard", + "wobble", + "wobbling", + "wobbly", + "wok", + "wolf", + "wolverine", + "womanhood", + "womankind", + "womanless", + "womanlike", + "womanly", + "womb", + "woof", + "wooing", + "wool", + "woozy", + "word", + "work", + "worried", + "worrier", + "worrisome", + "worry", + "worsening", + "worshiper", + "worst", + "wound", + "woven", + "wow", + "wrangle", + "wrath", + "wreath", + "wreckage", + "wrecker", + "wrecking", + "wrench", + "wriggle", + "wriggly", + "wrinkle", + "wrinkly", + "wrist", + "writing", + "written", + "wrongdoer", + "wronged", + "wrongful", + "wrongly", + "wrongness", + "wrought", + "xbox", + "xerox", + "yahoo", + "yam", + "yanking", + "yapping", + "yard", + "yarn", + "yeah", + "yearbook", + "yearling", + "yearly", + "yearning", + "yeast", + "yelling", + "yelp", + "yen", + "yesterday", + "yiddish", + "yield", + "yin", + "yippee", + "yo-yo", + "yodel", + "yoga", + "yogurt", + "yonder", + "yoyo", + "yummy", + "zap", + "zealous", + "zebra", + "zen", + "zeppelin", + "zero", + "zestfully", + "zesty", + "zigzagged", + "zipfile", + "zipping", + "zippy", + "zips", + "zit", + "zodiac", + "zombie", + "zone", + "zoning", + "zookeeper", + "zoologist", + "zoology", + "zoom", ]; diff --git a/common/src/models/api/cardApi.ts b/common/src/models/api/cardApi.ts index b837bb90..8d972624 100644 --- a/common/src/models/api/cardApi.ts +++ b/common/src/models/api/cardApi.ts @@ -1,23 +1,23 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; export class CardApi extends BaseResponse { - cardholderName: string; - brand: string; - number: string; - expMonth: string; - expYear: string; - code: string; + cardholderName: string; + brand: string; + number: string; + expMonth: string; + expYear: string; + code: string; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.cardholderName = this.getResponseProperty('CardholderName'); - this.brand = this.getResponseProperty('Brand'); - this.number = this.getResponseProperty('Number'); - this.expMonth = this.getResponseProperty('ExpMonth'); - this.expYear = this.getResponseProperty('ExpYear'); - this.code = this.getResponseProperty('Code'); + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.cardholderName = this.getResponseProperty("CardholderName"); + this.brand = this.getResponseProperty("Brand"); + this.number = this.getResponseProperty("Number"); + this.expMonth = this.getResponseProperty("ExpMonth"); + this.expYear = this.getResponseProperty("ExpYear"); + this.code = this.getResponseProperty("Code"); + } } diff --git a/common/src/models/api/fieldApi.ts b/common/src/models/api/fieldApi.ts index b9e8e0e9..d7e603ea 100644 --- a/common/src/models/api/fieldApi.ts +++ b/common/src/models/api/fieldApi.ts @@ -1,22 +1,22 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; -import { FieldType } from '../../enums/fieldType'; -import { LinkedIdType } from '../../enums/linkedIdType'; +import { FieldType } from "../../enums/fieldType"; +import { LinkedIdType } from "../../enums/linkedIdType"; export class FieldApi extends BaseResponse { - name: string; - value: string; - type: FieldType; - linkedId: LinkedIdType; + name: string; + value: string; + type: FieldType; + linkedId: LinkedIdType; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.type = this.getResponseProperty('Type'); - this.name = this.getResponseProperty('Name'); - this.value = this.getResponseProperty('Value'); - this.linkedId = this.getResponseProperty('linkedId'); + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.type = this.getResponseProperty("Type"); + this.name = this.getResponseProperty("Name"); + this.value = this.getResponseProperty("Value"); + this.linkedId = this.getResponseProperty("linkedId"); + } } diff --git a/common/src/models/api/identityApi.ts b/common/src/models/api/identityApi.ts index e271e5e3..9312438f 100644 --- a/common/src/models/api/identityApi.ts +++ b/common/src/models/api/identityApi.ts @@ -1,47 +1,47 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; export class IdentityApi extends BaseResponse { - title: string; - firstName: string; - middleName: string; - lastName: string; - address1: string; - address2: string; - address3: string; - city: string; - state: string; - postalCode: string; - country: string; - company: string; - email: string; - phone: string; - ssn: string; - username: string; - passportNumber: string; - licenseNumber: string; + title: string; + firstName: string; + middleName: string; + lastName: string; + address1: string; + address2: string; + address3: string; + city: string; + state: string; + postalCode: string; + country: string; + company: string; + email: string; + phone: string; + ssn: string; + username: string; + passportNumber: string; + licenseNumber: string; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.title = this.getResponseProperty('Title'); - this.firstName = this.getResponseProperty('FirstName'); - this.middleName = this.getResponseProperty('MiddleName'); - this.lastName = this.getResponseProperty('LastName'); - this.address1 = this.getResponseProperty('Address1'); - this.address2 = this.getResponseProperty('Address2'); - this.address3 = this.getResponseProperty('Address3'); - this.city = this.getResponseProperty('City'); - this.state = this.getResponseProperty('State'); - this.postalCode = this.getResponseProperty('PostalCode'); - this.country = this.getResponseProperty('Country'); - this.company = this.getResponseProperty('Company'); - this.email = this.getResponseProperty('Email'); - this.phone = this.getResponseProperty('Phone'); - this.ssn = this.getResponseProperty('SSN'); - this.username = this.getResponseProperty('Username'); - this.passportNumber = this.getResponseProperty('PassportNumber'); - this.licenseNumber = this.getResponseProperty('LicenseNumber'); + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.title = this.getResponseProperty("Title"); + this.firstName = this.getResponseProperty("FirstName"); + this.middleName = this.getResponseProperty("MiddleName"); + this.lastName = this.getResponseProperty("LastName"); + this.address1 = this.getResponseProperty("Address1"); + this.address2 = this.getResponseProperty("Address2"); + this.address3 = this.getResponseProperty("Address3"); + this.city = this.getResponseProperty("City"); + this.state = this.getResponseProperty("State"); + this.postalCode = this.getResponseProperty("PostalCode"); + this.country = this.getResponseProperty("Country"); + this.company = this.getResponseProperty("Company"); + this.email = this.getResponseProperty("Email"); + this.phone = this.getResponseProperty("Phone"); + this.ssn = this.getResponseProperty("SSN"); + this.username = this.getResponseProperty("Username"); + this.passportNumber = this.getResponseProperty("PassportNumber"); + this.licenseNumber = this.getResponseProperty("LicenseNumber"); + } } diff --git a/common/src/models/api/loginApi.ts b/common/src/models/api/loginApi.ts index a02cde38..ddbe37ec 100644 --- a/common/src/models/api/loginApi.ts +++ b/common/src/models/api/loginApi.ts @@ -1,29 +1,29 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; -import { LoginUriApi } from './loginUriApi'; +import { LoginUriApi } from "./loginUriApi"; export class LoginApi extends BaseResponse { - uris: LoginUriApi[]; - username: string; - password: string; - passwordRevisionDate: string; - totp: string; - autofillOnPageLoad: boolean; + uris: LoginUriApi[]; + username: string; + password: string; + passwordRevisionDate: string; + totp: string; + autofillOnPageLoad: boolean; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.username = this.getResponseProperty('Username'); - this.password = this.getResponseProperty('Password'); - this.passwordRevisionDate = this.getResponseProperty('PasswordRevisionDate'); - this.totp = this.getResponseProperty('Totp'); - this.autofillOnPageLoad = this.getResponseProperty('AutofillOnPageLoad'); - - const uris = this.getResponseProperty('Uris'); - if (uris != null) { - this.uris = uris.map((u: any) => new LoginUriApi(u)); - } + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.username = this.getResponseProperty("Username"); + this.password = this.getResponseProperty("Password"); + this.passwordRevisionDate = this.getResponseProperty("PasswordRevisionDate"); + this.totp = this.getResponseProperty("Totp"); + this.autofillOnPageLoad = this.getResponseProperty("AutofillOnPageLoad"); + + const uris = this.getResponseProperty("Uris"); + if (uris != null) { + this.uris = uris.map((u: any) => new LoginUriApi(u)); + } + } } diff --git a/common/src/models/api/loginUriApi.ts b/common/src/models/api/loginUriApi.ts index 6ea8d4e2..9da6e0a7 100644 --- a/common/src/models/api/loginUriApi.ts +++ b/common/src/models/api/loginUriApi.ts @@ -1,18 +1,18 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; -import { UriMatchType } from '../../enums/uriMatchType'; +import { UriMatchType } from "../../enums/uriMatchType"; export class LoginUriApi extends BaseResponse { - uri: string; - match: UriMatchType = null; + uri: string; + match: UriMatchType = null; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.uri = this.getResponseProperty('Uri'); - const match = this.getResponseProperty('Match'); - this.match = match != null ? match : null; + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.uri = this.getResponseProperty("Uri"); + const match = this.getResponseProperty("Match"); + this.match = match != null ? match : null; + } } diff --git a/common/src/models/api/permissionsApi.ts b/common/src/models/api/permissionsApi.ts index 0755074e..bac79bd3 100644 --- a/common/src/models/api/permissionsApi.ts +++ b/common/src/models/api/permissionsApi.ts @@ -1,55 +1,55 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; export class PermissionsApi extends BaseResponse { - accessEventLogs: boolean; - accessImportExport: boolean; - accessReports: boolean; - /** - * @deprecated Sep 29 2021: This permission has been split out to `createNewCollections`, `editAnyCollection`, and - * `deleteAnyCollection`. It exists here for backwards compatibility with Server versions <= 1.43.0 - */ - manageAllCollections: boolean; - createNewCollections: boolean; - editAnyCollection: boolean; - deleteAnyCollection: boolean; - /** - * @deprecated Sep 29 2021: This permission has been split out to `editAssignedCollections` and - * `deleteAssignedCollections`. It exists here for backwards compatibility with Server versions <= 1.43.0 - */ - manageAssignedCollections: boolean; - editAssignedCollections: boolean; - deleteAssignedCollections: boolean; - manageCiphers: boolean; - manageGroups: boolean; - manageSso: boolean; - managePolicies: boolean; - manageUsers: boolean; - manageResetPassword: boolean; + accessEventLogs: boolean; + accessImportExport: boolean; + accessReports: boolean; + /** + * @deprecated Sep 29 2021: This permission has been split out to `createNewCollections`, `editAnyCollection`, and + * `deleteAnyCollection`. It exists here for backwards compatibility with Server versions <= 1.43.0 + */ + manageAllCollections: boolean; + createNewCollections: boolean; + editAnyCollection: boolean; + deleteAnyCollection: boolean; + /** + * @deprecated Sep 29 2021: This permission has been split out to `editAssignedCollections` and + * `deleteAssignedCollections`. It exists here for backwards compatibility with Server versions <= 1.43.0 + */ + manageAssignedCollections: boolean; + editAssignedCollections: boolean; + deleteAssignedCollections: boolean; + manageCiphers: boolean; + manageGroups: boolean; + manageSso: boolean; + managePolicies: boolean; + manageUsers: boolean; + manageResetPassword: boolean; - constructor(data: any = null) { - super(data); - if (data == null) { - return this; - } - this.accessEventLogs = this.getResponseProperty('AccessEventLogs'); - this.accessImportExport = this.getResponseProperty('AccessImportExport'); - this.accessReports = this.getResponseProperty('AccessReports'); - - // For backwards compatibility with Server <= 1.43.0 - this.manageAllCollections = this.getResponseProperty('ManageAllCollections'); - this.manageAssignedCollections = this.getResponseProperty('ManageAssignedCollections'); - - this.createNewCollections = this.getResponseProperty('CreateNewCollections'); - this.editAnyCollection = this.getResponseProperty('EditAnyCollection'); - this.deleteAnyCollection = this.getResponseProperty('DeleteAnyCollection'); - this.editAssignedCollections = this.getResponseProperty('EditAssignedCollections'); - this.deleteAssignedCollections = this.getResponseProperty('DeleteAssignedCollections'); - - this.manageCiphers = this.getResponseProperty('ManageCiphers'); - this.manageGroups = this.getResponseProperty('ManageGroups'); - this.manageSso = this.getResponseProperty('ManageSso'); - this.managePolicies = this.getResponseProperty('ManagePolicies'); - this.manageUsers = this.getResponseProperty('ManageUsers'); - this.manageResetPassword = this.getResponseProperty('ManageResetPassword'); + constructor(data: any = null) { + super(data); + if (data == null) { + return this; } + this.accessEventLogs = this.getResponseProperty("AccessEventLogs"); + this.accessImportExport = this.getResponseProperty("AccessImportExport"); + this.accessReports = this.getResponseProperty("AccessReports"); + + // For backwards compatibility with Server <= 1.43.0 + this.manageAllCollections = this.getResponseProperty("ManageAllCollections"); + this.manageAssignedCollections = this.getResponseProperty("ManageAssignedCollections"); + + this.createNewCollections = this.getResponseProperty("CreateNewCollections"); + this.editAnyCollection = this.getResponseProperty("EditAnyCollection"); + this.deleteAnyCollection = this.getResponseProperty("DeleteAnyCollection"); + this.editAssignedCollections = this.getResponseProperty("EditAssignedCollections"); + this.deleteAssignedCollections = this.getResponseProperty("DeleteAssignedCollections"); + + this.manageCiphers = this.getResponseProperty("ManageCiphers"); + this.manageGroups = this.getResponseProperty("ManageGroups"); + this.manageSso = this.getResponseProperty("ManageSso"); + this.managePolicies = this.getResponseProperty("ManagePolicies"); + this.manageUsers = this.getResponseProperty("ManageUsers"); + this.manageResetPassword = this.getResponseProperty("ManageResetPassword"); + } } diff --git a/common/src/models/api/secureNoteApi.ts b/common/src/models/api/secureNoteApi.ts index 2fbdd94b..dfb25134 100644 --- a/common/src/models/api/secureNoteApi.ts +++ b/common/src/models/api/secureNoteApi.ts @@ -1,15 +1,15 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; -import { SecureNoteType } from '../../enums/secureNoteType'; +import { SecureNoteType } from "../../enums/secureNoteType"; export class SecureNoteApi extends BaseResponse { - type: SecureNoteType; + type: SecureNoteType; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.type = this.getResponseProperty('Type'); + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.type = this.getResponseProperty("Type"); + } } diff --git a/common/src/models/api/sendFileApi.ts b/common/src/models/api/sendFileApi.ts index fc4feeee..f4d0926c 100644 --- a/common/src/models/api/sendFileApi.ts +++ b/common/src/models/api/sendFileApi.ts @@ -1,21 +1,21 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; export class SendFileApi extends BaseResponse { - id: string; - fileName: string; - key: string; - size: string; - sizeName: string; + id: string; + fileName: string; + key: string; + size: string; + sizeName: string; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.id = this.getResponseProperty('Id'); - this.fileName = this.getResponseProperty('FileName'); - this.key = this.getResponseProperty('Key'); - this.size = this.getResponseProperty('Size'); - this.sizeName = this.getResponseProperty('SizeName'); + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.id = this.getResponseProperty("Id"); + this.fileName = this.getResponseProperty("FileName"); + this.key = this.getResponseProperty("Key"); + this.size = this.getResponseProperty("Size"); + this.sizeName = this.getResponseProperty("SizeName"); + } } diff --git a/common/src/models/api/sendTextApi.ts b/common/src/models/api/sendTextApi.ts index 083077c3..56d21450 100644 --- a/common/src/models/api/sendTextApi.ts +++ b/common/src/models/api/sendTextApi.ts @@ -1,15 +1,15 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; export class SendTextApi extends BaseResponse { - text: string; - hidden: boolean; + text: string; + hidden: boolean; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - this.text = this.getResponseProperty('Text'); - this.hidden = this.getResponseProperty('Hidden') || false; + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + this.text = this.getResponseProperty("Text"); + this.hidden = this.getResponseProperty("Hidden") || false; + } } diff --git a/common/src/models/api/ssoConfigApi.ts b/common/src/models/api/ssoConfigApi.ts index c846524a..338ab793 100644 --- a/common/src/models/api/ssoConfigApi.ts +++ b/common/src/models/api/ssoConfigApi.ts @@ -1,118 +1,124 @@ -import { BaseResponse } from '../response/baseResponse'; +import { BaseResponse } from "../response/baseResponse"; enum SsoType { - OpenIdConnect = 1, - Saml2 = 2, + OpenIdConnect = 1, + Saml2 = 2, } enum OpenIdConnectRedirectBehavior { - RedirectGet = 0, - FormPost = 1, + RedirectGet = 0, + FormPost = 1, } enum Saml2BindingType { - HttpRedirect = 1, - HttpPost = 2, - Artifact = 4, + HttpRedirect = 1, + HttpPost = 2, + Artifact = 4, } enum Saml2NameIdFormat { - NotConfigured = 0, - Unspecified = 1, - EmailAddress = 2, - X509SubjectName = 3, - WindowsDomainQualifiedName = 4, - KerberosPrincipalName = 5, - EntityIdentifier = 6, - Persistent = 7, - Transient = 8, + NotConfigured = 0, + Unspecified = 1, + EmailAddress = 2, + X509SubjectName = 3, + WindowsDomainQualifiedName = 4, + KerberosPrincipalName = 5, + EntityIdentifier = 6, + Persistent = 7, + Transient = 8, } enum Saml2SigningBehavior { - IfIdpWantAuthnRequestsSigned = 0, - Always = 1, - Never = 3, + IfIdpWantAuthnRequestsSigned = 0, + Always = 1, + Never = 3, } export class SsoConfigApi extends BaseResponse { - configType: SsoType; + configType: SsoType; - keyConnectorEnabled: boolean; - keyConnectorUrl: string; + keyConnectorEnabled: boolean; + keyConnectorUrl: string; - // OpenId - authority: string; - clientId: string; - clientSecret: string; - metadataAddress: string; - redirectBehavior: OpenIdConnectRedirectBehavior; - getClaimsFromUserInfoEndpoint: boolean; - additionalScopes: string; - additionalUserIdClaimTypes: string; - additionalEmailClaimTypes: string; - additionalNameClaimTypes: string; - acrValues: string; - expectedReturnAcrValue: string; + // OpenId + authority: string; + clientId: string; + clientSecret: string; + metadataAddress: string; + redirectBehavior: OpenIdConnectRedirectBehavior; + getClaimsFromUserInfoEndpoint: boolean; + additionalScopes: string; + additionalUserIdClaimTypes: string; + additionalEmailClaimTypes: string; + additionalNameClaimTypes: string; + acrValues: string; + expectedReturnAcrValue: string; - // SAML - spNameIdFormat: Saml2NameIdFormat; - spOutboundSigningAlgorithm: string; - spSigningBehavior: Saml2SigningBehavior; - spMinIncomingSigningAlgorithm: boolean; - spWantAssertionsSigned: boolean; - spValidateCertificates: boolean; + // SAML + spNameIdFormat: Saml2NameIdFormat; + spOutboundSigningAlgorithm: string; + spSigningBehavior: Saml2SigningBehavior; + spMinIncomingSigningAlgorithm: boolean; + spWantAssertionsSigned: boolean; + spValidateCertificates: boolean; - idpEntityId: string; - idpBindingType: Saml2BindingType; - idpSingleSignOnServiceUrl: string; - idpSingleLogoutServiceUrl: string; - idpArtifactResolutionServiceUrl: string; - idpX509PublicCert: string; - idpOutboundSigningAlgorithm: string; - idpAllowUnsolicitedAuthnResponse: boolean; - idpDisableOutboundLogoutRequests: boolean; - idpWantAuthnRequestsSigned: boolean; + idpEntityId: string; + idpBindingType: Saml2BindingType; + idpSingleSignOnServiceUrl: string; + idpSingleLogoutServiceUrl: string; + idpArtifactResolutionServiceUrl: string; + idpX509PublicCert: string; + idpOutboundSigningAlgorithm: string; + idpAllowUnsolicitedAuthnResponse: boolean; + idpDisableOutboundLogoutRequests: boolean; + idpWantAuthnRequestsSigned: boolean; - constructor(data: any = null) { - super(data); - if (data == null) { - return; - } - - this.configType = this.getResponseProperty('ConfigType'); - - this.keyConnectorEnabled = this.getResponseProperty('KeyConnectorEnabled'); - this.keyConnectorUrl = this.getResponseProperty('KeyConnectorUrl'); - - this.authority = this.getResponseProperty('Authority'); - this.clientId = this.getResponseProperty('ClientId'); - this.clientSecret = this.getResponseProperty('ClientSecret'); - this.metadataAddress = this.getResponseProperty('MetadataAddress'); - this.redirectBehavior = this.getResponseProperty('RedirectBehavior'); - this.getClaimsFromUserInfoEndpoint = this.getResponseProperty('GetClaimsFromUserInfoEndpoint'); - this.additionalScopes = this.getResponseProperty('AdditionalScopes'); - this.additionalUserIdClaimTypes = this.getResponseProperty('AdditionalUserIdClaimTypes'); - this.additionalEmailClaimTypes = this.getResponseProperty('AdditionalEmailClaimTypes'); - this.additionalNameClaimTypes = this.getResponseProperty('AdditionalNameClaimTypes'); - this.acrValues = this.getResponseProperty('AcrValues'); - this.expectedReturnAcrValue = this.getResponseProperty('ExpectedReturnAcrValue'); - - this.spNameIdFormat = this.getResponseProperty('SpNameIdFormat'); - this.spOutboundSigningAlgorithm = this.getResponseProperty('SpOutboundSigningAlgorithm'); - this.spSigningBehavior = this.getResponseProperty('SpSigningBehavior'); - this.spMinIncomingSigningAlgorithm = this.getResponseProperty('SpMinIncomingSigningAlgorithm'); - this.spWantAssertionsSigned = this.getResponseProperty('SpWantAssertionsSigned'); - this.spValidateCertificates = this.getResponseProperty('SpValidateCertificates'); - - this.idpEntityId = this.getResponseProperty('IdpEntityId'); - this.idpBindingType = this.getResponseProperty('IdpBindingType'); - this.idpSingleSignOnServiceUrl = this.getResponseProperty('IdpSingleSignOnServiceUrl'); - this.idpSingleLogoutServiceUrl = this.getResponseProperty('IdpSingleLogoutServiceUrl'); - this.idpArtifactResolutionServiceUrl = this.getResponseProperty('IdpArtifactResolutionServiceUrl'); - this.idpX509PublicCert = this.getResponseProperty('IdpX509PublicCert'); - this.idpOutboundSigningAlgorithm = this.getResponseProperty('IdpOutboundSigningAlgorithm'); - this.idpAllowUnsolicitedAuthnResponse = this.getResponseProperty('IdpAllowUnsolicitedAuthnResponse'); - this.idpDisableOutboundLogoutRequests = this.getResponseProperty('IdpDisableOutboundLogoutRequests'); - this.idpWantAuthnRequestsSigned = this.getResponseProperty('IdpWantAuthnRequestsSigned'); + constructor(data: any = null) { + super(data); + if (data == null) { + return; } + + this.configType = this.getResponseProperty("ConfigType"); + + this.keyConnectorEnabled = this.getResponseProperty("KeyConnectorEnabled"); + this.keyConnectorUrl = this.getResponseProperty("KeyConnectorUrl"); + + this.authority = this.getResponseProperty("Authority"); + this.clientId = this.getResponseProperty("ClientId"); + this.clientSecret = this.getResponseProperty("ClientSecret"); + this.metadataAddress = this.getResponseProperty("MetadataAddress"); + this.redirectBehavior = this.getResponseProperty("RedirectBehavior"); + this.getClaimsFromUserInfoEndpoint = this.getResponseProperty("GetClaimsFromUserInfoEndpoint"); + this.additionalScopes = this.getResponseProperty("AdditionalScopes"); + this.additionalUserIdClaimTypes = this.getResponseProperty("AdditionalUserIdClaimTypes"); + this.additionalEmailClaimTypes = this.getResponseProperty("AdditionalEmailClaimTypes"); + this.additionalNameClaimTypes = this.getResponseProperty("AdditionalNameClaimTypes"); + this.acrValues = this.getResponseProperty("AcrValues"); + this.expectedReturnAcrValue = this.getResponseProperty("ExpectedReturnAcrValue"); + + this.spNameIdFormat = this.getResponseProperty("SpNameIdFormat"); + this.spOutboundSigningAlgorithm = this.getResponseProperty("SpOutboundSigningAlgorithm"); + this.spSigningBehavior = this.getResponseProperty("SpSigningBehavior"); + this.spMinIncomingSigningAlgorithm = this.getResponseProperty("SpMinIncomingSigningAlgorithm"); + this.spWantAssertionsSigned = this.getResponseProperty("SpWantAssertionsSigned"); + this.spValidateCertificates = this.getResponseProperty("SpValidateCertificates"); + + this.idpEntityId = this.getResponseProperty("IdpEntityId"); + this.idpBindingType = this.getResponseProperty("IdpBindingType"); + this.idpSingleSignOnServiceUrl = this.getResponseProperty("IdpSingleSignOnServiceUrl"); + this.idpSingleLogoutServiceUrl = this.getResponseProperty("IdpSingleLogoutServiceUrl"); + this.idpArtifactResolutionServiceUrl = this.getResponseProperty( + "IdpArtifactResolutionServiceUrl" + ); + this.idpX509PublicCert = this.getResponseProperty("IdpX509PublicCert"); + this.idpOutboundSigningAlgorithm = this.getResponseProperty("IdpOutboundSigningAlgorithm"); + this.idpAllowUnsolicitedAuthnResponse = this.getResponseProperty( + "IdpAllowUnsolicitedAuthnResponse" + ); + this.idpDisableOutboundLogoutRequests = this.getResponseProperty( + "IdpDisableOutboundLogoutRequests" + ); + this.idpWantAuthnRequestsSigned = this.getResponseProperty("IdpWantAuthnRequestsSigned"); + } } diff --git a/common/src/models/data/attachmentData.ts b/common/src/models/data/attachmentData.ts index dc0f2220..50af03ac 100644 --- a/common/src/models/data/attachmentData.ts +++ b/common/src/models/data/attachmentData.ts @@ -1,22 +1,22 @@ -import { AttachmentResponse } from '../response/attachmentResponse'; +import { AttachmentResponse } from "../response/attachmentResponse"; export class AttachmentData { - id: string; - url: string; - fileName: string; - key: string; - size: string; - sizeName: string; + id: string; + url: string; + fileName: string; + key: string; + size: string; + sizeName: string; - constructor(response?: AttachmentResponse) { - if (response == null) { - return; - } - this.id = response.id; - this.url = response.url; - this.fileName = response.fileName; - this.key = response.key; - this.size = response.size; - this.sizeName = response.sizeName; + constructor(response?: AttachmentResponse) { + if (response == null) { + return; } + this.id = response.id; + this.url = response.url; + this.fileName = response.fileName; + this.key = response.key; + this.size = response.size; + this.sizeName = response.sizeName; + } } diff --git a/common/src/models/data/cardData.ts b/common/src/models/data/cardData.ts index d87c7231..9d90e4b2 100644 --- a/common/src/models/data/cardData.ts +++ b/common/src/models/data/cardData.ts @@ -1,23 +1,23 @@ -import { CardApi } from '../api/cardApi'; +import { CardApi } from "../api/cardApi"; export class CardData { - cardholderName: string; - brand: string; - number: string; - expMonth: string; - expYear: string; - code: string; + cardholderName: string; + brand: string; + number: string; + expMonth: string; + expYear: string; + code: string; - constructor(data?: CardApi) { - if (data == null) { - return; - } - - this.cardholderName = data.cardholderName; - this.brand = data.brand; - this.number = data.number; - this.expMonth = data.expMonth; - this.expYear = data.expYear; - this.code = data.code; + constructor(data?: CardApi) { + if (data == null) { + return; } + + this.cardholderName = data.cardholderName; + this.brand = data.brand; + this.number = data.number; + this.expMonth = data.expMonth; + this.expYear = data.expYear; + this.code = data.code; + } } diff --git a/common/src/models/data/cipherData.ts b/common/src/models/data/cipherData.ts index 679db751..cdda0e46 100644 --- a/common/src/models/data/cipherData.ts +++ b/common/src/models/data/cipherData.ts @@ -1,87 +1,87 @@ -import { CipherRepromptType } from '../../enums/cipherRepromptType'; -import { CipherType } from '../../enums/cipherType'; +import { CipherRepromptType } from "../../enums/cipherRepromptType"; +import { CipherType } from "../../enums/cipherType"; -import { AttachmentData } from './attachmentData'; -import { CardData } from './cardData'; -import { FieldData } from './fieldData'; -import { IdentityData } from './identityData'; -import { LoginData } from './loginData'; -import { PasswordHistoryData } from './passwordHistoryData'; -import { SecureNoteData } from './secureNoteData'; +import { AttachmentData } from "./attachmentData"; +import { CardData } from "./cardData"; +import { FieldData } from "./fieldData"; +import { IdentityData } from "./identityData"; +import { LoginData } from "./loginData"; +import { PasswordHistoryData } from "./passwordHistoryData"; +import { SecureNoteData } from "./secureNoteData"; -import { CipherResponse } from '../response/cipherResponse'; +import { CipherResponse } from "../response/cipherResponse"; export class CipherData { - id: string; - organizationId: string; - folderId: string; - userId: string; - edit: boolean; - viewPassword: boolean; - organizationUseTotp: boolean; - favorite: boolean; - revisionDate: string; - type: CipherType; - sizeName: string; - name: string; - notes: string; - login?: LoginData; - secureNote?: SecureNoteData; - card?: CardData; - identity?: IdentityData; - fields?: FieldData[]; - attachments?: AttachmentData[]; - passwordHistory?: PasswordHistoryData[]; - collectionIds?: string[]; - deletedDate: string; - reprompt: CipherRepromptType; + id: string; + organizationId: string; + folderId: string; + userId: string; + edit: boolean; + viewPassword: boolean; + organizationUseTotp: boolean; + favorite: boolean; + revisionDate: string; + type: CipherType; + sizeName: string; + name: string; + notes: string; + login?: LoginData; + secureNote?: SecureNoteData; + card?: CardData; + identity?: IdentityData; + fields?: FieldData[]; + attachments?: AttachmentData[]; + passwordHistory?: PasswordHistoryData[]; + collectionIds?: string[]; + deletedDate: string; + reprompt: CipherRepromptType; - constructor(response?: CipherResponse, userId?: string, collectionIds?: string[]) { - if (response == null) { - return; - } - - this.id = response.id; - this.organizationId = response.organizationId; - this.folderId = response.folderId; - this.userId = userId; - this.edit = response.edit; - this.viewPassword = response.viewPassword; - this.organizationUseTotp = response.organizationUseTotp; - this.favorite = response.favorite; - this.revisionDate = response.revisionDate; - this.type = response.type; - this.name = response.name; - this.notes = response.notes; - this.collectionIds = collectionIds != null ? collectionIds : response.collectionIds; - this.deletedDate = response.deletedDate; - this.reprompt = response.reprompt; - - switch (this.type) { - case CipherType.Login: - this.login = new LoginData(response.login); - break; - case CipherType.SecureNote: - this.secureNote = new SecureNoteData(response.secureNote); - break; - case CipherType.Card: - this.card = new CardData(response.card); - break; - case CipherType.Identity: - this.identity = new IdentityData(response.identity); - break; - default: - break; - } - - if (response.fields != null) { - this.fields = response.fields.map(f => new FieldData(f)); - } - if (response.attachments != null) { - this.attachments = response.attachments.map(a => new AttachmentData(a)); - } - if (response.passwordHistory != null) { - this.passwordHistory = response.passwordHistory.map(ph => new PasswordHistoryData(ph)); - } + constructor(response?: CipherResponse, userId?: string, collectionIds?: string[]) { + if (response == null) { + return; } + + this.id = response.id; + this.organizationId = response.organizationId; + this.folderId = response.folderId; + this.userId = userId; + this.edit = response.edit; + this.viewPassword = response.viewPassword; + this.organizationUseTotp = response.organizationUseTotp; + this.favorite = response.favorite; + this.revisionDate = response.revisionDate; + this.type = response.type; + this.name = response.name; + this.notes = response.notes; + this.collectionIds = collectionIds != null ? collectionIds : response.collectionIds; + this.deletedDate = response.deletedDate; + this.reprompt = response.reprompt; + + switch (this.type) { + case CipherType.Login: + this.login = new LoginData(response.login); + break; + case CipherType.SecureNote: + this.secureNote = new SecureNoteData(response.secureNote); + break; + case CipherType.Card: + this.card = new CardData(response.card); + break; + case CipherType.Identity: + this.identity = new IdentityData(response.identity); + break; + default: + break; + } + + if (response.fields != null) { + this.fields = response.fields.map((f) => new FieldData(f)); + } + if (response.attachments != null) { + this.attachments = response.attachments.map((a) => new AttachmentData(a)); + } + if (response.passwordHistory != null) { + this.passwordHistory = response.passwordHistory.map((ph) => new PasswordHistoryData(ph)); + } + } } diff --git a/common/src/models/data/collectionData.ts b/common/src/models/data/collectionData.ts index cc3ef64b..9e2607ed 100644 --- a/common/src/models/data/collectionData.ts +++ b/common/src/models/data/collectionData.ts @@ -1,17 +1,17 @@ -import { CollectionDetailsResponse } from '../response/collectionResponse'; +import { CollectionDetailsResponse } from "../response/collectionResponse"; export class CollectionData { - id: string; - organizationId: string; - name: string; - externalId: string; - readOnly: boolean; + id: string; + organizationId: string; + name: string; + externalId: string; + readOnly: boolean; - constructor(response: CollectionDetailsResponse) { - this.id = response.id; - this.organizationId = response.organizationId; - this.name = response.name; - this.externalId = response.externalId; - this.readOnly = response.readOnly; - } + constructor(response: CollectionDetailsResponse) { + this.id = response.id; + this.organizationId = response.organizationId; + this.name = response.name; + this.externalId = response.externalId; + this.readOnly = response.readOnly; + } } diff --git a/common/src/models/data/eventData.ts b/common/src/models/data/eventData.ts index f8639ad8..c0e38ddc 100644 --- a/common/src/models/data/eventData.ts +++ b/common/src/models/data/eventData.ts @@ -1,7 +1,7 @@ -import { EventType } from '../../enums/eventType'; +import { EventType } from "../../enums/eventType"; export class EventData { - type: EventType; - cipherId: string; - date: string; + type: EventType; + cipherId: string; + date: string; } diff --git a/common/src/models/data/fieldData.ts b/common/src/models/data/fieldData.ts index e83445f2..7b9fe197 100644 --- a/common/src/models/data/fieldData.ts +++ b/common/src/models/data/fieldData.ts @@ -1,21 +1,21 @@ -import { FieldType } from '../../enums/fieldType'; -import { LinkedIdType } from '../../enums/linkedIdType'; +import { FieldType } from "../../enums/fieldType"; +import { LinkedIdType } from "../../enums/linkedIdType"; -import { FieldApi } from '../api/fieldApi'; +import { FieldApi } from "../api/fieldApi"; export class FieldData { - type: FieldType; - name: string; - value: string; - linkedId: LinkedIdType; + type: FieldType; + name: string; + value: string; + linkedId: LinkedIdType; - constructor(response?: FieldApi) { - if (response == null) { - return; - } - this.type = response.type; - this.name = response.name; - this.value = response.value; - this.linkedId = response.linkedId; + constructor(response?: FieldApi) { + if (response == null) { + return; } + this.type = response.type; + this.name = response.name; + this.value = response.value; + this.linkedId = response.linkedId; + } } diff --git a/common/src/models/data/folderData.ts b/common/src/models/data/folderData.ts index 509267c9..459ba4de 100644 --- a/common/src/models/data/folderData.ts +++ b/common/src/models/data/folderData.ts @@ -1,15 +1,15 @@ -import { FolderResponse } from '../response/folderResponse'; +import { FolderResponse } from "../response/folderResponse"; export class FolderData { - id: string; - userId: string; - name: string; - revisionDate: string; + id: string; + userId: string; + name: string; + revisionDate: string; - constructor(response: FolderResponse, userId: string) { - this.userId = userId; - this.name = response.name; - this.id = response.id; - this.revisionDate = response.revisionDate; - } + constructor(response: FolderResponse, userId: string) { + this.userId = userId; + this.name = response.name; + this.id = response.id; + this.revisionDate = response.revisionDate; + } } diff --git a/common/src/models/data/identityData.ts b/common/src/models/data/identityData.ts index 50fff957..02aa7eb6 100644 --- a/common/src/models/data/identityData.ts +++ b/common/src/models/data/identityData.ts @@ -1,47 +1,47 @@ -import { IdentityApi } from '../api/identityApi'; +import { IdentityApi } from "../api/identityApi"; export class IdentityData { - title: string; - firstName: string; - middleName: string; - lastName: string; - address1: string; - address2: string; - address3: string; - city: string; - state: string; - postalCode: string; - country: string; - company: string; - email: string; - phone: string; - ssn: string; - username: string; - passportNumber: string; - licenseNumber: string; + title: string; + firstName: string; + middleName: string; + lastName: string; + address1: string; + address2: string; + address3: string; + city: string; + state: string; + postalCode: string; + country: string; + company: string; + email: string; + phone: string; + ssn: string; + username: string; + passportNumber: string; + licenseNumber: string; - constructor(data?: IdentityApi) { - if (data == null) { - return; - } - - this.title = data.title; - this.firstName = data.firstName; - this.middleName = data.middleName; - this.lastName = data.lastName; - this.address1 = data.address1; - this.address2 = data.address2; - this.address3 = data.address3; - this.city = data.city; - this.state = data.state; - this.postalCode = data.postalCode; - this.country = data.country; - this.company = data.company; - this.email = data.email; - this.phone = data.phone; - this.ssn = data.ssn; - this.username = data.username; - this.passportNumber = data.passportNumber; - this.licenseNumber = data.licenseNumber; + constructor(data?: IdentityApi) { + if (data == null) { + return; } + + this.title = data.title; + this.firstName = data.firstName; + this.middleName = data.middleName; + this.lastName = data.lastName; + this.address1 = data.address1; + this.address2 = data.address2; + this.address3 = data.address3; + this.city = data.city; + this.state = data.state; + this.postalCode = data.postalCode; + this.country = data.country; + this.company = data.company; + this.email = data.email; + this.phone = data.phone; + this.ssn = data.ssn; + this.username = data.username; + this.passportNumber = data.passportNumber; + this.licenseNumber = data.licenseNumber; + } } diff --git a/common/src/models/data/loginData.ts b/common/src/models/data/loginData.ts index 7b5d7027..e51180c8 100644 --- a/common/src/models/data/loginData.ts +++ b/common/src/models/data/loginData.ts @@ -1,28 +1,28 @@ -import { LoginApi } from '../api/loginApi'; +import { LoginApi } from "../api/loginApi"; -import { LoginUriData } from './loginUriData'; +import { LoginUriData } from "./loginUriData"; export class LoginData { - uris: LoginUriData[]; - username: string; - password: string; - passwordRevisionDate: string; - totp: string; - autofillOnPageLoad: boolean; + uris: LoginUriData[]; + username: string; + password: string; + passwordRevisionDate: string; + totp: string; + autofillOnPageLoad: boolean; - constructor(data?: LoginApi) { - if (data == null) { - return; - } - - this.username = data.username; - this.password = data.password; - this.passwordRevisionDate = data.passwordRevisionDate; - this.totp = data.totp; - this.autofillOnPageLoad = data.autofillOnPageLoad; - - if (data.uris) { - this.uris = data.uris.map(u => new LoginUriData(u)); - } + constructor(data?: LoginApi) { + if (data == null) { + return; } + + this.username = data.username; + this.password = data.password; + this.passwordRevisionDate = data.passwordRevisionDate; + this.totp = data.totp; + this.autofillOnPageLoad = data.autofillOnPageLoad; + + if (data.uris) { + this.uris = data.uris.map((u) => new LoginUriData(u)); + } + } } diff --git a/common/src/models/data/loginUriData.ts b/common/src/models/data/loginUriData.ts index e696355c..01cad0bf 100644 --- a/common/src/models/data/loginUriData.ts +++ b/common/src/models/data/loginUriData.ts @@ -1,16 +1,16 @@ -import { UriMatchType } from '../../enums/uriMatchType'; +import { UriMatchType } from "../../enums/uriMatchType"; -import { LoginUriApi } from '../api/loginUriApi'; +import { LoginUriApi } from "../api/loginUriApi"; export class LoginUriData { - uri: string; - match: UriMatchType = null; + uri: string; + match: UriMatchType = null; - constructor(data?: LoginUriApi) { - if (data == null) { - return; - } - this.uri = data.uri; - this.match = data.match; + constructor(data?: LoginUriApi) { + if (data == null) { + return; } + this.uri = data.uri; + this.match = data.match; + } } diff --git a/common/src/models/data/organizationData.ts b/common/src/models/data/organizationData.ts index c4061057..3903b0c2 100644 --- a/common/src/models/data/organizationData.ts +++ b/common/src/models/data/organizationData.ts @@ -1,80 +1,80 @@ -import { ProfileOrganizationResponse } from '../response/profileOrganizationResponse'; +import { ProfileOrganizationResponse } from "../response/profileOrganizationResponse"; -import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType'; -import { OrganizationUserType } from '../../enums/organizationUserType'; -import { ProductType } from '../../enums/productType'; +import { OrganizationUserStatusType } from "../../enums/organizationUserStatusType"; +import { OrganizationUserType } from "../../enums/organizationUserType"; +import { ProductType } from "../../enums/productType"; -import { PermissionsApi } from '../api/permissionsApi'; +import { PermissionsApi } from "../api/permissionsApi"; export class OrganizationData { - id: string; - name: string; - status: OrganizationUserStatusType; - type: OrganizationUserType; - enabled: boolean; - usePolicies: boolean; - useGroups: boolean; - useDirectory: boolean; - useEvents: boolean; - useTotp: boolean; - use2fa: boolean; - useApi: boolean; - useSso: boolean; - useKeyConnector: boolean; - useResetPassword: boolean; - selfHost: boolean; - usersGetPremium: boolean; - seats: number; - maxCollections: number; - maxStorageGb?: number; - ssoBound: boolean; - identifier: string; - permissions: PermissionsApi; - resetPasswordEnrolled: boolean; - userId: string; - hasPublicAndPrivateKeys: boolean; - providerId: string; - providerName: string; - isProviderUser: boolean; - familySponsorshipFriendlyName: string; - familySponsorshipAvailable: boolean; - planProductType: ProductType; - keyConnectorEnabled: boolean; - keyConnectorUrl: string; + id: string; + name: string; + status: OrganizationUserStatusType; + type: OrganizationUserType; + enabled: boolean; + usePolicies: boolean; + useGroups: boolean; + useDirectory: boolean; + useEvents: boolean; + useTotp: boolean; + use2fa: boolean; + useApi: boolean; + useSso: boolean; + useKeyConnector: boolean; + useResetPassword: boolean; + selfHost: boolean; + usersGetPremium: boolean; + seats: number; + maxCollections: number; + maxStorageGb?: number; + ssoBound: boolean; + identifier: string; + permissions: PermissionsApi; + resetPasswordEnrolled: boolean; + userId: string; + hasPublicAndPrivateKeys: boolean; + providerId: string; + providerName: string; + isProviderUser: boolean; + familySponsorshipFriendlyName: string; + familySponsorshipAvailable: boolean; + planProductType: ProductType; + keyConnectorEnabled: boolean; + keyConnectorUrl: string; - constructor(response: ProfileOrganizationResponse) { - this.id = response.id; - this.name = response.name; - this.status = response.status; - this.type = response.type; - this.enabled = response.enabled; - this.usePolicies = response.usePolicies; - this.useGroups = response.useGroups; - this.useDirectory = response.useDirectory; - this.useEvents = response.useEvents; - this.useTotp = response.useTotp; - this.use2fa = response.use2fa; - this.useApi = response.useApi; - this.useSso = response.useSso; - this.useKeyConnector = response.useKeyConnector; - this.useResetPassword = response.useResetPassword; - this.selfHost = response.selfHost; - this.usersGetPremium = response.usersGetPremium; - this.seats = response.seats; - this.maxCollections = response.maxCollections; - this.maxStorageGb = response.maxStorageGb; - this.ssoBound = response.ssoBound; - this.identifier = response.identifier; - this.permissions = response.permissions; - this.resetPasswordEnrolled = response.resetPasswordEnrolled; - this.userId = response.userId; - this.hasPublicAndPrivateKeys = response.hasPublicAndPrivateKeys; - this.providerId = response.providerId; - this.providerName = response.providerName; - this.familySponsorshipFriendlyName = response.familySponsorshipFriendlyName; - this.familySponsorshipAvailable = response.familySponsorshipAvailable; - this.planProductType = response.planProductType; - this.keyConnectorEnabled = response.keyConnectorEnabled; - this.keyConnectorUrl = response.keyConnectorUrl; - } + constructor(response: ProfileOrganizationResponse) { + this.id = response.id; + this.name = response.name; + this.status = response.status; + this.type = response.type; + this.enabled = response.enabled; + this.usePolicies = response.usePolicies; + this.useGroups = response.useGroups; + this.useDirectory = response.useDirectory; + this.useEvents = response.useEvents; + this.useTotp = response.useTotp; + this.use2fa = response.use2fa; + this.useApi = response.useApi; + this.useSso = response.useSso; + this.useKeyConnector = response.useKeyConnector; + this.useResetPassword = response.useResetPassword; + this.selfHost = response.selfHost; + this.usersGetPremium = response.usersGetPremium; + this.seats = response.seats; + this.maxCollections = response.maxCollections; + this.maxStorageGb = response.maxStorageGb; + this.ssoBound = response.ssoBound; + this.identifier = response.identifier; + this.permissions = response.permissions; + this.resetPasswordEnrolled = response.resetPasswordEnrolled; + this.userId = response.userId; + this.hasPublicAndPrivateKeys = response.hasPublicAndPrivateKeys; + this.providerId = response.providerId; + this.providerName = response.providerName; + this.familySponsorshipFriendlyName = response.familySponsorshipFriendlyName; + this.familySponsorshipAvailable = response.familySponsorshipAvailable; + this.planProductType = response.planProductType; + this.keyConnectorEnabled = response.keyConnectorEnabled; + this.keyConnectorUrl = response.keyConnectorUrl; + } } diff --git a/common/src/models/data/passwordHistoryData.ts b/common/src/models/data/passwordHistoryData.ts index 067c46fd..72436f3d 100644 --- a/common/src/models/data/passwordHistoryData.ts +++ b/common/src/models/data/passwordHistoryData.ts @@ -1,15 +1,15 @@ -import { PasswordHistoryResponse } from '../response/passwordHistoryResponse'; +import { PasswordHistoryResponse } from "../response/passwordHistoryResponse"; export class PasswordHistoryData { - password: string; - lastUsedDate: string; + password: string; + lastUsedDate: string; - constructor(response?: PasswordHistoryResponse) { - if (response == null) { - return; - } - - this.password = response.password; - this.lastUsedDate = response.lastUsedDate; + constructor(response?: PasswordHistoryResponse) { + if (response == null) { + return; } + + this.password = response.password; + this.lastUsedDate = response.lastUsedDate; + } } diff --git a/common/src/models/data/policyData.ts b/common/src/models/data/policyData.ts index 5f012424..46cbbeb9 100644 --- a/common/src/models/data/policyData.ts +++ b/common/src/models/data/policyData.ts @@ -1,19 +1,19 @@ -import { PolicyResponse } from '../response/policyResponse'; +import { PolicyResponse } from "../response/policyResponse"; -import { PolicyType } from '../../enums/policyType'; +import { PolicyType } from "../../enums/policyType"; export class PolicyData { - id: string; - organizationId: string; - type: PolicyType; - data: any; - enabled: boolean; + id: string; + organizationId: string; + type: PolicyType; + data: any; + enabled: boolean; - constructor(response: PolicyResponse) { - this.id = response.id; - this.organizationId = response.organizationId; - this.type = response.type; - this.data = response.data; - this.enabled = response.enabled; - } + constructor(response: PolicyResponse) { + this.id = response.id; + this.organizationId = response.organizationId; + this.type = response.type; + this.data = response.data; + this.enabled = response.enabled; + } } diff --git a/common/src/models/data/providerData.ts b/common/src/models/data/providerData.ts index 990a0190..7efdab05 100644 --- a/common/src/models/data/providerData.ts +++ b/common/src/models/data/providerData.ts @@ -1,24 +1,24 @@ -import { ProfileProviderResponse } from '../response/profileProviderResponse'; +import { ProfileProviderResponse } from "../response/profileProviderResponse"; -import { ProviderUserStatusType } from '../../enums/providerUserStatusType'; -import { ProviderUserType } from '../../enums/providerUserType'; +import { ProviderUserStatusType } from "../../enums/providerUserStatusType"; +import { ProviderUserType } from "../../enums/providerUserType"; export class ProviderData { - id: string; - name: string; - status: ProviderUserStatusType; - type: ProviderUserType; - enabled: boolean; - userId: string; - useEvents: boolean; + id: string; + name: string; + status: ProviderUserStatusType; + type: ProviderUserType; + enabled: boolean; + userId: string; + useEvents: boolean; - constructor(response: ProfileProviderResponse) { - this.id = response.id; - this.name = response.name; - this.status = response.status; - this.type = response.type; - this.enabled = response.enabled; - this.userId = response.userId; - this.useEvents = response.useEvents; - } + constructor(response: ProfileProviderResponse) { + this.id = response.id; + this.name = response.name; + this.status = response.status; + this.type = response.type; + this.enabled = response.enabled; + this.userId = response.userId; + this.useEvents = response.useEvents; + } } diff --git a/common/src/models/data/secureNoteData.ts b/common/src/models/data/secureNoteData.ts index 4a24f2cf..119c77b5 100644 --- a/common/src/models/data/secureNoteData.ts +++ b/common/src/models/data/secureNoteData.ts @@ -1,15 +1,15 @@ -import { SecureNoteType } from '../../enums/secureNoteType'; +import { SecureNoteType } from "../../enums/secureNoteType"; -import { SecureNoteApi } from '../api/secureNoteApi'; +import { SecureNoteApi } from "../api/secureNoteApi"; export class SecureNoteData { - type: SecureNoteType; + type: SecureNoteType; - constructor(data?: SecureNoteApi) { - if (data == null) { - return; - } - - this.type = data.type; + constructor(data?: SecureNoteApi) { + if (data == null) { + return; } + + this.type = data.type; + } } diff --git a/common/src/models/data/sendData.ts b/common/src/models/data/sendData.ts index 363429cc..d07dc362 100644 --- a/common/src/models/data/sendData.ts +++ b/common/src/models/data/sendData.ts @@ -1,59 +1,59 @@ -import { SendType } from '../../enums/sendType'; +import { SendType } from "../../enums/sendType"; -import { SendFileData } from './sendFileData'; -import { SendTextData } from './sendTextData'; +import { SendFileData } from "./sendFileData"; +import { SendTextData } from "./sendTextData"; -import { SendResponse } from '../response/sendResponse'; +import { SendResponse } from "../response/sendResponse"; export class SendData { - id: string; - accessId: string; - userId: string; - type: SendType; - name: string; - notes: string; - file: SendFileData; - text: SendTextData; - key: string; - maxAccessCount?: number; - accessCount: number; - revisionDate: string; - expirationDate: string; - deletionDate: string; - password: string; - disabled: boolean; - hideEmail: boolean; + id: string; + accessId: string; + userId: string; + type: SendType; + name: string; + notes: string; + file: SendFileData; + text: SendTextData; + key: string; + maxAccessCount?: number; + accessCount: number; + revisionDate: string; + expirationDate: string; + deletionDate: string; + password: string; + disabled: boolean; + hideEmail: boolean; - constructor(response?: SendResponse, userId?: string) { - if (response == null) { - return; - } - - this.id = response.id; - this.accessId = response.accessId; - this.userId = userId; - this.type = response.type; - this.name = response.name; - this.notes = response.notes; - this.key = response.key; - this.maxAccessCount = response.maxAccessCount; - this.accessCount = response.accessCount; - this.revisionDate = response.revisionDate; - this.expirationDate = response.expirationDate; - this.deletionDate = response.deletionDate; - this.password = response.password; - this.disabled = response.disable; - this.hideEmail = response.hideEmail; - - switch (this.type) { - case SendType.Text: - this.text = new SendTextData(response.text); - break; - case SendType.File: - this.file = new SendFileData(response.file); - break; - default: - break; - } + constructor(response?: SendResponse, userId?: string) { + if (response == null) { + return; } + + this.id = response.id; + this.accessId = response.accessId; + this.userId = userId; + this.type = response.type; + this.name = response.name; + this.notes = response.notes; + this.key = response.key; + this.maxAccessCount = response.maxAccessCount; + this.accessCount = response.accessCount; + this.revisionDate = response.revisionDate; + this.expirationDate = response.expirationDate; + this.deletionDate = response.deletionDate; + this.password = response.password; + this.disabled = response.disable; + this.hideEmail = response.hideEmail; + + switch (this.type) { + case SendType.Text: + this.text = new SendTextData(response.text); + break; + case SendType.File: + this.file = new SendFileData(response.file); + break; + default: + break; + } + } } diff --git a/common/src/models/data/sendFileData.ts b/common/src/models/data/sendFileData.ts index cb7b0850..d7bf8ea4 100644 --- a/common/src/models/data/sendFileData.ts +++ b/common/src/models/data/sendFileData.ts @@ -1,21 +1,21 @@ -import { SendFileApi } from '../api/sendFileApi'; +import { SendFileApi } from "../api/sendFileApi"; export class SendFileData { - id: string; - fileName: string; - key: string; - size: string; - sizeName: string; + id: string; + fileName: string; + key: string; + size: string; + sizeName: string; - constructor(data?: SendFileApi) { - if (data == null) { - return; - } - - this.id = data.id; - this.fileName = data.fileName; - this.key = data.key; - this.size = data.size; - this.sizeName = data.sizeName; + constructor(data?: SendFileApi) { + if (data == null) { + return; } + + this.id = data.id; + this.fileName = data.fileName; + this.key = data.key; + this.size = data.size; + this.sizeName = data.sizeName; + } } diff --git a/common/src/models/data/sendTextData.ts b/common/src/models/data/sendTextData.ts index 1d34adde..fedf2ed6 100644 --- a/common/src/models/data/sendTextData.ts +++ b/common/src/models/data/sendTextData.ts @@ -1,15 +1,15 @@ -import { SendTextApi } from '../api/sendTextApi'; +import { SendTextApi } from "../api/sendTextApi"; export class SendTextData { - text: string; - hidden: boolean; + text: string; + hidden: boolean; - constructor(data?: SendTextApi) { - if (data == null) { - return; - } - - this.text = data.text; - this.hidden = data.hidden; + constructor(data?: SendTextApi) { + if (data == null) { + return; } + + this.text = data.text; + this.hidden = data.hidden; + } } diff --git a/common/src/models/domain/attachment.ts b/common/src/models/domain/attachment.ts index 9f08a9df..ceafce3e 100644 --- a/common/src/models/domain/attachment.ts +++ b/common/src/models/domain/attachment.ts @@ -1,75 +1,91 @@ -import { AttachmentData } from '../data/attachmentData'; +import { AttachmentData } from "../data/attachmentData"; -import { AttachmentView } from '../view/attachmentView'; +import { AttachmentView } from "../view/attachmentView"; -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; -import { CryptoService } from '../../abstractions/crypto.service'; +import { CryptoService } from "../../abstractions/crypto.service"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; export class Attachment extends Domain { - id: string; - url: string; - size: string; - sizeName: string; - key: EncString; - fileName: EncString; + id: string; + url: string; + size: string; + sizeName: string; + key: EncString; + fileName: EncString; - constructor(obj?: AttachmentData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.size = obj.size; - this.buildDomainModel(this, obj, { - id: null, - url: null, - sizeName: null, - fileName: null, - key: null, - }, alreadyEncrypted, ['id', 'url', 'sizeName']); + constructor(obj?: AttachmentData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - async decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - const view = await this.decryptObj(new AttachmentView(this), { - fileName: null, - }, orgId, encKey); + this.size = obj.size; + this.buildDomainModel( + this, + obj, + { + id: null, + url: null, + sizeName: null, + fileName: null, + key: null, + }, + alreadyEncrypted, + ["id", "url", "sizeName"] + ); + } - if (this.key != null) { - let cryptoService: CryptoService; - const containerService = (Utils.global as any).bitwardenContainerService; - if (containerService) { - cryptoService = containerService.getCryptoService(); - } else { - throw new Error('global bitwardenContainerService not initialized.'); - } + async decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + const view = await this.decryptObj( + new AttachmentView(this), + { + fileName: null, + }, + orgId, + encKey + ); - try { - const orgKey = await cryptoService.getOrgKey(orgId); - const decValue = await cryptoService.decryptToBytes(this.key, orgKey ?? encKey); - view.key = new SymmetricCryptoKey(decValue); - } catch (e) { - // TODO: error? - } - } + if (this.key != null) { + let cryptoService: CryptoService; + const containerService = (Utils.global as any).bitwardenContainerService; + if (containerService) { + cryptoService = containerService.getCryptoService(); + } else { + throw new Error("global bitwardenContainerService not initialized."); + } - return view; + try { + const orgKey = await cryptoService.getOrgKey(orgId); + const decValue = await cryptoService.decryptToBytes(this.key, orgKey ?? encKey); + view.key = new SymmetricCryptoKey(decValue); + } catch (e) { + // TODO: error? + } } - toAttachmentData(): AttachmentData { - const a = new AttachmentData(); - a.size = this.size; - this.buildDataModel(this, a, { - id: null, - url: null, - sizeName: null, - fileName: null, - key: null, - }, ['id', 'url', 'sizeName']); - return a; - } + return view; + } + + toAttachmentData(): AttachmentData { + const a = new AttachmentData(); + a.size = this.size; + this.buildDataModel( + this, + a, + { + id: null, + url: null, + sizeName: null, + fileName: null, + key: null, + }, + ["id", "url", "sizeName"] + ); + return a; + } } diff --git a/common/src/models/domain/authResult.ts b/common/src/models/domain/authResult.ts index 7c5a39c1..eadad50f 100644 --- a/common/src/models/domain/authResult.ts +++ b/common/src/models/domain/authResult.ts @@ -1,9 +1,9 @@ -import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; +import { TwoFactorProviderType } from "../../enums/twoFactorProviderType"; export class AuthResult { - twoFactor: boolean = false; - captchaSiteKey: string = ''; - resetMasterPassword: boolean = false; - forcePasswordReset: boolean = false; - twoFactorProviders: Map = null; + twoFactor: boolean = false; + captchaSiteKey: string = ""; + resetMasterPassword: boolean = false; + forcePasswordReset: boolean = false; + twoFactorProviders: Map = null; } diff --git a/common/src/models/domain/card.ts b/common/src/models/domain/card.ts index da703608..62315d63 100644 --- a/common/src/models/domain/card.ts +++ b/common/src/models/domain/card.ts @@ -1,56 +1,67 @@ -import { CardData } from '../data/cardData'; +import { CardData } from "../data/cardData"; -import Domain from './domainBase'; -import { EncString } from './encString'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; -import { CardView } from '../view/cardView'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { CardView } from "../view/cardView"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class Card extends Domain { - cardholderName: EncString; - brand: EncString; - number: EncString; - expMonth: EncString; - expYear: EncString; - code: EncString; + cardholderName: EncString; + brand: EncString; + number: EncString; + expMonth: EncString; + expYear: EncString; + code: EncString; - constructor(obj?: CardData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - cardholderName: null, - brand: null, - number: null, - expMonth: null, - expYear: null, - code: null, - }, alreadyEncrypted, []); + constructor(obj?: CardData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - return this.decryptObj(new CardView(this), { - cardholderName: null, - brand: null, - number: null, - expMonth: null, - expYear: null, - code: null, - }, orgId, encKey); - } + this.buildDomainModel( + this, + obj, + { + cardholderName: null, + brand: null, + number: null, + expMonth: null, + expYear: null, + code: null, + }, + alreadyEncrypted, + [] + ); + } - toCardData(): CardData { - const c = new CardData(); - this.buildDataModel(this, c, { - cardholderName: null, - brand: null, - number: null, - expMonth: null, - expYear: null, - code: null, - }); - return c; - } + decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + return this.decryptObj( + new CardView(this), + { + cardholderName: null, + brand: null, + number: null, + expMonth: null, + expYear: null, + code: null, + }, + orgId, + encKey + ); + } + + toCardData(): CardData { + const c = new CardData(); + this.buildDataModel(this, c, { + cardholderName: null, + brand: null, + number: null, + expMonth: null, + expYear: null, + code: null, + }); + return c; + } } diff --git a/common/src/models/domain/cipher.ts b/common/src/models/domain/cipher.ts index 1eeb0387..14a7a14a 100644 --- a/common/src/models/domain/cipher.ts +++ b/common/src/models/domain/cipher.ts @@ -1,224 +1,241 @@ -import { CipherRepromptType } from '../../enums/cipherRepromptType'; -import { CipherType } from '../../enums/cipherType'; +import { CipherRepromptType } from "../../enums/cipherRepromptType"; +import { CipherType } from "../../enums/cipherType"; -import { CipherData } from '../data/cipherData'; +import { CipherData } from "../data/cipherData"; -import { CipherView } from '../view/cipherView'; +import { CipherView } from "../view/cipherView"; -import { Attachment } from './attachment'; -import { Card } from './card'; -import Domain from './domainBase'; -import { EncString } from './encString'; -import { Field } from './field'; -import { Identity } from './identity'; -import { Login } from './login'; -import { Password } from './password'; -import { SecureNote } from './secureNote'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { Attachment } from "./attachment"; +import { Card } from "./card"; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { Field } from "./field"; +import { Identity } from "./identity"; +import { Login } from "./login"; +import { Password } from "./password"; +import { SecureNote } from "./secureNote"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class Cipher extends Domain { - id: string; - organizationId: string; - folderId: string; - name: EncString; - notes: EncString; - type: CipherType; - favorite: boolean; - organizationUseTotp: boolean; - edit: boolean; - viewPassword: boolean; - revisionDate: Date; - localData: any; - login: Login; - identity: Identity; - card: Card; - secureNote: SecureNote; - attachments: Attachment[]; - fields: Field[]; - passwordHistory: Password[]; - collectionIds: string[]; - deletedDate: Date; - reprompt: CipherRepromptType; + id: string; + organizationId: string; + folderId: string; + name: EncString; + notes: EncString; + type: CipherType; + favorite: boolean; + organizationUseTotp: boolean; + edit: boolean; + viewPassword: boolean; + revisionDate: Date; + localData: any; + login: Login; + identity: Identity; + card: Card; + secureNote: SecureNote; + attachments: Attachment[]; + fields: Field[]; + passwordHistory: Password[]; + collectionIds: string[]; + deletedDate: Date; + reprompt: CipherRepromptType; - constructor(obj?: CipherData, alreadyEncrypted: boolean = false, localData: any = null) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - id: null, - userId: null, - organizationId: null, - folderId: null, - name: null, - notes: null, - }, alreadyEncrypted, ['id', 'userId', 'organizationId', 'folderId']); - - this.type = obj.type; - this.favorite = obj.favorite; - this.organizationUseTotp = obj.organizationUseTotp; - this.edit = obj.edit; - if (obj.viewPassword != null) { - this.viewPassword = obj.viewPassword; - } else { - this.viewPassword = true; // Default for already synced Ciphers without viewPassword - } - this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null; - this.collectionIds = obj.collectionIds; - this.localData = localData; - this.deletedDate = obj.deletedDate != null ? new Date(obj.deletedDate) : null; - this.reprompt = obj.reprompt; - - switch (this.type) { - case CipherType.Login: - this.login = new Login(obj.login, alreadyEncrypted); - break; - case CipherType.SecureNote: - this.secureNote = new SecureNote(obj.secureNote, alreadyEncrypted); - break; - case CipherType.Card: - this.card = new Card(obj.card, alreadyEncrypted); - break; - case CipherType.Identity: - this.identity = new Identity(obj.identity, alreadyEncrypted); - break; - default: - break; - } - - if (obj.attachments != null) { - this.attachments = obj.attachments.map(a => new Attachment(a, alreadyEncrypted)); - } else { - this.attachments = null; - } - - if (obj.fields != null) { - this.fields = obj.fields.map(f => new Field(f, alreadyEncrypted)); - } else { - this.fields = null; - } - - if (obj.passwordHistory != null) { - this.passwordHistory = obj.passwordHistory.map(ph => new Password(ph, alreadyEncrypted)); - } else { - this.passwordHistory = null; - } + constructor(obj?: CipherData, alreadyEncrypted: boolean = false, localData: any = null) { + super(); + if (obj == null) { + return; } - async decrypt(encKey?: SymmetricCryptoKey): Promise { - const model = new CipherView(this); + this.buildDomainModel( + this, + obj, + { + id: null, + userId: null, + organizationId: null, + folderId: null, + name: null, + notes: null, + }, + alreadyEncrypted, + ["id", "userId", "organizationId", "folderId"] + ); - await this.decryptObj(model, { - name: null, - notes: null, - }, this.organizationId, encKey); + this.type = obj.type; + this.favorite = obj.favorite; + this.organizationUseTotp = obj.organizationUseTotp; + this.edit = obj.edit; + if (obj.viewPassword != null) { + this.viewPassword = obj.viewPassword; + } else { + this.viewPassword = true; // Default for already synced Ciphers without viewPassword + } + this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null; + this.collectionIds = obj.collectionIds; + this.localData = localData; + this.deletedDate = obj.deletedDate != null ? new Date(obj.deletedDate) : null; + this.reprompt = obj.reprompt; - switch (this.type) { - case CipherType.Login: - model.login = await this.login.decrypt(this.organizationId, encKey); - break; - case CipherType.SecureNote: - model.secureNote = await this.secureNote.decrypt(this.organizationId, encKey); - break; - case CipherType.Card: - model.card = await this.card.decrypt(this.organizationId, encKey); - break; - case CipherType.Identity: - model.identity = await this.identity.decrypt(this.organizationId, encKey); - break; - default: - break; - } - - const orgId = this.organizationId; - - if (this.attachments != null && this.attachments.length > 0) { - const attachments: any[] = []; - await this.attachments.reduce((promise, attachment) => { - return promise.then(() => { - return attachment.decrypt(orgId, encKey); - }).then(decAttachment => { - attachments.push(decAttachment); - }); - }, Promise.resolve()); - model.attachments = attachments; - } - - if (this.fields != null && this.fields.length > 0) { - const fields: any[] = []; - await this.fields.reduce((promise, field) => { - return promise.then(() => { - return field.decrypt(orgId, encKey); - }).then(decField => { - fields.push(decField); - }); - }, Promise.resolve()); - model.fields = fields; - } - - if (this.passwordHistory != null && this.passwordHistory.length > 0) { - const passwordHistory: any[] = []; - await this.passwordHistory.reduce((promise, ph) => { - return promise.then(() => { - return ph.decrypt(orgId, encKey); - }).then(decPh => { - passwordHistory.push(decPh); - }); - }, Promise.resolve()); - model.passwordHistory = passwordHistory; - } - - return model; + switch (this.type) { + case CipherType.Login: + this.login = new Login(obj.login, alreadyEncrypted); + break; + case CipherType.SecureNote: + this.secureNote = new SecureNote(obj.secureNote, alreadyEncrypted); + break; + case CipherType.Card: + this.card = new Card(obj.card, alreadyEncrypted); + break; + case CipherType.Identity: + this.identity = new Identity(obj.identity, alreadyEncrypted); + break; + default: + break; } - toCipherData(userId: string): CipherData { - const c = new CipherData(); - c.id = this.id; - c.organizationId = this.organizationId; - c.folderId = this.folderId; - c.userId = this.organizationId != null ? userId : null; - c.edit = this.edit; - c.viewPassword = this.viewPassword; - c.organizationUseTotp = this.organizationUseTotp; - c.favorite = this.favorite; - c.revisionDate = this.revisionDate != null ? this.revisionDate.toISOString() : null; - c.type = this.type; - c.collectionIds = this.collectionIds; - c.deletedDate = this.deletedDate != null ? this.deletedDate.toISOString() : null; - c.reprompt = this.reprompt; - - this.buildDataModel(this, c, { - name: null, - notes: null, - }); - - switch (c.type) { - case CipherType.Login: - c.login = this.login.toLoginData(); - break; - case CipherType.SecureNote: - c.secureNote = this.secureNote.toSecureNoteData(); - break; - case CipherType.Card: - c.card = this.card.toCardData(); - break; - case CipherType.Identity: - c.identity = this.identity.toIdentityData(); - break; - default: - break; - } - - if (this.fields != null) { - c.fields = this.fields.map(f => f.toFieldData()); - } - if (this.attachments != null) { - c.attachments = this.attachments.map(a => a.toAttachmentData()); - } - if (this.passwordHistory != null) { - c.passwordHistory = this.passwordHistory.map(ph => ph.toPasswordHistoryData()); - } - return c; + if (obj.attachments != null) { + this.attachments = obj.attachments.map((a) => new Attachment(a, alreadyEncrypted)); + } else { + this.attachments = null; } + + if (obj.fields != null) { + this.fields = obj.fields.map((f) => new Field(f, alreadyEncrypted)); + } else { + this.fields = null; + } + + if (obj.passwordHistory != null) { + this.passwordHistory = obj.passwordHistory.map((ph) => new Password(ph, alreadyEncrypted)); + } else { + this.passwordHistory = null; + } + } + + async decrypt(encKey?: SymmetricCryptoKey): Promise { + const model = new CipherView(this); + + await this.decryptObj( + model, + { + name: null, + notes: null, + }, + this.organizationId, + encKey + ); + + switch (this.type) { + case CipherType.Login: + model.login = await this.login.decrypt(this.organizationId, encKey); + break; + case CipherType.SecureNote: + model.secureNote = await this.secureNote.decrypt(this.organizationId, encKey); + break; + case CipherType.Card: + model.card = await this.card.decrypt(this.organizationId, encKey); + break; + case CipherType.Identity: + model.identity = await this.identity.decrypt(this.organizationId, encKey); + break; + default: + break; + } + + const orgId = this.organizationId; + + if (this.attachments != null && this.attachments.length > 0) { + const attachments: any[] = []; + await this.attachments.reduce((promise, attachment) => { + return promise + .then(() => { + return attachment.decrypt(orgId, encKey); + }) + .then((decAttachment) => { + attachments.push(decAttachment); + }); + }, Promise.resolve()); + model.attachments = attachments; + } + + if (this.fields != null && this.fields.length > 0) { + const fields: any[] = []; + await this.fields.reduce((promise, field) => { + return promise + .then(() => { + return field.decrypt(orgId, encKey); + }) + .then((decField) => { + fields.push(decField); + }); + }, Promise.resolve()); + model.fields = fields; + } + + if (this.passwordHistory != null && this.passwordHistory.length > 0) { + const passwordHistory: any[] = []; + await this.passwordHistory.reduce((promise, ph) => { + return promise + .then(() => { + return ph.decrypt(orgId, encKey); + }) + .then((decPh) => { + passwordHistory.push(decPh); + }); + }, Promise.resolve()); + model.passwordHistory = passwordHistory; + } + + return model; + } + + toCipherData(userId: string): CipherData { + const c = new CipherData(); + c.id = this.id; + c.organizationId = this.organizationId; + c.folderId = this.folderId; + c.userId = this.organizationId != null ? userId : null; + c.edit = this.edit; + c.viewPassword = this.viewPassword; + c.organizationUseTotp = this.organizationUseTotp; + c.favorite = this.favorite; + c.revisionDate = this.revisionDate != null ? this.revisionDate.toISOString() : null; + c.type = this.type; + c.collectionIds = this.collectionIds; + c.deletedDate = this.deletedDate != null ? this.deletedDate.toISOString() : null; + c.reprompt = this.reprompt; + + this.buildDataModel(this, c, { + name: null, + notes: null, + }); + + switch (c.type) { + case CipherType.Login: + c.login = this.login.toLoginData(); + break; + case CipherType.SecureNote: + c.secureNote = this.secureNote.toSecureNoteData(); + break; + case CipherType.Card: + c.card = this.card.toCardData(); + break; + case CipherType.Identity: + c.identity = this.identity.toIdentityData(); + break; + default: + break; + } + + if (this.fields != null) { + c.fields = this.fields.map((f) => f.toFieldData()); + } + if (this.attachments != null) { + c.attachments = this.attachments.map((a) => a.toAttachmentData()); + } + if (this.passwordHistory != null) { + c.passwordHistory = this.passwordHistory.map((ph) => ph.toPasswordHistoryData()); + } + return c; + } } diff --git a/common/src/models/domain/collection.ts b/common/src/models/domain/collection.ts index 35a014ad..b08ecd0f 100644 --- a/common/src/models/domain/collection.ts +++ b/common/src/models/domain/collection.ts @@ -1,37 +1,47 @@ -import { CollectionData } from '../data/collectionData'; +import { CollectionData } from "../data/collectionData"; -import { CollectionView } from '../view/collectionView'; +import { CollectionView } from "../view/collectionView"; -import Domain from './domainBase'; -import { EncString } from './encString'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; export class Collection extends Domain { - id: string; - organizationId: string; - name: EncString; - externalId: string; - readOnly: boolean; - hidePasswords: boolean; + id: string; + organizationId: string; + name: EncString; + externalId: string; + readOnly: boolean; + hidePasswords: boolean; - constructor(obj?: CollectionData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - id: null, - organizationId: null, - name: null, - externalId: null, - readOnly: null, - hidePasswords: null, - }, alreadyEncrypted, ['id', 'organizationId', 'externalId', 'readOnly', 'hidePasswords']); + constructor(obj?: CollectionData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(): Promise { - return this.decryptObj(new CollectionView(this), { - name: null, - }, this.organizationId); - } + this.buildDomainModel( + this, + obj, + { + id: null, + organizationId: null, + name: null, + externalId: null, + readOnly: null, + hidePasswords: null, + }, + alreadyEncrypted, + ["id", "organizationId", "externalId", "readOnly", "hidePasswords"] + ); + } + + decrypt(): Promise { + return this.decryptObj( + new CollectionView(this), + { + name: null, + }, + this.organizationId + ); + } } diff --git a/common/src/models/domain/decryptParameters.ts b/common/src/models/domain/decryptParameters.ts index 1274e88d..09a4c1d8 100644 --- a/common/src/models/domain/decryptParameters.ts +++ b/common/src/models/domain/decryptParameters.ts @@ -1,8 +1,8 @@ export class DecryptParameters { - encKey: T; - data: T; - iv: T; - macKey: T; - mac: T; - macData: T; + encKey: T; + data: T; + iv: T; + macKey: T; + mac: T; + macData: T; } diff --git a/common/src/models/domain/domainBase.ts b/common/src/models/domain/domainBase.ts index dbf90243..a8c09abe 100644 --- a/common/src/models/domain/domainBase.ts +++ b/common/src/models/domain/domainBase.ts @@ -1,66 +1,82 @@ -import { EncString } from './encString'; +import { EncString } from "./encString"; -import { View } from '../view/view'; +import { View } from "../view/view"; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export default class Domain { - protected buildDomainModel(domain: D, dataObj: any, map: any, - alreadyEncrypted: boolean, notEncList: any[] = []) { - for (const prop in map) { - if (!map.hasOwnProperty(prop)) { - continue; - } + protected buildDomainModel( + domain: D, + dataObj: any, + map: any, + alreadyEncrypted: boolean, + notEncList: any[] = [] + ) { + for (const prop in map) { + if (!map.hasOwnProperty(prop)) { + continue; + } - const objProp = dataObj[(map[prop] || prop)]; - if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) { - (domain as any)[prop] = objProp ? objProp : null; - } else { - (domain as any)[prop] = objProp ? new EncString(objProp) : null; - } - } + const objProp = dataObj[map[prop] || prop]; + if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) { + (domain as any)[prop] = objProp ? objProp : null; + } else { + (domain as any)[prop] = objProp ? new EncString(objProp) : null; + } } - protected buildDataModel(domain: D, dataObj: any, map: any, notEncStringList: any[] = []) { - for (const prop in map) { - if (!map.hasOwnProperty(prop)) { - continue; - } + } + protected buildDataModel( + domain: D, + dataObj: any, + map: any, + notEncStringList: any[] = [] + ) { + for (const prop in map) { + if (!map.hasOwnProperty(prop)) { + continue; + } - const objProp = (domain as any)[(map[prop] || prop)]; - if (notEncStringList.indexOf(prop) > -1) { - (dataObj as any)[prop] = objProp != null ? objProp : null; - } else { - (dataObj as any)[prop] = objProp != null ? (objProp as EncString).encryptedString : null; + const objProp = (domain as any)[map[prop] || prop]; + if (notEncStringList.indexOf(prop) > -1) { + (dataObj as any)[prop] = objProp != null ? objProp : null; + } else { + (dataObj as any)[prop] = objProp != null ? (objProp as EncString).encryptedString : null; + } + } + } + + protected async decryptObj( + viewModel: T, + map: any, + orgId: string, + key: SymmetricCryptoKey = null + ): Promise { + const promises = []; + const self: any = this; + + for (const prop in map) { + if (!map.hasOwnProperty(prop)) { + continue; + } + + // tslint:disable-next-line + (function (theProp) { + const p = Promise.resolve() + .then(() => { + const mapProp = map[theProp] || theProp; + if (self[mapProp]) { + return self[mapProp].decrypt(orgId, key); } - } + return null; + }) + .then((val: any) => { + (viewModel as any)[theProp] = val; + }); + promises.push(p); + })(prop); } - protected async decryptObj(viewModel: T, map: any, orgId: string, - key: SymmetricCryptoKey = null): Promise { - const promises = []; - const self: any = this; - - for (const prop in map) { - if (!map.hasOwnProperty(prop)) { - continue; - } - - // tslint:disable-next-line - (function (theProp) { - const p = Promise.resolve().then(() => { - const mapProp = map[theProp] || theProp; - if (self[mapProp]) { - return self[mapProp].decrypt(orgId, key); - } - return null; - }).then((val: any) => { - (viewModel as any)[theProp] = val; - }); - promises.push(p); - })(prop); - } - - await Promise.all(promises); - return viewModel; - } + await Promise.all(promises); + return viewModel; + } } diff --git a/common/src/models/domain/encArrayBuffer.ts b/common/src/models/domain/encArrayBuffer.ts index abc16917..97f47c39 100644 --- a/common/src/models/domain/encArrayBuffer.ts +++ b/common/src/models/domain/encArrayBuffer.ts @@ -1,3 +1,3 @@ export class EncArrayBuffer { - constructor(public buffer: ArrayBuffer) { } + constructor(public buffer: ArrayBuffer) {} } diff --git a/common/src/models/domain/encString.ts b/common/src/models/domain/encString.ts index 58811e23..9ce1c394 100644 --- a/common/src/models/domain/encString.ts +++ b/common/src/models/domain/encString.ts @@ -1,117 +1,124 @@ -import { EncryptionType } from '../../enums/encryptionType'; +import { EncryptionType } from "../../enums/encryptionType"; -import { CryptoService } from '../../abstractions/crypto.service'; +import { CryptoService } from "../../abstractions/crypto.service"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class EncString { - encryptedString?: string; - encryptionType?: EncryptionType; - decryptedValue?: string; - data?: string; - iv?: string; - mac?: string; + encryptedString?: string; + encryptionType?: EncryptionType; + decryptedValue?: string; + data?: string; + iv?: string; + mac?: string; - constructor(encryptedStringOrType: string | EncryptionType, data?: string, iv?: string, mac?: string) { - if (data != null) { - // data and header - const encType = encryptedStringOrType as EncryptionType; + constructor( + encryptedStringOrType: string | EncryptionType, + data?: string, + iv?: string, + mac?: string + ) { + if (data != null) { + // data and header + const encType = encryptedStringOrType as EncryptionType; - if (iv != null) { - this.encryptedString = encType + '.' + iv + '|' + data; - } else { - this.encryptedString = encType + '.' + data; - } + if (iv != null) { + this.encryptedString = encType + "." + iv + "|" + data; + } else { + this.encryptedString = encType + "." + data; + } - // mac - if (mac != null) { - this.encryptedString += ('|' + mac); - } + // mac + if (mac != null) { + this.encryptedString += "|" + mac; + } - this.encryptionType = encType; - this.data = data; - this.iv = iv; - this.mac = mac; + this.encryptionType = encType; + this.data = data; + this.iv = iv; + this.mac = mac; - return; - } - - this.encryptedString = encryptedStringOrType as string; - if (!this.encryptedString) { - return; - } - - const headerPieces = this.encryptedString.split('.'); - let encPieces: string[] = null; - - if (headerPieces.length === 2) { - try { - this.encryptionType = parseInt(headerPieces[0], null); - encPieces = headerPieces[1].split('|'); - } catch (e) { - return; - } - } else { - encPieces = this.encryptedString.split('|'); - this.encryptionType = encPieces.length === 3 ? EncryptionType.AesCbc128_HmacSha256_B64 : - EncryptionType.AesCbc256_B64; - } - - switch (this.encryptionType) { - case EncryptionType.AesCbc128_HmacSha256_B64: - case EncryptionType.AesCbc256_HmacSha256_B64: - if (encPieces.length !== 3) { - return; - } - - this.iv = encPieces[0]; - this.data = encPieces[1]; - this.mac = encPieces[2]; - break; - case EncryptionType.AesCbc256_B64: - if (encPieces.length !== 2) { - return; - } - - this.iv = encPieces[0]; - this.data = encPieces[1]; - break; - case EncryptionType.Rsa2048_OaepSha256_B64: - case EncryptionType.Rsa2048_OaepSha1_B64: - if (encPieces.length !== 1) { - return; - } - - this.data = encPieces[0]; - break; - default: - return; - } + return; } - async decrypt(orgId: string, key: SymmetricCryptoKey = null): Promise { - if (this.decryptedValue != null) { - return this.decryptedValue; - } - - let cryptoService: CryptoService; - const containerService = (Utils.global as any).bitwardenContainerService; - if (containerService) { - cryptoService = containerService.getCryptoService(); - } else { - throw new Error('global bitwardenContainerService not initialized.'); - } - - try { - if (key == null) { - key = await cryptoService.getOrgKey(orgId); - } - this.decryptedValue = await cryptoService.decryptToUtf8(this, key); - } catch (e) { - this.decryptedValue = '[error: cannot decrypt]'; - } - return this.decryptedValue; + this.encryptedString = encryptedStringOrType as string; + if (!this.encryptedString) { + return; } + + const headerPieces = this.encryptedString.split("."); + let encPieces: string[] = null; + + if (headerPieces.length === 2) { + try { + this.encryptionType = parseInt(headerPieces[0], null); + encPieces = headerPieces[1].split("|"); + } catch (e) { + return; + } + } else { + encPieces = this.encryptedString.split("|"); + this.encryptionType = + encPieces.length === 3 + ? EncryptionType.AesCbc128_HmacSha256_B64 + : EncryptionType.AesCbc256_B64; + } + + switch (this.encryptionType) { + case EncryptionType.AesCbc128_HmacSha256_B64: + case EncryptionType.AesCbc256_HmacSha256_B64: + if (encPieces.length !== 3) { + return; + } + + this.iv = encPieces[0]; + this.data = encPieces[1]; + this.mac = encPieces[2]; + break; + case EncryptionType.AesCbc256_B64: + if (encPieces.length !== 2) { + return; + } + + this.iv = encPieces[0]; + this.data = encPieces[1]; + break; + case EncryptionType.Rsa2048_OaepSha256_B64: + case EncryptionType.Rsa2048_OaepSha1_B64: + if (encPieces.length !== 1) { + return; + } + + this.data = encPieces[0]; + break; + default: + return; + } + } + + async decrypt(orgId: string, key: SymmetricCryptoKey = null): Promise { + if (this.decryptedValue != null) { + return this.decryptedValue; + } + + let cryptoService: CryptoService; + const containerService = (Utils.global as any).bitwardenContainerService; + if (containerService) { + cryptoService = containerService.getCryptoService(); + } else { + throw new Error("global bitwardenContainerService not initialized."); + } + + try { + if (key == null) { + key = await cryptoService.getOrgKey(orgId); + } + this.decryptedValue = await cryptoService.decryptToUtf8(this, key); + } catch (e) { + this.decryptedValue = "[error: cannot decrypt]"; + } + return this.decryptedValue; + } } diff --git a/common/src/models/domain/encryptedObject.ts b/common/src/models/domain/encryptedObject.ts index f21fe300..5ce93dbe 100644 --- a/common/src/models/domain/encryptedObject.ts +++ b/common/src/models/domain/encryptedObject.ts @@ -1,8 +1,8 @@ -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class EncryptedObject { - iv: ArrayBuffer; - data: ArrayBuffer; - mac: ArrayBuffer; - key: SymmetricCryptoKey; + iv: ArrayBuffer; + data: ArrayBuffer; + mac: ArrayBuffer; + key: SymmetricCryptoKey; } diff --git a/common/src/models/domain/environmentUrls.ts b/common/src/models/domain/environmentUrls.ts index 2241bd0a..6426fef4 100644 --- a/common/src/models/domain/environmentUrls.ts +++ b/common/src/models/domain/environmentUrls.ts @@ -1,6 +1,6 @@ export class EnvironmentUrls { - base: string; - api: string; - identity: string; - events: string; + base: string; + api: string; + identity: string; + events: string; } diff --git a/common/src/models/domain/field.ts b/common/src/models/domain/field.ts index 7174797d..0aaf2a31 100644 --- a/common/src/models/domain/field.ts +++ b/common/src/models/domain/field.ts @@ -1,49 +1,65 @@ -import { FieldType } from '../../enums/fieldType'; -import { LinkedIdType } from '../../enums/linkedIdType'; +import { FieldType } from "../../enums/fieldType"; +import { LinkedIdType } from "../../enums/linkedIdType"; -import { FieldData } from '../data/fieldData'; +import { FieldData } from "../data/fieldData"; -import Domain from './domainBase'; -import { EncString } from './encString'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; -import { FieldView } from '../view/fieldView'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { FieldView } from "../view/fieldView"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class Field extends Domain { - name: EncString; - value: EncString; - type: FieldType; - linkedId: LinkedIdType; + name: EncString; + value: EncString; + type: FieldType; + linkedId: LinkedIdType; - constructor(obj?: FieldData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.type = obj.type; - this.linkedId = obj.linkedId; - this.buildDomainModel(this, obj, { - name: null, - value: null, - }, alreadyEncrypted, []); + constructor(obj?: FieldData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - return this.decryptObj(new FieldView(this), { - name: null, - value: null, - }, orgId, encKey); - } + this.type = obj.type; + this.linkedId = obj.linkedId; + this.buildDomainModel( + this, + obj, + { + name: null, + value: null, + }, + alreadyEncrypted, + [] + ); + } - toFieldData(): FieldData { - const f = new FieldData(); - this.buildDataModel(this, f, { - name: null, - value: null, - type: null, - linkedId: null, - }, ['type', 'linkedId']); - return f; - } + decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + return this.decryptObj( + new FieldView(this), + { + name: null, + value: null, + }, + orgId, + encKey + ); + } + + toFieldData(): FieldData { + const f = new FieldData(); + this.buildDataModel( + this, + f, + { + name: null, + value: null, + type: null, + linkedId: null, + }, + ["type", "linkedId"] + ); + return f; + } } diff --git a/common/src/models/domain/folder.ts b/common/src/models/domain/folder.ts index 7f267c07..4e4a08f2 100644 --- a/common/src/models/domain/folder.ts +++ b/common/src/models/domain/folder.ts @@ -1,32 +1,42 @@ -import { FolderData } from '../data/folderData'; +import { FolderData } from "../data/folderData"; -import { FolderView } from '../view/folderView'; +import { FolderView } from "../view/folderView"; -import Domain from './domainBase'; -import { EncString } from './encString'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; export class Folder extends Domain { - id: string; - name: EncString; - revisionDate: Date; + id: string; + name: EncString; + revisionDate: Date; - constructor(obj?: FolderData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - id: null, - name: null, - }, alreadyEncrypted, ['id']); - - this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null; + constructor(obj?: FolderData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(): Promise { - return this.decryptObj(new FolderView(this), { - name: null, - }, null); - } + this.buildDomainModel( + this, + obj, + { + id: null, + name: null, + }, + alreadyEncrypted, + ["id"] + ); + + this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null; + } + + decrypt(): Promise { + return this.decryptObj( + new FolderView(this), + { + name: null, + }, + null + ); + } } diff --git a/common/src/models/domain/generatedPasswordHistory.ts b/common/src/models/domain/generatedPasswordHistory.ts index 1b082565..b4cc9b22 100644 --- a/common/src/models/domain/generatedPasswordHistory.ts +++ b/common/src/models/domain/generatedPasswordHistory.ts @@ -1,9 +1,9 @@ export class GeneratedPasswordHistory { - password: string; - date: number; + password: string; + date: number; - constructor(password: string, date: number) { - this.password = password; - this.date = date; - } + constructor(password: string, date: number) { + this.password = password; + this.date = date; + } } diff --git a/common/src/models/domain/identity.ts b/common/src/models/domain/identity.ts index df08293c..8584c946 100644 --- a/common/src/models/domain/identity.ts +++ b/common/src/models/domain/identity.ts @@ -1,104 +1,115 @@ -import { IdentityData } from '../data/identityData'; +import { IdentityData } from "../data/identityData"; -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; -import { IdentityView } from '../view/identityView'; +import { IdentityView } from "../view/identityView"; export class Identity extends Domain { - title: EncString; - firstName: EncString; - middleName: EncString; - lastName: EncString; - address1: EncString; - address2: EncString; - address3: EncString; - city: EncString; - state: EncString; - postalCode: EncString; - country: EncString; - company: EncString; - email: EncString; - phone: EncString; - ssn: EncString; - username: EncString; - passportNumber: EncString; - licenseNumber: EncString; + title: EncString; + firstName: EncString; + middleName: EncString; + lastName: EncString; + address1: EncString; + address2: EncString; + address3: EncString; + city: EncString; + state: EncString; + postalCode: EncString; + country: EncString; + company: EncString; + email: EncString; + phone: EncString; + ssn: EncString; + username: EncString; + passportNumber: EncString; + licenseNumber: EncString; - constructor(obj?: IdentityData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - title: null, - firstName: null, - middleName: null, - lastName: null, - address1: null, - address2: null, - address3: null, - city: null, - state: null, - postalCode: null, - country: null, - company: null, - email: null, - phone: null, - ssn: null, - username: null, - passportNumber: null, - licenseNumber: null, - }, alreadyEncrypted, []); + constructor(obj?: IdentityData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - return this.decryptObj(new IdentityView(this), { - title: null, - firstName: null, - middleName: null, - lastName: null, - address1: null, - address2: null, - address3: null, - city: null, - state: null, - postalCode: null, - country: null, - company: null, - email: null, - phone: null, - ssn: null, - username: null, - passportNumber: null, - licenseNumber: null, - }, orgId, encKey); - } + this.buildDomainModel( + this, + obj, + { + title: null, + firstName: null, + middleName: null, + lastName: null, + address1: null, + address2: null, + address3: null, + city: null, + state: null, + postalCode: null, + country: null, + company: null, + email: null, + phone: null, + ssn: null, + username: null, + passportNumber: null, + licenseNumber: null, + }, + alreadyEncrypted, + [] + ); + } - toIdentityData(): IdentityData { - const i = new IdentityData(); - this.buildDataModel(this, i, { - title: null, - firstName: null, - middleName: null, - lastName: null, - address1: null, - address2: null, - address3: null, - city: null, - state: null, - postalCode: null, - country: null, - company: null, - email: null, - phone: null, - ssn: null, - username: null, - passportNumber: null, - licenseNumber: null, - }); - return i; - } + decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + return this.decryptObj( + new IdentityView(this), + { + title: null, + firstName: null, + middleName: null, + lastName: null, + address1: null, + address2: null, + address3: null, + city: null, + state: null, + postalCode: null, + country: null, + company: null, + email: null, + phone: null, + ssn: null, + username: null, + passportNumber: null, + licenseNumber: null, + }, + orgId, + encKey + ); + } + + toIdentityData(): IdentityData { + const i = new IdentityData(); + this.buildDataModel(this, i, { + title: null, + firstName: null, + middleName: null, + lastName: null, + address1: null, + address2: null, + address3: null, + city: null, + state: null, + postalCode: null, + country: null, + company: null, + email: null, + phone: null, + ssn: null, + username: null, + passportNumber: null, + licenseNumber: null, + }); + return i; + } } diff --git a/common/src/models/domain/importResult.ts b/common/src/models/domain/importResult.ts index 00534f4a..1ac28161 100644 --- a/common/src/models/domain/importResult.ts +++ b/common/src/models/domain/importResult.ts @@ -1,13 +1,13 @@ -import { CipherView } from '../view/cipherView'; -import { CollectionView } from '../view/collectionView'; -import { FolderView } from '../view/folderView'; +import { CipherView } from "../view/cipherView"; +import { CollectionView } from "../view/collectionView"; +import { FolderView } from "../view/folderView"; export class ImportResult { - success = false; - errorMessage: string; - ciphers: CipherView[] = []; - folders: FolderView[] = []; - folderRelationships: [number, number][] = []; - collections: CollectionView[] = []; - collectionRelationships: [number, number][] = []; + success = false; + errorMessage: string; + ciphers: CipherView[] = []; + folders: FolderView[] = []; + folderRelationships: [number, number][] = []; + collections: CollectionView[] = []; + collectionRelationships: [number, number][] = []; } diff --git a/common/src/models/domain/login.ts b/common/src/models/domain/login.ts index 33bd1216..8507e076 100644 --- a/common/src/models/domain/login.ts +++ b/common/src/models/domain/login.ts @@ -1,78 +1,91 @@ -import { LoginUri } from './loginUri'; +import { LoginUri } from "./loginUri"; -import { LoginData } from '../data/loginData'; +import { LoginData } from "../data/loginData"; -import { LoginView } from '../view/loginView'; +import { LoginView } from "../view/loginView"; -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class Login extends Domain { - uris: LoginUri[]; - username: EncString; - password: EncString; - passwordRevisionDate?: Date; - totp: EncString; - autofillOnPageLoad: boolean; + uris: LoginUri[]; + username: EncString; + password: EncString; + passwordRevisionDate?: Date; + totp: EncString; + autofillOnPageLoad: boolean; - constructor(obj?: LoginData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.passwordRevisionDate = obj.passwordRevisionDate != null ? new Date(obj.passwordRevisionDate) : null; - this.autofillOnPageLoad = obj.autofillOnPageLoad; - this.buildDomainModel(this, obj, { - username: null, - password: null, - totp: null, - }, alreadyEncrypted, []); - - if (obj.uris) { - this.uris = []; - obj.uris.forEach(u => { - this.uris.push(new LoginUri(u, alreadyEncrypted)); - }); - } + constructor(obj?: LoginData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - async decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - const view = await this.decryptObj(new LoginView(this), { - username: null, - password: null, - totp: null, - }, orgId, encKey); + this.passwordRevisionDate = + obj.passwordRevisionDate != null ? new Date(obj.passwordRevisionDate) : null; + this.autofillOnPageLoad = obj.autofillOnPageLoad; + this.buildDomainModel( + this, + obj, + { + username: null, + password: null, + totp: null, + }, + alreadyEncrypted, + [] + ); - if (this.uris != null) { - view.uris = []; - for (let i = 0; i < this.uris.length; i++) { - const uri = await this.uris[i].decrypt(orgId, encKey); - view.uris.push(uri); - } - } + if (obj.uris) { + this.uris = []; + obj.uris.forEach((u) => { + this.uris.push(new LoginUri(u, alreadyEncrypted)); + }); + } + } - return view; + async decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + const view = await this.decryptObj( + new LoginView(this), + { + username: null, + password: null, + totp: null, + }, + orgId, + encKey + ); + + if (this.uris != null) { + view.uris = []; + for (let i = 0; i < this.uris.length; i++) { + const uri = await this.uris[i].decrypt(orgId, encKey); + view.uris.push(uri); + } } - toLoginData(): LoginData { - const l = new LoginData(); - l.passwordRevisionDate = this.passwordRevisionDate != null ? this.passwordRevisionDate.toISOString() : null; - l.autofillOnPageLoad = this.autofillOnPageLoad; - this.buildDataModel(this, l, { - username: null, - password: null, - totp: null, - }); + return view; + } - if (this.uris != null && this.uris.length > 0) { - l.uris = []; - this.uris.forEach(u => { - l.uris.push(u.toLoginUriData()); - }); - } + toLoginData(): LoginData { + const l = new LoginData(); + l.passwordRevisionDate = + this.passwordRevisionDate != null ? this.passwordRevisionDate.toISOString() : null; + l.autofillOnPageLoad = this.autofillOnPageLoad; + this.buildDataModel(this, l, { + username: null, + password: null, + totp: null, + }); - return l; + if (this.uris != null && this.uris.length > 0) { + l.uris = []; + this.uris.forEach((u) => { + l.uris.push(u.toLoginUriData()); + }); } + + return l; + } } diff --git a/common/src/models/domain/loginUri.ts b/common/src/models/domain/loginUri.ts index 6f7bac1d..a80f7d0e 100644 --- a/common/src/models/domain/loginUri.ts +++ b/common/src/models/domain/loginUri.ts @@ -1,40 +1,56 @@ -import { UriMatchType } from '../../enums/uriMatchType'; +import { UriMatchType } from "../../enums/uriMatchType"; -import { LoginUriData } from '../data/loginUriData'; +import { LoginUriData } from "../data/loginUriData"; -import { LoginUriView } from '../view/loginUriView'; +import { LoginUriView } from "../view/loginUriView"; -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class LoginUri extends Domain { - uri: EncString; - match: UriMatchType; + uri: EncString; + match: UriMatchType; - constructor(obj?: LoginUriData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.match = obj.match; - this.buildDomainModel(this, obj, { - uri: null, - }, alreadyEncrypted, []); + constructor(obj?: LoginUriData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - return this.decryptObj(new LoginUriView(this), { - uri: null, - }, orgId, encKey); - } + this.match = obj.match; + this.buildDomainModel( + this, + obj, + { + uri: null, + }, + alreadyEncrypted, + [] + ); + } - toLoginUriData(): LoginUriData { - const u = new LoginUriData(); - this.buildDataModel(this, u, { - uri: null, - }, ['match']); - return u; - } + decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + return this.decryptObj( + new LoginUriView(this), + { + uri: null, + }, + orgId, + encKey + ); + } + + toLoginUriData(): LoginUriData { + const u = new LoginUriData(); + this.buildDataModel( + this, + u, + { + uri: null, + }, + ["match"] + ); + return u; + } } diff --git a/common/src/models/domain/masterPasswordPolicyOptions.ts b/common/src/models/domain/masterPasswordPolicyOptions.ts index ed04a455..4ffdc91f 100644 --- a/common/src/models/domain/masterPasswordPolicyOptions.ts +++ b/common/src/models/domain/masterPasswordPolicyOptions.ts @@ -1,10 +1,10 @@ -import Domain from './domainBase'; +import Domain from "./domainBase"; export class MasterPasswordPolicyOptions extends Domain { - minComplexity: number = 0; - minLength: number = 0; - requireUpper: boolean = false; - requireLower: boolean = false; - requireNumbers: boolean = false; - requireSpecial: boolean = false; + minComplexity: number = 0; + minLength: number = 0; + requireUpper: boolean = false; + requireLower: boolean = false; + requireNumbers: boolean = false; + requireSpecial: boolean = false; } diff --git a/common/src/models/domain/organization.ts b/common/src/models/domain/organization.ts index 492afda5..d21b49b9 100644 --- a/common/src/models/domain/organization.ts +++ b/common/src/models/domain/organization.ts @@ -1,169 +1,185 @@ -import { OrganizationData } from '../data/organizationData'; - -import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType'; -import { OrganizationUserType } from '../../enums/organizationUserType'; -import { ProductType } from '../../enums/productType'; -import { PermissionsApi } from '../api/permissionsApi'; +import { OrganizationData } from "../data/organizationData"; +import { OrganizationUserStatusType } from "../../enums/organizationUserStatusType"; +import { OrganizationUserType } from "../../enums/organizationUserType"; +import { ProductType } from "../../enums/productType"; +import { PermissionsApi } from "../api/permissionsApi"; export class Organization { - id: string; - name: string; - status: OrganizationUserStatusType; - type: OrganizationUserType; - enabled: boolean; - usePolicies: boolean; - useGroups: boolean; - useDirectory: boolean; - useEvents: boolean; - useTotp: boolean; - use2fa: boolean; - useApi: boolean; - useSso: boolean; - useKeyConnector: boolean; - useResetPassword: boolean; - selfHost: boolean; - usersGetPremium: boolean; - seats: number; - maxCollections: number; - maxStorageGb?: number; - ssoBound: boolean; - identifier: string; - permissions: PermissionsApi; - resetPasswordEnrolled: boolean; - userId: string; - hasPublicAndPrivateKeys: boolean; - providerId: string; - providerName: string; - isProviderUser: boolean; - familySponsorshipFriendlyName: string; - familySponsorshipAvailable: boolean; - planProductType: ProductType; - keyConnectorEnabled: boolean; - keyConnectorUrl: string; + id: string; + name: string; + status: OrganizationUserStatusType; + type: OrganizationUserType; + enabled: boolean; + usePolicies: boolean; + useGroups: boolean; + useDirectory: boolean; + useEvents: boolean; + useTotp: boolean; + use2fa: boolean; + useApi: boolean; + useSso: boolean; + useKeyConnector: boolean; + useResetPassword: boolean; + selfHost: boolean; + usersGetPremium: boolean; + seats: number; + maxCollections: number; + maxStorageGb?: number; + ssoBound: boolean; + identifier: string; + permissions: PermissionsApi; + resetPasswordEnrolled: boolean; + userId: string; + hasPublicAndPrivateKeys: boolean; + providerId: string; + providerName: string; + isProviderUser: boolean; + familySponsorshipFriendlyName: string; + familySponsorshipAvailable: boolean; + planProductType: ProductType; + keyConnectorEnabled: boolean; + keyConnectorUrl: string; - constructor(obj?: OrganizationData) { - if (obj == null) { - return; - } - - this.id = obj.id; - this.name = obj.name; - this.status = obj.status; - this.type = obj.type; - this.enabled = obj.enabled; - this.usePolicies = obj.usePolicies; - this.useGroups = obj.useGroups; - this.useDirectory = obj.useDirectory; - this.useEvents = obj.useEvents; - this.useTotp = obj.useTotp; - this.use2fa = obj.use2fa; - this.useApi = obj.useApi; - this.useSso = obj.useSso; - this.useKeyConnector = obj.useKeyConnector; - this.useResetPassword = obj.useResetPassword; - this.selfHost = obj.selfHost; - this.usersGetPremium = obj.usersGetPremium; - this.seats = obj.seats; - this.maxCollections = obj.maxCollections; - this.maxStorageGb = obj.maxStorageGb; - this.ssoBound = obj.ssoBound; - this.identifier = obj.identifier; - this.permissions = obj.permissions; - this.resetPasswordEnrolled = obj.resetPasswordEnrolled; - this.userId = obj.userId; - this.hasPublicAndPrivateKeys = obj.hasPublicAndPrivateKeys; - this.providerId = obj.providerId; - this.providerName = obj.providerName; - this.isProviderUser = obj.isProviderUser; - this.familySponsorshipFriendlyName = obj.familySponsorshipFriendlyName; - this.familySponsorshipAvailable = obj.familySponsorshipAvailable; - this.planProductType = obj.planProductType; - this.keyConnectorEnabled = obj.keyConnectorEnabled; - this.keyConnectorUrl = obj.keyConnectorUrl; + constructor(obj?: OrganizationData) { + if (obj == null) { + return; } - get canAccess() { - if (this.type === OrganizationUserType.Owner) { - return true; - } - return this.enabled && this.status === OrganizationUserStatusType.Confirmed; - } + this.id = obj.id; + this.name = obj.name; + this.status = obj.status; + this.type = obj.type; + this.enabled = obj.enabled; + this.usePolicies = obj.usePolicies; + this.useGroups = obj.useGroups; + this.useDirectory = obj.useDirectory; + this.useEvents = obj.useEvents; + this.useTotp = obj.useTotp; + this.use2fa = obj.use2fa; + this.useApi = obj.useApi; + this.useSso = obj.useSso; + this.useKeyConnector = obj.useKeyConnector; + this.useResetPassword = obj.useResetPassword; + this.selfHost = obj.selfHost; + this.usersGetPremium = obj.usersGetPremium; + this.seats = obj.seats; + this.maxCollections = obj.maxCollections; + this.maxStorageGb = obj.maxStorageGb; + this.ssoBound = obj.ssoBound; + this.identifier = obj.identifier; + this.permissions = obj.permissions; + this.resetPasswordEnrolled = obj.resetPasswordEnrolled; + this.userId = obj.userId; + this.hasPublicAndPrivateKeys = obj.hasPublicAndPrivateKeys; + this.providerId = obj.providerId; + this.providerName = obj.providerName; + this.isProviderUser = obj.isProviderUser; + this.familySponsorshipFriendlyName = obj.familySponsorshipFriendlyName; + this.familySponsorshipAvailable = obj.familySponsorshipAvailable; + this.planProductType = obj.planProductType; + this.keyConnectorEnabled = obj.keyConnectorEnabled; + this.keyConnectorUrl = obj.keyConnectorUrl; + } - get isManager() { - return this.type === OrganizationUserType.Manager || this.type === OrganizationUserType.Owner || - this.type === OrganizationUserType.Admin; + get canAccess() { + if (this.type === OrganizationUserType.Owner) { + return true; } + return this.enabled && this.status === OrganizationUserStatusType.Confirmed; + } - get isAdmin() { - return this.type === OrganizationUserType.Owner || this.type === OrganizationUserType.Admin; - } + get isManager() { + return ( + this.type === OrganizationUserType.Manager || + this.type === OrganizationUserType.Owner || + this.type === OrganizationUserType.Admin + ); + } - get isOwner() { - return this.type === OrganizationUserType.Owner || this.isProviderUser; - } + get isAdmin() { + return this.type === OrganizationUserType.Owner || this.type === OrganizationUserType.Admin; + } - get canAccessEventLogs() { - return this.isAdmin || this.permissions.accessEventLogs; - } + get isOwner() { + return this.type === OrganizationUserType.Owner || this.isProviderUser; + } - get canAccessImportExport() { - return this.isAdmin || this.permissions.accessImportExport; - } + get canAccessEventLogs() { + return this.isAdmin || this.permissions.accessEventLogs; + } - get canAccessReports() { - return this.isAdmin || this.permissions.accessReports; - } + get canAccessImportExport() { + return this.isAdmin || this.permissions.accessImportExport; + } - get canCreateNewCollections() { - return this.isManager || (this.permissions.createNewCollections ?? this.permissions.manageAllCollections); - } + get canAccessReports() { + return this.isAdmin || this.permissions.accessReports; + } - get canEditAnyCollection() { - return this.isAdmin || (this.permissions.editAnyCollection ?? this.permissions.manageAllCollections); - } + get canCreateNewCollections() { + return ( + this.isManager || + (this.permissions.createNewCollections ?? this.permissions.manageAllCollections) + ); + } - get canDeleteAnyCollection() { - return this.isAdmin || (this.permissions.deleteAnyCollection ?? this.permissions.manageAllCollections); - } + get canEditAnyCollection() { + return ( + this.isAdmin || (this.permissions.editAnyCollection ?? this.permissions.manageAllCollections) + ); + } - get canViewAllCollections() { - return this.canCreateNewCollections || this.canEditAnyCollection || this.canDeleteAnyCollection; - } + get canDeleteAnyCollection() { + return ( + this.isAdmin || + (this.permissions.deleteAnyCollection ?? this.permissions.manageAllCollections) + ); + } - get canEditAssignedCollections() { - return this.isManager || (this.permissions.editAssignedCollections ?? this.permissions.manageAssignedCollections); - } + get canViewAllCollections() { + return this.canCreateNewCollections || this.canEditAnyCollection || this.canDeleteAnyCollection; + } - get canDeleteAssignedCollections() { - return this.isManager || (this.permissions.deleteAssignedCollections ?? this.permissions.manageAssignedCollections); - } + get canEditAssignedCollections() { + return ( + this.isManager || + (this.permissions.editAssignedCollections ?? this.permissions.manageAssignedCollections) + ); + } - get canViewAssignedCollections() { - return this.canDeleteAssignedCollections || this.canEditAssignedCollections; - } + get canDeleteAssignedCollections() { + return ( + this.isManager || + (this.permissions.deleteAssignedCollections ?? this.permissions.manageAssignedCollections) + ); + } - get canManageGroups() { - return this.isAdmin || this.permissions.manageGroups; - } + get canViewAssignedCollections() { + return this.canDeleteAssignedCollections || this.canEditAssignedCollections; + } - get canManageSso() { - return this.isAdmin || this.permissions.manageSso; - } + get canManageGroups() { + return this.isAdmin || this.permissions.manageGroups; + } - get canManagePolicies() { - return this.isAdmin || this.permissions.managePolicies; - } + get canManageSso() { + return this.isAdmin || this.permissions.manageSso; + } - get canManageUsers() { - return this.isAdmin || this.permissions.manageUsers; - } + get canManagePolicies() { + return this.isAdmin || this.permissions.managePolicies; + } - get canManageUsersPassword() { - return this.isAdmin || this.permissions.manageResetPassword; - } + get canManageUsers() { + return this.isAdmin || this.permissions.manageUsers; + } - get isExemptFromPolicies() { - return this.canManagePolicies; - } + get canManageUsersPassword() { + return this.isAdmin || this.permissions.manageResetPassword; + } + + get isExemptFromPolicies() { + return this.canManagePolicies; + } } diff --git a/common/src/models/domain/password.ts b/common/src/models/domain/password.ts index 59c9670d..94e098c6 100644 --- a/common/src/models/domain/password.ts +++ b/common/src/models/domain/password.ts @@ -1,39 +1,49 @@ -import { PasswordHistoryData } from '../data/passwordHistoryData'; +import { PasswordHistoryData } from "../data/passwordHistoryData"; -import Domain from './domainBase'; -import { EncString } from './encString'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; -import { PasswordHistoryView } from '../view/passwordHistoryView'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { PasswordHistoryView } from "../view/passwordHistoryView"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class Password extends Domain { - password: EncString; - lastUsedDate: Date; + password: EncString; + lastUsedDate: Date; - constructor(obj?: PasswordHistoryData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - password: null, - }, alreadyEncrypted); - this.lastUsedDate = new Date(obj.lastUsedDate); + constructor(obj?: PasswordHistoryData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - return this.decryptObj(new PasswordHistoryView(this), { - password: null, - }, orgId, encKey); - } + this.buildDomainModel( + this, + obj, + { + password: null, + }, + alreadyEncrypted + ); + this.lastUsedDate = new Date(obj.lastUsedDate); + } - toPasswordHistoryData(): PasswordHistoryData { - const ph = new PasswordHistoryData(); - ph.lastUsedDate = this.lastUsedDate.toISOString(); - this.buildDataModel(this, ph, { - password: null, - }); - return ph; - } + decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + return this.decryptObj( + new PasswordHistoryView(this), + { + password: null, + }, + orgId, + encKey + ); + } + + toPasswordHistoryData(): PasswordHistoryData { + const ph = new PasswordHistoryData(); + ph.lastUsedDate = this.lastUsedDate.toISOString(); + this.buildDataModel(this, ph, { + password: null, + }); + return ph; + } } diff --git a/common/src/models/domain/passwordGeneratorPolicyOptions.ts b/common/src/models/domain/passwordGeneratorPolicyOptions.ts index d84b575a..5e37bcec 100644 --- a/common/src/models/domain/passwordGeneratorPolicyOptions.ts +++ b/common/src/models/domain/passwordGeneratorPolicyOptions.ts @@ -1,29 +1,31 @@ -import Domain from './domainBase'; +import Domain from "./domainBase"; export class PasswordGeneratorPolicyOptions extends Domain { - defaultType: string = ''; - minLength: number = 0; - useUppercase: boolean = false; - useLowercase: boolean = false; - useNumbers: boolean = false; - numberCount: number = 0; - useSpecial: boolean = false; - specialCount: number = 0; - minNumberWords: number = 0; - capitalize: boolean = false; - includeNumber: boolean = false; + defaultType: string = ""; + minLength: number = 0; + useUppercase: boolean = false; + useLowercase: boolean = false; + useNumbers: boolean = false; + numberCount: number = 0; + useSpecial: boolean = false; + specialCount: number = 0; + minNumberWords: number = 0; + capitalize: boolean = false; + includeNumber: boolean = false; - inEffect() { - return this.defaultType !== '' || - this.minLength > 0 || - this.numberCount > 0 || - this.specialCount > 0 || - this.useUppercase || - this.useLowercase || - this.useNumbers || - this.useSpecial || - this.minNumberWords > 0 || - this.capitalize || - this.includeNumber; - } + inEffect() { + return ( + this.defaultType !== "" || + this.minLength > 0 || + this.numberCount > 0 || + this.specialCount > 0 || + this.useUppercase || + this.useLowercase || + this.useNumbers || + this.useSpecial || + this.minNumberWords > 0 || + this.capitalize || + this.includeNumber + ); + } } diff --git a/common/src/models/domain/policy.ts b/common/src/models/domain/policy.ts index e8e5d00f..174c2c7c 100644 --- a/common/src/models/domain/policy.ts +++ b/common/src/models/domain/policy.ts @@ -1,26 +1,26 @@ -import { PolicyData } from '../data/policyData'; +import { PolicyData } from "../data/policyData"; -import Domain from './domainBase'; +import Domain from "./domainBase"; -import { PolicyType } from '../../enums/policyType'; +import { PolicyType } from "../../enums/policyType"; export class Policy extends Domain { - id: string; - organizationId: string; - type: PolicyType; - data: any; - enabled: boolean; + id: string; + organizationId: string; + type: PolicyType; + data: any; + enabled: boolean; - constructor(obj?: PolicyData) { - super(); - if (obj == null) { - return; - } - - this.id = obj.id; - this.organizationId = obj.organizationId; - this.type = obj.type; - this.data = obj.data; - this.enabled = obj.enabled; + constructor(obj?: PolicyData) { + super(); + if (obj == null) { + return; } + + this.id = obj.id; + this.organizationId = obj.organizationId; + this.type = obj.type; + this.data = obj.data; + this.enabled = obj.enabled; + } } diff --git a/common/src/models/domain/provider.ts b/common/src/models/domain/provider.ts index 24031ea1..6e14340b 100644 --- a/common/src/models/domain/provider.ts +++ b/common/src/models/domain/provider.ts @@ -1,50 +1,50 @@ -import { ProviderUserStatusType } from '../../enums/providerUserStatusType'; -import { ProviderUserType } from '../../enums/providerUserType'; -import { ProviderData } from '../data/providerData'; +import { ProviderUserStatusType } from "../../enums/providerUserStatusType"; +import { ProviderUserType } from "../../enums/providerUserType"; +import { ProviderData } from "../data/providerData"; export class Provider { - id: string; - name: string; - status: ProviderUserStatusType; - type: ProviderUserType; - enabled: boolean; - userId: string; - useEvents: boolean; + id: string; + name: string; + status: ProviderUserStatusType; + type: ProviderUserType; + enabled: boolean; + userId: string; + useEvents: boolean; - constructor(obj?: ProviderData) { - if (obj == null) { - return; - } - - this.id = obj.id; - this.name = obj.name; - this.status = obj.status; - this.type = obj.type; - this.enabled = obj.enabled; - this.userId = obj.userId; - this.useEvents = obj.useEvents; + constructor(obj?: ProviderData) { + if (obj == null) { + return; } - get canAccess() { - if (this.isProviderAdmin) { - return true; - } - return this.enabled && this.status === ProviderUserStatusType.Confirmed; - } + this.id = obj.id; + this.name = obj.name; + this.status = obj.status; + this.type = obj.type; + this.enabled = obj.enabled; + this.userId = obj.userId; + this.useEvents = obj.useEvents; + } - get canCreateOrganizations() { - return this.enabled && this.isProviderAdmin; + get canAccess() { + if (this.isProviderAdmin) { + return true; } + return this.enabled && this.status === ProviderUserStatusType.Confirmed; + } - get canManageUsers() { - return this.isProviderAdmin; - } + get canCreateOrganizations() { + return this.enabled && this.isProviderAdmin; + } - get canAccessEventLogs() { - return this.isProviderAdmin; - } + get canManageUsers() { + return this.isProviderAdmin; + } - get isProviderAdmin() { - return this.type === ProviderUserType.ProviderAdmin; - } + get canAccessEventLogs() { + return this.isProviderAdmin; + } + + get isProviderAdmin() { + return this.type === ProviderUserType.ProviderAdmin; + } } diff --git a/common/src/models/domain/resetPasswordPolicyOptions.ts b/common/src/models/domain/resetPasswordPolicyOptions.ts index 6a650e4c..8dbde376 100644 --- a/common/src/models/domain/resetPasswordPolicyOptions.ts +++ b/common/src/models/domain/resetPasswordPolicyOptions.ts @@ -1,5 +1,5 @@ -import Domain from './domainBase'; +import Domain from "./domainBase"; export class ResetPasswordPolicyOptions extends Domain { - autoEnrollEnabled: boolean = false; + autoEnrollEnabled: boolean = false; } diff --git a/common/src/models/domain/secureNote.ts b/common/src/models/domain/secureNote.ts index 91b23fff..42f31297 100644 --- a/common/src/models/domain/secureNote.ts +++ b/common/src/models/domain/secureNote.ts @@ -1,31 +1,31 @@ -import { SecureNoteType } from '../../enums/secureNoteType'; +import { SecureNoteType } from "../../enums/secureNoteType"; -import { SecureNoteData } from '../data/secureNoteData'; +import { SecureNoteData } from "../data/secureNoteData"; -import Domain from './domainBase'; +import Domain from "./domainBase"; -import { SecureNoteView } from '../view/secureNoteView'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import { SecureNoteView } from "../view/secureNoteView"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class SecureNote extends Domain { - type: SecureNoteType; + type: SecureNoteType; - constructor(obj?: SecureNoteData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.type = obj.type; + constructor(obj?: SecureNoteData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { - return Promise.resolve(new SecureNoteView(this)); - } + this.type = obj.type; + } - toSecureNoteData(): SecureNoteData { - const n = new SecureNoteData(); - n.type = this.type; - return n; - } + decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { + return Promise.resolve(new SecureNoteView(this)); + } + + toSecureNoteData(): SecureNoteData { + const n = new SecureNoteData(); + n.type = this.type; + return n; + } } diff --git a/common/src/models/domain/send.ts b/common/src/models/domain/send.ts index 84ed24e7..ab217f92 100644 --- a/common/src/models/domain/send.ts +++ b/common/src/models/domain/send.ts @@ -1,108 +1,119 @@ -import { CryptoService } from '../../abstractions/crypto.service'; +import { CryptoService } from "../../abstractions/crypto.service"; -import { SendType } from '../../enums/sendType'; +import { SendType } from "../../enums/sendType"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; -import { SendData } from '../data/sendData'; +import { SendData } from "../data/sendData"; -import { SendView } from '../view/sendView'; +import { SendView } from "../view/sendView"; -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SendFile } from './sendFile'; -import { SendText } from './sendText'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SendFile } from "./sendFile"; +import { SendText } from "./sendText"; export class Send extends Domain { - id: string; - accessId: string; - userId: string; - type: SendType; - name: EncString; - notes: EncString; - file: SendFile; - text: SendText; - key: EncString; - maxAccessCount?: number; - accessCount: number; - revisionDate: Date; - expirationDate: Date; - deletionDate: Date; - password: string; - disabled: boolean; - hideEmail: boolean; + id: string; + accessId: string; + userId: string; + type: SendType; + name: EncString; + notes: EncString; + file: SendFile; + text: SendText; + key: EncString; + maxAccessCount?: number; + accessCount: number; + revisionDate: Date; + expirationDate: Date; + deletionDate: Date; + password: string; + disabled: boolean; + hideEmail: boolean; - constructor(obj?: SendData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - id: null, - accessId: null, - userId: null, - name: null, - notes: null, - key: null, - }, alreadyEncrypted, ['id', 'accessId', 'userId']); - - this.type = obj.type; - this.maxAccessCount = obj.maxAccessCount; - this.accessCount = obj.accessCount; - this.password = obj.password; - this.disabled = obj.disabled; - this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null; - this.deletionDate = obj.deletionDate != null ? new Date(obj.deletionDate) : null; - this.expirationDate = obj.expirationDate != null ? new Date(obj.expirationDate) : null; - this.hideEmail = obj.hideEmail; - - switch (this.type) { - case SendType.Text: - this.text = new SendText(obj.text, alreadyEncrypted); - break; - case SendType.File: - this.file = new SendFile(obj.file, alreadyEncrypted); - break; - default: - break; - } + constructor(obj?: SendData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - async decrypt(): Promise { - const model = new SendView(this); + this.buildDomainModel( + this, + obj, + { + id: null, + accessId: null, + userId: null, + name: null, + notes: null, + key: null, + }, + alreadyEncrypted, + ["id", "accessId", "userId"] + ); - let cryptoService: CryptoService; - const containerService = (Utils.global as any).bitwardenContainerService; - if (containerService) { - cryptoService = containerService.getCryptoService(); - } else { - throw new Error('global bitwardenContainerService not initialized.'); - } + this.type = obj.type; + this.maxAccessCount = obj.maxAccessCount; + this.accessCount = obj.accessCount; + this.password = obj.password; + this.disabled = obj.disabled; + this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null; + this.deletionDate = obj.deletionDate != null ? new Date(obj.deletionDate) : null; + this.expirationDate = obj.expirationDate != null ? new Date(obj.expirationDate) : null; + this.hideEmail = obj.hideEmail; - try { - model.key = await cryptoService.decryptToBytes(this.key, null); - model.cryptoKey = await cryptoService.makeSendKey(model.key); - } catch (e) { - // TODO: error? - } - - await this.decryptObj(model, { - name: null, - notes: null, - }, null, model.cryptoKey); - - switch (this.type) { - case SendType.File: - model.file = await this.file.decrypt(model.cryptoKey); - break; - case SendType.Text: - model.text = await this.text.decrypt(model.cryptoKey); - break; - default: - break; - } - - return model; + switch (this.type) { + case SendType.Text: + this.text = new SendText(obj.text, alreadyEncrypted); + break; + case SendType.File: + this.file = new SendFile(obj.file, alreadyEncrypted); + break; + default: + break; } + } + + async decrypt(): Promise { + const model = new SendView(this); + + let cryptoService: CryptoService; + const containerService = (Utils.global as any).bitwardenContainerService; + if (containerService) { + cryptoService = containerService.getCryptoService(); + } else { + throw new Error("global bitwardenContainerService not initialized."); + } + + try { + model.key = await cryptoService.decryptToBytes(this.key, null); + model.cryptoKey = await cryptoService.makeSendKey(model.key); + } catch (e) { + // TODO: error? + } + + await this.decryptObj( + model, + { + name: null, + notes: null, + }, + null, + model.cryptoKey + ); + + switch (this.type) { + case SendType.File: + model.file = await this.file.decrypt(model.cryptoKey); + break; + case SendType.Text: + model.text = await this.text.decrypt(model.cryptoKey); + break; + default: + break; + } + + return model; + } } diff --git a/common/src/models/domain/sendAccess.ts b/common/src/models/domain/sendAccess.ts index f3ff1899..05ad9bde 100644 --- a/common/src/models/domain/sendAccess.ts +++ b/common/src/models/domain/sendAccess.ts @@ -1,69 +1,80 @@ -import { SendType } from '../../enums/sendType'; +import { SendType } from "../../enums/sendType"; -import { SendAccessResponse } from '../response/sendAccessResponse'; +import { SendAccessResponse } from "../response/sendAccessResponse"; -import { SendAccessView } from '../view/sendAccessView'; +import { SendAccessView } from "../view/sendAccessView"; -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SendFile } from './sendFile'; -import { SendText } from './sendText'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SendFile } from "./sendFile"; +import { SendText } from "./sendText"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; export class SendAccess extends Domain { - id: string; - type: SendType; - name: EncString; - file: SendFile; - text: SendText; - expirationDate: Date; - creatorIdentifier: string; + id: string; + type: SendType; + name: EncString; + file: SendFile; + text: SendText; + expirationDate: Date; + creatorIdentifier: string; - constructor(obj?: SendAccessResponse, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.buildDomainModel(this, obj, { - id: null, - name: null, - expirationDate: null, - creatorIdentifier: null, - }, alreadyEncrypted, ['id', 'expirationDate', 'creatorIdentifier']); - - this.type = obj.type; - - switch (this.type) { - case SendType.Text: - this.text = new SendText(obj.text, alreadyEncrypted); - break; - case SendType.File: - this.file = new SendFile(obj.file, alreadyEncrypted); - break; - default: - break; - } + constructor(obj?: SendAccessResponse, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - async decrypt(key: SymmetricCryptoKey): Promise { - const model = new SendAccessView(this); + this.buildDomainModel( + this, + obj, + { + id: null, + name: null, + expirationDate: null, + creatorIdentifier: null, + }, + alreadyEncrypted, + ["id", "expirationDate", "creatorIdentifier"] + ); - await this.decryptObj(model, { - name: null, - }, null, key); + this.type = obj.type; - switch (this.type) { - case SendType.File: - model.file = await this.file.decrypt(key); - break; - case SendType.Text: - model.text = await this.text.decrypt(key); - break; - default: - break; - } - - return model; + switch (this.type) { + case SendType.Text: + this.text = new SendText(obj.text, alreadyEncrypted); + break; + case SendType.File: + this.file = new SendFile(obj.file, alreadyEncrypted); + break; + default: + break; } + } + + async decrypt(key: SymmetricCryptoKey): Promise { + const model = new SendAccessView(this); + + await this.decryptObj( + model, + { + name: null, + }, + null, + key + ); + + switch (this.type) { + case SendType.File: + model.file = await this.file.decrypt(key); + break; + case SendType.Text: + model.text = await this.text.decrypt(key); + break; + default: + break; + } + + return model; + } } diff --git a/common/src/models/domain/sendFile.ts b/common/src/models/domain/sendFile.ts index 4a057301..76c566df 100644 --- a/common/src/models/domain/sendFile.ts +++ b/common/src/models/domain/sendFile.ts @@ -1,35 +1,46 @@ -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; -import { SendFileData } from '../data/sendFileData'; +import { SendFileData } from "../data/sendFileData"; -import { SendFileView } from '../view/sendFileView'; +import { SendFileView } from "../view/sendFileView"; export class SendFile extends Domain { - id: string; - size: string; - sizeName: string; - fileName: EncString; + id: string; + size: string; + sizeName: string; + fileName: EncString; - constructor(obj?: SendFileData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.size = obj.size; - this.buildDomainModel(this, obj, { - id: null, - sizeName: null, - fileName: null, - }, alreadyEncrypted, ['id', 'sizeName']); + constructor(obj?: SendFileData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - async decrypt(key: SymmetricCryptoKey): Promise { - const view = await this.decryptObj(new SendFileView(this), { - fileName: null, - }, null, key); - return view; - } + this.size = obj.size; + this.buildDomainModel( + this, + obj, + { + id: null, + sizeName: null, + fileName: null, + }, + alreadyEncrypted, + ["id", "sizeName"] + ); + } + + async decrypt(key: SymmetricCryptoKey): Promise { + const view = await this.decryptObj( + new SendFileView(this), + { + fileName: null, + }, + null, + key + ); + return view; + } } diff --git a/common/src/models/domain/sendText.ts b/common/src/models/domain/sendText.ts index edf12000..7d45332f 100644 --- a/common/src/models/domain/sendText.ts +++ b/common/src/models/domain/sendText.ts @@ -1,30 +1,41 @@ -import Domain from './domainBase'; -import { EncString } from './encString'; -import { SymmetricCryptoKey } from './symmetricCryptoKey'; +import Domain from "./domainBase"; +import { EncString } from "./encString"; +import { SymmetricCryptoKey } from "./symmetricCryptoKey"; -import { SendTextData } from '../data/sendTextData'; +import { SendTextData } from "../data/sendTextData"; -import { SendTextView } from '../view/sendTextView'; +import { SendTextView } from "../view/sendTextView"; export class SendText extends Domain { - text: EncString; - hidden: boolean; + text: EncString; + hidden: boolean; - constructor(obj?: SendTextData, alreadyEncrypted: boolean = false) { - super(); - if (obj == null) { - return; - } - - this.hidden = obj.hidden; - this.buildDomainModel(this, obj, { - text: null, - }, alreadyEncrypted, []); + constructor(obj?: SendTextData, alreadyEncrypted: boolean = false) { + super(); + if (obj == null) { + return; } - decrypt(key: SymmetricCryptoKey): Promise { - return this.decryptObj(new SendTextView(this), { - text: null, - }, null, key); - } + this.hidden = obj.hidden; + this.buildDomainModel( + this, + obj, + { + text: null, + }, + alreadyEncrypted, + [] + ); + } + + decrypt(key: SymmetricCryptoKey): Promise { + return this.decryptObj( + new SendTextView(this), + { + text: null, + }, + null, + key + ); + } } diff --git a/common/src/models/domain/sortedCiphersCache.ts b/common/src/models/domain/sortedCiphersCache.ts index 64f4b049..8c32744e 100644 --- a/common/src/models/domain/sortedCiphersCache.ts +++ b/common/src/models/domain/sortedCiphersCache.ts @@ -1,82 +1,87 @@ -import { CipherView } from '../view/cipherView'; +import { CipherView } from "../view/cipherView"; const CacheTTL = 3000; export class SortedCiphersCache { - private readonly sortedCiphersByUrl: Map = new Map(); - private readonly timeouts: Map = new Map(); + private readonly sortedCiphersByUrl: Map = new Map(); + private readonly timeouts: Map = new Map(); - constructor(private readonly comparator: (a: CipherView, b: CipherView) => number) { } + constructor(private readonly comparator: (a: CipherView, b: CipherView) => number) {} - isCached(url: string) { - return this.sortedCiphersByUrl.has(url); + isCached(url: string) { + return this.sortedCiphersByUrl.has(url); + } + + addCiphers(url: string, ciphers: CipherView[]) { + ciphers.sort(this.comparator); + this.sortedCiphersByUrl.set(url, new Ciphers(ciphers)); + this.resetTimer(url); + } + + getLastUsed(url: string) { + this.resetTimer(url); + return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getLastUsed() : null; + } + + getLastLaunched(url: string) { + return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getLastLaunched() : null; + } + + getNext(url: string) { + this.resetTimer(url); + return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getNext() : null; + } + + updateLastUsedIndex(url: string) { + if (this.isCached(url)) { + this.sortedCiphersByUrl.get(url).updateLastUsedIndex(); } + } - addCiphers(url: string, ciphers: CipherView[]) { - ciphers.sort(this.comparator); - this.sortedCiphersByUrl.set(url, new Ciphers(ciphers)); - this.resetTimer(url); - } + clear() { + this.sortedCiphersByUrl.clear(); + this.timeouts.clear(); + } - getLastUsed(url: string) { - this.resetTimer(url); - return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getLastUsed() : null; - } - - getLastLaunched(url: string) { - return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getLastLaunched() : null; - } - - getNext(url: string) { - this.resetTimer(url); - return this.isCached(url) ? this.sortedCiphersByUrl.get(url).getNext() : null; - } - - updateLastUsedIndex(url: string) { - if (this.isCached(url)) { - this.sortedCiphersByUrl.get(url).updateLastUsedIndex(); - } - } - - clear() { - this.sortedCiphersByUrl.clear(); - this.timeouts.clear(); - } - - private resetTimer(url: string) { - clearTimeout(this.timeouts.get(url)); - this.timeouts.set(url, setTimeout(() => { - this.sortedCiphersByUrl.delete(url); - this.timeouts.delete(url); - }, CacheTTL)); - } + private resetTimer(url: string) { + clearTimeout(this.timeouts.get(url)); + this.timeouts.set( + url, + setTimeout(() => { + this.sortedCiphersByUrl.delete(url); + this.timeouts.delete(url); + }, CacheTTL) + ); + } } class Ciphers { - lastUsedIndex = -1; + lastUsedIndex = -1; - constructor(private readonly ciphers: CipherView[]) { } + constructor(private readonly ciphers: CipherView[]) {} - getLastUsed() { - this.lastUsedIndex = Math.max(this.lastUsedIndex, 0); - return this.ciphers[this.lastUsedIndex]; - } + getLastUsed() { + this.lastUsedIndex = Math.max(this.lastUsedIndex, 0); + return this.ciphers[this.lastUsedIndex]; + } - getLastLaunched() { - const usedCiphers = this.ciphers.filter(cipher => cipher.localData?.lastLaunched); - const sortedCiphers = usedCiphers.sort((x, y) => y.localData.lastLaunched.valueOf() - x.localData.lastLaunched.valueOf()); - return sortedCiphers[0]; - } + getLastLaunched() { + const usedCiphers = this.ciphers.filter((cipher) => cipher.localData?.lastLaunched); + const sortedCiphers = usedCiphers.sort( + (x, y) => y.localData.lastLaunched.valueOf() - x.localData.lastLaunched.valueOf() + ); + return sortedCiphers[0]; + } - getNextIndex() { - return (this.lastUsedIndex + 1) % this.ciphers.length; - } + getNextIndex() { + return (this.lastUsedIndex + 1) % this.ciphers.length; + } - getNext() { - return this.ciphers[this.getNextIndex()]; - } + getNext() { + return this.ciphers[this.getNextIndex()]; + } - updateLastUsedIndex() { - this.lastUsedIndex = this.getNextIndex(); - } + updateLastUsedIndex() { + this.lastUsedIndex = this.getNextIndex(); + } } diff --git a/common/src/models/domain/symmetricCryptoKey.ts b/common/src/models/domain/symmetricCryptoKey.ts index e6e63b82..c3c80f06 100644 --- a/common/src/models/domain/symmetricCryptoKey.ts +++ b/common/src/models/domain/symmetricCryptoKey.ts @@ -1,58 +1,58 @@ -import { EncryptionType } from '../../enums/encryptionType'; +import { EncryptionType } from "../../enums/encryptionType"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; export class SymmetricCryptoKey { - key: ArrayBuffer; - encKey?: ArrayBuffer; - macKey?: ArrayBuffer; - encType: EncryptionType; + key: ArrayBuffer; + encKey?: ArrayBuffer; + macKey?: ArrayBuffer; + encType: EncryptionType; - keyB64: string; - encKeyB64: string; - macKeyB64: string; + keyB64: string; + encKeyB64: string; + macKeyB64: string; - meta: any; + meta: any; - constructor(key: ArrayBuffer, encType?: EncryptionType) { - if (key == null) { - throw new Error('Must provide key'); - } - - if (encType == null) { - if (key.byteLength === 32) { - encType = EncryptionType.AesCbc256_B64; - } else if (key.byteLength === 64) { - encType = EncryptionType.AesCbc256_HmacSha256_B64; - } else { - throw new Error('Unable to determine encType.'); - } - } - - this.key = key; - this.encType = encType; - - if (encType === EncryptionType.AesCbc256_B64 && key.byteLength === 32) { - this.encKey = key; - this.macKey = null; - } else if (encType === EncryptionType.AesCbc128_HmacSha256_B64 && key.byteLength === 32) { - this.encKey = key.slice(0, 16); - this.macKey = key.slice(16, 32); - } else if (encType === EncryptionType.AesCbc256_HmacSha256_B64 && key.byteLength === 64) { - this.encKey = key.slice(0, 32); - this.macKey = key.slice(32, 64); - } else { - throw new Error('Unsupported encType/key length.'); - } - - if (this.key != null) { - this.keyB64 = Utils.fromBufferToB64(this.key); - } - if (this.encKey != null) { - this.encKeyB64 = Utils.fromBufferToB64(this.encKey); - } - if (this.macKey != null) { - this.macKeyB64 = Utils.fromBufferToB64(this.macKey); - } + constructor(key: ArrayBuffer, encType?: EncryptionType) { + if (key == null) { + throw new Error("Must provide key"); } + + if (encType == null) { + if (key.byteLength === 32) { + encType = EncryptionType.AesCbc256_B64; + } else if (key.byteLength === 64) { + encType = EncryptionType.AesCbc256_HmacSha256_B64; + } else { + throw new Error("Unable to determine encType."); + } + } + + this.key = key; + this.encType = encType; + + if (encType === EncryptionType.AesCbc256_B64 && key.byteLength === 32) { + this.encKey = key; + this.macKey = null; + } else if (encType === EncryptionType.AesCbc128_HmacSha256_B64 && key.byteLength === 32) { + this.encKey = key.slice(0, 16); + this.macKey = key.slice(16, 32); + } else if (encType === EncryptionType.AesCbc256_HmacSha256_B64 && key.byteLength === 64) { + this.encKey = key.slice(0, 32); + this.macKey = key.slice(32, 64); + } else { + throw new Error("Unsupported encType/key length."); + } + + if (this.key != null) { + this.keyB64 = Utils.fromBufferToB64(this.key); + } + if (this.encKey != null) { + this.encKeyB64 = Utils.fromBufferToB64(this.encKey); + } + if (this.macKey != null) { + this.macKeyB64 = Utils.fromBufferToB64(this.macKey); + } + } } diff --git a/common/src/models/domain/treeNode.ts b/common/src/models/domain/treeNode.ts index 9ea553bc..6af973a5 100644 --- a/common/src/models/domain/treeNode.ts +++ b/common/src/models/domain/treeNode.ts @@ -1,16 +1,16 @@ export class TreeNode { - parent: T; - node: T; - children: TreeNode[] = []; + parent: T; + node: T; + children: TreeNode[] = []; - constructor(node: T, name: string, parent: T) { - this.parent = parent; - this.node = node; - this.node.name = name; - } + constructor(node: T, name: string, parent: T) { + this.parent = parent; + this.node = node; + this.node.name = name; + } } export interface ITreeNodeObject { - id: string; - name: string; + id: string; + name: string; } diff --git a/common/src/models/export/card.ts b/common/src/models/export/card.ts index a24c3e6e..853ce64b 100644 --- a/common/src/models/export/card.ts +++ b/common/src/models/export/card.ts @@ -1,66 +1,66 @@ -import { CardView } from '../view/cardView'; +import { CardView } from "../view/cardView"; -import { Card as CardDomain } from '../domain/card'; -import { EncString } from '../domain/encString'; +import { Card as CardDomain } from "../domain/card"; +import { EncString } from "../domain/encString"; export class Card { - static template(): Card { - const req = new Card(); - req.cardholderName = 'John Doe'; - req.brand = 'visa'; - req.number = '4242424242424242'; - req.expMonth = '04'; - req.expYear = '2023'; - req.code = '123'; - return req; + static template(): Card { + const req = new Card(); + req.cardholderName = "John Doe"; + req.brand = "visa"; + req.number = "4242424242424242"; + req.expMonth = "04"; + req.expYear = "2023"; + req.code = "123"; + return req; + } + + static toView(req: Card, view = new CardView()) { + view.cardholderName = req.cardholderName; + view.brand = req.brand; + view.number = req.number; + view.expMonth = req.expMonth; + view.expYear = req.expYear; + view.code = req.code; + return view; + } + + static toDomain(req: Card, domain = new CardDomain()) { + domain.cardholderName = req.cardholderName != null ? new EncString(req.cardholderName) : null; + domain.brand = req.brand != null ? new EncString(req.brand) : null; + domain.number = req.number != null ? new EncString(req.number) : null; + domain.expMonth = req.expMonth != null ? new EncString(req.expMonth) : null; + domain.expYear = req.expYear != null ? new EncString(req.expYear) : null; + domain.code = req.code != null ? new EncString(req.code) : null; + return domain; + } + + cardholderName: string; + brand: string; + number: string; + expMonth: string; + expYear: string; + code: string; + + constructor(o?: CardView | CardDomain) { + if (o == null) { + return; } - static toView(req: Card, view = new CardView()) { - view.cardholderName = req.cardholderName; - view.brand = req.brand; - view.number = req.number; - view.expMonth = req.expMonth; - view.expYear = req.expYear; - view.code = req.code; - return view; - } - - static toDomain(req: Card, domain = new CardDomain()) { - domain.cardholderName = req.cardholderName != null ? new EncString(req.cardholderName) : null; - domain.brand = req.brand != null ? new EncString(req.brand) : null; - domain.number = req.number != null ? new EncString(req.number) : null; - domain.expMonth = req.expMonth != null ? new EncString(req.expMonth) : null; - domain.expYear = req.expYear != null ? new EncString(req.expYear) : null; - domain.code = req.code != null ? new EncString(req.code) : null; - return domain; - } - - cardholderName: string; - brand: string; - number: string; - expMonth: string; - expYear: string; - code: string; - - constructor(o?: CardView | CardDomain) { - if (o == null) { - return; - } - - if (o instanceof CardView) { - this.cardholderName = o.cardholderName; - this.brand = o.brand; - this.number = o.number; - this.expMonth = o.expMonth; - this.expYear = o.expYear; - this.code = o.code; - } else { - this.cardholderName = o.cardholderName?.encryptedString; - this.brand = o.brand?.encryptedString; - this.number = o.number?.encryptedString; - this.expMonth = o.expMonth?.encryptedString; - this.expYear = o.expYear?.encryptedString; - this.code = o.code?.encryptedString; - } + if (o instanceof CardView) { + this.cardholderName = o.cardholderName; + this.brand = o.brand; + this.number = o.number; + this.expMonth = o.expMonth; + this.expYear = o.expYear; + this.code = o.code; + } else { + this.cardholderName = o.cardholderName?.encryptedString; + this.brand = o.brand?.encryptedString; + this.number = o.number?.encryptedString; + this.expMonth = o.expMonth?.encryptedString; + this.expYear = o.expYear?.encryptedString; + this.code = o.code?.encryptedString; } + } } diff --git a/common/src/models/export/cipher.ts b/common/src/models/export/cipher.ts index 6f050776..c433044d 100644 --- a/common/src/models/export/cipher.ts +++ b/common/src/models/export/cipher.ts @@ -1,158 +1,158 @@ -import { CipherRepromptType } from '../../enums/cipherRepromptType'; -import { CipherType } from '../../enums/cipherType'; +import { CipherRepromptType } from "../../enums/cipherRepromptType"; +import { CipherType } from "../../enums/cipherType"; -import { CipherView } from '../view/cipherView'; +import { CipherView } from "../view/cipherView"; -import { Cipher as CipherDomain } from '../domain/cipher'; -import { EncString } from '../domain/encString'; +import { Cipher as CipherDomain } from "../domain/cipher"; +import { EncString } from "../domain/encString"; -import { Card } from './card'; -import { Field } from './field'; -import { Identity } from './identity'; -import { Login } from './login'; -import { SecureNote } from './secureNote'; +import { Card } from "./card"; +import { Field } from "./field"; +import { Identity } from "./identity"; +import { Login } from "./login"; +import { SecureNote } from "./secureNote"; export class Cipher { - static template(): Cipher { - const req = new Cipher(); - req.organizationId = null; - req.collectionIds = null; - req.folderId = null; - req.type = CipherType.Login; - req.name = 'Item name'; - req.notes = 'Some notes about this item.'; - req.favorite = false; - req.fields = []; - req.login = null; - req.secureNote = null; - req.card = null; - req.identity = null; - req.reprompt = CipherRepromptType.None; - return req; + static template(): Cipher { + const req = new Cipher(); + req.organizationId = null; + req.collectionIds = null; + req.folderId = null; + req.type = CipherType.Login; + req.name = "Item name"; + req.notes = "Some notes about this item."; + req.favorite = false; + req.fields = []; + req.login = null; + req.secureNote = null; + req.card = null; + req.identity = null; + req.reprompt = CipherRepromptType.None; + return req; + } + + static toView(req: Cipher, view = new CipherView()) { + view.type = req.type; + view.folderId = req.folderId; + if (view.organizationId == null) { + view.organizationId = req.organizationId; + } + if (view.collectionIds || req.collectionIds) { + const set = new Set((view.collectionIds ?? []).concat(req.collectionIds ?? [])); + view.collectionIds = Array.from(set.values()); + } + view.name = req.name; + view.notes = req.notes; + view.favorite = req.favorite; + view.reprompt = req.reprompt ?? CipherRepromptType.None; + + if (req.fields != null) { + view.fields = req.fields.map((f) => Field.toView(f)); } - static toView(req: Cipher, view = new CipherView()) { - view.type = req.type; - view.folderId = req.folderId; - if (view.organizationId == null) { - view.organizationId = req.organizationId; - } - if (view.collectionIds || req.collectionIds) { - const set = new Set((view.collectionIds ?? []).concat(req.collectionIds ?? [])); - view.collectionIds = Array.from(set.values()); - } - view.name = req.name; - view.notes = req.notes; - view.favorite = req.favorite; - view.reprompt = req.reprompt ?? CipherRepromptType.None; - - if (req.fields != null) { - view.fields = req.fields.map(f => Field.toView(f)); - } - - switch (req.type) { - case CipherType.Login: - view.login = Login.toView(req.login); - break; - case CipherType.SecureNote: - view.secureNote = SecureNote.toView(req.secureNote); - break; - case CipherType.Card: - view.card = Card.toView(req.card); - break; - case CipherType.Identity: - view.identity = Identity.toView(req.identity); - break; - } - - return view; + switch (req.type) { + case CipherType.Login: + view.login = Login.toView(req.login); + break; + case CipherType.SecureNote: + view.secureNote = SecureNote.toView(req.secureNote); + break; + case CipherType.Card: + view.card = Card.toView(req.card); + break; + case CipherType.Identity: + view.identity = Identity.toView(req.identity); + break; } - static toDomain(req: Cipher, domain = new CipherDomain()) { - domain.type = req.type; - domain.folderId = req.folderId; - if (domain.organizationId == null) { - domain.organizationId = req.organizationId; - } - domain.name = req.name != null ? new EncString(req.name) : null; - domain.notes = req.notes != null ? new EncString(req.notes) : null; - domain.favorite = req.favorite; - domain.reprompt = req.reprompt ?? CipherRepromptType.None; + return view; + } - if (req.fields != null) { - domain.fields = req.fields.map(f => Field.toDomain(f)); - } + static toDomain(req: Cipher, domain = new CipherDomain()) { + domain.type = req.type; + domain.folderId = req.folderId; + if (domain.organizationId == null) { + domain.organizationId = req.organizationId; + } + domain.name = req.name != null ? new EncString(req.name) : null; + domain.notes = req.notes != null ? new EncString(req.notes) : null; + domain.favorite = req.favorite; + domain.reprompt = req.reprompt ?? CipherRepromptType.None; - switch (req.type) { - case CipherType.Login: - domain.login = Login.toDomain(req.login); - break; - case CipherType.SecureNote: - domain.secureNote = SecureNote.toDomain(req.secureNote); - break; - case CipherType.Card: - domain.card = Card.toDomain(req.card); - break; - case CipherType.Identity: - domain.identity = Identity.toDomain(req.identity); - break; - } - - return domain; + if (req.fields != null) { + domain.fields = req.fields.map((f) => Field.toDomain(f)); } - type: CipherType; - folderId: string; - organizationId: string; - collectionIds: string[]; - name: string; - notes: string; - favorite: boolean; - fields: Field[]; - login: Login; - secureNote: SecureNote; - card: Card; - identity: Identity; - reprompt: CipherRepromptType; - - // Use build method instead of ctor so that we can control order of JSON stringify for pretty print - build(o: CipherView | CipherDomain) { - this.organizationId = o.organizationId; - this.folderId = o.folderId; - this.type = o.type; - this.reprompt = o.reprompt; - - if (o instanceof CipherView) { - this.name = o.name; - this.notes = o.notes; - } else { - this.name = o.name?.encryptedString; - this.notes = o.notes?.encryptedString; - } - - this.favorite = o.favorite; - - if (o.fields != null) { - if (o instanceof CipherView) { - this.fields = o.fields.map(f => new Field(f)); - } else { - this.fields = o.fields.map(f => new Field(f)); - } - } - - switch (o.type) { - case CipherType.Login: - this.login = new Login(o.login); - break; - case CipherType.SecureNote: - this.secureNote = new SecureNote(o.secureNote); - break; - case CipherType.Card: - this.card = new Card(o.card); - break; - case CipherType.Identity: - this.identity = new Identity(o.identity); - break; - } + switch (req.type) { + case CipherType.Login: + domain.login = Login.toDomain(req.login); + break; + case CipherType.SecureNote: + domain.secureNote = SecureNote.toDomain(req.secureNote); + break; + case CipherType.Card: + domain.card = Card.toDomain(req.card); + break; + case CipherType.Identity: + domain.identity = Identity.toDomain(req.identity); + break; } + + return domain; + } + + type: CipherType; + folderId: string; + organizationId: string; + collectionIds: string[]; + name: string; + notes: string; + favorite: boolean; + fields: Field[]; + login: Login; + secureNote: SecureNote; + card: Card; + identity: Identity; + reprompt: CipherRepromptType; + + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: CipherView | CipherDomain) { + this.organizationId = o.organizationId; + this.folderId = o.folderId; + this.type = o.type; + this.reprompt = o.reprompt; + + if (o instanceof CipherView) { + this.name = o.name; + this.notes = o.notes; + } else { + this.name = o.name?.encryptedString; + this.notes = o.notes?.encryptedString; + } + + this.favorite = o.favorite; + + if (o.fields != null) { + if (o instanceof CipherView) { + this.fields = o.fields.map((f) => new Field(f)); + } else { + this.fields = o.fields.map((f) => new Field(f)); + } + } + + switch (o.type) { + case CipherType.Login: + this.login = new Login(o.login); + break; + case CipherType.SecureNote: + this.secureNote = new SecureNote(o.secureNote); + break; + case CipherType.Card: + this.card = new Card(o.card); + break; + case CipherType.Identity: + this.identity = new Identity(o.identity); + break; + } + } } diff --git a/common/src/models/export/cipherWithIds.ts b/common/src/models/export/cipherWithIds.ts index 184cd542..fccf713e 100644 --- a/common/src/models/export/cipherWithIds.ts +++ b/common/src/models/export/cipherWithIds.ts @@ -1,17 +1,17 @@ -import { Cipher } from './cipher'; +import { Cipher } from "./cipher"; -import { CipherView } from '../view/cipherView'; +import { CipherView } from "../view/cipherView"; -import { Cipher as CipherDomain } from '../domain/cipher'; +import { Cipher as CipherDomain } from "../domain/cipher"; export class CipherWithIds extends Cipher { - id: string; - collectionIds: string[]; + id: string; + collectionIds: string[]; - // Use build method instead of ctor so that we can control order of JSON stringify for pretty print - build(o: CipherView | CipherDomain) { - this.id = o.id; - super.build(o); - this.collectionIds = o.collectionIds; - } + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: CipherView | CipherDomain) { + this.id = o.id; + super.build(o); + this.collectionIds = o.collectionIds; + } } diff --git a/common/src/models/export/collection.ts b/common/src/models/export/collection.ts index e628be5b..70d52397 100644 --- a/common/src/models/export/collection.ts +++ b/common/src/models/export/collection.ts @@ -1,47 +1,47 @@ -import { CollectionView } from '../view/collectionView'; +import { CollectionView } from "../view/collectionView"; -import { Collection as CollectionDomain } from '../domain/collection'; -import { EncString } from '../domain/encString'; +import { Collection as CollectionDomain } from "../domain/collection"; +import { EncString } from "../domain/encString"; export class Collection { - static template(): Collection { - const req = new Collection(); - req.organizationId = '00000000-0000-0000-0000-000000000000'; - req.name = 'Collection name'; - req.externalId = null; - return req; - } + static template(): Collection { + const req = new Collection(); + req.organizationId = "00000000-0000-0000-0000-000000000000"; + req.name = "Collection name"; + req.externalId = null; + return req; + } - static toView(req: Collection, view = new CollectionView()) { - view.name = req.name; - view.externalId = req.externalId; - if (view.organizationId == null) { - view.organizationId = req.organizationId; - } - return view; + static toView(req: Collection, view = new CollectionView()) { + view.name = req.name; + view.externalId = req.externalId; + if (view.organizationId == null) { + view.organizationId = req.organizationId; } + return view; + } - static toDomain(req: Collection, domain = new CollectionDomain()) { - domain.name = req.name != null ? new EncString(req.name) : null; - domain.externalId = req.externalId; - if (domain.organizationId == null) { - domain.organizationId = req.organizationId; - } - return domain; + static toDomain(req: Collection, domain = new CollectionDomain()) { + domain.name = req.name != null ? new EncString(req.name) : null; + domain.externalId = req.externalId; + if (domain.organizationId == null) { + domain.organizationId = req.organizationId; } + return domain; + } - organizationId: string; - name: string; - externalId: string; + organizationId: string; + name: string; + externalId: string; - // Use build method instead of ctor so that we can control order of JSON stringify for pretty print - build(o: CollectionView | CollectionDomain) { - this.organizationId = o.organizationId; - if (o instanceof CollectionView) { - this.name = o.name; - } else { - this.name = o.name?.encryptedString; - } - this.externalId = o.externalId; + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: CollectionView | CollectionDomain) { + this.organizationId = o.organizationId; + if (o instanceof CollectionView) { + this.name = o.name; + } else { + this.name = o.name?.encryptedString; } + this.externalId = o.externalId; + } } diff --git a/common/src/models/export/collectionWithId.ts b/common/src/models/export/collectionWithId.ts index ef48ddd9..d5fcec58 100644 --- a/common/src/models/export/collectionWithId.ts +++ b/common/src/models/export/collectionWithId.ts @@ -1,15 +1,15 @@ -import { Collection } from './collection'; +import { Collection } from "./collection"; -import { CollectionView } from '../view/collectionView'; +import { CollectionView } from "../view/collectionView"; -import { Collection as CollectionDomain } from '../domain/collection'; +import { Collection as CollectionDomain } from "../domain/collection"; export class CollectionWithId extends Collection { - id: string; + id: string; - // Use build method instead of ctor so that we can control order of JSON stringify for pretty print - build(o: CollectionView | CollectionDomain) { - this.id = o.id; - super.build(o); - } + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: CollectionView | CollectionDomain) { + this.id = o.id; + super.build(o); + } } diff --git a/common/src/models/export/event.ts b/common/src/models/export/event.ts index 70e1f19e..09975f2f 100644 --- a/common/src/models/export/event.ts +++ b/common/src/models/export/event.ts @@ -1,26 +1,26 @@ -import { EventType } from '../../enums/eventType'; -import { EventView } from '../view/eventView'; +import { EventType } from "../../enums/eventType"; +import { EventView } from "../view/eventView"; export class Event { - message: string; - appIcon: string; - appName: string; - userId: string; - userName: string; - userEmail: string; - date: string; - ip: string; - type: string; + message: string; + appIcon: string; + appName: string; + userId: string; + userName: string; + userEmail: string; + date: string; + ip: string; + type: string; - constructor(event: EventView) { - this.message = event.humanReadableMessage; - this.appIcon = event.appIcon; - this.appName = event.appName; - this.userId = event.userId; - this.userName = event.userName; - this.userEmail = event.userEmail; - this.date = event.date; - this.ip = event.ip; - this.type = EventType[event.type]; - } + constructor(event: EventView) { + this.message = event.humanReadableMessage; + this.appIcon = event.appIcon; + this.appName = event.appName; + this.userId = event.userId; + this.userName = event.userName; + this.userEmail = event.userEmail; + this.date = event.date; + this.ip = event.ip; + this.type = EventType[event.type]; + } } diff --git a/common/src/models/export/field.ts b/common/src/models/export/field.ts index 0804c123..e4353a71 100644 --- a/common/src/models/export/field.ts +++ b/common/src/models/export/field.ts @@ -1,54 +1,54 @@ -import { FieldType } from '../../enums/fieldType'; -import { LinkedIdType } from '../../enums/linkedIdType'; +import { FieldType } from "../../enums/fieldType"; +import { LinkedIdType } from "../../enums/linkedIdType"; -import { FieldView } from '../view/fieldView'; +import { FieldView } from "../view/fieldView"; -import { EncString } from '../domain/encString'; -import { Field as FieldDomain } from '../domain/field'; +import { EncString } from "../domain/encString"; +import { Field as FieldDomain } from "../domain/field"; export class Field { - static template(): Field { - const req = new Field(); - req.name = 'Field name'; - req.value = 'Some value'; - req.type = FieldType.Text; - return req; + static template(): Field { + const req = new Field(); + req.name = "Field name"; + req.value = "Some value"; + req.type = FieldType.Text; + return req; + } + + static toView(req: Field, view = new FieldView()) { + view.type = req.type; + view.value = req.value; + view.name = req.name; + view.linkedId = req.linkedId; + return view; + } + + static toDomain(req: Field, domain = new FieldDomain()) { + domain.type = req.type; + domain.value = req.value != null ? new EncString(req.value) : null; + domain.name = req.name != null ? new EncString(req.name) : null; + domain.linkedId = req.linkedId; + return domain; + } + + name: string; + value: string; + type: FieldType; + linkedId: LinkedIdType; + + constructor(o?: FieldView | FieldDomain) { + if (o == null) { + return; } - static toView(req: Field, view = new FieldView()) { - view.type = req.type; - view.value = req.value; - view.name = req.name; - view.linkedId = req.linkedId; - return view; - } - - static toDomain(req: Field, domain = new FieldDomain()) { - domain.type = req.type; - domain.value = req.value != null ? new EncString(req.value) : null; - domain.name = req.name != null ? new EncString(req.name) : null; - domain.linkedId = req.linkedId; - return domain; - } - - name: string; - value: string; - type: FieldType; - linkedId: LinkedIdType; - - constructor(o?: FieldView | FieldDomain) { - if (o == null) { - return; - } - - if (o instanceof FieldView) { - this.name = o.name; - this.value = o.value; - } else { - this.name = o.name?.encryptedString; - this.value = o.value?.encryptedString; - } - this.type = o.type; - this.linkedId = o.linkedId; + if (o instanceof FieldView) { + this.name = o.name; + this.value = o.value; + } else { + this.name = o.name?.encryptedString; + this.value = o.value?.encryptedString; } + this.type = o.type; + this.linkedId = o.linkedId; + } } diff --git a/common/src/models/export/folder.ts b/common/src/models/export/folder.ts index 8391fb61..9f015b56 100644 --- a/common/src/models/export/folder.ts +++ b/common/src/models/export/folder.ts @@ -1,33 +1,33 @@ -import { FolderView } from '../view/folderView'; +import { FolderView } from "../view/folderView"; -import { EncString } from '../domain/encString'; -import { Folder as FolderDomain } from '../domain/folder'; +import { EncString } from "../domain/encString"; +import { Folder as FolderDomain } from "../domain/folder"; export class Folder { - static template(): Folder { - const req = new Folder(); - req.name = 'Folder name'; - return req; - } + static template(): Folder { + const req = new Folder(); + req.name = "Folder name"; + return req; + } - static toView(req: Folder, view = new FolderView()) { - view.name = req.name; - return view; - } + static toView(req: Folder, view = new FolderView()) { + view.name = req.name; + return view; + } - static toDomain(req: Folder, domain = new FolderDomain()) { - domain.name = req.name != null ? new EncString(req.name) : null; - return domain; - } + static toDomain(req: Folder, domain = new FolderDomain()) { + domain.name = req.name != null ? new EncString(req.name) : null; + return domain; + } - name: string; + name: string; - // Use build method instead of ctor so that we can control order of JSON stringify for pretty print - build(o: FolderView | FolderDomain) { - if (o instanceof FolderView) { - this.name = o.name; - } else { - this.name = o.name?.encryptedString; - } + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: FolderView | FolderDomain) { + if (o instanceof FolderView) { + this.name = o.name; + } else { + this.name = o.name?.encryptedString; } + } } diff --git a/common/src/models/export/folderWithId.ts b/common/src/models/export/folderWithId.ts index 83e57e71..69983cab 100644 --- a/common/src/models/export/folderWithId.ts +++ b/common/src/models/export/folderWithId.ts @@ -1,15 +1,15 @@ -import { Folder } from './folder'; +import { Folder } from "./folder"; -import { FolderView } from '../view/folderView'; +import { FolderView } from "../view/folderView"; -import { Folder as FolderDomain } from '../domain/folder'; +import { Folder as FolderDomain } from "../domain/folder"; export class FolderWithId extends Folder { - id: string; + id: string; - // Use build method instead of ctor so that we can control order of JSON stringify for pretty print - build(o: FolderView | FolderDomain) { - this.id = o.id; - super.build(o); - } + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: FolderView | FolderDomain) { + this.id = o.id; + super.build(o); + } } diff --git a/common/src/models/export/identity.ts b/common/src/models/export/identity.ts index abe6fb6c..42fb8865 100644 --- a/common/src/models/export/identity.ts +++ b/common/src/models/export/identity.ts @@ -1,138 +1,138 @@ -import { IdentityView } from '../view/identityView'; +import { IdentityView } from "../view/identityView"; -import { EncString } from '../domain/encString'; -import { Identity as IdentityDomain } from '../domain/identity'; +import { EncString } from "../domain/encString"; +import { Identity as IdentityDomain } from "../domain/identity"; export class Identity { - static template(): Identity { - const req = new Identity(); - req.title = 'Mr'; - req.firstName = 'John'; - req.middleName = 'William'; - req.lastName = 'Doe'; - req.address1 = '123 Any St'; - req.address2 = 'Apt #123'; - req.address3 = null; - req.city = 'New York'; - req.state = 'NY'; - req.postalCode = '10001'; - req.country = 'US'; - req.company = 'Acme Inc.'; - req.email = 'john@company.com'; - req.phone = '5555551234'; - req.ssn = '000-123-4567'; - req.username = 'jdoe'; - req.passportNumber = 'US-123456789'; - req.licenseNumber = 'D123-12-123-12333'; - return req; + static template(): Identity { + const req = new Identity(); + req.title = "Mr"; + req.firstName = "John"; + req.middleName = "William"; + req.lastName = "Doe"; + req.address1 = "123 Any St"; + req.address2 = "Apt #123"; + req.address3 = null; + req.city = "New York"; + req.state = "NY"; + req.postalCode = "10001"; + req.country = "US"; + req.company = "Acme Inc."; + req.email = "john@company.com"; + req.phone = "5555551234"; + req.ssn = "000-123-4567"; + req.username = "jdoe"; + req.passportNumber = "US-123456789"; + req.licenseNumber = "D123-12-123-12333"; + return req; + } + + static toView(req: Identity, view = new IdentityView()) { + view.title = req.title; + view.firstName = req.firstName; + view.middleName = req.middleName; + view.lastName = req.lastName; + view.address1 = req.address1; + view.address2 = req.address2; + view.address3 = req.address3; + view.city = req.city; + view.state = req.state; + view.postalCode = req.postalCode; + view.country = req.country; + view.company = req.company; + view.email = req.email; + view.phone = req.phone; + view.ssn = req.ssn; + view.username = req.username; + view.passportNumber = req.passportNumber; + view.licenseNumber = req.licenseNumber; + return view; + } + + static toDomain(req: Identity, domain = new IdentityDomain()) { + domain.title = req.title != null ? new EncString(req.title) : null; + domain.firstName = req.firstName != null ? new EncString(req.firstName) : null; + domain.middleName = req.middleName != null ? new EncString(req.middleName) : null; + domain.lastName = req.lastName != null ? new EncString(req.lastName) : null; + domain.address1 = req.address1 != null ? new EncString(req.address1) : null; + domain.address2 = req.address2 != null ? new EncString(req.address2) : null; + domain.address3 = req.address3 != null ? new EncString(req.address3) : null; + domain.city = req.city != null ? new EncString(req.city) : null; + domain.state = req.state != null ? new EncString(req.state) : null; + domain.postalCode = req.postalCode != null ? new EncString(req.postalCode) : null; + domain.country = req.country != null ? new EncString(req.country) : null; + domain.company = req.company != null ? new EncString(req.company) : null; + domain.email = req.email != null ? new EncString(req.email) : null; + domain.phone = req.phone != null ? new EncString(req.phone) : null; + domain.ssn = req.ssn != null ? new EncString(req.ssn) : null; + domain.username = req.username != null ? new EncString(req.username) : null; + domain.passportNumber = req.passportNumber != null ? new EncString(req.passportNumber) : null; + domain.licenseNumber = req.licenseNumber != null ? new EncString(req.licenseNumber) : null; + return domain; + } + + title: string; + firstName: string; + middleName: string; + lastName: string; + address1: string; + address2: string; + address3: string; + city: string; + state: string; + postalCode: string; + country: string; + company: string; + email: string; + phone: string; + ssn: string; + username: string; + passportNumber: string; + licenseNumber: string; + + constructor(o?: IdentityView | IdentityDomain) { + if (o == null) { + return; } - static toView(req: Identity, view = new IdentityView()) { - view.title = req.title; - view.firstName = req.firstName; - view.middleName = req.middleName; - view.lastName = req.lastName; - view.address1 = req.address1; - view.address2 = req.address2; - view.address3 = req.address3; - view.city = req.city; - view.state = req.state; - view.postalCode = req.postalCode; - view.country = req.country; - view.company = req.company; - view.email = req.email; - view.phone = req.phone; - view.ssn = req.ssn; - view.username = req.username; - view.passportNumber = req.passportNumber; - view.licenseNumber = req.licenseNumber; - return view; - } - - static toDomain(req: Identity, domain = new IdentityDomain()) { - domain.title = req.title != null ? new EncString(req.title) : null; - domain.firstName = req.firstName != null ? new EncString(req.firstName) : null; - domain.middleName = req.middleName != null ? new EncString(req.middleName) : null; - domain.lastName = req.lastName != null ? new EncString(req.lastName) : null; - domain.address1 = req.address1 != null ? new EncString(req.address1) : null; - domain.address2 = req.address2 != null ? new EncString(req.address2) : null; - domain.address3 = req.address3 != null ? new EncString(req.address3) : null; - domain.city = req.city != null ? new EncString(req.city) : null; - domain.state = req.state != null ? new EncString(req.state) : null; - domain.postalCode = req.postalCode != null ? new EncString(req.postalCode) : null; - domain.country = req.country != null ? new EncString(req.country) : null; - domain.company = req.company != null ? new EncString(req.company) : null; - domain.email = req.email != null ? new EncString(req.email) : null; - domain.phone = req.phone != null ? new EncString(req.phone) : null; - domain.ssn = req.ssn != null ? new EncString(req.ssn) : null; - domain.username = req.username != null ? new EncString(req.username) : null; - domain.passportNumber = req.passportNumber != null ? new EncString(req.passportNumber) : null; - domain.licenseNumber = req.licenseNumber != null ? new EncString(req.licenseNumber) : null; - return domain; - } - - title: string; - firstName: string; - middleName: string; - lastName: string; - address1: string; - address2: string; - address3: string; - city: string; - state: string; - postalCode: string; - country: string; - company: string; - email: string; - phone: string; - ssn: string; - username: string; - passportNumber: string; - licenseNumber: string; - - constructor(o?: IdentityView | IdentityDomain) { - if (o == null) { - return; - } - - if (o instanceof IdentityView) { - this.title = o.title; - this.firstName = o.firstName; - this.middleName = o.middleName; - this.lastName = o.lastName; - this.address1 = o.address1; - this.address2 = o.address2; - this.address3 = o.address3; - this.city = o.city; - this.state = o.state; - this.postalCode = o.postalCode; - this.country = o.country; - this.company = o.company; - this.email = o.email; - this.phone = o.phone; - this.ssn = o.ssn; - this.username = o.username; - this.passportNumber = o.passportNumber; - this.licenseNumber = o.licenseNumber; - } else { - this.title = o.title?.encryptedString; - this.firstName = o.firstName?.encryptedString; - this.middleName = o.middleName?.encryptedString; - this.lastName = o.lastName?.encryptedString; - this.address1 = o.address1?.encryptedString; - this.address2 = o.address2?.encryptedString; - this.address3 = o.address3?.encryptedString; - this.city = o.city?.encryptedString; - this.state = o.state?.encryptedString; - this.postalCode = o.postalCode?.encryptedString; - this.country = o.country?.encryptedString; - this.company = o.company?.encryptedString; - this.email = o.email?.encryptedString; - this.phone = o.phone?.encryptedString; - this.ssn = o.ssn?.encryptedString; - this.username = o.username?.encryptedString; - this.passportNumber = o.passportNumber?.encryptedString; - this.licenseNumber = o.licenseNumber?.encryptedString; - } + if (o instanceof IdentityView) { + this.title = o.title; + this.firstName = o.firstName; + this.middleName = o.middleName; + this.lastName = o.lastName; + this.address1 = o.address1; + this.address2 = o.address2; + this.address3 = o.address3; + this.city = o.city; + this.state = o.state; + this.postalCode = o.postalCode; + this.country = o.country; + this.company = o.company; + this.email = o.email; + this.phone = o.phone; + this.ssn = o.ssn; + this.username = o.username; + this.passportNumber = o.passportNumber; + this.licenseNumber = o.licenseNumber; + } else { + this.title = o.title?.encryptedString; + this.firstName = o.firstName?.encryptedString; + this.middleName = o.middleName?.encryptedString; + this.lastName = o.lastName?.encryptedString; + this.address1 = o.address1?.encryptedString; + this.address2 = o.address2?.encryptedString; + this.address3 = o.address3?.encryptedString; + this.city = o.city?.encryptedString; + this.state = o.state?.encryptedString; + this.postalCode = o.postalCode?.encryptedString; + this.country = o.country?.encryptedString; + this.company = o.company?.encryptedString; + this.email = o.email?.encryptedString; + this.phone = o.phone?.encryptedString; + this.ssn = o.ssn?.encryptedString; + this.username = o.username?.encryptedString; + this.passportNumber = o.passportNumber?.encryptedString; + this.licenseNumber = o.licenseNumber?.encryptedString; } + } } diff --git a/common/src/models/export/login.ts b/common/src/models/export/login.ts index 3b6b23a2..d64263b3 100644 --- a/common/src/models/export/login.ts +++ b/common/src/models/export/login.ts @@ -1,66 +1,66 @@ -import { LoginUri } from './loginUri'; +import { LoginUri } from "./loginUri"; -import { LoginView } from '../view/loginView'; +import { LoginView } from "../view/loginView"; -import { EncString } from '../domain/encString'; -import { Login as LoginDomain } from '../domain/login'; +import { EncString } from "../domain/encString"; +import { Login as LoginDomain } from "../domain/login"; export class Login { - static template(): Login { - const req = new Login(); - req.uris = []; - req.username = 'jdoe'; - req.password = 'myp@ssword123'; - req.totp = 'JBSWY3DPEHPK3PXP'; - return req; + static template(): Login { + const req = new Login(); + req.uris = []; + req.username = "jdoe"; + req.password = "myp@ssword123"; + req.totp = "JBSWY3DPEHPK3PXP"; + return req; + } + + static toView(req: Login, view = new LoginView()) { + if (req.uris != null) { + view.uris = req.uris.map((u) => LoginUri.toView(u)); + } + view.username = req.username; + view.password = req.password; + view.totp = req.totp; + return view; + } + + static toDomain(req: Login, domain = new LoginDomain()) { + if (req.uris != null) { + domain.uris = req.uris.map((u) => LoginUri.toDomain(u)); + } + domain.username = req.username != null ? new EncString(req.username) : null; + domain.password = req.password != null ? new EncString(req.password) : null; + domain.totp = req.totp != null ? new EncString(req.totp) : null; + return domain; + } + + uris: LoginUri[]; + username: string; + password: string; + totp: string; + + constructor(o?: LoginView | LoginDomain) { + if (o == null) { + return; } - static toView(req: Login, view = new LoginView()) { - if (req.uris != null) { - view.uris = req.uris.map(u => LoginUri.toView(u)); - } - view.username = req.username; - view.password = req.password; - view.totp = req.totp; - return view; + if (o.uris != null) { + if (o instanceof LoginView) { + this.uris = o.uris.map((u) => new LoginUri(u)); + } else { + this.uris = o.uris.map((u) => new LoginUri(u)); + } } - static toDomain(req: Login, domain = new LoginDomain()) { - if (req.uris != null) { - domain.uris = req.uris.map(u => LoginUri.toDomain(u)); - } - domain.username = req.username != null ? new EncString(req.username) : null; - domain.password = req.password != null ? new EncString(req.password) : null; - domain.totp = req.totp != null ? new EncString(req.totp) : null; - return domain; - } - - uris: LoginUri[]; - username: string; - password: string; - totp: string; - - constructor(o?: LoginView | LoginDomain) { - if (o == null) { - return; - } - - if (o.uris != null) { - if (o instanceof LoginView) { - this.uris = o.uris.map(u => new LoginUri(u)); - } else { - this.uris = o.uris.map(u => new LoginUri(u)); - } - } - - if (o instanceof LoginView) { - this.username = o.username; - this.password = o.password; - this.totp = o.totp; - } else { - this.username = o.username?.encryptedString; - this.password = o.password?.encryptedString; - this.totp = o.totp?.encryptedString; - } + if (o instanceof LoginView) { + this.username = o.username; + this.password = o.password; + this.totp = o.totp; + } else { + this.username = o.username?.encryptedString; + this.password = o.password?.encryptedString; + this.totp = o.totp?.encryptedString; } + } } diff --git a/common/src/models/export/loginUri.ts b/common/src/models/export/loginUri.ts index 81d6b625..445b1a25 100644 --- a/common/src/models/export/loginUri.ts +++ b/common/src/models/export/loginUri.ts @@ -1,43 +1,43 @@ -import { UriMatchType } from '../../enums/uriMatchType'; +import { UriMatchType } from "../../enums/uriMatchType"; -import { LoginUriView } from '../view/loginUriView'; +import { LoginUriView } from "../view/loginUriView"; -import { EncString } from '../domain/encString'; -import { LoginUri as LoginUriDomain } from '../domain/loginUri'; +import { EncString } from "../domain/encString"; +import { LoginUri as LoginUriDomain } from "../domain/loginUri"; export class LoginUri { - static template(): LoginUri { - const req = new LoginUri(); - req.uri = 'https://google.com'; - req.match = null; - return req; + static template(): LoginUri { + const req = new LoginUri(); + req.uri = "https://google.com"; + req.match = null; + return req; + } + + static toView(req: LoginUri, view = new LoginUriView()) { + view.uri = req.uri; + view.match = req.match; + return view; + } + + static toDomain(req: LoginUri, domain = new LoginUriDomain()) { + domain.uri = req.uri != null ? new EncString(req.uri) : null; + domain.match = req.match; + return domain; + } + + uri: string; + match: UriMatchType = null; + + constructor(o?: LoginUriView | LoginUriDomain) { + if (o == null) { + return; } - static toView(req: LoginUri, view = new LoginUriView()) { - view.uri = req.uri; - view.match = req.match; - return view; - } - - static toDomain(req: LoginUri, domain = new LoginUriDomain()) { - domain.uri = req.uri != null ? new EncString(req.uri) : null; - domain.match = req.match; - return domain; - } - - uri: string; - match: UriMatchType = null; - - constructor(o?: LoginUriView | LoginUriDomain) { - if (o == null) { - return; - } - - if (o instanceof LoginUriView) { - this.uri = o.uri; - } else { - this.uri = o.uri?.encryptedString; - } - this.match = o.match; + if (o instanceof LoginUriView) { + this.uri = o.uri; + } else { + this.uri = o.uri?.encryptedString; } + this.match = o.match; + } } diff --git a/common/src/models/export/secureNote.ts b/common/src/models/export/secureNote.ts index 078f4033..2dc75a9a 100644 --- a/common/src/models/export/secureNote.ts +++ b/common/src/models/export/secureNote.ts @@ -1,33 +1,33 @@ -import { SecureNoteType } from '../../enums/secureNoteType'; +import { SecureNoteType } from "../../enums/secureNoteType"; -import { SecureNoteView } from '../view/secureNoteView'; +import { SecureNoteView } from "../view/secureNoteView"; -import { SecureNote as SecureNoteDomain } from '../domain/secureNote'; +import { SecureNote as SecureNoteDomain } from "../domain/secureNote"; export class SecureNote { - static template(): SecureNote { - const req = new SecureNote(); - req.type = SecureNoteType.Generic; - return req; + static template(): SecureNote { + const req = new SecureNote(); + req.type = SecureNoteType.Generic; + return req; + } + + static toView(req: SecureNote, view = new SecureNoteView()) { + view.type = req.type; + return view; + } + + static toDomain(req: SecureNote, view = new SecureNoteDomain()) { + view.type = req.type; + return view; + } + + type: SecureNoteType; + + constructor(o?: SecureNoteView | SecureNoteDomain) { + if (o == null) { + return; } - static toView(req: SecureNote, view = new SecureNoteView()) { - view.type = req.type; - return view; - } - - static toDomain(req: SecureNote, view = new SecureNoteDomain()) { - view.type = req.type; - return view; - } - - type: SecureNoteType; - - constructor(o?: SecureNoteView | SecureNoteDomain) { - if (o == null) { - return; - } - - this.type = o.type; - } + this.type = o.type; + } } diff --git a/common/src/models/request/account/setKeyConnectorKeyRequest.ts b/common/src/models/request/account/setKeyConnectorKeyRequest.ts index 87b580d0..b71ce290 100644 --- a/common/src/models/request/account/setKeyConnectorKeyRequest.ts +++ b/common/src/models/request/account/setKeyConnectorKeyRequest.ts @@ -1,19 +1,25 @@ -import { KeysRequest } from '../keysRequest'; +import { KeysRequest } from "../keysRequest"; -import { KdfType } from '../../../enums/kdfType'; +import { KdfType } from "../../../enums/kdfType"; export class SetKeyConnectorKeyRequest { - key: string; - keys: KeysRequest; - kdf: KdfType; - kdfIterations: number; - orgIdentifier: string; + key: string; + keys: KeysRequest; + kdf: KdfType; + kdfIterations: number; + orgIdentifier: string; - constructor(key: string, kdf: KdfType, kdfIterations: number, orgIdentifier: string, keys: KeysRequest) { - this.key = key; - this.kdf = kdf; - this.kdfIterations = kdfIterations; - this.orgIdentifier = orgIdentifier; - this.keys = keys; - } + constructor( + key: string, + kdf: KdfType, + kdfIterations: number, + orgIdentifier: string, + keys: KeysRequest + ) { + this.key = key; + this.kdf = kdf; + this.kdfIterations = kdfIterations; + this.orgIdentifier = orgIdentifier; + this.keys = keys; + } } diff --git a/common/src/models/request/account/verifyOTPRequest.ts b/common/src/models/request/account/verifyOTPRequest.ts index 8cc8f985..2eb8816e 100644 --- a/common/src/models/request/account/verifyOTPRequest.ts +++ b/common/src/models/request/account/verifyOTPRequest.ts @@ -1,7 +1,7 @@ export class VerifyOTPRequest { - OTP: string; + OTP: string; - constructor(OTP: string) { - this.OTP = OTP; - } + constructor(OTP: string) { + this.OTP = OTP; + } } diff --git a/common/src/models/request/attachmentRequest.ts b/common/src/models/request/attachmentRequest.ts index 466829aa..ea1ea821 100644 --- a/common/src/models/request/attachmentRequest.ts +++ b/common/src/models/request/attachmentRequest.ts @@ -1,6 +1,6 @@ export class AttachmentRequest { - fileName: string; - key: string; - fileSize: number; - adminRequest: boolean; + fileName: string; + key: string; + fileSize: number; + adminRequest: boolean; } diff --git a/common/src/models/request/bitPayInvoiceRequest.ts b/common/src/models/request/bitPayInvoiceRequest.ts index 2d1369ea..9042611b 100644 --- a/common/src/models/request/bitPayInvoiceRequest.ts +++ b/common/src/models/request/bitPayInvoiceRequest.ts @@ -1,9 +1,9 @@ export class BitPayInvoiceRequest { - userId: string; - organizationId: string; - credit: boolean; - amount: number; - returnUrl: string; - name: string; - email: string; + userId: string; + organizationId: string; + credit: boolean; + amount: number; + returnUrl: string; + name: string; + email: string; } diff --git a/common/src/models/request/captchaProtectedRequest.ts b/common/src/models/request/captchaProtectedRequest.ts index 18b6d6c2..54721e01 100644 --- a/common/src/models/request/captchaProtectedRequest.ts +++ b/common/src/models/request/captchaProtectedRequest.ts @@ -1,3 +1,3 @@ export abstract class CaptchaProtectedRequest { - captchaResponse: string = null; + captchaResponse: string = null; } diff --git a/common/src/models/request/cipherBulkDeleteRequest.ts b/common/src/models/request/cipherBulkDeleteRequest.ts index 97fab41b..227f1a66 100644 --- a/common/src/models/request/cipherBulkDeleteRequest.ts +++ b/common/src/models/request/cipherBulkDeleteRequest.ts @@ -1,9 +1,9 @@ export class CipherBulkDeleteRequest { - ids: string[]; - organizationId: string; + ids: string[]; + organizationId: string; - constructor(ids: string[], organizationId?: string) { - this.ids = ids == null ? [] : ids; - this.organizationId = organizationId; - } + constructor(ids: string[], organizationId?: string) { + this.ids = ids == null ? [] : ids; + this.organizationId = organizationId; + } } diff --git a/common/src/models/request/cipherBulkMoveRequest.ts b/common/src/models/request/cipherBulkMoveRequest.ts index c0e8c626..06a737de 100644 --- a/common/src/models/request/cipherBulkMoveRequest.ts +++ b/common/src/models/request/cipherBulkMoveRequest.ts @@ -1,9 +1,9 @@ export class CipherBulkMoveRequest { - ids: string[]; - folderId: string; + ids: string[]; + folderId: string; - constructor(ids: string[], folderId: string) { - this.ids = ids == null ? [] : ids; - this.folderId = folderId; - } + constructor(ids: string[], folderId: string) { + this.ids = ids == null ? [] : ids; + this.folderId = folderId; + } } diff --git a/common/src/models/request/cipherBulkRestoreRequest.ts b/common/src/models/request/cipherBulkRestoreRequest.ts index 546cc924..70e5a4e8 100644 --- a/common/src/models/request/cipherBulkRestoreRequest.ts +++ b/common/src/models/request/cipherBulkRestoreRequest.ts @@ -1,7 +1,7 @@ export class CipherBulkRestoreRequest { - ids: string[]; + ids: string[]; - constructor(ids: string[]) { - this.ids = ids == null ? [] : ids; - } + constructor(ids: string[]) { + this.ids = ids == null ? [] : ids; + } } diff --git a/common/src/models/request/cipherBulkShareRequest.ts b/common/src/models/request/cipherBulkShareRequest.ts index 5d1e6781..be36da9d 100644 --- a/common/src/models/request/cipherBulkShareRequest.ts +++ b/common/src/models/request/cipherBulkShareRequest.ts @@ -1,18 +1,18 @@ -import { CipherWithIdRequest } from './cipherWithIdRequest'; +import { CipherWithIdRequest } from "./cipherWithIdRequest"; -import { Cipher } from '../domain/cipher'; +import { Cipher } from "../domain/cipher"; export class CipherBulkShareRequest { - ciphers: CipherWithIdRequest[]; - collectionIds: string[]; + ciphers: CipherWithIdRequest[]; + collectionIds: string[]; - constructor(ciphers: Cipher[], collectionIds: string[]) { - if (ciphers != null) { - this.ciphers = []; - ciphers.forEach(c => { - this.ciphers.push(new CipherWithIdRequest(c)); - }); - } - this.collectionIds = collectionIds; + constructor(ciphers: Cipher[], collectionIds: string[]) { + if (ciphers != null) { + this.ciphers = []; + ciphers.forEach((c) => { + this.ciphers.push(new CipherWithIdRequest(c)); + }); } + this.collectionIds = collectionIds; + } } diff --git a/common/src/models/request/cipherCollectionsRequest.ts b/common/src/models/request/cipherCollectionsRequest.ts index 1473f4e3..8d555389 100644 --- a/common/src/models/request/cipherCollectionsRequest.ts +++ b/common/src/models/request/cipherCollectionsRequest.ts @@ -1,7 +1,7 @@ export class CipherCollectionsRequest { - collectionIds: string[]; + collectionIds: string[]; - constructor(collectionIds: string[]) { - this.collectionIds = collectionIds == null ? [] : collectionIds; - } + constructor(collectionIds: string[]) { + this.collectionIds = collectionIds == null ? [] : collectionIds; + } } diff --git a/common/src/models/request/cipherCreateRequest.ts b/common/src/models/request/cipherCreateRequest.ts index 683d0a52..443ef318 100644 --- a/common/src/models/request/cipherCreateRequest.ts +++ b/common/src/models/request/cipherCreateRequest.ts @@ -1,13 +1,13 @@ -import { CipherRequest } from './cipherRequest'; +import { CipherRequest } from "./cipherRequest"; -import { Cipher } from '../domain/cipher'; +import { Cipher } from "../domain/cipher"; export class CipherCreateRequest { - cipher: CipherRequest; - collectionIds: string[]; + cipher: CipherRequest; + collectionIds: string[]; - constructor(cipher: Cipher) { - this.cipher = new CipherRequest(cipher); - this.collectionIds = cipher.collectionIds; - } + constructor(cipher: Cipher) { + this.cipher = new CipherRequest(cipher); + this.collectionIds = cipher.collectionIds; + } } diff --git a/common/src/models/request/cipherRequest.ts b/common/src/models/request/cipherRequest.ts index 23f09462..c14274d9 100644 --- a/common/src/models/request/cipherRequest.ts +++ b/common/src/models/request/cipherRequest.ts @@ -1,152 +1,166 @@ -import { CipherRepromptType } from '../../enums/cipherRepromptType'; -import { CipherType } from '../../enums/cipherType'; +import { CipherRepromptType } from "../../enums/cipherRepromptType"; +import { CipherType } from "../../enums/cipherType"; -import { Cipher } from '../domain/cipher'; +import { Cipher } from "../domain/cipher"; -import { CardApi } from '../api/cardApi'; -import { FieldApi } from '../api/fieldApi'; -import { IdentityApi } from '../api/identityApi'; -import { LoginApi } from '../api/loginApi'; -import { LoginUriApi } from '../api/loginUriApi'; -import { SecureNoteApi } from '../api/secureNoteApi'; +import { CardApi } from "../api/cardApi"; +import { FieldApi } from "../api/fieldApi"; +import { IdentityApi } from "../api/identityApi"; +import { LoginApi } from "../api/loginApi"; +import { LoginUriApi } from "../api/loginUriApi"; +import { SecureNoteApi } from "../api/secureNoteApi"; -import { AttachmentRequest } from './attachmentRequest'; -import { PasswordHistoryRequest } from './passwordHistoryRequest'; +import { AttachmentRequest } from "./attachmentRequest"; +import { PasswordHistoryRequest } from "./passwordHistoryRequest"; export class CipherRequest { - type: CipherType; - folderId: string; - organizationId: string; - name: string; - notes: string; - favorite: boolean; - login: LoginApi; - secureNote: SecureNoteApi; - card: CardApi; - identity: IdentityApi; - fields: FieldApi[]; - passwordHistory: PasswordHistoryRequest[]; - // Deprecated, remove at some point and rename attachments2 to attachments - attachments: { [id: string]: string; }; - attachments2: { [id: string]: AttachmentRequest; }; - lastKnownRevisionDate: Date; - reprompt: CipherRepromptType; + type: CipherType; + folderId: string; + organizationId: string; + name: string; + notes: string; + favorite: boolean; + login: LoginApi; + secureNote: SecureNoteApi; + card: CardApi; + identity: IdentityApi; + fields: FieldApi[]; + passwordHistory: PasswordHistoryRequest[]; + // Deprecated, remove at some point and rename attachments2 to attachments + attachments: { [id: string]: string }; + attachments2: { [id: string]: AttachmentRequest }; + lastKnownRevisionDate: Date; + reprompt: CipherRepromptType; - constructor(cipher: Cipher) { - this.type = cipher.type; - this.folderId = cipher.folderId; - this.organizationId = cipher.organizationId; - this.name = cipher.name ? cipher.name.encryptedString : null; - this.notes = cipher.notes ? cipher.notes.encryptedString : null; - this.favorite = cipher.favorite; - this.lastKnownRevisionDate = cipher.revisionDate; - this.reprompt = cipher.reprompt; + constructor(cipher: Cipher) { + this.type = cipher.type; + this.folderId = cipher.folderId; + this.organizationId = cipher.organizationId; + this.name = cipher.name ? cipher.name.encryptedString : null; + this.notes = cipher.notes ? cipher.notes.encryptedString : null; + this.favorite = cipher.favorite; + this.lastKnownRevisionDate = cipher.revisionDate; + this.reprompt = cipher.reprompt; - switch (this.type) { - case CipherType.Login: - this.login = new LoginApi(); - this.login.uris = null; - this.login.username = cipher.login.username ? cipher.login.username.encryptedString : null; - this.login.password = cipher.login.password ? cipher.login.password.encryptedString : null; - this.login.passwordRevisionDate = cipher.login.passwordRevisionDate != null ? - cipher.login.passwordRevisionDate.toISOString() : null; - this.login.totp = cipher.login.totp ? cipher.login.totp.encryptedString : null; - this.login.autofillOnPageLoad = cipher.login.autofillOnPageLoad; + switch (this.type) { + case CipherType.Login: + this.login = new LoginApi(); + this.login.uris = null; + this.login.username = cipher.login.username ? cipher.login.username.encryptedString : null; + this.login.password = cipher.login.password ? cipher.login.password.encryptedString : null; + this.login.passwordRevisionDate = + cipher.login.passwordRevisionDate != null + ? cipher.login.passwordRevisionDate.toISOString() + : null; + this.login.totp = cipher.login.totp ? cipher.login.totp.encryptedString : null; + this.login.autofillOnPageLoad = cipher.login.autofillOnPageLoad; - if (cipher.login.uris != null) { - this.login.uris = cipher.login.uris.map(u => { - const uri = new LoginUriApi(); - uri.uri = u.uri != null ? u.uri.encryptedString : null; - uri.match = u.match != null ? u.match : null; - return uri; - }); - } - break; - case CipherType.SecureNote: - this.secureNote = new SecureNoteApi(); - this.secureNote.type = cipher.secureNote.type; - break; - case CipherType.Card: - this.card = new CardApi(); - this.card.cardholderName = cipher.card.cardholderName != null ? - cipher.card.cardholderName.encryptedString : null; - this.card.brand = cipher.card.brand != null ? cipher.card.brand.encryptedString : null; - this.card.number = cipher.card.number != null ? cipher.card.number.encryptedString : null; - this.card.expMonth = cipher.card.expMonth != null ? cipher.card.expMonth.encryptedString : null; - this.card.expYear = cipher.card.expYear != null ? cipher.card.expYear.encryptedString : null; - this.card.code = cipher.card.code != null ? cipher.card.code.encryptedString : null; - break; - case CipherType.Identity: - this.identity = new IdentityApi(); - this.identity.title = cipher.identity.title != null ? cipher.identity.title.encryptedString : null; - this.identity.firstName = cipher.identity.firstName != null ? - cipher.identity.firstName.encryptedString : null; - this.identity.middleName = cipher.identity.middleName != null ? - cipher.identity.middleName.encryptedString : null; - this.identity.lastName = cipher.identity.lastName != null ? - cipher.identity.lastName.encryptedString : null; - this.identity.address1 = cipher.identity.address1 != null ? - cipher.identity.address1.encryptedString : null; - this.identity.address2 = cipher.identity.address2 != null ? - cipher.identity.address2.encryptedString : null; - this.identity.address3 = cipher.identity.address3 != null ? - cipher.identity.address3.encryptedString : null; - this.identity.city = cipher.identity.city != null ? cipher.identity.city.encryptedString : null; - this.identity.state = cipher.identity.state != null ? cipher.identity.state.encryptedString : null; - this.identity.postalCode = cipher.identity.postalCode != null ? - cipher.identity.postalCode.encryptedString : null; - this.identity.country = cipher.identity.country != null ? - cipher.identity.country.encryptedString : null; - this.identity.company = cipher.identity.company != null ? - cipher.identity.company.encryptedString : null; - this.identity.email = cipher.identity.email != null ? cipher.identity.email.encryptedString : null; - this.identity.phone = cipher.identity.phone != null ? cipher.identity.phone.encryptedString : null; - this.identity.ssn = cipher.identity.ssn != null ? cipher.identity.ssn.encryptedString : null; - this.identity.username = cipher.identity.username != null ? - cipher.identity.username.encryptedString : null; - this.identity.passportNumber = cipher.identity.passportNumber != null ? - cipher.identity.passportNumber.encryptedString : null; - this.identity.licenseNumber = cipher.identity.licenseNumber != null ? - cipher.identity.licenseNumber.encryptedString : null; - break; - default: - break; - } - - if (cipher.fields != null) { - this.fields = cipher.fields.map(f => { - const field = new FieldApi(); - field.type = f.type; - field.name = f.name ? f.name.encryptedString : null; - field.value = f.value ? f.value.encryptedString : null; - field.linkedId = f.linkedId; - return field; - }); - } - - if (cipher.passwordHistory != null) { - this.passwordHistory = []; - cipher.passwordHistory.forEach(ph => { - this.passwordHistory.push({ - lastUsedDate: ph.lastUsedDate, - password: ph.password ? ph.password.encryptedString : null, - }); - }); - } - - if (cipher.attachments != null) { - this.attachments = {}; - this.attachments2 = {}; - cipher.attachments.forEach(attachment => { - const fileName = attachment.fileName ? attachment.fileName.encryptedString : null; - this.attachments[attachment.id] = fileName; - const attachmentRequest = new AttachmentRequest(); - attachmentRequest.fileName = fileName; - if (attachment.key != null) { - attachmentRequest.key = attachment.key.encryptedString; - } - this.attachments2[attachment.id] = attachmentRequest; - }); + if (cipher.login.uris != null) { + this.login.uris = cipher.login.uris.map((u) => { + const uri = new LoginUriApi(); + uri.uri = u.uri != null ? u.uri.encryptedString : null; + uri.match = u.match != null ? u.match : null; + return uri; + }); } + break; + case CipherType.SecureNote: + this.secureNote = new SecureNoteApi(); + this.secureNote.type = cipher.secureNote.type; + break; + case CipherType.Card: + this.card = new CardApi(); + this.card.cardholderName = + cipher.card.cardholderName != null ? cipher.card.cardholderName.encryptedString : null; + this.card.brand = cipher.card.brand != null ? cipher.card.brand.encryptedString : null; + this.card.number = cipher.card.number != null ? cipher.card.number.encryptedString : null; + this.card.expMonth = + cipher.card.expMonth != null ? cipher.card.expMonth.encryptedString : null; + this.card.expYear = + cipher.card.expYear != null ? cipher.card.expYear.encryptedString : null; + this.card.code = cipher.card.code != null ? cipher.card.code.encryptedString : null; + break; + case CipherType.Identity: + this.identity = new IdentityApi(); + this.identity.title = + cipher.identity.title != null ? cipher.identity.title.encryptedString : null; + this.identity.firstName = + cipher.identity.firstName != null ? cipher.identity.firstName.encryptedString : null; + this.identity.middleName = + cipher.identity.middleName != null ? cipher.identity.middleName.encryptedString : null; + this.identity.lastName = + cipher.identity.lastName != null ? cipher.identity.lastName.encryptedString : null; + this.identity.address1 = + cipher.identity.address1 != null ? cipher.identity.address1.encryptedString : null; + this.identity.address2 = + cipher.identity.address2 != null ? cipher.identity.address2.encryptedString : null; + this.identity.address3 = + cipher.identity.address3 != null ? cipher.identity.address3.encryptedString : null; + this.identity.city = + cipher.identity.city != null ? cipher.identity.city.encryptedString : null; + this.identity.state = + cipher.identity.state != null ? cipher.identity.state.encryptedString : null; + this.identity.postalCode = + cipher.identity.postalCode != null ? cipher.identity.postalCode.encryptedString : null; + this.identity.country = + cipher.identity.country != null ? cipher.identity.country.encryptedString : null; + this.identity.company = + cipher.identity.company != null ? cipher.identity.company.encryptedString : null; + this.identity.email = + cipher.identity.email != null ? cipher.identity.email.encryptedString : null; + this.identity.phone = + cipher.identity.phone != null ? cipher.identity.phone.encryptedString : null; + this.identity.ssn = + cipher.identity.ssn != null ? cipher.identity.ssn.encryptedString : null; + this.identity.username = + cipher.identity.username != null ? cipher.identity.username.encryptedString : null; + this.identity.passportNumber = + cipher.identity.passportNumber != null + ? cipher.identity.passportNumber.encryptedString + : null; + this.identity.licenseNumber = + cipher.identity.licenseNumber != null + ? cipher.identity.licenseNumber.encryptedString + : null; + break; + default: + break; } + + if (cipher.fields != null) { + this.fields = cipher.fields.map((f) => { + const field = new FieldApi(); + field.type = f.type; + field.name = f.name ? f.name.encryptedString : null; + field.value = f.value ? f.value.encryptedString : null; + field.linkedId = f.linkedId; + return field; + }); + } + + if (cipher.passwordHistory != null) { + this.passwordHistory = []; + cipher.passwordHistory.forEach((ph) => { + this.passwordHistory.push({ + lastUsedDate: ph.lastUsedDate, + password: ph.password ? ph.password.encryptedString : null, + }); + }); + } + + if (cipher.attachments != null) { + this.attachments = {}; + this.attachments2 = {}; + cipher.attachments.forEach((attachment) => { + const fileName = attachment.fileName ? attachment.fileName.encryptedString : null; + this.attachments[attachment.id] = fileName; + const attachmentRequest = new AttachmentRequest(); + attachmentRequest.fileName = fileName; + if (attachment.key != null) { + attachmentRequest.key = attachment.key.encryptedString; + } + this.attachments2[attachment.id] = attachmentRequest; + }); + } + } } diff --git a/common/src/models/request/cipherShareRequest.ts b/common/src/models/request/cipherShareRequest.ts index 46468902..430e4ef8 100644 --- a/common/src/models/request/cipherShareRequest.ts +++ b/common/src/models/request/cipherShareRequest.ts @@ -1,13 +1,13 @@ -import { CipherRequest } from './cipherRequest'; +import { CipherRequest } from "./cipherRequest"; -import { Cipher } from '../domain/cipher'; +import { Cipher } from "../domain/cipher"; export class CipherShareRequest { - cipher: CipherRequest; - collectionIds: string[]; + cipher: CipherRequest; + collectionIds: string[]; - constructor(cipher: Cipher) { - this.cipher = new CipherRequest(cipher); - this.collectionIds = cipher.collectionIds; - } + constructor(cipher: Cipher) { + this.cipher = new CipherRequest(cipher); + this.collectionIds = cipher.collectionIds; + } } diff --git a/common/src/models/request/cipherWithIdRequest.ts b/common/src/models/request/cipherWithIdRequest.ts index a3d5e9d8..a722e4a9 100644 --- a/common/src/models/request/cipherWithIdRequest.ts +++ b/common/src/models/request/cipherWithIdRequest.ts @@ -1,12 +1,12 @@ -import { CipherRequest } from './cipherRequest'; +import { CipherRequest } from "./cipherRequest"; -import { Cipher } from '../domain/cipher'; +import { Cipher } from "../domain/cipher"; export class CipherWithIdRequest extends CipherRequest { - id: string; + id: string; - constructor(cipher: Cipher) { - super(cipher); - this.id = cipher.id; - } + constructor(cipher: Cipher) { + super(cipher); + this.id = cipher.id; + } } diff --git a/common/src/models/request/collectionRequest.ts b/common/src/models/request/collectionRequest.ts index 20f86956..c2176095 100644 --- a/common/src/models/request/collectionRequest.ts +++ b/common/src/models/request/collectionRequest.ts @@ -1,17 +1,17 @@ -import { Collection } from '../domain/collection'; +import { Collection } from "../domain/collection"; -import { SelectionReadOnlyRequest } from './selectionReadOnlyRequest'; +import { SelectionReadOnlyRequest } from "./selectionReadOnlyRequest"; export class CollectionRequest { - name: string; - externalId: string; - groups: SelectionReadOnlyRequest[] = []; + name: string; + externalId: string; + groups: SelectionReadOnlyRequest[] = []; - constructor(collection?: Collection) { - if (collection == null) { - return; - } - this.name = collection.name ? collection.name.encryptedString : null; - this.externalId = collection.externalId; + constructor(collection?: Collection) { + if (collection == null) { + return; } + this.name = collection.name ? collection.name.encryptedString : null; + this.externalId = collection.externalId; + } } diff --git a/common/src/models/request/deleteRecoverRequest.ts b/common/src/models/request/deleteRecoverRequest.ts index 90d6064f..02a019b8 100644 --- a/common/src/models/request/deleteRecoverRequest.ts +++ b/common/src/models/request/deleteRecoverRequest.ts @@ -1,3 +1,3 @@ export class DeleteRecoverRequest { - email: string; + email: string; } diff --git a/common/src/models/request/deviceRequest.ts b/common/src/models/request/deviceRequest.ts index 2aaa42cb..06da38a1 100644 --- a/common/src/models/request/deviceRequest.ts +++ b/common/src/models/request/deviceRequest.ts @@ -1,17 +1,17 @@ -import { DeviceType } from '../../enums/deviceType'; +import { DeviceType } from "../../enums/deviceType"; -import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; +import { PlatformUtilsService } from "../../abstractions/platformUtils.service"; export class DeviceRequest { - type: DeviceType; - name: string; - identifier: string; - pushToken?: string; + type: DeviceType; + name: string; + identifier: string; + pushToken?: string; - constructor(appId: string, platformUtilsService: PlatformUtilsService) { - this.type = platformUtilsService.getDevice(); - this.name = platformUtilsService.getDeviceString(); - this.identifier = appId; - this.pushToken = null; - } + constructor(appId: string, platformUtilsService: PlatformUtilsService) { + this.type = platformUtilsService.getDevice(); + this.name = platformUtilsService.getDeviceString(); + this.identifier = appId; + this.pushToken = null; + } } diff --git a/common/src/models/request/deviceTokenRequest.ts b/common/src/models/request/deviceTokenRequest.ts index 5d663f60..99ca69a2 100644 --- a/common/src/models/request/deviceTokenRequest.ts +++ b/common/src/models/request/deviceTokenRequest.ts @@ -1,7 +1,7 @@ export class DeviceTokenRequest { - pushToken: string; + pushToken: string; - constructor() { - this.pushToken = null; - } + constructor() { + this.pushToken = null; + } } diff --git a/common/src/models/request/emailRequest.ts b/common/src/models/request/emailRequest.ts index a2172a1e..0b559615 100644 --- a/common/src/models/request/emailRequest.ts +++ b/common/src/models/request/emailRequest.ts @@ -1,7 +1,7 @@ -import { EmailTokenRequest } from './emailTokenRequest'; +import { EmailTokenRequest } from "./emailTokenRequest"; export class EmailRequest extends EmailTokenRequest { - newMasterPasswordHash: string; - token: string; - key: string; + newMasterPasswordHash: string; + token: string; + key: string; } diff --git a/common/src/models/request/emailTokenRequest.ts b/common/src/models/request/emailTokenRequest.ts index 90a806b6..7e0515ca 100644 --- a/common/src/models/request/emailTokenRequest.ts +++ b/common/src/models/request/emailTokenRequest.ts @@ -1,6 +1,6 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class EmailTokenRequest extends SecretVerificationRequest { - newEmail: string; - masterPasswordHash: string; + newEmail: string; + masterPasswordHash: string; } diff --git a/common/src/models/request/emergencyAccessAcceptRequest.ts b/common/src/models/request/emergencyAccessAcceptRequest.ts index ff6f41c4..1cb10253 100644 --- a/common/src/models/request/emergencyAccessAcceptRequest.ts +++ b/common/src/models/request/emergencyAccessAcceptRequest.ts @@ -1,3 +1,3 @@ export class EmergencyAccessAcceptRequest { - token: string; + token: string; } diff --git a/common/src/models/request/emergencyAccessConfirmRequest.ts b/common/src/models/request/emergencyAccessConfirmRequest.ts index 5b138c84..ee54a4fe 100644 --- a/common/src/models/request/emergencyAccessConfirmRequest.ts +++ b/common/src/models/request/emergencyAccessConfirmRequest.ts @@ -1,3 +1,3 @@ export class EmergencyAccessConfirmRequest { - key: string; + key: string; } diff --git a/common/src/models/request/emergencyAccessInviteRequest.ts b/common/src/models/request/emergencyAccessInviteRequest.ts index f97620d5..d75ed419 100644 --- a/common/src/models/request/emergencyAccessInviteRequest.ts +++ b/common/src/models/request/emergencyAccessInviteRequest.ts @@ -1,7 +1,7 @@ -import { EmergencyAccessType } from '../../enums/emergencyAccessType'; +import { EmergencyAccessType } from "../../enums/emergencyAccessType"; export class EmergencyAccessInviteRequest { - email: string; - type: EmergencyAccessType; - waitTimeDays: number; + email: string; + type: EmergencyAccessType; + waitTimeDays: number; } diff --git a/common/src/models/request/emergencyAccessPasswordRequest.ts b/common/src/models/request/emergencyAccessPasswordRequest.ts index 9d95f86b..3fb459e1 100644 --- a/common/src/models/request/emergencyAccessPasswordRequest.ts +++ b/common/src/models/request/emergencyAccessPasswordRequest.ts @@ -1,4 +1,4 @@ export class EmergencyAccessPasswordRequest { - newMasterPasswordHash: string; - key: string; + newMasterPasswordHash: string; + key: string; } diff --git a/common/src/models/request/emergencyAccessUpdateRequest.ts b/common/src/models/request/emergencyAccessUpdateRequest.ts index ed535cb0..d7c55c94 100644 --- a/common/src/models/request/emergencyAccessUpdateRequest.ts +++ b/common/src/models/request/emergencyAccessUpdateRequest.ts @@ -1,7 +1,7 @@ -import { EmergencyAccessType } from '../../enums/emergencyAccessType'; +import { EmergencyAccessType } from "../../enums/emergencyAccessType"; export class EmergencyAccessUpdateRequest { - type: EmergencyAccessType; - waitTimeDays: number; - keyEncrypted?: string; + type: EmergencyAccessType; + waitTimeDays: number; + keyEncrypted?: string; } diff --git a/common/src/models/request/eventRequest.ts b/common/src/models/request/eventRequest.ts index 83bfa390..a6228fd6 100644 --- a/common/src/models/request/eventRequest.ts +++ b/common/src/models/request/eventRequest.ts @@ -1,7 +1,7 @@ -import { EventType } from '../../enums/eventType'; +import { EventType } from "../../enums/eventType"; export class EventRequest { - type: EventType; - cipherId: string; - date: string; + type: EventType; + cipherId: string; + date: string; } diff --git a/common/src/models/request/folderRequest.ts b/common/src/models/request/folderRequest.ts index 54ec76ca..a37f66dd 100644 --- a/common/src/models/request/folderRequest.ts +++ b/common/src/models/request/folderRequest.ts @@ -1,9 +1,9 @@ -import { Folder } from '../domain/folder'; +import { Folder } from "../domain/folder"; export class FolderRequest { - name: string; + name: string; - constructor(folder: Folder) { - this.name = folder.name ? folder.name.encryptedString : null; - } + constructor(folder: Folder) { + this.name = folder.name ? folder.name.encryptedString : null; + } } diff --git a/common/src/models/request/folderWithIdRequest.ts b/common/src/models/request/folderWithIdRequest.ts index a97ad6d8..1c83e73f 100644 --- a/common/src/models/request/folderWithIdRequest.ts +++ b/common/src/models/request/folderWithIdRequest.ts @@ -1,12 +1,12 @@ -import { FolderRequest } from './folderRequest'; +import { FolderRequest } from "./folderRequest"; -import { Folder } from '../domain/folder'; +import { Folder } from "../domain/folder"; export class FolderWithIdRequest extends FolderRequest { - id: string; + id: string; - constructor(folder: Folder) { - super(folder); - this.id = folder.id; - } + constructor(folder: Folder) { + super(folder); + this.id = folder.id; + } } diff --git a/common/src/models/request/groupRequest.ts b/common/src/models/request/groupRequest.ts index d3e18cf1..c4c349c8 100644 --- a/common/src/models/request/groupRequest.ts +++ b/common/src/models/request/groupRequest.ts @@ -1,8 +1,8 @@ -import { SelectionReadOnlyRequest } from './selectionReadOnlyRequest'; +import { SelectionReadOnlyRequest } from "./selectionReadOnlyRequest"; export class GroupRequest { - name: string; - accessAll: boolean; - externalId: string; - collections: SelectionReadOnlyRequest[] = []; + name: string; + accessAll: boolean; + externalId: string; + collections: SelectionReadOnlyRequest[] = []; } diff --git a/common/src/models/request/iapCheckRequest.ts b/common/src/models/request/iapCheckRequest.ts index 75ad723c..b8796e8c 100644 --- a/common/src/models/request/iapCheckRequest.ts +++ b/common/src/models/request/iapCheckRequest.ts @@ -1,5 +1,5 @@ -import { PaymentMethodType } from '../../enums/paymentMethodType'; +import { PaymentMethodType } from "../../enums/paymentMethodType"; export class IapCheckRequest { - paymentMethodType: PaymentMethodType; + paymentMethodType: PaymentMethodType; } diff --git a/common/src/models/request/importCiphersRequest.ts b/common/src/models/request/importCiphersRequest.ts index eec62602..ebaa03a3 100644 --- a/common/src/models/request/importCiphersRequest.ts +++ b/common/src/models/request/importCiphersRequest.ts @@ -1,9 +1,9 @@ -import { CipherRequest } from './cipherRequest'; -import { FolderRequest } from './folderRequest'; -import { KvpRequest } from './kvpRequest'; +import { CipherRequest } from "./cipherRequest"; +import { FolderRequest } from "./folderRequest"; +import { KvpRequest } from "./kvpRequest"; export class ImportCiphersRequest { - ciphers: CipherRequest[] = []; - folders: FolderRequest[] = []; - folderRelationships: KvpRequest[] = []; + ciphers: CipherRequest[] = []; + folders: FolderRequest[] = []; + folderRelationships: KvpRequest[] = []; } diff --git a/common/src/models/request/importDirectoryRequest.ts b/common/src/models/request/importDirectoryRequest.ts index 16bf69b9..a13ce456 100644 --- a/common/src/models/request/importDirectoryRequest.ts +++ b/common/src/models/request/importDirectoryRequest.ts @@ -1,9 +1,9 @@ -import { ImportDirectoryRequestGroup } from './importDirectoryRequestGroup'; -import { ImportDirectoryRequestUser } from './importDirectoryRequestUser'; +import { ImportDirectoryRequestGroup } from "./importDirectoryRequestGroup"; +import { ImportDirectoryRequestUser } from "./importDirectoryRequestUser"; export class ImportDirectoryRequest { - groups: ImportDirectoryRequestGroup[] = []; - users: ImportDirectoryRequestUser[] = []; - overwriteExisting = false; - largeImport = false; + groups: ImportDirectoryRequestGroup[] = []; + users: ImportDirectoryRequestUser[] = []; + overwriteExisting = false; + largeImport = false; } diff --git a/common/src/models/request/importDirectoryRequestGroup.ts b/common/src/models/request/importDirectoryRequestGroup.ts index 8e4f7f4a..4b7b3567 100644 --- a/common/src/models/request/importDirectoryRequestGroup.ts +++ b/common/src/models/request/importDirectoryRequestGroup.ts @@ -1,5 +1,5 @@ export class ImportDirectoryRequestGroup { - name: string; - externalId: string; - users: string[]; + name: string; + externalId: string; + users: string[]; } diff --git a/common/src/models/request/importDirectoryRequestUser.ts b/common/src/models/request/importDirectoryRequestUser.ts index 99d699e7..9dbf6a34 100644 --- a/common/src/models/request/importDirectoryRequestUser.ts +++ b/common/src/models/request/importDirectoryRequestUser.ts @@ -1,5 +1,5 @@ export class ImportDirectoryRequestUser { - externalId: string; - email: string; - deleted: boolean; + externalId: string; + email: string; + deleted: boolean; } diff --git a/common/src/models/request/importOrganizationCiphersRequest.ts b/common/src/models/request/importOrganizationCiphersRequest.ts index a19293c2..f2936afb 100644 --- a/common/src/models/request/importOrganizationCiphersRequest.ts +++ b/common/src/models/request/importOrganizationCiphersRequest.ts @@ -1,9 +1,9 @@ -import { CipherRequest } from './cipherRequest'; -import { CollectionRequest } from './collectionRequest'; -import { KvpRequest } from './kvpRequest'; +import { CipherRequest } from "./cipherRequest"; +import { CollectionRequest } from "./collectionRequest"; +import { KvpRequest } from "./kvpRequest"; export class ImportOrganizationCiphersRequest { - ciphers: CipherRequest[] = []; - collections: CollectionRequest[] = []; - collectionRelationships: KvpRequest[] = []; + ciphers: CipherRequest[] = []; + collections: CollectionRequest[] = []; + collectionRelationships: KvpRequest[] = []; } diff --git a/common/src/models/request/kdfRequest.ts b/common/src/models/request/kdfRequest.ts index 996aab0f..82a031b1 100644 --- a/common/src/models/request/kdfRequest.ts +++ b/common/src/models/request/kdfRequest.ts @@ -1,8 +1,8 @@ -import { PasswordRequest } from './passwordRequest'; +import { PasswordRequest } from "./passwordRequest"; -import { KdfType } from '../../enums/kdfType'; +import { KdfType } from "../../enums/kdfType"; export class KdfRequest extends PasswordRequest { - kdf: KdfType; - kdfIterations: number; + kdf: KdfType; + kdfIterations: number; } diff --git a/common/src/models/request/keyConnectorUserKeyRequest.ts b/common/src/models/request/keyConnectorUserKeyRequest.ts index 182de57f..3df2db82 100644 --- a/common/src/models/request/keyConnectorUserKeyRequest.ts +++ b/common/src/models/request/keyConnectorUserKeyRequest.ts @@ -1,7 +1,7 @@ export class KeyConnectorUserKeyRequest { - key: string; + key: string; - constructor(key: string) { - this.key = key; - } + constructor(key: string) { + this.key = key; + } } diff --git a/common/src/models/request/keysRequest.ts b/common/src/models/request/keysRequest.ts index 6ce11e8e..da4144e9 100644 --- a/common/src/models/request/keysRequest.ts +++ b/common/src/models/request/keysRequest.ts @@ -1,9 +1,9 @@ export class KeysRequest { - publicKey: string; - encryptedPrivateKey: string; + publicKey: string; + encryptedPrivateKey: string; - constructor(publicKey: string, encryptedPrivateKey: string) { - this.publicKey = publicKey; - this.encryptedPrivateKey = encryptedPrivateKey; - } + constructor(publicKey: string, encryptedPrivateKey: string) { + this.publicKey = publicKey; + this.encryptedPrivateKey = encryptedPrivateKey; + } } diff --git a/common/src/models/request/kvpRequest.ts b/common/src/models/request/kvpRequest.ts index 0611a4e0..ca37a85d 100644 --- a/common/src/models/request/kvpRequest.ts +++ b/common/src/models/request/kvpRequest.ts @@ -1,9 +1,9 @@ export class KvpRequest { - key: TK; - value: TV; + key: TK; + value: TV; - constructor(key: TK, value: TV) { - this.key = key; - this.value = value; - } + constructor(key: TK, value: TV) { + this.key = key; + this.value = value; + } } diff --git a/common/src/models/request/organization/organizationSponsorshipCreateRequest.ts b/common/src/models/request/organization/organizationSponsorshipCreateRequest.ts index 6dd8c267..7cc854b6 100644 --- a/common/src/models/request/organization/organizationSponsorshipCreateRequest.ts +++ b/common/src/models/request/organization/organizationSponsorshipCreateRequest.ts @@ -1,4 +1,4 @@ -import { PlanSponsorshipType } from '../../../enums/planSponsorshipType'; +import { PlanSponsorshipType } from "../../../enums/planSponsorshipType"; export class OrganizationSponsorshipCreateRequest { sponsoredEmail: string; diff --git a/common/src/models/request/organization/organizationSponsorshipRedeemRequest.ts b/common/src/models/request/organization/organizationSponsorshipRedeemRequest.ts index 7f325ea1..4c73836e 100644 --- a/common/src/models/request/organization/organizationSponsorshipRedeemRequest.ts +++ b/common/src/models/request/organization/organizationSponsorshipRedeemRequest.ts @@ -1,6 +1,6 @@ -import { PlanSponsorshipType } from '../../../enums/planSponsorshipType'; +import { PlanSponsorshipType } from "../../../enums/planSponsorshipType"; export class OrganizationSponsorshipRedeemRequest { - planSponsorshipType: PlanSponsorshipType; - sponsoredOrganizationId: string; + planSponsorshipType: PlanSponsorshipType; + sponsoredOrganizationId: string; } diff --git a/common/src/models/request/organization/organizationSsoRequest.ts b/common/src/models/request/organization/organizationSsoRequest.ts index 74afb318..8a2cbab9 100644 --- a/common/src/models/request/organization/organizationSsoRequest.ts +++ b/common/src/models/request/organization/organizationSsoRequest.ts @@ -1,6 +1,6 @@ -import { SsoConfigApi } from '../../api/ssoConfigApi'; +import { SsoConfigApi } from "../../api/ssoConfigApi"; export class OrganizationSsoRequest { - enabled: boolean = false; - data: SsoConfigApi; + enabled: boolean = false; + data: SsoConfigApi; } diff --git a/common/src/models/request/organizationCreateRequest.ts b/common/src/models/request/organizationCreateRequest.ts index 7be02660..db713d90 100644 --- a/common/src/models/request/organizationCreateRequest.ts +++ b/common/src/models/request/organizationCreateRequest.ts @@ -1,27 +1,27 @@ -import { PaymentMethodType } from '../../enums/paymentMethodType'; -import { PlanType } from '../../enums/planType'; +import { PaymentMethodType } from "../../enums/paymentMethodType"; +import { PlanType } from "../../enums/planType"; -import { OrganizationKeysRequest } from './organizationKeysRequest'; +import { OrganizationKeysRequest } from "./organizationKeysRequest"; export class OrganizationCreateRequest { - name: string; - businessName: string; - billingEmail: string; - planType: PlanType; - key: string; - keys: OrganizationKeysRequest; - paymentMethodType: PaymentMethodType; - paymentToken: string; - additionalSeats: number; - maxAutoscaleSeats: number; - additionalStorageGb: number; - premiumAccessAddon: boolean; - collectionName: string; - taxIdNumber: string; - billingAddressLine1: string; - billingAddressLine2: string; - billingAddressCity: string; - billingAddressState: string; - billingAddressPostalCode: string; - billingAddressCountry: string; + name: string; + businessName: string; + billingEmail: string; + planType: PlanType; + key: string; + keys: OrganizationKeysRequest; + paymentMethodType: PaymentMethodType; + paymentToken: string; + additionalSeats: number; + maxAutoscaleSeats: number; + additionalStorageGb: number; + premiumAccessAddon: boolean; + collectionName: string; + taxIdNumber: string; + billingAddressLine1: string; + billingAddressLine2: string; + billingAddressCity: string; + billingAddressState: string; + billingAddressPostalCode: string; + billingAddressCountry: string; } diff --git a/common/src/models/request/organizationImportGroupRequest.ts b/common/src/models/request/organizationImportGroupRequest.ts index 0cbb0faf..086ce653 100644 --- a/common/src/models/request/organizationImportGroupRequest.ts +++ b/common/src/models/request/organizationImportGroupRequest.ts @@ -1,19 +1,18 @@ -import { ImportDirectoryRequestGroup } from './importDirectoryRequestGroup'; +import { ImportDirectoryRequestGroup } from "./importDirectoryRequestGroup"; export class OrganizationImportGroupRequest { - name: string; - externalId: string; - memberExternalIds: string[]; + name: string; + externalId: string; + memberExternalIds: string[]; - constructor(model: Required | ImportDirectoryRequestGroup) { - this.name = model.name; - this.externalId = model.externalId; + constructor(model: Required | ImportDirectoryRequestGroup) { + this.name = model.name; + this.externalId = model.externalId; - if (model instanceof ImportDirectoryRequestGroup) { - this.memberExternalIds = model.users; - } - else { - this.memberExternalIds = model.memberExternalIds; - } + if (model instanceof ImportDirectoryRequestGroup) { + this.memberExternalIds = model.users; + } else { + this.memberExternalIds = model.memberExternalIds; } + } } diff --git a/common/src/models/request/organizationImportMemberRequest.ts b/common/src/models/request/organizationImportMemberRequest.ts index 78b09498..8161365c 100644 --- a/common/src/models/request/organizationImportMemberRequest.ts +++ b/common/src/models/request/organizationImportMemberRequest.ts @@ -1,13 +1,13 @@ -import { ImportDirectoryRequestUser } from './importDirectoryRequestUser'; +import { ImportDirectoryRequestUser } from "./importDirectoryRequestUser"; export class OrganizationImportMemberRequest { - email: string; - externalId: string; - deleted: boolean; + email: string; + externalId: string; + deleted: boolean; - constructor(model: Required | ImportDirectoryRequestUser) { - this.email = model.email; - this.externalId = model.externalId; - this.deleted = model.deleted; - } + constructor(model: Required | ImportDirectoryRequestUser) { + this.email = model.email; + this.externalId = model.externalId; + this.deleted = model.deleted; + } } diff --git a/common/src/models/request/organizationImportRequest.ts b/common/src/models/request/organizationImportRequest.ts index 6b1bc304..4ff23df7 100644 --- a/common/src/models/request/organizationImportRequest.ts +++ b/common/src/models/request/organizationImportRequest.ts @@ -1,25 +1,31 @@ -import { ImportDirectoryRequest } from './importDirectoryRequest'; -import { OrganizationImportGroupRequest } from './organizationImportGroupRequest'; -import { OrganizationImportMemberRequest } from './organizationImportMemberRequest'; +import { ImportDirectoryRequest } from "./importDirectoryRequest"; +import { OrganizationImportGroupRequest } from "./organizationImportGroupRequest"; +import { OrganizationImportMemberRequest } from "./organizationImportMemberRequest"; export class OrganizationImportRequest { - groups: OrganizationImportGroupRequest[] = []; - members: OrganizationImportMemberRequest[] = []; - overwriteExisting: boolean = false; - largeImport: boolean = false; + groups: OrganizationImportGroupRequest[] = []; + members: OrganizationImportMemberRequest[] = []; + overwriteExisting: boolean = false; + largeImport: boolean = false; - constructor(model: { - groups: Required[], - users: Required[], overwriteExisting: boolean, largeImport: boolean; - } | ImportDirectoryRequest) { - if (model instanceof ImportDirectoryRequest) { - this.groups = model.groups.map(g => new OrganizationImportGroupRequest(g)); - this.members = model.users.map(u => new OrganizationImportMemberRequest(u)); - } else { - this.groups = model.groups.map(g => new OrganizationImportGroupRequest(g)); - this.members = model.users.map(u => new OrganizationImportMemberRequest(u)); + constructor( + model: + | { + groups: Required[]; + users: Required[]; + overwriteExisting: boolean; + largeImport: boolean; } - this.overwriteExisting = model.overwriteExisting; - this.largeImport = model.largeImport; + | ImportDirectoryRequest + ) { + if (model instanceof ImportDirectoryRequest) { + this.groups = model.groups.map((g) => new OrganizationImportGroupRequest(g)); + this.members = model.users.map((u) => new OrganizationImportMemberRequest(u)); + } else { + this.groups = model.groups.map((g) => new OrganizationImportGroupRequest(g)); + this.members = model.users.map((u) => new OrganizationImportMemberRequest(u)); } + this.overwriteExisting = model.overwriteExisting; + this.largeImport = model.largeImport; + } } diff --git a/common/src/models/request/organizationKeysRequest.ts b/common/src/models/request/organizationKeysRequest.ts index 932f28ce..c63e05ab 100644 --- a/common/src/models/request/organizationKeysRequest.ts +++ b/common/src/models/request/organizationKeysRequest.ts @@ -1,7 +1,7 @@ -import { KeysRequest } from './keysRequest'; +import { KeysRequest } from "./keysRequest"; export class OrganizationKeysRequest extends KeysRequest { - constructor(publicKey: string, encryptedPrivateKey: string) { - super(publicKey, encryptedPrivateKey); - } + constructor(publicKey: string, encryptedPrivateKey: string) { + super(publicKey, encryptedPrivateKey); + } } diff --git a/common/src/models/request/organizationSubscriptionUpdateRequest.ts b/common/src/models/request/organizationSubscriptionUpdateRequest.ts index 85ea6f4f..9db3d4be 100644 --- a/common/src/models/request/organizationSubscriptionUpdateRequest.ts +++ b/common/src/models/request/organizationSubscriptionUpdateRequest.ts @@ -1,3 +1,3 @@ export class OrganizationSubscriptionUpdateRequest { - constructor(public seatAdjustment: number, public maxAutoscaleSeats?: number) { } + constructor(public seatAdjustment: number, public maxAutoscaleSeats?: number) {} } diff --git a/common/src/models/request/organizationTaxInfoUpdateRequest.ts b/common/src/models/request/organizationTaxInfoUpdateRequest.ts index 73df4ad5..283151f4 100644 --- a/common/src/models/request/organizationTaxInfoUpdateRequest.ts +++ b/common/src/models/request/organizationTaxInfoUpdateRequest.ts @@ -1,9 +1,9 @@ -import { TaxInfoUpdateRequest } from './taxInfoUpdateRequest'; +import { TaxInfoUpdateRequest } from "./taxInfoUpdateRequest"; export class OrganizationTaxInfoUpdateRequest extends TaxInfoUpdateRequest { - taxId: string; - line1: string; - line2: string; - city: string; - state: string; + taxId: string; + line1: string; + line2: string; + city: string; + state: string; } diff --git a/common/src/models/request/organizationUpdateRequest.ts b/common/src/models/request/organizationUpdateRequest.ts index 6e20b671..faddf641 100644 --- a/common/src/models/request/organizationUpdateRequest.ts +++ b/common/src/models/request/organizationUpdateRequest.ts @@ -1,9 +1,9 @@ -import { OrganizationKeysRequest } from './organizationKeysRequest'; +import { OrganizationKeysRequest } from "./organizationKeysRequest"; export class OrganizationUpdateRequest { - name: string; - identifier: string; - businessName: string; - billingEmail: string; - keys: OrganizationKeysRequest; + name: string; + identifier: string; + businessName: string; + billingEmail: string; + keys: OrganizationKeysRequest; } diff --git a/common/src/models/request/organizationUpgradeRequest.ts b/common/src/models/request/organizationUpgradeRequest.ts index 1000e19e..b62976fa 100644 --- a/common/src/models/request/organizationUpgradeRequest.ts +++ b/common/src/models/request/organizationUpgradeRequest.ts @@ -1,14 +1,14 @@ -import { PlanType } from '../../enums/planType'; +import { PlanType } from "../../enums/planType"; -import { OrganizationKeysRequest } from './organizationKeysRequest'; +import { OrganizationKeysRequest } from "./organizationKeysRequest"; export class OrganizationUpgradeRequest { - businessName: string; - planType: PlanType; - additionalSeats: number; - additionalStorageGb: number; - premiumAccessAddon: boolean; - billingAddressCountry: string; - billingAddressPostalCode: string; - keys: OrganizationKeysRequest; + businessName: string; + planType: PlanType; + additionalSeats: number; + additionalStorageGb: number; + premiumAccessAddon: boolean; + billingAddressCountry: string; + billingAddressPostalCode: string; + keys: OrganizationKeysRequest; } diff --git a/common/src/models/request/organizationUserAcceptRequest.ts b/common/src/models/request/organizationUserAcceptRequest.ts index acd36a67..c4b2a4d3 100644 --- a/common/src/models/request/organizationUserAcceptRequest.ts +++ b/common/src/models/request/organizationUserAcceptRequest.ts @@ -1,3 +1,3 @@ export class OrganizationUserAcceptRequest { - token: string; + token: string; } diff --git a/common/src/models/request/organizationUserBulkConfirmRequest.ts b/common/src/models/request/organizationUserBulkConfirmRequest.ts index 8412baed..35e05602 100644 --- a/common/src/models/request/organizationUserBulkConfirmRequest.ts +++ b/common/src/models/request/organizationUserBulkConfirmRequest.ts @@ -1,12 +1,12 @@ type OrganizationUserBulkRequestEntry = { - id: string; - key: string; + id: string; + key: string; }; export class OrganizationUserBulkConfirmRequest { - keys: OrganizationUserBulkRequestEntry[]; + keys: OrganizationUserBulkRequestEntry[]; - constructor(keys: OrganizationUserBulkRequestEntry[]) { - this.keys = keys; - } + constructor(keys: OrganizationUserBulkRequestEntry[]) { + this.keys = keys; + } } diff --git a/common/src/models/request/organizationUserBulkRequest.ts b/common/src/models/request/organizationUserBulkRequest.ts index 4b92620c..c73800eb 100644 --- a/common/src/models/request/organizationUserBulkRequest.ts +++ b/common/src/models/request/organizationUserBulkRequest.ts @@ -1,7 +1,7 @@ export class OrganizationUserBulkRequest { - ids: string[]; + ids: string[]; - constructor(ids: string[]) { - this.ids = ids == null ? [] : ids; - } + constructor(ids: string[]) { + this.ids = ids == null ? [] : ids; + } } diff --git a/common/src/models/request/organizationUserConfirmRequest.ts b/common/src/models/request/organizationUserConfirmRequest.ts index c4d23305..abd48749 100644 --- a/common/src/models/request/organizationUserConfirmRequest.ts +++ b/common/src/models/request/organizationUserConfirmRequest.ts @@ -1,3 +1,3 @@ export class OrganizationUserConfirmRequest { - key: string; + key: string; } diff --git a/common/src/models/request/organizationUserInviteRequest.ts b/common/src/models/request/organizationUserInviteRequest.ts index 4195eec8..5c4046af 100644 --- a/common/src/models/request/organizationUserInviteRequest.ts +++ b/common/src/models/request/organizationUserInviteRequest.ts @@ -1,12 +1,12 @@ -import { SelectionReadOnlyRequest } from './selectionReadOnlyRequest'; +import { SelectionReadOnlyRequest } from "./selectionReadOnlyRequest"; -import { OrganizationUserType } from '../../enums/organizationUserType'; -import { PermissionsApi } from '../api/permissionsApi'; +import { OrganizationUserType } from "../../enums/organizationUserType"; +import { PermissionsApi } from "../api/permissionsApi"; export class OrganizationUserInviteRequest { - emails: string[] = []; - type: OrganizationUserType; - accessAll: boolean; - collections: SelectionReadOnlyRequest[] = []; - permissions: PermissionsApi; + emails: string[] = []; + type: OrganizationUserType; + accessAll: boolean; + collections: SelectionReadOnlyRequest[] = []; + permissions: PermissionsApi; } diff --git a/common/src/models/request/organizationUserResetPasswordEnrollmentRequest.ts b/common/src/models/request/organizationUserResetPasswordEnrollmentRequest.ts index d017c4a6..8d88164d 100644 --- a/common/src/models/request/organizationUserResetPasswordEnrollmentRequest.ts +++ b/common/src/models/request/organizationUserResetPasswordEnrollmentRequest.ts @@ -1,3 +1,3 @@ export class OrganizationUserResetPasswordEnrollmentRequest { - resetPasswordKey: string; + resetPasswordKey: string; } diff --git a/common/src/models/request/organizationUserResetPasswordRequest.ts b/common/src/models/request/organizationUserResetPasswordRequest.ts index 7e0b1bdb..b0c4e483 100644 --- a/common/src/models/request/organizationUserResetPasswordRequest.ts +++ b/common/src/models/request/organizationUserResetPasswordRequest.ts @@ -1,4 +1,4 @@ export class OrganizationUserResetPasswordRequest { - newMasterPasswordHash: string; - key: string; + newMasterPasswordHash: string; + key: string; } diff --git a/common/src/models/request/organizationUserUpdateGroupsRequest.ts b/common/src/models/request/organizationUserUpdateGroupsRequest.ts index 0d7805cc..cd30d940 100644 --- a/common/src/models/request/organizationUserUpdateGroupsRequest.ts +++ b/common/src/models/request/organizationUserUpdateGroupsRequest.ts @@ -1,3 +1,3 @@ export class OrganizationUserUpdateGroupsRequest { - groupIds: string[] = []; + groupIds: string[] = []; } diff --git a/common/src/models/request/organizationUserUpdateRequest.ts b/common/src/models/request/organizationUserUpdateRequest.ts index 80803cd6..2bd9dd62 100644 --- a/common/src/models/request/organizationUserUpdateRequest.ts +++ b/common/src/models/request/organizationUserUpdateRequest.ts @@ -1,11 +1,11 @@ -import { SelectionReadOnlyRequest } from './selectionReadOnlyRequest'; +import { SelectionReadOnlyRequest } from "./selectionReadOnlyRequest"; -import { OrganizationUserType } from '../../enums/organizationUserType'; -import { PermissionsApi } from '../api/permissionsApi'; +import { OrganizationUserType } from "../../enums/organizationUserType"; +import { PermissionsApi } from "../api/permissionsApi"; export class OrganizationUserUpdateRequest { - type: OrganizationUserType; - accessAll: boolean; - collections: SelectionReadOnlyRequest[] = []; - permissions: PermissionsApi; + type: OrganizationUserType; + accessAll: boolean; + collections: SelectionReadOnlyRequest[] = []; + permissions: PermissionsApi; } diff --git a/common/src/models/request/passwordHintRequest.ts b/common/src/models/request/passwordHintRequest.ts index 35b37f4f..7182e05e 100644 --- a/common/src/models/request/passwordHintRequest.ts +++ b/common/src/models/request/passwordHintRequest.ts @@ -1,7 +1,7 @@ export class PasswordHintRequest { - email: string; + email: string; - constructor(email: string) { - this.email = email; - } + constructor(email: string) { + this.email = email; + } } diff --git a/common/src/models/request/passwordHistoryRequest.ts b/common/src/models/request/passwordHistoryRequest.ts index 7b74cb12..6cca2b86 100644 --- a/common/src/models/request/passwordHistoryRequest.ts +++ b/common/src/models/request/passwordHistoryRequest.ts @@ -1,4 +1,4 @@ export class PasswordHistoryRequest { - password: string; - lastUsedDate: Date; + password: string; + lastUsedDate: Date; } diff --git a/common/src/models/request/passwordRequest.ts b/common/src/models/request/passwordRequest.ts index 0d639a09..9f7df7df 100644 --- a/common/src/models/request/passwordRequest.ts +++ b/common/src/models/request/passwordRequest.ts @@ -1,6 +1,6 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class PasswordRequest extends SecretVerificationRequest { - newMasterPasswordHash: string; - key: string; + newMasterPasswordHash: string; + key: string; } diff --git a/common/src/models/request/paymentRequest.ts b/common/src/models/request/paymentRequest.ts index e3d420ea..8e7f70a1 100644 --- a/common/src/models/request/paymentRequest.ts +++ b/common/src/models/request/paymentRequest.ts @@ -1,7 +1,7 @@ -import { PaymentMethodType } from '../../enums/paymentMethodType'; -import { OrganizationTaxInfoUpdateRequest } from '../request/organizationTaxInfoUpdateRequest'; +import { PaymentMethodType } from "../../enums/paymentMethodType"; +import { OrganizationTaxInfoUpdateRequest } from "../request/organizationTaxInfoUpdateRequest"; export class PaymentRequest extends OrganizationTaxInfoUpdateRequest { - paymentMethodType: PaymentMethodType; - paymentToken: string; + paymentMethodType: PaymentMethodType; + paymentToken: string; } diff --git a/common/src/models/request/policyRequest.ts b/common/src/models/request/policyRequest.ts index a1314d08..98b05912 100644 --- a/common/src/models/request/policyRequest.ts +++ b/common/src/models/request/policyRequest.ts @@ -1,7 +1,7 @@ -import { PolicyType } from '../../enums/policyType'; +import { PolicyType } from "../../enums/policyType"; export class PolicyRequest { - type: PolicyType; - enabled: boolean; - data: any; + type: PolicyType; + enabled: boolean; + data: any; } diff --git a/common/src/models/request/preloginRequest.ts b/common/src/models/request/preloginRequest.ts index bee6058c..689204b7 100644 --- a/common/src/models/request/preloginRequest.ts +++ b/common/src/models/request/preloginRequest.ts @@ -1,7 +1,7 @@ export class PreloginRequest { - email: string; + email: string; - constructor(email: string) { - this.email = email; - } + constructor(email: string) { + this.email = email; + } } diff --git a/common/src/models/request/provider/providerAddOrganizationRequest.ts b/common/src/models/request/provider/providerAddOrganizationRequest.ts index ebdd1bc6..380eea1d 100644 --- a/common/src/models/request/provider/providerAddOrganizationRequest.ts +++ b/common/src/models/request/provider/providerAddOrganizationRequest.ts @@ -1,4 +1,4 @@ export class ProviderAddOrganizationRequest { - organizationId: string; - key: string; + organizationId: string; + key: string; } diff --git a/common/src/models/request/provider/providerOrganizationCreateRequest.ts b/common/src/models/request/provider/providerOrganizationCreateRequest.ts index e116de6a..8d02f530 100644 --- a/common/src/models/request/provider/providerOrganizationCreateRequest.ts +++ b/common/src/models/request/provider/providerOrganizationCreateRequest.ts @@ -1,5 +1,8 @@ -import { OrganizationCreateRequest } from '../organizationCreateRequest'; +import { OrganizationCreateRequest } from "../organizationCreateRequest"; export class ProviderOrganizationCreateRequest { - constructor(public clientOwnerEmail: string, public organizationCreateRequest: OrganizationCreateRequest) { } + constructor( + public clientOwnerEmail: string, + public organizationCreateRequest: OrganizationCreateRequest + ) {} } diff --git a/common/src/models/request/provider/providerSetupRequest.ts b/common/src/models/request/provider/providerSetupRequest.ts index 5063fec0..61eb943f 100644 --- a/common/src/models/request/provider/providerSetupRequest.ts +++ b/common/src/models/request/provider/providerSetupRequest.ts @@ -1,7 +1,7 @@ export class ProviderSetupRequest { - name: string; - businessName: string; - billingEmail: string; - token: string; - key: string; + name: string; + businessName: string; + billingEmail: string; + token: string; + key: string; } diff --git a/common/src/models/request/provider/providerUpdateRequest.ts b/common/src/models/request/provider/providerUpdateRequest.ts index d30e6346..dafa7418 100644 --- a/common/src/models/request/provider/providerUpdateRequest.ts +++ b/common/src/models/request/provider/providerUpdateRequest.ts @@ -1,5 +1,5 @@ export class ProviderUpdateRequest { - name: string; - businessName: string; - billingEmail: string; + name: string; + businessName: string; + billingEmail: string; } diff --git a/common/src/models/request/provider/providerUserAcceptRequest.ts b/common/src/models/request/provider/providerUserAcceptRequest.ts index 15e0370b..0435e1df 100644 --- a/common/src/models/request/provider/providerUserAcceptRequest.ts +++ b/common/src/models/request/provider/providerUserAcceptRequest.ts @@ -1,3 +1,3 @@ export class ProviderUserAcceptRequest { - token: string; + token: string; } diff --git a/common/src/models/request/provider/providerUserBulkConfirmRequest.ts b/common/src/models/request/provider/providerUserBulkConfirmRequest.ts index cb5a252c..76628b09 100644 --- a/common/src/models/request/provider/providerUserBulkConfirmRequest.ts +++ b/common/src/models/request/provider/providerUserBulkConfirmRequest.ts @@ -1,12 +1,12 @@ type ProviderUserBulkRequestEntry = { - id: string; - key: string; + id: string; + key: string; }; export class ProviderUserBulkConfirmRequest { - keys: ProviderUserBulkRequestEntry[]; + keys: ProviderUserBulkRequestEntry[]; - constructor(keys: ProviderUserBulkRequestEntry[]) { - this.keys = keys; - } + constructor(keys: ProviderUserBulkRequestEntry[]) { + this.keys = keys; + } } diff --git a/common/src/models/request/provider/providerUserBulkRequest.ts b/common/src/models/request/provider/providerUserBulkRequest.ts index e676b1f8..f45ed1bb 100644 --- a/common/src/models/request/provider/providerUserBulkRequest.ts +++ b/common/src/models/request/provider/providerUserBulkRequest.ts @@ -1,7 +1,7 @@ export class ProviderUserBulkRequest { - ids: string[]; + ids: string[]; - constructor(ids: string[]) { - this.ids = ids == null ? [] : ids; - } + constructor(ids: string[]) { + this.ids = ids == null ? [] : ids; + } } diff --git a/common/src/models/request/provider/providerUserConfirmRequest.ts b/common/src/models/request/provider/providerUserConfirmRequest.ts index 8d7203d6..1b7d4a06 100644 --- a/common/src/models/request/provider/providerUserConfirmRequest.ts +++ b/common/src/models/request/provider/providerUserConfirmRequest.ts @@ -1,3 +1,3 @@ export class ProviderUserConfirmRequest { - key: string; + key: string; } diff --git a/common/src/models/request/provider/providerUserInviteRequest.ts b/common/src/models/request/provider/providerUserInviteRequest.ts index d8daedd2..65d8ba67 100644 --- a/common/src/models/request/provider/providerUserInviteRequest.ts +++ b/common/src/models/request/provider/providerUserInviteRequest.ts @@ -1,6 +1,6 @@ -import { ProviderUserType } from '../../../enums/providerUserType'; +import { ProviderUserType } from "../../../enums/providerUserType"; export class ProviderUserInviteRequest { - emails: string[] = []; - type: ProviderUserType; + emails: string[] = []; + type: ProviderUserType; } diff --git a/common/src/models/request/provider/providerUserUpdateRequest.ts b/common/src/models/request/provider/providerUserUpdateRequest.ts index 77519e24..25efdd89 100644 --- a/common/src/models/request/provider/providerUserUpdateRequest.ts +++ b/common/src/models/request/provider/providerUserUpdateRequest.ts @@ -1,5 +1,5 @@ -import { ProviderUserType } from '../../../enums/providerUserType'; +import { ProviderUserType } from "../../../enums/providerUserType"; export class ProviderUserUpdateRequest { - type: ProviderUserType; + type: ProviderUserType; } diff --git a/common/src/models/request/referenceEventRequest.ts b/common/src/models/request/referenceEventRequest.ts index 4cd8c507..7a0b535a 100644 --- a/common/src/models/request/referenceEventRequest.ts +++ b/common/src/models/request/referenceEventRequest.ts @@ -1,5 +1,5 @@ export class ReferenceEventRequest { - id: string; - layout: string; - flow: string; + id: string; + layout: string; + flow: string; } diff --git a/common/src/models/request/registerRequest.ts b/common/src/models/request/registerRequest.ts index 04f06b49..5c53ce59 100644 --- a/common/src/models/request/registerRequest.ts +++ b/common/src/models/request/registerRequest.ts @@ -1,20 +1,27 @@ -import { KeysRequest } from './keysRequest'; -import { ReferenceEventRequest } from './referenceEventRequest'; +import { KeysRequest } from "./keysRequest"; +import { ReferenceEventRequest } from "./referenceEventRequest"; -import { KdfType } from '../../enums/kdfType'; +import { KdfType } from "../../enums/kdfType"; -import { CaptchaProtectedRequest } from './captchaProtectedRequest'; +import { CaptchaProtectedRequest } from "./captchaProtectedRequest"; export class RegisterRequest implements CaptchaProtectedRequest { - masterPasswordHint: string; - keys: KeysRequest; - token: string; - organizationUserId: string; + masterPasswordHint: string; + keys: KeysRequest; + token: string; + organizationUserId: string; - - constructor(public email: string, public name: string, public masterPasswordHash: string, - masterPasswordHint: string, public key: string, public kdf: KdfType, public kdfIterations: number, - public referenceData: ReferenceEventRequest, public captchaResponse: string) { - this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null; - } + constructor( + public email: string, + public name: string, + public masterPasswordHash: string, + masterPasswordHint: string, + public key: string, + public kdf: KdfType, + public kdfIterations: number, + public referenceData: ReferenceEventRequest, + public captchaResponse: string + ) { + this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null; + } } diff --git a/common/src/models/request/seatRequest.ts b/common/src/models/request/seatRequest.ts index 92d47669..d60e41fa 100644 --- a/common/src/models/request/seatRequest.ts +++ b/common/src/models/request/seatRequest.ts @@ -1,3 +1,3 @@ export class SeatRequest { - seatAdjustment: number; + seatAdjustment: number; } diff --git a/common/src/models/request/secretVerificationRequest.ts b/common/src/models/request/secretVerificationRequest.ts index 554aa1c6..c0170a3e 100644 --- a/common/src/models/request/secretVerificationRequest.ts +++ b/common/src/models/request/secretVerificationRequest.ts @@ -1,4 +1,4 @@ export class SecretVerificationRequest { - masterPasswordHash: string; - otp: string; + masterPasswordHash: string; + otp: string; } diff --git a/common/src/models/request/selectionReadOnlyRequest.ts b/common/src/models/request/selectionReadOnlyRequest.ts index d001edb2..7b007324 100644 --- a/common/src/models/request/selectionReadOnlyRequest.ts +++ b/common/src/models/request/selectionReadOnlyRequest.ts @@ -1,11 +1,11 @@ export class SelectionReadOnlyRequest { - id: string; - readOnly: boolean; - hidePasswords: boolean; + id: string; + readOnly: boolean; + hidePasswords: boolean; - constructor(id: string, readOnly: boolean, hidePasswords: boolean) { - this.id = id; - this.readOnly = readOnly; - this.hidePasswords = hidePasswords; - } + constructor(id: string, readOnly: boolean, hidePasswords: boolean) { + this.id = id; + this.readOnly = readOnly; + this.hidePasswords = hidePasswords; + } } diff --git a/common/src/models/request/sendAccessRequest.ts b/common/src/models/request/sendAccessRequest.ts index 3d49c0c2..7607b03c 100644 --- a/common/src/models/request/sendAccessRequest.ts +++ b/common/src/models/request/sendAccessRequest.ts @@ -1,3 +1,3 @@ export class SendAccessRequest { - password: string; + password: string; } diff --git a/common/src/models/request/sendRequest.ts b/common/src/models/request/sendRequest.ts index 5e5861f0..6fa481ee 100644 --- a/common/src/models/request/sendRequest.ts +++ b/common/src/models/request/sendRequest.ts @@ -1,50 +1,50 @@ -import { SendType } from '../../enums/sendType'; +import { SendType } from "../../enums/sendType"; -import { SendFileApi } from '../api/sendFileApi'; -import { SendTextApi } from '../api/sendTextApi'; +import { SendFileApi } from "../api/sendFileApi"; +import { SendTextApi } from "../api/sendTextApi"; -import { Send } from '../domain/send'; +import { Send } from "../domain/send"; export class SendRequest { - type: SendType; - fileLength?: number; - name: string; - notes: string; - key: string; - maxAccessCount?: number; - expirationDate: string; - deletionDate: string; - text: SendTextApi; - file: SendFileApi; - password: string; - disabled: boolean; - hideEmail: boolean; + type: SendType; + fileLength?: number; + name: string; + notes: string; + key: string; + maxAccessCount?: number; + expirationDate: string; + deletionDate: string; + text: SendTextApi; + file: SendFileApi; + password: string; + disabled: boolean; + hideEmail: boolean; - constructor(send: Send, fileLength?: number) { - this.type = send.type; - this.fileLength = fileLength; - this.name = send.name ? send.name.encryptedString : null; - this.notes = send.notes ? send.notes.encryptedString : null; - this.maxAccessCount = send.maxAccessCount; - this.expirationDate = send.expirationDate != null ? send.expirationDate.toISOString() : null; - this.deletionDate = send.deletionDate != null ? send.deletionDate.toISOString() : null; - this.key = send.key != null ? send.key.encryptedString : null; - this.password = send.password; - this.disabled = send.disabled; - this.hideEmail = send.hideEmail; + constructor(send: Send, fileLength?: number) { + this.type = send.type; + this.fileLength = fileLength; + this.name = send.name ? send.name.encryptedString : null; + this.notes = send.notes ? send.notes.encryptedString : null; + this.maxAccessCount = send.maxAccessCount; + this.expirationDate = send.expirationDate != null ? send.expirationDate.toISOString() : null; + this.deletionDate = send.deletionDate != null ? send.deletionDate.toISOString() : null; + this.key = send.key != null ? send.key.encryptedString : null; + this.password = send.password; + this.disabled = send.disabled; + this.hideEmail = send.hideEmail; - switch (this.type) { - case SendType.Text: - this.text = new SendTextApi(); - this.text.text = send.text.text != null ? send.text.text.encryptedString : null; - this.text.hidden = send.text.hidden; - break; - case SendType.File: - this.file = new SendFileApi(); - this.file.fileName = send.file.fileName != null ? send.file.fileName.encryptedString : null; - break; - default: - break; - } + switch (this.type) { + case SendType.Text: + this.text = new SendTextApi(); + this.text.text = send.text.text != null ? send.text.text.encryptedString : null; + this.text.hidden = send.text.hidden; + break; + case SendType.File: + this.file = new SendFileApi(); + this.file.fileName = send.file.fileName != null ? send.file.fileName.encryptedString : null; + break; + default: + break; } + } } diff --git a/common/src/models/request/sendWithIdRequest.ts b/common/src/models/request/sendWithIdRequest.ts index 277cfa48..903151e3 100644 --- a/common/src/models/request/sendWithIdRequest.ts +++ b/common/src/models/request/sendWithIdRequest.ts @@ -1,12 +1,12 @@ -import { SendRequest } from './sendRequest'; +import { SendRequest } from "./sendRequest"; -import { Send } from '../domain/send'; +import { Send } from "../domain/send"; export class SendWithIdRequest extends SendRequest { - id: string; + id: string; - constructor(send: Send) { - super(send); - this.id = send.id; - } + constructor(send: Send) { + super(send); + this.id = send.id; + } } diff --git a/common/src/models/request/setPasswordRequest.ts b/common/src/models/request/setPasswordRequest.ts index 70c77e62..de3b8489 100644 --- a/common/src/models/request/setPasswordRequest.ts +++ b/common/src/models/request/setPasswordRequest.ts @@ -1,24 +1,31 @@ -import { KeysRequest } from './keysRequest'; +import { KeysRequest } from "./keysRequest"; -import { KdfType } from '../../enums/kdfType'; +import { KdfType } from "../../enums/kdfType"; export class SetPasswordRequest { - masterPasswordHash: string; - key: string; - masterPasswordHint: string; - keys: KeysRequest; - kdf: KdfType; - kdfIterations: number; - orgIdentifier: string; + masterPasswordHash: string; + key: string; + masterPasswordHint: string; + keys: KeysRequest; + kdf: KdfType; + kdfIterations: number; + orgIdentifier: string; - constructor(masterPasswordHash: string, key: string, masterPasswordHint: string, kdf: KdfType, - kdfIterations: number, orgIdentifier: string, keys: KeysRequest) { - this.masterPasswordHash = masterPasswordHash; - this.key = key; - this.masterPasswordHint = masterPasswordHint; - this.kdf = kdf; - this.kdfIterations = kdfIterations; - this.orgIdentifier = orgIdentifier; - this.keys = keys; - } + constructor( + masterPasswordHash: string, + key: string, + masterPasswordHint: string, + kdf: KdfType, + kdfIterations: number, + orgIdentifier: string, + keys: KeysRequest + ) { + this.masterPasswordHash = masterPasswordHash; + this.key = key; + this.masterPasswordHint = masterPasswordHint; + this.kdf = kdf; + this.kdfIterations = kdfIterations; + this.orgIdentifier = orgIdentifier; + this.keys = keys; + } } diff --git a/common/src/models/request/storageRequest.ts b/common/src/models/request/storageRequest.ts index f4b78559..4b3b614d 100644 --- a/common/src/models/request/storageRequest.ts +++ b/common/src/models/request/storageRequest.ts @@ -1,3 +1,3 @@ export class StorageRequest { - storageGbAdjustment: number; + storageGbAdjustment: number; } diff --git a/common/src/models/request/taxInfoUpdateRequest.ts b/common/src/models/request/taxInfoUpdateRequest.ts index 5485164e..6881a8a4 100644 --- a/common/src/models/request/taxInfoUpdateRequest.ts +++ b/common/src/models/request/taxInfoUpdateRequest.ts @@ -1,4 +1,4 @@ export class TaxInfoUpdateRequest { - country: string; - postalCode: string; + country: string; + postalCode: string; } diff --git a/common/src/models/request/tokenRequest.ts b/common/src/models/request/tokenRequest.ts index 41797eb0..43e344ae 100644 --- a/common/src/models/request/tokenRequest.ts +++ b/common/src/models/request/tokenRequest.ts @@ -1,84 +1,91 @@ -import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; +import { TwoFactorProviderType } from "../../enums/twoFactorProviderType"; -import { CaptchaProtectedRequest } from './captchaProtectedRequest'; -import { DeviceRequest } from './deviceRequest'; +import { CaptchaProtectedRequest } from "./captchaProtectedRequest"; +import { DeviceRequest } from "./deviceRequest"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; export class TokenRequest implements CaptchaProtectedRequest { - email: string; - masterPasswordHash: string; - code: string; - codeVerifier: string; - redirectUri: string; - clientId: string; - clientSecret: string; - device?: DeviceRequest; + email: string; + masterPasswordHash: string; + code: string; + codeVerifier: string; + redirectUri: string; + clientId: string; + clientSecret: string; + device?: DeviceRequest; - constructor(credentials: string[], codes: string[], clientIdClientSecret: string[], public provider: TwoFactorProviderType, - public token: string, public remember: boolean, public captchaResponse: string, device?: DeviceRequest) { - if (credentials != null && credentials.length > 1) { - this.email = credentials[0]; - this.masterPasswordHash = credentials[1]; - } else if (codes != null && codes.length > 2) { - this.code = codes[0]; - this.codeVerifier = codes[1]; - this.redirectUri = codes[2]; - } else if (clientIdClientSecret != null && clientIdClientSecret.length > 1) { - this.clientId = clientIdClientSecret[0]; - this.clientSecret = clientIdClientSecret[1]; - } - this.device = device != null ? device : null; + constructor( + credentials: string[], + codes: string[], + clientIdClientSecret: string[], + public provider: TwoFactorProviderType, + public token: string, + public remember: boolean, + public captchaResponse: string, + device?: DeviceRequest + ) { + if (credentials != null && credentials.length > 1) { + this.email = credentials[0]; + this.masterPasswordHash = credentials[1]; + } else if (codes != null && codes.length > 2) { + this.code = codes[0]; + this.codeVerifier = codes[1]; + this.redirectUri = codes[2]; + } else if (clientIdClientSecret != null && clientIdClientSecret.length > 1) { + this.clientId = clientIdClientSecret[0]; + this.clientSecret = clientIdClientSecret[1]; + } + this.device = device != null ? device : null; + } + + toIdentityToken(clientId: string) { + const obj: any = { + scope: "api offline_access", + client_id: clientId, + }; + + if (this.clientSecret != null) { + obj.scope = clientId.startsWith("organization") ? "api.organization" : "api"; + obj.grant_type = "client_credentials"; + obj.client_secret = this.clientSecret; + } else if (this.masterPasswordHash != null && this.email != null) { + obj.grant_type = "password"; + obj.username = this.email; + obj.password = this.masterPasswordHash; + } else if (this.code != null && this.codeVerifier != null && this.redirectUri != null) { + obj.grant_type = "authorization_code"; + obj.code = this.code; + obj.code_verifier = this.codeVerifier; + obj.redirect_uri = this.redirectUri; + } else { + throw new Error("must provide credentials or codes"); } - toIdentityToken(clientId: string) { - const obj: any = { - scope: 'api offline_access', - client_id: clientId, - }; - - if (this.clientSecret != null) { - obj.scope = clientId.startsWith('organization') ? 'api.organization' : 'api'; - obj.grant_type = 'client_credentials'; - obj.client_secret = this.clientSecret; - } else if (this.masterPasswordHash != null && this.email != null) { - obj.grant_type = 'password'; - obj.username = this.email; - obj.password = this.masterPasswordHash; - } else if (this.code != null && this.codeVerifier != null && this.redirectUri != null) { - obj.grant_type = 'authorization_code'; - obj.code = this.code; - obj.code_verifier = this.codeVerifier; - obj.redirect_uri = this.redirectUri; - } else { - throw new Error('must provide credentials or codes'); - } - - if (this.device) { - obj.deviceType = this.device.type; - obj.deviceIdentifier = this.device.identifier; - obj.deviceName = this.device.name; - // no push tokens for browser apps yet - // obj.devicePushToken = this.device.pushToken; - } - - if (this.token && this.provider != null) { - obj.twoFactorToken = this.token; - obj.twoFactorProvider = this.provider; - obj.twoFactorRemember = this.remember ? '1' : '0'; - } - - if (this.captchaResponse != null) { - obj.captchaResponse = this.captchaResponse; - } - - - return obj; + if (this.device) { + obj.deviceType = this.device.type; + obj.deviceIdentifier = this.device.identifier; + obj.deviceName = this.device.name; + // no push tokens for browser apps yet + // obj.devicePushToken = this.device.pushToken; } - alterIdentityTokenHeaders(headers: Headers) { - if (this.clientSecret == null && this.masterPasswordHash != null && this.email != null) { - headers.set('Auth-Email', Utils.fromUtf8ToUrlB64(this.email)); - } + if (this.token && this.provider != null) { + obj.twoFactorToken = this.token; + obj.twoFactorProvider = this.provider; + obj.twoFactorRemember = this.remember ? "1" : "0"; } + + if (this.captchaResponse != null) { + obj.captchaResponse = this.captchaResponse; + } + + return obj; + } + + alterIdentityTokenHeaders(headers: Headers) { + if (this.clientSecret == null && this.masterPasswordHash != null && this.email != null) { + headers.set("Auth-Email", Utils.fromUtf8ToUrlB64(this.email)); + } + } } diff --git a/common/src/models/request/twoFactorEmailRequest.ts b/common/src/models/request/twoFactorEmailRequest.ts index 6eeb0185..36c168b6 100644 --- a/common/src/models/request/twoFactorEmailRequest.ts +++ b/common/src/models/request/twoFactorEmailRequest.ts @@ -1,5 +1,5 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class TwoFactorEmailRequest extends SecretVerificationRequest { - email: string; + email: string; } diff --git a/common/src/models/request/twoFactorProviderRequest.ts b/common/src/models/request/twoFactorProviderRequest.ts index c9138597..d80ba5ba 100644 --- a/common/src/models/request/twoFactorProviderRequest.ts +++ b/common/src/models/request/twoFactorProviderRequest.ts @@ -1,7 +1,7 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; -import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; +import { TwoFactorProviderType } from "../../enums/twoFactorProviderType"; export class TwoFactorProviderRequest extends SecretVerificationRequest { - type: TwoFactorProviderType; + type: TwoFactorProviderType; } diff --git a/common/src/models/request/twoFactorRecoveryRequest.ts b/common/src/models/request/twoFactorRecoveryRequest.ts index 3352f327..39135a37 100644 --- a/common/src/models/request/twoFactorRecoveryRequest.ts +++ b/common/src/models/request/twoFactorRecoveryRequest.ts @@ -1,6 +1,6 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class TwoFactorRecoveryRequest extends SecretVerificationRequest { - recoveryCode: string; - email: string; + recoveryCode: string; + email: string; } diff --git a/common/src/models/request/updateDomainsRequest.ts b/common/src/models/request/updateDomainsRequest.ts index d624369d..528d3682 100644 --- a/common/src/models/request/updateDomainsRequest.ts +++ b/common/src/models/request/updateDomainsRequest.ts @@ -1,4 +1,4 @@ export class UpdateDomainsRequest { - equivalentDomains: string[][]; - excludedGlobalEquivalentDomains: number[]; + equivalentDomains: string[][]; + excludedGlobalEquivalentDomains: number[]; } diff --git a/common/src/models/request/updateKeyRequest.ts b/common/src/models/request/updateKeyRequest.ts index c0521b9b..a9fceffd 100644 --- a/common/src/models/request/updateKeyRequest.ts +++ b/common/src/models/request/updateKeyRequest.ts @@ -1,12 +1,12 @@ -import { CipherWithIdRequest } from './cipherWithIdRequest'; -import { FolderWithIdRequest } from './folderWithIdRequest'; -import { SendWithIdRequest } from './sendWithIdRequest'; +import { CipherWithIdRequest } from "./cipherWithIdRequest"; +import { FolderWithIdRequest } from "./folderWithIdRequest"; +import { SendWithIdRequest } from "./sendWithIdRequest"; export class UpdateKeyRequest { - ciphers: CipherWithIdRequest[] = []; - folders: FolderWithIdRequest[] = []; - sends: SendWithIdRequest[] = []; - masterPasswordHash: string; - privateKey: string; - key: string; + ciphers: CipherWithIdRequest[] = []; + folders: FolderWithIdRequest[] = []; + sends: SendWithIdRequest[] = []; + masterPasswordHash: string; + privateKey: string; + key: string; } diff --git a/common/src/models/request/updateProfileRequest.ts b/common/src/models/request/updateProfileRequest.ts index e029f3f7..14ed554d 100644 --- a/common/src/models/request/updateProfileRequest.ts +++ b/common/src/models/request/updateProfileRequest.ts @@ -1,10 +1,10 @@ export class UpdateProfileRequest { - name: string; - masterPasswordHint: string; - culture = 'en-US'; // deprecated + name: string; + masterPasswordHint: string; + culture = "en-US"; // deprecated - constructor(name: string, masterPasswordHint: string) { - this.name = name; - this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null; - } + constructor(name: string, masterPasswordHint: string) { + this.name = name; + this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null; + } } diff --git a/common/src/models/request/updateTempPasswordRequest.ts b/common/src/models/request/updateTempPasswordRequest.ts index 044311d3..1bd97697 100644 --- a/common/src/models/request/updateTempPasswordRequest.ts +++ b/common/src/models/request/updateTempPasswordRequest.ts @@ -1,5 +1,5 @@ -import { OrganizationUserResetPasswordRequest } from './organizationUserResetPasswordRequest'; +import { OrganizationUserResetPasswordRequest } from "./organizationUserResetPasswordRequest"; export class UpdateTempPasswordRequest extends OrganizationUserResetPasswordRequest { - masterPasswordHint: string; + masterPasswordHint: string; } diff --git a/common/src/models/request/updateTwoFactorAuthenticatorRequest.ts b/common/src/models/request/updateTwoFactorAuthenticatorRequest.ts index fa0a96c0..9b718287 100644 --- a/common/src/models/request/updateTwoFactorAuthenticatorRequest.ts +++ b/common/src/models/request/updateTwoFactorAuthenticatorRequest.ts @@ -1,6 +1,6 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class UpdateTwoFactorAuthenticatorRequest extends SecretVerificationRequest { - token: string; - key: string; + token: string; + key: string; } diff --git a/common/src/models/request/updateTwoFactorDuoRequest.ts b/common/src/models/request/updateTwoFactorDuoRequest.ts index 9465e2f9..cd82215d 100644 --- a/common/src/models/request/updateTwoFactorDuoRequest.ts +++ b/common/src/models/request/updateTwoFactorDuoRequest.ts @@ -1,7 +1,7 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class UpdateTwoFactorDuoRequest extends SecretVerificationRequest { - integrationKey: string; - secretKey: string; - host: string; + integrationKey: string; + secretKey: string; + host: string; } diff --git a/common/src/models/request/updateTwoFactorEmailRequest.ts b/common/src/models/request/updateTwoFactorEmailRequest.ts index ce2fedb5..be7da1fd 100644 --- a/common/src/models/request/updateTwoFactorEmailRequest.ts +++ b/common/src/models/request/updateTwoFactorEmailRequest.ts @@ -1,6 +1,6 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class UpdateTwoFactorEmailRequest extends SecretVerificationRequest { - token: string; - email: string; + token: string; + email: string; } diff --git a/common/src/models/request/updateTwoFactorWebAuthnDeleteRequest.ts b/common/src/models/request/updateTwoFactorWebAuthnDeleteRequest.ts index 8fa5fcd0..1decda72 100644 --- a/common/src/models/request/updateTwoFactorWebAuthnDeleteRequest.ts +++ b/common/src/models/request/updateTwoFactorWebAuthnDeleteRequest.ts @@ -1,5 +1,5 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class UpdateTwoFactorWebAuthnDeleteRequest extends SecretVerificationRequest { - id: number; + id: number; } diff --git a/common/src/models/request/updateTwoFactorWebAuthnRequest.ts b/common/src/models/request/updateTwoFactorWebAuthnRequest.ts index 09976c31..2e788b52 100644 --- a/common/src/models/request/updateTwoFactorWebAuthnRequest.ts +++ b/common/src/models/request/updateTwoFactorWebAuthnRequest.ts @@ -1,7 +1,7 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class UpdateTwoFactorWebAuthnRequest extends SecretVerificationRequest { - deviceResponse: PublicKeyCredential; - name: string; - id: number; + deviceResponse: PublicKeyCredential; + name: string; + id: number; } diff --git a/common/src/models/request/updateTwoFactorYubioOtpRequest.ts b/common/src/models/request/updateTwoFactorYubioOtpRequest.ts index 29a9dd81..cb495b1e 100644 --- a/common/src/models/request/updateTwoFactorYubioOtpRequest.ts +++ b/common/src/models/request/updateTwoFactorYubioOtpRequest.ts @@ -1,10 +1,10 @@ -import { SecretVerificationRequest } from './secretVerificationRequest'; +import { SecretVerificationRequest } from "./secretVerificationRequest"; export class UpdateTwoFactorYubioOtpRequest extends SecretVerificationRequest { - key1: string; - key2: string; - key3: string; - key4: string; - key5: string; - nfc: boolean; + key1: string; + key2: string; + key3: string; + key4: string; + key5: string; + nfc: boolean; } diff --git a/common/src/models/request/verifyBankRequest.ts b/common/src/models/request/verifyBankRequest.ts index bddd452d..823eaf46 100644 --- a/common/src/models/request/verifyBankRequest.ts +++ b/common/src/models/request/verifyBankRequest.ts @@ -1,4 +1,4 @@ export class VerifyBankRequest { - amount1: number; - amount2: number; + amount1: number; + amount2: number; } diff --git a/common/src/models/request/verifyDeleteRecoverRequest.ts b/common/src/models/request/verifyDeleteRecoverRequest.ts index 9372b4bf..2374d32d 100644 --- a/common/src/models/request/verifyDeleteRecoverRequest.ts +++ b/common/src/models/request/verifyDeleteRecoverRequest.ts @@ -1,9 +1,9 @@ export class VerifyDeleteRecoverRequest { - userId: string; - token: string; + userId: string; + token: string; - constructor(userId: string, token: string) { - this.userId = userId; - this.token = token; - } + constructor(userId: string, token: string) { + this.userId = userId; + this.token = token; + } } diff --git a/common/src/models/request/verifyEmailRequest.ts b/common/src/models/request/verifyEmailRequest.ts index 7609fd06..ecee0190 100644 --- a/common/src/models/request/verifyEmailRequest.ts +++ b/common/src/models/request/verifyEmailRequest.ts @@ -1,9 +1,9 @@ export class VerifyEmailRequest { - userId: string; - token: string; + userId: string; + token: string; - constructor(userId: string, token: string) { - this.userId = userId; - this.token = token; - } + constructor(userId: string, token: string) { + this.userId = userId; + this.token = token; + } } diff --git a/common/src/models/response/apiKeyResponse.ts b/common/src/models/response/apiKeyResponse.ts index b530b2dc..f1a24be0 100644 --- a/common/src/models/response/apiKeyResponse.ts +++ b/common/src/models/response/apiKeyResponse.ts @@ -1,10 +1,10 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class ApiKeyResponse extends BaseResponse { - apiKey: string; + apiKey: string; - constructor(response: any) { - super(response); - this.apiKey = this.getResponseProperty('ApiKey'); - } + constructor(response: any) { + super(response); + this.apiKey = this.getResponseProperty("ApiKey"); + } } diff --git a/common/src/models/response/attachmentResponse.ts b/common/src/models/response/attachmentResponse.ts index 47c01cad..a9ebfaf3 100644 --- a/common/src/models/response/attachmentResponse.ts +++ b/common/src/models/response/attachmentResponse.ts @@ -1,20 +1,20 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class AttachmentResponse extends BaseResponse { - id: string; - url: string; - fileName: string; - key: string; - size: string; - sizeName: string; + id: string; + url: string; + fileName: string; + key: string; + size: string; + sizeName: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.url = this.getResponseProperty('Url'); - this.fileName = this.getResponseProperty('FileName'); - this.key = this.getResponseProperty('Key'); - this.size = this.getResponseProperty('Size'); - this.sizeName = this.getResponseProperty('SizeName'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.url = this.getResponseProperty("Url"); + this.fileName = this.getResponseProperty("FileName"); + this.key = this.getResponseProperty("Key"); + this.size = this.getResponseProperty("Size"); + this.sizeName = this.getResponseProperty("SizeName"); + } } diff --git a/common/src/models/response/attachmentUploadDataResponse.ts b/common/src/models/response/attachmentUploadDataResponse.ts index dd71276c..e9651452 100644 --- a/common/src/models/response/attachmentUploadDataResponse.ts +++ b/common/src/models/response/attachmentUploadDataResponse.ts @@ -1,22 +1,22 @@ -import { FileUploadType } from '../../enums/fileUploadType'; -import { BaseResponse } from './baseResponse'; -import { CipherResponse } from './cipherResponse'; +import { FileUploadType } from "../../enums/fileUploadType"; +import { BaseResponse } from "./baseResponse"; +import { CipherResponse } from "./cipherResponse"; export class AttachmentUploadDataResponse extends BaseResponse { - attachmentId: string; - fileUploadType: FileUploadType; - cipherResponse: CipherResponse; - cipherMiniResponse: CipherResponse; - url: string = null; - constructor(response: any) { - super(response); - this.attachmentId = this.getResponseProperty('AttachmentId'); - this.fileUploadType = this.getResponseProperty('FileUploadType'); - const cipherResponse = this.getResponseProperty('CipherResponse'); - const cipherMiniResponse = this.getResponseProperty('CipherMiniResponse'); - this.cipherResponse = cipherResponse == null ? null : new CipherResponse(cipherResponse); - this.cipherMiniResponse = cipherMiniResponse == null ? null : new CipherResponse(cipherMiniResponse); - this.url = this.getResponseProperty('Url'); - } - + attachmentId: string; + fileUploadType: FileUploadType; + cipherResponse: CipherResponse; + cipherMiniResponse: CipherResponse; + url: string = null; + constructor(response: any) { + super(response); + this.attachmentId = this.getResponseProperty("AttachmentId"); + this.fileUploadType = this.getResponseProperty("FileUploadType"); + const cipherResponse = this.getResponseProperty("CipherResponse"); + const cipherMiniResponse = this.getResponseProperty("CipherMiniResponse"); + this.cipherResponse = cipherResponse == null ? null : new CipherResponse(cipherResponse); + this.cipherMiniResponse = + cipherMiniResponse == null ? null : new CipherResponse(cipherMiniResponse); + this.url = this.getResponseProperty("Url"); + } } diff --git a/common/src/models/response/baseResponse.ts b/common/src/models/response/baseResponse.ts index 38184322..8c599fba 100644 --- a/common/src/models/response/baseResponse.ts +++ b/common/src/models/response/baseResponse.ts @@ -1,39 +1,43 @@ export abstract class BaseResponse { - private response: any; + private response: any; - constructor(response: any) { - this.response = response; + constructor(response: any) { + this.response = response; + } + + protected getResponseProperty( + propertyName: string, + response: any = null, + exactName = false + ): any { + if (propertyName == null || propertyName === "") { + throw new Error("propertyName must not be null/empty."); } - - protected getResponseProperty(propertyName: string, response: any = null, exactName = false): any { - if (propertyName == null || propertyName === '') { - throw new Error('propertyName must not be null/empty.'); - } - if (response == null && this.response != null) { - response = this.response; - } - if (response == null) { - return null; - } - if (!exactName && response[propertyName] === undefined) { - let otherCasePropertyName: string = null; - if (propertyName.charAt(0) === propertyName.charAt(0).toUpperCase()) { - otherCasePropertyName = propertyName.charAt(0).toLowerCase(); - } else { - otherCasePropertyName = propertyName.charAt(0).toUpperCase(); - } - if (propertyName.length > 1) { - otherCasePropertyName += propertyName.slice(1); - } - - propertyName = otherCasePropertyName; - if (response[propertyName] === undefined) { - propertyName = propertyName.toLowerCase(); - } - if (response[propertyName] === undefined) { - propertyName = propertyName.toUpperCase(); - } - } - return response[propertyName]; + if (response == null && this.response != null) { + response = this.response; } + if (response == null) { + return null; + } + if (!exactName && response[propertyName] === undefined) { + let otherCasePropertyName: string = null; + if (propertyName.charAt(0) === propertyName.charAt(0).toUpperCase()) { + otherCasePropertyName = propertyName.charAt(0).toLowerCase(); + } else { + otherCasePropertyName = propertyName.charAt(0).toUpperCase(); + } + if (propertyName.length > 1) { + otherCasePropertyName += propertyName.slice(1); + } + + propertyName = otherCasePropertyName; + if (response[propertyName] === undefined) { + propertyName = propertyName.toLowerCase(); + } + if (response[propertyName] === undefined) { + propertyName = propertyName.toUpperCase(); + } + } + return response[propertyName]; + } } diff --git a/common/src/models/response/billingResponse.ts b/common/src/models/response/billingResponse.ts index 36954db6..91905cb2 100644 --- a/common/src/models/response/billingResponse.ts +++ b/common/src/models/response/billingResponse.ts @@ -1,83 +1,83 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { PaymentMethodType } from '../../enums/paymentMethodType'; -import { TransactionType } from '../../enums/transactionType'; +import { PaymentMethodType } from "../../enums/paymentMethodType"; +import { TransactionType } from "../../enums/transactionType"; export class BillingResponse extends BaseResponse { - balance: number; - paymentSource: BillingSourceResponse; - invoices: BillingInvoiceResponse[] = []; - transactions: BillingTransactionResponse[] = []; + balance: number; + paymentSource: BillingSourceResponse; + invoices: BillingInvoiceResponse[] = []; + transactions: BillingTransactionResponse[] = []; - constructor(response: any) { - super(response); - this.balance = this.getResponseProperty('Balance'); - const paymentSource = this.getResponseProperty('PaymentSource'); - const transactions = this.getResponseProperty('Transactions'); - const invoices = this.getResponseProperty('Invoices'); - this.paymentSource = paymentSource == null ? null : new BillingSourceResponse(paymentSource); - if (transactions != null) { - this.transactions = transactions.map((t: any) => new BillingTransactionResponse(t)); - } - if (invoices != null) { - this.invoices = invoices.map((i: any) => new BillingInvoiceResponse(i)); - } + constructor(response: any) { + super(response); + this.balance = this.getResponseProperty("Balance"); + const paymentSource = this.getResponseProperty("PaymentSource"); + const transactions = this.getResponseProperty("Transactions"); + const invoices = this.getResponseProperty("Invoices"); + this.paymentSource = paymentSource == null ? null : new BillingSourceResponse(paymentSource); + if (transactions != null) { + this.transactions = transactions.map((t: any) => new BillingTransactionResponse(t)); } + if (invoices != null) { + this.invoices = invoices.map((i: any) => new BillingInvoiceResponse(i)); + } + } } export class BillingSourceResponse extends BaseResponse { - type: PaymentMethodType; - cardBrand: string; - description: string; - needsVerification: boolean; + type: PaymentMethodType; + cardBrand: string; + description: string; + needsVerification: boolean; - constructor(response: any) { - super(response); - this.type = this.getResponseProperty('Type'); - this.cardBrand = this.getResponseProperty('CardBrand'); - this.description = this.getResponseProperty('Description'); - this.needsVerification = this.getResponseProperty('NeedsVerification'); - } + constructor(response: any) { + super(response); + this.type = this.getResponseProperty("Type"); + this.cardBrand = this.getResponseProperty("CardBrand"); + this.description = this.getResponseProperty("Description"); + this.needsVerification = this.getResponseProperty("NeedsVerification"); + } } export class BillingInvoiceResponse extends BaseResponse { - url: string; - pdfUrl: string; - number: string; - paid: boolean; - date: string; - amount: number; + url: string; + pdfUrl: string; + number: string; + paid: boolean; + date: string; + amount: number; - constructor(response: any) { - super(response); - this.url = this.getResponseProperty('Url'); - this.pdfUrl = this.getResponseProperty('PdfUrl'); - this.number = this.getResponseProperty('Number'); - this.paid = this.getResponseProperty('Paid'); - this.date = this.getResponseProperty('Date'); - this.amount = this.getResponseProperty('Amount'); - } + constructor(response: any) { + super(response); + this.url = this.getResponseProperty("Url"); + this.pdfUrl = this.getResponseProperty("PdfUrl"); + this.number = this.getResponseProperty("Number"); + this.paid = this.getResponseProperty("Paid"); + this.date = this.getResponseProperty("Date"); + this.amount = this.getResponseProperty("Amount"); + } } export class BillingTransactionResponse extends BaseResponse { - createdDate: string; - amount: number; - refunded: boolean; - partiallyRefunded: boolean; - refundedAmount: number; - type: TransactionType; - paymentMethodType: PaymentMethodType; - details: string; + createdDate: string; + amount: number; + refunded: boolean; + partiallyRefunded: boolean; + refundedAmount: number; + type: TransactionType; + paymentMethodType: PaymentMethodType; + details: string; - constructor(response: any) { - super(response); - this.createdDate = this.getResponseProperty('CreatedDate'); - this.amount = this.getResponseProperty('Amount'); - this.refunded = this.getResponseProperty('Refunded'); - this.partiallyRefunded = this.getResponseProperty('PartiallyRefunded'); - this.refundedAmount = this.getResponseProperty('RefundedAmount'); - this.type = this.getResponseProperty('Type'); - this.paymentMethodType = this.getResponseProperty('PaymentMethodType'); - this.details = this.getResponseProperty('Details'); - } + constructor(response: any) { + super(response); + this.createdDate = this.getResponseProperty("CreatedDate"); + this.amount = this.getResponseProperty("Amount"); + this.refunded = this.getResponseProperty("Refunded"); + this.partiallyRefunded = this.getResponseProperty("PartiallyRefunded"); + this.refundedAmount = this.getResponseProperty("RefundedAmount"); + this.type = this.getResponseProperty("Type"); + this.paymentMethodType = this.getResponseProperty("PaymentMethodType"); + this.details = this.getResponseProperty("Details"); + } } diff --git a/common/src/models/response/breachAccountResponse.ts b/common/src/models/response/breachAccountResponse.ts index bfa4f70c..00d39acc 100644 --- a/common/src/models/response/breachAccountResponse.ts +++ b/common/src/models/response/breachAccountResponse.ts @@ -1,32 +1,32 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class BreachAccountResponse extends BaseResponse { - addedDate: string; - breachDate: string; - dataClasses: string[]; - description: string; - domain: string; - isActive: boolean; - isVerified: boolean; - logoPath: string; - modifiedDate: string; - name: string; - pwnCount: number; - title: string; + addedDate: string; + breachDate: string; + dataClasses: string[]; + description: string; + domain: string; + isActive: boolean; + isVerified: boolean; + logoPath: string; + modifiedDate: string; + name: string; + pwnCount: number; + title: string; - constructor(response: any) { - super(response); - this.addedDate = this.getResponseProperty('AddedDate'); - this.breachDate = this.getResponseProperty('BreachDate'); - this.dataClasses = this.getResponseProperty('DataClasses'); - this.description = this.getResponseProperty('Description'); - this.domain = this.getResponseProperty('Domain'); - this.isActive = this.getResponseProperty('IsActive'); - this.isVerified = this.getResponseProperty('IsVerified'); - this.logoPath = this.getResponseProperty('LogoPath'); - this.modifiedDate = this.getResponseProperty('ModifiedDate'); - this.name = this.getResponseProperty('Name'); - this.pwnCount = this.getResponseProperty('PwnCount'); - this.title = this.getResponseProperty('Title'); - } + constructor(response: any) { + super(response); + this.addedDate = this.getResponseProperty("AddedDate"); + this.breachDate = this.getResponseProperty("BreachDate"); + this.dataClasses = this.getResponseProperty("DataClasses"); + this.description = this.getResponseProperty("Description"); + this.domain = this.getResponseProperty("Domain"); + this.isActive = this.getResponseProperty("IsActive"); + this.isVerified = this.getResponseProperty("IsVerified"); + this.logoPath = this.getResponseProperty("LogoPath"); + this.modifiedDate = this.getResponseProperty("ModifiedDate"); + this.name = this.getResponseProperty("Name"); + this.pwnCount = this.getResponseProperty("PwnCount"); + this.title = this.getResponseProperty("Title"); + } } diff --git a/common/src/models/response/cipherResponse.ts b/common/src/models/response/cipherResponse.ts index 55548939..0be26463 100644 --- a/common/src/models/response/cipherResponse.ts +++ b/common/src/models/response/cipherResponse.ts @@ -1,92 +1,92 @@ -import { AttachmentResponse } from './attachmentResponse'; -import { BaseResponse } from './baseResponse'; -import { PasswordHistoryResponse } from './passwordHistoryResponse'; +import { AttachmentResponse } from "./attachmentResponse"; +import { BaseResponse } from "./baseResponse"; +import { PasswordHistoryResponse } from "./passwordHistoryResponse"; -import { CipherRepromptType } from '../../enums/cipherRepromptType'; -import { CardApi } from '../api/cardApi'; -import { FieldApi } from '../api/fieldApi'; -import { IdentityApi } from '../api/identityApi'; -import { LoginApi } from '../api/loginApi'; -import { SecureNoteApi } from '../api/secureNoteApi'; +import { CipherRepromptType } from "../../enums/cipherRepromptType"; +import { CardApi } from "../api/cardApi"; +import { FieldApi } from "../api/fieldApi"; +import { IdentityApi } from "../api/identityApi"; +import { LoginApi } from "../api/loginApi"; +import { SecureNoteApi } from "../api/secureNoteApi"; export class CipherResponse extends BaseResponse { - id: string; - organizationId: string; - folderId: string; - type: number; - name: string; - notes: string; - fields: FieldApi[]; - login: LoginApi; - card: CardApi; - identity: IdentityApi; - secureNote: SecureNoteApi; - favorite: boolean; - edit: boolean; - viewPassword: boolean; - organizationUseTotp: boolean; - revisionDate: string; - attachments: AttachmentResponse[]; - passwordHistory: PasswordHistoryResponse[]; - collectionIds: string[]; - deletedDate: string; - reprompt: CipherRepromptType; + id: string; + organizationId: string; + folderId: string; + type: number; + name: string; + notes: string; + fields: FieldApi[]; + login: LoginApi; + card: CardApi; + identity: IdentityApi; + secureNote: SecureNoteApi; + favorite: boolean; + edit: boolean; + viewPassword: boolean; + organizationUseTotp: boolean; + revisionDate: string; + attachments: AttachmentResponse[]; + passwordHistory: PasswordHistoryResponse[]; + collectionIds: string[]; + deletedDate: string; + reprompt: CipherRepromptType; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.organizationId = this.getResponseProperty('OrganizationId'); - this.folderId = this.getResponseProperty('FolderId') || null; - this.type = this.getResponseProperty('Type'); - this.name = this.getResponseProperty('Name'); - this.notes = this.getResponseProperty('Notes'); - this.favorite = this.getResponseProperty('Favorite') || false; - this.edit = !!this.getResponseProperty('Edit'); - if (this.getResponseProperty('ViewPassword') == null) { - this.viewPassword = true; - } else { - this.viewPassword = this.getResponseProperty('ViewPassword'); - } - this.organizationUseTotp = this.getResponseProperty('OrganizationUseTotp'); - this.revisionDate = this.getResponseProperty('RevisionDate'); - this.collectionIds = this.getResponseProperty('CollectionIds'); - this.deletedDate = this.getResponseProperty('DeletedDate'); - - const login = this.getResponseProperty('Login'); - if (login != null) { - this.login = new LoginApi(login); - } - - const card = this.getResponseProperty('Card'); - if (card != null) { - this.card = new CardApi(card); - } - - const identity = this.getResponseProperty('Identity'); - if (identity != null) { - this.identity = new IdentityApi(identity); - } - - const secureNote = this.getResponseProperty('SecureNote'); - if (secureNote != null) { - this.secureNote = new SecureNoteApi(secureNote); - } - - const fields = this.getResponseProperty('Fields'); - if (fields != null) { - this.fields = fields.map((f: any) => new FieldApi(f)); - } - - const attachments = this.getResponseProperty('Attachments'); - if (attachments != null) { - this.attachments = attachments.map((a: any) => new AttachmentResponse(a)); - } - - const passwordHistory = this.getResponseProperty('PasswordHistory'); - if (passwordHistory != null) { - this.passwordHistory = passwordHistory.map((h: any) => new PasswordHistoryResponse(h)); - } - - this.reprompt = this.getResponseProperty('Reprompt') || CipherRepromptType.None; + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.folderId = this.getResponseProperty("FolderId") || null; + this.type = this.getResponseProperty("Type"); + this.name = this.getResponseProperty("Name"); + this.notes = this.getResponseProperty("Notes"); + this.favorite = this.getResponseProperty("Favorite") || false; + this.edit = !!this.getResponseProperty("Edit"); + if (this.getResponseProperty("ViewPassword") == null) { + this.viewPassword = true; + } else { + this.viewPassword = this.getResponseProperty("ViewPassword"); } + this.organizationUseTotp = this.getResponseProperty("OrganizationUseTotp"); + this.revisionDate = this.getResponseProperty("RevisionDate"); + this.collectionIds = this.getResponseProperty("CollectionIds"); + this.deletedDate = this.getResponseProperty("DeletedDate"); + + const login = this.getResponseProperty("Login"); + if (login != null) { + this.login = new LoginApi(login); + } + + const card = this.getResponseProperty("Card"); + if (card != null) { + this.card = new CardApi(card); + } + + const identity = this.getResponseProperty("Identity"); + if (identity != null) { + this.identity = new IdentityApi(identity); + } + + const secureNote = this.getResponseProperty("SecureNote"); + if (secureNote != null) { + this.secureNote = new SecureNoteApi(secureNote); + } + + const fields = this.getResponseProperty("Fields"); + if (fields != null) { + this.fields = fields.map((f: any) => new FieldApi(f)); + } + + const attachments = this.getResponseProperty("Attachments"); + if (attachments != null) { + this.attachments = attachments.map((a: any) => new AttachmentResponse(a)); + } + + const passwordHistory = this.getResponseProperty("PasswordHistory"); + if (passwordHistory != null) { + this.passwordHistory = passwordHistory.map((h: any) => new PasswordHistoryResponse(h)); + } + + this.reprompt = this.getResponseProperty("Reprompt") || CipherRepromptType.None; + } } diff --git a/common/src/models/response/collectionResponse.ts b/common/src/models/response/collectionResponse.ts index eb9441c4..2f677f7d 100644 --- a/common/src/models/response/collectionResponse.ts +++ b/common/src/models/response/collectionResponse.ts @@ -1,38 +1,38 @@ -import { BaseResponse } from './baseResponse'; -import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse'; +import { BaseResponse } from "./baseResponse"; +import { SelectionReadOnlyResponse } from "./selectionReadOnlyResponse"; export class CollectionResponse extends BaseResponse { - id: string; - organizationId: string; - name: string; - externalId: string; + id: string; + organizationId: string; + name: string; + externalId: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.organizationId = this.getResponseProperty('OrganizationId'); - this.name = this.getResponseProperty('Name'); - this.externalId = this.getResponseProperty('ExternalId'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.name = this.getResponseProperty("Name"); + this.externalId = this.getResponseProperty("ExternalId"); + } } export class CollectionDetailsResponse extends CollectionResponse { - readOnly: boolean; + readOnly: boolean; - constructor(response: any) { - super(response); - this.readOnly = this.getResponseProperty('ReadOnly') || false; - } + constructor(response: any) { + super(response); + this.readOnly = this.getResponseProperty("ReadOnly") || false; + } } export class CollectionGroupDetailsResponse extends CollectionResponse { - groups: SelectionReadOnlyResponse[] = []; + groups: SelectionReadOnlyResponse[] = []; - constructor(response: any) { - super(response); - const groups = this.getResponseProperty('Groups'); - if (groups != null) { - this.groups = groups.map((g: any) => new SelectionReadOnlyResponse(g)); - } + constructor(response: any) { + super(response); + const groups = this.getResponseProperty("Groups"); + if (groups != null) { + this.groups = groups.map((g: any) => new SelectionReadOnlyResponse(g)); } + } } diff --git a/common/src/models/response/deviceResponse.ts b/common/src/models/response/deviceResponse.ts index 30f4e400..e3857cc1 100644 --- a/common/src/models/response/deviceResponse.ts +++ b/common/src/models/response/deviceResponse.ts @@ -1,20 +1,20 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { DeviceType } from '../../enums/deviceType'; +import { DeviceType } from "../../enums/deviceType"; export class DeviceResponse extends BaseResponse { - id: string; - name: number; - identifier: string; - type: DeviceType; - creationDate: string; + id: string; + name: number; + identifier: string; + type: DeviceType; + creationDate: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.name = this.getResponseProperty('Name'); - this.identifier = this.getResponseProperty('Identifier'); - this.type = this.getResponseProperty('Type'); - this.creationDate = this.getResponseProperty('CreationDate'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.name = this.getResponseProperty("Name"); + this.identifier = this.getResponseProperty("Identifier"); + this.type = this.getResponseProperty("Type"); + this.creationDate = this.getResponseProperty("CreationDate"); + } } diff --git a/common/src/models/response/domainsResponse.ts b/common/src/models/response/domainsResponse.ts index 3e7727e9..3014c2f2 100644 --- a/common/src/models/response/domainsResponse.ts +++ b/common/src/models/response/domainsResponse.ts @@ -1,18 +1,20 @@ -import { BaseResponse } from './baseResponse'; -import { GlobalDomainResponse } from './globalDomainResponse'; +import { BaseResponse } from "./baseResponse"; +import { GlobalDomainResponse } from "./globalDomainResponse"; export class DomainsResponse extends BaseResponse { - equivalentDomains: string[][]; - globalEquivalentDomains: GlobalDomainResponse[] = []; + equivalentDomains: string[][]; + globalEquivalentDomains: GlobalDomainResponse[] = []; - constructor(response: any) { - super(response); - this.equivalentDomains = this.getResponseProperty('EquivalentDomains'); - const globalEquivalentDomains = this.getResponseProperty('GlobalEquivalentDomains'); - if (globalEquivalentDomains != null) { - this.globalEquivalentDomains = globalEquivalentDomains.map((d: any) => new GlobalDomainResponse(d)); - } else { - this.globalEquivalentDomains = []; - } + constructor(response: any) { + super(response); + this.equivalentDomains = this.getResponseProperty("EquivalentDomains"); + const globalEquivalentDomains = this.getResponseProperty("GlobalEquivalentDomains"); + if (globalEquivalentDomains != null) { + this.globalEquivalentDomains = globalEquivalentDomains.map( + (d: any) => new GlobalDomainResponse(d) + ); + } else { + this.globalEquivalentDomains = []; } + } } diff --git a/common/src/models/response/emergencyAccessResponse.ts b/common/src/models/response/emergencyAccessResponse.ts index fbd60849..703543b2 100644 --- a/common/src/models/response/emergencyAccessResponse.ts +++ b/common/src/models/response/emergencyAccessResponse.ts @@ -1,81 +1,81 @@ -import { EmergencyAccessStatusType } from '../../enums/emergencyAccessStatusType'; -import { EmergencyAccessType } from '../../enums/emergencyAccessType'; -import { KdfType } from '../../enums/kdfType'; -import { BaseResponse } from './baseResponse'; -import { CipherResponse } from './cipherResponse'; +import { EmergencyAccessStatusType } from "../../enums/emergencyAccessStatusType"; +import { EmergencyAccessType } from "../../enums/emergencyAccessType"; +import { KdfType } from "../../enums/kdfType"; +import { BaseResponse } from "./baseResponse"; +import { CipherResponse } from "./cipherResponse"; export class EmergencyAccessGranteeDetailsResponse extends BaseResponse { - id: string; - granteeId: string; - name: string; - email: string; - type: EmergencyAccessType; - status: EmergencyAccessStatusType; - waitTimeDays: number; - creationDate: string; + id: string; + granteeId: string; + name: string; + email: string; + type: EmergencyAccessType; + status: EmergencyAccessStatusType; + waitTimeDays: number; + creationDate: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.granteeId = this.getResponseProperty('GranteeId'); - this.name = this.getResponseProperty('Name'); - this.email = this.getResponseProperty('Email'); - this.type = this.getResponseProperty('Type'); - this.status = this.getResponseProperty('Status'); - this.waitTimeDays = this.getResponseProperty('WaitTimeDays'); - this.creationDate = this.getResponseProperty('CreationDate'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.granteeId = this.getResponseProperty("GranteeId"); + this.name = this.getResponseProperty("Name"); + this.email = this.getResponseProperty("Email"); + this.type = this.getResponseProperty("Type"); + this.status = this.getResponseProperty("Status"); + this.waitTimeDays = this.getResponseProperty("WaitTimeDays"); + this.creationDate = this.getResponseProperty("CreationDate"); + } } export class EmergencyAccessGrantorDetailsResponse extends BaseResponse { - id: string; - grantorId: string; - name: string; - email: string; - type: EmergencyAccessType; - status: EmergencyAccessStatusType; - waitTimeDays: number; - creationDate: string; + id: string; + grantorId: string; + name: string; + email: string; + type: EmergencyAccessType; + status: EmergencyAccessStatusType; + waitTimeDays: number; + creationDate: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.grantorId = this.getResponseProperty('GrantorId'); - this.name = this.getResponseProperty('Name'); - this.email = this.getResponseProperty('Email'); - this.type = this.getResponseProperty('Type'); - this.status = this.getResponseProperty('Status'); - this.waitTimeDays = this.getResponseProperty('WaitTimeDays'); - this.creationDate = this.getResponseProperty('CreationDate'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.grantorId = this.getResponseProperty("GrantorId"); + this.name = this.getResponseProperty("Name"); + this.email = this.getResponseProperty("Email"); + this.type = this.getResponseProperty("Type"); + this.status = this.getResponseProperty("Status"); + this.waitTimeDays = this.getResponseProperty("WaitTimeDays"); + this.creationDate = this.getResponseProperty("CreationDate"); + } } export class EmergencyAccessTakeoverResponse extends BaseResponse { - keyEncrypted: string; - kdf: KdfType; - kdfIterations: number; + keyEncrypted: string; + kdf: KdfType; + kdfIterations: number; - constructor(response: any) { - super(response); + constructor(response: any) { + super(response); - this.keyEncrypted = this.getResponseProperty('KeyEncrypted'); - this.kdf = this.getResponseProperty('Kdf'); - this.kdfIterations = this.getResponseProperty('KdfIterations'); - } + this.keyEncrypted = this.getResponseProperty("KeyEncrypted"); + this.kdf = this.getResponseProperty("Kdf"); + this.kdfIterations = this.getResponseProperty("KdfIterations"); + } } export class EmergencyAccessViewResponse extends BaseResponse { - keyEncrypted: string; - ciphers: CipherResponse[] = []; + keyEncrypted: string; + ciphers: CipherResponse[] = []; - constructor(response: any) { - super(response); + constructor(response: any) { + super(response); - this.keyEncrypted = this.getResponseProperty('KeyEncrypted'); + this.keyEncrypted = this.getResponseProperty("KeyEncrypted"); - const ciphers = this.getResponseProperty('Ciphers'); - if (ciphers != null) { - this.ciphers = ciphers.map((c: any) => new CipherResponse(c)); - } + const ciphers = this.getResponseProperty("Ciphers"); + if (ciphers != null) { + this.ciphers = ciphers.map((c: any) => new CipherResponse(c)); } + } } diff --git a/common/src/models/response/errorResponse.ts b/common/src/models/response/errorResponse.ts index bac1ff12..6e19ace9 100644 --- a/common/src/models/response/errorResponse.ts +++ b/common/src/models/response/errorResponse.ts @@ -1,72 +1,72 @@ -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class ErrorResponse extends BaseResponse { - message: string; - validationErrors: { [key: string]: string[]; }; - statusCode: number; - captchaRequired: boolean; - captchaSiteKey: string; + message: string; + validationErrors: { [key: string]: string[] }; + statusCode: number; + captchaRequired: boolean; + captchaSiteKey: string; - constructor(response: any, status: number, identityResponse?: boolean) { - super(response); - let errorModel = null; - if (response != null) { - const responseErrorModel = this.getResponseProperty('ErrorModel'); - if (responseErrorModel && identityResponse) { - errorModel = responseErrorModel; - } else { - errorModel = response; - } - } - - if (errorModel) { - this.message = this.getResponseProperty('Message', errorModel); - this.validationErrors = this.getResponseProperty('ValidationErrors', errorModel); - this.captchaSiteKey = this.validationErrors?.HCaptcha_SiteKey?.[0]; - this.captchaRequired = !Utils.isNullOrWhitespace(this.captchaSiteKey); - } else { - if (status === 429) { - this.message = 'Rate limit exceeded. Try again later.'; - } - } - this.statusCode = status; + constructor(response: any, status: number, identityResponse?: boolean) { + super(response); + let errorModel = null; + if (response != null) { + const responseErrorModel = this.getResponseProperty("ErrorModel"); + if (responseErrorModel && identityResponse) { + errorModel = responseErrorModel; + } else { + errorModel = response; + } } - getSingleMessage(): string { - if (this.validationErrors == null) { - return this.message; - } - for (const key in this.validationErrors) { - if (!this.validationErrors.hasOwnProperty(key)) { - continue; - } - if (this.validationErrors[key].length) { - return this.validationErrors[key][0]; - } - } - return this.message; + if (errorModel) { + this.message = this.getResponseProperty("Message", errorModel); + this.validationErrors = this.getResponseProperty("ValidationErrors", errorModel); + this.captchaSiteKey = this.validationErrors?.HCaptcha_SiteKey?.[0]; + this.captchaRequired = !Utils.isNullOrWhitespace(this.captchaSiteKey); + } else { + if (status === 429) { + this.message = "Rate limit exceeded. Try again later."; + } } + this.statusCode = status; + } - getAllMessages(): string[] { - const messages: string[] = []; - if (this.validationErrors == null) { - return messages; - } - for (const key in this.validationErrors) { - if (!this.validationErrors.hasOwnProperty(key)) { - continue; - } - this.validationErrors[key].forEach((item: string) => { - let prefix = ''; - if (key.indexOf('[') > -1 && key.indexOf(']') > -1) { - const lastSep = key.lastIndexOf('.'); - prefix = key.substr(0, lastSep > -1 ? lastSep : key.length) + ': '; - } - messages.push(prefix + item); - }); - } - return messages; + getSingleMessage(): string { + if (this.validationErrors == null) { + return this.message; } + for (const key in this.validationErrors) { + if (!this.validationErrors.hasOwnProperty(key)) { + continue; + } + if (this.validationErrors[key].length) { + return this.validationErrors[key][0]; + } + } + return this.message; + } + + getAllMessages(): string[] { + const messages: string[] = []; + if (this.validationErrors == null) { + return messages; + } + for (const key in this.validationErrors) { + if (!this.validationErrors.hasOwnProperty(key)) { + continue; + } + this.validationErrors[key].forEach((item: string) => { + let prefix = ""; + if (key.indexOf("[") > -1 && key.indexOf("]") > -1) { + const lastSep = key.lastIndexOf("."); + prefix = key.substr(0, lastSep > -1 ? lastSep : key.length) + ": "; + } + messages.push(prefix + item); + }); + } + return messages; + } } diff --git a/common/src/models/response/eventResponse.ts b/common/src/models/response/eventResponse.ts index ef7ab807..b56e172c 100644 --- a/common/src/models/response/eventResponse.ts +++ b/common/src/models/response/eventResponse.ts @@ -1,41 +1,41 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { DeviceType } from '../../enums/deviceType'; -import { EventType } from '../../enums/eventType'; +import { DeviceType } from "../../enums/deviceType"; +import { EventType } from "../../enums/eventType"; export class EventResponse extends BaseResponse { - type: EventType; - userId: string; - organizationId: string; - providerId: string; - cipherId: string; - collectionId: string; - groupId: string; - policyId: string; - organizationUserId: string; - providerUserId: string; - providerOrganizationId: string; - actingUserId: string; - date: string; - deviceType: DeviceType; - ipAddress: string; + type: EventType; + userId: string; + organizationId: string; + providerId: string; + cipherId: string; + collectionId: string; + groupId: string; + policyId: string; + organizationUserId: string; + providerUserId: string; + providerOrganizationId: string; + actingUserId: string; + date: string; + deviceType: DeviceType; + ipAddress: string; - constructor(response: any) { - super(response); - this.type = this.getResponseProperty('Type'); - this.userId = this.getResponseProperty('UserId'); - this.organizationId = this.getResponseProperty('OrganizationId'); - this.providerId = this.getResponseProperty('ProviderId'); - this.cipherId = this.getResponseProperty('CipherId'); - this.collectionId = this.getResponseProperty('CollectionId'); - this.groupId = this.getResponseProperty('GroupId'); - this.policyId = this.getResponseProperty('PolicyId'); - this.organizationUserId = this.getResponseProperty('OrganizationUserId'); - this.providerUserId = this.getResponseProperty('ProviderUserId'); - this.providerOrganizationId = this.getResponseProperty('ProviderOrganizationId'); - this.actingUserId = this.getResponseProperty('ActingUserId'); - this.date = this.getResponseProperty('Date'); - this.deviceType = this.getResponseProperty('DeviceType'); - this.ipAddress = this.getResponseProperty('IpAddress'); - } + constructor(response: any) { + super(response); + this.type = this.getResponseProperty("Type"); + this.userId = this.getResponseProperty("UserId"); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.providerId = this.getResponseProperty("ProviderId"); + this.cipherId = this.getResponseProperty("CipherId"); + this.collectionId = this.getResponseProperty("CollectionId"); + this.groupId = this.getResponseProperty("GroupId"); + this.policyId = this.getResponseProperty("PolicyId"); + this.organizationUserId = this.getResponseProperty("OrganizationUserId"); + this.providerUserId = this.getResponseProperty("ProviderUserId"); + this.providerOrganizationId = this.getResponseProperty("ProviderOrganizationId"); + this.actingUserId = this.getResponseProperty("ActingUserId"); + this.date = this.getResponseProperty("Date"); + this.deviceType = this.getResponseProperty("DeviceType"); + this.ipAddress = this.getResponseProperty("IpAddress"); + } } diff --git a/common/src/models/response/folderResponse.ts b/common/src/models/response/folderResponse.ts index 00b3d3d8..70d4897f 100644 --- a/common/src/models/response/folderResponse.ts +++ b/common/src/models/response/folderResponse.ts @@ -1,14 +1,14 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class FolderResponse extends BaseResponse { - id: string; - name: string; - revisionDate: string; + id: string; + name: string; + revisionDate: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.name = this.getResponseProperty('Name'); - this.revisionDate = this.getResponseProperty('RevisionDate'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.name = this.getResponseProperty("Name"); + this.revisionDate = this.getResponseProperty("RevisionDate"); + } } diff --git a/common/src/models/response/globalDomainResponse.ts b/common/src/models/response/globalDomainResponse.ts index 861282a9..e3197e76 100644 --- a/common/src/models/response/globalDomainResponse.ts +++ b/common/src/models/response/globalDomainResponse.ts @@ -1,14 +1,14 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class GlobalDomainResponse extends BaseResponse { - type: number; - domains: string[]; - excluded: boolean; + type: number; + domains: string[]; + excluded: boolean; - constructor(response: any) { - super(response); - this.type = this.getResponseProperty('Type'); - this.domains = this.getResponseProperty('Domains'); - this.excluded = this.getResponseProperty('Excluded'); - } + constructor(response: any) { + super(response); + this.type = this.getResponseProperty("Type"); + this.domains = this.getResponseProperty("Domains"); + this.excluded = this.getResponseProperty("Excluded"); + } } diff --git a/common/src/models/response/groupResponse.ts b/common/src/models/response/groupResponse.ts index 2c3cf119..ab4b58b7 100644 --- a/common/src/models/response/groupResponse.ts +++ b/common/src/models/response/groupResponse.ts @@ -1,31 +1,31 @@ -import { BaseResponse } from './baseResponse'; -import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse'; +import { BaseResponse } from "./baseResponse"; +import { SelectionReadOnlyResponse } from "./selectionReadOnlyResponse"; export class GroupResponse extends BaseResponse { - id: string; - organizationId: string; - name: string; - accessAll: boolean; - externalId: string; + id: string; + organizationId: string; + name: string; + accessAll: boolean; + externalId: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.organizationId = this.getResponseProperty('OrganizationId'); - this.name = this.getResponseProperty('Name'); - this.accessAll = this.getResponseProperty('AccessAll'); - this.externalId = this.getResponseProperty('ExternalId'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.name = this.getResponseProperty("Name"); + this.accessAll = this.getResponseProperty("AccessAll"); + this.externalId = this.getResponseProperty("ExternalId"); + } } export class GroupDetailsResponse extends GroupResponse { - collections: SelectionReadOnlyResponse[] = []; + collections: SelectionReadOnlyResponse[] = []; - constructor(response: any) { - super(response); - const collections = this.getResponseProperty('Collections'); - if (collections != null) { - this.collections = collections.map((c: any) => new SelectionReadOnlyResponse(c)); - } + constructor(response: any) { + super(response); + const collections = this.getResponseProperty("Collections"); + if (collections != null) { + this.collections = collections.map((c: any) => new SelectionReadOnlyResponse(c)); } + } } diff --git a/common/src/models/response/identityCaptchaResponse.ts b/common/src/models/response/identityCaptchaResponse.ts index 082423e3..2537057e 100644 --- a/common/src/models/response/identityCaptchaResponse.ts +++ b/common/src/models/response/identityCaptchaResponse.ts @@ -1,10 +1,10 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class IdentityCaptchaResponse extends BaseResponse { - siteKey: string; + siteKey: string; - constructor(response: any) { - super(response); - this.siteKey = this.getResponseProperty('HCaptcha_SiteKey'); - } + constructor(response: any) { + super(response); + this.siteKey = this.getResponseProperty("HCaptcha_SiteKey"); + } } diff --git a/common/src/models/response/identityTokenResponse.ts b/common/src/models/response/identityTokenResponse.ts index c2283956..f17e144a 100644 --- a/common/src/models/response/identityTokenResponse.ts +++ b/common/src/models/response/identityTokenResponse.ts @@ -1,38 +1,38 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { KdfType } from '../../enums/kdfType'; +import { KdfType } from "../../enums/kdfType"; export class IdentityTokenResponse extends BaseResponse { - accessToken: string; - expiresIn: number; - refreshToken: string; - tokenType: string; + accessToken: string; + expiresIn: number; + refreshToken: string; + tokenType: string; - resetMasterPassword: boolean; - privateKey: string; - key: string; - twoFactorToken: string; - kdf: KdfType; - kdfIterations: number; - forcePasswordReset: boolean; - apiUseKeyConnector: boolean; - keyConnectorUrl: string; + resetMasterPassword: boolean; + privateKey: string; + key: string; + twoFactorToken: string; + kdf: KdfType; + kdfIterations: number; + forcePasswordReset: boolean; + apiUseKeyConnector: boolean; + keyConnectorUrl: string; - constructor(response: any) { - super(response); - this.accessToken = response.access_token; - this.expiresIn = response.expires_in; - this.refreshToken = response.refresh_token; - this.tokenType = response.token_type; + constructor(response: any) { + super(response); + this.accessToken = response.access_token; + this.expiresIn = response.expires_in; + this.refreshToken = response.refresh_token; + this.tokenType = response.token_type; - this.resetMasterPassword = this.getResponseProperty('ResetMasterPassword'); - this.privateKey = this.getResponseProperty('PrivateKey'); - this.key = this.getResponseProperty('Key'); - this.twoFactorToken = this.getResponseProperty('TwoFactorToken'); - this.kdf = this.getResponseProperty('Kdf'); - this.kdfIterations = this.getResponseProperty('KdfIterations'); - this.forcePasswordReset = this.getResponseProperty('ForcePasswordReset'); - this.apiUseKeyConnector = this.getResponseProperty('ApiUseKeyConnector'); - this.keyConnectorUrl = this.getResponseProperty('KeyConnectorUrl'); - } + this.resetMasterPassword = this.getResponseProperty("ResetMasterPassword"); + this.privateKey = this.getResponseProperty("PrivateKey"); + this.key = this.getResponseProperty("Key"); + this.twoFactorToken = this.getResponseProperty("TwoFactorToken"); + this.kdf = this.getResponseProperty("Kdf"); + this.kdfIterations = this.getResponseProperty("KdfIterations"); + this.forcePasswordReset = this.getResponseProperty("ForcePasswordReset"); + this.apiUseKeyConnector = this.getResponseProperty("ApiUseKeyConnector"); + this.keyConnectorUrl = this.getResponseProperty("KeyConnectorUrl"); + } } diff --git a/common/src/models/response/identityTwoFactorResponse.ts b/common/src/models/response/identityTwoFactorResponse.ts index 92886a40..bb826537 100644 --- a/common/src/models/response/identityTwoFactorResponse.ts +++ b/common/src/models/response/identityTwoFactorResponse.ts @@ -1,23 +1,23 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; +import { TwoFactorProviderType } from "../../enums/twoFactorProviderType"; export class IdentityTwoFactorResponse extends BaseResponse { - twoFactorProviders: TwoFactorProviderType[]; - twoFactorProviders2 = new Map(); - captchaToken: string; + twoFactorProviders: TwoFactorProviderType[]; + twoFactorProviders2 = new Map(); + captchaToken: string; - constructor(response: any) { - super(response); - this.captchaToken = this.getResponseProperty('CaptchaBypassToken'); - this.twoFactorProviders = this.getResponseProperty('TwoFactorProviders'); - const twoFactorProviders2 = this.getResponseProperty('TwoFactorProviders2'); - if (twoFactorProviders2 != null) { - for (const prop in twoFactorProviders2) { - if (twoFactorProviders2.hasOwnProperty(prop)) { - this.twoFactorProviders2.set(parseInt(prop, null), twoFactorProviders2[prop]); - } - } + constructor(response: any) { + super(response); + this.captchaToken = this.getResponseProperty("CaptchaBypassToken"); + this.twoFactorProviders = this.getResponseProperty("TwoFactorProviders"); + const twoFactorProviders2 = this.getResponseProperty("TwoFactorProviders2"); + if (twoFactorProviders2 != null) { + for (const prop in twoFactorProviders2) { + if (twoFactorProviders2.hasOwnProperty(prop)) { + this.twoFactorProviders2.set(parseInt(prop, null), twoFactorProviders2[prop]); } + } } + } } diff --git a/common/src/models/response/keyConnectorUserKeyResponse.ts b/common/src/models/response/keyConnectorUserKeyResponse.ts index 4da60be3..5183397b 100644 --- a/common/src/models/response/keyConnectorUserKeyResponse.ts +++ b/common/src/models/response/keyConnectorUserKeyResponse.ts @@ -1,10 +1,10 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class KeyConnectorUserKeyResponse extends BaseResponse { - key: string; + key: string; - constructor(response: any) { - super(response); - this.key = this.getResponseProperty('Key'); - } + constructor(response: any) { + super(response); + this.key = this.getResponseProperty("Key"); + } } diff --git a/common/src/models/response/keysResponse.ts b/common/src/models/response/keysResponse.ts index 405edcdc..e1e8e5db 100644 --- a/common/src/models/response/keysResponse.ts +++ b/common/src/models/response/keysResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class KeysResponse extends BaseResponse { - privateKey: string; - publicKey: string; + privateKey: string; + publicKey: string; - constructor(response: any) { - super(response); - this.privateKey = this.getResponseProperty('PrivateKey'); - this.publicKey = this.getResponseProperty('PublicKey'); - } + constructor(response: any) { + super(response); + this.privateKey = this.getResponseProperty("PrivateKey"); + this.publicKey = this.getResponseProperty("PublicKey"); + } } diff --git a/common/src/models/response/listResponse.ts b/common/src/models/response/listResponse.ts index 3b15a3f5..e37c6697 100644 --- a/common/src/models/response/listResponse.ts +++ b/common/src/models/response/listResponse.ts @@ -1,13 +1,13 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class ListResponse extends BaseResponse { - data: T[]; - continuationToken: string; + data: T[]; + continuationToken: string; - constructor(response: any, t: new (dataResponse: any) => T) { - super(response); - const data = this.getResponseProperty('Data'); - this.data = data == null ? [] : data.map((dr: any) => new t(dr)); - this.continuationToken = this.getResponseProperty('ContinuationToken'); - } + constructor(response: any, t: new (dataResponse: any) => T) { + super(response); + const data = this.getResponseProperty("Data"); + this.data = data == null ? [] : data.map((dr: any) => new t(dr)); + this.continuationToken = this.getResponseProperty("ContinuationToken"); + } } diff --git a/common/src/models/response/notificationResponse.ts b/common/src/models/response/notificationResponse.ts index b60f38a6..79bbdb0e 100644 --- a/common/src/models/response/notificationResponse.ts +++ b/common/src/models/response/notificationResponse.ts @@ -1,97 +1,97 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { NotificationType } from '../../enums/notificationType'; +import { NotificationType } from "../../enums/notificationType"; export class NotificationResponse extends BaseResponse { - contextId: string; - type: NotificationType; - payload: any; + contextId: string; + type: NotificationType; + payload: any; - constructor(response: any) { - super(response); - this.contextId = this.getResponseProperty('ContextId'); - this.type = this.getResponseProperty('Type'); + constructor(response: any) { + super(response); + this.contextId = this.getResponseProperty("ContextId"); + this.type = this.getResponseProperty("Type"); - const payload = this.getResponseProperty('Payload'); - switch (this.type) { - case NotificationType.SyncCipherCreate: - case NotificationType.SyncCipherDelete: - case NotificationType.SyncCipherUpdate: - case NotificationType.SyncLoginDelete: - this.payload = new SyncCipherNotification(payload); - break; - case NotificationType.SyncFolderCreate: - case NotificationType.SyncFolderDelete: - case NotificationType.SyncFolderUpdate: - this.payload = new SyncFolderNotification(payload); - break; - case NotificationType.SyncVault: - case NotificationType.SyncCiphers: - case NotificationType.SyncOrgKeys: - case NotificationType.SyncSettings: - case NotificationType.LogOut: - this.payload = new UserNotification(payload); - break; - case NotificationType.SyncSendCreate: - case NotificationType.SyncSendUpdate: - case NotificationType.SyncSendDelete: - this.payload = new SyncSendNotification(payload); - default: - break; - } + const payload = this.getResponseProperty("Payload"); + switch (this.type) { + case NotificationType.SyncCipherCreate: + case NotificationType.SyncCipherDelete: + case NotificationType.SyncCipherUpdate: + case NotificationType.SyncLoginDelete: + this.payload = new SyncCipherNotification(payload); + break; + case NotificationType.SyncFolderCreate: + case NotificationType.SyncFolderDelete: + case NotificationType.SyncFolderUpdate: + this.payload = new SyncFolderNotification(payload); + break; + case NotificationType.SyncVault: + case NotificationType.SyncCiphers: + case NotificationType.SyncOrgKeys: + case NotificationType.SyncSettings: + case NotificationType.LogOut: + this.payload = new UserNotification(payload); + break; + case NotificationType.SyncSendCreate: + case NotificationType.SyncSendUpdate: + case NotificationType.SyncSendDelete: + this.payload = new SyncSendNotification(payload); + default: + break; } + } } export class SyncCipherNotification extends BaseResponse { - id: string; - userId: string; - organizationId: string; - collectionIds: string[]; - revisionDate: Date; + id: string; + userId: string; + organizationId: string; + collectionIds: string[]; + revisionDate: Date; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.userId = this.getResponseProperty('UserId'); - this.organizationId = this.getResponseProperty('OrganizationId'); - this.collectionIds = this.getResponseProperty('CollectionIds'); - this.revisionDate = new Date(this.getResponseProperty('RevisionDate')); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.userId = this.getResponseProperty("UserId"); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.collectionIds = this.getResponseProperty("CollectionIds"); + this.revisionDate = new Date(this.getResponseProperty("RevisionDate")); + } } export class SyncFolderNotification extends BaseResponse { - id: string; - userId: string; - revisionDate: Date; + id: string; + userId: string; + revisionDate: Date; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.userId = this.getResponseProperty('UserId'); - this.revisionDate = new Date(this.getResponseProperty('RevisionDate')); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.userId = this.getResponseProperty("UserId"); + this.revisionDate = new Date(this.getResponseProperty("RevisionDate")); + } } export class UserNotification extends BaseResponse { - userId: string; - date: Date; + userId: string; + date: Date; - constructor(response: any) { - super(response); - this.userId = this.getResponseProperty('UserId'); - this.date = new Date(this.getResponseProperty('Date')); - } + constructor(response: any) { + super(response); + this.userId = this.getResponseProperty("UserId"); + this.date = new Date(this.getResponseProperty("Date")); + } } export class SyncSendNotification extends BaseResponse { - id: string; - userId: string; - revisionDate: Date; + id: string; + userId: string; + revisionDate: Date; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.userId = this.getResponseProperty('UserId'); - this.revisionDate = new Date(this.getResponseProperty('RevisionDate')); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.userId = this.getResponseProperty("UserId"); + this.revisionDate = new Date(this.getResponseProperty("RevisionDate")); + } } diff --git a/common/src/models/response/organization/organizationSsoResponse.ts b/common/src/models/response/organization/organizationSsoResponse.ts index 46709d61..71432912 100644 --- a/common/src/models/response/organization/organizationSsoResponse.ts +++ b/common/src/models/response/organization/organizationSsoResponse.ts @@ -1,32 +1,32 @@ -import { SsoConfigApi } from '../../api/ssoConfigApi'; -import { BaseResponse } from '../baseResponse'; +import { SsoConfigApi } from "../../api/ssoConfigApi"; +import { BaseResponse } from "../baseResponse"; export class OrganizationSsoResponse extends BaseResponse { - enabled: boolean; - data: SsoConfigApi; - urls: SsoUrls; + enabled: boolean; + data: SsoConfigApi; + urls: SsoUrls; - constructor(response: any) { - super(response); - this.enabled = this.getResponseProperty('Enabled'); - this.data = new SsoConfigApi(this.getResponseProperty('Data')); - this.urls = new SsoUrls(this.getResponseProperty('Urls')); - } + constructor(response: any) { + super(response); + this.enabled = this.getResponseProperty("Enabled"); + this.data = new SsoConfigApi(this.getResponseProperty("Data")); + this.urls = new SsoUrls(this.getResponseProperty("Urls")); + } } class SsoUrls extends BaseResponse { - callbackPath: string; - signedOutCallbackPath: string; - spEntityId: string; - spMetadataUrl: string; - spAcsUrl: string; + callbackPath: string; + signedOutCallbackPath: string; + spEntityId: string; + spMetadataUrl: string; + spAcsUrl: string; - constructor(response: any) { - super(response); - this.callbackPath = this.getResponseProperty('CallbackPath'); - this.signedOutCallbackPath = this.getResponseProperty('SignedOutCallbackPath'); - this.spEntityId = this.getResponseProperty('SpEntityId'); - this.spMetadataUrl = this.getResponseProperty('SpMetadataUrl'); - this.spAcsUrl = this.getResponseProperty('SpAcsUrl'); - } + constructor(response: any) { + super(response); + this.callbackPath = this.getResponseProperty("CallbackPath"); + this.signedOutCallbackPath = this.getResponseProperty("SignedOutCallbackPath"); + this.spEntityId = this.getResponseProperty("SpEntityId"); + this.spMetadataUrl = this.getResponseProperty("SpMetadataUrl"); + this.spAcsUrl = this.getResponseProperty("SpAcsUrl"); + } } diff --git a/common/src/models/response/organizationAutoEnrollStatusResponse.ts b/common/src/models/response/organizationAutoEnrollStatusResponse.ts index 1f9f77b5..d960463e 100644 --- a/common/src/models/response/organizationAutoEnrollStatusResponse.ts +++ b/common/src/models/response/organizationAutoEnrollStatusResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class OrganizationAutoEnrollStatusResponse extends BaseResponse { - id: string; - resetPasswordEnabled: boolean; + id: string; + resetPasswordEnabled: boolean; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.resetPasswordEnabled = this.getResponseProperty('ResetPasswordEnabled'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.resetPasswordEnabled = this.getResponseProperty("ResetPasswordEnabled"); + } } diff --git a/common/src/models/response/organizationKeysResponse.ts b/common/src/models/response/organizationKeysResponse.ts index a5ed77d3..3d5c0d29 100644 --- a/common/src/models/response/organizationKeysResponse.ts +++ b/common/src/models/response/organizationKeysResponse.ts @@ -1,7 +1,7 @@ -import { KeysResponse } from './keysResponse'; +import { KeysResponse } from "./keysResponse"; export class OrganizationKeysResponse extends KeysResponse { - constructor(response: any) { - super(response); - } + constructor(response: any) { + super(response); + } } diff --git a/common/src/models/response/organizationResponse.ts b/common/src/models/response/organizationResponse.ts index 0965bea9..c1938253 100644 --- a/common/src/models/response/organizationResponse.ts +++ b/common/src/models/response/organizationResponse.ts @@ -1,60 +1,60 @@ -import { BaseResponse } from './baseResponse'; -import { PlanResponse } from './planResponse'; +import { BaseResponse } from "./baseResponse"; +import { PlanResponse } from "./planResponse"; -import { PlanType } from '../../enums/planType'; +import { PlanType } from "../../enums/planType"; export class OrganizationResponse extends BaseResponse { - id: string; - identifier: string; - name: string; - businessName: string; - businessAddress1: string; - businessAddress2: string; - businessAddress3: string; - businessCountry: string; - businessTaxNumber: string; - billingEmail: string; - plan: PlanResponse; - planType: PlanType; - seats: number; - maxAutoscaleSeats: number; - maxCollections: number; - maxStorageGb: number; - useGroups: boolean; - useDirectory: boolean; - useEvents: boolean; - useTotp: boolean; - use2fa: boolean; - useApi: boolean; - useResetPassword: boolean; - hasPublicAndPrivateKeys: boolean; + id: string; + identifier: string; + name: string; + businessName: string; + businessAddress1: string; + businessAddress2: string; + businessAddress3: string; + businessCountry: string; + businessTaxNumber: string; + billingEmail: string; + plan: PlanResponse; + planType: PlanType; + seats: number; + maxAutoscaleSeats: number; + maxCollections: number; + maxStorageGb: number; + useGroups: boolean; + useDirectory: boolean; + useEvents: boolean; + useTotp: boolean; + use2fa: boolean; + useApi: boolean; + useResetPassword: boolean; + hasPublicAndPrivateKeys: boolean; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.identifier = this.getResponseProperty('Identifier'); - this.name = this.getResponseProperty('Name'); - this.businessName = this.getResponseProperty('BusinessName'); - this.businessAddress1 = this.getResponseProperty('BusinessAddress1'); - this.businessAddress2 = this.getResponseProperty('BusinessAddress2'); - this.businessAddress3 = this.getResponseProperty('BusinessAddress3'); - this.businessCountry = this.getResponseProperty('BusinessCountry'); - this.businessTaxNumber = this.getResponseProperty('BusinessTaxNumber'); - this.billingEmail = this.getResponseProperty('BillingEmail'); - const plan = this.getResponseProperty('Plan'); - this.plan = plan == null ? null : new PlanResponse(plan); - this.planType = this.getResponseProperty('PlanType'); - this.seats = this.getResponseProperty('Seats'); - this.maxAutoscaleSeats = this.getResponseProperty('MaxAutoscaleSeats'); - this.maxCollections = this.getResponseProperty('MaxCollections'); - this.maxStorageGb = this.getResponseProperty('MaxStorageGb'); - this.useGroups = this.getResponseProperty('UseGroups'); - this.useDirectory = this.getResponseProperty('UseDirectory'); - this.useEvents = this.getResponseProperty('UseEvents'); - this.useTotp = this.getResponseProperty('UseTotp'); - this.use2fa = this.getResponseProperty('Use2fa'); - this.useApi = this.getResponseProperty('UseApi'); - this.useResetPassword = this.getResponseProperty('UseResetPassword'); - this.hasPublicAndPrivateKeys = this.getResponseProperty('HasPublicAndPrivateKeys'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.identifier = this.getResponseProperty("Identifier"); + this.name = this.getResponseProperty("Name"); + this.businessName = this.getResponseProperty("BusinessName"); + this.businessAddress1 = this.getResponseProperty("BusinessAddress1"); + this.businessAddress2 = this.getResponseProperty("BusinessAddress2"); + this.businessAddress3 = this.getResponseProperty("BusinessAddress3"); + this.businessCountry = this.getResponseProperty("BusinessCountry"); + this.businessTaxNumber = this.getResponseProperty("BusinessTaxNumber"); + this.billingEmail = this.getResponseProperty("BillingEmail"); + const plan = this.getResponseProperty("Plan"); + this.plan = plan == null ? null : new PlanResponse(plan); + this.planType = this.getResponseProperty("PlanType"); + this.seats = this.getResponseProperty("Seats"); + this.maxAutoscaleSeats = this.getResponseProperty("MaxAutoscaleSeats"); + this.maxCollections = this.getResponseProperty("MaxCollections"); + this.maxStorageGb = this.getResponseProperty("MaxStorageGb"); + this.useGroups = this.getResponseProperty("UseGroups"); + this.useDirectory = this.getResponseProperty("UseDirectory"); + this.useEvents = this.getResponseProperty("UseEvents"); + this.useTotp = this.getResponseProperty("UseTotp"); + this.use2fa = this.getResponseProperty("Use2fa"); + this.useApi = this.getResponseProperty("UseApi"); + this.useResetPassword = this.getResponseProperty("UseResetPassword"); + this.hasPublicAndPrivateKeys = this.getResponseProperty("HasPublicAndPrivateKeys"); + } } diff --git a/common/src/models/response/organizationSubscriptionResponse.ts b/common/src/models/response/organizationSubscriptionResponse.ts index 9fbd16d5..1985dc6e 100644 --- a/common/src/models/response/organizationSubscriptionResponse.ts +++ b/common/src/models/response/organizationSubscriptionResponse.ts @@ -1,25 +1,27 @@ -import { OrganizationResponse } from './organizationResponse'; +import { OrganizationResponse } from "./organizationResponse"; import { - BillingSubscriptionResponse, - BillingSubscriptionUpcomingInvoiceResponse, -} from './subscriptionResponse'; + BillingSubscriptionResponse, + BillingSubscriptionUpcomingInvoiceResponse, +} from "./subscriptionResponse"; export class OrganizationSubscriptionResponse extends OrganizationResponse { - storageName: string; - storageGb: number; - subscription: BillingSubscriptionResponse; - upcomingInvoice: BillingSubscriptionUpcomingInvoiceResponse; - expiration: string; + storageName: string; + storageGb: number; + subscription: BillingSubscriptionResponse; + upcomingInvoice: BillingSubscriptionUpcomingInvoiceResponse; + expiration: string; - constructor(response: any) { - super(response); - this.storageName = this.getResponseProperty('StorageName'); - this.storageGb = this.getResponseProperty('StorageGb'); - const subscription = this.getResponseProperty('Subscription'); - this.subscription = subscription == null ? null : new BillingSubscriptionResponse(subscription); - const upcomingInvoice = this.getResponseProperty('UpcomingInvoice'); - this.upcomingInvoice = upcomingInvoice == null ? null : - new BillingSubscriptionUpcomingInvoiceResponse(upcomingInvoice); - this.expiration = this.getResponseProperty('Expiration'); - } + constructor(response: any) { + super(response); + this.storageName = this.getResponseProperty("StorageName"); + this.storageGb = this.getResponseProperty("StorageGb"); + const subscription = this.getResponseProperty("Subscription"); + this.subscription = subscription == null ? null : new BillingSubscriptionResponse(subscription); + const upcomingInvoice = this.getResponseProperty("UpcomingInvoice"); + this.upcomingInvoice = + upcomingInvoice == null + ? null + : new BillingSubscriptionUpcomingInvoiceResponse(upcomingInvoice); + this.expiration = this.getResponseProperty("Expiration"); + } } diff --git a/common/src/models/response/organizationUserBulkPublicKeyResponse.ts b/common/src/models/response/organizationUserBulkPublicKeyResponse.ts index f5891c10..1b77e036 100644 --- a/common/src/models/response/organizationUserBulkPublicKeyResponse.ts +++ b/common/src/models/response/organizationUserBulkPublicKeyResponse.ts @@ -1,14 +1,14 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class OrganizationUserBulkPublicKeyResponse extends BaseResponse { - id: string; - userId: string; - key: string; + id: string; + userId: string; + key: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.userId = this.getResponseProperty('UserId'); - this.key = this.getResponseProperty('Key'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.userId = this.getResponseProperty("UserId"); + this.key = this.getResponseProperty("Key"); + } } diff --git a/common/src/models/response/organizationUserBulkResponse.ts b/common/src/models/response/organizationUserBulkResponse.ts index eeee2c8f..15c6f371 100644 --- a/common/src/models/response/organizationUserBulkResponse.ts +++ b/common/src/models/response/organizationUserBulkResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class OrganizationUserBulkResponse extends BaseResponse { - id: string; - error: string; + id: string; + error: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.error = this.getResponseProperty('Error'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.error = this.getResponseProperty("Error"); + } } diff --git a/common/src/models/response/organizationUserResponse.ts b/common/src/models/response/organizationUserResponse.ts index 3b155f01..493d2661 100644 --- a/common/src/models/response/organizationUserResponse.ts +++ b/common/src/models/response/organizationUserResponse.ts @@ -1,71 +1,71 @@ -import { BaseResponse } from './baseResponse'; -import { SelectionReadOnlyResponse } from './selectionReadOnlyResponse'; +import { BaseResponse } from "./baseResponse"; +import { SelectionReadOnlyResponse } from "./selectionReadOnlyResponse"; -import { PermissionsApi } from '../api/permissionsApi'; +import { PermissionsApi } from "../api/permissionsApi"; -import { KdfType } from '../../enums/kdfType'; -import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType'; -import { OrganizationUserType } from '../../enums/organizationUserType'; +import { KdfType } from "../../enums/kdfType"; +import { OrganizationUserStatusType } from "../../enums/organizationUserStatusType"; +import { OrganizationUserType } from "../../enums/organizationUserType"; export class OrganizationUserResponse extends BaseResponse { - id: string; - userId: string; - type: OrganizationUserType; - status: OrganizationUserStatusType; - accessAll: boolean; - permissions: PermissionsApi; - resetPasswordEnrolled: boolean; + id: string; + userId: string; + type: OrganizationUserType; + status: OrganizationUserStatusType; + accessAll: boolean; + permissions: PermissionsApi; + resetPasswordEnrolled: boolean; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.userId = this.getResponseProperty('UserId'); - this.type = this.getResponseProperty('Type'); - this.status = this.getResponseProperty('Status'); - this.permissions = new PermissionsApi(this.getResponseProperty('Permissions')); - this.accessAll = this.getResponseProperty('AccessAll'); - this.resetPasswordEnrolled = this.getResponseProperty('ResetPasswordEnrolled'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.userId = this.getResponseProperty("UserId"); + this.type = this.getResponseProperty("Type"); + this.status = this.getResponseProperty("Status"); + this.permissions = new PermissionsApi(this.getResponseProperty("Permissions")); + this.accessAll = this.getResponseProperty("AccessAll"); + this.resetPasswordEnrolled = this.getResponseProperty("ResetPasswordEnrolled"); + } } export class OrganizationUserUserDetailsResponse extends OrganizationUserResponse { - name: string; - email: string; - twoFactorEnabled: boolean; - usesKeyConnector: boolean; + name: string; + email: string; + twoFactorEnabled: boolean; + usesKeyConnector: boolean; - constructor(response: any) { - super(response); - this.name = this.getResponseProperty('Name'); - this.email = this.getResponseProperty('Email'); - this.twoFactorEnabled = this.getResponseProperty('TwoFactorEnabled'); - this.usesKeyConnector = this.getResponseProperty('UsesKeyConnector') ?? false; - } + constructor(response: any) { + super(response); + this.name = this.getResponseProperty("Name"); + this.email = this.getResponseProperty("Email"); + this.twoFactorEnabled = this.getResponseProperty("TwoFactorEnabled"); + this.usesKeyConnector = this.getResponseProperty("UsesKeyConnector") ?? false; + } } export class OrganizationUserDetailsResponse extends OrganizationUserResponse { - collections: SelectionReadOnlyResponse[] = []; + collections: SelectionReadOnlyResponse[] = []; - constructor(response: any) { - super(response); - const collections = this.getResponseProperty('Collections'); - if (collections != null) { - this.collections = collections.map((c: any) => new SelectionReadOnlyResponse(c)); - } + constructor(response: any) { + super(response); + const collections = this.getResponseProperty("Collections"); + if (collections != null) { + this.collections = collections.map((c: any) => new SelectionReadOnlyResponse(c)); } + } } export class OrganizationUserResetPasswordDetailsReponse extends BaseResponse { - kdf: KdfType; - kdfIterations: number; - resetPasswordKey: string; - encryptedPrivateKey: string; + kdf: KdfType; + kdfIterations: number; + resetPasswordKey: string; + encryptedPrivateKey: string; - constructor(response: any) { - super(response); - this.kdf = this.getResponseProperty('Kdf'); - this.kdfIterations = this.getResponseProperty('KdfIterations'); - this.resetPasswordKey = this.getResponseProperty('ResetPasswordKey'); - this.encryptedPrivateKey = this.getResponseProperty('EncryptedPrivateKey'); - } + constructor(response: any) { + super(response); + this.kdf = this.getResponseProperty("Kdf"); + this.kdfIterations = this.getResponseProperty("KdfIterations"); + this.resetPasswordKey = this.getResponseProperty("ResetPasswordKey"); + this.encryptedPrivateKey = this.getResponseProperty("EncryptedPrivateKey"); + } } diff --git a/common/src/models/response/passwordHistoryResponse.ts b/common/src/models/response/passwordHistoryResponse.ts index 805a5668..f3a8a133 100644 --- a/common/src/models/response/passwordHistoryResponse.ts +++ b/common/src/models/response/passwordHistoryResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class PasswordHistoryResponse extends BaseResponse { - password: string; - lastUsedDate: string; + password: string; + lastUsedDate: string; - constructor(response: any) { - super(response); - this.password = this.getResponseProperty('Password'); - this.lastUsedDate = this.getResponseProperty('LastUsedDate'); - } + constructor(response: any) { + super(response); + this.password = this.getResponseProperty("Password"); + this.lastUsedDate = this.getResponseProperty("LastUsedDate"); + } } diff --git a/common/src/models/response/paymentResponse.ts b/common/src/models/response/paymentResponse.ts index f4cc6745..ec4977cd 100644 --- a/common/src/models/response/paymentResponse.ts +++ b/common/src/models/response/paymentResponse.ts @@ -1,18 +1,18 @@ -import { BaseResponse } from './baseResponse'; -import { ProfileResponse } from './profileResponse'; +import { BaseResponse } from "./baseResponse"; +import { ProfileResponse } from "./profileResponse"; export class PaymentResponse extends BaseResponse { - userProfile: ProfileResponse; - paymentIntentClientSecret: string; - success: boolean; + userProfile: ProfileResponse; + paymentIntentClientSecret: string; + success: boolean; - constructor(response: any) { - super(response); - const userProfile = this.getResponseProperty('UserProfile'); - if (userProfile != null) { - this.userProfile = new ProfileResponse(userProfile); - } - this.paymentIntentClientSecret = this.getResponseProperty('PaymentIntentClientSecret'); - this.success = this.getResponseProperty('Success'); + constructor(response: any) { + super(response); + const userProfile = this.getResponseProperty("UserProfile"); + if (userProfile != null) { + this.userProfile = new ProfileResponse(userProfile); } + this.paymentIntentClientSecret = this.getResponseProperty("PaymentIntentClientSecret"); + this.success = this.getResponseProperty("Success"); + } } diff --git a/common/src/models/response/planResponse.ts b/common/src/models/response/planResponse.ts index cd201db9..04652542 100644 --- a/common/src/models/response/planResponse.ts +++ b/common/src/models/response/planResponse.ts @@ -1,95 +1,95 @@ -import { PlanType } from '../../enums/planType'; -import { ProductType } from '../../enums/productType'; +import { PlanType } from "../../enums/planType"; +import { ProductType } from "../../enums/productType"; -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class PlanResponse extends BaseResponse { - type: PlanType; - product: ProductType; - name: string; - isAnnual: boolean; - nameLocalizationKey: string; - descriptionLocalizationKey: string; - canBeUsedByBusiness: boolean; - baseSeats: number; - baseStorageGb: number; - maxCollections: number; - maxUsers: number; + type: PlanType; + product: ProductType; + name: string; + isAnnual: boolean; + nameLocalizationKey: string; + descriptionLocalizationKey: string; + canBeUsedByBusiness: boolean; + baseSeats: number; + baseStorageGb: number; + maxCollections: number; + maxUsers: number; - hasAdditionalSeatsOption: boolean; - maxAdditionalSeats: number; - hasAdditionalStorageOption: boolean; - maxAdditionalStorage: number; - hasPremiumAccessOption: boolean; - trialPeriodDays: number; + hasAdditionalSeatsOption: boolean; + maxAdditionalSeats: number; + hasAdditionalStorageOption: boolean; + maxAdditionalStorage: number; + hasPremiumAccessOption: boolean; + trialPeriodDays: number; - hasSelfHost: boolean; - hasPolicies: boolean; - hasGroups: boolean; - hasDirectory: boolean; - hasEvents: boolean; - hasTotp: boolean; - has2fa: boolean; - hasApi: boolean; - hasSso: boolean; - hasResetPassword: boolean; - usersGetPremium: boolean; + hasSelfHost: boolean; + hasPolicies: boolean; + hasGroups: boolean; + hasDirectory: boolean; + hasEvents: boolean; + hasTotp: boolean; + has2fa: boolean; + hasApi: boolean; + hasSso: boolean; + hasResetPassword: boolean; + usersGetPremium: boolean; - upgradeSortOrder: number; - displaySortOrder: number; - legacyYear: number; - disabled: boolean; + upgradeSortOrder: number; + displaySortOrder: number; + legacyYear: number; + disabled: boolean; - stripePlanId: string; - stripeSeatPlanId: string; - stripeStoragePlanId: string; - stripePremiumAccessPlanId: string; - basePrice: number; - seatPrice: number; - additionalStoragePricePerGb: number; - premiumAccessOptionPrice: number; + stripePlanId: string; + stripeSeatPlanId: string; + stripeStoragePlanId: string; + stripePremiumAccessPlanId: string; + basePrice: number; + seatPrice: number; + additionalStoragePricePerGb: number; + premiumAccessOptionPrice: number; - constructor(response: any) { - super(response); - this.type = this.getResponseProperty('Type'); - this.product = this.getResponseProperty('Product'); - this.name = this.getResponseProperty('Name'); - this.isAnnual = this.getResponseProperty('IsAnnual'); - this.nameLocalizationKey = this.getResponseProperty('NameLocalizationKey'); - this.descriptionLocalizationKey = this.getResponseProperty('DescriptionLocalizationKey'); - this.canBeUsedByBusiness = this.getResponseProperty('CanBeUsedByBusiness'); - this.baseSeats = this.getResponseProperty('BaseSeats'); - this.baseStorageGb = this.getResponseProperty('BaseStorageGb'); - this.maxCollections = this.getResponseProperty('MaxCollections'); - this.maxUsers = this.getResponseProperty('MaxUsers'); - this.hasAdditionalSeatsOption = this.getResponseProperty('HasAdditionalSeatsOption'); - this.maxAdditionalSeats = this.getResponseProperty('MaxAdditionalSeats'); - this.hasAdditionalStorageOption = this.getResponseProperty('HasAdditionalStorageOption'); - this.maxAdditionalStorage = this.getResponseProperty('MaxAdditionalStorage'); - this.hasPremiumAccessOption = this.getResponseProperty('HasPremiumAccessOption'); - this.trialPeriodDays = this.getResponseProperty('TrialPeriodDays'); - this.hasSelfHost = this.getResponseProperty('HasSelfHost'); - this.hasPolicies = this.getResponseProperty('HasPolicies'); - this.hasGroups = this.getResponseProperty('HasGroups'); - this.hasDirectory = this.getResponseProperty('HasDirectory'); - this.hasEvents = this.getResponseProperty('HasEvents'); - this.hasTotp = this.getResponseProperty('HasTotp'); - this.has2fa = this.getResponseProperty('Has2fa'); - this.hasApi = this.getResponseProperty('HasApi'); - this.hasSso = this.getResponseProperty('HasSso'); - this.hasResetPassword = this.getResponseProperty('HasResetPassword'); - this.usersGetPremium = this.getResponseProperty('UsersGetPremium'); - this.upgradeSortOrder = this.getResponseProperty('UpgradeSortOrder'); - this.displaySortOrder = this.getResponseProperty('SortOrder'); - this.legacyYear = this.getResponseProperty('LegacyYear'); - this.disabled = this.getResponseProperty('Disabled'); - this.stripePlanId = this.getResponseProperty('StripePlanId'); - this.stripeSeatPlanId = this.getResponseProperty('StripeSeatPlanId'); - this.stripeStoragePlanId = this.getResponseProperty('StripeStoragePlanId'); - this.stripePremiumAccessPlanId = this.getResponseProperty('StripePremiumAccessPlanId'); - this.basePrice = this.getResponseProperty('BasePrice'); - this.seatPrice = this.getResponseProperty('SeatPrice'); - this.additionalStoragePricePerGb = this.getResponseProperty('AdditionalStoragePricePerGb'); - this.premiumAccessOptionPrice = this.getResponseProperty('PremiumAccessOptionPrice'); - } + constructor(response: any) { + super(response); + this.type = this.getResponseProperty("Type"); + this.product = this.getResponseProperty("Product"); + this.name = this.getResponseProperty("Name"); + this.isAnnual = this.getResponseProperty("IsAnnual"); + this.nameLocalizationKey = this.getResponseProperty("NameLocalizationKey"); + this.descriptionLocalizationKey = this.getResponseProperty("DescriptionLocalizationKey"); + this.canBeUsedByBusiness = this.getResponseProperty("CanBeUsedByBusiness"); + this.baseSeats = this.getResponseProperty("BaseSeats"); + this.baseStorageGb = this.getResponseProperty("BaseStorageGb"); + this.maxCollections = this.getResponseProperty("MaxCollections"); + this.maxUsers = this.getResponseProperty("MaxUsers"); + this.hasAdditionalSeatsOption = this.getResponseProperty("HasAdditionalSeatsOption"); + this.maxAdditionalSeats = this.getResponseProperty("MaxAdditionalSeats"); + this.hasAdditionalStorageOption = this.getResponseProperty("HasAdditionalStorageOption"); + this.maxAdditionalStorage = this.getResponseProperty("MaxAdditionalStorage"); + this.hasPremiumAccessOption = this.getResponseProperty("HasPremiumAccessOption"); + this.trialPeriodDays = this.getResponseProperty("TrialPeriodDays"); + this.hasSelfHost = this.getResponseProperty("HasSelfHost"); + this.hasPolicies = this.getResponseProperty("HasPolicies"); + this.hasGroups = this.getResponseProperty("HasGroups"); + this.hasDirectory = this.getResponseProperty("HasDirectory"); + this.hasEvents = this.getResponseProperty("HasEvents"); + this.hasTotp = this.getResponseProperty("HasTotp"); + this.has2fa = this.getResponseProperty("Has2fa"); + this.hasApi = this.getResponseProperty("HasApi"); + this.hasSso = this.getResponseProperty("HasSso"); + this.hasResetPassword = this.getResponseProperty("HasResetPassword"); + this.usersGetPremium = this.getResponseProperty("UsersGetPremium"); + this.upgradeSortOrder = this.getResponseProperty("UpgradeSortOrder"); + this.displaySortOrder = this.getResponseProperty("SortOrder"); + this.legacyYear = this.getResponseProperty("LegacyYear"); + this.disabled = this.getResponseProperty("Disabled"); + this.stripePlanId = this.getResponseProperty("StripePlanId"); + this.stripeSeatPlanId = this.getResponseProperty("StripeSeatPlanId"); + this.stripeStoragePlanId = this.getResponseProperty("StripeStoragePlanId"); + this.stripePremiumAccessPlanId = this.getResponseProperty("StripePremiumAccessPlanId"); + this.basePrice = this.getResponseProperty("BasePrice"); + this.seatPrice = this.getResponseProperty("SeatPrice"); + this.additionalStoragePricePerGb = this.getResponseProperty("AdditionalStoragePricePerGb"); + this.premiumAccessOptionPrice = this.getResponseProperty("PremiumAccessOptionPrice"); + } } diff --git a/common/src/models/response/policyResponse.ts b/common/src/models/response/policyResponse.ts index 2fa931f3..328491cf 100644 --- a/common/src/models/response/policyResponse.ts +++ b/common/src/models/response/policyResponse.ts @@ -1,20 +1,20 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { PolicyType } from '../../enums/policyType'; +import { PolicyType } from "../../enums/policyType"; export class PolicyResponse extends BaseResponse { - id: string; - organizationId: string; - type: PolicyType; - data: any; - enabled: boolean; + id: string; + organizationId: string; + type: PolicyType; + data: any; + enabled: boolean; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.organizationId = this.getResponseProperty('OrganizationId'); - this.type = this.getResponseProperty('Type'); - this.data = this.getResponseProperty('Data'); - this.enabled = this.getResponseProperty('Enabled'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.type = this.getResponseProperty("Type"); + this.data = this.getResponseProperty("Data"); + this.enabled = this.getResponseProperty("Enabled"); + } } diff --git a/common/src/models/response/preloginResponse.ts b/common/src/models/response/preloginResponse.ts index fcbd4cb2..d5396830 100644 --- a/common/src/models/response/preloginResponse.ts +++ b/common/src/models/response/preloginResponse.ts @@ -1,14 +1,14 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { KdfType } from '../../enums/kdfType'; +import { KdfType } from "../../enums/kdfType"; export class PreloginResponse extends BaseResponse { - kdf: KdfType; - kdfIterations: number; + kdf: KdfType; + kdfIterations: number; - constructor(response: any) { - super(response); - this.kdf = this.getResponseProperty('Kdf'); - this.kdfIterations = this.getResponseProperty('KdfIterations'); - } + constructor(response: any) { + super(response); + this.kdf = this.getResponseProperty("Kdf"); + this.kdfIterations = this.getResponseProperty("KdfIterations"); + } } diff --git a/common/src/models/response/profileOrganizationResponse.ts b/common/src/models/response/profileOrganizationResponse.ts index fdd873ba..efa2e3f8 100644 --- a/common/src/models/response/profileOrganizationResponse.ts +++ b/common/src/models/response/profileOrganizationResponse.ts @@ -1,81 +1,81 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { OrganizationUserStatusType } from '../../enums/organizationUserStatusType'; -import { OrganizationUserType } from '../../enums/organizationUserType'; -import { ProductType } from '../../enums/productType'; -import { PermissionsApi } from '../api/permissionsApi'; +import { OrganizationUserStatusType } from "../../enums/organizationUserStatusType"; +import { OrganizationUserType } from "../../enums/organizationUserType"; +import { ProductType } from "../../enums/productType"; +import { PermissionsApi } from "../api/permissionsApi"; export class ProfileOrganizationResponse extends BaseResponse { - id: string; - name: string; - usePolicies: boolean; - useGroups: boolean; - useDirectory: boolean; - useEvents: boolean; - useTotp: boolean; - use2fa: boolean; - useApi: boolean; - useSso: boolean; - useKeyConnector: boolean; - useResetPassword: boolean; - selfHost: boolean; - usersGetPremium: boolean; - seats: number; - maxCollections: number; - maxStorageGb?: number; - key: string; - hasPublicAndPrivateKeys: boolean; - status: OrganizationUserStatusType; - type: OrganizationUserType; - enabled: boolean; - ssoBound: boolean; - identifier: string; - permissions: PermissionsApi; - resetPasswordEnrolled: boolean; - userId: string; - providerId: string; - providerName: string; - familySponsorshipFriendlyName: string; - familySponsorshipAvailable: boolean; - planProductType: ProductType; - keyConnectorEnabled: boolean; - keyConnectorUrl: string; + id: string; + name: string; + usePolicies: boolean; + useGroups: boolean; + useDirectory: boolean; + useEvents: boolean; + useTotp: boolean; + use2fa: boolean; + useApi: boolean; + useSso: boolean; + useKeyConnector: boolean; + useResetPassword: boolean; + selfHost: boolean; + usersGetPremium: boolean; + seats: number; + maxCollections: number; + maxStorageGb?: number; + key: string; + hasPublicAndPrivateKeys: boolean; + status: OrganizationUserStatusType; + type: OrganizationUserType; + enabled: boolean; + ssoBound: boolean; + identifier: string; + permissions: PermissionsApi; + resetPasswordEnrolled: boolean; + userId: string; + providerId: string; + providerName: string; + familySponsorshipFriendlyName: string; + familySponsorshipAvailable: boolean; + planProductType: ProductType; + keyConnectorEnabled: boolean; + keyConnectorUrl: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.name = this.getResponseProperty('Name'); - this.usePolicies = this.getResponseProperty('UsePolicies'); - this.useGroups = this.getResponseProperty('UseGroups'); - this.useDirectory = this.getResponseProperty('UseDirectory'); - this.useEvents = this.getResponseProperty('UseEvents'); - this.useTotp = this.getResponseProperty('UseTotp'); - this.use2fa = this.getResponseProperty('Use2fa'); - this.useApi = this.getResponseProperty('UseApi'); - this.useSso = this.getResponseProperty('UseSso'); - this.useKeyConnector = this.getResponseProperty('UseKeyConnector') ?? false; - this.useResetPassword = this.getResponseProperty('UseResetPassword'); - this.selfHost = this.getResponseProperty('SelfHost'); - this.usersGetPremium = this.getResponseProperty('UsersGetPremium'); - this.seats = this.getResponseProperty('Seats'); - this.maxCollections = this.getResponseProperty('MaxCollections'); - this.maxStorageGb = this.getResponseProperty('MaxStorageGb'); - this.key = this.getResponseProperty('Key'); - this.hasPublicAndPrivateKeys = this.getResponseProperty('HasPublicAndPrivateKeys'); - this.status = this.getResponseProperty('Status'); - this.type = this.getResponseProperty('Type'); - this.enabled = this.getResponseProperty('Enabled'); - this.ssoBound = this.getResponseProperty('SsoBound'); - this.identifier = this.getResponseProperty('Identifier'); - this.permissions = new PermissionsApi(this.getResponseProperty('permissions')); - this.resetPasswordEnrolled = this.getResponseProperty('ResetPasswordEnrolled'); - this.userId = this.getResponseProperty('UserId'); - this.providerId = this.getResponseProperty('ProviderId'); - this.providerName = this.getResponseProperty('ProviderName'); - this.familySponsorshipFriendlyName = this.getResponseProperty('FamilySponsorshipFriendlyName'); - this.familySponsorshipAvailable = this.getResponseProperty('FamilySponsorshipAvailable'); - this.planProductType = this.getResponseProperty('PlanProductType'); - this.keyConnectorEnabled = this.getResponseProperty('KeyConnectorEnabled') ?? false; - this.keyConnectorUrl = this.getResponseProperty('KeyConnectorUrl'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.name = this.getResponseProperty("Name"); + this.usePolicies = this.getResponseProperty("UsePolicies"); + this.useGroups = this.getResponseProperty("UseGroups"); + this.useDirectory = this.getResponseProperty("UseDirectory"); + this.useEvents = this.getResponseProperty("UseEvents"); + this.useTotp = this.getResponseProperty("UseTotp"); + this.use2fa = this.getResponseProperty("Use2fa"); + this.useApi = this.getResponseProperty("UseApi"); + this.useSso = this.getResponseProperty("UseSso"); + this.useKeyConnector = this.getResponseProperty("UseKeyConnector") ?? false; + this.useResetPassword = this.getResponseProperty("UseResetPassword"); + this.selfHost = this.getResponseProperty("SelfHost"); + this.usersGetPremium = this.getResponseProperty("UsersGetPremium"); + this.seats = this.getResponseProperty("Seats"); + this.maxCollections = this.getResponseProperty("MaxCollections"); + this.maxStorageGb = this.getResponseProperty("MaxStorageGb"); + this.key = this.getResponseProperty("Key"); + this.hasPublicAndPrivateKeys = this.getResponseProperty("HasPublicAndPrivateKeys"); + this.status = this.getResponseProperty("Status"); + this.type = this.getResponseProperty("Type"); + this.enabled = this.getResponseProperty("Enabled"); + this.ssoBound = this.getResponseProperty("SsoBound"); + this.identifier = this.getResponseProperty("Identifier"); + this.permissions = new PermissionsApi(this.getResponseProperty("permissions")); + this.resetPasswordEnrolled = this.getResponseProperty("ResetPasswordEnrolled"); + this.userId = this.getResponseProperty("UserId"); + this.providerId = this.getResponseProperty("ProviderId"); + this.providerName = this.getResponseProperty("ProviderName"); + this.familySponsorshipFriendlyName = this.getResponseProperty("FamilySponsorshipFriendlyName"); + this.familySponsorshipAvailable = this.getResponseProperty("FamilySponsorshipAvailable"); + this.planProductType = this.getResponseProperty("PlanProductType"); + this.keyConnectorEnabled = this.getResponseProperty("KeyConnectorEnabled") ?? false; + this.keyConnectorUrl = this.getResponseProperty("KeyConnectorUrl"); + } } diff --git a/common/src/models/response/profileProviderOrganizationResponse.ts b/common/src/models/response/profileProviderOrganizationResponse.ts index d34b78d0..74b74c00 100644 --- a/common/src/models/response/profileProviderOrganizationResponse.ts +++ b/common/src/models/response/profileProviderOrganizationResponse.ts @@ -1,8 +1,8 @@ -import { ProfileOrganizationResponse } from './profileOrganizationResponse'; +import { ProfileOrganizationResponse } from "./profileOrganizationResponse"; export class ProfileProviderOrganizationResponse extends ProfileOrganizationResponse { - constructor(response: any) { - super(response); - this.keyConnectorEnabled = false; - } + constructor(response: any) { + super(response); + this.keyConnectorEnabled = false; + } } diff --git a/common/src/models/response/profileProviderResponse.ts b/common/src/models/response/profileProviderResponse.ts index b3c23404..04610080 100644 --- a/common/src/models/response/profileProviderResponse.ts +++ b/common/src/models/response/profileProviderResponse.ts @@ -1,31 +1,31 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { ProviderUserStatusType } from '../../enums/providerUserStatusType'; -import { ProviderUserType } from '../../enums/providerUserType'; +import { ProviderUserStatusType } from "../../enums/providerUserStatusType"; +import { ProviderUserType } from "../../enums/providerUserType"; -import { PermissionsApi } from '../api/permissionsApi'; +import { PermissionsApi } from "../api/permissionsApi"; export class ProfileProviderResponse extends BaseResponse { - id: string; - name: string; - key: string; - status: ProviderUserStatusType; - type: ProviderUserType; - enabled: boolean; - permissions: PermissionsApi; - userId: string; - useEvents: boolean; + id: string; + name: string; + key: string; + status: ProviderUserStatusType; + type: ProviderUserType; + enabled: boolean; + permissions: PermissionsApi; + userId: string; + useEvents: boolean; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.name = this.getResponseProperty('Name'); - this.key = this.getResponseProperty('Key'); - this.status = this.getResponseProperty('Status'); - this.type = this.getResponseProperty('Type'); - this.enabled = this.getResponseProperty('Enabled'); - this.permissions = new PermissionsApi(this.getResponseProperty('permissions')); - this.userId = this.getResponseProperty('UserId'); - this.useEvents = this.getResponseProperty('UseEvents'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.name = this.getResponseProperty("Name"); + this.key = this.getResponseProperty("Key"); + this.status = this.getResponseProperty("Status"); + this.type = this.getResponseProperty("Type"); + this.enabled = this.getResponseProperty("Enabled"); + this.permissions = new PermissionsApi(this.getResponseProperty("permissions")); + this.userId = this.getResponseProperty("UserId"); + this.useEvents = this.getResponseProperty("UseEvents"); + } } diff --git a/common/src/models/response/profileResponse.ts b/common/src/models/response/profileResponse.ts index 913ff820..2c3e66fb 100644 --- a/common/src/models/response/profileResponse.ts +++ b/common/src/models/response/profileResponse.ts @@ -1,53 +1,55 @@ -import { BaseResponse } from './baseResponse'; -import { ProfileOrganizationResponse } from './profileOrganizationResponse'; -import { ProfileProviderOrganizationResponse } from './profileProviderOrganizationResponse'; -import { ProfileProviderResponse } from './profileProviderResponse'; +import { BaseResponse } from "./baseResponse"; +import { ProfileOrganizationResponse } from "./profileOrganizationResponse"; +import { ProfileProviderOrganizationResponse } from "./profileProviderOrganizationResponse"; +import { ProfileProviderResponse } from "./profileProviderResponse"; export class ProfileResponse extends BaseResponse { - id: string; - name: string; - email: string; - emailVerified: boolean; - masterPasswordHint: string; - premium: boolean; - culture: string; - twoFactorEnabled: boolean; - key: string; - privateKey: string; - securityStamp: string; - forcePasswordReset: boolean; - usesKeyConnector: boolean; - organizations: ProfileOrganizationResponse[] = []; - providers: ProfileProviderResponse[] = []; - providerOrganizations: ProfileProviderOrganizationResponse[] = []; + id: string; + name: string; + email: string; + emailVerified: boolean; + masterPasswordHint: string; + premium: boolean; + culture: string; + twoFactorEnabled: boolean; + key: string; + privateKey: string; + securityStamp: string; + forcePasswordReset: boolean; + usesKeyConnector: boolean; + organizations: ProfileOrganizationResponse[] = []; + providers: ProfileProviderResponse[] = []; + providerOrganizations: ProfileProviderOrganizationResponse[] = []; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.name = this.getResponseProperty('Name'); - this.email = this.getResponseProperty('Email'); - this.emailVerified = this.getResponseProperty('EmailVerified'); - this.masterPasswordHint = this.getResponseProperty('MasterPasswordHint'); - this.premium = this.getResponseProperty('Premium'); - this.culture = this.getResponseProperty('Culture'); - this.twoFactorEnabled = this.getResponseProperty('TwoFactorEnabled'); - this.key = this.getResponseProperty('Key'); - this.privateKey = this.getResponseProperty('PrivateKey'); - this.securityStamp = this.getResponseProperty('SecurityStamp'); - this.forcePasswordReset = this.getResponseProperty('ForcePasswordReset') ?? false; - this.usesKeyConnector = this.getResponseProperty('UsesKeyConnector') ?? false; + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.name = this.getResponseProperty("Name"); + this.email = this.getResponseProperty("Email"); + this.emailVerified = this.getResponseProperty("EmailVerified"); + this.masterPasswordHint = this.getResponseProperty("MasterPasswordHint"); + this.premium = this.getResponseProperty("Premium"); + this.culture = this.getResponseProperty("Culture"); + this.twoFactorEnabled = this.getResponseProperty("TwoFactorEnabled"); + this.key = this.getResponseProperty("Key"); + this.privateKey = this.getResponseProperty("PrivateKey"); + this.securityStamp = this.getResponseProperty("SecurityStamp"); + this.forcePasswordReset = this.getResponseProperty("ForcePasswordReset") ?? false; + this.usesKeyConnector = this.getResponseProperty("UsesKeyConnector") ?? false; - const organizations = this.getResponseProperty('Organizations'); - if (organizations != null) { - this.organizations = organizations.map((o: any) => new ProfileOrganizationResponse(o)); - } - const providers = this.getResponseProperty('Providers'); - if (providers != null) { - this.providers = providers.map((o: any) => new ProfileProviderResponse(o)); - } - const providerOrganizations = this.getResponseProperty('ProviderOrganizations'); - if (providerOrganizations != null) { - this.providerOrganizations = providerOrganizations.map((o: any) => new ProfileProviderOrganizationResponse(o)); - } + const organizations = this.getResponseProperty("Organizations"); + if (organizations != null) { + this.organizations = organizations.map((o: any) => new ProfileOrganizationResponse(o)); } + const providers = this.getResponseProperty("Providers"); + if (providers != null) { + this.providers = providers.map((o: any) => new ProfileProviderResponse(o)); + } + const providerOrganizations = this.getResponseProperty("ProviderOrganizations"); + if (providerOrganizations != null) { + this.providerOrganizations = providerOrganizations.map( + (o: any) => new ProfileProviderOrganizationResponse(o) + ); + } + } } diff --git a/common/src/models/response/provider/providerOrganizationResponse.ts b/common/src/models/response/provider/providerOrganizationResponse.ts index 91fa6a46..d733362a 100644 --- a/common/src/models/response/provider/providerOrganizationResponse.ts +++ b/common/src/models/response/provider/providerOrganizationResponse.ts @@ -1,31 +1,31 @@ -import { BaseResponse } from '../baseResponse'; +import { BaseResponse } from "../baseResponse"; export class ProviderOrganizationResponse extends BaseResponse { - id: string; - providerId: string; - organizationId: string; - key: string; - settings: string; - creationDate: string; - revisionDate: string; + id: string; + providerId: string; + organizationId: string; + key: string; + settings: string; + creationDate: string; + revisionDate: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.providerId = this.getResponseProperty('ProviderId'); - this.organizationId = this.getResponseProperty('OrganizationId'); - this.key = this.getResponseProperty('Key'); - this.settings = this.getResponseProperty('Settings'); - this.creationDate = this.getResponseProperty('CreationDate'); - this.revisionDate = this.getResponseProperty('RevisionDate'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.providerId = this.getResponseProperty("ProviderId"); + this.organizationId = this.getResponseProperty("OrganizationId"); + this.key = this.getResponseProperty("Key"); + this.settings = this.getResponseProperty("Settings"); + this.creationDate = this.getResponseProperty("CreationDate"); + this.revisionDate = this.getResponseProperty("RevisionDate"); + } } export class ProviderOrganizationOrganizationDetailsResponse extends ProviderOrganizationResponse { - organizationName: string; + organizationName: string; - constructor(response: any) { - super(response); - this.organizationName = this.getResponseProperty('OrganizationName'); - } + constructor(response: any) { + super(response); + this.organizationName = this.getResponseProperty("OrganizationName"); + } } diff --git a/common/src/models/response/provider/providerResponse.ts b/common/src/models/response/provider/providerResponse.ts index d3d2364e..2b8729fa 100644 --- a/common/src/models/response/provider/providerResponse.ts +++ b/common/src/models/response/provider/providerResponse.ts @@ -1,16 +1,16 @@ -import { BaseResponse } from '../baseResponse'; +import { BaseResponse } from "../baseResponse"; export class ProviderResponse extends BaseResponse { - id: string; - name: string; - businessName: string; - billingEmail: string; + id: string; + name: string; + businessName: string; + billingEmail: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.name = this.getResponseProperty('Name'); - this.businessName = this.getResponseProperty('BusinessName'); - this.billingEmail = this.getResponseProperty('BillingEmail'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.name = this.getResponseProperty("Name"); + this.businessName = this.getResponseProperty("BusinessName"); + this.billingEmail = this.getResponseProperty("BillingEmail"); + } } diff --git a/common/src/models/response/provider/providerUserBulkPublicKeyResponse.ts b/common/src/models/response/provider/providerUserBulkPublicKeyResponse.ts index 122be2aa..ad078f98 100644 --- a/common/src/models/response/provider/providerUserBulkPublicKeyResponse.ts +++ b/common/src/models/response/provider/providerUserBulkPublicKeyResponse.ts @@ -1,5 +1,3 @@ -import { OrganizationUserBulkPublicKeyResponse } from '../organizationUserBulkPublicKeyResponse'; +import { OrganizationUserBulkPublicKeyResponse } from "../organizationUserBulkPublicKeyResponse"; -export class ProviderUserBulkPublicKeyResponse extends OrganizationUserBulkPublicKeyResponse { - -} +export class ProviderUserBulkPublicKeyResponse extends OrganizationUserBulkPublicKeyResponse {} diff --git a/common/src/models/response/provider/providerUserBulkResponse.ts b/common/src/models/response/provider/providerUserBulkResponse.ts index 019ee4f5..6cf12f96 100644 --- a/common/src/models/response/provider/providerUserBulkResponse.ts +++ b/common/src/models/response/provider/providerUserBulkResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from '../baseResponse'; +import { BaseResponse } from "../baseResponse"; export class ProviderUserBulkResponse extends BaseResponse { - id: string; - error: string; + id: string; + error: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.error = this.getResponseProperty('Error'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.error = this.getResponseProperty("Error"); + } } diff --git a/common/src/models/response/provider/providerUserResponse.ts b/common/src/models/response/provider/providerUserResponse.ts index 728b708f..4aad5814 100644 --- a/common/src/models/response/provider/providerUserResponse.ts +++ b/common/src/models/response/provider/providerUserResponse.ts @@ -1,34 +1,34 @@ -import { BaseResponse } from '../baseResponse'; +import { BaseResponse } from "../baseResponse"; -import { PermissionsApi } from '../../api/permissionsApi'; +import { PermissionsApi } from "../../api/permissionsApi"; -import { ProviderUserStatusType } from '../../../enums/providerUserStatusType'; -import { ProviderUserType } from '../../../enums/providerUserType'; +import { ProviderUserStatusType } from "../../../enums/providerUserStatusType"; +import { ProviderUserType } from "../../../enums/providerUserType"; export class ProviderUserResponse extends BaseResponse { - id: string; - userId: string; - type: ProviderUserType; - status: ProviderUserStatusType; - permissions: PermissionsApi; + id: string; + userId: string; + type: ProviderUserType; + status: ProviderUserStatusType; + permissions: PermissionsApi; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.userId = this.getResponseProperty('UserId'); - this.type = this.getResponseProperty('Type'); - this.status = this.getResponseProperty('Status'); - this.permissions = new PermissionsApi(this.getResponseProperty('Permissions')); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.userId = this.getResponseProperty("UserId"); + this.type = this.getResponseProperty("Type"); + this.status = this.getResponseProperty("Status"); + this.permissions = new PermissionsApi(this.getResponseProperty("Permissions")); + } } export class ProviderUserUserDetailsResponse extends ProviderUserResponse { - name: string; - email: string; + name: string; + email: string; - constructor(response: any) { - super(response); - this.name = this.getResponseProperty('Name'); - this.email = this.getResponseProperty('Email'); - } + constructor(response: any) { + super(response); + this.name = this.getResponseProperty("Name"); + this.email = this.getResponseProperty("Email"); + } } diff --git a/common/src/models/response/selectionReadOnlyResponse.ts b/common/src/models/response/selectionReadOnlyResponse.ts index ebcf5247..cee9361c 100644 --- a/common/src/models/response/selectionReadOnlyResponse.ts +++ b/common/src/models/response/selectionReadOnlyResponse.ts @@ -1,14 +1,14 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class SelectionReadOnlyResponse extends BaseResponse { - id: string; - readOnly: boolean; - hidePasswords: boolean; + id: string; + readOnly: boolean; + hidePasswords: boolean; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.readOnly = this.getResponseProperty('ReadOnly'); - this.hidePasswords = this.getResponseProperty('HidePasswords'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.readOnly = this.getResponseProperty("ReadOnly"); + this.hidePasswords = this.getResponseProperty("HidePasswords"); + } } diff --git a/common/src/models/response/sendAccessResponse.ts b/common/src/models/response/sendAccessResponse.ts index ef4a57aa..2742c7f9 100644 --- a/common/src/models/response/sendAccessResponse.ts +++ b/common/src/models/response/sendAccessResponse.ts @@ -1,36 +1,36 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { SendType } from '../../enums/sendType'; +import { SendType } from "../../enums/sendType"; -import { SendFileApi } from '../api/sendFileApi'; -import { SendTextApi } from '../api/sendTextApi'; +import { SendFileApi } from "../api/sendFileApi"; +import { SendTextApi } from "../api/sendTextApi"; export class SendAccessResponse extends BaseResponse { - id: string; - type: SendType; - name: string; - file: SendFileApi; - text: SendTextApi; - expirationDate: Date; - creatorIdentifier: string; + id: string; + type: SendType; + name: string; + file: SendFileApi; + text: SendTextApi; + expirationDate: Date; + creatorIdentifier: string; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.type = this.getResponseProperty('Type'); - this.name = this.getResponseProperty('Name'); + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.type = this.getResponseProperty("Type"); + this.name = this.getResponseProperty("Name"); - const text = this.getResponseProperty('Text'); - if (text != null) { - this.text = new SendTextApi(text); - } - - const file = this.getResponseProperty('File'); - if (file != null) { - this.file = new SendFileApi(file); - } - - this.expirationDate = this.getResponseProperty('ExpirationDate'); - this.creatorIdentifier = this.getResponseProperty('CreatorIdentifier'); + const text = this.getResponseProperty("Text"); + if (text != null) { + this.text = new SendTextApi(text); } + + const file = this.getResponseProperty("File"); + if (file != null) { + this.file = new SendFileApi(file); + } + + this.expirationDate = this.getResponseProperty("ExpirationDate"); + this.creatorIdentifier = this.getResponseProperty("CreatorIdentifier"); + } } diff --git a/common/src/models/response/sendFileDownloadDataResponse.ts b/common/src/models/response/sendFileDownloadDataResponse.ts index 734ef224..ca2575a2 100644 --- a/common/src/models/response/sendFileDownloadDataResponse.ts +++ b/common/src/models/response/sendFileDownloadDataResponse.ts @@ -1,12 +1,11 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class SendFileDownloadDataResponse extends BaseResponse { - - id: string = null; - url: string = null; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.url = this.getResponseProperty('Url'); - } + id: string = null; + url: string = null; + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.url = this.getResponseProperty("Url"); + } } diff --git a/common/src/models/response/sendFileUploadDataResponse.ts b/common/src/models/response/sendFileUploadDataResponse.ts index 3f7f0b3d..b787f2cc 100644 --- a/common/src/models/response/sendFileUploadDataResponse.ts +++ b/common/src/models/response/sendFileUploadDataResponse.ts @@ -1,18 +1,17 @@ -import { FileUploadType } from '../../enums/fileUploadType'; +import { FileUploadType } from "../../enums/fileUploadType"; -import { BaseResponse } from './baseResponse'; -import { SendResponse } from './sendResponse'; +import { BaseResponse } from "./baseResponse"; +import { SendResponse } from "./sendResponse"; export class SendFileUploadDataResponse extends BaseResponse { - - fileUploadType: FileUploadType; - sendResponse: SendResponse; - url: string = null; - constructor(response: any) { - super(response); - this.fileUploadType = this.getResponseProperty('FileUploadType'); - const sendResponse = this.getResponseProperty('SendResponse'); - this.sendResponse = sendResponse == null ? null : new SendResponse(sendResponse); - this.url = this.getResponseProperty('Url'); - } + fileUploadType: FileUploadType; + sendResponse: SendResponse; + url: string = null; + constructor(response: any) { + super(response); + this.fileUploadType = this.getResponseProperty("FileUploadType"); + const sendResponse = this.getResponseProperty("SendResponse"); + this.sendResponse = sendResponse == null ? null : new SendResponse(sendResponse); + this.url = this.getResponseProperty("Url"); + } } diff --git a/common/src/models/response/sendResponse.ts b/common/src/models/response/sendResponse.ts index fdbbf334..edb009c3 100644 --- a/common/src/models/response/sendResponse.ts +++ b/common/src/models/response/sendResponse.ts @@ -1,53 +1,53 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { SendType } from '../../enums/sendType'; +import { SendType } from "../../enums/sendType"; -import { SendFileApi } from '../api/sendFileApi'; -import { SendTextApi } from '../api/sendTextApi'; +import { SendFileApi } from "../api/sendFileApi"; +import { SendTextApi } from "../api/sendTextApi"; export class SendResponse extends BaseResponse { - id: string; - accessId: string; - type: SendType; - name: string; - notes: string; - file: SendFileApi; - text: SendTextApi; - key: string; - maxAccessCount?: number; - accessCount: number; - revisionDate: string; - expirationDate: string; - deletionDate: string; - password: string; - disable: boolean; - hideEmail: boolean; + id: string; + accessId: string; + type: SendType; + name: string; + notes: string; + file: SendFileApi; + text: SendTextApi; + key: string; + maxAccessCount?: number; + accessCount: number; + revisionDate: string; + expirationDate: string; + deletionDate: string; + password: string; + disable: boolean; + hideEmail: boolean; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.accessId = this.getResponseProperty('AccessId'); - this.type = this.getResponseProperty('Type'); - this.name = this.getResponseProperty('Name'); - this.notes = this.getResponseProperty('Notes'); - this.key = this.getResponseProperty('Key'); - this.maxAccessCount = this.getResponseProperty('MaxAccessCount'); - this.accessCount = this.getResponseProperty('AccessCount'); - this.revisionDate = this.getResponseProperty('RevisionDate'); - this.expirationDate = this.getResponseProperty('ExpirationDate'); - this.deletionDate = this.getResponseProperty('DeletionDate'); - this.password = this.getResponseProperty('Password'); - this.disable = this.getResponseProperty('Disabled') || false; - this.hideEmail = this.getResponseProperty('HideEmail') || false; + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.accessId = this.getResponseProperty("AccessId"); + this.type = this.getResponseProperty("Type"); + this.name = this.getResponseProperty("Name"); + this.notes = this.getResponseProperty("Notes"); + this.key = this.getResponseProperty("Key"); + this.maxAccessCount = this.getResponseProperty("MaxAccessCount"); + this.accessCount = this.getResponseProperty("AccessCount"); + this.revisionDate = this.getResponseProperty("RevisionDate"); + this.expirationDate = this.getResponseProperty("ExpirationDate"); + this.deletionDate = this.getResponseProperty("DeletionDate"); + this.password = this.getResponseProperty("Password"); + this.disable = this.getResponseProperty("Disabled") || false; + this.hideEmail = this.getResponseProperty("HideEmail") || false; - const text = this.getResponseProperty('Text'); - if (text != null) { - this.text = new SendTextApi(text); - } - - const file = this.getResponseProperty('File'); - if (file != null) { - this.file = new SendFileApi(file); - } + const text = this.getResponseProperty("Text"); + if (text != null) { + this.text = new SendTextApi(text); } + + const file = this.getResponseProperty("File"); + if (file != null) { + this.file = new SendFileApi(file); + } + } } diff --git a/common/src/models/response/subscriptionResponse.ts b/common/src/models/response/subscriptionResponse.ts index 616d5a8b..fc5570c3 100644 --- a/common/src/models/response/subscriptionResponse.ts +++ b/common/src/models/response/subscriptionResponse.ts @@ -1,83 +1,85 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class SubscriptionResponse extends BaseResponse { - storageName: string; - storageGb: number; - maxStorageGb: number; - subscription: BillingSubscriptionResponse; - upcomingInvoice: BillingSubscriptionUpcomingInvoiceResponse; - license: any; - expiration: string; - usingInAppPurchase: boolean; + storageName: string; + storageGb: number; + maxStorageGb: number; + subscription: BillingSubscriptionResponse; + upcomingInvoice: BillingSubscriptionUpcomingInvoiceResponse; + license: any; + expiration: string; + usingInAppPurchase: boolean; - constructor(response: any) { - super(response); - this.storageName = this.getResponseProperty('StorageName'); - this.storageGb = this.getResponseProperty('StorageGb'); - this.maxStorageGb = this.getResponseProperty('MaxStorageGb'); - this.license = this.getResponseProperty('License'); - this.expiration = this.getResponseProperty('Expiration'); - this.usingInAppPurchase = this.getResponseProperty('UsingInAppPurchase'); - const subscription = this.getResponseProperty('Subscription'); - const upcomingInvoice = this.getResponseProperty('UpcomingInvoice'); - this.subscription = subscription == null ? null : new BillingSubscriptionResponse(subscription); - this.upcomingInvoice = upcomingInvoice == null ? null : - new BillingSubscriptionUpcomingInvoiceResponse(upcomingInvoice); - } + constructor(response: any) { + super(response); + this.storageName = this.getResponseProperty("StorageName"); + this.storageGb = this.getResponseProperty("StorageGb"); + this.maxStorageGb = this.getResponseProperty("MaxStorageGb"); + this.license = this.getResponseProperty("License"); + this.expiration = this.getResponseProperty("Expiration"); + this.usingInAppPurchase = this.getResponseProperty("UsingInAppPurchase"); + const subscription = this.getResponseProperty("Subscription"); + const upcomingInvoice = this.getResponseProperty("UpcomingInvoice"); + this.subscription = subscription == null ? null : new BillingSubscriptionResponse(subscription); + this.upcomingInvoice = + upcomingInvoice == null + ? null + : new BillingSubscriptionUpcomingInvoiceResponse(upcomingInvoice); + } } export class BillingSubscriptionResponse extends BaseResponse { - trialStartDate: string; - trialEndDate: string; - periodStartDate: string; - periodEndDate: string; - cancelledDate: string; - cancelAtEndDate: boolean; - status: string; - cancelled: boolean; - items: BillingSubscriptionItemResponse[] = []; + trialStartDate: string; + trialEndDate: string; + periodStartDate: string; + periodEndDate: string; + cancelledDate: string; + cancelAtEndDate: boolean; + status: string; + cancelled: boolean; + items: BillingSubscriptionItemResponse[] = []; - constructor(response: any) { - super(response); - this.trialEndDate = this.getResponseProperty('TrialStartDate'); - this.trialEndDate = this.getResponseProperty('TrialEndDate'); - this.periodStartDate = this.getResponseProperty('PeriodStartDate'); - this.periodEndDate = this.getResponseProperty('PeriodEndDate'); - this.cancelledDate = this.getResponseProperty('CancelledDate'); - this.cancelAtEndDate = this.getResponseProperty('CancelAtEndDate'); - this.status = this.getResponseProperty('Status'); - this.cancelled = this.getResponseProperty('Cancelled'); - const items = this.getResponseProperty('Items'); - if (items != null) { - this.items = items.map((i: any) => new BillingSubscriptionItemResponse(i)); - } + constructor(response: any) { + super(response); + this.trialEndDate = this.getResponseProperty("TrialStartDate"); + this.trialEndDate = this.getResponseProperty("TrialEndDate"); + this.periodStartDate = this.getResponseProperty("PeriodStartDate"); + this.periodEndDate = this.getResponseProperty("PeriodEndDate"); + this.cancelledDate = this.getResponseProperty("CancelledDate"); + this.cancelAtEndDate = this.getResponseProperty("CancelAtEndDate"); + this.status = this.getResponseProperty("Status"); + this.cancelled = this.getResponseProperty("Cancelled"); + const items = this.getResponseProperty("Items"); + if (items != null) { + this.items = items.map((i: any) => new BillingSubscriptionItemResponse(i)); } + } } export class BillingSubscriptionItemResponse extends BaseResponse { - name: string; - amount: number; - quantity: number; - interval: string; - sponsoredSubscriptionItem: boolean; + name: string; + amount: number; + quantity: number; + interval: string; + sponsoredSubscriptionItem: boolean; - constructor(response: any) { - super(response); - this.name = this.getResponseProperty('Name'); - this.amount = this.getResponseProperty('Amount'); - this.quantity = this.getResponseProperty('Quantity'); - this.interval = this.getResponseProperty('Interval'); - this.sponsoredSubscriptionItem = this.getResponseProperty('SponsoredSubscriptionItem'); - } + constructor(response: any) { + super(response); + this.name = this.getResponseProperty("Name"); + this.amount = this.getResponseProperty("Amount"); + this.quantity = this.getResponseProperty("Quantity"); + this.interval = this.getResponseProperty("Interval"); + this.sponsoredSubscriptionItem = this.getResponseProperty("SponsoredSubscriptionItem"); + } } export class BillingSubscriptionUpcomingInvoiceResponse extends BaseResponse { - date: string; - amount: number; + date: string; + amount: number; - constructor(response: any) { - super(response); - this.date = this.getResponseProperty('Date'); - this.amount = this.getResponseProperty('Amount'); - } + constructor(response: any) { + super(response); + this.date = this.getResponseProperty("Date"); + this.amount = this.getResponseProperty("Amount"); + } } diff --git a/common/src/models/response/syncResponse.ts b/common/src/models/response/syncResponse.ts index 1fb655a3..cab3ff2e 100644 --- a/common/src/models/response/syncResponse.ts +++ b/common/src/models/response/syncResponse.ts @@ -1,57 +1,57 @@ -import { BaseResponse } from './baseResponse'; -import { CipherResponse } from './cipherResponse'; -import { CollectionDetailsResponse } from './collectionResponse'; -import { DomainsResponse } from './domainsResponse'; -import { FolderResponse } from './folderResponse'; -import { PolicyResponse } from './policyResponse'; -import { ProfileResponse } from './profileResponse'; -import { SendResponse } from './sendResponse'; +import { BaseResponse } from "./baseResponse"; +import { CipherResponse } from "./cipherResponse"; +import { CollectionDetailsResponse } from "./collectionResponse"; +import { DomainsResponse } from "./domainsResponse"; +import { FolderResponse } from "./folderResponse"; +import { PolicyResponse } from "./policyResponse"; +import { ProfileResponse } from "./profileResponse"; +import { SendResponse } from "./sendResponse"; export class SyncResponse extends BaseResponse { - profile?: ProfileResponse; - folders: FolderResponse[] = []; - collections: CollectionDetailsResponse[] = []; - ciphers: CipherResponse[] = []; - domains?: DomainsResponse; - policies?: PolicyResponse[] = []; - sends: SendResponse[] = []; + profile?: ProfileResponse; + folders: FolderResponse[] = []; + collections: CollectionDetailsResponse[] = []; + ciphers: CipherResponse[] = []; + domains?: DomainsResponse; + policies?: PolicyResponse[] = []; + sends: SendResponse[] = []; - constructor(response: any) { - super(response); + constructor(response: any) { + super(response); - const profile = this.getResponseProperty('Profile'); - if (profile != null) { - this.profile = new ProfileResponse(profile); - } - - const folders = this.getResponseProperty('Folders'); - if (folders != null) { - this.folders = folders.map((f: any) => new FolderResponse(f)); - } - - const collections = this.getResponseProperty('Collections'); - if (collections != null) { - this.collections = collections.map((c: any) => new CollectionDetailsResponse(c)); - } - - const ciphers = this.getResponseProperty('Ciphers'); - if (ciphers != null) { - this.ciphers = ciphers.map((c: any) => new CipherResponse(c)); - } - - const domains = this.getResponseProperty('Domains'); - if (domains != null) { - this.domains = new DomainsResponse(domains); - } - - const policies = this.getResponseProperty('Policies'); - if (policies != null) { - this.policies = policies.map((p: any) => new PolicyResponse(p)); - } - - const sends = this.getResponseProperty('Sends'); - if (sends != null) { - this.sends = sends.map((s: any) => new SendResponse(s)); - } + const profile = this.getResponseProperty("Profile"); + if (profile != null) { + this.profile = new ProfileResponse(profile); } + + const folders = this.getResponseProperty("Folders"); + if (folders != null) { + this.folders = folders.map((f: any) => new FolderResponse(f)); + } + + const collections = this.getResponseProperty("Collections"); + if (collections != null) { + this.collections = collections.map((c: any) => new CollectionDetailsResponse(c)); + } + + const ciphers = this.getResponseProperty("Ciphers"); + if (ciphers != null) { + this.ciphers = ciphers.map((c: any) => new CipherResponse(c)); + } + + const domains = this.getResponseProperty("Domains"); + if (domains != null) { + this.domains = new DomainsResponse(domains); + } + + const policies = this.getResponseProperty("Policies"); + if (policies != null) { + this.policies = policies.map((p: any) => new PolicyResponse(p)); + } + + const sends = this.getResponseProperty("Sends"); + if (sends != null) { + this.sends = sends.map((s: any) => new SendResponse(s)); + } + } } diff --git a/common/src/models/response/taxInfoResponse.ts b/common/src/models/response/taxInfoResponse.ts index 9759bbe3..bb4693ca 100644 --- a/common/src/models/response/taxInfoResponse.ts +++ b/common/src/models/response/taxInfoResponse.ts @@ -1,24 +1,24 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class TaxInfoResponse extends BaseResponse { - taxId: string; - taxIdType: string; - line1: string; - line2: string; - city: string; - state: string; - country: string; - postalCode: string; + taxId: string; + taxIdType: string; + line1: string; + line2: string; + city: string; + state: string; + country: string; + postalCode: string; - constructor(response: any) { - super(response); - this.taxId = this.getResponseProperty('TaxIdNumber'); - this.taxIdType = this.getResponseProperty('TaxIdType'); - this.line1 = this.getResponseProperty('Line1'); - this.line2 = this.getResponseProperty('Line2'); - this.city = this.getResponseProperty('City'); - this.state = this.getResponseProperty('State'); - this.postalCode = this.getResponseProperty('PostalCode'); - this.country = this.getResponseProperty('Country'); - } + constructor(response: any) { + super(response); + this.taxId = this.getResponseProperty("TaxIdNumber"); + this.taxIdType = this.getResponseProperty("TaxIdType"); + this.line1 = this.getResponseProperty("Line1"); + this.line2 = this.getResponseProperty("Line2"); + this.city = this.getResponseProperty("City"); + this.state = this.getResponseProperty("State"); + this.postalCode = this.getResponseProperty("PostalCode"); + this.country = this.getResponseProperty("Country"); + } } diff --git a/common/src/models/response/taxRateResponse.ts b/common/src/models/response/taxRateResponse.ts index 83970afa..28274a50 100644 --- a/common/src/models/response/taxRateResponse.ts +++ b/common/src/models/response/taxRateResponse.ts @@ -1,18 +1,18 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class TaxRateResponse extends BaseResponse { - id: string; - country: string; - state: string; - postalCode: string; - rate: number; + id: string; + country: string; + state: string; + postalCode: string; + rate: number; - constructor(response: any) { - super(response); - this.id = this.getResponseProperty('Id'); - this.country = this.getResponseProperty('Country'); - this.state = this.getResponseProperty('State'); - this.postalCode = this.getResponseProperty('PostalCode'); - this.rate = this.getResponseProperty('Rate'); - } + constructor(response: any) { + super(response); + this.id = this.getResponseProperty("Id"); + this.country = this.getResponseProperty("Country"); + this.state = this.getResponseProperty("State"); + this.postalCode = this.getResponseProperty("PostalCode"); + this.rate = this.getResponseProperty("Rate"); + } } diff --git a/common/src/models/response/twoFactorAuthenticatorResponse.ts b/common/src/models/response/twoFactorAuthenticatorResponse.ts index b08ecb19..8eb73eaa 100644 --- a/common/src/models/response/twoFactorAuthenticatorResponse.ts +++ b/common/src/models/response/twoFactorAuthenticatorResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class TwoFactorAuthenticatorResponse extends BaseResponse { - enabled: boolean; - key: string; + enabled: boolean; + key: string; - constructor(response: any) { - super(response); - this.enabled = this.getResponseProperty('Enabled'); - this.key = this.getResponseProperty('Key'); - } + constructor(response: any) { + super(response); + this.enabled = this.getResponseProperty("Enabled"); + this.key = this.getResponseProperty("Key"); + } } diff --git a/common/src/models/response/twoFactorDuoResponse.ts b/common/src/models/response/twoFactorDuoResponse.ts index 087fce48..401de796 100644 --- a/common/src/models/response/twoFactorDuoResponse.ts +++ b/common/src/models/response/twoFactorDuoResponse.ts @@ -1,16 +1,16 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class TwoFactorDuoResponse extends BaseResponse { - enabled: boolean; - host: string; - secretKey: string; - integrationKey: string; + enabled: boolean; + host: string; + secretKey: string; + integrationKey: string; - constructor(response: any) { - super(response); - this.enabled = this.getResponseProperty('Enabled'); - this.host = this.getResponseProperty('Host'); - this.secretKey = this.getResponseProperty('SecretKey'); - this.integrationKey = this.getResponseProperty('IntegrationKey'); - } + constructor(response: any) { + super(response); + this.enabled = this.getResponseProperty("Enabled"); + this.host = this.getResponseProperty("Host"); + this.secretKey = this.getResponseProperty("SecretKey"); + this.integrationKey = this.getResponseProperty("IntegrationKey"); + } } diff --git a/common/src/models/response/twoFactorEmailResponse.ts b/common/src/models/response/twoFactorEmailResponse.ts index 54f4a551..ad1936d3 100644 --- a/common/src/models/response/twoFactorEmailResponse.ts +++ b/common/src/models/response/twoFactorEmailResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class TwoFactorEmailResponse extends BaseResponse { - enabled: boolean; - email: string; + enabled: boolean; + email: string; - constructor(response: any) { - super(response); - this.enabled = this.getResponseProperty('Enabled'); - this.email = this.getResponseProperty('Email'); - } + constructor(response: any) { + super(response); + this.enabled = this.getResponseProperty("Enabled"); + this.email = this.getResponseProperty("Email"); + } } diff --git a/common/src/models/response/twoFactorProviderResponse.ts b/common/src/models/response/twoFactorProviderResponse.ts index 570b1d6e..6f149136 100644 --- a/common/src/models/response/twoFactorProviderResponse.ts +++ b/common/src/models/response/twoFactorProviderResponse.ts @@ -1,14 +1,14 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; -import { TwoFactorProviderType } from '../../enums/twoFactorProviderType'; +import { TwoFactorProviderType } from "../../enums/twoFactorProviderType"; export class TwoFactorProviderResponse extends BaseResponse { - enabled: boolean; - type: TwoFactorProviderType; + enabled: boolean; + type: TwoFactorProviderType; - constructor(response: any) { - super(response); - this.enabled = this.getResponseProperty('Enabled'); - this.type = this.getResponseProperty('Type'); - } + constructor(response: any) { + super(response); + this.enabled = this.getResponseProperty("Enabled"); + this.type = this.getResponseProperty("Type"); + } } diff --git a/common/src/models/response/twoFactorRescoverResponse.ts b/common/src/models/response/twoFactorRescoverResponse.ts index 62bfdfe6..0e26db9b 100644 --- a/common/src/models/response/twoFactorRescoverResponse.ts +++ b/common/src/models/response/twoFactorRescoverResponse.ts @@ -1,10 +1,10 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class TwoFactorRecoverResponse extends BaseResponse { - code: string; + code: string; - constructor(response: any) { - super(response); - this.code = this.getResponseProperty('Code'); - } + constructor(response: any) { + super(response); + this.code = this.getResponseProperty("Code"); + } } diff --git a/common/src/models/response/twoFactorWebAuthnResponse.ts b/common/src/models/response/twoFactorWebAuthnResponse.ts index 499bdca5..9c855b76 100644 --- a/common/src/models/response/twoFactorWebAuthnResponse.ts +++ b/common/src/models/response/twoFactorWebAuthnResponse.ts @@ -1,59 +1,59 @@ -import { Utils } from '../../misc/utils'; -import { BaseResponse } from './baseResponse'; +import { Utils } from "../../misc/utils"; +import { BaseResponse } from "./baseResponse"; export class TwoFactorWebAuthnResponse extends BaseResponse { - enabled: boolean; - keys: KeyResponse[]; + enabled: boolean; + keys: KeyResponse[]; - constructor(response: any) { - super(response); - this.enabled = this.getResponseProperty('Enabled'); - const keys = this.getResponseProperty('Keys'); - this.keys = keys == null ? null : keys.map((k: any) => new KeyResponse(k)); - } + constructor(response: any) { + super(response); + this.enabled = this.getResponseProperty("Enabled"); + const keys = this.getResponseProperty("Keys"); + this.keys = keys == null ? null : keys.map((k: any) => new KeyResponse(k)); + } } export class KeyResponse extends BaseResponse { - name: string; - id: number; - migrated: boolean; + name: string; + id: number; + migrated: boolean; - constructor(response: any) { - super(response); - this.name = this.getResponseProperty('Name'); - this.id = this.getResponseProperty('Id'); - this.migrated = this.getResponseProperty('Migrated'); - } + constructor(response: any) { + super(response); + this.name = this.getResponseProperty("Name"); + this.id = this.getResponseProperty("Id"); + this.migrated = this.getResponseProperty("Migrated"); + } } export class ChallengeResponse extends BaseResponse implements PublicKeyCredentialCreationOptions { - attestation?: AttestationConveyancePreference; - authenticatorSelection?: AuthenticatorSelectionCriteria; - challenge: BufferSource; - excludeCredentials?: PublicKeyCredentialDescriptor[]; - extensions?: AuthenticationExtensionsClientInputs; - pubKeyCredParams: PublicKeyCredentialParameters[]; - rp: PublicKeyCredentialRpEntity; - timeout?: number; - user: PublicKeyCredentialUserEntity; + attestation?: AttestationConveyancePreference; + authenticatorSelection?: AuthenticatorSelectionCriteria; + challenge: BufferSource; + excludeCredentials?: PublicKeyCredentialDescriptor[]; + extensions?: AuthenticationExtensionsClientInputs; + pubKeyCredParams: PublicKeyCredentialParameters[]; + rp: PublicKeyCredentialRpEntity; + timeout?: number; + user: PublicKeyCredentialUserEntity; - constructor(response: any) { - super(response); - this.attestation = this.getResponseProperty('attestation'); - this.authenticatorSelection = this.getResponseProperty('authenticatorSelection'); - this.challenge = Utils.fromUrlB64ToArray(this.getResponseProperty('challenge')); - this.excludeCredentials = this.getResponseProperty('excludeCredentials').map((c: any) => { - c.id = Utils.fromUrlB64ToArray(c.id).buffer; - return c; - }); - this.extensions = this.getResponseProperty('extensions'); - this.pubKeyCredParams = this.getResponseProperty('pubKeyCredParams'); - this.rp = this.getResponseProperty('rp'); - this.timeout = this.getResponseProperty('timeout'); + constructor(response: any) { + super(response); + this.attestation = this.getResponseProperty("attestation"); + this.authenticatorSelection = this.getResponseProperty("authenticatorSelection"); + this.challenge = Utils.fromUrlB64ToArray(this.getResponseProperty("challenge")); + this.excludeCredentials = this.getResponseProperty("excludeCredentials").map((c: any) => { + c.id = Utils.fromUrlB64ToArray(c.id).buffer; + return c; + }); + this.extensions = this.getResponseProperty("extensions"); + this.pubKeyCredParams = this.getResponseProperty("pubKeyCredParams"); + this.rp = this.getResponseProperty("rp"); + this.timeout = this.getResponseProperty("timeout"); - const user = this.getResponseProperty('user'); - user.id = Utils.fromUrlB64ToArray(user.id); + const user = this.getResponseProperty("user"); + user.id = Utils.fromUrlB64ToArray(user.id); - this.user = user; - } + this.user = user; + } } diff --git a/common/src/models/response/twoFactorYubiKeyResponse.ts b/common/src/models/response/twoFactorYubiKeyResponse.ts index 92d8cffb..ee75074b 100644 --- a/common/src/models/response/twoFactorYubiKeyResponse.ts +++ b/common/src/models/response/twoFactorYubiKeyResponse.ts @@ -1,22 +1,22 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class TwoFactorYubiKeyResponse extends BaseResponse { - enabled: boolean; - key1: string; - key2: string; - key3: string; - key4: string; - key5: string; - nfc: boolean; + enabled: boolean; + key1: string; + key2: string; + key3: string; + key4: string; + key5: string; + nfc: boolean; - constructor(response: any) { - super(response); - this.enabled = this.getResponseProperty('Enabled'); - this.key1 = this.getResponseProperty('Key1'); - this.key2 = this.getResponseProperty('Key2'); - this.key3 = this.getResponseProperty('Key3'); - this.key4 = this.getResponseProperty('Key4'); - this.key5 = this.getResponseProperty('Key5'); - this.nfc = this.getResponseProperty('Nfc'); - } + constructor(response: any) { + super(response); + this.enabled = this.getResponseProperty("Enabled"); + this.key1 = this.getResponseProperty("Key1"); + this.key2 = this.getResponseProperty("Key2"); + this.key3 = this.getResponseProperty("Key3"); + this.key4 = this.getResponseProperty("Key4"); + this.key5 = this.getResponseProperty("Key5"); + this.nfc = this.getResponseProperty("Nfc"); + } } diff --git a/common/src/models/response/userKeyResponse.ts b/common/src/models/response/userKeyResponse.ts index 66af3639..5550abdf 100644 --- a/common/src/models/response/userKeyResponse.ts +++ b/common/src/models/response/userKeyResponse.ts @@ -1,12 +1,12 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class UserKeyResponse extends BaseResponse { - userId: string; - publicKey: string; + userId: string; + publicKey: string; - constructor(response: any) { - super(response); - this.userId = this.getResponseProperty('UserId'); - this.publicKey = this.getResponseProperty('PublicKey'); - } + constructor(response: any) { + super(response); + this.userId = this.getResponseProperty("UserId"); + this.publicKey = this.getResponseProperty("PublicKey"); + } } diff --git a/common/src/models/view/attachmentView.ts b/common/src/models/view/attachmentView.ts index 45c04f48..7bf8186f 100644 --- a/common/src/models/view/attachmentView.ts +++ b/common/src/models/view/attachmentView.ts @@ -1,35 +1,35 @@ -import { View } from './view'; +import { View } from "./view"; -import { Attachment } from '../domain/attachment'; -import { SymmetricCryptoKey } from '../domain/symmetricCryptoKey'; +import { Attachment } from "../domain/attachment"; +import { SymmetricCryptoKey } from "../domain/symmetricCryptoKey"; export class AttachmentView implements View { - id: string = null; - url: string = null; - size: string = null; - sizeName: string = null; - fileName: string = null; - key: SymmetricCryptoKey = null; + id: string = null; + url: string = null; + size: string = null; + sizeName: string = null; + fileName: string = null; + key: SymmetricCryptoKey = null; - constructor(a?: Attachment) { - if (!a) { - return; - } - - this.id = a.id; - this.url = a.url; - this.size = a.size; - this.sizeName = a.sizeName; + constructor(a?: Attachment) { + if (!a) { + return; } - get fileSize(): number { - try { - if (this.size != null) { - return parseInt(this.size, null); - } - } catch { - // Invalid file size. - } - return 0; + this.id = a.id; + this.url = a.url; + this.size = a.size; + this.sizeName = a.sizeName; + } + + get fileSize(): number { + try { + if (this.size != null) { + return parseInt(this.size, null); + } + } catch { + // Invalid file size. } + return 0; + } } diff --git a/common/src/models/view/cardView.ts b/common/src/models/view/cardView.ts index 94e7ae49..4aa3a999 100644 --- a/common/src/models/view/cardView.ts +++ b/common/src/models/view/cardView.ts @@ -1,86 +1,87 @@ -import { ItemView } from './itemView'; +import { ItemView } from "./itemView"; -import { Card } from '../domain/card'; +import { Card } from "../domain/card"; -import { CardLinkedId as LinkedId } from '../../enums/linkedIdType'; +import { CardLinkedId as LinkedId } from "../../enums/linkedIdType"; -import { linkedFieldOption } from '../../misc/linkedFieldOption.decorator'; +import { linkedFieldOption } from "../../misc/linkedFieldOption.decorator"; export class CardView extends ItemView { - @linkedFieldOption(LinkedId.CardholderName) - cardholderName: string = null; - @linkedFieldOption(LinkedId.ExpMonth, 'expirationMonth') - expMonth: string = null; - @linkedFieldOption(LinkedId.ExpYear, 'expirationYear') - expYear: string = null; - @linkedFieldOption(LinkedId.Code, 'securityCode') - code: string = null; + @linkedFieldOption(LinkedId.CardholderName) + cardholderName: string = null; + @linkedFieldOption(LinkedId.ExpMonth, "expirationMonth") + expMonth: string = null; + @linkedFieldOption(LinkedId.ExpYear, "expirationYear") + expYear: string = null; + @linkedFieldOption(LinkedId.Code, "securityCode") + code: string = null; - // tslint:disable - private _brand: string = null; - private _number: string = null; - private _subTitle: string = null; - // tslint:enable + // tslint:disable + private _brand: string = null; + private _number: string = null; + private _subTitle: string = null; + // tslint:enable - constructor(c?: Card) { - super(); - } + constructor(c?: Card) { + super(); + } - get maskedCode(): string { - return this.code != null ? '•'.repeat(this.code.length) : null; - } + get maskedCode(): string { + return this.code != null ? "•".repeat(this.code.length) : null; + } - get maskedNumber(): string { - return this.number != null ? '•'.repeat(this.number.length) : null; - } + get maskedNumber(): string { + return this.number != null ? "•".repeat(this.number.length) : null; + } - @linkedFieldOption(LinkedId.Brand) - get brand(): string { - return this._brand; - } - set brand(value: string) { - this._brand = value; - this._subTitle = null; - } + @linkedFieldOption(LinkedId.Brand) + get brand(): string { + return this._brand; + } + set brand(value: string) { + this._brand = value; + this._subTitle = null; + } - @linkedFieldOption(LinkedId.Number) - get number(): string { - return this._number; - } - set number(value: string) { - this._number = value; - this._subTitle = null; - } + @linkedFieldOption(LinkedId.Number) + get number(): string { + return this._number; + } + set number(value: string) { + this._number = value; + this._subTitle = null; + } - get subTitle(): string { - if (this._subTitle == null) { - this._subTitle = this.brand; - if (this.number != null && this.number.length >= 4) { - if (this._subTitle != null && this._subTitle !== '') { - this._subTitle += ', '; - } else { - this._subTitle = ''; - } - - // Show last 5 on amex, last 4 for all others - const count = this.number.length >= 5 && this.number.match(new RegExp('^3[47]')) != null ? 5 : 4; - this._subTitle += ('*' + this.number.substr(this.number.length - count)); - } - } - return this._subTitle; - } - - get expiration(): string { - if (!this.expMonth && !this.expYear) { - return null; + get subTitle(): string { + if (this._subTitle == null) { + this._subTitle = this.brand; + if (this.number != null && this.number.length >= 4) { + if (this._subTitle != null && this._subTitle !== "") { + this._subTitle += ", "; + } else { + this._subTitle = ""; } - let exp = this.expMonth != null ? ('0' + this.expMonth).slice(-2) : '__'; - exp += (' / ' + (this.expYear != null ? this.formatYear(this.expYear) : '____')); - return exp; + // Show last 5 on amex, last 4 for all others + const count = + this.number.length >= 5 && this.number.match(new RegExp("^3[47]")) != null ? 5 : 4; + this._subTitle += "*" + this.number.substr(this.number.length - count); + } + } + return this._subTitle; + } + + get expiration(): string { + if (!this.expMonth && !this.expYear) { + return null; } - private formatYear(year: string): string { - return year.length === 2 ? '20' + year : year; - } + let exp = this.expMonth != null ? ("0" + this.expMonth).slice(-2) : "__"; + exp += " / " + (this.expYear != null ? this.formatYear(this.expYear) : "____"); + return exp; + } + + private formatYear(year: string): string { + return year.length === 2 ? "20" + year : year; + } } diff --git a/common/src/models/view/cipherView.ts b/common/src/models/view/cipherView.ts index e4e5c3f1..073b2a2c 100644 --- a/common/src/models/view/cipherView.ts +++ b/common/src/models/view/cipherView.ts @@ -1,136 +1,136 @@ -import { CipherRepromptType } from '../../enums/cipherRepromptType'; -import { CipherType } from '../../enums/cipherType'; -import { LinkedIdType } from '../../enums/linkedIdType'; +import { CipherRepromptType } from "../../enums/cipherRepromptType"; +import { CipherType } from "../../enums/cipherType"; +import { LinkedIdType } from "../../enums/linkedIdType"; -import { Cipher } from '../domain/cipher'; +import { Cipher } from "../domain/cipher"; -import { AttachmentView } from './attachmentView'; -import { CardView } from './cardView'; -import { FieldView } from './fieldView'; -import { IdentityView } from './identityView'; -import { ItemView } from './itemView'; -import { LoginView } from './loginView'; -import { PasswordHistoryView } from './passwordHistoryView'; -import { SecureNoteView } from './secureNoteView'; -import { View } from './view'; +import { AttachmentView } from "./attachmentView"; +import { CardView } from "./cardView"; +import { FieldView } from "./fieldView"; +import { IdentityView } from "./identityView"; +import { ItemView } from "./itemView"; +import { LoginView } from "./loginView"; +import { PasswordHistoryView } from "./passwordHistoryView"; +import { SecureNoteView } from "./secureNoteView"; +import { View } from "./view"; export class CipherView implements View { - id: string = null; - organizationId: string = null; - folderId: string = null; - name: string = null; - notes: string = null; - type: CipherType = null; - favorite = false; - organizationUseTotp = false; - edit = false; - viewPassword = true; - localData: any; - login = new LoginView(); - identity = new IdentityView(); - card = new CardView(); - secureNote = new SecureNoteView(); - attachments: AttachmentView[] = null; - fields: FieldView[] = null; - passwordHistory: PasswordHistoryView[] = null; - collectionIds: string[] = null; - revisionDate: Date = null; - deletedDate: Date = null; - reprompt: CipherRepromptType = CipherRepromptType.None; + id: string = null; + organizationId: string = null; + folderId: string = null; + name: string = null; + notes: string = null; + type: CipherType = null; + favorite = false; + organizationUseTotp = false; + edit = false; + viewPassword = true; + localData: any; + login = new LoginView(); + identity = new IdentityView(); + card = new CardView(); + secureNote = new SecureNoteView(); + attachments: AttachmentView[] = null; + fields: FieldView[] = null; + passwordHistory: PasswordHistoryView[] = null; + collectionIds: string[] = null; + revisionDate: Date = null; + deletedDate: Date = null; + reprompt: CipherRepromptType = CipherRepromptType.None; - constructor(c?: Cipher) { - if (!c) { - return; + constructor(c?: Cipher) { + if (!c) { + return; + } + + this.id = c.id; + this.organizationId = c.organizationId; + this.folderId = c.folderId; + this.favorite = c.favorite; + this.organizationUseTotp = c.organizationUseTotp; + this.edit = c.edit; + this.viewPassword = c.viewPassword; + this.type = c.type; + this.localData = c.localData; + this.collectionIds = c.collectionIds; + this.revisionDate = c.revisionDate; + this.deletedDate = c.deletedDate; + // Old locally stored ciphers might have reprompt == null. If so set it to None. + this.reprompt = c.reprompt ?? CipherRepromptType.None; + } + + private get item() { + switch (this.type) { + case CipherType.Login: + return this.login; + case CipherType.SecureNote: + return this.secureNote; + case CipherType.Card: + return this.card; + case CipherType.Identity: + return this.identity; + default: + break; + } + + return null; + } + + get subTitle(): string { + return this.item.subTitle; + } + + get hasPasswordHistory(): boolean { + return this.passwordHistory && this.passwordHistory.length > 0; + } + + get hasAttachments(): boolean { + return this.attachments && this.attachments.length > 0; + } + + get hasOldAttachments(): boolean { + if (this.hasAttachments) { + for (let i = 0; i < this.attachments.length; i++) { + if (this.attachments[i].key == null) { + return true; } + } + } + return false; + } - this.id = c.id; - this.organizationId = c.organizationId; - this.folderId = c.folderId; - this.favorite = c.favorite; - this.organizationUseTotp = c.organizationUseTotp; - this.edit = c.edit; - this.viewPassword = c.viewPassword; - this.type = c.type; - this.localData = c.localData; - this.collectionIds = c.collectionIds; - this.revisionDate = c.revisionDate; - this.deletedDate = c.deletedDate; - // Old locally stored ciphers might have reprompt == null. If so set it to None. - this.reprompt = c.reprompt ?? CipherRepromptType.None; + get hasFields(): boolean { + return this.fields && this.fields.length > 0; + } + + get passwordRevisionDisplayDate(): Date { + if (this.type !== CipherType.Login || this.login == null) { + return null; + } else if (this.login.password == null || this.login.password === "") { + return null; + } + return this.login.passwordRevisionDate; + } + + get isDeleted(): boolean { + return this.deletedDate != null; + } + + get linkedFieldOptions() { + return this.item.linkedFieldOptions; + } + + linkedFieldValue(id: LinkedIdType) { + const linkedFieldOption = this.linkedFieldOptions?.get(id); + if (linkedFieldOption == null) { + return null; } - private get item() { - switch (this.type) { - case CipherType.Login: - return this.login; - case CipherType.SecureNote: - return this.secureNote; - case CipherType.Card: - return this.card; - case CipherType.Identity: - return this.identity; - default: - break; - } + const item = this.item; + return this.item[linkedFieldOption.propertyKey as keyof typeof item]; + } - return null; - } - - get subTitle(): string { - return this.item.subTitle; - } - - get hasPasswordHistory(): boolean { - return this.passwordHistory && this.passwordHistory.length > 0; - } - - get hasAttachments(): boolean { - return this.attachments && this.attachments.length > 0; - } - - get hasOldAttachments(): boolean { - if (this.hasAttachments) { - for (let i = 0; i < this.attachments.length; i++) { - if (this.attachments[i].key == null) { - return true; - } - } - } - return false; - } - - get hasFields(): boolean { - return this.fields && this.fields.length > 0; - } - - get passwordRevisionDisplayDate(): Date { - if (this.type !== CipherType.Login || this.login == null) { - return null; - } else if (this.login.password == null || this.login.password === '') { - return null; - } - return this.login.passwordRevisionDate; - } - - get isDeleted(): boolean { - return this.deletedDate != null; - } - - get linkedFieldOptions() { - return this.item.linkedFieldOptions; - } - - linkedFieldValue(id: LinkedIdType) { - const linkedFieldOption = this.linkedFieldOptions?.get(id); - if (linkedFieldOption == null) { - return null; - } - - const item = this.item; - return this.item[linkedFieldOption.propertyKey as keyof typeof item]; - } - - linkedFieldI18nKey(id: LinkedIdType): string { - return this.linkedFieldOptions.get(id)?.i18nKey; - } + linkedFieldI18nKey(id: LinkedIdType): string { + return this.linkedFieldOptions.get(id)?.i18nKey; + } } diff --git a/common/src/models/view/collectionView.ts b/common/src/models/view/collectionView.ts index 9c27c9fb..0f580837 100644 --- a/common/src/models/view/collectionView.ts +++ b/common/src/models/view/collectionView.ts @@ -1,29 +1,29 @@ -import { View } from './view'; +import { View } from "./view"; -import { Collection } from '../domain/collection'; -import { ITreeNodeObject } from '../domain/treeNode'; +import { Collection } from "../domain/collection"; +import { ITreeNodeObject } from "../domain/treeNode"; -import { CollectionGroupDetailsResponse } from '../response/collectionResponse'; +import { CollectionGroupDetailsResponse } from "../response/collectionResponse"; export class CollectionView implements View, ITreeNodeObject { - id: string = null; - organizationId: string = null; - name: string = null; - externalId: string = null; - readOnly: boolean = null; - hidePasswords: boolean = null; + id: string = null; + organizationId: string = null; + name: string = null; + externalId: string = null; + readOnly: boolean = null; + hidePasswords: boolean = null; - constructor(c?: Collection | CollectionGroupDetailsResponse) { - if (!c) { - return; - } - - this.id = c.id; - this.organizationId = c.organizationId; - this.externalId = c.externalId; - if (c instanceof Collection) { - this.readOnly = c.readOnly; - this.hidePasswords = c.hidePasswords; - } + constructor(c?: Collection | CollectionGroupDetailsResponse) { + if (!c) { + return; } + + this.id = c.id; + this.organizationId = c.organizationId; + this.externalId = c.externalId; + if (c instanceof Collection) { + this.readOnly = c.readOnly; + this.hidePasswords = c.hidePasswords; + } + } } diff --git a/common/src/models/view/eventView.ts b/common/src/models/view/eventView.ts index 39e40c4d..17339ecb 100644 --- a/common/src/models/view/eventView.ts +++ b/common/src/models/view/eventView.ts @@ -1,27 +1,27 @@ -import { EventType } from '../../enums/eventType'; +import { EventType } from "../../enums/eventType"; export class EventView { - message: string; - humanReadableMessage: string; - appIcon: string; - appName: string; - userId: string; - userName: string; - userEmail: string; - date: string; - ip: string; - type: EventType; + message: string; + humanReadableMessage: string; + appIcon: string; + appName: string; + userId: string; + userName: string; + userEmail: string; + date: string; + ip: string; + type: EventType; - constructor(data: Required) { - this.message = data.message; - this.humanReadableMessage = data.humanReadableMessage; - this.appIcon = data.appIcon; - this.appName = data.appName; - this.userId = data.userId; - this.userName = data.userName; - this.userEmail = data.userEmail; - this.date = data.date; - this.ip = data.ip; - this.type = data.type; - } + constructor(data: Required) { + this.message = data.message; + this.humanReadableMessage = data.humanReadableMessage; + this.appIcon = data.appIcon; + this.appName = data.appName; + this.userId = data.userId; + this.userName = data.userName; + this.userEmail = data.userEmail; + this.date = data.date; + this.ip = data.ip; + this.type = data.type; + } } diff --git a/common/src/models/view/fieldView.ts b/common/src/models/view/fieldView.ts index 3202d4b1..c1c1b1e4 100644 --- a/common/src/models/view/fieldView.ts +++ b/common/src/models/view/fieldView.ts @@ -1,28 +1,28 @@ -import { FieldType } from '../../enums/fieldType'; -import { LinkedIdType } from '../../enums/linkedIdType'; +import { FieldType } from "../../enums/fieldType"; +import { LinkedIdType } from "../../enums/linkedIdType"; -import { View } from './view'; +import { View } from "./view"; -import { Field } from '../domain/field'; +import { Field } from "../domain/field"; export class FieldView implements View { - name: string = null; - value: string = null; - type: FieldType = null; - newField: boolean = false; // Marks if the field is new and hasn't been saved - showValue: boolean = false; - linkedId: LinkedIdType = null; + name: string = null; + value: string = null; + type: FieldType = null; + newField: boolean = false; // Marks if the field is new and hasn't been saved + showValue: boolean = false; + linkedId: LinkedIdType = null; - constructor(f?: Field) { - if (!f) { - return; - } - - this.type = f.type; - this.linkedId = f.linkedId; + constructor(f?: Field) { + if (!f) { + return; } - get maskedValue(): string { - return this.value != null ? '••••••••' : null; - } + this.type = f.type; + this.linkedId = f.linkedId; + } + + get maskedValue(): string { + return this.value != null ? "••••••••" : null; + } } diff --git a/common/src/models/view/folderView.ts b/common/src/models/view/folderView.ts index 1446a972..5ecd8822 100644 --- a/common/src/models/view/folderView.ts +++ b/common/src/models/view/folderView.ts @@ -1,19 +1,19 @@ -import { View } from './view'; +import { View } from "./view"; -import { Folder } from '../domain/folder'; -import { ITreeNodeObject } from '../domain/treeNode'; +import { Folder } from "../domain/folder"; +import { ITreeNodeObject } from "../domain/treeNode"; export class FolderView implements View, ITreeNodeObject { - id: string = null; - name: string = null; - revisionDate: Date = null; + id: string = null; + name: string = null; + revisionDate: Date = null; - constructor(f?: Folder) { - if (!f) { - return; - } - - this.id = f.id; - this.revisionDate = f.revisionDate; + constructor(f?: Folder) { + if (!f) { + return; } + + this.id = f.id; + this.revisionDate = f.revisionDate; + } } diff --git a/common/src/models/view/identityView.ts b/common/src/models/view/identityView.ts index 844a8acd..10e6616e 100644 --- a/common/src/models/view/identityView.ts +++ b/common/src/models/view/identityView.ts @@ -1,143 +1,148 @@ -import { ItemView } from './itemView'; +import { ItemView } from "./itemView"; -import { Identity } from '../domain/identity'; +import { Identity } from "../domain/identity"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; -import { IdentityLinkedId as LinkedId } from '../../enums/linkedIdType'; +import { IdentityLinkedId as LinkedId } from "../../enums/linkedIdType"; -import { linkedFieldOption } from '../../misc/linkedFieldOption.decorator'; +import { linkedFieldOption } from "../../misc/linkedFieldOption.decorator"; export class IdentityView extends ItemView { - @linkedFieldOption(LinkedId.Title) - title: string = null; - @linkedFieldOption(LinkedId.MiddleName) - middleName: string = null; - @linkedFieldOption(LinkedId.Address1) - address1: string = null; - @linkedFieldOption(LinkedId.Address2) - address2: string = null; - @linkedFieldOption(LinkedId.Address3) - address3: string = null; - @linkedFieldOption(LinkedId.City, 'cityTown') - city: string = null; - @linkedFieldOption(LinkedId.State, 'stateProvince') - state: string = null; - @linkedFieldOption(LinkedId.PostalCode, 'zipPostalCode') - postalCode: string = null; - @linkedFieldOption(LinkedId.Country) - country: string = null; - @linkedFieldOption(LinkedId.Company) - company: string = null; - @linkedFieldOption(LinkedId.Email) - email: string = null; - @linkedFieldOption(LinkedId.Phone) - phone: string = null; - @linkedFieldOption(LinkedId.Ssn) - ssn: string = null; - @linkedFieldOption(LinkedId.Username) - username: string = null; - @linkedFieldOption(LinkedId.PassportNumber) - passportNumber: string = null; - @linkedFieldOption(LinkedId.LicenseNumber) - licenseNumber: string = null; + @linkedFieldOption(LinkedId.Title) + title: string = null; + @linkedFieldOption(LinkedId.MiddleName) + middleName: string = null; + @linkedFieldOption(LinkedId.Address1) + address1: string = null; + @linkedFieldOption(LinkedId.Address2) + address2: string = null; + @linkedFieldOption(LinkedId.Address3) + address3: string = null; + @linkedFieldOption(LinkedId.City, "cityTown") + city: string = null; + @linkedFieldOption(LinkedId.State, "stateProvince") + state: string = null; + @linkedFieldOption(LinkedId.PostalCode, "zipPostalCode") + postalCode: string = null; + @linkedFieldOption(LinkedId.Country) + country: string = null; + @linkedFieldOption(LinkedId.Company) + company: string = null; + @linkedFieldOption(LinkedId.Email) + email: string = null; + @linkedFieldOption(LinkedId.Phone) + phone: string = null; + @linkedFieldOption(LinkedId.Ssn) + ssn: string = null; + @linkedFieldOption(LinkedId.Username) + username: string = null; + @linkedFieldOption(LinkedId.PassportNumber) + passportNumber: string = null; + @linkedFieldOption(LinkedId.LicenseNumber) + licenseNumber: string = null; - // tslint:disable - private _firstName: string = null; - private _lastName: string = null; - private _subTitle: string = null; - // tslint:enable + // tslint:disable + private _firstName: string = null; + private _lastName: string = null; + private _subTitle: string = null; + // tslint:enable - constructor(i?: Identity) { - super(); - } + constructor(i?: Identity) { + super(); + } - @linkedFieldOption(LinkedId.FirstName) - get firstName(): string { - return this._firstName; - } - set firstName(value: string) { - this._firstName = value; - this._subTitle = null; - } + @linkedFieldOption(LinkedId.FirstName) + get firstName(): string { + return this._firstName; + } + set firstName(value: string) { + this._firstName = value; + this._subTitle = null; + } - @linkedFieldOption(LinkedId.LastName) - get lastName(): string { - return this._lastName; - } - set lastName(value: string) { - this._lastName = value; - this._subTitle = null; - } + @linkedFieldOption(LinkedId.LastName) + get lastName(): string { + return this._lastName; + } + set lastName(value: string) { + this._lastName = value; + this._subTitle = null; + } - get subTitle(): string { - if (this._subTitle == null && (this.firstName != null || this.lastName != null)) { - this._subTitle = ''; - if (this.firstName != null) { - this._subTitle = this.firstName; - } - if (this.lastName != null) { - if (this._subTitle !== '') { - this._subTitle += ' '; - } - this._subTitle += this.lastName; - } + get subTitle(): string { + if (this._subTitle == null && (this.firstName != null || this.lastName != null)) { + this._subTitle = ""; + if (this.firstName != null) { + this._subTitle = this.firstName; + } + if (this.lastName != null) { + if (this._subTitle !== "") { + this._subTitle += " "; } - - return this._subTitle; + this._subTitle += this.lastName; + } } - @linkedFieldOption(LinkedId.FullName) - get fullName(): string { - if (this.title != null || this.firstName != null || this.middleName != null || this.lastName != null) { - let name = ''; - if (this.title != null) { - name += (this.title + ' '); - } - if (this.firstName != null) { - name += (this.firstName + ' '); - } - if (this.middleName != null) { - name += (this.middleName + ' '); - } - if (this.lastName != null) { - name += this.lastName; - } - return name.trim(); - } + return this._subTitle; + } - return null; + @linkedFieldOption(LinkedId.FullName) + get fullName(): string { + if ( + this.title != null || + this.firstName != null || + this.middleName != null || + this.lastName != null + ) { + let name = ""; + if (this.title != null) { + name += this.title + " "; + } + if (this.firstName != null) { + name += this.firstName + " "; + } + if (this.middleName != null) { + name += this.middleName + " "; + } + if (this.lastName != null) { + name += this.lastName; + } + return name.trim(); } - get fullAddress(): string { - let address = this.address1; - if (!Utils.isNullOrWhitespace(this.address2)) { - if (!Utils.isNullOrWhitespace(address)) { - address += ', '; - } - address += this.address2; - } - if (!Utils.isNullOrWhitespace(this.address3)) { - if (!Utils.isNullOrWhitespace(address)) { - address += ', '; - } - address += this.address3; - } - return address; - } + return null; + } - get fullAddressPart2(): string { - if (this.city == null && this.state == null && this.postalCode == null) { - return null; - } - const city = this.city || '-'; - const state = this.state; - const postalCode = this.postalCode || '-'; - let addressPart2 = city; - if (!Utils.isNullOrWhitespace(state)) { - addressPart2 += ', ' + state; - } - addressPart2 += ', ' + postalCode; - return addressPart2; + get fullAddress(): string { + let address = this.address1; + if (!Utils.isNullOrWhitespace(this.address2)) { + if (!Utils.isNullOrWhitespace(address)) { + address += ", "; + } + address += this.address2; } + if (!Utils.isNullOrWhitespace(this.address3)) { + if (!Utils.isNullOrWhitespace(address)) { + address += ", "; + } + address += this.address3; + } + return address; + } + + get fullAddressPart2(): string { + if (this.city == null && this.state == null && this.postalCode == null) { + return null; + } + const city = this.city || "-"; + const state = this.state; + const postalCode = this.postalCode || "-"; + let addressPart2 = city; + if (!Utils.isNullOrWhitespace(state)) { + addressPart2 += ", " + state; + } + addressPart2 += ", " + postalCode; + return addressPart2; + } } diff --git a/common/src/models/view/itemView.ts b/common/src/models/view/itemView.ts index aaeac473..edd85b7d 100644 --- a/common/src/models/view/itemView.ts +++ b/common/src/models/view/itemView.ts @@ -1,8 +1,8 @@ -import { View } from './view'; +import { View } from "./view"; -import { LinkedMetadata } from '../../misc/linkedFieldOption.decorator'; +import { LinkedMetadata } from "../../misc/linkedFieldOption.decorator"; export abstract class ItemView implements View { - linkedFieldOptions: Map; - abstract get subTitle(): string; + linkedFieldOptions: Map; + abstract get subTitle(): string; } diff --git a/common/src/models/view/loginUriView.ts b/common/src/models/view/loginUriView.ts index eab4806b..cd5dc2b8 100644 --- a/common/src/models/view/loginUriView.ts +++ b/common/src/models/view/loginUriView.ts @@ -1,125 +1,131 @@ -import { UriMatchType } from '../../enums/uriMatchType'; +import { UriMatchType } from "../../enums/uriMatchType"; -import { View } from './view'; +import { View } from "./view"; -import { LoginUri } from '../domain/loginUri'; +import { LoginUri } from "../domain/loginUri"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; const CanLaunchWhitelist = [ - 'https://', - 'http://', - 'ssh://', - 'ftp://', - 'sftp://', - 'irc://', - 'vnc://', - // https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/remote-desktop-uri - 'rdp://', // Legacy RDP URI scheme - 'ms-rd:', // Preferred RDP URI scheme - 'chrome://', - 'iosapp://', - 'androidapp://', + "https://", + "http://", + "ssh://", + "ftp://", + "sftp://", + "irc://", + "vnc://", + // https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/remote-desktop-uri + "rdp://", // Legacy RDP URI scheme + "ms-rd:", // Preferred RDP URI scheme + "chrome://", + "iosapp://", + "androidapp://", ]; export class LoginUriView implements View { - match: UriMatchType = null; + match: UriMatchType = null; - // tslint:disable - private _uri: string = null; - private _domain: string = null; - private _hostname: string = null; - private _host: string = null; - private _canLaunch: boolean = null; - // tslint:enable + // tslint:disable + private _uri: string = null; + private _domain: string = null; + private _hostname: string = null; + private _host: string = null; + private _canLaunch: boolean = null; + // tslint:enable - constructor(u?: LoginUri) { - if (!u) { - return; - } - - this.match = u.match; + constructor(u?: LoginUri) { + if (!u) { + return; } - get uri(): string { - return this._uri; - } - set uri(value: string) { - this._uri = value; + this.match = u.match; + } + + get uri(): string { + return this._uri; + } + set uri(value: string) { + this._uri = value; + this._domain = null; + this._canLaunch = null; + } + + get domain(): string { + if (this._domain == null && this.uri != null) { + this._domain = Utils.getDomain(this.uri); + if (this._domain === "") { this._domain = null; - this._canLaunch = null; + } } - get domain(): string { - if (this._domain == null && this.uri != null) { - this._domain = Utils.getDomain(this.uri); - if (this._domain === '') { - this._domain = null; - } + return this._domain; + } + + get hostname(): string { + if (this.match === UriMatchType.RegularExpression) { + return null; + } + if (this._hostname == null && this.uri != null) { + this._hostname = Utils.getHostname(this.uri); + if (this._hostname === "") { + this._hostname = null; + } + } + + return this._hostname; + } + + get host(): string { + if (this.match === UriMatchType.RegularExpression) { + return null; + } + if (this._host == null && this.uri != null) { + this._host = Utils.getHost(this.uri); + if (this._host === "") { + this._host = null; + } + } + + return this._host; + } + + get hostnameOrUri(): string { + return this.hostname != null ? this.hostname : this.uri; + } + + get hostOrUri(): string { + return this.host != null ? this.host : this.uri; + } + + get isWebsite(): boolean { + return ( + this.uri != null && + (this.uri.indexOf("http://") === 0 || + this.uri.indexOf("https://") === 0 || + (this.uri.indexOf("://") < 0 && Utils.tldEndingRegex.test(this.uri))) + ); + } + + get canLaunch(): boolean { + if (this._canLaunch != null) { + return this._canLaunch; + } + if (this.uri != null && this.match !== UriMatchType.RegularExpression) { + const uri = this.launchUri; + for (let i = 0; i < CanLaunchWhitelist.length; i++) { + if (uri.indexOf(CanLaunchWhitelist[i]) === 0) { + this._canLaunch = true; + return this._canLaunch; } - - return this._domain; + } } + this._canLaunch = false; + return this._canLaunch; + } - get hostname(): string { - if (this.match === UriMatchType.RegularExpression) { - return null; - } - if (this._hostname == null && this.uri != null) { - this._hostname = Utils.getHostname(this.uri); - if (this._hostname === '') { - this._hostname = null; - } - } - - return this._hostname; - } - - get host(): string { - if (this.match === UriMatchType.RegularExpression) { - return null; - } - if (this._host == null && this.uri != null) { - this._host = Utils.getHost(this.uri); - if (this._host === '') { - this._host = null; - } - } - - return this._host; - } - - get hostnameOrUri(): string { - return this.hostname != null ? this.hostname : this.uri; - } - - get hostOrUri(): string { - return this.host != null ? this.host : this.uri; - } - - get isWebsite(): boolean { - return this.uri != null && (this.uri.indexOf('http://') === 0 || this.uri.indexOf('https://') === 0 || - (this.uri.indexOf('://') < 0 && Utils.tldEndingRegex.test(this.uri))); - } - - get canLaunch(): boolean { - if (this._canLaunch != null) { - return this._canLaunch; - } - if (this.uri != null && this.match !== UriMatchType.RegularExpression) { - const uri = this.launchUri; - for (let i = 0; i < CanLaunchWhitelist.length; i++) { - if (uri.indexOf(CanLaunchWhitelist[i]) === 0) { - this._canLaunch = true; - return this._canLaunch; - } - } - } - this._canLaunch = false; - return this._canLaunch; - } - - get launchUri(): string { - return this.uri.indexOf('://') < 0 && Utils.tldEndingRegex.test(this.uri) ? ('http://' + this.uri) : this.uri; - } + get launchUri(): string { + return this.uri.indexOf("://") < 0 && Utils.tldEndingRegex.test(this.uri) + ? "http://" + this.uri + : this.uri; + } } diff --git a/common/src/models/view/loginView.ts b/common/src/models/view/loginView.ts index 3bd1ea58..b301f532 100644 --- a/common/src/models/view/loginView.ts +++ b/common/src/models/view/loginView.ts @@ -1,66 +1,66 @@ -import { ItemView } from './itemView'; -import { LoginUriView } from './loginUriView'; +import { ItemView } from "./itemView"; +import { LoginUriView } from "./loginUriView"; -import { Utils } from '../../misc/utils'; +import { Utils } from "../../misc/utils"; -import { Login } from '../domain/login'; +import { Login } from "../domain/login"; -import { LoginLinkedId as LinkedId } from '../../enums/linkedIdType'; +import { LoginLinkedId as LinkedId } from "../../enums/linkedIdType"; -import { linkedFieldOption } from '../../misc/linkedFieldOption.decorator'; +import { linkedFieldOption } from "../../misc/linkedFieldOption.decorator"; export class LoginView extends ItemView { - @linkedFieldOption(LinkedId.Username) - username: string = null; - @linkedFieldOption(LinkedId.Password) - password: string = null; + @linkedFieldOption(LinkedId.Username) + username: string = null; + @linkedFieldOption(LinkedId.Password) + password: string = null; - passwordRevisionDate?: Date = null; - totp: string = null; - uris: LoginUriView[] = null; - autofillOnPageLoad: boolean = null; + passwordRevisionDate?: Date = null; + totp: string = null; + uris: LoginUriView[] = null; + autofillOnPageLoad: boolean = null; - constructor(l?: Login) { - super(); - if (!l) { - return; - } - - this.passwordRevisionDate = l.passwordRevisionDate; - this.autofillOnPageLoad = l.autofillOnPageLoad; + constructor(l?: Login) { + super(); + if (!l) { + return; } - get uri(): string { - return this.hasUris ? this.uris[0].uri : null; - } + this.passwordRevisionDate = l.passwordRevisionDate; + this.autofillOnPageLoad = l.autofillOnPageLoad; + } - get maskedPassword(): string { - return this.password != null ? '••••••••' : null; - } + get uri(): string { + return this.hasUris ? this.uris[0].uri : null; + } - get subTitle(): string { - return this.username; - } + get maskedPassword(): string { + return this.password != null ? "••••••••" : null; + } - get canLaunch(): boolean { - return this.hasUris && this.uris.some(u => u.canLaunch); - } + get subTitle(): string { + return this.username; + } - get hasTotp(): boolean { - return !Utils.isNullOrWhitespace(this.totp); - } + get canLaunch(): boolean { + return this.hasUris && this.uris.some((u) => u.canLaunch); + } - get launchUri(): string { - if (this.hasUris) { - const uri = this.uris.find(u => u.canLaunch); - if (uri != null) { - return uri.launchUri; - } - } - return null; - } + get hasTotp(): boolean { + return !Utils.isNullOrWhitespace(this.totp); + } - get hasUris(): boolean { - return this.uris != null && this.uris.length > 0; + get launchUri(): string { + if (this.hasUris) { + const uri = this.uris.find((u) => u.canLaunch); + if (uri != null) { + return uri.launchUri; + } } + return null; + } + + get hasUris(): boolean { + return this.uris != null && this.uris.length > 0; + } } diff --git a/common/src/models/view/passwordHistoryView.ts b/common/src/models/view/passwordHistoryView.ts index 5a0ca0e6..637b9b4f 100644 --- a/common/src/models/view/passwordHistoryView.ts +++ b/common/src/models/view/passwordHistoryView.ts @@ -1,16 +1,16 @@ -import { View } from './view'; +import { View } from "./view"; -import { Password } from '../domain/password'; +import { Password } from "../domain/password"; export class PasswordHistoryView implements View { - password: string = null; - lastUsedDate: Date = null; + password: string = null; + lastUsedDate: Date = null; - constructor(ph?: Password) { - if (!ph) { - return; - } - - this.lastUsedDate = ph.lastUsedDate; + constructor(ph?: Password) { + if (!ph) { + return; } + + this.lastUsedDate = ph.lastUsedDate; + } } diff --git a/common/src/models/view/secureNoteView.ts b/common/src/models/view/secureNoteView.ts index 2d209025..c660ac9f 100644 --- a/common/src/models/view/secureNoteView.ts +++ b/common/src/models/view/secureNoteView.ts @@ -1,22 +1,22 @@ -import { SecureNoteType } from '../../enums/secureNoteType'; +import { SecureNoteType } from "../../enums/secureNoteType"; -import { ItemView } from './itemView'; +import { ItemView } from "./itemView"; -import { SecureNote } from '../domain/secureNote'; +import { SecureNote } from "../domain/secureNote"; export class SecureNoteView extends ItemView { - type: SecureNoteType = null; + type: SecureNoteType = null; - constructor(n?: SecureNote) { - super(); - if (!n) { - return; - } - - this.type = n.type; + constructor(n?: SecureNote) { + super(); + if (!n) { + return; } - get subTitle(): string { - return null; - } + this.type = n.type; + } + + get subTitle(): string { + return null; + } } diff --git a/common/src/models/view/sendAccessView.ts b/common/src/models/view/sendAccessView.ts index 2aec827e..1b848169 100644 --- a/common/src/models/view/sendAccessView.ts +++ b/common/src/models/view/sendAccessView.ts @@ -1,28 +1,28 @@ -import { SendType } from '../../enums/sendType'; +import { SendType } from "../../enums/sendType"; -import { SendAccess } from '../domain/sendAccess'; +import { SendAccess } from "../domain/sendAccess"; -import { SendFileView } from './sendFileView'; -import { SendTextView } from './sendTextView'; -import { View } from './view'; +import { SendFileView } from "./sendFileView"; +import { SendTextView } from "./sendTextView"; +import { View } from "./view"; export class SendAccessView implements View { - id: string = null; - name: string = null; - type: SendType = null; - text = new SendTextView(); - file = new SendFileView(); - expirationDate: Date = null; - creatorIdentifier: string = null; + id: string = null; + name: string = null; + type: SendType = null; + text = new SendTextView(); + file = new SendFileView(); + expirationDate: Date = null; + creatorIdentifier: string = null; - constructor(s?: SendAccess) { - if (!s) { - return; - } - - this.id = s.id; - this.type = s.type; - this.expirationDate = s.expirationDate; - this.creatorIdentifier = s.creatorIdentifier; + constructor(s?: SendAccess) { + if (!s) { + return; } + + this.id = s.id; + this.type = s.type; + this.expirationDate = s.expirationDate; + this.creatorIdentifier = s.creatorIdentifier; + } } diff --git a/common/src/models/view/sendFileView.ts b/common/src/models/view/sendFileView.ts index a58df8f3..deff8700 100644 --- a/common/src/models/view/sendFileView.ts +++ b/common/src/models/view/sendFileView.ts @@ -1,31 +1,31 @@ -import { View } from './view'; +import { View } from "./view"; -import { SendFile } from '../domain/sendFile'; +import { SendFile } from "../domain/sendFile"; export class SendFileView implements View { - id: string = null; - size: string = null; - sizeName: string = null; - fileName: string = null; + id: string = null; + size: string = null; + sizeName: string = null; + fileName: string = null; - constructor(f?: SendFile) { - if (!f) { - return; - } - - this.id = f.id; - this.size = f.size; - this.sizeName = f.sizeName; + constructor(f?: SendFile) { + if (!f) { + return; } - get fileSize(): number { - try { - if (this.size != null) { - return parseInt(this.size, null); - } - } catch { - // Invalid file size. - } - return 0; + this.id = f.id; + this.size = f.size; + this.sizeName = f.sizeName; + } + + get fileSize(): number { + try { + if (this.size != null) { + return parseInt(this.size, null); + } + } catch { + // Invalid file size. } + return 0; + } } diff --git a/common/src/models/view/sendTextView.ts b/common/src/models/view/sendTextView.ts index b6ec45ee..5c1f018e 100644 --- a/common/src/models/view/sendTextView.ts +++ b/common/src/models/view/sendTextView.ts @@ -1,20 +1,20 @@ -import { View } from './view'; +import { View } from "./view"; -import { SendText } from '../domain/sendText'; +import { SendText } from "../domain/sendText"; export class SendTextView implements View { - text: string = null; - hidden: boolean; + text: string = null; + hidden: boolean; - constructor(t?: SendText) { - if (!t) { - return; - } - - this.hidden = t.hidden; + constructor(t?: SendText) { + if (!t) { + return; } - get maskedText(): string { - return this.text != null ? '••••••••' : null; - } + this.hidden = t.hidden; + } + + get maskedText(): string { + return this.text != null ? "••••••••" : null; + } } diff --git a/common/src/models/view/sendView.ts b/common/src/models/view/sendView.ts index 1730bce6..48aa887e 100644 --- a/common/src/models/view/sendView.ts +++ b/common/src/models/view/sendView.ts @@ -1,69 +1,69 @@ -import { SendType } from '../../enums/sendType'; -import { Utils } from '../../misc/utils'; +import { SendType } from "../../enums/sendType"; +import { Utils } from "../../misc/utils"; -import { Send } from '../domain/send'; -import { SymmetricCryptoKey } from '../domain/symmetricCryptoKey'; +import { Send } from "../domain/send"; +import { SymmetricCryptoKey } from "../domain/symmetricCryptoKey"; -import { SendFileView } from './sendFileView'; -import { SendTextView } from './sendTextView'; -import { View } from './view'; +import { SendFileView } from "./sendFileView"; +import { SendTextView } from "./sendTextView"; +import { View } from "./view"; export class SendView implements View { - id: string = null; - accessId: string = null; - name: string = null; - notes: string = null; - key: ArrayBuffer; - cryptoKey: SymmetricCryptoKey; - type: SendType = null; - text = new SendTextView(); - file = new SendFileView(); - maxAccessCount?: number = null; - accessCount: number = 0; - revisionDate: Date = null; - deletionDate: Date = null; - expirationDate: Date = null; - password: string = null; - disabled: boolean = false; - hideEmail: boolean = false; + id: string = null; + accessId: string = null; + name: string = null; + notes: string = null; + key: ArrayBuffer; + cryptoKey: SymmetricCryptoKey; + type: SendType = null; + text = new SendTextView(); + file = new SendFileView(); + maxAccessCount?: number = null; + accessCount: number = 0; + revisionDate: Date = null; + deletionDate: Date = null; + expirationDate: Date = null; + password: string = null; + disabled: boolean = false; + hideEmail: boolean = false; - constructor(s?: Send) { - if (!s) { - return; - } - - this.id = s.id; - this.accessId = s.accessId; - this.type = s.type; - this.maxAccessCount = s.maxAccessCount; - this.accessCount = s.accessCount; - this.revisionDate = s.revisionDate; - this.deletionDate = s.deletionDate; - this.expirationDate = s.expirationDate; - this.disabled = s.disabled; - this.password = s.password; - this.hideEmail = s.hideEmail; + constructor(s?: Send) { + if (!s) { + return; } - get urlB64Key(): string { - return Utils.fromBufferToUrlB64(this.key); - } + this.id = s.id; + this.accessId = s.accessId; + this.type = s.type; + this.maxAccessCount = s.maxAccessCount; + this.accessCount = s.accessCount; + this.revisionDate = s.revisionDate; + this.deletionDate = s.deletionDate; + this.expirationDate = s.expirationDate; + this.disabled = s.disabled; + this.password = s.password; + this.hideEmail = s.hideEmail; + } - get maxAccessCountReached(): boolean { - if (this.maxAccessCount == null) { - return false; - } - return this.accessCount >= this.maxAccessCount; - } + get urlB64Key(): string { + return Utils.fromBufferToUrlB64(this.key); + } - get expired(): boolean { - if (this.expirationDate == null) { - return false; - } - return this.expirationDate <= new Date(); + get maxAccessCountReached(): boolean { + if (this.maxAccessCount == null) { + return false; } + return this.accessCount >= this.maxAccessCount; + } - get pendingDelete(): boolean { - return this.deletionDate <= new Date(); + get expired(): boolean { + if (this.expirationDate == null) { + return false; } + return this.expirationDate <= new Date(); + } + + get pendingDelete(): boolean { + return this.deletionDate <= new Date(); + } } diff --git a/common/src/models/view/view.ts b/common/src/models/view/view.ts index c295888e..1f16b3d5 100644 --- a/common/src/models/view/view.ts +++ b/common/src/models/view/view.ts @@ -1,2 +1 @@ -export class View { -} +export class View {} diff --git a/common/src/services/appId.service.ts b/common/src/services/appId.service.ts index c37668d1..8ffd20f9 100644 --- a/common/src/services/appId.service.ts +++ b/common/src/services/appId.service.ts @@ -1,28 +1,27 @@ -import { Utils } from '../misc/utils'; +import { Utils } from "../misc/utils"; -import { AppIdService as AppIdServiceAbstraction } from '../abstractions/appId.service'; -import { StorageService } from '../abstractions/storage.service'; +import { AppIdService as AppIdServiceAbstraction } from "../abstractions/appId.service"; +import { StorageService } from "../abstractions/storage.service"; export class AppIdService implements AppIdServiceAbstraction { - constructor(private storageService: StorageService) { + constructor(private storageService: StorageService) {} + + getAppId(): Promise { + return this.makeAndGetAppId("appId"); + } + + getAnonymousAppId(): Promise { + return this.makeAndGetAppId("anonymousAppId"); + } + + private async makeAndGetAppId(key: string) { + const existingId = await this.storageService.get(key); + if (existingId != null) { + return existingId; } - getAppId(): Promise { - return this.makeAndGetAppId('appId'); - } - - getAnonymousAppId(): Promise { - return this.makeAndGetAppId('anonymousAppId'); - } - - private async makeAndGetAppId(key: string) { - const existingId = await this.storageService.get(key); - if (existingId != null) { - return existingId; - } - - const guid = Utils.newGuid(); - await this.storageService.save(key, guid); - return guid; - } + const guid = Utils.newGuid(); + await this.storageService.save(key, guid); + return guid; + } } diff --git a/common/src/services/audit.service.ts b/common/src/services/audit.service.ts index db9a0457..2136b442 100644 --- a/common/src/services/audit.service.ts +++ b/common/src/services/audit.service.ts @@ -1,43 +1,46 @@ -import { ApiService } from '../abstractions/api.service'; -import { AuditService as AuditServiceAbstraction } from '../abstractions/audit.service'; -import { CryptoFunctionService } from '../abstractions/cryptoFunction.service'; +import { ApiService } from "../abstractions/api.service"; +import { AuditService as AuditServiceAbstraction } from "../abstractions/audit.service"; +import { CryptoFunctionService } from "../abstractions/cryptoFunction.service"; -import { throttle } from '../misc/throttle'; -import { Utils } from '../misc/utils'; +import { throttle } from "../misc/throttle"; +import { Utils } from "../misc/utils"; -import { BreachAccountResponse } from '../models/response/breachAccountResponse'; -import { ErrorResponse } from '../models/response/errorResponse'; +import { BreachAccountResponse } from "../models/response/breachAccountResponse"; +import { ErrorResponse } from "../models/response/errorResponse"; -const PwnedPasswordsApi = 'https://api.pwnedpasswords.com/range/'; +const PwnedPasswordsApi = "https://api.pwnedpasswords.com/range/"; export class AuditService implements AuditServiceAbstraction { - constructor(private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) { } + constructor( + private cryptoFunctionService: CryptoFunctionService, + private apiService: ApiService + ) {} - @throttle(100, () => 'passwordLeaked') - async passwordLeaked(password: string): Promise { - const hashBytes = await this.cryptoFunctionService.hash(password, 'sha1'); - const hash = Utils.fromBufferToHex(hashBytes).toUpperCase(); - const hashStart = hash.substr(0, 5); - const hashEnding = hash.substr(5); + @throttle(100, () => "passwordLeaked") + async passwordLeaked(password: string): Promise { + const hashBytes = await this.cryptoFunctionService.hash(password, "sha1"); + const hash = Utils.fromBufferToHex(hashBytes).toUpperCase(); + const hashStart = hash.substr(0, 5); + const hashEnding = hash.substr(5); - const response = await this.apiService.nativeFetch(new Request(PwnedPasswordsApi + hashStart)); - const leakedHashes = await response.text(); - const match = leakedHashes.split(/\r?\n/).find(v => { - return v.split(':')[0] === hashEnding; - }); + const response = await this.apiService.nativeFetch(new Request(PwnedPasswordsApi + hashStart)); + const leakedHashes = await response.text(); + const match = leakedHashes.split(/\r?\n/).find((v) => { + return v.split(":")[0] === hashEnding; + }); - return match != null ? parseInt(match.split(':')[1], 10) : 0; - } - - async breachedAccounts(username: string): Promise { - try { - return await this.apiService.getHibpBreach(username); - } catch (e) { - const error = e as ErrorResponse; - if (error.statusCode === 404) { - return []; - } - throw new Error(); - } + return match != null ? parseInt(match.split(":")[1], 10) : 0; + } + + async breachedAccounts(username: string): Promise { + try { + return await this.apiService.getHibpBreach(username); + } catch (e) { + const error = e as ErrorResponse; + if (error.statusCode === 404) { + return []; + } + throw new Error(); } + } } diff --git a/common/src/services/azureFileUpload.service.ts b/common/src/services/azureFileUpload.service.ts index 680e5ffc..300ee7b7 100644 --- a/common/src/services/azureFileUpload.service.ts +++ b/common/src/services/azureFileUpload.service.ts @@ -1,201 +1,215 @@ -import { LogService } from '../abstractions/log.service'; +import { LogService } from "../abstractions/log.service"; -import { Utils } from '../misc/utils'; +import { Utils } from "../misc/utils"; -import { EncArrayBuffer } from '../models/domain/encArrayBuffer'; +import { EncArrayBuffer } from "../models/domain/encArrayBuffer"; const MAX_SINGLE_BLOB_UPLOAD_SIZE = 256 * 1024 * 1024; // 256 MiB const MAX_BLOCKS_PER_BLOB = 50000; export class AzureFileUploadService { - constructor(private logService: LogService) { } + constructor(private logService: LogService) {} - async upload(url: string, data: EncArrayBuffer, renewalCallback: () => Promise) { - if (data.buffer.byteLength <= MAX_SINGLE_BLOB_UPLOAD_SIZE) { - return await this.azureUploadBlob(url, data); - } else { - return await this.azureUploadBlocks(url, data, renewalCallback); - } + async upload(url: string, data: EncArrayBuffer, renewalCallback: () => Promise) { + if (data.buffer.byteLength <= MAX_SINGLE_BLOB_UPLOAD_SIZE) { + return await this.azureUploadBlob(url, data); + } else { + return await this.azureUploadBlocks(url, data, renewalCallback); } - private async azureUploadBlob(url: string, data: EncArrayBuffer) { - const urlObject = Utils.getUrl(url); - const headers = new Headers({ - 'x-ms-date': new Date().toUTCString(), - 'x-ms-version': urlObject.searchParams.get('sv'), - 'Content-Length': data.buffer.byteLength.toString(), - 'x-ms-blob-type': 'BlockBlob', + } + private async azureUploadBlob(url: string, data: EncArrayBuffer) { + const urlObject = Utils.getUrl(url); + const headers = new Headers({ + "x-ms-date": new Date().toUTCString(), + "x-ms-version": urlObject.searchParams.get("sv"), + "Content-Length": data.buffer.byteLength.toString(), + "x-ms-blob-type": "BlockBlob", + }); + + const request = new Request(url, { + body: data.buffer, + cache: "no-store", + method: "PUT", + headers: headers, + }); + + const blobResponse = await fetch(request); + + if (blobResponse.status !== 201) { + throw new Error(`Failed to create Azure blob: ${blobResponse.status}`); + } + } + private async azureUploadBlocks( + url: string, + data: EncArrayBuffer, + renewalCallback: () => Promise + ) { + const baseUrl = Utils.getUrl(url); + const blockSize = this.getMaxBlockSize(baseUrl.searchParams.get("sv")); + let blockIndex = 0; + const numBlocks = Math.ceil(data.buffer.byteLength / blockSize); + const blocksStaged: string[] = []; + + if (numBlocks > MAX_BLOCKS_PER_BLOB) { + throw new Error( + `Cannot upload file, exceeds maximum size of ${blockSize * MAX_BLOCKS_PER_BLOB}` + ); + } + + try { + while (blockIndex < numBlocks) { + url = await this.renewUrlIfNecessary(url, renewalCallback); + const blockUrl = Utils.getUrl(url); + const blockId = this.encodedBlockId(blockIndex); + blockUrl.searchParams.append("comp", "block"); + blockUrl.searchParams.append("blockid", blockId); + const start = blockIndex * blockSize; + const blockData = data.buffer.slice(start, start + blockSize); + const blockHeaders = new Headers({ + "x-ms-date": new Date().toUTCString(), + "x-ms-version": blockUrl.searchParams.get("sv"), + "Content-Length": blockData.byteLength.toString(), }); - const request = new Request(url, { - body: data.buffer, - cache: 'no-store', - method: 'PUT', - headers: headers, + const blockRequest = new Request(blockUrl.toString(), { + body: blockData, + cache: "no-store", + method: "PUT", + headers: blockHeaders, }); - const blobResponse = await fetch(request); + const blockResponse = await fetch(blockRequest); - if (blobResponse.status !== 201) { - throw new Error(`Failed to create Azure blob: ${blobResponse.status}`); - } - } - private async azureUploadBlocks(url: string, data: EncArrayBuffer, renewalCallback: () => Promise) { - const baseUrl = Utils.getUrl(url); - const blockSize = this.getMaxBlockSize(baseUrl.searchParams.get('sv')); - let blockIndex = 0; - const numBlocks = Math.ceil(data.buffer.byteLength / blockSize); - const blocksStaged: string[] = []; - - if (numBlocks > MAX_BLOCKS_PER_BLOB) { - throw new Error(`Cannot upload file, exceeds maximum size of ${blockSize * MAX_BLOCKS_PER_BLOB}`); + if (blockResponse.status !== 201) { + const message = `Unsuccessful block PUT. Received status ${blockResponse.status}`; + this.logService.error(message + "\n" + (await blockResponse.json())); + throw new Error(message); } - try { - while (blockIndex < numBlocks) { - url = await this.renewUrlIfNecessary(url, renewalCallback); - const blockUrl = Utils.getUrl(url); - const blockId = this.encodedBlockId(blockIndex); - blockUrl.searchParams.append('comp', 'block'); - blockUrl.searchParams.append('blockid', blockId); - const start = blockIndex * blockSize; - const blockData = data.buffer.slice(start, start + blockSize); - const blockHeaders = new Headers({ - 'x-ms-date': new Date().toUTCString(), - 'x-ms-version': blockUrl.searchParams.get('sv'), - 'Content-Length': blockData.byteLength.toString(), - }); + blocksStaged.push(blockId); + blockIndex++; + } - const blockRequest = new Request(blockUrl.toString(), { - body: blockData, - cache: 'no-store', - method: 'PUT', - headers: blockHeaders, - }); + url = await this.renewUrlIfNecessary(url, renewalCallback); + const blockListUrl = Utils.getUrl(url); + const blockListXml = this.blockListXml(blocksStaged); + blockListUrl.searchParams.append("comp", "blocklist"); + const headers = new Headers({ + "x-ms-date": new Date().toUTCString(), + "x-ms-version": blockListUrl.searchParams.get("sv"), + "Content-Length": blockListXml.length.toString(), + }); - const blockResponse = await fetch(blockRequest); + const request = new Request(blockListUrl.toString(), { + body: blockListXml, + cache: "no-store", + method: "PUT", + headers: headers, + }); - if (blockResponse.status !== 201) { - const message = `Unsuccessful block PUT. Received status ${blockResponse.status}`; - this.logService.error(message + '\n' + await blockResponse.json()); - throw new Error(message); - } + const response = await fetch(request); - blocksStaged.push(blockId); - blockIndex++; - } + if (response.status !== 201) { + const message = `Unsuccessful block list PUT. Received status ${response.status}`; + this.logService.error(message + "\n" + (await response.json())); + throw new Error(message); + } + } catch (e) { + throw e; + } + } - url = await this.renewUrlIfNecessary(url, renewalCallback); - const blockListUrl = Utils.getUrl(url); - const blockListXml = this.blockListXml(blocksStaged); - blockListUrl.searchParams.append('comp', 'blocklist'); - const headers = new Headers({ - 'x-ms-date': new Date().toUTCString(), - 'x-ms-version': blockListUrl.searchParams.get('sv'), - 'Content-Length': blockListXml.length.toString(), - }); + private async renewUrlIfNecessary( + url: string, + renewalCallback: () => Promise + ): Promise { + const urlObject = Utils.getUrl(url); + const expiry = new Date(urlObject.searchParams.get("se") ?? ""); - const request = new Request(blockListUrl.toString(), { - body: blockListXml, - cache: 'no-store', - method: 'PUT', - headers: headers, - }); - - const response = await fetch(request); - - if (response.status !== 201) { - const message = `Unsuccessful block list PUT. Received status ${response.status}`; - this.logService.error(message + '\n' + await response.json()); - throw new Error(message); - } - } catch (e) { - throw e; - } + if (isNaN(expiry.getTime())) { + expiry.setTime(Date.now() + 3600000); } - private async renewUrlIfNecessary(url: string, renewalCallback: () => Promise): Promise { - const urlObject = Utils.getUrl(url); - const expiry = new Date(urlObject.searchParams.get('se') ?? ''); - - if (isNaN(expiry.getTime())) { - expiry.setTime(Date.now() + 3600000); - } - - if (expiry.getTime() < Date.now() + 1000) { - return await renewalCallback(); - } - return url; + if (expiry.getTime() < Date.now() + 1000) { + return await renewalCallback(); } + return url; + } - private encodedBlockId(blockIndex: number) { - // Encoded blockId max size is 64, so pre-encoding max size is 48 - const utfBlockId = ('000000000000000000000000000000000000000000000000' + blockIndex.toString()).slice(-48); - return Utils.fromUtf8ToB64(utfBlockId); - } + private encodedBlockId(blockIndex: number) { + // Encoded blockId max size is 64, so pre-encoding max size is 48 + const utfBlockId = ( + "000000000000000000000000000000000000000000000000" + blockIndex.toString() + ).slice(-48); + return Utils.fromUtf8ToB64(utfBlockId); + } - private blockListXml(blockIdList: string[]) { - let xml = ''; - blockIdList.forEach(blockId => { - xml += `${blockId}`; - }); - xml += ''; - return xml; - } + private blockListXml(blockIdList: string[]) { + let xml = ''; + blockIdList.forEach((blockId) => { + xml += `${blockId}`; + }); + xml += ""; + return xml; + } - private getMaxBlockSize(version: string) { - if (Version.compare(version, '2019-12-12') >= 0) { - return 4000 * 1024 * 1024; // 4000 MiB - } else if (Version.compare(version, '2016-05-31') >= 0) { - return 100 * 1024 * 1024; // 100 MiB - } else { - return 4 * 1024 * 1024; // 4 MiB - } + private getMaxBlockSize(version: string) { + if (Version.compare(version, "2019-12-12") >= 0) { + return 4000 * 1024 * 1024; // 4000 MiB + } else if (Version.compare(version, "2016-05-31") >= 0) { + return 100 * 1024 * 1024; // 100 MiB + } else { + return 4 * 1024 * 1024; // 4 MiB } + } } class Version { - /** - * Compares two Azure Versions against each other - * @param a Version to compare - * @param b Version to compare - * @returns a number less than zero if b is newer than a, 0 if equal, - * and greater than zero if a is newer than b - */ - static compare(a: Required | string, b: Required | string) { - if (typeof (a) === 'string') { - a = new Version(a); - } - - if (typeof (b) === 'string') { - b = new Version(b); - } - - return a.year !== b.year ? a.year - b.year : - a.month !== b.month ? a.month - b.month : - a.day !== b.day ? a.day - b.day : - 0; + /** + * Compares two Azure Versions against each other + * @param a Version to compare + * @param b Version to compare + * @returns a number less than zero if b is newer than a, 0 if equal, + * and greater than zero if a is newer than b + */ + static compare(a: Required | string, b: Required | string) { + if (typeof a === "string") { + a = new Version(a); } - year = 0; - month = 0; - day = 0; - constructor(version: string) { - try { - const parts = version.split('-').map(v => Number.parseInt(v, 10)); - this.year = parts[0]; - this.month = parts[1]; - this.day = parts[2]; - } catch { - // Ignore error - } + if (typeof b === "string") { + b = new Version(b); } - /** - * Compares two Azure Versions against each other - * @param compareTo Version to compare against - * @returns a number less than zero if compareTo is newer, 0 if equal, - * and greater than zero if this is greater than compareTo - */ - compare(compareTo: Required | string) { - return Version.compare(this, compareTo); + + return a.year !== b.year + ? a.year - b.year + : a.month !== b.month + ? a.month - b.month + : a.day !== b.day + ? a.day - b.day + : 0; + } + year = 0; + month = 0; + day = 0; + + constructor(version: string) { + try { + const parts = version.split("-").map((v) => Number.parseInt(v, 10)); + this.year = parts[0]; + this.month = parts[1]; + this.day = parts[2]; + } catch { + // Ignore error } + } + /** + * Compares two Azure Versions against each other + * @param compareTo Version to compare against + * @returns a number less than zero if compareTo is newer, 0 if equal, + * and greater than zero if this is greater than compareTo + */ + compare(compareTo: Required | string) { + return Version.compare(this, compareTo); + } } diff --git a/common/src/services/bitwardenFileUpload.service.ts b/common/src/services/bitwardenFileUpload.service.ts index 9c699a48..3f54f73e 100644 --- a/common/src/services/bitwardenFileUpload.service.ts +++ b/common/src/services/bitwardenFileUpload.service.ts @@ -1,29 +1,36 @@ -import { ApiService } from '../abstractions/api.service'; +import { ApiService } from "../abstractions/api.service"; -import { EncArrayBuffer } from '../models/domain/encArrayBuffer'; +import { EncArrayBuffer } from "../models/domain/encArrayBuffer"; -import { Utils } from '../misc/utils'; +import { Utils } from "../misc/utils"; -export class BitwardenFileUploadService -{ - constructor(private apiService: ApiService) { } +export class BitwardenFileUploadService { + constructor(private apiService: ApiService) {} - async upload(encryptedFileName: string, encryptedFileData: EncArrayBuffer, apiCall: (fd: FormData) => Promise) { - const fd = new FormData(); - try { - const blob = new Blob([encryptedFileData.buffer], { type: 'application/octet-stream' }); - fd.append('data', blob, encryptedFileName); - } catch (e) { - if (Utils.isNode && !Utils.isBrowser) { - fd.append('data', Buffer.from(encryptedFileData.buffer) as any, { - filepath: encryptedFileName, - contentType: 'application/octet-stream', - } as any); - } else { - throw e; - } - } - - await apiCall(fd); + async upload( + encryptedFileName: string, + encryptedFileData: EncArrayBuffer, + apiCall: (fd: FormData) => Promise + ) { + const fd = new FormData(); + try { + const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" }); + fd.append("data", blob, encryptedFileName); + } catch (e) { + if (Utils.isNode && !Utils.isBrowser) { + fd.append( + "data", + Buffer.from(encryptedFileData.buffer) as any, + { + filepath: encryptedFileName, + contentType: "application/octet-stream", + } as any + ); + } else { + throw e; + } } + + await apiCall(fd); + } } diff --git a/common/src/services/broadcaster.service.ts b/common/src/services/broadcaster.service.ts index 6dfbfa64..999fbe4b 100644 --- a/common/src/services/broadcaster.service.ts +++ b/common/src/services/broadcaster.service.ts @@ -1,28 +1,28 @@ -import { BroadcasterService as BroadcasterServiceAbstraction } from '../abstractions/broadcaster.service'; +import { BroadcasterService as BroadcasterServiceAbstraction } from "../abstractions/broadcaster.service"; export class BroadcasterService implements BroadcasterServiceAbstraction { - subscribers: Map any> = new Map any>(); + subscribers: Map any> = new Map any>(); - send(message: any, id?: string) { - if (id != null) { - if (this.subscribers.has(id)) { - this.subscribers.get(id)(message); - } - return; - } - - this.subscribers.forEach(value => { - value(message); - }); + send(message: any, id?: string) { + if (id != null) { + if (this.subscribers.has(id)) { + this.subscribers.get(id)(message); + } + return; } - subscribe(id: string, messageCallback: (message: any) => any) { - this.subscribers.set(id, messageCallback); - } + this.subscribers.forEach((value) => { + value(message); + }); + } - unsubscribe(id: string) { - if (this.subscribers.has(id)) { - this.subscribers.delete(id); - } + subscribe(id: string, messageCallback: (message: any) => any) { + this.subscribers.set(id, messageCallback); + } + + unsubscribe(id: string) { + if (this.subscribers.has(id)) { + this.subscribers.delete(id); } + } } diff --git a/common/src/services/consoleLog.service.ts b/common/src/services/consoleLog.service.ts index 64d81266..1ecd2499 100644 --- a/common/src/services/consoleLog.service.ts +++ b/common/src/services/consoleLog.service.ts @@ -1,70 +1,73 @@ -import { LogLevelType } from '../enums/logLevelType'; +import { LogLevelType } from "../enums/logLevelType"; -import { LogService as LogServiceAbstraction } from '../abstractions/log.service'; +import { LogService as LogServiceAbstraction } from "../abstractions/log.service"; -import * as hrtime from 'browser-hrtime'; +import * as hrtime from "browser-hrtime"; export class ConsoleLogService implements LogServiceAbstraction { - protected timersMap: Map = new Map(); + protected timersMap: Map = new Map(); - constructor(protected isDev: boolean, protected filter: (level: LogLevelType) => boolean = null) { } + constructor( + protected isDev: boolean, + protected filter: (level: LogLevelType) => boolean = null + ) {} - debug(message: string) { - if (!this.isDev) { - return; - } - this.write(LogLevelType.Debug, message); + debug(message: string) { + if (!this.isDev) { + return; + } + this.write(LogLevelType.Debug, message); + } + + info(message: string) { + this.write(LogLevelType.Info, message); + } + + warning(message: string) { + this.write(LogLevelType.Warning, message); + } + + error(message: string) { + this.write(LogLevelType.Error, message); + } + + write(level: LogLevelType, message: string) { + if (this.filter != null && this.filter(level)) { + return; } - info(message: string) { - this.write(LogLevelType.Info, message); + switch (level) { + case LogLevelType.Debug: + // tslint:disable-next-line + console.log(message); + break; + case LogLevelType.Info: + // tslint:disable-next-line + console.log(message); + break; + case LogLevelType.Warning: + // tslint:disable-next-line + console.warn(message); + break; + case LogLevelType.Error: + // tslint:disable-next-line + console.error(message); + break; + default: + break; } + } - warning(message: string) { - this.write(LogLevelType.Warning, message); + time(label: string = "default") { + if (!this.timersMap.has(label)) { + this.timersMap.set(label, hrtime()); } + } - error(message: string) { - this.write(LogLevelType.Error, message); - } - - write(level: LogLevelType, message: string) { - if (this.filter != null && this.filter(level)) { - return; - } - - switch (level) { - case LogLevelType.Debug: - // tslint:disable-next-line - console.log(message); - break; - case LogLevelType.Info: - // tslint:disable-next-line - console.log(message); - break; - case LogLevelType.Warning: - // tslint:disable-next-line - console.warn(message); - break; - case LogLevelType.Error: - // tslint:disable-next-line - console.error(message); - break; - default: - break; - } - } - - time(label: string = 'default') { - if (!this.timersMap.has(label)) { - this.timersMap.set(label, hrtime()); - } - } - - timeEnd(label: string = 'default'): [number, number] { - const elapsed = hrtime(this.timersMap.get(label)); - this.timersMap.delete(label); - this.write(LogLevelType.Info, `${label}: ${elapsed[0] * 1000 + elapsed[1] / 10e6}ms`); - return elapsed; - } + timeEnd(label: string = "default"): [number, number] { + const elapsed = hrtime(this.timersMap.get(label)); + this.timersMap.delete(label); + this.write(LogLevelType.Info, `${label}: ${elapsed[0] * 1000 + elapsed[1] / 10e6}ms`); + return elapsed; + } } diff --git a/common/src/services/container.service.ts b/common/src/services/container.service.ts index 08f428ad..2880e7c7 100644 --- a/common/src/services/container.service.ts +++ b/common/src/services/container.service.ts @@ -1,21 +1,20 @@ -import { CryptoService } from '../abstractions/crypto.service'; +import { CryptoService } from "../abstractions/crypto.service"; export class ContainerService { - constructor(private cryptoService: CryptoService) { - } + constructor(private cryptoService: CryptoService) {} - // deprecated, use attachToGlobal instead - attachToWindow(win: any) { - this.attachToGlobal(win); - } + // deprecated, use attachToGlobal instead + attachToWindow(win: any) { + this.attachToGlobal(win); + } - attachToGlobal(global: any) { - if (!global.bitwardenContainerService) { - global.bitwardenContainerService = this; - } + attachToGlobal(global: any) { + if (!global.bitwardenContainerService) { + global.bitwardenContainerService = this; } + } - getCryptoService(): CryptoService { - return this.cryptoService; - } + getCryptoService(): CryptoService { + return this.cryptoService; + } } diff --git a/common/src/services/export.service.ts b/common/src/services/export.service.ts index 7afb6988..31b1b0b6 100644 --- a/common/src/services/export.service.ts +++ b/common/src/services/export.service.ts @@ -1,369 +1,410 @@ -import * as papa from 'papaparse'; +import * as papa from "papaparse"; -import { CipherType } from '../enums/cipherType'; +import { CipherType } from "../enums/cipherType"; -import { ApiService } from '../abstractions/api.service'; -import { CipherService } from '../abstractions/cipher.service'; -import { CryptoService } from '../abstractions/crypto.service'; -import { ExportService as ExportServiceAbstraction } from '../abstractions/export.service'; -import { FolderService } from '../abstractions/folder.service'; +import { ApiService } from "../abstractions/api.service"; +import { CipherService } from "../abstractions/cipher.service"; +import { CryptoService } from "../abstractions/crypto.service"; +import { ExportService as ExportServiceAbstraction } from "../abstractions/export.service"; +import { FolderService } from "../abstractions/folder.service"; -import { CipherView } from '../models/view/cipherView'; -import { CollectionView } from '../models/view/collectionView'; -import { FolderView } from '../models/view/folderView'; +import { CipherView } from "../models/view/cipherView"; +import { CollectionView } from "../models/view/collectionView"; +import { FolderView } from "../models/view/folderView"; -import { Cipher } from '../models/domain/cipher'; -import { Collection } from '../models/domain/collection'; -import { Folder } from '../models/domain/folder'; +import { Cipher } from "../models/domain/cipher"; +import { Collection } from "../models/domain/collection"; +import { Folder } from "../models/domain/folder"; -import { CipherData } from '../models/data/cipherData'; -import { CollectionData } from '../models/data/collectionData'; -import { CollectionDetailsResponse } from '../models/response/collectionResponse'; +import { CipherData } from "../models/data/cipherData"; +import { CollectionData } from "../models/data/collectionData"; +import { CollectionDetailsResponse } from "../models/response/collectionResponse"; -import { CipherWithIds as CipherExport } from '../models/export/cipherWithIds'; -import { CollectionWithId as CollectionExport } from '../models/export/collectionWithId'; -import { Event } from '../models/export/event'; -import { FolderWithId as FolderExport } from '../models/export/folderWithId'; -import { EventView } from '../models/view/eventView'; +import { CipherWithIds as CipherExport } from "../models/export/cipherWithIds"; +import { CollectionWithId as CollectionExport } from "../models/export/collectionWithId"; +import { Event } from "../models/export/event"; +import { FolderWithId as FolderExport } from "../models/export/folderWithId"; +import { EventView } from "../models/view/eventView"; -import { Utils } from '../misc/utils'; +import { Utils } from "../misc/utils"; export class ExportService implements ExportServiceAbstraction { - constructor(private folderService: FolderService, private cipherService: CipherService, - private apiService: ApiService, private cryptoService: CryptoService) { } + constructor( + private folderService: FolderService, + private cipherService: CipherService, + private apiService: ApiService, + private cryptoService: CryptoService + ) {} - async getExport(format: 'csv' | 'json' | 'encrypted_json' = 'csv'): Promise { - if (format === 'encrypted_json') { - return this.getEncryptedExport(); + async getExport(format: "csv" | "json" | "encrypted_json" = "csv"): Promise { + if (format === "encrypted_json") { + return this.getEncryptedExport(); + } else { + return this.getDecryptedExport(format); + } + } + + async getOrganizationExport( + organizationId: string, + format: "csv" | "json" | "encrypted_json" = "csv" + ): Promise { + if (format === "encrypted_json") { + return this.getOrganizationEncryptedExport(organizationId); + } else { + return this.getOrganizationDecryptedExport(organizationId, format); + } + } + + async getEventExport(events: EventView[]): Promise { + return papa.unparse(events.map((e) => new Event(e))); + } + + getFileName(prefix: string = null, extension: string = "csv"): string { + const now = new Date(); + const dateString = + now.getFullYear() + + "" + + this.padNumber(now.getMonth() + 1, 2) + + "" + + this.padNumber(now.getDate(), 2) + + this.padNumber(now.getHours(), 2) + + "" + + this.padNumber(now.getMinutes(), 2) + + this.padNumber(now.getSeconds(), 2); + + return "bitwarden" + (prefix ? "_" + prefix : "") + "_export_" + dateString + "." + extension; + } + + private async getDecryptedExport(format: "json" | "csv"): Promise { + let decFolders: FolderView[] = []; + let decCiphers: CipherView[] = []; + const promises = []; + + promises.push( + this.folderService.getAllDecrypted().then((folders) => { + decFolders = folders; + }) + ); + + promises.push( + this.cipherService.getAllDecrypted().then((ciphers) => { + decCiphers = ciphers.filter((f) => f.deletedDate == null); + }) + ); + + await Promise.all(promises); + + if (format === "csv") { + const foldersMap = new Map(); + decFolders.forEach((f) => { + if (f.id != null) { + foldersMap.set(f.id, f); + } + }); + + const exportCiphers: any[] = []; + decCiphers.forEach((c) => { + // only export logins and secure notes + if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) { + return; + } + if (c.organizationId != null) { + return; + } + + const cipher: any = {}; + cipher.folder = + c.folderId != null && foldersMap.has(c.folderId) ? foldersMap.get(c.folderId).name : null; + cipher.favorite = c.favorite ? 1 : null; + this.buildCommonCipher(cipher, c); + exportCiphers.push(cipher); + }); + + return papa.unparse(exportCiphers); + } else { + const jsonDoc: any = { + encrypted: false, + folders: [], + items: [], + }; + + decFolders.forEach((f) => { + if (f.id == null) { + return; + } + const folder = new FolderExport(); + folder.build(f); + jsonDoc.folders.push(folder); + }); + + decCiphers.forEach((c) => { + if (c.organizationId != null) { + return; + } + const cipher = new CipherExport(); + cipher.build(c); + cipher.collectionIds = null; + jsonDoc.items.push(cipher); + }); + + return JSON.stringify(jsonDoc, null, " "); + } + } + + private async getEncryptedExport(): Promise { + let folders: Folder[] = []; + let ciphers: Cipher[] = []; + const promises = []; + + promises.push( + this.folderService.getAll().then((f) => { + folders = f; + }) + ); + + promises.push( + this.cipherService.getAll().then((c) => { + ciphers = c.filter((f) => f.deletedDate == null); + }) + ); + + await Promise.all(promises); + + const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid()); + + const jsonDoc: any = { + encrypted: true, + encKeyValidation_DO_NOT_EDIT: encKeyValidation.encryptedString, + folders: [], + items: [], + }; + + folders.forEach((f) => { + if (f.id == null) { + return; + } + const folder = new FolderExport(); + folder.build(f); + jsonDoc.folders.push(folder); + }); + + ciphers.forEach((c) => { + if (c.organizationId != null) { + return; + } + const cipher = new CipherExport(); + cipher.build(c); + cipher.collectionIds = null; + jsonDoc.items.push(cipher); + }); + + return JSON.stringify(jsonDoc, null, " "); + } + + private async getOrganizationDecryptedExport( + organizationId: string, + format: "json" | "csv" + ): Promise { + const decCollections: CollectionView[] = []; + const decCiphers: CipherView[] = []; + const promises = []; + + promises.push( + this.apiService.getCollections(organizationId).then((collections) => { + const collectionPromises: any = []; + if (collections != null && collections.data != null && collections.data.length > 0) { + collections.data.forEach((c) => { + const collection = new Collection(new CollectionData(c as CollectionDetailsResponse)); + collectionPromises.push( + collection.decrypt().then((decCol) => { + decCollections.push(decCol); + }) + ); + }); + } + return Promise.all(collectionPromises); + }) + ); + + promises.push( + this.apiService.getCiphersOrganization(organizationId).then((ciphers) => { + const cipherPromises: any = []; + if (ciphers != null && ciphers.data != null && ciphers.data.length > 0) { + ciphers.data + .filter((c) => c.deletedDate === null) + .forEach((c) => { + const cipher = new Cipher(new CipherData(c)); + cipherPromises.push( + cipher.decrypt().then((decCipher) => { + decCiphers.push(decCipher); + }) + ); + }); + } + return Promise.all(cipherPromises); + }) + ); + + await Promise.all(promises); + + if (format === "csv") { + const collectionsMap = new Map(); + decCollections.forEach((c) => { + collectionsMap.set(c.id, c); + }); + + const exportCiphers: any[] = []; + decCiphers.forEach((c) => { + // only export logins and secure notes + if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) { + return; + } + + const cipher: any = {}; + cipher.collections = []; + if (c.collectionIds != null) { + cipher.collections = c.collectionIds + .filter((id) => collectionsMap.has(id)) + .map((id) => collectionsMap.get(id).name); + } + this.buildCommonCipher(cipher, c); + exportCiphers.push(cipher); + }); + + return papa.unparse(exportCiphers); + } else { + const jsonDoc: any = { + encrypted: false, + collections: [], + items: [], + }; + + decCollections.forEach((c) => { + const collection = new CollectionExport(); + collection.build(c); + jsonDoc.collections.push(collection); + }); + + decCiphers.forEach((c) => { + const cipher = new CipherExport(); + cipher.build(c); + jsonDoc.items.push(cipher); + }); + return JSON.stringify(jsonDoc, null, " "); + } + } + + private async getOrganizationEncryptedExport(organizationId: string): Promise { + const collections: Collection[] = []; + const ciphers: Cipher[] = []; + const promises = []; + + promises.push( + this.apiService.getCollections(organizationId).then((c) => { + const collectionPromises: any = []; + if (c != null && c.data != null && c.data.length > 0) { + c.data.forEach((r) => { + const collection = new Collection(new CollectionData(r as CollectionDetailsResponse)); + collections.push(collection); + }); + } + return Promise.all(collectionPromises); + }) + ); + + promises.push( + this.apiService.getCiphersOrganization(organizationId).then((c) => { + const cipherPromises: any = []; + if (c != null && c.data != null && c.data.length > 0) { + c.data + .filter((item) => item.deletedDate === null) + .forEach((item) => { + const cipher = new Cipher(new CipherData(item)); + ciphers.push(cipher); + }); + } + return Promise.all(cipherPromises); + }) + ); + + await Promise.all(promises); + + const orgKey = await this.cryptoService.getOrgKey(organizationId); + const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid(), orgKey); + + const jsonDoc: any = { + encrypted: true, + encKeyValidation_DO_NOT_EDIT: encKeyValidation.encryptedString, + collections: [], + items: [], + }; + + collections.forEach((c) => { + const collection = new CollectionExport(); + collection.build(c); + jsonDoc.collections.push(collection); + }); + + ciphers.forEach((c) => { + const cipher = new CipherExport(); + cipher.build(c); + jsonDoc.items.push(cipher); + }); + return JSON.stringify(jsonDoc, null, " "); + } + + private padNumber(num: number, width: number, padCharacter: string = "0"): string { + const numString = num.toString(); + return numString.length >= width + ? numString + : new Array(width - numString.length + 1).join(padCharacter) + numString; + } + + private buildCommonCipher(cipher: any, c: CipherView) { + cipher.type = null; + cipher.name = c.name; + cipher.notes = c.notes; + cipher.fields = null; + cipher.reprompt = c.reprompt; + // Login props + cipher.login_uri = null; + cipher.login_username = null; + cipher.login_password = null; + cipher.login_totp = null; + + if (c.fields) { + c.fields.forEach((f: any) => { + if (!cipher.fields) { + cipher.fields = ""; } else { - return this.getDecryptedExport(format); - } - } - - async getOrganizationExport(organizationId: string, - format: 'csv' | 'json' | 'encrypted_json' = 'csv'): Promise { - if (format === 'encrypted_json') { - return this.getOrganizationEncryptedExport(organizationId); - } else { - return this.getOrganizationDecryptedExport(organizationId, format); - } - } - - async getEventExport(events: EventView[]): Promise { - return papa.unparse(events.map(e => new Event(e))); - } - - getFileName(prefix: string = null, extension: string = 'csv'): string { - const now = new Date(); - const dateString = - now.getFullYear() + '' + this.padNumber(now.getMonth() + 1, 2) + '' + this.padNumber(now.getDate(), 2) + - this.padNumber(now.getHours(), 2) + '' + this.padNumber(now.getMinutes(), 2) + - this.padNumber(now.getSeconds(), 2); - - return 'bitwarden' + (prefix ? ('_' + prefix) : '') + '_export_' + dateString + '.' + extension; - } - - private async getDecryptedExport(format: 'json' | 'csv'): Promise { - let decFolders: FolderView[] = []; - let decCiphers: CipherView[] = []; - const promises = []; - - promises.push(this.folderService.getAllDecrypted().then(folders => { - decFolders = folders; - })); - - promises.push(this.cipherService.getAllDecrypted().then(ciphers => { - decCiphers = ciphers.filter(f => f.deletedDate == null); - })); - - await Promise.all(promises); - - if (format === 'csv') { - const foldersMap = new Map(); - decFolders.forEach(f => { - if (f.id != null) { - foldersMap.set(f.id, f); - } - }); - - const exportCiphers: any[] = []; - decCiphers.forEach(c => { - // only export logins and secure notes - if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) { - return; - } - if (c.organizationId != null) { - return; - } - - const cipher: any = {}; - cipher.folder = c.folderId != null && foldersMap.has(c.folderId) ? - foldersMap.get(c.folderId).name : null; - cipher.favorite = c.favorite ? 1 : null; - this.buildCommonCipher(cipher, c); - exportCiphers.push(cipher); - }); - - return papa.unparse(exportCiphers); - } else { - const jsonDoc: any = { - encrypted: false, - folders: [], - items: [], - }; - - decFolders.forEach(f => { - if (f.id == null) { - return; - } - const folder = new FolderExport(); - folder.build(f); - jsonDoc.folders.push(folder); - }); - - decCiphers.forEach(c => { - if (c.organizationId != null) { - return; - } - const cipher = new CipherExport(); - cipher.build(c); - cipher.collectionIds = null; - jsonDoc.items.push(cipher); - }); - - return JSON.stringify(jsonDoc, null, ' '); - } - } - - private async getEncryptedExport(): Promise { - let folders: Folder[] = []; - let ciphers: Cipher[] = []; - const promises = []; - - promises.push(this.folderService.getAll().then(f => { - folders = f; - })); - - promises.push(this.cipherService.getAll().then(c => { - ciphers = c.filter(f => f.deletedDate == null); - })); - - await Promise.all(promises); - - const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid()); - - const jsonDoc: any = { - encrypted: true, - encKeyValidation_DO_NOT_EDIT: encKeyValidation.encryptedString, - folders: [], - items: [], - }; - - folders.forEach(f => { - if (f.id == null) { - return; - } - const folder = new FolderExport(); - folder.build(f); - jsonDoc.folders.push(folder); - }); - - ciphers.forEach(c => { - if (c.organizationId != null) { - return; - } - const cipher = new CipherExport(); - cipher.build(c); - cipher.collectionIds = null; - jsonDoc.items.push(cipher); - }); - - return JSON.stringify(jsonDoc, null, ' '); - } - - private async getOrganizationDecryptedExport(organizationId: string, format: 'json' | 'csv'): Promise { - const decCollections: CollectionView[] = []; - const decCiphers: CipherView[] = []; - const promises = []; - - promises.push(this.apiService.getCollections(organizationId).then(collections => { - const collectionPromises: any = []; - if (collections != null && collections.data != null && collections.data.length > 0) { - collections.data.forEach(c => { - const collection = new Collection(new CollectionData(c as CollectionDetailsResponse)); - collectionPromises.push(collection.decrypt().then(decCol => { - decCollections.push(decCol); - })); - }); - } - return Promise.all(collectionPromises); - })); - - promises.push(this.apiService.getCiphersOrganization(organizationId).then(ciphers => { - const cipherPromises: any = []; - if (ciphers != null && ciphers.data != null && ciphers.data.length > 0) { - ciphers.data.filter(c => c.deletedDate === null).forEach(c => { - const cipher = new Cipher(new CipherData(c)); - cipherPromises.push(cipher.decrypt().then(decCipher => { - decCiphers.push(decCipher); - })); - }); - } - return Promise.all(cipherPromises); - })); - - await Promise.all(promises); - - if (format === 'csv') { - const collectionsMap = new Map(); - decCollections.forEach(c => { - collectionsMap.set(c.id, c); - }); - - const exportCiphers: any[] = []; - decCiphers.forEach(c => { - // only export logins and secure notes - if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) { - return; - } - - const cipher: any = {}; - cipher.collections = []; - if (c.collectionIds != null) { - cipher.collections = c.collectionIds.filter(id => collectionsMap.has(id)) - .map(id => collectionsMap.get(id).name); - } - this.buildCommonCipher(cipher, c); - exportCiphers.push(cipher); - }); - - return papa.unparse(exportCiphers); - } else { - const jsonDoc: any = { - encrypted: false, - collections: [], - items: [], - }; - - decCollections.forEach(c => { - const collection = new CollectionExport(); - collection.build(c); - jsonDoc.collections.push(collection); - }); - - decCiphers.forEach(c => { - const cipher = new CipherExport(); - cipher.build(c); - jsonDoc.items.push(cipher); - }); - return JSON.stringify(jsonDoc, null, ' '); - } - } - - private async getOrganizationEncryptedExport(organizationId: string): Promise { - const collections: Collection[] = []; - const ciphers: Cipher[] = []; - const promises = []; - - promises.push(this.apiService.getCollections(organizationId).then(c => { - const collectionPromises: any = []; - if (c != null && c.data != null && c.data.length > 0) { - c.data.forEach(r => { - const collection = new Collection(new CollectionData(r as CollectionDetailsResponse)); - collections.push(collection); - }); - } - return Promise.all(collectionPromises); - })); - - promises.push(this.apiService.getCiphersOrganization(organizationId).then(c => { - const cipherPromises: any = []; - if (c != null && c.data != null && c.data.length > 0) { - c.data.filter(item => item.deletedDate === null).forEach(item => { - const cipher = new Cipher(new CipherData(item)); - ciphers.push(cipher); - }); - } - return Promise.all(cipherPromises); - })); - - await Promise.all(promises); - - const orgKey = await this.cryptoService.getOrgKey(organizationId); - const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid(), orgKey); - - const jsonDoc: any = { - encrypted: true, - encKeyValidation_DO_NOT_EDIT: encKeyValidation.encryptedString, - collections: [], - items: [], - }; - - collections.forEach(c => { - const collection = new CollectionExport(); - collection.build(c); - jsonDoc.collections.push(collection); - }); - - ciphers.forEach(c => { - const cipher = new CipherExport(); - cipher.build(c); - jsonDoc.items.push(cipher); - }); - return JSON.stringify(jsonDoc, null, ' '); - } - - private padNumber(num: number, width: number, padCharacter: string = '0'): string { - const numString = num.toString(); - return numString.length >= width ? numString : - new Array(width - numString.length + 1).join(padCharacter) + numString; - } - - private buildCommonCipher(cipher: any, c: CipherView) { - cipher.type = null; - cipher.name = c.name; - cipher.notes = c.notes; - cipher.fields = null; - cipher.reprompt = c.reprompt; - // Login props - cipher.login_uri = null; - cipher.login_username = null; - cipher.login_password = null; - cipher.login_totp = null; - - if (c.fields) { - c.fields.forEach((f: any) => { - if (!cipher.fields) { - cipher.fields = ''; - } else { - cipher.fields += '\n'; - } - - cipher.fields += ((f.name || '') + ': ' + f.value); - }); + cipher.fields += "\n"; } - switch (c.type) { - case CipherType.Login: - cipher.type = 'login'; - cipher.login_username = c.login.username; - cipher.login_password = c.login.password; - cipher.login_totp = c.login.totp; - - if (c.login.uris) { - cipher.login_uri = []; - c.login.uris.forEach(u => { - cipher.login_uri.push(u.uri); - }); - } - break; - case CipherType.SecureNote: - cipher.type = 'note'; - break; - default: - return; - } - - return cipher; + cipher.fields += (f.name || "") + ": " + f.value; + }); } + + switch (c.type) { + case CipherType.Login: + cipher.type = "login"; + cipher.login_username = c.login.username; + cipher.login_password = c.login.password; + cipher.login_totp = c.login.totp; + + if (c.login.uris) { + cipher.login_uri = []; + c.login.uris.forEach((u) => { + cipher.login_uri.push(u.uri); + }); + } + break; + case CipherType.SecureNote: + cipher.type = "note"; + break; + default: + return; + } + + return cipher; + } } diff --git a/common/src/services/fileUpload.service.ts b/common/src/services/fileUpload.service.ts index 1dedc289..516011dd 100644 --- a/common/src/services/fileUpload.service.ts +++ b/common/src/services/fileUpload.service.ts @@ -1,79 +1,109 @@ -import { ApiService } from '../abstractions/api.service'; -import { FileUploadService as FileUploadServiceAbstraction } from '../abstractions/fileUpload.service'; -import { LogService } from '../abstractions/log.service'; +import { ApiService } from "../abstractions/api.service"; +import { FileUploadService as FileUploadServiceAbstraction } from "../abstractions/fileUpload.service"; +import { LogService } from "../abstractions/log.service"; -import { FileUploadType } from '../enums/fileUploadType'; +import { FileUploadType } from "../enums/fileUploadType"; -import { EncArrayBuffer } from '../models/domain/encArrayBuffer'; -import { EncString } from '../models/domain/encString'; +import { EncArrayBuffer } from "../models/domain/encArrayBuffer"; +import { EncString } from "../models/domain/encString"; -import { AttachmentUploadDataResponse } from '../models/response/attachmentUploadDataResponse'; -import { SendFileUploadDataResponse } from '../models/response/sendFileUploadDataResponse'; +import { AttachmentUploadDataResponse } from "../models/response/attachmentUploadDataResponse"; +import { SendFileUploadDataResponse } from "../models/response/sendFileUploadDataResponse"; -import { AzureFileUploadService } from './azureFileUpload.service'; -import { BitwardenFileUploadService } from './bitwardenFileUpload.service'; +import { AzureFileUploadService } from "./azureFileUpload.service"; +import { BitwardenFileUploadService } from "./bitwardenFileUpload.service"; export class FileUploadService implements FileUploadServiceAbstraction { - private azureFileUploadService: AzureFileUploadService; - private bitwardenFileUploadService: BitwardenFileUploadService; + private azureFileUploadService: AzureFileUploadService; + private bitwardenFileUploadService: BitwardenFileUploadService; - constructor(private logService: LogService, private apiService: ApiService) { - this.azureFileUploadService = new AzureFileUploadService(logService); - this.bitwardenFileUploadService = new BitwardenFileUploadService(apiService); - } + constructor(private logService: LogService, private apiService: ApiService) { + this.azureFileUploadService = new AzureFileUploadService(logService); + this.bitwardenFileUploadService = new BitwardenFileUploadService(apiService); + } - async uploadSendFile(uploadData: SendFileUploadDataResponse, fileName: EncString, encryptedFileData: EncArrayBuffer) { - try { - switch (uploadData.fileUploadType) { - case FileUploadType.Direct: - await this.bitwardenFileUploadService.upload(fileName.encryptedString, encryptedFileData, - fd => this.apiService.postSendFile(uploadData.sendResponse.id, uploadData.sendResponse.file.id, fd)); - break; - case FileUploadType.Azure: - const renewalCallback = async () => { - const renewalResponse = await this.apiService.renewSendFileUploadUrl(uploadData.sendResponse.id, - uploadData.sendResponse.file.id); - return renewalResponse.url; - }; - await this.azureFileUploadService.upload(uploadData.url, encryptedFileData, - renewalCallback); - break; - default: - throw new Error('Unknown file upload type'); - } - } catch (e) { - await this.apiService.deleteSend(uploadData.sendResponse.id); - throw e; - } + async uploadSendFile( + uploadData: SendFileUploadDataResponse, + fileName: EncString, + encryptedFileData: EncArrayBuffer + ) { + try { + switch (uploadData.fileUploadType) { + case FileUploadType.Direct: + await this.bitwardenFileUploadService.upload( + fileName.encryptedString, + encryptedFileData, + (fd) => + this.apiService.postSendFile( + uploadData.sendResponse.id, + uploadData.sendResponse.file.id, + fd + ) + ); + break; + case FileUploadType.Azure: + const renewalCallback = async () => { + const renewalResponse = await this.apiService.renewSendFileUploadUrl( + uploadData.sendResponse.id, + uploadData.sendResponse.file.id + ); + return renewalResponse.url; + }; + await this.azureFileUploadService.upload( + uploadData.url, + encryptedFileData, + renewalCallback + ); + break; + default: + throw new Error("Unknown file upload type"); + } + } catch (e) { + await this.apiService.deleteSend(uploadData.sendResponse.id); + throw e; } + } - async uploadCipherAttachment(admin: boolean, uploadData: AttachmentUploadDataResponse, encryptedFileName: EncString, - encryptedFileData: EncArrayBuffer) { - const response = admin ? uploadData.cipherMiniResponse : uploadData.cipherResponse; - try { - switch (uploadData.fileUploadType) { - case FileUploadType.Direct: - await this.bitwardenFileUploadService.upload(encryptedFileName.encryptedString, encryptedFileData, - fd => this.apiService.postAttachmentFile(response.id, uploadData.attachmentId, fd)); - break; - case FileUploadType.Azure: - const renewalCallback = async () => { - const renewalResponse = await this.apiService.renewAttachmentUploadUrl(response.id, - uploadData.attachmentId); - return renewalResponse.url; - }; - await this.azureFileUploadService.upload(uploadData.url, encryptedFileData, renewalCallback); - break; - default: - throw new Error('Unknown file upload type.'); - } - } catch (e) { - if (admin) { - await this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId); - } else { - await this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId); - } - throw e; - } + async uploadCipherAttachment( + admin: boolean, + uploadData: AttachmentUploadDataResponse, + encryptedFileName: EncString, + encryptedFileData: EncArrayBuffer + ) { + const response = admin ? uploadData.cipherMiniResponse : uploadData.cipherResponse; + try { + switch (uploadData.fileUploadType) { + case FileUploadType.Direct: + await this.bitwardenFileUploadService.upload( + encryptedFileName.encryptedString, + encryptedFileData, + (fd) => this.apiService.postAttachmentFile(response.id, uploadData.attachmentId, fd) + ); + break; + case FileUploadType.Azure: + const renewalCallback = async () => { + const renewalResponse = await this.apiService.renewAttachmentUploadUrl( + response.id, + uploadData.attachmentId + ); + return renewalResponse.url; + }; + await this.azureFileUploadService.upload( + uploadData.url, + encryptedFileData, + renewalCallback + ); + break; + default: + throw new Error("Unknown file upload type."); + } + } catch (e) { + if (admin) { + await this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId); + } else { + await this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId); + } + throw e; } + } } diff --git a/common/src/services/i18n.service.ts b/common/src/services/i18n.service.ts index b67ee001..698bc297 100644 --- a/common/src/services/i18n.service.ts +++ b/common/src/services/i18n.service.ts @@ -1,153 +1,160 @@ -import { I18nService as I18nServiceAbstraction } from '../abstractions/i18n.service'; +import { I18nService as I18nServiceAbstraction } from "../abstractions/i18n.service"; export class I18nService implements I18nServiceAbstraction { - locale: string; - // First locale is the default (English) - supportedTranslationLocales: string[] = ['en']; - translationLocale: string; - collator: Intl.Collator; - localeNames = new Map([ - ['af', 'Afrikaans'], - ['az', 'Azərbaycanca'], - ['be', 'Беларуская'], - ['bg', 'български'], - ['ca', 'català'], - ['cs', 'čeština'], - ['da', 'dansk'], - ['de', 'Deutsch'], - ['el', 'Ελληνικά'], - ['en', 'English'], - ['en-GB', 'English (British)'], - ['eo', 'Esperanto'], - ['es', 'español'], - ['et', 'eesti'], - ['fa', 'فارسی'], - ['fi', 'suomi'], - ['fr', 'français'], - ['he', 'עברית'], - ['hi', 'हिन्दी'], - ['hr', 'hrvatski'], - ['hu', 'magyar'], - ['id', 'Bahasa Indonesia'], - ['it', 'italiano'], - ['ja', '日本語'], - ['ko', '한국어'], - ['lv', 'Latvietis'], - ['ml', 'മലയാളം'], - ['nb', 'norsk (bokmål)'], - ['nl', 'Nederlands'], - ['pl', 'polski'], - ['pt-BR', 'português do Brasil'], - ['pt-PT', 'português'], - ['ro', 'română'], - ['ru', 'русский'], - ['sk', 'slovenčina'], - ['sr', 'Српски'], - ['sv', 'svenska'], - ['th', 'ไทย'], - ['tr', 'Türkçe'], - ['uk', 'українська'], - ['vi', 'Tiếng Việt'], - ['zh-CN', '中文(中国大陆)'], - ['zh-TW', '中文(台灣)'], - ]); + locale: string; + // First locale is the default (English) + supportedTranslationLocales: string[] = ["en"]; + translationLocale: string; + collator: Intl.Collator; + localeNames = new Map([ + ["af", "Afrikaans"], + ["az", "Azərbaycanca"], + ["be", "Беларуская"], + ["bg", "български"], + ["ca", "català"], + ["cs", "čeština"], + ["da", "dansk"], + ["de", "Deutsch"], + ["el", "Ελληνικά"], + ["en", "English"], + ["en-GB", "English (British)"], + ["eo", "Esperanto"], + ["es", "español"], + ["et", "eesti"], + ["fa", "فارسی"], + ["fi", "suomi"], + ["fr", "français"], + ["he", "עברית"], + ["hi", "हिन्दी"], + ["hr", "hrvatski"], + ["hu", "magyar"], + ["id", "Bahasa Indonesia"], + ["it", "italiano"], + ["ja", "日本語"], + ["ko", "한국어"], + ["lv", "Latvietis"], + ["ml", "മലയാളം"], + ["nb", "norsk (bokmål)"], + ["nl", "Nederlands"], + ["pl", "polski"], + ["pt-BR", "português do Brasil"], + ["pt-PT", "português"], + ["ro", "română"], + ["ru", "русский"], + ["sk", "slovenčina"], + ["sr", "Српски"], + ["sv", "svenska"], + ["th", "ไทย"], + ["tr", "Türkçe"], + ["uk", "українська"], + ["vi", "Tiếng Việt"], + ["zh-CN", "中文(中国大陆)"], + ["zh-TW", "中文(台灣)"], + ]); - protected inited: boolean; - protected defaultMessages: any = {}; - protected localeMessages: any = {}; + protected inited: boolean; + protected defaultMessages: any = {}; + protected localeMessages: any = {}; - constructor(protected systemLanguage: string, protected localesDirectory: string, - protected getLocalesJson: (formattedLocale: string) => Promise) { - this.systemLanguage = systemLanguage.replace('_', '-'); + constructor( + protected systemLanguage: string, + protected localesDirectory: string, + protected getLocalesJson: (formattedLocale: string) => Promise + ) { + this.systemLanguage = systemLanguage.replace("_", "-"); + } + + async init(locale?: string) { + if (this.inited) { + throw new Error("i18n already initialized."); + } + if (this.supportedTranslationLocales == null || this.supportedTranslationLocales.length === 0) { + throw new Error("supportedTranslationLocales not set."); } - async init(locale?: string) { - if (this.inited) { - throw new Error('i18n already initialized.'); - } - if (this.supportedTranslationLocales == null || this.supportedTranslationLocales.length === 0) { - throw new Error('supportedTranslationLocales not set.'); - } + this.inited = true; + this.locale = this.translationLocale = locale != null ? locale : this.systemLanguage; - this.inited = true; - this.locale = this.translationLocale = locale != null ? locale : this.systemLanguage; - - try { - this.collator = new Intl.Collator(this.locale, { numeric: true, sensitivity: 'base' }); - } catch { - this.collator = null; - } - - if (this.supportedTranslationLocales.indexOf(this.translationLocale) === -1) { - this.translationLocale = this.translationLocale.slice(0, 2); - - if (this.supportedTranslationLocales.indexOf(this.translationLocale) === -1) { - this.translationLocale = this.supportedTranslationLocales[0]; - } - } - - if (this.localesDirectory != null) { - await this.loadMessages(this.translationLocale, this.localeMessages); - if (this.translationLocale !== this.supportedTranslationLocales[0]) { - await this.loadMessages(this.supportedTranslationLocales[0], this.defaultMessages); - } - } + try { + this.collator = new Intl.Collator(this.locale, { numeric: true, sensitivity: "base" }); + } catch { + this.collator = null; } - t(id: string, p1?: string, p2?: string, p3?: string): string { - return this.translate(id, p1, p2, p3); + if (this.supportedTranslationLocales.indexOf(this.translationLocale) === -1) { + this.translationLocale = this.translationLocale.slice(0, 2); + + if (this.supportedTranslationLocales.indexOf(this.translationLocale) === -1) { + this.translationLocale = this.supportedTranslationLocales[0]; + } } - translate(id: string, p1?: string, p2?: string, p3?: string): string { - let result: string; - if (this.localeMessages.hasOwnProperty(id) && this.localeMessages[id]) { - result = this.localeMessages[id]; - } else if (this.defaultMessages.hasOwnProperty(id) && this.defaultMessages[id]) { - result = this.defaultMessages[id]; - } else { - result = ''; - } + if (this.localesDirectory != null) { + await this.loadMessages(this.translationLocale, this.localeMessages); + if (this.translationLocale !== this.supportedTranslationLocales[0]) { + await this.loadMessages(this.supportedTranslationLocales[0], this.defaultMessages); + } + } + } - if (result !== '') { - if (p1 != null) { - result = result.split('__$1__').join(p1); - } - if (p2 != null) { - result = result.split('__$2__').join(p2); - } - if (p3 != null) { - result = result.split('__$3__').join(p3); - } - } + t(id: string, p1?: string, p2?: string, p3?: string): string { + return this.translate(id, p1, p2, p3); + } - return result; + translate(id: string, p1?: string, p2?: string, p3?: string): string { + let result: string; + if (this.localeMessages.hasOwnProperty(id) && this.localeMessages[id]) { + result = this.localeMessages[id]; + } else if (this.defaultMessages.hasOwnProperty(id) && this.defaultMessages[id]) { + result = this.defaultMessages[id]; + } else { + result = ""; } - private async loadMessages(locale: string, messagesObj: any): Promise { - const formattedLocale = locale.replace('-', '_'); - const locales = await this.getLocalesJson(formattedLocale); - for (const prop in locales) { - if (!locales.hasOwnProperty(prop)) { - continue; - } - messagesObj[prop] = locales[prop].message; - - if (locales[prop].placeholders) { - for (const placeProp in locales[prop].placeholders) { - if (!locales[prop].placeholders.hasOwnProperty(placeProp) || - !locales[prop].placeholders[placeProp].content) { - continue; - } - - const replaceToken = '\\$' + placeProp.toUpperCase() + '\\$'; - let replaceContent = locales[prop].placeholders[placeProp].content; - if (replaceContent === '$1' || replaceContent === '$2' || replaceContent === '$3') { - replaceContent = '__$' + replaceContent + '__'; - } - messagesObj[prop] = messagesObj[prop].replace(new RegExp(replaceToken, 'g'), replaceContent); - } - } - } + if (result !== "") { + if (p1 != null) { + result = result.split("__$1__").join(p1); + } + if (p2 != null) { + result = result.split("__$2__").join(p2); + } + if (p3 != null) { + result = result.split("__$3__").join(p3); + } } + return result; + } + + private async loadMessages(locale: string, messagesObj: any): Promise { + const formattedLocale = locale.replace("-", "_"); + const locales = await this.getLocalesJson(formattedLocale); + for (const prop in locales) { + if (!locales.hasOwnProperty(prop)) { + continue; + } + messagesObj[prop] = locales[prop].message; + + if (locales[prop].placeholders) { + for (const placeProp in locales[prop].placeholders) { + if ( + !locales[prop].placeholders.hasOwnProperty(placeProp) || + !locales[prop].placeholders[placeProp].content + ) { + continue; + } + + const replaceToken = "\\$" + placeProp.toUpperCase() + "\\$"; + let replaceContent = locales[prop].placeholders[placeProp].content; + if (replaceContent === "$1" || replaceContent === "$2" || replaceContent === "$3") { + replaceContent = "__$" + replaceContent + "__"; + } + messagesObj[prop] = messagesObj[prop].replace( + new RegExp(replaceToken, "g"), + replaceContent + ); + } + } + } + } } diff --git a/common/src/services/import.service.ts b/common/src/services/import.service.ts index d04ede50..7d8cfa92 100644 --- a/common/src/services/import.service.ts +++ b/common/src/services/import.service.ts @@ -1,403 +1,420 @@ -import { ApiService } from '../abstractions/api.service'; -import { CipherService } from '../abstractions/cipher.service'; -import { CollectionService } from '../abstractions/collection.service'; -import { CryptoService } from '../abstractions/crypto.service'; -import { FolderService } from '../abstractions/folder.service'; -import { I18nService } from '../abstractions/i18n.service'; +import { ApiService } from "../abstractions/api.service"; +import { CipherService } from "../abstractions/cipher.service"; +import { CollectionService } from "../abstractions/collection.service"; +import { CryptoService } from "../abstractions/crypto.service"; +import { FolderService } from "../abstractions/folder.service"; +import { I18nService } from "../abstractions/i18n.service"; import { - ImportOption, - ImportService as ImportServiceAbstraction, -} from '../abstractions/import.service'; -import { PlatformUtilsService } from '../abstractions/platformUtils.service'; + ImportOption, + ImportService as ImportServiceAbstraction, +} from "../abstractions/import.service"; +import { PlatformUtilsService } from "../abstractions/platformUtils.service"; -import { ImportResult } from '../models/domain/importResult'; +import { ImportResult } from "../models/domain/importResult"; -import { CipherType } from '../enums/cipherType'; +import { CipherType } from "../enums/cipherType"; -import { Utils } from '../misc/utils'; +import { Utils } from "../misc/utils"; -import { CipherRequest } from '../models/request/cipherRequest'; -import { CollectionRequest } from '../models/request/collectionRequest'; -import { FolderRequest } from '../models/request/folderRequest'; -import { ImportCiphersRequest } from '../models/request/importCiphersRequest'; -import { ImportOrganizationCiphersRequest } from '../models/request/importOrganizationCiphersRequest'; -import { KvpRequest } from '../models/request/kvpRequest'; +import { CipherRequest } from "../models/request/cipherRequest"; +import { CollectionRequest } from "../models/request/collectionRequest"; +import { FolderRequest } from "../models/request/folderRequest"; +import { ImportCiphersRequest } from "../models/request/importCiphersRequest"; +import { ImportOrganizationCiphersRequest } from "../models/request/importOrganizationCiphersRequest"; +import { KvpRequest } from "../models/request/kvpRequest"; -import { ErrorResponse } from '../models/response/errorResponse'; -import { CipherView } from '../models/view/cipherView'; +import { ErrorResponse } from "../models/response/errorResponse"; +import { CipherView } from "../models/view/cipherView"; -import { AscendoCsvImporter } from '../importers/ascendoCsvImporter'; -import { AvastCsvImporter } from '../importers/avastCsvImporter'; -import { AvastJsonImporter } from '../importers/avastJsonImporter'; -import { AviraCsvImporter } from '../importers/aviraCsvImporter'; -import { BitwardenCsvImporter } from '../importers/bitwardenCsvImporter'; -import { BitwardenJsonImporter } from '../importers/bitwardenJsonImporter'; -import { BlackBerryCsvImporter } from '../importers/blackBerryCsvImporter'; -import { BlurCsvImporter } from '../importers/blurCsvImporter'; -import { ButtercupCsvImporter } from '../importers/buttercupCsvImporter'; -import { ChromeCsvImporter } from '../importers/chromeCsvImporter'; -import { ClipperzHtmlImporter } from '../importers/clipperzHtmlImporter'; -import { CodebookCsvImporter } from '../importers/codebookCsvImporter'; -import { DashlaneJsonImporter } from '../importers/dashlaneJsonImporter'; -import { EncryptrCsvImporter } from '../importers/encryptrCsvImporter'; -import { EnpassCsvImporter } from '../importers/enpassCsvImporter'; -import { EnpassJsonImporter } from '../importers/enpassJsonImporter'; -import { FirefoxCsvImporter } from '../importers/firefoxCsvImporter'; -import { FSecureFskImporter } from '../importers/fsecureFskImporter'; -import { GnomeJsonImporter } from '../importers/gnomeJsonImporter'; -import { Importer } from '../importers/importer'; -import { KasperskyTxtImporter } from '../importers/kasperskyTxtImporter'; -import { KeePass2XmlImporter } from '../importers/keepass2XmlImporter'; -import { KeePassXCsvImporter } from '../importers/keepassxCsvImporter'; -import { KeeperCsvImporter } from '../importers/keeperCsvImporter'; -import { LastPassCsvImporter } from '../importers/lastpassCsvImporter'; -import { LogMeOnceCsvImporter } from '../importers/logMeOnceCsvImporter'; -import { MeldiumCsvImporter } from '../importers/meldiumCsvImporter'; -import { MSecureCsvImporter } from '../importers/msecureCsvImporter'; -import { MykiCsvImporter } from '../importers/mykiCsvImporter'; -import { NordPassCsvImporter } from '../importers/nordpassCsvImporter'; -import { OnePassword1PifImporter } from '../importers/onepasswordImporters/onepassword1PifImporter'; -import { OnePasswordMacCsvImporter } from '../importers/onepasswordImporters/onepasswordMacCsvImporter'; -import { OnePasswordWinCsvImporter } from '../importers/onepasswordImporters/onepasswordWinCsvImporter'; -import { PadlockCsvImporter } from '../importers/padlockCsvImporter'; -import { PassKeepCsvImporter } from '../importers/passkeepCsvImporter'; -import { PassmanJsonImporter } from '../importers/passmanJsonImporter'; -import { PasspackCsvImporter } from '../importers/passpackCsvImporter'; -import { PasswordAgentCsvImporter } from '../importers/passwordAgentCsvImporter'; -import { PasswordBossJsonImporter } from '../importers/passwordBossJsonImporter'; -import { PasswordDragonXmlImporter } from '../importers/passwordDragonXmlImporter'; -import { PasswordSafeXmlImporter } from '../importers/passwordSafeXmlImporter'; -import { PasswordWalletTxtImporter } from '../importers/passwordWalletTxtImporter'; -import { RememBearCsvImporter } from '../importers/rememBearCsvImporter'; -import { RoboFormCsvImporter } from '../importers/roboformCsvImporter'; -import { SafariCsvImporter } from '../importers/safariCsvImporter'; -import { SafeInCloudXmlImporter } from '../importers/safeInCloudXmlImporter'; -import { SaferPassCsvImporter } from '../importers/saferpassCsvImport'; -import { SecureSafeCsvImporter } from '../importers/secureSafeCsvImporter'; -import { SplashIdCsvImporter } from '../importers/splashIdCsvImporter'; -import { StickyPasswordXmlImporter } from '../importers/stickyPasswordXmlImporter'; -import { TrueKeyCsvImporter } from '../importers/truekeyCsvImporter'; -import { UpmCsvImporter } from '../importers/upmCsvImporter'; -import { YotiCsvImporter } from '../importers/yotiCsvImporter'; -import { ZohoVaultCsvImporter } from '../importers/zohoVaultCsvImporter'; +import { AscendoCsvImporter } from "../importers/ascendoCsvImporter"; +import { AvastCsvImporter } from "../importers/avastCsvImporter"; +import { AvastJsonImporter } from "../importers/avastJsonImporter"; +import { AviraCsvImporter } from "../importers/aviraCsvImporter"; +import { BitwardenCsvImporter } from "../importers/bitwardenCsvImporter"; +import { BitwardenJsonImporter } from "../importers/bitwardenJsonImporter"; +import { BlackBerryCsvImporter } from "../importers/blackBerryCsvImporter"; +import { BlurCsvImporter } from "../importers/blurCsvImporter"; +import { ButtercupCsvImporter } from "../importers/buttercupCsvImporter"; +import { ChromeCsvImporter } from "../importers/chromeCsvImporter"; +import { ClipperzHtmlImporter } from "../importers/clipperzHtmlImporter"; +import { CodebookCsvImporter } from "../importers/codebookCsvImporter"; +import { DashlaneJsonImporter } from "../importers/dashlaneJsonImporter"; +import { EncryptrCsvImporter } from "../importers/encryptrCsvImporter"; +import { EnpassCsvImporter } from "../importers/enpassCsvImporter"; +import { EnpassJsonImporter } from "../importers/enpassJsonImporter"; +import { FirefoxCsvImporter } from "../importers/firefoxCsvImporter"; +import { FSecureFskImporter } from "../importers/fsecureFskImporter"; +import { GnomeJsonImporter } from "../importers/gnomeJsonImporter"; +import { Importer } from "../importers/importer"; +import { KasperskyTxtImporter } from "../importers/kasperskyTxtImporter"; +import { KeePass2XmlImporter } from "../importers/keepass2XmlImporter"; +import { KeePassXCsvImporter } from "../importers/keepassxCsvImporter"; +import { KeeperCsvImporter } from "../importers/keeperCsvImporter"; +import { LastPassCsvImporter } from "../importers/lastpassCsvImporter"; +import { LogMeOnceCsvImporter } from "../importers/logMeOnceCsvImporter"; +import { MeldiumCsvImporter } from "../importers/meldiumCsvImporter"; +import { MSecureCsvImporter } from "../importers/msecureCsvImporter"; +import { MykiCsvImporter } from "../importers/mykiCsvImporter"; +import { NordPassCsvImporter } from "../importers/nordpassCsvImporter"; +import { OnePassword1PifImporter } from "../importers/onepasswordImporters/onepassword1PifImporter"; +import { OnePasswordMacCsvImporter } from "../importers/onepasswordImporters/onepasswordMacCsvImporter"; +import { OnePasswordWinCsvImporter } from "../importers/onepasswordImporters/onepasswordWinCsvImporter"; +import { PadlockCsvImporter } from "../importers/padlockCsvImporter"; +import { PassKeepCsvImporter } from "../importers/passkeepCsvImporter"; +import { PassmanJsonImporter } from "../importers/passmanJsonImporter"; +import { PasspackCsvImporter } from "../importers/passpackCsvImporter"; +import { PasswordAgentCsvImporter } from "../importers/passwordAgentCsvImporter"; +import { PasswordBossJsonImporter } from "../importers/passwordBossJsonImporter"; +import { PasswordDragonXmlImporter } from "../importers/passwordDragonXmlImporter"; +import { PasswordSafeXmlImporter } from "../importers/passwordSafeXmlImporter"; +import { PasswordWalletTxtImporter } from "../importers/passwordWalletTxtImporter"; +import { RememBearCsvImporter } from "../importers/rememBearCsvImporter"; +import { RoboFormCsvImporter } from "../importers/roboformCsvImporter"; +import { SafariCsvImporter } from "../importers/safariCsvImporter"; +import { SafeInCloudXmlImporter } from "../importers/safeInCloudXmlImporter"; +import { SaferPassCsvImporter } from "../importers/saferpassCsvImport"; +import { SecureSafeCsvImporter } from "../importers/secureSafeCsvImporter"; +import { SplashIdCsvImporter } from "../importers/splashIdCsvImporter"; +import { StickyPasswordXmlImporter } from "../importers/stickyPasswordXmlImporter"; +import { TrueKeyCsvImporter } from "../importers/truekeyCsvImporter"; +import { UpmCsvImporter } from "../importers/upmCsvImporter"; +import { YotiCsvImporter } from "../importers/yotiCsvImporter"; +import { ZohoVaultCsvImporter } from "../importers/zohoVaultCsvImporter"; export class ImportService implements ImportServiceAbstraction { - featuredImportOptions = [ - { id: 'bitwardenjson', name: 'Bitwarden (json)' }, - { id: 'bitwardencsv', name: 'Bitwarden (csv)' }, - { id: 'chromecsv', name: 'Chrome (csv)' }, - { id: 'dashlanejson', name: 'Dashlane (json)' }, - { id: 'firefoxcsv', name: 'Firefox (csv)' }, - { id: 'keepass2xml', name: 'KeePass 2 (xml)' }, - { id: 'lastpasscsv', name: 'LastPass (csv)' }, - { id: 'safaricsv', name: 'Safari and macOS (csv)' }, - { id: '1password1pif', name: '1Password (1pif)' }, - ]; + featuredImportOptions = [ + { id: "bitwardenjson", name: "Bitwarden (json)" }, + { id: "bitwardencsv", name: "Bitwarden (csv)" }, + { id: "chromecsv", name: "Chrome (csv)" }, + { id: "dashlanejson", name: "Dashlane (json)" }, + { id: "firefoxcsv", name: "Firefox (csv)" }, + { id: "keepass2xml", name: "KeePass 2 (xml)" }, + { id: "lastpasscsv", name: "LastPass (csv)" }, + { id: "safaricsv", name: "Safari and macOS (csv)" }, + { id: "1password1pif", name: "1Password (1pif)" }, + ]; - regularImportOptions: ImportOption[] = [ - { id: 'keepassxcsv', name: 'KeePassX (csv)' }, - { id: '1passwordwincsv', name: '1Password 6 and 7 Windows (csv)' }, - { id: '1passwordmaccsv', name: '1Password 6 and 7 Mac (csv)' }, - { id: 'roboformcsv', name: 'RoboForm (csv)' }, - { id: 'keepercsv', name: 'Keeper (csv)' }, - { id: 'enpasscsv', name: 'Enpass (csv)' }, - { id: 'enpassjson', name: 'Enpass (json)' }, - { id: 'safeincloudxml', name: 'SafeInCloud (xml)' }, - { id: 'pwsafexml', name: 'Password Safe (xml)' }, - { id: 'stickypasswordxml', name: 'Sticky Password (xml)' }, - { id: 'msecurecsv', name: 'mSecure (csv)' }, - { id: 'truekeycsv', name: 'True Key (csv)' }, - { id: 'passwordbossjson', name: 'Password Boss (json)' }, - { id: 'zohovaultcsv', name: 'Zoho Vault (csv)' }, - { id: 'splashidcsv', name: 'SplashID (csv)' }, - { id: 'passworddragonxml', name: 'Password Dragon (xml)' }, - { id: 'padlockcsv', name: 'Padlock (csv)' }, - { id: 'passboltcsv', name: 'Passbolt (csv)' }, - { id: 'clipperzhtml', name: 'Clipperz (html)' }, - { id: 'aviracsv', name: 'Avira (csv)' }, - { id: 'saferpasscsv', name: 'SaferPass (csv)' }, - { id: 'upmcsv', name: 'Universal Password Manager (csv)' }, - { id: 'ascendocsv', name: 'Ascendo DataVault (csv)' }, - { id: 'meldiumcsv', name: 'Meldium (csv)' }, - { id: 'passkeepcsv', name: 'PassKeep (csv)' }, - { id: 'operacsv', name: 'Opera (csv)' }, - { id: 'vivaldicsv', name: 'Vivaldi (csv)' }, - { id: 'gnomejson', name: 'GNOME Passwords and Keys/Seahorse (json)' }, - { id: 'blurcsv', name: 'Blur (csv)' }, - { id: 'passwordagentcsv', name: 'Password Agent (csv)' }, - { id: 'passpackcsv', name: 'Passpack (csv)' }, - { id: 'passmanjson', name: 'Passman (json)' }, - { id: 'avastcsv', name: 'Avast Passwords (csv)' }, - { id: 'avastjson', name: 'Avast Passwords (json)' }, - { id: 'fsecurefsk', name: 'F-Secure KEY (fsk)' }, - { id: 'kasperskytxt', name: 'Kaspersky Password Manager (txt)' }, - { id: 'remembearcsv', name: 'RememBear (csv)' }, - { id: 'passwordwallettxt', name: 'PasswordWallet (txt)' }, - { id: 'mykicsv', name: 'Myki (csv)' }, - { id: 'securesafecsv', name: 'SecureSafe (csv)' }, - { id: 'logmeoncecsv', name: 'LogMeOnce (csv)' }, - { id: 'blackberrycsv', name: 'BlackBerry Password Keeper (csv)' }, - { id: 'buttercupcsv', name: 'Buttercup (csv)' }, - { id: 'codebookcsv', name: 'Codebook (csv)' }, - { id: 'encryptrcsv', name: 'Encryptr (csv)' }, - { id: 'yoticsv', name: 'Yoti (csv)' }, - { id: 'nordpasscsv', name: 'Nordpass (csv)' }, - ]; + regularImportOptions: ImportOption[] = [ + { id: "keepassxcsv", name: "KeePassX (csv)" }, + { id: "1passwordwincsv", name: "1Password 6 and 7 Windows (csv)" }, + { id: "1passwordmaccsv", name: "1Password 6 and 7 Mac (csv)" }, + { id: "roboformcsv", name: "RoboForm (csv)" }, + { id: "keepercsv", name: "Keeper (csv)" }, + { id: "enpasscsv", name: "Enpass (csv)" }, + { id: "enpassjson", name: "Enpass (json)" }, + { id: "safeincloudxml", name: "SafeInCloud (xml)" }, + { id: "pwsafexml", name: "Password Safe (xml)" }, + { id: "stickypasswordxml", name: "Sticky Password (xml)" }, + { id: "msecurecsv", name: "mSecure (csv)" }, + { id: "truekeycsv", name: "True Key (csv)" }, + { id: "passwordbossjson", name: "Password Boss (json)" }, + { id: "zohovaultcsv", name: "Zoho Vault (csv)" }, + { id: "splashidcsv", name: "SplashID (csv)" }, + { id: "passworddragonxml", name: "Password Dragon (xml)" }, + { id: "padlockcsv", name: "Padlock (csv)" }, + { id: "passboltcsv", name: "Passbolt (csv)" }, + { id: "clipperzhtml", name: "Clipperz (html)" }, + { id: "aviracsv", name: "Avira (csv)" }, + { id: "saferpasscsv", name: "SaferPass (csv)" }, + { id: "upmcsv", name: "Universal Password Manager (csv)" }, + { id: "ascendocsv", name: "Ascendo DataVault (csv)" }, + { id: "meldiumcsv", name: "Meldium (csv)" }, + { id: "passkeepcsv", name: "PassKeep (csv)" }, + { id: "operacsv", name: "Opera (csv)" }, + { id: "vivaldicsv", name: "Vivaldi (csv)" }, + { id: "gnomejson", name: "GNOME Passwords and Keys/Seahorse (json)" }, + { id: "blurcsv", name: "Blur (csv)" }, + { id: "passwordagentcsv", name: "Password Agent (csv)" }, + { id: "passpackcsv", name: "Passpack (csv)" }, + { id: "passmanjson", name: "Passman (json)" }, + { id: "avastcsv", name: "Avast Passwords (csv)" }, + { id: "avastjson", name: "Avast Passwords (json)" }, + { id: "fsecurefsk", name: "F-Secure KEY (fsk)" }, + { id: "kasperskytxt", name: "Kaspersky Password Manager (txt)" }, + { id: "remembearcsv", name: "RememBear (csv)" }, + { id: "passwordwallettxt", name: "PasswordWallet (txt)" }, + { id: "mykicsv", name: "Myki (csv)" }, + { id: "securesafecsv", name: "SecureSafe (csv)" }, + { id: "logmeoncecsv", name: "LogMeOnce (csv)" }, + { id: "blackberrycsv", name: "BlackBerry Password Keeper (csv)" }, + { id: "buttercupcsv", name: "Buttercup (csv)" }, + { id: "codebookcsv", name: "Codebook (csv)" }, + { id: "encryptrcsv", name: "Encryptr (csv)" }, + { id: "yoticsv", name: "Yoti (csv)" }, + { id: "nordpasscsv", name: "Nordpass (csv)" }, + ]; - constructor(private cipherService: CipherService, private folderService: FolderService, - private apiService: ApiService, private i18nService: I18nService, - private collectionService: CollectionService, private platformUtilsService: PlatformUtilsService, - private cryptoService: CryptoService) { } + constructor( + private cipherService: CipherService, + private folderService: FolderService, + private apiService: ApiService, + private i18nService: I18nService, + private collectionService: CollectionService, + private platformUtilsService: PlatformUtilsService, + private cryptoService: CryptoService + ) {} - getImportOptions(): ImportOption[] { - return this.featuredImportOptions.concat(this.regularImportOptions); - } + getImportOptions(): ImportOption[] { + return this.featuredImportOptions.concat(this.regularImportOptions); + } - async import(importer: Importer, fileContents: string, organizationId: string = null): Promise { - const importResult = await importer.parse(fileContents); - if (importResult.success) { - if (importResult.folders.length === 0 && importResult.ciphers.length === 0) { - return new Error(this.i18nService.t('importNothingError')); - } else if (importResult.ciphers.length > 0) { - const halfway = Math.floor(importResult.ciphers.length / 2); - const last = importResult.ciphers.length - 1; + async import( + importer: Importer, + fileContents: string, + organizationId: string = null + ): Promise { + const importResult = await importer.parse(fileContents); + if (importResult.success) { + if (importResult.folders.length === 0 && importResult.ciphers.length === 0) { + return new Error(this.i18nService.t("importNothingError")); + } else if (importResult.ciphers.length > 0) { + const halfway = Math.floor(importResult.ciphers.length / 2); + const last = importResult.ciphers.length - 1; - if (this.badData(importResult.ciphers[0]) && - this.badData(importResult.ciphers[halfway]) && - this.badData(importResult.ciphers[last])) { - return new Error(this.i18nService.t('importFormatError')); - } - } - try { - await this.postImport(importResult, organizationId); - } catch (error) { - const errorResponse = new ErrorResponse(error, 400); - return this.handleServerError(errorResponse, importResult); - } - return null; - } else { - if (!Utils.isNullOrWhitespace(importResult.errorMessage)) { - return new Error(importResult.errorMessage); - } else { - return new Error(this.i18nService.t('importFormatError')); - } + if ( + this.badData(importResult.ciphers[0]) && + this.badData(importResult.ciphers[halfway]) && + this.badData(importResult.ciphers[last]) + ) { + return new Error(this.i18nService.t("importFormatError")); } + } + try { + await this.postImport(importResult, organizationId); + } catch (error) { + const errorResponse = new ErrorResponse(error, 400); + return this.handleServerError(errorResponse, importResult); + } + return null; + } else { + if (!Utils.isNullOrWhitespace(importResult.errorMessage)) { + return new Error(importResult.errorMessage); + } else { + return new Error(this.i18nService.t("importFormatError")); + } + } + } + + getImporter(format: string, organizationId: string = null): Importer { + const importer = this.getImporterInstance(format); + if (importer == null) { + return null; + } + importer.organizationId = organizationId; + return importer; + } + + private getImporterInstance(format: string) { + if (format == null || format === "") { + return null; } - getImporter(format: string, organizationId: string = null): Importer { - const importer = this.getImporterInstance(format); - if (importer == null) { - return null; + switch (format) { + case "bitwardencsv": + return new BitwardenCsvImporter(); + case "bitwardenjson": + return new BitwardenJsonImporter(this.cryptoService, this.i18nService); + case "lastpasscsv": + case "passboltcsv": + return new LastPassCsvImporter(); + case "keepassxcsv": + return new KeePassXCsvImporter(); + case "aviracsv": + return new AviraCsvImporter(); + case "blurcsv": + return new BlurCsvImporter(); + case "safeincloudxml": + return new SafeInCloudXmlImporter(); + case "padlockcsv": + return new PadlockCsvImporter(); + case "keepass2xml": + return new KeePass2XmlImporter(); + case "chromecsv": + case "operacsv": + case "vivaldicsv": + return new ChromeCsvImporter(); + case "firefoxcsv": + return new FirefoxCsvImporter(); + case "upmcsv": + return new UpmCsvImporter(); + case "saferpasscsv": + return new SaferPassCsvImporter(); + case "safaricsv": + return new SafariCsvImporter(); + case "meldiumcsv": + return new MeldiumCsvImporter(); + case "1password1pif": + return new OnePassword1PifImporter(); + case "1passwordwincsv": + return new OnePasswordWinCsvImporter(); + case "1passwordmaccsv": + return new OnePasswordMacCsvImporter(); + case "keepercsv": + return new KeeperCsvImporter(); + case "passworddragonxml": + return new PasswordDragonXmlImporter(); + case "enpasscsv": + return new EnpassCsvImporter(); + case "enpassjson": + return new EnpassJsonImporter(); + case "pwsafexml": + return new PasswordSafeXmlImporter(); + case "dashlanejson": + return new DashlaneJsonImporter(); + case "msecurecsv": + return new MSecureCsvImporter(); + case "stickypasswordxml": + return new StickyPasswordXmlImporter(); + case "truekeycsv": + return new TrueKeyCsvImporter(); + case "clipperzhtml": + return new ClipperzHtmlImporter(); + case "roboformcsv": + return new RoboFormCsvImporter(); + case "ascendocsv": + return new AscendoCsvImporter(); + case "passwordbossjson": + return new PasswordBossJsonImporter(); + case "zohovaultcsv": + return new ZohoVaultCsvImporter(); + case "splashidcsv": + return new SplashIdCsvImporter(); + case "passkeepcsv": + return new PassKeepCsvImporter(); + case "gnomejson": + return new GnomeJsonImporter(); + case "passwordagentcsv": + return new PasswordAgentCsvImporter(); + case "passpackcsv": + return new PasspackCsvImporter(); + case "passmanjson": + return new PassmanJsonImporter(); + case "avastcsv": + return new AvastCsvImporter(); + case "avastjson": + return new AvastJsonImporter(); + case "fsecurefsk": + return new FSecureFskImporter(); + case "kasperskytxt": + return new KasperskyTxtImporter(); + case "remembearcsv": + return new RememBearCsvImporter(); + case "passwordwallettxt": + return new PasswordWalletTxtImporter(); + case "mykicsv": + return new MykiCsvImporter(); + case "securesafecsv": + return new SecureSafeCsvImporter(); + case "logmeoncecsv": + return new LogMeOnceCsvImporter(); + case "blackberrycsv": + return new BlackBerryCsvImporter(); + case "buttercupcsv": + return new ButtercupCsvImporter(); + case "codebookcsv": + return new CodebookCsvImporter(); + case "encryptrcsv": + return new EncryptrCsvImporter(); + case "yoticsv": + return new YotiCsvImporter(); + case "nordpasscsv": + return new NordPassCsvImporter(); + default: + return null; + } + } + + private async postImport(importResult: ImportResult, organizationId: string = null) { + if (organizationId == null) { + const request = new ImportCiphersRequest(); + for (let i = 0; i < importResult.ciphers.length; i++) { + const c = await this.cipherService.encrypt(importResult.ciphers[i]); + request.ciphers.push(new CipherRequest(c)); + } + if (importResult.folders != null) { + for (let i = 0; i < importResult.folders.length; i++) { + const f = await this.folderService.encrypt(importResult.folders[i]); + request.folders.push(new FolderRequest(f)); } - importer.organizationId = organizationId; - return importer; - } - - private getImporterInstance(format: string) { - if (format == null || format === '') { - return null; + } + if (importResult.folderRelationships != null) { + importResult.folderRelationships.forEach((r) => + request.folderRelationships.push(new KvpRequest(r[0], r[1])) + ); + } + return await this.apiService.postImportCiphers(request); + } else { + const request = new ImportOrganizationCiphersRequest(); + for (let i = 0; i < importResult.ciphers.length; i++) { + importResult.ciphers[i].organizationId = organizationId; + const c = await this.cipherService.encrypt(importResult.ciphers[i]); + request.ciphers.push(new CipherRequest(c)); + } + if (importResult.collections != null) { + for (let i = 0; i < importResult.collections.length; i++) { + importResult.collections[i].organizationId = organizationId; + const c = await this.collectionService.encrypt(importResult.collections[i]); + request.collections.push(new CollectionRequest(c)); } + } + if (importResult.collectionRelationships != null) { + importResult.collectionRelationships.forEach((r) => + request.collectionRelationships.push(new KvpRequest(r[0], r[1])) + ); + } + return await this.apiService.postImportOrganizationCiphers(organizationId, request); + } + } - switch (format) { - case 'bitwardencsv': - return new BitwardenCsvImporter(); - case 'bitwardenjson': - return new BitwardenJsonImporter(this.cryptoService, this.i18nService); - case 'lastpasscsv': - case 'passboltcsv': - return new LastPassCsvImporter(); - case 'keepassxcsv': - return new KeePassXCsvImporter(); - case 'aviracsv': - return new AviraCsvImporter(); - case 'blurcsv': - return new BlurCsvImporter(); - case 'safeincloudxml': - return new SafeInCloudXmlImporter(); - case 'padlockcsv': - return new PadlockCsvImporter(); - case 'keepass2xml': - return new KeePass2XmlImporter(); - case 'chromecsv': - case 'operacsv': - case 'vivaldicsv': - return new ChromeCsvImporter(); - case 'firefoxcsv': - return new FirefoxCsvImporter(); - case 'upmcsv': - return new UpmCsvImporter(); - case 'saferpasscsv': - return new SaferPassCsvImporter(); - case 'safaricsv': - return new SafariCsvImporter(); - case 'meldiumcsv': - return new MeldiumCsvImporter(); - case '1password1pif': - return new OnePassword1PifImporter(); - case '1passwordwincsv': - return new OnePasswordWinCsvImporter(); - case '1passwordmaccsv': - return new OnePasswordMacCsvImporter(); - case 'keepercsv': - return new KeeperCsvImporter(); - case 'passworddragonxml': - return new PasswordDragonXmlImporter(); - case 'enpasscsv': - return new EnpassCsvImporter(); - case 'enpassjson': - return new EnpassJsonImporter(); - case 'pwsafexml': - return new PasswordSafeXmlImporter(); - case 'dashlanejson': - return new DashlaneJsonImporter(); - case 'msecurecsv': - return new MSecureCsvImporter(); - case 'stickypasswordxml': - return new StickyPasswordXmlImporter(); - case 'truekeycsv': - return new TrueKeyCsvImporter(); - case 'clipperzhtml': - return new ClipperzHtmlImporter(); - case 'roboformcsv': - return new RoboFormCsvImporter(); - case 'ascendocsv': - return new AscendoCsvImporter(); - case 'passwordbossjson': - return new PasswordBossJsonImporter(); - case 'zohovaultcsv': - return new ZohoVaultCsvImporter(); - case 'splashidcsv': - return new SplashIdCsvImporter(); - case 'passkeepcsv': - return new PassKeepCsvImporter(); - case 'gnomejson': - return new GnomeJsonImporter(); - case 'passwordagentcsv': - return new PasswordAgentCsvImporter(); - case 'passpackcsv': - return new PasspackCsvImporter(); - case 'passmanjson': - return new PassmanJsonImporter(); - case 'avastcsv': - return new AvastCsvImporter(); - case 'avastjson': - return new AvastJsonImporter(); - case 'fsecurefsk': - return new FSecureFskImporter(); - case 'kasperskytxt': - return new KasperskyTxtImporter(); - case 'remembearcsv': - return new RememBearCsvImporter(); - case 'passwordwallettxt': - return new PasswordWalletTxtImporter(); - case 'mykicsv': - return new MykiCsvImporter(); - case 'securesafecsv': - return new SecureSafeCsvImporter(); - case 'logmeoncecsv': - return new LogMeOnceCsvImporter(); - case 'blackberrycsv': - return new BlackBerryCsvImporter(); - case 'buttercupcsv': - return new ButtercupCsvImporter(); - case 'codebookcsv': - return new CodebookCsvImporter(); - case 'encryptrcsv': - return new EncryptrCsvImporter(); - case 'yoticsv': - return new YotiCsvImporter(); - case 'nordpasscsv': - return new NordPassCsvImporter(); - default: - return null; - } + private badData(c: CipherView) { + return ( + (c.name == null || c.name === "--") && + c.type === CipherType.Login && + c.login != null && + Utils.isNullOrWhitespace(c.login.password) + ); + } + + private handleServerError(errorResponse: ErrorResponse, importResult: ImportResult): Error { + if (errorResponse.validationErrors == null) { + return new Error(errorResponse.message); } - private async postImport(importResult: ImportResult, organizationId: string = null) { - if (organizationId == null) { - const request = new ImportCiphersRequest(); - for (let i = 0; i < importResult.ciphers.length; i++) { - const c = await this.cipherService.encrypt(importResult.ciphers[i]); - request.ciphers.push(new CipherRequest(c)); - } - if (importResult.folders != null) { - for (let i = 0; i < importResult.folders.length; i++) { - const f = await this.folderService.encrypt(importResult.folders[i]); - request.folders.push(new FolderRequest(f)); - } - } - if (importResult.folderRelationships != null) { - importResult.folderRelationships.forEach(r => - request.folderRelationships.push(new KvpRequest(r[0], r[1]))); - } - return await this.apiService.postImportCiphers(request); - } else { - const request = new ImportOrganizationCiphersRequest(); - for (let i = 0; i < importResult.ciphers.length; i++) { - importResult.ciphers[i].organizationId = organizationId; - const c = await this.cipherService.encrypt(importResult.ciphers[i]); - request.ciphers.push(new CipherRequest(c)); - } - if (importResult.collections != null) { - for (let i = 0; i < importResult.collections.length; i++) { - importResult.collections[i].organizationId = organizationId; - const c = await this.collectionService.encrypt(importResult.collections[i]); - request.collections.push(new CollectionRequest(c)); - } - } - if (importResult.collectionRelationships != null) { - importResult.collectionRelationships.forEach(r => - request.collectionRelationships.push(new KvpRequest(r[0], r[1]))); - } - return await this.apiService.postImportOrganizationCiphers(organizationId, request); - } - } + let errorMessage = ""; - private badData(c: CipherView) { - return (c.name == null || c.name === '--') && - (c.type === CipherType.Login && c.login != null && Utils.isNullOrWhitespace(c.login.password)); - } + Object.entries(errorResponse.validationErrors).forEach(([key, value], index) => { + let item; + let itemType; + const i = Number(key.match(/[0-9]+/)[0]); - private handleServerError(errorResponse: ErrorResponse, importResult: ImportResult): Error { - if (errorResponse.validationErrors == null) { - return new Error(errorResponse.message); - } + switch (key.match(/^\w+/)[0]) { + case "Ciphers": + item = importResult.ciphers[i]; + itemType = CipherType[item.type]; + break; + case "Folders": + item = importResult.folders[i]; + itemType = "Folder"; + break; + case "Collections": + item = importResult.collections[i]; + itemType = "Collection"; + break; + default: + return; + } - let errorMessage = ''; + if (index > 0) { + errorMessage += "\n\n"; + } - Object.entries(errorResponse.validationErrors).forEach(([key, value], index) => { - let item; - let itemType; - const i = Number(key.match(/[0-9]+/)[0]); + if (itemType !== "Folder" && itemType !== "Collection") { + errorMessage += "[" + (i + 1) + "] "; + } - switch (key.match(/^\w+/)[0]) { - case 'Ciphers': - item = importResult.ciphers[i]; - itemType = CipherType[item.type]; - break; - case 'Folders': - item = importResult.folders[i]; - itemType = 'Folder'; - break; - case 'Collections': - item = importResult.collections[i]; - itemType = 'Collection'; - break; - default: - return; - } + errorMessage += "[" + itemType + '] "' + item.name + '": ' + value; + }); - if (index > 0) { - errorMessage += '\n\n'; - } - - if (itemType !== 'Folder' && itemType !== 'Collection') { - errorMessage += '[' + (i + 1) + '] '; - } - - errorMessage += '[' + itemType + '] "' + item.name + '": ' + value; - }); - - return new Error(errorMessage); - } + return new Error(errorMessage); + } } diff --git a/common/src/services/noopMessaging.service.ts b/common/src/services/noopMessaging.service.ts index c1a1443c..d1a60bc5 100644 --- a/common/src/services/noopMessaging.service.ts +++ b/common/src/services/noopMessaging.service.ts @@ -1,7 +1,7 @@ -import { MessagingService } from '../abstractions/messaging.service'; +import { MessagingService } from "../abstractions/messaging.service"; export class NoopMessagingService implements MessagingService { - send(subscriber: string, arg: any = {}) { - // Do nothing... - } + send(subscriber: string, arg: any = {}) { + // Do nothing... + } } diff --git a/common/src/services/search.service.ts b/common/src/services/search.service.ts index 91eb2b6b..97b0d247 100644 --- a/common/src/services/search.service.ts +++ b/common/src/services/search.service.ts @@ -1,272 +1,287 @@ -import * as lunr from 'lunr'; +import * as lunr from "lunr"; -import { CipherView } from '../models/view/cipherView'; +import { CipherView } from "../models/view/cipherView"; -import { CipherService } from '../abstractions/cipher.service'; -import { I18nService } from '../abstractions/i18n.service'; -import { LogService } from '../abstractions/log.service'; -import { SearchService as SearchServiceAbstraction } from '../abstractions/search.service'; +import { CipherService } from "../abstractions/cipher.service"; +import { I18nService } from "../abstractions/i18n.service"; +import { LogService } from "../abstractions/log.service"; +import { SearchService as SearchServiceAbstraction } from "../abstractions/search.service"; -import { CipherType } from '../enums/cipherType'; -import { FieldType } from '../enums/fieldType'; -import { UriMatchType } from '../enums/uriMatchType'; -import { SendView } from '../models/view/sendView'; +import { CipherType } from "../enums/cipherType"; +import { FieldType } from "../enums/fieldType"; +import { UriMatchType } from "../enums/uriMatchType"; +import { SendView } from "../models/view/sendView"; export class SearchService implements SearchServiceAbstraction { - indexedEntityId?: string = null; - private indexing = false; - private index: lunr.Index = null; - private searchableMinLength = 2; + indexedEntityId?: string = null; + private indexing = false; + private index: lunr.Index = null; + private searchableMinLength = 2; - constructor(private cipherService: CipherService, private logService: LogService, - private i18nService: I18nService) { - if (['zh-CN', 'zh-TW'].indexOf(i18nService.locale) !== -1) { - this.searchableMinLength = 1; + constructor( + private cipherService: CipherService, + private logService: LogService, + private i18nService: I18nService + ) { + if (["zh-CN", "zh-TW"].indexOf(i18nService.locale) !== -1) { + this.searchableMinLength = 1; + } + } + + clearIndex(): void { + this.indexedEntityId = null; + this.index = null; + } + + isSearchable(query: string): boolean { + const notSearchable = + query == null || + (this.index == null && query.length < this.searchableMinLength) || + (this.index != null && query.length < this.searchableMinLength && query.indexOf(">") !== 0); + return !notSearchable; + } + + async indexCiphers(indexedEntityId?: string, ciphers?: CipherView[]): Promise { + if (this.indexing) { + return; + } + + this.logService.time("search indexing"); + this.indexing = true; + this.indexedEntityId = indexedEntityId; + this.index = null; + const builder = new lunr.Builder(); + builder.ref("id"); + builder.field("shortid", { boost: 100, extractor: (c: CipherView) => c.id.substr(0, 8) }); + builder.field("name", { boost: 10 }); + builder.field("subtitle", { + boost: 5, + extractor: (c: CipherView) => { + if (c.subTitle != null && c.type === CipherType.Card) { + return c.subTitle.replace(/\*/g, ""); } + return c.subTitle; + }, + }); + builder.field("notes"); + builder.field("login.username", { + extractor: (c: CipherView) => + c.type === CipherType.Login && c.login != null ? c.login.username : null, + }); + builder.field("login.uris", { boost: 2, extractor: (c: CipherView) => this.uriExtractor(c) }); + builder.field("fields", { extractor: (c: CipherView) => this.fieldExtractor(c, false) }); + builder.field("fields_joined", { extractor: (c: CipherView) => this.fieldExtractor(c, true) }); + builder.field("attachments", { + extractor: (c: CipherView) => this.attachmentExtractor(c, false), + }); + builder.field("attachments_joined", { + extractor: (c: CipherView) => this.attachmentExtractor(c, true), + }); + builder.field("organizationid", { extractor: (c: CipherView) => c.organizationId }); + ciphers = ciphers || (await this.cipherService.getAllDecrypted()); + ciphers.forEach((c) => builder.add(c)); + this.index = builder.build(); + + this.indexing = false; + + this.logService.timeEnd("search indexing"); + } + + async searchCiphers( + query: string, + filter: ((cipher: CipherView) => boolean) | ((cipher: CipherView) => boolean)[] = null, + ciphers: CipherView[] = null + ): Promise { + const results: CipherView[] = []; + if (query != null) { + query = query.trim().toLowerCase(); + } + if (query === "") { + query = null; } - clearIndex(): void { - this.indexedEntityId = null; - this.index = null; + if (ciphers == null) { + ciphers = await this.cipherService.getAllDecrypted(); } - isSearchable(query: string): boolean { - const notSearchable = query == null || (this.index == null && query.length < this.searchableMinLength) || - (this.index != null && query.length < this.searchableMinLength && query.indexOf('>') !== 0); - return !notSearchable; + if (filter != null && Array.isArray(filter) && filter.length > 0) { + ciphers = ciphers.filter((c) => filter.every((f) => f == null || f(c))); + } else if (filter != null) { + ciphers = ciphers.filter(filter as (cipher: CipherView) => boolean); } - async indexCiphers(indexedEntityId?: string, ciphers?: CipherView[]): Promise { - if (this.indexing) { - return; - } + if (!this.isSearchable(query)) { + return ciphers; + } - this.logService.time('search indexing'); - this.indexing = true; - this.indexedEntityId = indexedEntityId; - this.index = null; - const builder = new lunr.Builder(); - builder.ref('id'); - builder.field('shortid', { boost: 100, extractor: (c: CipherView) => c.id.substr(0, 8) }); - builder.field('name', { boost: 10 }); - builder.field('subtitle', { - boost: 5, - extractor: (c: CipherView) => { - if (c.subTitle != null && c.type === CipherType.Card) { - return c.subTitle.replace(/\*/g, ''); - } - return c.subTitle; - }, + if (this.indexing) { + await new Promise((r) => setTimeout(r, 250)); + if (this.indexing) { + await new Promise((r) => setTimeout(r, 500)); + } + } + + const index = this.getIndexForSearch(); + if (index == null) { + // Fall back to basic search if index is not available + return this.searchCiphersBasic(ciphers, query); + } + + const ciphersMap = new Map(); + ciphers.forEach((c) => ciphersMap.set(c.id, c)); + + let searchResults: lunr.Index.Result[] = null; + const isQueryString = query != null && query.length > 1 && query.indexOf(">") === 0; + if (isQueryString) { + try { + searchResults = index.search(query.substr(1).trim()); + } catch (e) { + this.logService.error(e); + } + } else { + // tslint:disable-next-line + const soWild = lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING; + searchResults = index.query((q) => { + lunr.tokenizer(query).forEach((token) => { + const t = token.toString(); + q.term(t, { fields: ["name"], wildcard: soWild }); + q.term(t, { fields: ["subtitle"], wildcard: soWild }); + q.term(t, { fields: ["login.uris"], wildcard: soWild }); + q.term(t, {}); }); - builder.field('notes'); - builder.field('login.username', { - extractor: (c: CipherView) => c.type === CipherType.Login && c.login != null ? c.login.username : null, - }); - builder.field('login.uris', { boost: 2, extractor: (c: CipherView) => this.uriExtractor(c) }); - builder.field('fields', { extractor: (c: CipherView) => this.fieldExtractor(c, false) }); - builder.field('fields_joined', { extractor: (c: CipherView) => this.fieldExtractor(c, true) }); - builder.field('attachments', { extractor: (c: CipherView) => this.attachmentExtractor(c, false) }); - builder.field('attachments_joined', - { extractor: (c: CipherView) => this.attachmentExtractor(c, true) }); - builder.field('organizationid', { extractor: (c: CipherView) => c.organizationId }); - ciphers = ciphers || await this.cipherService.getAllDecrypted(); - ciphers.forEach(c => builder.add(c)); - this.index = builder.build(); - - this.indexing = false; - - this.logService.timeEnd('search indexing'); + }); } - async searchCiphers(query: string, - filter: (((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[])) = null, - ciphers: CipherView[] = null): - Promise { - const results: CipherView[] = []; - if (query != null) { - query = query.trim().toLowerCase(); - } - if (query === '') { - query = null; + if (searchResults != null) { + searchResults.forEach((r) => { + if (ciphersMap.has(r.ref)) { + results.push(ciphersMap.get(r.ref)); } + }); + } + return results; + } - if (ciphers == null) { - ciphers = await this.cipherService.getAllDecrypted(); - } + searchCiphersBasic(ciphers: CipherView[], query: string, deleted: boolean = false) { + query = query.trim().toLowerCase(); + return ciphers.filter((c) => { + if (deleted !== c.isDeleted) { + return false; + } + if (c.name != null && c.name.toLowerCase().indexOf(query) > -1) { + return true; + } + if (query.length >= 8 && c.id.startsWith(query)) { + return true; + } + if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(query) > -1) { + return true; + } + if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(query) > -1) { + return true; + } + return false; + }); + } - if (filter != null && Array.isArray(filter) && filter.length > 0) { - ciphers = ciphers.filter(c => filter.every(f => f == null || f(c))); - } else if (filter != null) { - ciphers = ciphers.filter(filter as (cipher: CipherView) => boolean); - } + searchSends(sends: SendView[], query: string) { + query = query.trim().toLocaleLowerCase(); - if (!this.isSearchable(query)) { - return ciphers; - } + return sends.filter((s) => { + if (s.name != null && s.name.toLowerCase().indexOf(query) > -1) { + return true; + } + if ( + query.length >= 8 && + (s.id.startsWith(query) || + s.accessId.toLocaleLowerCase().startsWith(query) || + (s.file?.id != null && s.file.id.startsWith(query))) + ) { + return true; + } + if (s.notes != null && s.notes.toLowerCase().indexOf(query) > -1) { + return true; + } + if (s.text?.text != null && s.text.text.toLowerCase().indexOf(query) > -1) { + return true; + } + if (s.file?.fileName != null && s.file.fileName.toLowerCase().indexOf(query) > -1) { + return true; + } + }); + } - if (this.indexing) { - await new Promise(r => setTimeout(r, 250)); - if (this.indexing) { - await new Promise(r => setTimeout(r, 500)); - } - } + getIndexForSearch(): lunr.Index { + return this.index; + } - const index = this.getIndexForSearch(); - if (index == null) { - // Fall back to basic search if index is not available - return this.searchCiphersBasic(ciphers, query); - } + private fieldExtractor(c: CipherView, joined: boolean) { + if (!c.hasFields) { + return null; + } + let fields: string[] = []; + c.fields.forEach((f) => { + if (f.name != null) { + fields.push(f.name); + } + if (f.type === FieldType.Text && f.value != null) { + fields.push(f.value); + } + }); + fields = fields.filter((f) => f.trim() !== ""); + if (fields.length === 0) { + return null; + } + return joined ? fields.join(" ") : fields; + } - const ciphersMap = new Map(); - ciphers.forEach(c => ciphersMap.set(c.id, c)); - - let searchResults: lunr.Index.Result[] = null; - const isQueryString = query != null && query.length > 1 && query.indexOf('>') === 0; - if (isQueryString) { - try { - searchResults = index.search(query.substr(1).trim()); - } catch (e) { - this.logService.error(e); - } + private attachmentExtractor(c: CipherView, joined: boolean) { + if (!c.hasAttachments) { + return null; + } + let attachments: string[] = []; + c.attachments.forEach((a) => { + if (a != null && a.fileName != null) { + if (joined && a.fileName.indexOf(".") > -1) { + attachments.push(a.fileName.substr(0, a.fileName.lastIndexOf("."))); } else { - // tslint:disable-next-line - const soWild = lunr.Query.wildcard.LEADING | lunr.Query.wildcard.TRAILING; - searchResults = index.query(q => { - lunr.tokenizer(query).forEach(token => { - const t = token.toString(); - q.term(t, { fields: ['name'], wildcard: soWild }); - q.term(t, { fields: ['subtitle'], wildcard: soWild }); - q.term(t, { fields: ['login.uris'], wildcard: soWild }); - q.term(t, {}); - }); - }); + attachments.push(a.fileName); } + } + }); + attachments = attachments.filter((f) => f.trim() !== ""); + if (attachments.length === 0) { + return null; + } + return joined ? attachments.join(" ") : attachments; + } - if (searchResults != null) { - searchResults.forEach(r => { - if (ciphersMap.has(r.ref)) { - results.push(ciphersMap.get(r.ref)); - } - }); + private uriExtractor(c: CipherView) { + if (c.type !== CipherType.Login || c.login == null || !c.login.hasUris) { + return null; + } + const uris: string[] = []; + c.login.uris.forEach((u) => { + if (u.uri == null || u.uri === "") { + return; + } + if (u.hostname != null) { + uris.push(u.hostname); + return; + } + let uri = u.uri; + if (u.match !== UriMatchType.RegularExpression) { + const protocolIndex = uri.indexOf("://"); + if (protocolIndex > -1) { + uri = uri.substr(protocolIndex + 3); } - return results; - } - - searchCiphersBasic(ciphers: CipherView[], query: string, deleted: boolean = false) { - query = query.trim().toLowerCase(); - return ciphers.filter(c => { - if (deleted !== c.isDeleted) { - return false; - } - if (c.name != null && c.name.toLowerCase().indexOf(query) > -1) { - return true; - } - if (query.length >= 8 && c.id.startsWith(query)) { - return true; - } - if (c.subTitle != null && c.subTitle.toLowerCase().indexOf(query) > -1) { - return true; - } - if (c.login && c.login.uri != null && c.login.uri.toLowerCase().indexOf(query) > -1) { - return true; - } - return false; - }); - } - - searchSends(sends: SendView[], query: string) { - query = query.trim().toLocaleLowerCase(); - - return sends.filter(s => { - if (s.name != null && s.name.toLowerCase().indexOf(query) > -1) { - return true; - } - if (query.length >= 8 && (s.id.startsWith(query) || s.accessId.toLocaleLowerCase().startsWith(query) || (s.file?.id != null && s.file.id.startsWith(query)))) { - return true; - } - if (s.notes != null && s.notes.toLowerCase().indexOf(query) > -1) { - return true; - } - if (s.text?.text != null && s.text.text.toLowerCase().indexOf(query) > -1) { - return true; - } - if (s.file?.fileName != null && s.file.fileName.toLowerCase().indexOf(query) > -1) { - return true; - } - }); - } - - getIndexForSearch(): lunr.Index { - return this.index; - } - - private fieldExtractor(c: CipherView, joined: boolean) { - if (!c.hasFields) { - return null; + const queryIndex = uri.search(/\?|&|#/); + if (queryIndex > -1) { + uri = uri.substring(0, queryIndex); } - let fields: string[] = []; - c.fields.forEach(f => { - if (f.name != null) { - fields.push(f.name); - } - if (f.type === FieldType.Text && f.value != null) { - fields.push(f.value); - } - }); - fields = fields.filter(f => f.trim() !== ''); - if (fields.length === 0) { - return null; - } - return joined ? fields.join(' ') : fields; - } - - private attachmentExtractor(c: CipherView, joined: boolean) { - if (!c.hasAttachments) { - return null; - } - let attachments: string[] = []; - c.attachments.forEach(a => { - if (a != null && a.fileName != null) { - if (joined && a.fileName.indexOf('.') > -1) { - attachments.push(a.fileName.substr(0, a.fileName.lastIndexOf('.'))); - } else { - attachments.push(a.fileName); - } - } - }); - attachments = attachments.filter(f => f.trim() !== ''); - if (attachments.length === 0) { - return null; - } - return joined ? attachments.join(' ') : attachments; - } - - private uriExtractor(c: CipherView) { - if (c.type !== CipherType.Login || c.login == null || !c.login.hasUris) { - return null; - } - const uris: string[] = []; - c.login.uris.forEach(u => { - if (u.uri == null || u.uri === '') { - return; - } - if (u.hostname != null) { - uris.push(u.hostname); - return; - } - let uri = u.uri; - if (u.match !== UriMatchType.RegularExpression) { - const protocolIndex = uri.indexOf('://'); - if (protocolIndex > -1) { - uri = uri.substr(protocolIndex + 3); - } - const queryIndex = uri.search(/\?|&|#/); - if (queryIndex > -1) { - uri = uri.substring(0, queryIndex); - } - } - uris.push(uri); - }); - return uris.length > 0 ? uris : null; - } + } + uris.push(uri); + }); + return uris.length > 0 ? uris : null; + } } diff --git a/common/src/services/userVerification.service.ts b/common/src/services/userVerification.service.ts index 2b94ffae..f5189a4d 100644 --- a/common/src/services/userVerification.service.ts +++ b/common/src/services/userVerification.service.ts @@ -1,69 +1,77 @@ -import { UserVerificationService as UserVerificationServiceAbstraction } from '../abstractions/userVerification.service'; +import { UserVerificationService as UserVerificationServiceAbstraction } from "../abstractions/userVerification.service"; -import { ApiService } from '../abstractions/api.service'; -import { CryptoService } from '../abstractions/crypto.service'; -import { I18nService } from '../abstractions/i18n.service'; +import { ApiService } from "../abstractions/api.service"; +import { CryptoService } from "../abstractions/crypto.service"; +import { I18nService } from "../abstractions/i18n.service"; -import { VerificationType } from '../enums/verificationType'; +import { VerificationType } from "../enums/verificationType"; -import { VerifyOTPRequest } from '../models/request/account/verifyOTPRequest'; -import { SecretVerificationRequest } from '../models/request/secretVerificationRequest'; +import { VerifyOTPRequest } from "../models/request/account/verifyOTPRequest"; +import { SecretVerificationRequest } from "../models/request/secretVerificationRequest"; -import { Verification } from '../types/verification'; +import { Verification } from "../types/verification"; export class UserVerificationService implements UserVerificationServiceAbstraction { - constructor(private cryptoService: CryptoService, private i18nService: I18nService, - private apiService: ApiService) { } + constructor( + private cryptoService: CryptoService, + private i18nService: I18nService, + private apiService: ApiService + ) {} - async buildRequest(verification: Verification, - requestClass?: new () => T, alreadyHashed?: boolean) { - this.validateInput(verification); + async buildRequest( + verification: Verification, + requestClass?: new () => T, + alreadyHashed?: boolean + ) { + this.validateInput(verification); - const request = requestClass != null - ? new requestClass() - : new SecretVerificationRequest() as T; + const request = + requestClass != null ? new requestClass() : (new SecretVerificationRequest() as T); - if (verification.type === VerificationType.OTP) { - request.otp = verification.secret; - } else { - request.masterPasswordHash = alreadyHashed - ? verification.secret - : await this.cryptoService.hashPassword(verification.secret, null); - } - - return request; + if (verification.type === VerificationType.OTP) { + request.otp = verification.secret; + } else { + request.masterPasswordHash = alreadyHashed + ? verification.secret + : await this.cryptoService.hashPassword(verification.secret, null); } - async verifyUser(verification: Verification): Promise { - this.validateInput(verification); + return request; + } - if (verification.type === VerificationType.OTP) { - const request = new VerifyOTPRequest(verification.secret); - try { - await this.apiService.postAccountVerifyOTP(request); - } catch (e) { - throw new Error(this.i18nService.t('invalidVerificationCode')); - } - } else { - const passwordValid = await this.cryptoService.compareAndUpdateKeyHash(verification.secret, null); - if (!passwordValid) { - throw new Error(this.i18nService.t('invalidMasterPassword')); - } - } - return true; - } + async verifyUser(verification: Verification): Promise { + this.validateInput(verification); - async requestOTP() { - await this.apiService.postAccountRequestOTP(); + if (verification.type === VerificationType.OTP) { + const request = new VerifyOTPRequest(verification.secret); + try { + await this.apiService.postAccountVerifyOTP(request); + } catch (e) { + throw new Error(this.i18nService.t("invalidVerificationCode")); + } + } else { + const passwordValid = await this.cryptoService.compareAndUpdateKeyHash( + verification.secret, + null + ); + if (!passwordValid) { + throw new Error(this.i18nService.t("invalidMasterPassword")); + } } + return true; + } - private validateInput(verification: Verification) { - if (verification?.secret == null || verification.secret === '') { - if (verification.type === VerificationType.OTP) { - throw new Error(this.i18nService.t('verificationCodeRequired')); - } else { - throw new Error(this.i18nService.t('masterPassRequired')); - } - } + async requestOTP() { + await this.apiService.postAccountRequestOTP(); + } + + private validateInput(verification: Verification) { + if (verification?.secret == null || verification.secret === "") { + if (verification.type === VerificationType.OTP) { + throw new Error(this.i18nService.t("verificationCodeRequired")); + } else { + throw new Error(this.i18nService.t("masterPassRequired")); + } } + } } diff --git a/common/src/services/webCryptoFunction.service.ts b/common/src/services/webCryptoFunction.service.ts index 2cabb96d..8f7a8019 100644 --- a/common/src/services/webCryptoFunction.service.ts +++ b/common/src/services/webCryptoFunction.service.ts @@ -1,332 +1,389 @@ -import * as forge from 'node-forge'; +import * as forge from "node-forge"; -import { CryptoFunctionService } from '../abstractions/cryptoFunction.service'; -import { PlatformUtilsService } from '../abstractions/platformUtils.service'; +import { CryptoFunctionService } from "../abstractions/cryptoFunction.service"; +import { PlatformUtilsService } from "../abstractions/platformUtils.service"; -import { Utils } from '../misc/utils'; +import { Utils } from "../misc/utils"; -import { DecryptParameters } from '../models/domain/decryptParameters'; -import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey'; +import { DecryptParameters } from "../models/domain/decryptParameters"; +import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey"; export class WebCryptoFunctionService implements CryptoFunctionService { - private crypto: Crypto; - private subtle: SubtleCrypto; - private isIE: boolean; - private isOldSafari: boolean; + private crypto: Crypto; + private subtle: SubtleCrypto; + private isIE: boolean; + private isOldSafari: boolean; - constructor(private win: Window, private platformUtilsService: PlatformUtilsService) { - this.crypto = typeof win.crypto !== 'undefined' ? win.crypto : null; - this.subtle = (!!this.crypto && typeof win.crypto.subtle !== 'undefined') ? win.crypto.subtle : null; - this.isIE = platformUtilsService.isIE(); - const ua = win.navigator.userAgent; - this.isOldSafari = platformUtilsService.isSafari() && - (ua.indexOf(' Version/10.') > -1 || ua.indexOf(' Version/9.') > -1); + constructor(private win: Window, private platformUtilsService: PlatformUtilsService) { + this.crypto = typeof win.crypto !== "undefined" ? win.crypto : null; + this.subtle = + !!this.crypto && typeof win.crypto.subtle !== "undefined" ? win.crypto.subtle : null; + this.isIE = platformUtilsService.isIE(); + const ua = win.navigator.userAgent; + this.isOldSafari = + platformUtilsService.isSafari() && + (ua.indexOf(" Version/10.") > -1 || ua.indexOf(" Version/9.") > -1); + } + + async pbkdf2( + password: string | ArrayBuffer, + salt: string | ArrayBuffer, + algorithm: "sha256" | "sha512", + iterations: number + ): Promise { + if (this.isIE || this.isOldSafari) { + const forgeLen = algorithm === "sha256" ? 32 : 64; + const passwordBytes = this.toByteString(password); + const saltBytes = this.toByteString(salt); + const derivedKeyBytes = (forge as any).pbkdf2( + passwordBytes, + saltBytes, + iterations, + forgeLen, + algorithm + ); + return Utils.fromByteStringToArray(derivedKeyBytes).buffer; } - async pbkdf2(password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512', - iterations: number): Promise { - if (this.isIE || this.isOldSafari) { - const forgeLen = algorithm === 'sha256' ? 32 : 64; - const passwordBytes = this.toByteString(password); - const saltBytes = this.toByteString(salt); - const derivedKeyBytes = (forge as any).pbkdf2(passwordBytes, saltBytes, iterations, forgeLen, algorithm); - return Utils.fromByteStringToArray(derivedKeyBytes).buffer; - } + const wcLen = algorithm === "sha256" ? 256 : 512; + const passwordBuf = this.toBuf(password); + const saltBuf = this.toBuf(salt); - const wcLen = algorithm === 'sha256' ? 256 : 512; - const passwordBuf = this.toBuf(password); - const saltBuf = this.toBuf(salt); + const pbkdf2Params: Pbkdf2Params = { + name: "PBKDF2", + salt: saltBuf, + iterations: iterations, + hash: { name: this.toWebCryptoAlgorithm(algorithm) }, + }; - const pbkdf2Params: Pbkdf2Params = { - name: 'PBKDF2', - salt: saltBuf, - iterations: iterations, - hash: { name: this.toWebCryptoAlgorithm(algorithm) }, - }; + const impKey = await this.subtle.importKey( + "raw", + passwordBuf, + { name: "PBKDF2" } as any, + false, + ["deriveBits"] + ); + return await this.subtle.deriveBits(pbkdf2Params, impKey, wcLen); + } - const impKey = await this.subtle.importKey('raw', passwordBuf, { name: 'PBKDF2' } as any, - false, ['deriveBits']); - return await this.subtle.deriveBits(pbkdf2Params, impKey, wcLen); + async hkdf( + ikm: ArrayBuffer, + salt: string | ArrayBuffer, + info: string | ArrayBuffer, + outputByteSize: number, + algorithm: "sha256" | "sha512" + ): Promise { + const saltBuf = this.toBuf(salt); + const infoBuf = this.toBuf(info); + + const hkdfParams: HkdfParams = { + name: "HKDF", + salt: saltBuf, + info: infoBuf, + hash: { name: this.toWebCryptoAlgorithm(algorithm) }, + }; + + const impKey = await this.subtle.importKey("raw", ikm, { name: "HKDF" } as any, false, [ + "deriveBits", + ]); + return await this.subtle.deriveBits(hkdfParams as any, impKey, outputByteSize * 8); + } + + // ref: https://tools.ietf.org/html/rfc5869 + async hkdfExpand( + prk: ArrayBuffer, + info: string | ArrayBuffer, + outputByteSize: number, + algorithm: "sha256" | "sha512" + ): Promise { + const hashLen = algorithm === "sha256" ? 32 : 64; + if (outputByteSize > 255 * hashLen) { + throw new Error("outputByteSize is too large."); + } + const prkArr = new Uint8Array(prk); + if (prkArr.length < hashLen) { + throw new Error("prk is too small."); + } + const infoBuf = this.toBuf(info); + const infoArr = new Uint8Array(infoBuf); + let runningOkmLength = 0; + let previousT = new Uint8Array(0); + const n = Math.ceil(outputByteSize / hashLen); + const okm = new Uint8Array(n * hashLen); + for (let i = 0; i < n; i++) { + const t = new Uint8Array(previousT.length + infoArr.length + 1); + t.set(previousT); + t.set(infoArr, previousT.length); + t.set([i + 1], t.length - 1); + previousT = new Uint8Array(await this.hmac(t.buffer, prk, algorithm)); + okm.set(previousT, runningOkmLength); + runningOkmLength += previousT.length; + if (runningOkmLength >= outputByteSize) { + break; + } + } + return okm.slice(0, outputByteSize).buffer; + } + + async hash( + value: string | ArrayBuffer, + algorithm: "sha1" | "sha256" | "sha512" | "md5" + ): Promise { + if ((this.isIE && algorithm === "sha1") || algorithm === "md5") { + const md = algorithm === "md5" ? forge.md.md5.create() : forge.md.sha1.create(); + const valueBytes = this.toByteString(value); + md.update(valueBytes, "raw"); + return Utils.fromByteStringToArray(md.digest().data).buffer; } - async hkdf(ikm: ArrayBuffer, salt: string | ArrayBuffer, info: string | ArrayBuffer, - outputByteSize: number, algorithm: 'sha256' | 'sha512'): Promise { - const saltBuf = this.toBuf(salt); - const infoBuf = this.toBuf(info); + const valueBuf = this.toBuf(value); + return await this.subtle.digest({ name: this.toWebCryptoAlgorithm(algorithm) }, valueBuf); + } - const hkdfParams: HkdfParams = { - name: 'HKDF', - salt: saltBuf, - info: infoBuf, - hash: { name: this.toWebCryptoAlgorithm(algorithm) }, - }; - - const impKey = await this.subtle.importKey('raw', ikm, { name: 'HKDF' } as any, - false, ['deriveBits']); - return await this.subtle.deriveBits(hkdfParams as any, impKey, outputByteSize * 8); + async hmac( + value: ArrayBuffer, + key: ArrayBuffer, + algorithm: "sha1" | "sha256" | "sha512" + ): Promise { + if (this.isIE && algorithm === "sha512") { + const hmac = (forge as any).hmac.create(); + const keyBytes = this.toByteString(key); + const valueBytes = this.toByteString(value); + hmac.start(algorithm, keyBytes); + hmac.update(valueBytes, "raw"); + return Utils.fromByteStringToArray(hmac.digest().data).buffer; } - // ref: https://tools.ietf.org/html/rfc5869 - async hkdfExpand(prk: ArrayBuffer, info: string | ArrayBuffer, outputByteSize: number, - algorithm: 'sha256' | 'sha512'): Promise { - const hashLen = algorithm === 'sha256' ? 32 : 64; - if (outputByteSize > 255 * hashLen) { - throw new Error('outputByteSize is too large.'); - } - const prkArr = new Uint8Array(prk); - if (prkArr.length < hashLen) { - throw new Error('prk is too small.'); - } - const infoBuf = this.toBuf(info); - const infoArr = new Uint8Array(infoBuf); - let runningOkmLength = 0; - let previousT = new Uint8Array(0); - const n = Math.ceil(outputByteSize / hashLen); - const okm = new Uint8Array(n * hashLen); - for (let i = 0; i < n; i++) { - const t = new Uint8Array(previousT.length + infoArr.length + 1); - t.set(previousT); - t.set(infoArr, previousT.length); - t.set([i + 1], t.length - 1); - previousT = new Uint8Array(await this.hmac(t.buffer, prk, algorithm)); - okm.set(previousT, runningOkmLength); - runningOkmLength += previousT.length; - if (runningOkmLength >= outputByteSize) { - break; - } - } - return okm.slice(0, outputByteSize).buffer; + const signingAlgorithm = { + name: "HMAC", + hash: { name: this.toWebCryptoAlgorithm(algorithm) }, + }; + + const impKey = await this.subtle.importKey("raw", key, signingAlgorithm, false, ["sign"]); + return await this.subtle.sign(signingAlgorithm, impKey, value); + } + + // Safely compare two values in a way that protects against timing attacks (Double HMAC Verification). + // ref: https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/ + // ref: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy + async compare(a: ArrayBuffer, b: ArrayBuffer): Promise { + const macKey = await this.randomBytes(32); + const signingAlgorithm = { + name: "HMAC", + hash: { name: "SHA-256" }, + }; + const impKey = await this.subtle.importKey("raw", macKey, signingAlgorithm, false, ["sign"]); + const mac1 = await this.subtle.sign(signingAlgorithm, impKey, a); + const mac2 = await this.subtle.sign(signingAlgorithm, impKey, b); + + if (mac1.byteLength !== mac2.byteLength) { + return false; } - async hash(value: string | ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512' | 'md5'): Promise { - if ((this.isIE && algorithm === 'sha1') || algorithm === 'md5') { - const md = algorithm === 'md5' ? forge.md.md5.create() : forge.md.sha1.create(); - const valueBytes = this.toByteString(value); - md.update(valueBytes, 'raw'); - return Utils.fromByteStringToArray(md.digest().data).buffer; - } - - const valueBuf = this.toBuf(value); - return await this.subtle.digest({ name: this.toWebCryptoAlgorithm(algorithm) }, valueBuf); + const arr1 = new Uint8Array(mac1); + const arr2 = new Uint8Array(mac2); + for (let i = 0; i < arr2.length; i++) { + if (arr1[i] !== arr2[i]) { + return false; + } } - async hmac(value: ArrayBuffer, key: ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512'): Promise { - if (this.isIE && algorithm === 'sha512') { - const hmac = (forge as any).hmac.create(); - const keyBytes = this.toByteString(key); - const valueBytes = this.toByteString(value); - hmac.start(algorithm, keyBytes); - hmac.update(valueBytes, 'raw'); - return Utils.fromByteStringToArray(hmac.digest().data).buffer; - } + return true; + } - const signingAlgorithm = { - name: 'HMAC', - hash: { name: this.toWebCryptoAlgorithm(algorithm) }, - }; + hmacFast(value: string, key: string, algorithm: "sha1" | "sha256" | "sha512"): Promise { + const hmac = (forge as any).hmac.create(); + hmac.start(algorithm, key); + hmac.update(value); + const bytes = hmac.digest().getBytes(); + return Promise.resolve(bytes); + } - const impKey = await this.subtle.importKey('raw', key, signingAlgorithm, false, ['sign']); - return await this.subtle.sign(signingAlgorithm, impKey, value); + async compareFast(a: string, b: string): Promise { + const rand = await this.randomBytes(32); + const bytes = new Uint32Array(rand); + const buffer = forge.util.createBuffer(); + for (let i = 0; i < bytes.length; i++) { + buffer.putInt32(bytes[i]); + } + const macKey = buffer.getBytes(); + + const hmac = (forge as any).hmac.create(); + hmac.start("sha256", macKey); + hmac.update(a); + const mac1 = hmac.digest().getBytes(); + + hmac.start(null, null); + hmac.update(b); + const mac2 = hmac.digest().getBytes(); + + const equals = mac1 === mac2; + return equals; + } + + async aesEncrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { + const impKey = await this.subtle.importKey("raw", key, { name: "AES-CBC" } as any, false, [ + "encrypt", + ]); + return await this.subtle.encrypt({ name: "AES-CBC", iv: iv }, impKey, data); + } + + aesDecryptFastParameters( + data: string, + iv: string, + mac: string, + key: SymmetricCryptoKey + ): DecryptParameters { + const p = new DecryptParameters(); + if (key.meta != null) { + p.encKey = key.meta.encKeyByteString; + p.macKey = key.meta.macKeyByteString; } - // Safely compare two values in a way that protects against timing attacks (Double HMAC Verification). - // ref: https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/ - // ref: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy - async compare(a: ArrayBuffer, b: ArrayBuffer): Promise { - const macKey = await this.randomBytes(32); - const signingAlgorithm = { - name: 'HMAC', - hash: { name: 'SHA-256' }, - }; - const impKey = await this.subtle.importKey('raw', macKey, signingAlgorithm, false, ['sign']); - const mac1 = await this.subtle.sign(signingAlgorithm, impKey, a); - const mac2 = await this.subtle.sign(signingAlgorithm, impKey, b); - - if (mac1.byteLength !== mac2.byteLength) { - return false; - } - - const arr1 = new Uint8Array(mac1); - const arr2 = new Uint8Array(mac2); - for (let i = 0; i < arr2.length; i++) { - if (arr1[i] !== arr2[i]) { - return false; - } - } - - return true; + if (p.encKey == null) { + p.encKey = forge.util.decode64(key.encKeyB64); + } + p.data = forge.util.decode64(data); + p.iv = forge.util.decode64(iv); + p.macData = p.iv + p.data; + if (p.macKey == null && key.macKeyB64 != null) { + p.macKey = forge.util.decode64(key.macKeyB64); + } + if (mac != null) { + p.mac = forge.util.decode64(mac); } - hmacFast(value: string, key: string, algorithm: 'sha1' | 'sha256' | 'sha512'): Promise { - const hmac = (forge as any).hmac.create(); - hmac.start(algorithm, key); - hmac.update(value); - const bytes = hmac.digest().getBytes(); - return Promise.resolve(bytes); + // cache byte string keys for later + if (key.meta == null) { + key.meta = {}; + } + if (key.meta.encKeyByteString == null) { + key.meta.encKeyByteString = p.encKey; + } + if (p.macKey != null && key.meta.macKeyByteString == null) { + key.meta.macKeyByteString = p.macKey; } - async compareFast(a: string, b: string): Promise { - const rand = await this.randomBytes(32); - const bytes = new Uint32Array(rand); - const buffer = forge.util.createBuffer(); - for (let i = 0; i < bytes.length; i++) { - buffer.putInt32(bytes[i]); - } - const macKey = buffer.getBytes(); + return p; + } - const hmac = (forge as any).hmac.create(); - hmac.start('sha256', macKey); - hmac.update(a); - const mac1 = hmac.digest().getBytes(); + aesDecryptFast(parameters: DecryptParameters): Promise { + const dataBuffer = (forge as any).util.createBuffer(parameters.data); + const decipher = (forge as any).cipher.createDecipher("AES-CBC", parameters.encKey); + decipher.start({ iv: parameters.iv }); + decipher.update(dataBuffer); + decipher.finish(); + const val = decipher.output.toString("utf8"); + return Promise.resolve(val); + } - hmac.start(null, null); - hmac.update(b); - const mac2 = hmac.digest().getBytes(); + async aesDecrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { + const impKey = await this.subtle.importKey("raw", key, { name: "AES-CBC" } as any, false, [ + "decrypt", + ]); + return await this.subtle.decrypt({ name: "AES-CBC", iv: iv }, impKey, data); + } - const equals = mac1 === mac2; - return equals; + async rsaEncrypt( + data: ArrayBuffer, + publicKey: ArrayBuffer, + algorithm: "sha1" | "sha256" + ): Promise { + // Note: Edge browser requires that we specify name and hash for both key import and decrypt. + // We cannot use the proper types here. + const rsaParams = { + name: "RSA-OAEP", + hash: { name: this.toWebCryptoAlgorithm(algorithm) }, + }; + const impKey = await this.subtle.importKey("spki", publicKey, rsaParams, false, ["encrypt"]); + return await this.subtle.encrypt(rsaParams, impKey, data); + } + + async rsaDecrypt( + data: ArrayBuffer, + privateKey: ArrayBuffer, + algorithm: "sha1" | "sha256" + ): Promise { + // Note: Edge browser requires that we specify name and hash for both key import and decrypt. + // We cannot use the proper types here. + const rsaParams = { + name: "RSA-OAEP", + hash: { name: this.toWebCryptoAlgorithm(algorithm) }, + }; + const impKey = await this.subtle.importKey("pkcs8", privateKey, rsaParams, false, ["decrypt"]); + return await this.subtle.decrypt(rsaParams, impKey, data); + } + + async rsaExtractPublicKey(privateKey: ArrayBuffer): Promise { + const rsaParams = { + name: "RSA-OAEP", + // Have to specify some algorithm + hash: { name: this.toWebCryptoAlgorithm("sha1") }, + }; + const impPrivateKey = await this.subtle.importKey("pkcs8", privateKey, rsaParams, true, [ + "decrypt", + ]); + const jwkPrivateKey = await this.subtle.exportKey("jwk", impPrivateKey); + const jwkPublicKeyParams = { + kty: "RSA", + e: jwkPrivateKey.e, + n: jwkPrivateKey.n, + alg: "RSA-OAEP", + ext: true, + }; + const impPublicKey = await this.subtle.importKey("jwk", jwkPublicKeyParams, rsaParams, true, [ + "encrypt", + ]); + return await this.subtle.exportKey("spki", impPublicKey); + } + + async rsaGenerateKeyPair(length: 1024 | 2048 | 4096): Promise<[ArrayBuffer, ArrayBuffer]> { + const rsaParams = { + name: "RSA-OAEP", + modulusLength: length, + publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // 65537 + // Have to specify some algorithm + hash: { name: this.toWebCryptoAlgorithm("sha1") }, + }; + const keyPair = (await this.subtle.generateKey(rsaParams, true, [ + "encrypt", + "decrypt", + ])) as CryptoKeyPair; + const publicKey = await this.subtle.exportKey("spki", keyPair.publicKey); + const privateKey = await this.subtle.exportKey("pkcs8", keyPair.privateKey); + return [publicKey, privateKey]; + } + + randomBytes(length: number): Promise { + const arr = new Uint8Array(length); + this.crypto.getRandomValues(arr); + return Promise.resolve(arr.buffer); + } + + private toBuf(value: string | ArrayBuffer): ArrayBuffer { + let buf: ArrayBuffer; + if (typeof value === "string") { + buf = Utils.fromUtf8ToArray(value).buffer; + } else { + buf = value; } + return buf; + } - async aesEncrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { - const impKey = await this.subtle.importKey('raw', key, { name: 'AES-CBC' } as any, false, ['encrypt']); - return await this.subtle.encrypt({ name: 'AES-CBC', iv: iv }, impKey, data); + private toByteString(value: string | ArrayBuffer): string { + let bytes: string; + if (typeof value === "string") { + bytes = forge.util.encodeUtf8(value); + } else { + bytes = Utils.fromBufferToByteString(value); } + return bytes; + } - aesDecryptFastParameters(data: string, iv: string, mac: string, key: SymmetricCryptoKey): - DecryptParameters { - const p = new DecryptParameters(); - if (key.meta != null) { - p.encKey = key.meta.encKeyByteString; - p.macKey = key.meta.macKeyByteString; - } - - if (p.encKey == null) { - p.encKey = forge.util.decode64(key.encKeyB64); - } - p.data = forge.util.decode64(data); - p.iv = forge.util.decode64(iv); - p.macData = p.iv + p.data; - if (p.macKey == null && key.macKeyB64 != null) { - p.macKey = forge.util.decode64(key.macKeyB64); - } - if (mac != null) { - p.mac = forge.util.decode64(mac); - } - - // cache byte string keys for later - if (key.meta == null) { - key.meta = {}; - } - if (key.meta.encKeyByteString == null) { - key.meta.encKeyByteString = p.encKey; - } - if (p.macKey != null && key.meta.macKeyByteString == null) { - key.meta.macKeyByteString = p.macKey; - } - - return p; - } - - aesDecryptFast(parameters: DecryptParameters): Promise { - const dataBuffer = (forge as any).util.createBuffer(parameters.data); - const decipher = (forge as any).cipher.createDecipher('AES-CBC', parameters.encKey); - decipher.start({ iv: parameters.iv }); - decipher.update(dataBuffer); - decipher.finish(); - const val = decipher.output.toString('utf8'); - return Promise.resolve(val); - } - - async aesDecrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { - const impKey = await this.subtle.importKey('raw', key, { name: 'AES-CBC' } as any, false, ['decrypt']); - return await this.subtle.decrypt({ name: 'AES-CBC', iv: iv }, impKey, data); - } - - async rsaEncrypt(data: ArrayBuffer, publicKey: ArrayBuffer, algorithm: 'sha1' | 'sha256'): Promise { - // Note: Edge browser requires that we specify name and hash for both key import and decrypt. - // We cannot use the proper types here. - const rsaParams = { - name: 'RSA-OAEP', - hash: { name: this.toWebCryptoAlgorithm(algorithm) }, - }; - const impKey = await this.subtle.importKey('spki', publicKey, rsaParams, false, ['encrypt']); - return await this.subtle.encrypt(rsaParams, impKey, data); - } - - async rsaDecrypt(data: ArrayBuffer, privateKey: ArrayBuffer, algorithm: 'sha1' | 'sha256'): Promise { - // Note: Edge browser requires that we specify name and hash for both key import and decrypt. - // We cannot use the proper types here. - const rsaParams = { - name: 'RSA-OAEP', - hash: { name: this.toWebCryptoAlgorithm(algorithm) }, - }; - const impKey = await this.subtle.importKey('pkcs8', privateKey, rsaParams, false, ['decrypt']); - return await this.subtle.decrypt(rsaParams, impKey, data); - } - - async rsaExtractPublicKey(privateKey: ArrayBuffer): Promise { - const rsaParams = { - name: 'RSA-OAEP', - // Have to specify some algorithm - hash: { name: this.toWebCryptoAlgorithm('sha1') }, - }; - const impPrivateKey = await this.subtle.importKey('pkcs8', privateKey, rsaParams, true, ['decrypt']); - const jwkPrivateKey = await this.subtle.exportKey('jwk', impPrivateKey); - const jwkPublicKeyParams = { - kty: 'RSA', - e: jwkPrivateKey.e, - n: jwkPrivateKey.n, - alg: 'RSA-OAEP', - ext: true, - }; - const impPublicKey = await this.subtle.importKey('jwk', jwkPublicKeyParams, rsaParams, true, ['encrypt']); - return await this.subtle.exportKey('spki', impPublicKey); - } - - async rsaGenerateKeyPair(length: 1024 | 2048 | 4096): Promise<[ArrayBuffer, ArrayBuffer]> { - const rsaParams = { - name: 'RSA-OAEP', - modulusLength: length, - publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // 65537 - // Have to specify some algorithm - hash: { name: this.toWebCryptoAlgorithm('sha1') }, - }; - const keyPair = (await this.subtle.generateKey(rsaParams, true, ['encrypt', 'decrypt'])) as CryptoKeyPair; - const publicKey = await this.subtle.exportKey('spki', keyPair.publicKey); - const privateKey = await this.subtle.exportKey('pkcs8', keyPair.privateKey); - return [publicKey, privateKey]; - } - - randomBytes(length: number): Promise { - const arr = new Uint8Array(length); - this.crypto.getRandomValues(arr); - return Promise.resolve(arr.buffer); - } - - private toBuf(value: string | ArrayBuffer): ArrayBuffer { - let buf: ArrayBuffer; - if (typeof (value) === 'string') { - buf = Utils.fromUtf8ToArray(value).buffer; - } else { - buf = value; - } - return buf; - } - - private toByteString(value: string | ArrayBuffer): string { - let bytes: string; - if (typeof (value) === 'string') { - bytes = forge.util.encodeUtf8(value); - } else { - bytes = Utils.fromBufferToByteString(value); - } - return bytes; - } - - private toWebCryptoAlgorithm(algorithm: 'sha1' | 'sha256' | 'sha512' | 'md5'): string { - if (algorithm === 'md5') { - throw new Error('MD5 is not supported in WebCrypto.'); - } - return algorithm === 'sha1' ? 'SHA-1' : algorithm === 'sha256' ? 'SHA-256' : 'SHA-512'; + private toWebCryptoAlgorithm(algorithm: "sha1" | "sha256" | "sha512" | "md5"): string { + if (algorithm === "md5") { + throw new Error("MD5 is not supported in WebCrypto."); } + return algorithm === "sha1" ? "SHA-1" : algorithm === "sha256" ? "SHA-256" : "SHA-512"; + } } diff --git a/common/src/types/verification.ts b/common/src/types/verification.ts index 72ee8b0a..07ca4bbf 100644 --- a/common/src/types/verification.ts +++ b/common/src/types/verification.ts @@ -1,6 +1,6 @@ -import { VerificationType } from '../enums/verificationType'; +import { VerificationType } from "../enums/verificationType"; export type Verification = { - type: VerificationType, - secret: string, + type: VerificationType; + secret: string; }; diff --git a/common/tsconfig.json b/common/tsconfig.json index 96033322..3366a0dd 100644 --- a/common/tsconfig.json +++ b/common/tsconfig.json @@ -13,16 +13,8 @@ "emitDecoratorMetadata": true, "declarationDir": "dist/types", "outDir": "dist", - "typeRoots": [ - "node_modules/@types" - ] + "typeRoots": ["node_modules/@types"] }, - "include": [ - "src", - "spec" - ], - "exclude": [ - "node_modules", - "dist" - ] + "include": ["src", "spec"], + "exclude": ["node_modules", "dist"] } diff --git a/electron/src/baseMenu.ts b/electron/src/baseMenu.ts index 7a2c66bf..f52db2a5 100644 --- a/electron/src/baseMenu.ts +++ b/electron/src/baseMenu.ts @@ -1,229 +1,224 @@ -import { - app, - clipboard, - dialog, - Menu, - MenuItemConstructorOptions, -} from 'electron'; +import { app, clipboard, dialog, Menu, MenuItemConstructorOptions } from "electron"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { WindowMain } from './window.main'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { WindowMain } from "./window.main"; export class BaseMenu { - protected editMenuItemOptions: MenuItemConstructorOptions; - protected viewSubMenuItemOptions: MenuItemConstructorOptions[]; - protected windowMenuItemOptions: MenuItemConstructorOptions; - protected macAppMenuItemOptions: MenuItemConstructorOptions[]; - protected macWindowSubmenuOptions: MenuItemConstructorOptions[]; + protected editMenuItemOptions: MenuItemConstructorOptions; + protected viewSubMenuItemOptions: MenuItemConstructorOptions[]; + protected windowMenuItemOptions: MenuItemConstructorOptions; + protected macAppMenuItemOptions: MenuItemConstructorOptions[]; + protected macWindowSubmenuOptions: MenuItemConstructorOptions[]; - constructor(protected i18nService: I18nService, protected windowMain: WindowMain) { } + constructor(protected i18nService: I18nService, protected windowMain: WindowMain) {} - protected initProperties() { - this.editMenuItemOptions = { - label: this.i18nService.t('edit'), - submenu: [ - { - label: this.i18nService.t('undo'), - role: 'undo', - }, - { - label: this.i18nService.t('redo'), - role: 'redo', - }, - { type: 'separator' }, - { - label: this.i18nService.t('cut'), - role: 'cut', - }, - { - label: this.i18nService.t('copy'), - role: 'copy', - }, - { - label: this.i18nService.t('paste'), - role: 'paste', - }, - { type: 'separator' }, - { - label: this.i18nService.t('selectAll'), - role: 'selectAll', - }, - ], - }; + protected initProperties() { + this.editMenuItemOptions = { + label: this.i18nService.t("edit"), + submenu: [ + { + label: this.i18nService.t("undo"), + role: "undo", + }, + { + label: this.i18nService.t("redo"), + role: "redo", + }, + { type: "separator" }, + { + label: this.i18nService.t("cut"), + role: "cut", + }, + { + label: this.i18nService.t("copy"), + role: "copy", + }, + { + label: this.i18nService.t("paste"), + role: "paste", + }, + { type: "separator" }, + { + label: this.i18nService.t("selectAll"), + role: "selectAll", + }, + ], + }; - this.viewSubMenuItemOptions = [ - { - label: this.i18nService.t('zoomIn'), - role: 'zoomIn', - accelerator: 'CmdOrCtrl+=', - }, - { - label: this.i18nService.t('zoomOut'), - role: 'zoomOut', - accelerator: 'CmdOrCtrl+-', - }, - { - label: this.i18nService.t('resetZoom'), - role: 'resetZoom', - accelerator: 'CmdOrCtrl+0', - }, - { type: 'separator' }, - { - label: this.i18nService.t('toggleFullScreen'), - role: 'togglefullscreen', - }, - { type: 'separator' }, - { - label: this.i18nService.t('reload'), - role: 'forceReload', - }, - { - label: this.i18nService.t('toggleDevTools'), - role: 'toggleDevTools', - accelerator: 'F12', - }, - ]; + this.viewSubMenuItemOptions = [ + { + label: this.i18nService.t("zoomIn"), + role: "zoomIn", + accelerator: "CmdOrCtrl+=", + }, + { + label: this.i18nService.t("zoomOut"), + role: "zoomOut", + accelerator: "CmdOrCtrl+-", + }, + { + label: this.i18nService.t("resetZoom"), + role: "resetZoom", + accelerator: "CmdOrCtrl+0", + }, + { type: "separator" }, + { + label: this.i18nService.t("toggleFullScreen"), + role: "togglefullscreen", + }, + { type: "separator" }, + { + label: this.i18nService.t("reload"), + role: "forceReload", + }, + { + label: this.i18nService.t("toggleDevTools"), + role: "toggleDevTools", + accelerator: "F12", + }, + ]; - this.windowMenuItemOptions = { - label: this.i18nService.t('window'), - role: 'window', - submenu: [ - { - label: this.i18nService.t('minimize'), - role: 'minimize', - }, - { - label: this.i18nService.t('close'), - role: 'close', - }, - ], - }; + this.windowMenuItemOptions = { + label: this.i18nService.t("window"), + role: "window", + submenu: [ + { + label: this.i18nService.t("minimize"), + role: "minimize", + }, + { + label: this.i18nService.t("close"), + role: "close", + }, + ], + }; - if (process.platform === 'darwin') { - this.macAppMenuItemOptions = [ - { - label: this.i18nService.t('services'), - role: 'services', submenu: [], - }, - { type: 'separator' }, - { - label: this.i18nService.t('hideBitwarden'), - role: 'hide', - }, - { - label: this.i18nService.t('hideOthers'), - role: 'hideOthers', - }, - { - label: this.i18nService.t('showAll'), - role: 'unhide', - }, - { type: 'separator' }, - { - label: this.i18nService.t('quitBitwarden'), - role: 'quit', - }, - ]; + if (process.platform === "darwin") { + this.macAppMenuItemOptions = [ + { + label: this.i18nService.t("services"), + role: "services", + submenu: [], + }, + { type: "separator" }, + { + label: this.i18nService.t("hideBitwarden"), + role: "hide", + }, + { + label: this.i18nService.t("hideOthers"), + role: "hideOthers", + }, + { + label: this.i18nService.t("showAll"), + role: "unhide", + }, + { type: "separator" }, + { + label: this.i18nService.t("quitBitwarden"), + role: "quit", + }, + ]; - this.macWindowSubmenuOptions = [ - { - label: this.i18nService.t('minimize'), - role: 'minimize', - }, - { - label: this.i18nService.t('zoom'), - role: 'zoom', - }, - { type: 'separator' }, - { - label: this.i18nService.t('bringAllToFront'), - role: 'front', - }, - { - label: this.i18nService.t('close'), - role: 'close', - }, - ]; - } + this.macWindowSubmenuOptions = [ + { + label: this.i18nService.t("minimize"), + role: "minimize", + }, + { + label: this.i18nService.t("zoom"), + role: "zoom", + }, + { type: "separator" }, + { + label: this.i18nService.t("bringAllToFront"), + role: "front", + }, + { + label: this.i18nService.t("close"), + role: "close", + }, + ]; + } + } + + protected initContextMenu() { + if (this.windowMain.win == null) { + return; } - protected initContextMenu() { - if (this.windowMain.win == null) { - return; - } + const selectionMenu = Menu.buildFromTemplate([ + { + label: this.i18nService.t("copy"), + role: "copy", + }, + { type: "separator" }, + { + label: this.i18nService.t("selectAll"), + role: "selectAll", + }, + ]); - const selectionMenu = Menu.buildFromTemplate([ - { - label: this.i18nService.t('copy'), - role: 'copy', - }, - { type: 'separator' }, - { - label: this.i18nService.t('selectAll'), - role: 'selectAll', - }, - ]); + const inputMenu = Menu.buildFromTemplate([ + { + label: this.i18nService.t("undo"), + role: "undo", + }, + { + label: this.i18nService.t("redo"), + role: "redo", + }, + { type: "separator" }, + { + label: this.i18nService.t("cut"), + role: "cut", + enabled: false, + }, + { + label: this.i18nService.t("copy"), + role: "copy", + enabled: false, + }, + { + label: this.i18nService.t("paste"), + role: "paste", + }, + { type: "separator" }, + { + label: this.i18nService.t("selectAll"), + role: "selectAll", + }, + ]); - const inputMenu = Menu.buildFromTemplate([ - { - label: this.i18nService.t('undo'), - role: 'undo', - }, - { - label: this.i18nService.t('redo'), - role: 'redo', - }, - { type: 'separator' }, - { - label: this.i18nService.t('cut'), - role: 'cut', - enabled: false, - }, - { - label: this.i18nService.t('copy'), - role: 'copy', - enabled: false, - }, - { - label: this.i18nService.t('paste'), - role: 'paste', - }, - { type: 'separator' }, - { - label: this.i18nService.t('selectAll'), - role: 'selectAll', - }, - ]); + const inputSelectionMenu = Menu.buildFromTemplate([ + { + label: this.i18nService.t("cut"), + role: "cut", + }, + { + label: this.i18nService.t("copy"), + role: "copy", + }, + { + label: this.i18nService.t("paste"), + role: "paste", + }, + { type: "separator" }, + { + label: this.i18nService.t("selectAll"), + role: "selectAll", + }, + ]); - const inputSelectionMenu = Menu.buildFromTemplate([ - { - label: this.i18nService.t('cut'), - role: 'cut', - }, - { - label: this.i18nService.t('copy'), - role: 'copy', - }, - { - label: this.i18nService.t('paste'), - role: 'paste', - }, - { type: 'separator' }, - { - label: this.i18nService.t('selectAll'), - role: 'selectAll', - }, - ]); - - this.windowMain.win.webContents.on('context-menu', (e, props) => { - const selected = props.selectionText && props.selectionText.trim() !== ''; - if (props.isEditable && selected) { - inputSelectionMenu.popup({ window: this.windowMain.win }); - } else if (props.isEditable) { - inputMenu.popup({ window: this.windowMain.win }); - } else if (selected) { - selectionMenu.popup({ window: this.windowMain.win }); - } - }); - } + this.windowMain.win.webContents.on("context-menu", (e, props) => { + const selected = props.selectionText && props.selectionText.trim() !== ""; + if (props.isEditable && selected) { + inputSelectionMenu.popup({ window: this.windowMain.win }); + } else if (props.isEditable) { + inputMenu.popup({ window: this.windowMain.win }); + } else if (selected) { + selectionMenu.popup({ window: this.windowMain.win }); + } + }); + } } diff --git a/electron/src/globals.d.ts b/electron/src/globals.d.ts index d94bfae2..1b85bb1b 100644 --- a/electron/src/globals.d.ts +++ b/electron/src/globals.d.ts @@ -1 +1 @@ -declare module 'forcefocus'; +declare module "forcefocus"; diff --git a/electron/src/keytarStorageListener.ts b/electron/src/keytarStorageListener.ts index fb263cb3..a8e8ec4a 100644 --- a/electron/src/keytarStorageListener.ts +++ b/electron/src/keytarStorageListener.ts @@ -1,56 +1,52 @@ -import { ipcMain } from 'electron'; +import { ipcMain } from "electron"; -import { - deletePassword, - getPassword, - setPassword, -} from 'keytar'; +import { deletePassword, getPassword, setPassword } from "keytar"; -import { BiometricMain } from 'jslib-common/abstractions/biometric.main'; +import { BiometricMain } from "jslib-common/abstractions/biometric.main"; -const AuthRequiredSuffix = '_biometric'; -const AuthenticatedActions = ['getPassword']; +const AuthRequiredSuffix = "_biometric"; +const AuthenticatedActions = ["getPassword"]; export class KeytarStorageListener { - constructor(private serviceName: string, private biometricService: BiometricMain) { } + constructor(private serviceName: string, private biometricService: BiometricMain) {} - init() { - ipcMain.on('keytar', async (event: any, message: any) => { - try { - let serviceName = this.serviceName; - message.keySuffix = '_' + (message.keySuffix ?? ''); - if (message.keySuffix !== '_') { - serviceName += message.keySuffix; - } - - const authenticationRequired = AuthenticatedActions.includes(message.action) && - AuthRequiredSuffix === message.keySuffix; - const authenticated = !authenticationRequired || await this.authenticateBiometric(); - - let val: string | boolean = null; - if (authenticated && message.action && message.key) { - if (message.action === 'getPassword') { - val = await getPassword(serviceName, message.key); - } else if (message.action === 'hasPassword') { - const result = await getPassword(serviceName, message.key); - val = result != null; - } else if (message.action === 'setPassword' && message.value) { - await setPassword(serviceName, message.key, message.value); - } else if (message.action === 'deletePassword') { - await deletePassword(serviceName, message.key); - } - } - event.returnValue = val; - } catch { - event.returnValue = null; - } - }); - } - - private async authenticateBiometric(): Promise { - if (this.biometricService) { - return await this.biometricService.authenticateBiometric(); + init() { + ipcMain.on("keytar", async (event: any, message: any) => { + try { + let serviceName = this.serviceName; + message.keySuffix = "_" + (message.keySuffix ?? ""); + if (message.keySuffix !== "_") { + serviceName += message.keySuffix; } - return false; + + const authenticationRequired = + AuthenticatedActions.includes(message.action) && AuthRequiredSuffix === message.keySuffix; + const authenticated = !authenticationRequired || (await this.authenticateBiometric()); + + let val: string | boolean = null; + if (authenticated && message.action && message.key) { + if (message.action === "getPassword") { + val = await getPassword(serviceName, message.key); + } else if (message.action === "hasPassword") { + const result = await getPassword(serviceName, message.key); + val = result != null; + } else if (message.action === "setPassword" && message.value) { + await setPassword(serviceName, message.key, message.value); + } else if (message.action === "deletePassword") { + await deletePassword(serviceName, message.key); + } + } + event.returnValue = val; + } catch { + event.returnValue = null; + } + }); + } + + private async authenticateBiometric(): Promise { + if (this.biometricService) { + return await this.biometricService.authenticateBiometric(); } + return false; + } } diff --git a/electron/src/services/electronLog.service.ts b/electron/src/services/electronLog.service.ts index 57eeb0d4..008678ae 100644 --- a/electron/src/services/electronLog.service.ts +++ b/electron/src/services/electronLog.service.ts @@ -1,46 +1,45 @@ -import log from 'electron-log'; -import * as path from 'path'; +import log from "electron-log"; +import * as path from "path"; -import { isDev } from '../utils'; +import { isDev } from "../utils"; -import { LogLevelType } from 'jslib-common/enums/logLevelType'; +import { LogLevelType } from "jslib-common/enums/logLevelType"; -import { ConsoleLogService as BaseLogService } from 'jslib-common/services/consoleLog.service'; +import { ConsoleLogService as BaseLogService } from "jslib-common/services/consoleLog.service"; export class ElectronLogService extends BaseLogService { - - constructor(protected filter: (level: LogLevelType) => boolean = null, logDir: string = null) { - super(isDev(), filter); - if (log.transports == null) { - return; - } - - log.transports.file.level = 'info'; - if (logDir != null) { - log.transports.file.file = path.join(logDir, 'app.log'); - } + constructor(protected filter: (level: LogLevelType) => boolean = null, logDir: string = null) { + super(isDev(), filter); + if (log.transports == null) { + return; } - write(level: LogLevelType, message: string) { - if (this.filter != null && this.filter(level)) { - return; - } - - switch (level) { - case LogLevelType.Debug: - log.debug(message); - break; - case LogLevelType.Info: - log.info(message); - break; - case LogLevelType.Warning: - log.warn(message); - break; - case LogLevelType.Error: - log.error(message); - break; - default: - break; - } + log.transports.file.level = "info"; + if (logDir != null) { + log.transports.file.file = path.join(logDir, "app.log"); } + } + + write(level: LogLevelType, message: string) { + if (this.filter != null && this.filter(level)) { + return; + } + + switch (level) { + case LogLevelType.Debug: + log.debug(message); + break; + case LogLevelType.Info: + log.info(message); + break; + case LogLevelType.Warning: + log.warn(message); + break; + case LogLevelType.Error: + log.error(message); + break; + default: + break; + } + } } diff --git a/electron/src/services/electronMainMessaging.service.ts b/electron/src/services/electronMainMessaging.service.ts index d58d3b09..99dd5b32 100644 --- a/electron/src/services/electronMainMessaging.service.ts +++ b/electron/src/services/electronMainMessaging.service.ts @@ -1,58 +1,66 @@ -import { app, dialog, ipcMain, Menu, MenuItem, nativeTheme } from 'electron'; -import { promises as fs } from 'fs'; -import { MessagingService } from 'jslib-common/abstractions/messaging.service'; -import { RendererMenuItem } from '../utils'; +import { app, dialog, ipcMain, Menu, MenuItem, nativeTheme } from "electron"; +import { promises as fs } from "fs"; +import { MessagingService } from "jslib-common/abstractions/messaging.service"; +import { RendererMenuItem } from "../utils"; -import { ThemeType } from 'jslib-common/enums/themeType'; +import { ThemeType } from "jslib-common/enums/themeType"; -import { WindowMain } from '../window.main'; +import { WindowMain } from "../window.main"; export class ElectronMainMessagingService implements MessagingService { - constructor(private windowMain: WindowMain, private onMessage: (message: any) => void) { - ipcMain.handle('appVersion', () => { - return app.getVersion(); - }); + constructor(private windowMain: WindowMain, private onMessage: (message: any) => void) { + ipcMain.handle("appVersion", () => { + return app.getVersion(); + }); - ipcMain.handle('systemTheme', () => { - return nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light; - }); + ipcMain.handle("systemTheme", () => { + return nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light; + }); - ipcMain.handle('showMessageBox', (event, options) => { - return dialog.showMessageBox(options); - }); + ipcMain.handle("showMessageBox", (event, options) => { + return dialog.showMessageBox(options); + }); - ipcMain.handle('openContextMenu', (event, options: {menu: RendererMenuItem[]}) => { - return new Promise(resolve => { - const menu = new Menu(); - options.menu.forEach((m, index) => { - menu.append(new MenuItem({ - label: m.label, - type: m.type, - click: () => { - resolve(index); - }, - })); - }); - menu.popup({ window: windowMain.win, callback: () => { - resolve(-1); - }}); - }); + ipcMain.handle("openContextMenu", (event, options: { menu: RendererMenuItem[] }) => { + return new Promise((resolve) => { + const menu = new Menu(); + options.menu.forEach((m, index) => { + menu.append( + new MenuItem({ + label: m.label, + type: m.type, + click: () => { + resolve(index); + }, + }) + ); }); + menu.popup({ + window: windowMain.win, + callback: () => { + resolve(-1); + }, + }); + }); + }); - ipcMain.handle('windowVisible', () => { - return windowMain.win?.isVisible(); - }); + ipcMain.handle("windowVisible", () => { + return windowMain.win?.isVisible(); + }); - nativeTheme.on('updated', () => { - windowMain.win?.webContents.send('systemThemeUpdated', nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light); - }); - } - - send(subscriber: string, arg: any = {}) { - const message = Object.assign({}, { command: subscriber }, arg); - this.onMessage(message); - if (this.windowMain.win != null) { - this.windowMain.win.webContents.send('messagingService', message); - } + nativeTheme.on("updated", () => { + windowMain.win?.webContents.send( + "systemThemeUpdated", + nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light + ); + }); + } + + send(subscriber: string, arg: any = {}) { + const message = Object.assign({}, { command: subscriber }, arg); + this.onMessage(message); + if (this.windowMain.win != null) { + this.windowMain.win.webContents.send("messagingService", message); } + } } diff --git a/electron/src/services/electronRendererMessaging.service.ts b/electron/src/services/electronRendererMessaging.service.ts index c9509074..89350a65 100644 --- a/electron/src/services/electronRendererMessaging.service.ts +++ b/electron/src/services/electronRendererMessaging.service.ts @@ -1,26 +1,26 @@ -import { ipcRenderer } from 'electron'; +import { ipcRenderer } from "electron"; -import { BroadcasterService } from 'jslib-common/abstractions/broadcaster.service'; -import { MessagingService } from 'jslib-common/abstractions/messaging.service'; +import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service"; +import { MessagingService } from "jslib-common/abstractions/messaging.service"; export class ElectronRendererMessagingService implements MessagingService { - constructor(private broadcasterService: BroadcasterService) { - ipcRenderer.on('messagingService', async (event: any, message: any) => { - if (message.command) { - this.sendMessage(message.command, message, false); - } - }); - } + constructor(private broadcasterService: BroadcasterService) { + ipcRenderer.on("messagingService", async (event: any, message: any) => { + if (message.command) { + this.sendMessage(message.command, message, false); + } + }); + } - send(subscriber: string, arg: any = {}) { - this.sendMessage(subscriber, arg, true); - } + send(subscriber: string, arg: any = {}) { + this.sendMessage(subscriber, arg, true); + } - private sendMessage(subscriber: string, arg: any = {}, toMain: boolean) { - const message = Object.assign({}, { command: subscriber }, arg); - this.broadcasterService.send(message); - if (toMain) { - ipcRenderer.send('messagingService', message); - } + private sendMessage(subscriber: string, arg: any = {}, toMain: boolean) { + const message = Object.assign({}, { command: subscriber }, arg); + this.broadcasterService.send(message); + if (toMain) { + ipcRenderer.send("messagingService", message); } + } } diff --git a/electron/src/services/electronRendererStorage.service.ts b/electron/src/services/electronRendererStorage.service.ts index e1554a7e..69436bfe 100644 --- a/electron/src/services/electronRendererStorage.service.ts +++ b/electron/src/services/electronRendererStorage.service.ts @@ -1,34 +1,34 @@ -import { ipcRenderer } from 'electron'; +import { ipcRenderer } from "electron"; -import { StorageService } from 'jslib-common/abstractions/storage.service'; +import { StorageService } from "jslib-common/abstractions/storage.service"; export class ElectronRendererStorageService implements StorageService { - get(key: string): Promise { - return ipcRenderer.invoke('storageService', { - action: 'get', - key: key, - }); - } + get(key: string): Promise { + return ipcRenderer.invoke("storageService", { + action: "get", + key: key, + }); + } - has(key: string): Promise { - return ipcRenderer.invoke('storageService', { - action: 'has', - key: key, - }); - } + has(key: string): Promise { + return ipcRenderer.invoke("storageService", { + action: "has", + key: key, + }); + } - save(key: string, obj: any): Promise { - return ipcRenderer.invoke('storageService', { - action: 'save', - key: key, - obj: obj, - }); - } + save(key: string, obj: any): Promise { + return ipcRenderer.invoke("storageService", { + action: "save", + key: key, + obj: obj, + }); + } - remove(key: string): Promise { - return ipcRenderer.invoke('storageService', { - action: 'remove', - key: key, - }); - } + remove(key: string): Promise { + return ipcRenderer.invoke("storageService", { + action: "remove", + key: key, + }); + } } diff --git a/electron/src/services/electronStorage.service.ts b/electron/src/services/electronStorage.service.ts index 5bf8d26c..08d49ed0 100644 --- a/electron/src/services/electronStorage.service.ts +++ b/electron/src/services/electronStorage.service.ts @@ -1,60 +1,60 @@ -import { ipcMain, ipcRenderer } from 'electron'; -import * as fs from 'fs'; +import { ipcMain, ipcRenderer } from "electron"; +import * as fs from "fs"; -import { StorageService } from 'jslib-common/abstractions/storage.service'; +import { StorageService } from "jslib-common/abstractions/storage.service"; -import { NodeUtils } from 'jslib-common/misc/nodeUtils'; +import { NodeUtils } from "jslib-common/misc/nodeUtils"; // tslint:disable-next-line -const Store = require('electron-store'); +const Store = require("electron-store"); export class ElectronStorageService implements StorageService { - private store: any; + private store: any; - constructor(dir: string, defaults = {}) { - if (!fs.existsSync(dir)) { - NodeUtils.mkdirpSync(dir, '700'); - } - const storeConfig: any = { - defaults: defaults, - name: 'data', - }; - this.store = new Store(storeConfig); - - ipcMain.handle('storageService', (event, options) => { - switch (options.action) { - case 'get': - return this.get(options.key); - case 'has': - return this.has(options.key); - case 'save': - return this.save(options.key, options.obj); - case 'remove': - return this.remove(options.key); - } - }); + constructor(dir: string, defaults = {}) { + if (!fs.existsSync(dir)) { + NodeUtils.mkdirpSync(dir, "700"); } + const storeConfig: any = { + defaults: defaults, + name: "data", + }; + this.store = new Store(storeConfig); - get(key: string): Promise { - const val = this.store.get(key) as T; - return Promise.resolve(val != null ? val : null); - } + ipcMain.handle("storageService", (event, options) => { + switch (options.action) { + case "get": + return this.get(options.key); + case "has": + return this.has(options.key); + case "save": + return this.save(options.key, options.obj); + case "remove": + return this.remove(options.key); + } + }); + } - has(key: string): Promise { - const val = this.store.get(key); - return Promise.resolve(val != null); - } + get(key: string): Promise { + const val = this.store.get(key) as T; + return Promise.resolve(val != null ? val : null); + } - save(key: string, obj: any): Promise { - if (obj instanceof Set) { - obj = Array.from(obj); - } - this.store.set(key, obj); - return Promise.resolve(); - } + has(key: string): Promise { + const val = this.store.get(key); + return Promise.resolve(val != null); + } - remove(key: string): Promise { - this.store.delete(key); - return Promise.resolve(); + save(key: string, obj: any): Promise { + if (obj instanceof Set) { + obj = Array.from(obj); } + this.store.set(key, obj); + return Promise.resolve(); + } + + remove(key: string): Promise { + this.store.delete(key); + return Promise.resolve(); + } } diff --git a/electron/src/updater.main.ts b/electron/src/updater.main.ts index 712a79a4..bc0fb4b4 100644 --- a/electron/src/updater.main.ts +++ b/electron/src/updater.main.ts @@ -1,155 +1,154 @@ -import { - dialog, - Menu, - MenuItem, - shell, -} from 'electron'; -import log from 'electron-log'; -import { autoUpdater } from 'electron-updater'; +import { dialog, Menu, MenuItem, shell } from "electron"; +import log from "electron-log"; +import { autoUpdater } from "electron-updater"; -import { - isAppImage, - isDev, - isMacAppStore, - isWindowsPortable, - isWindowsStore, -} from './utils'; +import { isAppImage, isDev, isMacAppStore, isWindowsPortable, isWindowsStore } from "./utils"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { WindowMain } from './window.main'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { WindowMain } from "./window.main"; const UpdaterCheckInitalDelay = 5 * 1000; // 5 seconds const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours export class UpdaterMain { - private doingUpdateCheck = false; - private doingUpdateCheckWithFeedback = false; - private canUpdate = false; + private doingUpdateCheck = false; + private doingUpdateCheckWithFeedback = false; + private canUpdate = false; - constructor(private i18nService: I18nService, private windowMain: WindowMain, - private gitHubProject: string, private onCheckingForUpdate: () => void = null, - private onReset: () => void = null, private onUpdateDownloaded: () => void = null, - private projectName: string) { - autoUpdater.logger = log; + constructor( + private i18nService: I18nService, + private windowMain: WindowMain, + private gitHubProject: string, + private onCheckingForUpdate: () => void = null, + private onReset: () => void = null, + private onUpdateDownloaded: () => void = null, + private projectName: string + ) { + autoUpdater.logger = log; - const linuxCanUpdate = process.platform === 'linux' && isAppImage(); - const windowsCanUpdate = process.platform === 'win32' && !isWindowsStore() && !isWindowsPortable(); - const macCanUpdate = process.platform === 'darwin' && !isMacAppStore(); - this.canUpdate = process.env.ELECTRON_NO_UPDATER !== '1' && - (linuxCanUpdate || windowsCanUpdate || macCanUpdate); - } + const linuxCanUpdate = process.platform === "linux" && isAppImage(); + const windowsCanUpdate = + process.platform === "win32" && !isWindowsStore() && !isWindowsPortable(); + const macCanUpdate = process.platform === "darwin" && !isMacAppStore(); + this.canUpdate = + process.env.ELECTRON_NO_UPDATER !== "1" && + (linuxCanUpdate || windowsCanUpdate || macCanUpdate); + } - async init() { - global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay); - global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval); + async init() { + global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay); + global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval); - autoUpdater.on('checking-for-update', () => { - if (this.onCheckingForUpdate != null) { - this.onCheckingForUpdate(); - } - this.doingUpdateCheck = true; - }); + autoUpdater.on("checking-for-update", () => { + if (this.onCheckingForUpdate != null) { + this.onCheckingForUpdate(); + } + this.doingUpdateCheck = true; + }); - autoUpdater.on('update-available', async () => { - if (this.doingUpdateCheckWithFeedback) { - if (this.windowMain.win == null) { - this.reset(); - return; - } - - const result = await dialog.showMessageBox(this.windowMain.win, { - type: 'info', - title: this.i18nService.t(this.projectName) + ' - ' + this.i18nService.t('updateAvailable'), - message: this.i18nService.t('updateAvailable'), - detail: this.i18nService.t('updateAvailableDesc'), - buttons: [this.i18nService.t('yes'), this.i18nService.t('no')], - cancelId: 1, - defaultId: 0, - noLink: true, - }); - - if (result.response === 0) { - autoUpdater.downloadUpdate(); - } else { - this.reset(); - } - } - }); - - autoUpdater.on('update-not-available', () => { - if (this.doingUpdateCheckWithFeedback && this.windowMain.win != null) { - dialog.showMessageBox(this.windowMain.win, { - message: this.i18nService.t('noUpdatesAvailable'), - buttons: [this.i18nService.t('ok')], - defaultId: 0, - noLink: true, - }); - } - - this.reset(); - }); - - autoUpdater.on('update-downloaded', async info => { - if (this.onUpdateDownloaded != null) { - this.onUpdateDownloaded(); - } - - if (this.windowMain.win == null) { - return; - } - - const result = await dialog.showMessageBox(this.windowMain.win, { - type: 'info', - title: this.i18nService.t(this.projectName) + ' - ' + this.i18nService.t('restartToUpdate'), - message: this.i18nService.t('restartToUpdate'), - detail: this.i18nService.t('restartToUpdateDesc', info.version), - buttons: [this.i18nService.t('restart'), this.i18nService.t('later')], - cancelId: 1, - defaultId: 0, - noLink: true, - }); - - if (result.response === 0) { - autoUpdater.quitAndInstall(false, true); - } - }); - - autoUpdater.on('error', error => { - if (this.doingUpdateCheckWithFeedback) { - dialog.showErrorBox(this.i18nService.t('updateError'), - error == null ? this.i18nService.t('unknown') : (error.stack || error).toString()); - } - - this.reset(); - }); - } - - async checkForUpdate(withFeedback: boolean = false) { - if (this.doingUpdateCheck || isDev()) { - return; + autoUpdater.on("update-available", async () => { + if (this.doingUpdateCheckWithFeedback) { + if (this.windowMain.win == null) { + this.reset(); + return; } - if (!this.canUpdate) { - if (withFeedback) { - shell.openExternal('https://github.com/bitwarden/' + this.gitHubProject + '/releases'); - } + const result = await dialog.showMessageBox(this.windowMain.win, { + type: "info", + title: + this.i18nService.t(this.projectName) + " - " + this.i18nService.t("updateAvailable"), + message: this.i18nService.t("updateAvailable"), + detail: this.i18nService.t("updateAvailableDesc"), + buttons: [this.i18nService.t("yes"), this.i18nService.t("no")], + cancelId: 1, + defaultId: 0, + noLink: true, + }); - return; + if (result.response === 0) { + autoUpdater.downloadUpdate(); + } else { + this.reset(); } + } + }); - this.doingUpdateCheckWithFeedback = withFeedback; - if (withFeedback) { - autoUpdater.autoDownload = false; - } + autoUpdater.on("update-not-available", () => { + if (this.doingUpdateCheckWithFeedback && this.windowMain.win != null) { + dialog.showMessageBox(this.windowMain.win, { + message: this.i18nService.t("noUpdatesAvailable"), + buttons: [this.i18nService.t("ok")], + defaultId: 0, + noLink: true, + }); + } - await autoUpdater.checkForUpdates(); + this.reset(); + }); + + autoUpdater.on("update-downloaded", async (info) => { + if (this.onUpdateDownloaded != null) { + this.onUpdateDownloaded(); + } + + if (this.windowMain.win == null) { + return; + } + + const result = await dialog.showMessageBox(this.windowMain.win, { + type: "info", + title: this.i18nService.t(this.projectName) + " - " + this.i18nService.t("restartToUpdate"), + message: this.i18nService.t("restartToUpdate"), + detail: this.i18nService.t("restartToUpdateDesc", info.version), + buttons: [this.i18nService.t("restart"), this.i18nService.t("later")], + cancelId: 1, + defaultId: 0, + noLink: true, + }); + + if (result.response === 0) { + autoUpdater.quitAndInstall(false, true); + } + }); + + autoUpdater.on("error", (error) => { + if (this.doingUpdateCheckWithFeedback) { + dialog.showErrorBox( + this.i18nService.t("updateError"), + error == null ? this.i18nService.t("unknown") : (error.stack || error).toString() + ); + } + + this.reset(); + }); + } + + async checkForUpdate(withFeedback: boolean = false) { + if (this.doingUpdateCheck || isDev()) { + return; } - private reset() { - if (this.onReset != null) { - this.onReset(); - } - autoUpdater.autoDownload = true; - this.doingUpdateCheck = false; + if (!this.canUpdate) { + if (withFeedback) { + shell.openExternal("https://github.com/bitwarden/" + this.gitHubProject + "/releases"); + } + + return; } + + this.doingUpdateCheckWithFeedback = withFeedback; + if (withFeedback) { + autoUpdater.autoDownload = false; + } + + await autoUpdater.checkForUpdates(); + } + + private reset() { + if (this.onReset != null) { + this.onReset(); + } + autoUpdater.autoDownload = true; + this.doingUpdateCheck = false; + } } diff --git a/electron/tsconfig.json b/electron/tsconfig.json index 3d41e86c..36dffb93 100644 --- a/electron/tsconfig.json +++ b/electron/tsconfig.json @@ -14,17 +14,9 @@ "declarationDir": "dist/types", "outDir": "dist", "paths": { - "jslib-common/*": [ - "../common/src/*" - ] + "jslib-common/*": ["../common/src/*"] } }, - "include": [ - "src", - "spec" - ], - "exclude": [ - "node_modules", - "dist" - ] + "include": ["src", "spec"], + "exclude": ["node_modules", "dist"] } diff --git a/node/src/cli/commands/logout.command.ts b/node/src/cli/commands/logout.command.ts index 12b1533e..752d142d 100644 --- a/node/src/cli/commands/logout.command.ts +++ b/node/src/cli/commands/logout.command.ts @@ -1,19 +1,24 @@ -import * as program from 'commander'; +import * as program from "commander"; -import { AuthService } from 'jslib-common/abstractions/auth.service'; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; +import { AuthService } from "jslib-common/abstractions/auth.service"; +import { I18nService } from "jslib-common/abstractions/i18n.service"; -import { Response } from '../models/response'; -import { MessageResponse } from '../models/response/messageResponse'; +import { Response } from "../models/response"; +import { MessageResponse } from "../models/response/messageResponse"; export class LogoutCommand { - constructor(private authService: AuthService, private i18nService: I18nService, - private logoutCallback: () => Promise) { } + constructor( + private authService: AuthService, + private i18nService: I18nService, + private logoutCallback: () => Promise + ) {} - async run() { - await this.logoutCallback(); - this.authService.logOut(() => { /* Do nothing */ }); - const res = new MessageResponse('You have logged out.', null); - return Response.success(res); - } + async run() { + await this.logoutCallback(); + this.authService.logOut(() => { + /* Do nothing */ + }); + const res = new MessageResponse("You have logged out.", null); + return Response.success(res); + } } diff --git a/node/src/cli/commands/update.command.ts b/node/src/cli/commands/update.command.ts index 94dc046e..147a4694 100644 --- a/node/src/cli/commands/update.command.ts +++ b/node/src/cli/commands/update.command.ts @@ -1,86 +1,105 @@ -import * as program from 'commander'; -import * as fetch from 'node-fetch'; +import * as program from "commander"; +import * as fetch from "node-fetch"; -import { I18nService } from 'jslib-common/abstractions/i18n.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { I18nService } from "jslib-common/abstractions/i18n.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { Response } from '../models/response'; -import { MessageResponse } from '../models/response/messageResponse'; +import { Response } from "../models/response"; +import { MessageResponse } from "../models/response/messageResponse"; export class UpdateCommand { - inPkg: boolean = false; + inPkg: boolean = false; - constructor(private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private repoName: string, private executableName: string, private showExtendedMessage: boolean) { - this.inPkg = !!(process as any).pkg; - } + constructor( + private platformUtilsService: PlatformUtilsService, + private i18nService: I18nService, + private repoName: string, + private executableName: string, + private showExtendedMessage: boolean + ) { + this.inPkg = !!(process as any).pkg; + } - async run(): Promise { - const currentVersion = await this.platformUtilsService.getApplicationVersion(); + async run(): Promise { + const currentVersion = await this.platformUtilsService.getApplicationVersion(); - const response = await fetch.default('https://api.github.com/repos/bitwarden/' + - this.repoName + '/releases/latest'); - if (response.status === 200) { - const responseJson = await response.json(); - const res = new MessageResponse(null, null); + const response = await fetch.default( + "https://api.github.com/repos/bitwarden/" + this.repoName + "/releases/latest" + ); + if (response.status === 200) { + const responseJson = await response.json(); + const res = new MessageResponse(null, null); - const tagName: string = responseJson.tag_name; - if (tagName === ('v' + currentVersion)) { - res.title = 'No update available.'; - res.noColor = true; - return Response.success(res); - } + const tagName: string = responseJson.tag_name; + if (tagName === "v" + currentVersion) { + res.title = "No update available."; + res.noColor = true; + return Response.success(res); + } - let downloadUrl: string = null; - if (responseJson.assets != null) { - for (const a of responseJson.assets) { - const download: string = a.browser_download_url; - if (download == null) { - continue; - } + let downloadUrl: string = null; + if (responseJson.assets != null) { + for (const a of responseJson.assets) { + const download: string = a.browser_download_url; + if (download == null) { + continue; + } - if (download.indexOf('.zip') === -1) { - continue; - } + if (download.indexOf(".zip") === -1) { + continue; + } - if (process.platform === 'win32' && download.indexOf(this.executableName + '-windows') > -1) { - downloadUrl = download; - break; - } else if (process.platform === 'darwin' && download.indexOf(this.executableName + '-macos') > -1) { - downloadUrl = download; - break; - } else if (process.platform === 'linux' && download.indexOf(this.executableName + '-linux') > -1) { - downloadUrl = download; - break; - } - } - } - - res.title = 'A new version is available: ' + tagName; - if (downloadUrl == null) { - downloadUrl = 'https://github.com/bitwarden/' + this.repoName + '/releases'; - } else { - res.raw = downloadUrl; - } - res.message = ''; - if (responseJson.body != null && responseJson.body !== '') { - res.message = responseJson.body + '\n\n'; - } - - res.message += 'You can download this update at ' + downloadUrl; - - if (this.showExtendedMessage) { - if (this.inPkg) { - res.message += '\n\nIf you installed this CLI through a package manager ' + - 'you should probably update using its update command instead.'; - } else { - res.message += '\n\nIf you installed this CLI through NPM ' + - 'you should update using `npm install -g @bitwarden/' + this.repoName + '`'; - } - } - return Response.success(res); - } else { - return Response.error('Error contacting update API: ' + response.status); + if ( + process.platform === "win32" && + download.indexOf(this.executableName + "-windows") > -1 + ) { + downloadUrl = download; + break; + } else if ( + process.platform === "darwin" && + download.indexOf(this.executableName + "-macos") > -1 + ) { + downloadUrl = download; + break; + } else if ( + process.platform === "linux" && + download.indexOf(this.executableName + "-linux") > -1 + ) { + downloadUrl = download; + break; + } } + } + + res.title = "A new version is available: " + tagName; + if (downloadUrl == null) { + downloadUrl = "https://github.com/bitwarden/" + this.repoName + "/releases"; + } else { + res.raw = downloadUrl; + } + res.message = ""; + if (responseJson.body != null && responseJson.body !== "") { + res.message = responseJson.body + "\n\n"; + } + + res.message += "You can download this update at " + downloadUrl; + + if (this.showExtendedMessage) { + if (this.inPkg) { + res.message += + "\n\nIf you installed this CLI through a package manager " + + "you should probably update using its update command instead."; + } else { + res.message += + "\n\nIf you installed this CLI through NPM " + + "you should update using `npm install -g @bitwarden/" + + this.repoName + + "`"; + } + } + return Response.success(res); + } else { + return Response.error("Error contacting update API: " + response.status); } + } } diff --git a/node/src/cli/models/response.ts b/node/src/cli/models/response.ts index d3a858ac..d768c51f 100644 --- a/node/src/cli/models/response.ts +++ b/node/src/cli/models/response.ts @@ -1,45 +1,50 @@ -import { BaseResponse } from './response/baseResponse'; +import { BaseResponse } from "./response/baseResponse"; export class Response { - static error(error: any, data?: any): Response { - const res = new Response(); - res.success = false; - if (typeof (error) === 'string') { - res.message = error; - } else { - res.message = error.message != null ? error.message : - error.toString() === '[object Object]' ? JSON.stringify(error) : error.toString(); - } - res.data = data; - return res; + static error(error: any, data?: any): Response { + const res = new Response(); + res.success = false; + if (typeof error === "string") { + res.message = error; + } else { + res.message = + error.message != null + ? error.message + : error.toString() === "[object Object]" + ? JSON.stringify(error) + : error.toString(); } + res.data = data; + return res; + } - static notFound(): Response { - return Response.error('Not found.'); - } + static notFound(): Response { + return Response.error("Not found."); + } - static badRequest(message: string): Response { - return Response.error(message); - } + static badRequest(message: string): Response { + return Response.error(message); + } - static multipleResults(ids: string[]): Response { - let msg = 'More than one result was found. Try getting a specific object by `id` instead. ' + - 'The following objects were found:'; - ids.forEach(id => { - msg += '\n' + id; - }); - return Response.error(msg, ids); - } + static multipleResults(ids: string[]): Response { + let msg = + "More than one result was found. Try getting a specific object by `id` instead. " + + "The following objects were found:"; + ids.forEach((id) => { + msg += "\n" + id; + }); + return Response.error(msg, ids); + } - static success(data?: BaseResponse): Response { - const res = new Response(); - res.success = true; - res.data = data; - return res; - } + static success(data?: BaseResponse): Response { + const res = new Response(); + res.success = true; + res.data = data; + return res; + } - success: boolean; - message: string; - errorCode: number; - data: BaseResponse; + success: boolean; + message: string; + errorCode: number; + data: BaseResponse; } diff --git a/node/src/cli/models/response/baseResponse.ts b/node/src/cli/models/response/baseResponse.ts index 9d8beca0..b0cc57da 100644 --- a/node/src/cli/models/response/baseResponse.ts +++ b/node/src/cli/models/response/baseResponse.ts @@ -1,3 +1,3 @@ export interface BaseResponse { - object: string; + object: string; } diff --git a/node/src/cli/models/response/fileResponse.ts b/node/src/cli/models/response/fileResponse.ts index 2e832dfc..c16b56e0 100644 --- a/node/src/cli/models/response/fileResponse.ts +++ b/node/src/cli/models/response/fileResponse.ts @@ -1,13 +1,13 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class FileResponse implements BaseResponse { - object: string; - data: Buffer; - fileName: string; + object: string; + data: Buffer; + fileName: string; - constructor(data: Buffer, fileName: string) { - this.object = 'file'; - this.data = data; - this.fileName = fileName; - } + constructor(data: Buffer, fileName: string) { + this.object = "file"; + this.data = data; + this.fileName = fileName; + } } diff --git a/node/src/cli/models/response/listResponse.ts b/node/src/cli/models/response/listResponse.ts index 7995bd4f..db415bcd 100644 --- a/node/src/cli/models/response/listResponse.ts +++ b/node/src/cli/models/response/listResponse.ts @@ -1,11 +1,11 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class ListResponse implements BaseResponse { - object: string; - data: BaseResponse[]; + object: string; + data: BaseResponse[]; - constructor(data: BaseResponse[]) { - this.object = 'list'; - this.data = data; - } + constructor(data: BaseResponse[]) { + this.object = "list"; + this.data = data; + } } diff --git a/node/src/cli/models/response/messageResponse.ts b/node/src/cli/models/response/messageResponse.ts index 448e3db7..8612841a 100644 --- a/node/src/cli/models/response/messageResponse.ts +++ b/node/src/cli/models/response/messageResponse.ts @@ -1,15 +1,15 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class MessageResponse implements BaseResponse { - object: string; - title: string; - message: string; - raw: string; - noColor = false; + object: string; + title: string; + message: string; + raw: string; + noColor = false; - constructor(title: string, message: string) { - this.object = 'message'; - this.title = title; - this.message = message; - } + constructor(title: string, message: string) { + this.object = "message"; + this.title = title; + this.message = message; + } } diff --git a/node/src/cli/models/response/stringResponse.ts b/node/src/cli/models/response/stringResponse.ts index b9a0f044..f4becfe8 100644 --- a/node/src/cli/models/response/stringResponse.ts +++ b/node/src/cli/models/response/stringResponse.ts @@ -1,11 +1,11 @@ -import { BaseResponse } from './baseResponse'; +import { BaseResponse } from "./baseResponse"; export class StringResponse implements BaseResponse { - object: string; - data: string; + object: string; + data: string; - constructor(data: string) { - this.object = 'string'; - this.data = data; - } + constructor(data: string) { + this.object = "string"; + this.data = data; + } } diff --git a/node/src/cli/services/cliPlatformUtils.service.ts b/node/src/cli/services/cliPlatformUtils.service.ts index 78afaee9..7975d064 100644 --- a/node/src/cli/services/cliPlatformUtils.service.ts +++ b/node/src/cli/services/cliPlatformUtils.service.ts @@ -1,157 +1,166 @@ -import * as child_process from 'child_process'; +import * as child_process from "child_process"; -import { DeviceType } from 'jslib-common/enums/deviceType'; -import { ThemeType } from 'jslib-common/enums/themeType'; +import { DeviceType } from "jslib-common/enums/deviceType"; +import { ThemeType } from "jslib-common/enums/themeType"; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; // tslint:disable-next-line -const open = require('open'); +const open = require("open"); export class CliPlatformUtilsService implements PlatformUtilsService { - identityClientId: string; + identityClientId: string; - private deviceCache: DeviceType = null; + private deviceCache: DeviceType = null; - constructor(identityClientId: string, private packageJson: any) { - this.identityClientId = identityClientId; + constructor(identityClientId: string, private packageJson: any) { + this.identityClientId = identityClientId; + } + + getDevice(): DeviceType { + if (!this.deviceCache) { + switch (process.platform) { + case "win32": + this.deviceCache = DeviceType.WindowsDesktop; + break; + case "darwin": + this.deviceCache = DeviceType.MacOsDesktop; + break; + case "linux": + default: + this.deviceCache = DeviceType.LinuxDesktop; + break; + } } - getDevice(): DeviceType { - if (!this.deviceCache) { - switch (process.platform) { - case 'win32': - this.deviceCache = DeviceType.WindowsDesktop; - break; - case 'darwin': - this.deviceCache = DeviceType.MacOsDesktop; - break; - case 'linux': - default: - this.deviceCache = DeviceType.LinuxDesktop; - break; - } - } + return this.deviceCache; + } - return this.deviceCache; - } + getDeviceString(): string { + const device = DeviceType[this.getDevice()].toLowerCase(); + return device.replace("desktop", ""); + } - getDeviceString(): string { - const device = DeviceType[this.getDevice()].toLowerCase(); - return device.replace('desktop', ''); - } + isFirefox() { + return false; + } - isFirefox() { - return false; - } + isChrome() { + return false; + } - isChrome() { - return false; - } + isEdge() { + return false; + } - isEdge() { - return false; - } + isOpera() { + return false; + } - isOpera() { - return false; - } + isVivaldi() { + return false; + } - isVivaldi() { - return false; - } + isSafari() { + return false; + } - isSafari() { - return false; - } + isIE() { + return false; + } - isIE() { - return false; - } + isMacAppStore() { + return false; + } - isMacAppStore() { - return false; - } + isViewOpen() { + return Promise.resolve(false); + } - isViewOpen() { - return Promise.resolve(false); + launchUri(uri: string, options?: any): void { + if (process.platform === "linux") { + child_process.spawnSync("xdg-open", [uri]); + } else { + open(uri); } + } - launchUri(uri: string, options?: any): void { - if (process.platform === 'linux') { - child_process.spawnSync('xdg-open', [uri]); - } else { - open(uri); - } - } + saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void { + throw new Error("Not implemented."); + } - saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void { - throw new Error('Not implemented.'); - } + getApplicationVersion(): Promise { + return Promise.resolve(this.packageJson.version); + } - getApplicationVersion(): Promise { - return Promise.resolve(this.packageJson.version); - } + getApplicationVersionSync(): string { + return this.packageJson.version; + } - getApplicationVersionSync(): string { - return this.packageJson.version; - } + supportsWebAuthn(win: Window) { + return false; + } - supportsWebAuthn(win: Window) { - return false; - } + supportsDuo(): boolean { + return false; + } - supportsDuo(): boolean { - return false; - } + showToast( + type: "error" | "success" | "warning" | "info", + title: string, + text: string | string[], + options?: any + ): void { + throw new Error("Not implemented."); + } - showToast(type: 'error' | 'success' | 'warning' | 'info', title: string, text: string | string[], - options?: any): void { - throw new Error('Not implemented.'); - } + showDialog( + text: string, + title?: string, + confirmText?: string, + cancelText?: string, + type?: string + ): Promise { + throw new Error("Not implemented."); + } - showDialog(text: string, title?: string, confirmText?: string, cancelText?: string, type?: string): - Promise { - throw new Error('Not implemented.'); - } + isDev(): boolean { + return process.env.BWCLI_ENV === "development"; + } - isDev(): boolean { - return process.env.BWCLI_ENV === 'development'; - } + isSelfHost(): boolean { + return false; + } - isSelfHost(): boolean { - return false; - } + copyToClipboard(text: string, options?: any): void { + throw new Error("Not implemented."); + } - copyToClipboard(text: string, options?: any): void { - throw new Error('Not implemented.'); - } + readFromClipboard(options?: any): Promise { + throw new Error("Not implemented."); + } - readFromClipboard(options?: any): Promise { - throw new Error('Not implemented.'); - } + supportsBiometric(): Promise { + return Promise.resolve(false); + } - supportsBiometric(): Promise { - return Promise.resolve(false); - } + authenticateBiometric(): Promise { + return Promise.resolve(false); + } - authenticateBiometric(): Promise { - return Promise.resolve(false); - } + getDefaultSystemTheme() { + return Promise.resolve(ThemeType.Light as ThemeType.Light | ThemeType.Dark); + } - getDefaultSystemTheme() { - return Promise.resolve(ThemeType.Light as ThemeType.Light | ThemeType.Dark); - } + onDefaultSystemThemeChange() { + /* noop */ + } - onDefaultSystemThemeChange() { - /* noop */ - } + getEffectiveTheme() { + return Promise.resolve(ThemeType.Light); + } - getEffectiveTheme() { - return Promise.resolve(ThemeType.Light); - } - - supportsSecureStorage(): boolean { - return false; - } + supportsSecureStorage(): boolean { + return false; + } } diff --git a/node/src/cli/services/consoleLog.service.ts b/node/src/cli/services/consoleLog.service.ts index f603f326..f55e2d7d 100644 --- a/node/src/cli/services/consoleLog.service.ts +++ b/node/src/cli/services/consoleLog.service.ts @@ -1,23 +1,23 @@ -import { LogLevelType } from 'jslib-common/enums/logLevelType'; +import { LogLevelType } from "jslib-common/enums/logLevelType"; -import { ConsoleLogService as BaseConsoleLogService } from 'jslib-common/services/consoleLog.service'; +import { ConsoleLogService as BaseConsoleLogService } from "jslib-common/services/consoleLog.service"; export class ConsoleLogService extends BaseConsoleLogService { - constructor(isDev: boolean, filter: (level: LogLevelType) => boolean = null) { - super(isDev, filter); + constructor(isDev: boolean, filter: (level: LogLevelType) => boolean = null) { + super(isDev, filter); + } + + write(level: LogLevelType, message: string) { + if (this.filter != null && this.filter(level)) { + return; } - write(level: LogLevelType, message: string) { - if (this.filter != null && this.filter(level)) { - return; - } - - if (process.env.BW_RESPONSE === 'true') { - // tslint:disable-next-line - console.error(message); - return; - } - - super.write(level, message); + if (process.env.BW_RESPONSE === "true") { + // tslint:disable-next-line + console.error(message); + return; } + + super.write(level, message); + } } diff --git a/node/src/services/lowdbStorage.service.ts b/node/src/services/lowdbStorage.service.ts index 99b327a1..1dcaaf1a 100644 --- a/node/src/services/lowdbStorage.service.ts +++ b/node/src/services/lowdbStorage.service.ts @@ -1,119 +1,130 @@ -import * as fs from 'fs'; -import * as lowdb from 'lowdb'; -import * as FileSync from 'lowdb/adapters/FileSync'; -import * as path from 'path'; +import * as fs from "fs"; +import * as lowdb from "lowdb"; +import * as FileSync from "lowdb/adapters/FileSync"; +import * as path from "path"; -import { LogService } from 'jslib-common/abstractions/log.service'; -import { StorageService } from 'jslib-common/abstractions/storage.service'; +import { LogService } from "jslib-common/abstractions/log.service"; +import { StorageService } from "jslib-common/abstractions/storage.service"; -import { NodeUtils } from 'jslib-common/misc/nodeUtils'; -import { Utils } from 'jslib-common/misc/utils'; +import { NodeUtils } from "jslib-common/misc/nodeUtils"; +import { Utils } from "jslib-common/misc/utils"; export class LowdbStorageService implements StorageService { - protected dataFilePath: string; - private db: lowdb.LowdbSync; - private defaults: any; + protected dataFilePath: string; + private db: lowdb.LowdbSync; + private defaults: any; - constructor(protected logService: LogService, defaults?: any, private dir?: string, private allowCache = false) { - this.defaults = defaults; + constructor( + protected logService: LogService, + defaults?: any, + private dir?: string, + private allowCache = false + ) { + this.defaults = defaults; + } + + async init() { + this.logService.info("Initializing lowdb storage service."); + let adapter: lowdb.AdapterSync; + if (Utils.isNode && this.dir != null) { + if (!fs.existsSync(this.dir)) { + this.logService.warning(`Could not find dir, "${this.dir}"; creating it instead.`); + NodeUtils.mkdirpSync(this.dir, "700"); + this.logService.info(`Created dir "${this.dir}".`); + } + this.dataFilePath = path.join(this.dir, "data.json"); + if (!fs.existsSync(this.dataFilePath)) { + this.logService.warning( + `Could not find data file, "${this.dataFilePath}"; creating it instead.` + ); + fs.writeFileSync(this.dataFilePath, "", { mode: 0o600 }); + fs.chmodSync(this.dataFilePath, 0o600); + this.logService.info(`Created data file "${this.dataFilePath}" with chmod 600.`); + } else { + this.logService.info(`db file "${this.dataFilePath} already exists"; using existing db`); + } + await this.lockDbFile(() => { + adapter = new FileSync(this.dataFilePath); + }); } - - async init() { - this.logService.info('Initializing lowdb storage service.'); - let adapter: lowdb.AdapterSync; - if (Utils.isNode && this.dir != null) { - if (!fs.existsSync(this.dir)) { - this.logService.warning(`Could not find dir, "${this.dir}"; creating it instead.`); - NodeUtils.mkdirpSync(this.dir, '700'); - this.logService.info(`Created dir "${this.dir}".`); - } - this.dataFilePath = path.join(this.dir, 'data.json'); - if (!fs.existsSync(this.dataFilePath)) { - this.logService.warning(`Could not find data file, "${this.dataFilePath}"; creating it instead.`); - fs.writeFileSync(this.dataFilePath, '', { mode: 0o600 }); - fs.chmodSync(this.dataFilePath, 0o600); - this.logService.info(`Created data file "${this.dataFilePath}" with chmod 600.`); - } else { - this.logService.info(`db file "${this.dataFilePath} already exists"; using existing db`); - } - await this.lockDbFile(() => { - adapter = new FileSync(this.dataFilePath); - }); - } - try { - this.logService.info('Attempting to create lowdb storage adapter.'); - this.db = lowdb(adapter); - this.logService.info('Successfully created lowdb storage adapter.'); - } catch (e) { - if (e instanceof SyntaxError) { - this.logService.warning(`Error creating lowdb storage adapter, "${e.message}"; emptying data file.`); - if (fs.existsSync(this.dataFilePath)) { - const backupPath = this.dataFilePath + '.bak'; - this.logService.warning(`Writing backup of data file to ${backupPath}`); - await fs.copyFile(this.dataFilePath, backupPath, err => { - this.logService.warning(`Error while creating data file backup, "${e.message}". No backup may have been created.`); - }); - } - adapter.write({}); - this.db = lowdb(adapter); - } else { - this.logService.error(`Error creating lowdb storage adapter, "${e.message}".`); - throw e; - } - } - - if (this.defaults != null) { - this.lockDbFile(() => { - this.logService.info('Writing defaults.'); - this.readForNoCache(); - this.db.defaults(this.defaults).write(); - this.logService.info('Successfully wrote defaults to db.'); - }); + try { + this.logService.info("Attempting to create lowdb storage adapter."); + this.db = lowdb(adapter); + this.logService.info("Successfully created lowdb storage adapter."); + } catch (e) { + if (e instanceof SyntaxError) { + this.logService.warning( + `Error creating lowdb storage adapter, "${e.message}"; emptying data file.` + ); + if (fs.existsSync(this.dataFilePath)) { + const backupPath = this.dataFilePath + ".bak"; + this.logService.warning(`Writing backup of data file to ${backupPath}`); + await fs.copyFile(this.dataFilePath, backupPath, (err) => { + this.logService.warning( + `Error while creating data file backup, "${e.message}". No backup may have been created.` + ); + }); } + adapter.write({}); + this.db = lowdb(adapter); + } else { + this.logService.error(`Error creating lowdb storage adapter, "${e.message}".`); + throw e; + } } - get(key: string): Promise { - return this.lockDbFile(() => { - this.readForNoCache(); - const val = this.db.get(key).value(); - this.logService.debug(`Successfully read ${key} from db`); - if (val == null) { - return null; - } - return val as T; - }); + if (this.defaults != null) { + this.lockDbFile(() => { + this.logService.info("Writing defaults."); + this.readForNoCache(); + this.db.defaults(this.defaults).write(); + this.logService.info("Successfully wrote defaults to db."); + }); } + } - has(key: string): Promise { - return this.get(key).then(v => v != null); - } + get(key: string): Promise { + return this.lockDbFile(() => { + this.readForNoCache(); + const val = this.db.get(key).value(); + this.logService.debug(`Successfully read ${key} from db`); + if (val == null) { + return null; + } + return val as T; + }); + } - save(key: string, obj: any): Promise { - return this.lockDbFile(() => { - this.readForNoCache(); - this.db.set(key, obj).write(); - this.logService.debug(`Successfully wrote ${key} to db`); - return; - }); - } + has(key: string): Promise { + return this.get(key).then((v) => v != null); + } - remove(key: string): Promise { - return this.lockDbFile(() => { - this.readForNoCache(); - this.db.unset(key).write(); - this.logService.debug(`Successfully removed ${key} from db`); - return; - }); - } + save(key: string, obj: any): Promise { + return this.lockDbFile(() => { + this.readForNoCache(); + this.db.set(key, obj).write(); + this.logService.debug(`Successfully wrote ${key} to db`); + return; + }); + } - protected async lockDbFile(action: () => T): Promise { - // Lock methods implemented in clients - return Promise.resolve(action()); - } + remove(key: string): Promise { + return this.lockDbFile(() => { + this.readForNoCache(); + this.db.unset(key).write(); + this.logService.debug(`Successfully removed ${key} from db`); + return; + }); + } - private readForNoCache() { - if (!this.allowCache) { - this.db.read(); - } + protected async lockDbFile(action: () => T): Promise { + // Lock methods implemented in clients + return Promise.resolve(action()); + } + + private readForNoCache() { + if (!this.allowCache) { + this.db.read(); } + } } diff --git a/node/src/services/nodeApi.service.ts b/node/src/services/nodeApi.service.ts index 3cfc5bb8..08d85449 100644 --- a/node/src/services/nodeApi.service.ts +++ b/node/src/services/nodeApi.service.ts @@ -1,12 +1,12 @@ -import * as FormData from 'form-data'; -import { HttpsProxyAgent } from 'https-proxy-agent'; -import * as fe from 'node-fetch'; +import * as FormData from "form-data"; +import { HttpsProxyAgent } from "https-proxy-agent"; +import * as fe from "node-fetch"; -import { ApiService } from 'jslib-common/services/api.service'; +import { ApiService } from "jslib-common/services/api.service"; -import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; -import { TokenService } from 'jslib-common/abstractions/token.service'; +import { EnvironmentService } from "jslib-common/abstractions/environment.service"; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; +import { TokenService } from "jslib-common/abstractions/token.service"; (global as any).fetch = fe.default; (global as any).Request = fe.Request; @@ -15,18 +15,23 @@ import { TokenService } from 'jslib-common/abstractions/token.service'; (global as any).FormData = FormData; export class NodeApiService extends ApiService { - constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService, - environmentService: EnvironmentService, logoutCallback: (expired: boolean) => Promise, - customUserAgent: string = null, apiKeyRefresh: (clientId: string, clientSecret: string) => Promise) { - super(tokenService, platformUtilsService, environmentService, logoutCallback, customUserAgent); - this.apiKeyRefresh = apiKeyRefresh; - } + constructor( + tokenService: TokenService, + platformUtilsService: PlatformUtilsService, + environmentService: EnvironmentService, + logoutCallback: (expired: boolean) => Promise, + customUserAgent: string = null, + apiKeyRefresh: (clientId: string, clientSecret: string) => Promise + ) { + super(tokenService, platformUtilsService, environmentService, logoutCallback, customUserAgent); + this.apiKeyRefresh = apiKeyRefresh; + } - nativeFetch(request: Request): Promise { - const proxy = process.env.http_proxy || process.env.https_proxy; - if (proxy) { - (request as any).agent = new HttpsProxyAgent(proxy); - } - return fetch(request); + nativeFetch(request: Request): Promise { + const proxy = process.env.http_proxy || process.env.https_proxy; + if (proxy) { + (request as any).agent = new HttpsProxyAgent(proxy); } + return fetch(request); + } } diff --git a/node/src/services/nodeCryptoFunction.service.ts b/node/src/services/nodeCryptoFunction.service.ts index 5fd6b2c5..dae6fa68 100644 --- a/node/src/services/nodeCryptoFunction.service.ts +++ b/node/src/services/nodeCryptoFunction.service.ts @@ -1,263 +1,302 @@ -import * as crypto from 'crypto'; -import * as forge from 'node-forge'; +import * as crypto from "crypto"; +import * as forge from "node-forge"; -import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; +import { CryptoFunctionService } from "jslib-common/abstractions/cryptoFunction.service"; -import { DecryptParameters } from 'jslib-common/models/domain/decryptParameters'; -import { SymmetricCryptoKey } from 'jslib-common/models/domain/symmetricCryptoKey'; +import { DecryptParameters } from "jslib-common/models/domain/decryptParameters"; +import { SymmetricCryptoKey } from "jslib-common/models/domain/symmetricCryptoKey"; -import { Utils } from 'jslib-common/misc/utils'; +import { Utils } from "jslib-common/misc/utils"; export class NodeCryptoFunctionService implements CryptoFunctionService { - pbkdf2(password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512', - iterations: number): Promise { - const len = algorithm === 'sha256' ? 32 : 64; - const nodePassword = this.toNodeValue(password); - const nodeSalt = this.toNodeValue(salt); - return new Promise((resolve, reject) => { - crypto.pbkdf2(nodePassword, nodeSalt, iterations, len, algorithm, (error, key) => { - if (error != null) { - reject(error); - } else { - resolve(this.toArrayBuffer(key)); - } - }); - }); - } - - // ref: https://tools.ietf.org/html/rfc5869 - async hkdf(ikm: ArrayBuffer, salt: string | ArrayBuffer, info: string | ArrayBuffer, - outputByteSize: number, algorithm: 'sha256' | 'sha512'): Promise { - const saltBuf = this.toArrayBuffer(salt); - const prk = await this.hmac(ikm, saltBuf, algorithm); - return this.hkdfExpand(prk, info, outputByteSize, algorithm); - } - - // ref: https://tools.ietf.org/html/rfc5869 - async hkdfExpand(prk: ArrayBuffer, info: string | ArrayBuffer, outputByteSize: number, - algorithm: 'sha256' | 'sha512'): Promise { - const hashLen = algorithm === 'sha256' ? 32 : 64; - if (outputByteSize > 255 * hashLen) { - throw new Error('outputByteSize is too large.'); - } - const prkArr = new Uint8Array(prk); - if (prkArr.length < hashLen) { - throw new Error('prk is too small.'); - } - const infoBuf = this.toArrayBuffer(info); - const infoArr = new Uint8Array(infoBuf); - let runningOkmLength = 0; - let previousT = new Uint8Array(0); - const n = Math.ceil(outputByteSize / hashLen); - const okm = new Uint8Array(n * hashLen); - for (let i = 0; i < n; i++) { - const t = new Uint8Array(previousT.length + infoArr.length + 1); - t.set(previousT); - t.set(infoArr, previousT.length); - t.set([i + 1], t.length - 1); - previousT = new Uint8Array(await this.hmac(t.buffer, prk, algorithm)); - okm.set(previousT, runningOkmLength); - runningOkmLength += previousT.length; - if (runningOkmLength >= outputByteSize) { - break; - } - } - return okm.slice(0, outputByteSize).buffer; - } - - hash(value: string | ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512' | 'md5'): Promise { - const nodeValue = this.toNodeValue(value); - const hash = crypto.createHash(algorithm); - hash.update(nodeValue); - return Promise.resolve(this.toArrayBuffer(hash.digest())); - } - - hmac(value: ArrayBuffer, key: ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512'): Promise { - const nodeValue = this.toNodeBuffer(value); - const nodeKey = this.toNodeBuffer(key); - const hmac = crypto.createHmac(algorithm, nodeKey); - hmac.update(nodeValue); - return Promise.resolve(this.toArrayBuffer(hmac.digest())); - } - - async compare(a: ArrayBuffer, b: ArrayBuffer): Promise { - const key = await this.randomBytes(32); - const mac1 = await this.hmac(a, key, 'sha256'); - const mac2 = await this.hmac(b, key, 'sha256'); - if (mac1.byteLength !== mac2.byteLength) { - return false; - } - - const arr1 = new Uint8Array(mac1); - const arr2 = new Uint8Array(mac2); - for (let i = 0; i < arr2.length; i++) { - if (arr1[i] !== arr2[i]) { - return false; - } - } - - return true; - } - - hmacFast(value: ArrayBuffer, key: ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512'): Promise { - return this.hmac(value, key, algorithm); - } - - compareFast(a: ArrayBuffer, b: ArrayBuffer): Promise { - return this.compare(a, b); - } - - aesEncrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { - const nodeData = this.toNodeBuffer(data); - const nodeIv = this.toNodeBuffer(iv); - const nodeKey = this.toNodeBuffer(key); - const cipher = crypto.createCipheriv('aes-256-cbc', nodeKey, nodeIv); - const encBuf = Buffer.concat([cipher.update(nodeData), cipher.final()]); - return Promise.resolve(this.toArrayBuffer(encBuf)); - } - - aesDecryptFastParameters(data: string, iv: string, mac: string, key: SymmetricCryptoKey): - DecryptParameters { - const p = new DecryptParameters(); - p.encKey = key.encKey; - p.data = Utils.fromB64ToArray(data).buffer; - p.iv = Utils.fromB64ToArray(iv).buffer; - - const macData = new Uint8Array(p.iv.byteLength + p.data.byteLength); - macData.set(new Uint8Array(p.iv), 0); - macData.set(new Uint8Array(p.data), p.iv.byteLength); - p.macData = macData.buffer; - - if (key.macKey != null) { - p.macKey = key.macKey; - } - if (mac != null) { - p.mac = Utils.fromB64ToArray(mac).buffer; - } - - return p; - } - - async aesDecryptFast(parameters: DecryptParameters): Promise { - const decBuf = await this.aesDecrypt(parameters.data, parameters.iv, parameters.encKey); - return Utils.fromBufferToUtf8(decBuf); - } - - aesDecrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { - const nodeData = this.toNodeBuffer(data); - const nodeIv = this.toNodeBuffer(iv); - const nodeKey = this.toNodeBuffer(key); - const decipher = crypto.createDecipheriv('aes-256-cbc', nodeKey, nodeIv); - const decBuf = Buffer.concat([decipher.update(nodeData), decipher.final()]); - return Promise.resolve(this.toArrayBuffer(decBuf)); - } - - rsaEncrypt(data: ArrayBuffer, publicKey: ArrayBuffer, algorithm: 'sha1' | 'sha256'): Promise { - if (algorithm === 'sha256') { - throw new Error('Node crypto does not support RSA-OAEP SHA-256'); - } - - const pem = this.toPemPublicKey(publicKey); - const decipher = crypto.publicEncrypt(pem, this.toNodeBuffer(data)); - return Promise.resolve(this.toArrayBuffer(decipher)); - } - - rsaDecrypt(data: ArrayBuffer, privateKey: ArrayBuffer, algorithm: 'sha1' | 'sha256'): Promise { - if (algorithm === 'sha256') { - throw new Error('Node crypto does not support RSA-OAEP SHA-256'); - } - - const pem = this.toPemPrivateKey(privateKey); - const decipher = crypto.privateDecrypt(pem, this.toNodeBuffer(data)); - return Promise.resolve(this.toArrayBuffer(decipher)); - } - - rsaExtractPublicKey(privateKey: ArrayBuffer): Promise { - const privateKeyByteString = Utils.fromBufferToByteString(privateKey); - const privateKeyAsn1 = forge.asn1.fromDer(privateKeyByteString); - const forgePrivateKey = (forge as any).pki.privateKeyFromAsn1(privateKeyAsn1); - const forgePublicKey = (forge.pki as any).setRsaPublicKey(forgePrivateKey.n, forgePrivateKey.e); - const publicKeyAsn1 = (forge.pki as any).publicKeyToAsn1(forgePublicKey); - const publicKeyByteString = forge.asn1.toDer(publicKeyAsn1).data; - const publicKeyArray = Utils.fromByteStringToArray(publicKeyByteString); - return Promise.resolve(publicKeyArray.buffer); - } - - async rsaGenerateKeyPair(length: 1024 | 2048 | 4096): Promise<[ArrayBuffer, ArrayBuffer]> { - return new Promise<[ArrayBuffer, ArrayBuffer]>((resolve, reject) => { - forge.pki.rsa.generateKeyPair({ - bits: length, - workers: -1, - e: 0x10001, // 65537 - }, (error, keyPair) => { - if (error != null) { - reject(error); - return; - } - - const publicKeyAsn1 = (forge.pki as any).publicKeyToAsn1(keyPair.publicKey); - const publicKeyByteString = forge.asn1.toDer(publicKeyAsn1).getBytes(); - const publicKey = Utils.fromByteStringToArray(publicKeyByteString); - - const privateKeyAsn1 = (forge.pki as any).privateKeyToAsn1(keyPair.privateKey); - const privateKeyPkcs8 = (forge.pki as any).wrapRsaPrivateKey(privateKeyAsn1); - const privateKeyByteString = forge.asn1.toDer(privateKeyPkcs8).getBytes(); - const privateKey = Utils.fromByteStringToArray(privateKeyByteString); - - resolve([publicKey.buffer, privateKey.buffer]); - }); - }); - } - - randomBytes(length: number): Promise { - return new Promise((resolve, reject) => { - crypto.randomBytes(length, (error, bytes) => { - if (error != null) { - reject(error); - } else { - resolve(this.toArrayBuffer(bytes)); - } - }); - }); - } - - private toNodeValue(value: string | ArrayBuffer): string | Buffer { - let nodeValue: string | Buffer; - if (typeof (value) === 'string') { - nodeValue = value; + pbkdf2( + password: string | ArrayBuffer, + salt: string | ArrayBuffer, + algorithm: "sha256" | "sha512", + iterations: number + ): Promise { + const len = algorithm === "sha256" ? 32 : 64; + const nodePassword = this.toNodeValue(password); + const nodeSalt = this.toNodeValue(salt); + return new Promise((resolve, reject) => { + crypto.pbkdf2(nodePassword, nodeSalt, iterations, len, algorithm, (error, key) => { + if (error != null) { + reject(error); } else { - nodeValue = this.toNodeBuffer(value); + resolve(this.toArrayBuffer(key)); } - return nodeValue; + }); + }); + } + + // ref: https://tools.ietf.org/html/rfc5869 + async hkdf( + ikm: ArrayBuffer, + salt: string | ArrayBuffer, + info: string | ArrayBuffer, + outputByteSize: number, + algorithm: "sha256" | "sha512" + ): Promise { + const saltBuf = this.toArrayBuffer(salt); + const prk = await this.hmac(ikm, saltBuf, algorithm); + return this.hkdfExpand(prk, info, outputByteSize, algorithm); + } + + // ref: https://tools.ietf.org/html/rfc5869 + async hkdfExpand( + prk: ArrayBuffer, + info: string | ArrayBuffer, + outputByteSize: number, + algorithm: "sha256" | "sha512" + ): Promise { + const hashLen = algorithm === "sha256" ? 32 : 64; + if (outputByteSize > 255 * hashLen) { + throw new Error("outputByteSize is too large."); + } + const prkArr = new Uint8Array(prk); + if (prkArr.length < hashLen) { + throw new Error("prk is too small."); + } + const infoBuf = this.toArrayBuffer(info); + const infoArr = new Uint8Array(infoBuf); + let runningOkmLength = 0; + let previousT = new Uint8Array(0); + const n = Math.ceil(outputByteSize / hashLen); + const okm = new Uint8Array(n * hashLen); + for (let i = 0; i < n; i++) { + const t = new Uint8Array(previousT.length + infoArr.length + 1); + t.set(previousT); + t.set(infoArr, previousT.length); + t.set([i + 1], t.length - 1); + previousT = new Uint8Array(await this.hmac(t.buffer, prk, algorithm)); + okm.set(previousT, runningOkmLength); + runningOkmLength += previousT.length; + if (runningOkmLength >= outputByteSize) { + break; + } + } + return okm.slice(0, outputByteSize).buffer; + } + + hash( + value: string | ArrayBuffer, + algorithm: "sha1" | "sha256" | "sha512" | "md5" + ): Promise { + const nodeValue = this.toNodeValue(value); + const hash = crypto.createHash(algorithm); + hash.update(nodeValue); + return Promise.resolve(this.toArrayBuffer(hash.digest())); + } + + hmac( + value: ArrayBuffer, + key: ArrayBuffer, + algorithm: "sha1" | "sha256" | "sha512" + ): Promise { + const nodeValue = this.toNodeBuffer(value); + const nodeKey = this.toNodeBuffer(key); + const hmac = crypto.createHmac(algorithm, nodeKey); + hmac.update(nodeValue); + return Promise.resolve(this.toArrayBuffer(hmac.digest())); + } + + async compare(a: ArrayBuffer, b: ArrayBuffer): Promise { + const key = await this.randomBytes(32); + const mac1 = await this.hmac(a, key, "sha256"); + const mac2 = await this.hmac(b, key, "sha256"); + if (mac1.byteLength !== mac2.byteLength) { + return false; } - private toNodeBuffer(value: ArrayBuffer): Buffer { - return Buffer.from(new Uint8Array(value) as any); + const arr1 = new Uint8Array(mac1); + const arr2 = new Uint8Array(mac2); + for (let i = 0; i < arr2.length; i++) { + if (arr1[i] !== arr2[i]) { + return false; + } } - private toArrayBuffer(value: Buffer | string | ArrayBuffer): ArrayBuffer { - let buf: ArrayBuffer; - if (typeof (value) === 'string') { - buf = Utils.fromUtf8ToArray(value).buffer; + return true; + } + + hmacFast( + value: ArrayBuffer, + key: ArrayBuffer, + algorithm: "sha1" | "sha256" | "sha512" + ): Promise { + return this.hmac(value, key, algorithm); + } + + compareFast(a: ArrayBuffer, b: ArrayBuffer): Promise { + return this.compare(a, b); + } + + aesEncrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { + const nodeData = this.toNodeBuffer(data); + const nodeIv = this.toNodeBuffer(iv); + const nodeKey = this.toNodeBuffer(key); + const cipher = crypto.createCipheriv("aes-256-cbc", nodeKey, nodeIv); + const encBuf = Buffer.concat([cipher.update(nodeData), cipher.final()]); + return Promise.resolve(this.toArrayBuffer(encBuf)); + } + + aesDecryptFastParameters( + data: string, + iv: string, + mac: string, + key: SymmetricCryptoKey + ): DecryptParameters { + const p = new DecryptParameters(); + p.encKey = key.encKey; + p.data = Utils.fromB64ToArray(data).buffer; + p.iv = Utils.fromB64ToArray(iv).buffer; + + const macData = new Uint8Array(p.iv.byteLength + p.data.byteLength); + macData.set(new Uint8Array(p.iv), 0); + macData.set(new Uint8Array(p.data), p.iv.byteLength); + p.macData = macData.buffer; + + if (key.macKey != null) { + p.macKey = key.macKey; + } + if (mac != null) { + p.mac = Utils.fromB64ToArray(mac).buffer; + } + + return p; + } + + async aesDecryptFast(parameters: DecryptParameters): Promise { + const decBuf = await this.aesDecrypt(parameters.data, parameters.iv, parameters.encKey); + return Utils.fromBufferToUtf8(decBuf); + } + + aesDecrypt(data: ArrayBuffer, iv: ArrayBuffer, key: ArrayBuffer): Promise { + const nodeData = this.toNodeBuffer(data); + const nodeIv = this.toNodeBuffer(iv); + const nodeKey = this.toNodeBuffer(key); + const decipher = crypto.createDecipheriv("aes-256-cbc", nodeKey, nodeIv); + const decBuf = Buffer.concat([decipher.update(nodeData), decipher.final()]); + return Promise.resolve(this.toArrayBuffer(decBuf)); + } + + rsaEncrypt( + data: ArrayBuffer, + publicKey: ArrayBuffer, + algorithm: "sha1" | "sha256" + ): Promise { + if (algorithm === "sha256") { + throw new Error("Node crypto does not support RSA-OAEP SHA-256"); + } + + const pem = this.toPemPublicKey(publicKey); + const decipher = crypto.publicEncrypt(pem, this.toNodeBuffer(data)); + return Promise.resolve(this.toArrayBuffer(decipher)); + } + + rsaDecrypt( + data: ArrayBuffer, + privateKey: ArrayBuffer, + algorithm: "sha1" | "sha256" + ): Promise { + if (algorithm === "sha256") { + throw new Error("Node crypto does not support RSA-OAEP SHA-256"); + } + + const pem = this.toPemPrivateKey(privateKey); + const decipher = crypto.privateDecrypt(pem, this.toNodeBuffer(data)); + return Promise.resolve(this.toArrayBuffer(decipher)); + } + + rsaExtractPublicKey(privateKey: ArrayBuffer): Promise { + const privateKeyByteString = Utils.fromBufferToByteString(privateKey); + const privateKeyAsn1 = forge.asn1.fromDer(privateKeyByteString); + const forgePrivateKey = (forge as any).pki.privateKeyFromAsn1(privateKeyAsn1); + const forgePublicKey = (forge.pki as any).setRsaPublicKey(forgePrivateKey.n, forgePrivateKey.e); + const publicKeyAsn1 = (forge.pki as any).publicKeyToAsn1(forgePublicKey); + const publicKeyByteString = forge.asn1.toDer(publicKeyAsn1).data; + const publicKeyArray = Utils.fromByteStringToArray(publicKeyByteString); + return Promise.resolve(publicKeyArray.buffer); + } + + async rsaGenerateKeyPair(length: 1024 | 2048 | 4096): Promise<[ArrayBuffer, ArrayBuffer]> { + return new Promise<[ArrayBuffer, ArrayBuffer]>((resolve, reject) => { + forge.pki.rsa.generateKeyPair( + { + bits: length, + workers: -1, + e: 0x10001, // 65537 + }, + (error, keyPair) => { + if (error != null) { + reject(error); + return; + } + + const publicKeyAsn1 = (forge.pki as any).publicKeyToAsn1(keyPair.publicKey); + const publicKeyByteString = forge.asn1.toDer(publicKeyAsn1).getBytes(); + const publicKey = Utils.fromByteStringToArray(publicKeyByteString); + + const privateKeyAsn1 = (forge.pki as any).privateKeyToAsn1(keyPair.privateKey); + const privateKeyPkcs8 = (forge.pki as any).wrapRsaPrivateKey(privateKeyAsn1); + const privateKeyByteString = forge.asn1.toDer(privateKeyPkcs8).getBytes(); + const privateKey = Utils.fromByteStringToArray(privateKeyByteString); + + resolve([publicKey.buffer, privateKey.buffer]); + } + ); + }); + } + + randomBytes(length: number): Promise { + return new Promise((resolve, reject) => { + crypto.randomBytes(length, (error, bytes) => { + if (error != null) { + reject(error); } else { - buf = new Uint8Array(value).buffer; + resolve(this.toArrayBuffer(bytes)); } - return buf; - } + }); + }); + } - private toPemPrivateKey(key: ArrayBuffer): string { - const byteString = Utils.fromBufferToByteString(key); - const asn1 = forge.asn1.fromDer(byteString); - const privateKey = (forge as any).pki.privateKeyFromAsn1(asn1); - const rsaPrivateKey = (forge.pki as any).privateKeyToAsn1(privateKey); - const privateKeyInfo = (forge.pki as any).wrapRsaPrivateKey(rsaPrivateKey); - return (forge.pki as any).privateKeyInfoToPem(privateKeyInfo); + private toNodeValue(value: string | ArrayBuffer): string | Buffer { + let nodeValue: string | Buffer; + if (typeof value === "string") { + nodeValue = value; + } else { + nodeValue = this.toNodeBuffer(value); } + return nodeValue; + } - private toPemPublicKey(key: ArrayBuffer): string { - const byteString = Utils.fromBufferToByteString(key); - const asn1 = forge.asn1.fromDer(byteString); - const publicKey = (forge as any).pki.publicKeyFromAsn1(asn1); - return (forge.pki as any).publicKeyToPem(publicKey); + private toNodeBuffer(value: ArrayBuffer): Buffer { + return Buffer.from(new Uint8Array(value) as any); + } + + private toArrayBuffer(value: Buffer | string | ArrayBuffer): ArrayBuffer { + let buf: ArrayBuffer; + if (typeof value === "string") { + buf = Utils.fromUtf8ToArray(value).buffer; + } else { + buf = new Uint8Array(value).buffer; } + return buf; + } + + private toPemPrivateKey(key: ArrayBuffer): string { + const byteString = Utils.fromBufferToByteString(key); + const asn1 = forge.asn1.fromDer(byteString); + const privateKey = (forge as any).pki.privateKeyFromAsn1(asn1); + const rsaPrivateKey = (forge.pki as any).privateKeyToAsn1(privateKey); + const privateKeyInfo = (forge.pki as any).wrapRsaPrivateKey(rsaPrivateKey); + return (forge.pki as any).privateKeyInfoToPem(privateKeyInfo); + } + + private toPemPublicKey(key: ArrayBuffer): string { + const byteString = Utils.fromBufferToByteString(key); + const asn1 = forge.asn1.fromDer(byteString); + const publicKey = (forge as any).pki.publicKeyFromAsn1(asn1); + return (forge.pki as any).publicKeyToPem(publicKey); + } } diff --git a/node/tsconfig.json b/node/tsconfig.json index 69844dd1..9836d519 100644 --- a/node/tsconfig.json +++ b/node/tsconfig.json @@ -15,17 +15,9 @@ "outDir": "dist", "types": [], "paths": { - "jslib-common/*": [ - "../common/src/*" - ] + "jslib-common/*": ["../common/src/*"] } }, - "include": [ - "src", - "spec" - ], - "exclude": [ - "node_modules", - "dist" - ] + "include": ["src", "spec"], + "exclude": ["node_modules", "dist"] } diff --git a/spec/common/importers/firefoxCsvImporter.spec.ts b/spec/common/importers/firefoxCsvImporter.spec.ts index 81f31e0d..fc42c6ec 100644 --- a/spec/common/importers/firefoxCsvImporter.spec.ts +++ b/spec/common/importers/firefoxCsvImporter.spec.ts @@ -1,73 +1,73 @@ -import { FirefoxCsvImporter as Importer } from 'jslib-common/importers/firefoxCsvImporter'; +import { FirefoxCsvImporter as Importer } from "jslib-common/importers/firefoxCsvImporter"; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { LoginUriView } from 'jslib-common/models/view/loginUriView'; -import { LoginView } from 'jslib-common/models/view/loginView'; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { LoginUriView } from "jslib-common/models/view/loginUriView"; +import { LoginView } from "jslib-common/models/view/loginView"; -import { data as firefoxAccountsData } from './testData/firefoxCsv/firefoxAccountsData.csv'; -import { data as simplePasswordData } from './testData/firefoxCsv/simplePasswordData.csv'; +import { data as firefoxAccountsData } from "./testData/firefoxCsv/firefoxAccountsData.csv"; +import { data as simplePasswordData } from "./testData/firefoxCsv/simplePasswordData.csv"; const CipherData = [ - { - title: 'should parse password', - csv: simplePasswordData, - expected: Object.assign(new CipherView(), { - id: null, - organizationId: null, - folderId: null, - name: 'example.com', - login: Object.assign(new LoginView(), { - username: 'foo', - password: 'bar', - uris: [ - Object.assign(new LoginUriView(), { - uri: 'https://example.com', - }), - ], - }), - notes: null, - type: 1, - }), - }, - { - title: 'should skip "chrome://FirefoxAccounts"', - csv: firefoxAccountsData, - expected: Object.assign(new CipherView(), { - id: null, - organizationId: null, - folderId: null, - name: 'example.com', - login: Object.assign(new LoginView(), { - username: 'foo', - password: 'bar', - uris: [ - Object.assign(new LoginUriView(), { - uri: 'https://example.com', - }), - ], - }), - notes: null, - type: 1, - }), - }, + { + title: "should parse password", + csv: simplePasswordData, + expected: Object.assign(new CipherView(), { + id: null, + organizationId: null, + folderId: null, + name: "example.com", + login: Object.assign(new LoginView(), { + username: "foo", + password: "bar", + uris: [ + Object.assign(new LoginUriView(), { + uri: "https://example.com", + }), + ], + }), + notes: null, + type: 1, + }), + }, + { + title: 'should skip "chrome://FirefoxAccounts"', + csv: firefoxAccountsData, + expected: Object.assign(new CipherView(), { + id: null, + organizationId: null, + folderId: null, + name: "example.com", + login: Object.assign(new LoginView(), { + username: "foo", + password: "bar", + uris: [ + Object.assign(new LoginUriView(), { + uri: "https://example.com", + }), + ], + }), + notes: null, + type: 1, + }), + }, ]; -describe('Firefox CSV Importer', () => { - CipherData.forEach(data => { - it(data.title, async () => { - const importer = new Importer(); - const result = await importer.parse(data.csv); - expect(result != null).toBe(true); - expect(result.ciphers.length).toBeGreaterThan(0); +describe("Firefox CSV Importer", () => { + CipherData.forEach((data) => { + it(data.title, async () => { + const importer = new Importer(); + const result = await importer.parse(data.csv); + expect(result != null).toBe(true); + expect(result.ciphers.length).toBeGreaterThan(0); - const cipher = result.ciphers.shift(); - let property: keyof typeof data.expected; - for (property in data.expected) { - if (data.expected.hasOwnProperty(property)) { - expect(cipher.hasOwnProperty(property)).toBe(true); - expect(cipher[property]).toEqual(data.expected[property]); - } - } - }); + const cipher = result.ciphers.shift(); + let property: keyof typeof data.expected; + for (property in data.expected) { + if (data.expected.hasOwnProperty(property)) { + expect(cipher.hasOwnProperty(property)).toBe(true); + expect(cipher[property]).toEqual(data.expected[property]); + } + } }); + }); }); diff --git a/spec/common/importers/keepass2XmlImporter.spec.ts b/spec/common/importers/keepass2XmlImporter.spec.ts index abeb4911..ff0f2d14 100644 --- a/spec/common/importers/keepass2XmlImporter.spec.ts +++ b/spec/common/importers/keepass2XmlImporter.spec.ts @@ -1,4 +1,4 @@ -import { KeePass2XmlImporter as Importer } from 'jslib-common/importers/keepass2XmlImporter'; +import { KeePass2XmlImporter as Importer } from "jslib-common/importers/keepass2XmlImporter"; const TestData: string = ` @@ -180,10 +180,10 @@ line2 `; -describe('KeePass2 Xml Importer', () => { - it('should parse XML data', async () => { - const importer = new Importer(); - const result = await importer.parse(TestData); - expect(result != null).toBe(true); - }); +describe("KeePass2 Xml Importer", () => { + it("should parse XML data", async () => { + const importer = new Importer(); + const result = await importer.parse(TestData); + expect(result != null).toBe(true); + }); }); diff --git a/spec/common/importers/lastpassCsvImporter.spec.ts b/spec/common/importers/lastpassCsvImporter.spec.ts index f42ea676..935db38c 100644 --- a/spec/common/importers/lastpassCsvImporter.spec.ts +++ b/spec/common/importers/lastpassCsvImporter.spec.ts @@ -1,33 +1,33 @@ -import { LastPassCsvImporter as Importer } from 'jslib-common/importers/lastpassCsvImporter'; +import { LastPassCsvImporter as Importer } from "jslib-common/importers/lastpassCsvImporter"; -import { ImportResult } from 'jslib-common/models/domain/importResult'; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { FieldView } from 'jslib-common/models/view/fieldView'; +import { ImportResult } from "jslib-common/models/domain/importResult"; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { FieldView } from "jslib-common/models/view/fieldView"; -import { CipherType } from 'jslib-common/enums/cipherType'; -import { FieldType } from 'jslib-common/enums/fieldType'; +import { CipherType } from "jslib-common/enums/cipherType"; +import { FieldType } from "jslib-common/enums/fieldType"; function baseExcept(result: ImportResult) { - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); } function expectLogin(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Login); + expect(cipher.type).toBe(CipherType.Login); - expect(cipher.name).toBe('example.com'); - expect(cipher.notes).toBe('super secure notes'); - expect(cipher.login.uri).toBe('http://example.com'); - expect(cipher.login.username).toBe('someUser'); - expect(cipher.login.password).toBe('myPassword'); - expect(cipher.login.totp).toBe('Y64VEVMBTSXCYIWRSHRNDZW62MPGVU2G'); + expect(cipher.name).toBe("example.com"); + expect(cipher.notes).toBe("super secure notes"); + expect(cipher.login.uri).toBe("http://example.com"); + expect(cipher.login.username).toBe("someUser"); + expect(cipher.login.password).toBe("myPassword"); + expect(cipher.login.totp).toBe("Y64VEVMBTSXCYIWRSHRNDZW62MPGVU2G"); } const CipherData = [ - { - title: 'should parse expiration date', - csv: `url,username,password,extra,name,grouping,fav + { + title: "should parse expiration date", + csv: `url,username,password,extra,name,grouping,fav http://sn,,,"NoteType:Credit Card Name on Card:John Doe Type: @@ -37,32 +37,32 @@ Start Date:October,2017 Expiration Date:June,2020 Notes:some text ",Credit-card,,0`, - expected: Object.assign(new CipherView(), { - id: null, - organizationId: null, - folderId: null, - name: 'Credit-card', - notes: 'some text\n', - type: 3, - card: { - cardholderName: 'John Doe', - number: '1234567812345678', - code: '123', - expYear: '2020', - expMonth: '6', - }, - fields: [ - Object.assign(new FieldView(), { - name: 'Start Date', - value: 'October,2017', - type: FieldType.Text, - }), - ], + expected: Object.assign(new CipherView(), { + id: null, + organizationId: null, + folderId: null, + name: "Credit-card", + notes: "some text\n", + type: 3, + card: { + cardholderName: "John Doe", + number: "1234567812345678", + code: "123", + expYear: "2020", + expMonth: "6", + }, + fields: [ + Object.assign(new FieldView(), { + name: "Start Date", + value: "October,2017", + type: FieldType.Text, }), - }, - { - title: 'should parse blank card note', - csv: `url,username,password,extra,name,grouping,fav + ], + }), + }, + { + title: "should parse blank card note", + csv: `url,username,password,extra,name,grouping,fav http://sn,,,"NoteType:Credit Card Name on Card: Type: @@ -71,28 +71,28 @@ Security Code: Start Date:, Expiration Date:, Notes:",empty,,0`, - expected: Object.assign(new CipherView(), { - id: null, - organizationId: null, - folderId: null, - name: 'empty', - notes: null, - type: 3, - card: { - expMonth: undefined, - }, - fields: [ - Object.assign(new FieldView(), { - name: 'Start Date', - value: ',', - type: FieldType.Text, - }), - ], + expected: Object.assign(new CipherView(), { + id: null, + organizationId: null, + folderId: null, + name: "empty", + notes: null, + type: 3, + card: { + expMonth: undefined, + }, + fields: [ + Object.assign(new FieldView(), { + name: "Start Date", + value: ",", + type: FieldType.Text, }), - }, - { - title: 'should parse card expiration date w/ no exp year', - csv: `url,username,password,extra,name,grouping,fav + ], + }), + }, + { + title: "should parse card expiration date w/ no exp year", + csv: `url,username,password,extra,name,grouping,fav http://sn,,,"NoteType:Credit Card Name on Card:John Doe Type:Visa @@ -101,36 +101,36 @@ Security Code:321 Start Date:, Expiration Date:January, Notes:",noyear,,0`, - expected: Object.assign(new CipherView(), { - id: null, - organizationId: null, - folderId: null, - name: 'noyear', - notes: null, - type: 3, - card: { - cardholderName: 'John Doe', - number: '1234567887654321', - code: '321', - expMonth: '1', - }, - fields: [ - Object.assign(new FieldView(), { - name: 'Type', - value: 'Visa', - type: FieldType.Text, - }), - Object.assign(new FieldView(), { - name: 'Start Date', - value: ',', - type: FieldType.Text, - }), - ], + expected: Object.assign(new CipherView(), { + id: null, + organizationId: null, + folderId: null, + name: "noyear", + notes: null, + type: 3, + card: { + cardholderName: "John Doe", + number: "1234567887654321", + code: "321", + expMonth: "1", + }, + fields: [ + Object.assign(new FieldView(), { + name: "Type", + value: "Visa", + type: FieldType.Text, }), - }, - { - title: 'should parse card expiration date w/ no month', - csv: `url,username,password,extra,name,grouping,fav + Object.assign(new FieldView(), { + name: "Start Date", + value: ",", + type: FieldType.Text, + }), + ], + }), + }, + { + title: "should parse card expiration date w/ no month", + csv: `url,username,password,extra,name,grouping,fav http://sn,,,"NoteType:Credit Card Name on Card:John Doe Type:Mastercard @@ -139,64 +139,64 @@ Security Code:987 Start Date:, Expiration Date:,2020 Notes:",nomonth,,0`, - expected: Object.assign(new CipherView(), { - id: null, - organizationId: null, - folderId: null, - name: 'nomonth', - notes: null, - type: 3, - card: { - cardholderName: 'John Doe', - number: '8765432112345678', - code: '987', - expYear: '2020', - expMonth: undefined, - }, - fields: [ - Object.assign(new FieldView(), { - name: 'Type', - value: 'Mastercard', - type: FieldType.Text, - }), - Object.assign(new FieldView(), { - name: 'Start Date', - value: ',', - type: FieldType.Text, - }), - ], + expected: Object.assign(new CipherView(), { + id: null, + organizationId: null, + folderId: null, + name: "nomonth", + notes: null, + type: 3, + card: { + cardholderName: "John Doe", + number: "8765432112345678", + code: "987", + expYear: "2020", + expMonth: undefined, + }, + fields: [ + Object.assign(new FieldView(), { + name: "Type", + value: "Mastercard", + type: FieldType.Text, }), - }, + Object.assign(new FieldView(), { + name: "Start Date", + value: ",", + type: FieldType.Text, + }), + ], + }), + }, ]; -describe('Lastpass CSV Importer', () => { - CipherData.forEach(data => { - it(data.title, async () => { - const importer = new Importer(); - const result = await importer.parse(data.csv); - expect(result != null).toBe(true); - expect(result.ciphers.length).toBeGreaterThan(0); +describe("Lastpass CSV Importer", () => { + CipherData.forEach((data) => { + it(data.title, async () => { + const importer = new Importer(); + const result = await importer.parse(data.csv); + expect(result != null).toBe(true); + expect(result.ciphers.length).toBeGreaterThan(0); - const cipher = result.ciphers.shift(); - let property: keyof typeof data.expected; - for (property in data.expected) { - if (data.expected.hasOwnProperty(property)) { - expect(cipher.hasOwnProperty(property)).toBe(true); - expect(cipher[property]).toEqual(data.expected[property]); - } - } - }); + const cipher = result.ciphers.shift(); + let property: keyof typeof data.expected; + for (property in data.expected) { + if (data.expected.hasOwnProperty(property)) { + expect(cipher.hasOwnProperty(property)).toBe(true); + expect(cipher[property]).toEqual(data.expected[property]); + } + } }); + }); - it('should parse login with totp', async () => { - const input = `url,username,password,totp,extra,name,grouping,fav + it("should parse login with totp", async () => { + const input = `url,username,password,totp,extra,name,grouping,fav http://example.com,someUser,myPassword,Y64VEVMBTSXCYIWRSHRNDZW62MPGVU2G,super secure notes,example.com,,0`; - const importer = new Importer(); - const result = await importer.parse(input); - baseExcept(result); + const importer = new Importer(); + const result = await importer.parse(input); + baseExcept(result); - const cipher = result.ciphers[0]; - expectLogin(cipher); - }); -}); \ No newline at end of file + const cipher = result.ciphers[0]; + expectLogin(cipher); + }); +}); diff --git a/spec/common/importers/nordpassCsvImporter.spec.ts b/spec/common/importers/nordpassCsvImporter.spec.ts index 4e8cfcbf..7ac99bd2 100644 --- a/spec/common/importers/nordpassCsvImporter.spec.ts +++ b/spec/common/importers/nordpassCsvImporter.spec.ts @@ -1,181 +1,182 @@ -import { NordPassCsvImporter as Importer } from 'jslib-common/importers/nordpassCsvImporter'; +import { NordPassCsvImporter as Importer } from "jslib-common/importers/nordpassCsvImporter"; -import { CipherType } from 'jslib-common/enums/cipherType'; -import { SecureNoteType } from 'jslib-common/enums/secureNoteType'; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { IdentityView } from 'jslib-common/models/view/identityView'; +import { CipherType } from "jslib-common/enums/cipherType"; +import { SecureNoteType } from "jslib-common/enums/secureNoteType"; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { IdentityView } from "jslib-common/models/view/identityView"; -import { data as creditCardData } from './testData/nordpassCsv/nordpass.card.csv'; -import { data as identityData } from './testData/nordpassCsv/nordpass.identity.csv'; -import { data as loginData } from './testData/nordpassCsv/nordpass.login.csv'; -import { data as secureNoteData } from './testData/nordpassCsv/nordpass.secureNote.csv'; +import { data as creditCardData } from "./testData/nordpassCsv/nordpass.card.csv"; +import { data as identityData } from "./testData/nordpassCsv/nordpass.identity.csv"; +import { data as loginData } from "./testData/nordpassCsv/nordpass.login.csv"; +import { data as secureNoteData } from "./testData/nordpassCsv/nordpass.secureNote.csv"; const namesTestData = [ - { - title: 'Given #fullName should set firstName', - fullName: 'MyFirstName', - expected: Object.assign(new IdentityView(), { - firstName: 'MyFirstName', - middleName: null, - lastName: null, - }), - }, - { - title: 'Given #fullName should set first- and lastName', - fullName: 'MyFirstName MyLastName', - expected: Object.assign(new IdentityView(), { - firstName: 'MyFirstName', - middleName: null, - lastName: 'MyLastName', - }), - }, - { - title: 'Given #fullName should set first-, middle and lastName', - fullName: 'MyFirstName MyMiddleName MyLastName', - expected: Object.assign(new IdentityView(), { - firstName: 'MyFirstName', - middleName: 'MyMiddleName', - lastName: 'MyLastName', - }), - }, - { - title: 'Given #fullName should set first-, middle and lastName with Jr', - fullName: 'MyFirstName MyMiddleName MyLastName Jr', - expected: Object.assign(new IdentityView(), { - firstName: 'MyFirstName', - middleName: 'MyMiddleName', - lastName: 'MyLastName Jr', - }), - }, - { - title: 'Given #fullName should set first-, middle and lastName with Jr and III', - fullName: 'MyFirstName MyMiddleName MyLastName Jr III', - expected: Object.assign(new IdentityView(), { - firstName: 'MyFirstName', - middleName: 'MyMiddleName', - lastName: 'MyLastName Jr III', - }), - }, + { + title: "Given #fullName should set firstName", + fullName: "MyFirstName", + expected: Object.assign(new IdentityView(), { + firstName: "MyFirstName", + middleName: null, + lastName: null, + }), + }, + { + title: "Given #fullName should set first- and lastName", + fullName: "MyFirstName MyLastName", + expected: Object.assign(new IdentityView(), { + firstName: "MyFirstName", + middleName: null, + lastName: "MyLastName", + }), + }, + { + title: "Given #fullName should set first-, middle and lastName", + fullName: "MyFirstName MyMiddleName MyLastName", + expected: Object.assign(new IdentityView(), { + firstName: "MyFirstName", + middleName: "MyMiddleName", + lastName: "MyLastName", + }), + }, + { + title: "Given #fullName should set first-, middle and lastName with Jr", + fullName: "MyFirstName MyMiddleName MyLastName Jr", + expected: Object.assign(new IdentityView(), { + firstName: "MyFirstName", + middleName: "MyMiddleName", + lastName: "MyLastName Jr", + }), + }, + { + title: "Given #fullName should set first-, middle and lastName with Jr and III", + fullName: "MyFirstName MyMiddleName MyLastName Jr III", + expected: Object.assign(new IdentityView(), { + firstName: "MyFirstName", + middleName: "MyMiddleName", + lastName: "MyLastName Jr III", + }), + }, ]; - function expectLogin(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Login); + expect(cipher.type).toBe(CipherType.Login); - expect(cipher.name).toBe('SomeVaultItemName'); - expect(cipher.notes).toBe('Some note for the VaultItem'); - expect(cipher.login.uri).toBe('https://example.com'); - expect(cipher.login.username).toBe('hello@bitwarden.com'); - expect(cipher.login.password).toBe('someStrongPassword'); + expect(cipher.name).toBe("SomeVaultItemName"); + expect(cipher.notes).toBe("Some note for the VaultItem"); + expect(cipher.login.uri).toBe("https://example.com"); + expect(cipher.login.username).toBe("hello@bitwarden.com"); + expect(cipher.login.password).toBe("someStrongPassword"); } function expectCreditCard(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Card); + expect(cipher.type).toBe(CipherType.Card); - expect(cipher.name).toBe('SomeVisa'); - expect(cipher.card.brand).toBe('Visa'); - expect(cipher.card.cardholderName).toBe('SomeHolder'); - expect(cipher.card.number).toBe('4024007103939509'); - expect(cipher.card.code).toBe('123'); - expect(cipher.card.expMonth).toBe('1'); - expect(cipher.card.expYear).toBe('22'); + expect(cipher.name).toBe("SomeVisa"); + expect(cipher.card.brand).toBe("Visa"); + expect(cipher.card.cardholderName).toBe("SomeHolder"); + expect(cipher.card.number).toBe("4024007103939509"); + expect(cipher.card.code).toBe("123"); + expect(cipher.card.expMonth).toBe("1"); + expect(cipher.card.expYear).toBe("22"); } function expectIdentity(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Identity); + expect(cipher.type).toBe(CipherType.Identity); - expect(cipher.name).toBe('SomeTitle'); - expect(cipher.identity.fullName).toBe('MyFirstName MyMiddleName MyLastName'); - expect(cipher.identity.firstName).toBe('MyFirstName'); - expect(cipher.identity.middleName).toBe('MyMiddleName'); - expect(cipher.identity.lastName).toBe('MyLastName'); - expect(cipher.identity.email).toBe('hello@bitwarden.com'); - expect(cipher.identity.phone).toBe('123456789'); + expect(cipher.name).toBe("SomeTitle"); + expect(cipher.identity.fullName).toBe("MyFirstName MyMiddleName MyLastName"); + expect(cipher.identity.firstName).toBe("MyFirstName"); + expect(cipher.identity.middleName).toBe("MyMiddleName"); + expect(cipher.identity.lastName).toBe("MyLastName"); + expect(cipher.identity.email).toBe("hello@bitwarden.com"); + expect(cipher.identity.phone).toBe("123456789"); - expect(cipher.identity.address1).toBe('Test street 123'); - expect(cipher.identity.address2).toBe('additional addressinfo'); - expect(cipher.identity.postalCode).toBe('123456'); - expect(cipher.identity.city).toBe('Cologne'); - expect(cipher.identity.state).toBe('North-Rhine-Westphalia'); - expect(cipher.identity.country).toBe('GERMANY'); - expect(cipher.notes).toBe('SomeNoteToMyIdentity'); + expect(cipher.identity.address1).toBe("Test street 123"); + expect(cipher.identity.address2).toBe("additional addressinfo"); + expect(cipher.identity.postalCode).toBe("123456"); + expect(cipher.identity.city).toBe("Cologne"); + expect(cipher.identity.state).toBe("North-Rhine-Westphalia"); + expect(cipher.identity.country).toBe("GERMANY"); + expect(cipher.notes).toBe("SomeNoteToMyIdentity"); } function expectSecureNote(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.SecureNote); + expect(cipher.type).toBe(CipherType.SecureNote); - expect(cipher.name).toBe('MySuperSecureNoteTitle'); - expect(cipher.secureNote.type).toBe(SecureNoteType.Generic); - expect(cipher.notes).toBe('MySuperSecureNote'); + expect(cipher.name).toBe("MySuperSecureNoteTitle"); + expect(cipher.secureNote.type).toBe(SecureNoteType.Generic); + expect(cipher.notes).toBe("MySuperSecureNote"); } -describe('NordPass CSV Importer', () => { - let importer: Importer; - beforeEach(() => { - importer = new Importer(); +describe("NordPass CSV Importer", () => { + let importer: Importer; + beforeEach(() => { + importer = new Importer(); + }); + + it("should parse login records", async () => { + const result = await importer.parse(loginData); + + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectLogin(cipher); + }); + + it("should parse credit card records", async () => { + const result = await importer.parse(creditCardData); + + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectCreditCard(cipher); + }); + + it("should parse identity records", async () => { + const result = await importer.parse( + identityData.replace("#fullName", "MyFirstName MyMiddleName MyLastName") + ); + + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectIdentity(cipher); + }); + + namesTestData.forEach((data) => { + it(data.title.replace("#fullName", data.fullName), async () => { + const result = await importer.parse(identityData.replace("#fullName", data.fullName)); + + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expect(cipher.identity.firstName).toBe(data.expected.firstName); + expect(cipher.identity.middleName).toBe(data.expected.middleName); + expect(cipher.identity.lastName).toBe(data.expected.lastName); }); + }); - it('should parse login records', async () => { - const result = await importer.parse(loginData); + it("should parse secureNote records", async () => { + const result = await importer.parse(secureNoteData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectLogin(cipher); - }); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectSecureNote(cipher); + }); - it('should parse credit card records', async () => { - const result = await importer.parse(creditCardData); + it("should parse an item and create a folder", async () => { + const result = await importer.parse(secureNoteData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectCreditCard(cipher); - }); - - it('should parse identity records', async () => { - const result = await importer.parse(identityData.replace('#fullName', 'MyFirstName MyMiddleName MyLastName')); - - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectIdentity(cipher); - }); - - namesTestData.forEach(data => { - it(data.title.replace('#fullName', data.fullName), async () => { - const result = await importer.parse(identityData.replace('#fullName', data.fullName)); - - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expect(cipher.identity.firstName).toBe(data.expected.firstName); - expect(cipher.identity.middleName).toBe(data.expected.middleName); - expect(cipher.identity.lastName).toBe(data.expected.lastName); - }); - }); - - it('should parse secureNote records', async () => { - const result = await importer.parse(secureNoteData); - - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectSecureNote(cipher); - }); - - it('should parse an item and create a folder', async () => { - const result = await importer.parse(secureNoteData); - - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.folders.length).toBe(1); - const folder = result.folders[0]; - expect(folder.name).toBe('notesFolder'); - }); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.folders.length).toBe(1); + const folder = result.folders[0]; + expect(folder.name).toBe("notesFolder"); + }); }); diff --git a/spec/common/importers/onepassword1PifImporter.spec.ts b/spec/common/importers/onepassword1PifImporter.spec.ts index 4c26a001..ade73e99 100644 --- a/spec/common/importers/onepassword1PifImporter.spec.ts +++ b/spec/common/importers/onepassword1PifImporter.spec.ts @@ -1,513 +1,514 @@ -import { FieldType } from 'jslib-common/enums/fieldType'; -import { OnePassword1PifImporter as Importer } from 'jslib-common/importers/onepasswordImporters/onepassword1PifImporter'; +import { FieldType } from "jslib-common/enums/fieldType"; +import { OnePassword1PifImporter as Importer } from "jslib-common/importers/onepasswordImporters/onepassword1PifImporter"; -const TestData: string = '***aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee***\n' + - JSON.stringify({ - uuid: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', - updatedAt: 1486071244, - securityLevel: 'SL5', - contentsHash: 'aaaaaaaa', - title: 'Imported Entry', - location: 'https://www.google.com', - secureContents: { - fields: [ - { - value: 'user@test.net', - id: 'email-input', - name: 'email', - type: 'T', - designation: 'username', - }, - { - value: 'myservicepassword', - id: 'password-input', - name: 'password', - type: 'P', - designation: 'password', - }, - ], - sections: [ - { - fields: [ - { - k: 'concealed', - n: 'AAAAAAAAAAAABBBBBBBBBBBCCCCCCCCC', - v: 'console-password-123', - t: 'console password', - }, - ], - title: 'Admin Console', - name: 'admin_console', - }, - ], - passwordHistory: [ - { - value: 'old-password', - time: 1447791421, - }, - ], +const TestData: string = + "***aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee***\n" + + JSON.stringify({ + uuid: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + updatedAt: 1486071244, + securityLevel: "SL5", + contentsHash: "aaaaaaaa", + title: "Imported Entry", + location: "https://www.google.com", + secureContents: { + fields: [ + { + value: "user@test.net", + id: "email-input", + name: "email", + type: "T", + designation: "username", }, - URLs: [ + { + value: "myservicepassword", + id: "password-input", + name: "password", + type: "P", + designation: "password", + }, + ], + sections: [ + { + fields: [ { - label: 'website', - url: 'https://www.google.com', + k: "concealed", + n: "AAAAAAAAAAAABBBBBBBBBBBCCCCCCCCC", + v: "console-password-123", + t: "console password", }, - ], - txTimestamp: 1508941334, - createdAt: 1390426636, - typeName: 'webforms.WebForm', - }); + ], + title: "Admin Console", + name: "admin_console", + }, + ], + passwordHistory: [ + { + value: "old-password", + time: 1447791421, + }, + ], + }, + URLs: [ + { + label: "website", + url: "https://www.google.com", + }, + ], + txTimestamp: 1508941334, + createdAt: 1390426636, + typeName: "webforms.WebForm", + }); const WindowsOpVaultTestData = JSON.stringify({ - category: '001', - created: 1544823719, - hmac: 'NtyBmTTPOb88HV3JUKPx1xl/vcMhac9kvCfe/NtszY0=', - k: '**REMOVED LONG LINE FOR LINTER** -Kyle', - tx: 1553395669, - updated: 1553395669, - uuid: '528AB076FB5F4FBF960884B8E01619AC', - overview: { - title: 'Google', - URLs: [ - { - u: 'google.com', - }, - ], - url: 'google.com', - ps: 26, - ainfo: 'googluser', - }, - details: { - passwordHistory: [ - { - value: 'oldpass1', - time: 1553394449, - }, - { - value: 'oldpass2', - time: 1553394457, - }, - { - value: 'oldpass3', - time: 1553394458, - }, - { - value: 'oldpass4', - time: 1553394459, - }, - { - value: 'oldpass5', - time: 1553394460, - }, - { - value: 'oldpass6', - time: 1553394461, - }, - ], + category: "001", + created: 1544823719, + hmac: "NtyBmTTPOb88HV3JUKPx1xl/vcMhac9kvCfe/NtszY0=", + k: "**REMOVED LONG LINE FOR LINTER** -Kyle", + tx: 1553395669, + updated: 1553395669, + uuid: "528AB076FB5F4FBF960884B8E01619AC", + overview: { + title: "Google", + URLs: [ + { + u: "google.com", + }, + ], + url: "google.com", + ps: 26, + ainfo: "googluser", + }, + details: { + passwordHistory: [ + { + value: "oldpass1", + time: 1553394449, + }, + { + value: "oldpass2", + time: 1553394457, + }, + { + value: "oldpass3", + time: 1553394458, + }, + { + value: "oldpass4", + time: 1553394459, + }, + { + value: "oldpass5", + time: 1553394460, + }, + { + value: "oldpass6", + time: 1553394461, + }, + ], + fields: [ + { + type: "T", + id: "username", + name: "username", + value: "googluser", + designation: "username", + }, + { + type: "P", + id: "password", + name: "password", + value: "12345678901", + designation: "password", + }, + ], + notesPlain: "This is a note\r\n\r\nline1\r\nline2", + sections: [ + { + title: "test", + name: "1214FD88CD30405D9EED14BEB4D61B60", fields: [ - { - type: 'T', - id: 'username', - name: 'username', - value: 'googluser', - designation: 'username', - }, - { - type: 'P', - id: 'password', - name: 'password', - value: '12345678901', - designation: 'password', - }, + { + k: "string", + n: "6CC3BD77482D4559A4B8BB2D360F821B", + v: "fgfg", + t: "fgggf", + }, + { + k: "concealed", + n: "5CFE7BCAA1DF4578BBF7EB508959BFF3", + v: "dfgdfgfdg", + t: "pwfield", + }, ], - notesPlain: 'This is a note\r\n\r\nline1\r\nline2', - sections: [ - { - title: 'test', - name: '1214FD88CD30405D9EED14BEB4D61B60', - fields: [ - { - k: 'string', - n: '6CC3BD77482D4559A4B8BB2D360F821B', - v: 'fgfg', - t: 'fgggf', - }, - { - k: 'concealed', - n: '5CFE7BCAA1DF4578BBF7EB508959BFF3', - v: 'dfgdfgfdg', - t: 'pwfield', - }, - ], - }, - ], - }, + }, + ], + }, }); const IdentityTestData = JSON.stringify({ - uuid: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', - updatedAt: 1553365894, - securityLevel: 'SL5', - contentsHash: 'eeeeeeee', - title: 'Test Identity', - secureContents: { - lastname: 'Fritzenberger', - zip: '223344', - birthdate_dd: '11', - homephone: '+49 333 222 111', - company: 'Web Inc.', - firstname: 'Frank', - birthdate_mm: '3', - country: 'de', - sex: 'male', - sections: [ - { - fields: [ - { - k: 'string', - inputTraits: { - autocapitalization: 'Words', - }, - n: 'firstname', - v: 'Frank', - a: { - guarded: 'yes', - }, - t: 'first name', - }, - { - k: 'string', - inputTraits: { - autocapitalization: 'Words', - }, - n: 'initial', - v: 'MD', - a: { - guarded: 'yes', - }, - t: 'initial', - }, - { - k: 'string', - inputTraits: { - autocapitalization: 'Words', - }, - n: 'lastname', - v: 'Fritzenberger', - a: { - guarded: 'yes', - }, - t: 'last name', - }, - { - k: 'menu', - v: 'male', - n: 'sex', - a: { - guarded: 'yes', - }, - t: 'sex', - }, - { - k: 'date', - v: 1552305660, - n: 'birthdate', - a: { - guarded: 'yes', - }, - t: 'birth date', - }, - { - k: 'string', - inputTraits: { - autocapitalization: 'Words', - }, - n: 'occupation', - v: 'Engineer', - a: { - guarded: 'yes', - }, - t: 'occupation', - }, - { - k: 'string', - inputTraits: { - autocapitalization: 'Words', - }, - n: 'company', - v: 'Web Inc.', - a: { - guarded: 'yes', - }, - t: 'company', - }, - { - k: 'string', - inputTraits: { - autocapitalization: 'Words', - }, - n: 'department', - v: 'IT', - a: { - guarded: 'yes', - }, - t: 'department', - }, - { - k: 'string', - inputTraits: { - autocapitalization: 'Words', - }, - n: 'jobtitle', - v: 'Developer', - a: { - guarded: 'yes', - }, - t: 'job title', - }, - ], - title: 'Identification', - name: 'name', + uuid: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + updatedAt: 1553365894, + securityLevel: "SL5", + contentsHash: "eeeeeeee", + title: "Test Identity", + secureContents: { + lastname: "Fritzenberger", + zip: "223344", + birthdate_dd: "11", + homephone: "+49 333 222 111", + company: "Web Inc.", + firstname: "Frank", + birthdate_mm: "3", + country: "de", + sex: "male", + sections: [ + { + fields: [ + { + k: "string", + inputTraits: { + autocapitalization: "Words", }, - { - fields: [ - { - k: 'address', - inputTraits: { - autocapitalization: 'Sentences', - }, - n: 'address', - v: { - street: 'Mainstreet 1', - city: 'Berlin', - country: 'de', - zip: '223344', - }, - a: { - guarded: 'yes', - }, - t: 'address', - }, - { - k: 'phone', - v: '+49 001 222 333 44', - n: 'defphone', - a: { - guarded: 'yes', - }, - t: 'default phone', - }, - { - k: 'phone', - v: '+49 333 222 111', - n: 'homephone', - a: { - guarded: 'yes', - }, - t: 'home', - }, - { - k: 'phone', - n: 'cellphone', - a: { - guarded: 'yes', - }, - t: 'mobile', - }, - { - k: 'phone', - n: 'busphone', - a: { - guarded: 'yes', - }, - t: 'business', - }, - ], - title: 'Address', - name: 'address', + n: "firstname", + v: "Frank", + a: { + guarded: "yes", }, - { - fields: [ - { - k: 'string', - n: 'username', - a: { - guarded: 'yes', - }, - t: 'username', - }, - { - k: 'string', - n: 'reminderq', - t: 'reminder question', - }, - { - k: 'string', - n: 'remindera', - t: 'reminder answer', - }, - { - k: 'string', - inputTraits: { - keyboard: 'EmailAddress', - }, - n: 'email', - v: 'test@web.de', - a: { - guarded: 'yes', - }, - t: 'email', - }, - { - k: 'string', - n: 'website', - inputTraits: { - keyboard: 'URL', - }, - t: 'website', - }, - { - k: 'string', - n: 'icq', - t: 'ICQ', - }, - { - k: 'string', - n: 'skype', - t: 'skype', - }, - { - k: 'string', - n: 'aim', - t: 'AOL/AIM', - }, - { - k: 'string', - n: 'yahoo', - t: 'Yahoo', - }, - { - k: 'string', - n: 'msn', - t: 'MSN', - }, - { - k: 'string', - n: 'forumsig', - t: 'forum signature', - }, - ], - title: 'Internet Details', - name: 'internet', + t: "first name", + }, + { + k: "string", + inputTraits: { + autocapitalization: "Words", }, - { - title: 'Related Items', - name: 'linked items', + n: "initial", + v: "MD", + a: { + guarded: "yes", }, + t: "initial", + }, + { + k: "string", + inputTraits: { + autocapitalization: "Words", + }, + n: "lastname", + v: "Fritzenberger", + a: { + guarded: "yes", + }, + t: "last name", + }, + { + k: "menu", + v: "male", + n: "sex", + a: { + guarded: "yes", + }, + t: "sex", + }, + { + k: "date", + v: 1552305660, + n: "birthdate", + a: { + guarded: "yes", + }, + t: "birth date", + }, + { + k: "string", + inputTraits: { + autocapitalization: "Words", + }, + n: "occupation", + v: "Engineer", + a: { + guarded: "yes", + }, + t: "occupation", + }, + { + k: "string", + inputTraits: { + autocapitalization: "Words", + }, + n: "company", + v: "Web Inc.", + a: { + guarded: "yes", + }, + t: "company", + }, + { + k: "string", + inputTraits: { + autocapitalization: "Words", + }, + n: "department", + v: "IT", + a: { + guarded: "yes", + }, + t: "department", + }, + { + k: "string", + inputTraits: { + autocapitalization: "Words", + }, + n: "jobtitle", + v: "Developer", + a: { + guarded: "yes", + }, + t: "job title", + }, ], - initial: 'MD', - address1: 'Mainstreet 1', - city: 'Berlin', - jobtitle: 'Developer', - occupation: 'Engineer', - department: 'IT', - email: 'test@web.de', - birthdate_yy: '2019', - homephone_local: '+49 333 222 111', - defphone_local: '+49 001 222 333 44', - defphone: '+49 001 222 333 44', - }, - txTimestamp: 1553365894, - createdAt: 1553364679, - typeName: 'identities.Identity', + title: "Identification", + name: "name", + }, + { + fields: [ + { + k: "address", + inputTraits: { + autocapitalization: "Sentences", + }, + n: "address", + v: { + street: "Mainstreet 1", + city: "Berlin", + country: "de", + zip: "223344", + }, + a: { + guarded: "yes", + }, + t: "address", + }, + { + k: "phone", + v: "+49 001 222 333 44", + n: "defphone", + a: { + guarded: "yes", + }, + t: "default phone", + }, + { + k: "phone", + v: "+49 333 222 111", + n: "homephone", + a: { + guarded: "yes", + }, + t: "home", + }, + { + k: "phone", + n: "cellphone", + a: { + guarded: "yes", + }, + t: "mobile", + }, + { + k: "phone", + n: "busphone", + a: { + guarded: "yes", + }, + t: "business", + }, + ], + title: "Address", + name: "address", + }, + { + fields: [ + { + k: "string", + n: "username", + a: { + guarded: "yes", + }, + t: "username", + }, + { + k: "string", + n: "reminderq", + t: "reminder question", + }, + { + k: "string", + n: "remindera", + t: "reminder answer", + }, + { + k: "string", + inputTraits: { + keyboard: "EmailAddress", + }, + n: "email", + v: "test@web.de", + a: { + guarded: "yes", + }, + t: "email", + }, + { + k: "string", + n: "website", + inputTraits: { + keyboard: "URL", + }, + t: "website", + }, + { + k: "string", + n: "icq", + t: "ICQ", + }, + { + k: "string", + n: "skype", + t: "skype", + }, + { + k: "string", + n: "aim", + t: "AOL/AIM", + }, + { + k: "string", + n: "yahoo", + t: "Yahoo", + }, + { + k: "string", + n: "msn", + t: "MSN", + }, + { + k: "string", + n: "forumsig", + t: "forum signature", + }, + ], + title: "Internet Details", + name: "internet", + }, + { + title: "Related Items", + name: "linked items", + }, + ], + initial: "MD", + address1: "Mainstreet 1", + city: "Berlin", + jobtitle: "Developer", + occupation: "Engineer", + department: "IT", + email: "test@web.de", + birthdate_yy: "2019", + homephone_local: "+49 333 222 111", + defphone_local: "+49 001 222 333 44", + defphone: "+49 001 222 333 44", + }, + txTimestamp: 1553365894, + createdAt: 1553364679, + typeName: "identities.Identity", }); -describe('1Password 1Pif Importer', () => { - it('should parse data', async () => { - const importer = new Importer(); - const result = await importer.parse(TestData); - expect(result != null).toBe(true); +describe("1Password 1Pif Importer", () => { + it("should parse data", async () => { + const importer = new Importer(); + const result = await importer.parse(TestData); + expect(result != null).toBe(true); - const cipher = result.ciphers.shift(); - expect(cipher.login.username).toEqual('user@test.net'); - expect(cipher.login.password).toEqual('myservicepassword'); - expect(cipher.login.uris.length).toEqual(1); - const uriView = cipher.login.uris.shift(); - expect(uriView.uri).toEqual('https://www.google.com'); - }); + const cipher = result.ciphers.shift(); + expect(cipher.login.username).toEqual("user@test.net"); + expect(cipher.login.password).toEqual("myservicepassword"); + expect(cipher.login.uris.length).toEqual(1); + const uriView = cipher.login.uris.shift(); + expect(uriView.uri).toEqual("https://www.google.com"); + }); - it('should create concealed field as "hidden" type', async () => { - const importer = new Importer(); - const result = await importer.parse(TestData); - expect(result != null).toBe(true); + it('should create concealed field as "hidden" type', async () => { + const importer = new Importer(); + const result = await importer.parse(TestData); + expect(result != null).toBe(true); - const ciphers = result.ciphers; - expect(ciphers.length).toEqual(1); + const ciphers = result.ciphers; + expect(ciphers.length).toEqual(1); - const cipher = ciphers.shift(); - const fields = cipher.fields; - expect(fields.length).toEqual(1); + const cipher = ciphers.shift(); + const fields = cipher.fields; + expect(fields.length).toEqual(1); - const field = fields.shift(); - expect(field.name).toEqual('console password'); - expect(field.value).toEqual('console-password-123'); - expect(field.type).toEqual(FieldType.Hidden); - }); + const field = fields.shift(); + expect(field.name).toEqual("console password"); + expect(field.value).toEqual("console-password-123"); + expect(field.type).toEqual(FieldType.Hidden); + }); - it('should create identity records', async () => { - const importer = new Importer(); - const result = await importer.parse(IdentityTestData); - expect(result != null).toBe(true); - const cipher = result.ciphers.shift(); - expect(cipher.name).toEqual('Test Identity'); + it("should create identity records", async () => { + const importer = new Importer(); + const result = await importer.parse(IdentityTestData); + expect(result != null).toBe(true); + const cipher = result.ciphers.shift(); + expect(cipher.name).toEqual("Test Identity"); - const identity = cipher.identity; - expect(identity.firstName).toEqual('Frank'); - expect(identity.middleName).toEqual('MD'); - expect(identity.lastName).toEqual('Fritzenberger'); - expect(identity.company).toEqual('Web Inc.'); - expect(identity.address1).toEqual('Mainstreet 1'); - expect(identity.country).toEqual('DE'); - expect(identity.city).toEqual('Berlin'); - expect(identity.postalCode).toEqual('223344'); - expect(identity.phone).toEqual('+49 001 222 333 44'); - expect(identity.email).toEqual('test@web.de'); + const identity = cipher.identity; + expect(identity.firstName).toEqual("Frank"); + expect(identity.middleName).toEqual("MD"); + expect(identity.lastName).toEqual("Fritzenberger"); + expect(identity.company).toEqual("Web Inc."); + expect(identity.address1).toEqual("Mainstreet 1"); + expect(identity.country).toEqual("DE"); + expect(identity.city).toEqual("Berlin"); + expect(identity.postalCode).toEqual("223344"); + expect(identity.phone).toEqual("+49 001 222 333 44"); + expect(identity.email).toEqual("test@web.de"); - // remaining fields as custom fields - expect(cipher.fields.length).toEqual(6); - }); + // remaining fields as custom fields + expect(cipher.fields.length).toEqual(6); + }); - it('should create password history', async () => { - const importer = new Importer(); - const result = await importer.parse(TestData); - const cipher = result.ciphers.shift(); + it("should create password history", async () => { + const importer = new Importer(); + const result = await importer.parse(TestData); + const cipher = result.ciphers.shift(); - expect(cipher.passwordHistory.length).toEqual(1); - const ph = cipher.passwordHistory.shift(); - expect(ph.password).toEqual('old-password'); - expect(ph.lastUsedDate.toISOString()).toEqual('2015-11-17T20:17:01.000Z'); - }); + expect(cipher.passwordHistory.length).toEqual(1); + const ph = cipher.passwordHistory.shift(); + expect(ph.password).toEqual("old-password"); + expect(ph.lastUsedDate.toISOString()).toEqual("2015-11-17T20:17:01.000Z"); + }); - it('should create password history from windows opvault 1pif format', async () => { - const importer = new Importer(); - const result = await importer.parse(WindowsOpVaultTestData); - const cipher = result.ciphers.shift(); + it("should create password history from windows opvault 1pif format", async () => { + const importer = new Importer(); + const result = await importer.parse(WindowsOpVaultTestData); + const cipher = result.ciphers.shift(); - expect(cipher.passwordHistory.length).toEqual(5); - let ph = cipher.passwordHistory.shift(); - expect(ph.password).toEqual('oldpass6'); - expect(ph.lastUsedDate.toISOString()).toEqual('2019-03-24T02:27:41.000Z'); - ph = cipher.passwordHistory.shift(); - expect(ph.password).toEqual('oldpass5'); - expect(ph.lastUsedDate.toISOString()).toEqual('2019-03-24T02:27:40.000Z'); - ph = cipher.passwordHistory.shift(); - expect(ph.password).toEqual('oldpass4'); - expect(ph.lastUsedDate.toISOString()).toEqual('2019-03-24T02:27:39.000Z'); - ph = cipher.passwordHistory.shift(); - expect(ph.password).toEqual('oldpass3'); - expect(ph.lastUsedDate.toISOString()).toEqual('2019-03-24T02:27:38.000Z'); - ph = cipher.passwordHistory.shift(); - expect(ph.password).toEqual('oldpass2'); - expect(ph.lastUsedDate.toISOString()).toEqual('2019-03-24T02:27:37.000Z'); - }); + expect(cipher.passwordHistory.length).toEqual(5); + let ph = cipher.passwordHistory.shift(); + expect(ph.password).toEqual("oldpass6"); + expect(ph.lastUsedDate.toISOString()).toEqual("2019-03-24T02:27:41.000Z"); + ph = cipher.passwordHistory.shift(); + expect(ph.password).toEqual("oldpass5"); + expect(ph.lastUsedDate.toISOString()).toEqual("2019-03-24T02:27:40.000Z"); + ph = cipher.passwordHistory.shift(); + expect(ph.password).toEqual("oldpass4"); + expect(ph.lastUsedDate.toISOString()).toEqual("2019-03-24T02:27:39.000Z"); + ph = cipher.passwordHistory.shift(); + expect(ph.password).toEqual("oldpass3"); + expect(ph.lastUsedDate.toISOString()).toEqual("2019-03-24T02:27:38.000Z"); + ph = cipher.passwordHistory.shift(); + expect(ph.password).toEqual("oldpass2"); + expect(ph.lastUsedDate.toISOString()).toEqual("2019-03-24T02:27:37.000Z"); + }); }); diff --git a/spec/common/importers/onepasswordMacCsvImporter.spec.ts b/spec/common/importers/onepasswordMacCsvImporter.spec.ts index 47326db6..ed643c8d 100644 --- a/spec/common/importers/onepasswordMacCsvImporter.spec.ts +++ b/spec/common/importers/onepasswordMacCsvImporter.spec.ts @@ -1,71 +1,75 @@ -import { OnePasswordMacCsvImporter as Importer } from 'jslib-common/importers/onepasswordImporters/onepasswordMacCsvImporter'; +import { OnePasswordMacCsvImporter as Importer } from "jslib-common/importers/onepasswordImporters/onepasswordMacCsvImporter"; -import { CipherType } from 'jslib-common/enums/cipherType'; -import { CipherView } from 'jslib-common/models/view/cipherView'; +import { CipherType } from "jslib-common/enums/cipherType"; +import { CipherView } from "jslib-common/models/view/cipherView"; -import { data as creditCardData } from './testData/onePasswordCsv/creditCard.mac.csv'; -import { data as identityData } from './testData/onePasswordCsv/identity.mac.csv'; -import { data as multiTypeData } from './testData/onePasswordCsv/multipleItems.mac.csv'; +import { data as creditCardData } from "./testData/onePasswordCsv/creditCard.mac.csv"; +import { data as identityData } from "./testData/onePasswordCsv/identity.mac.csv"; +import { data as multiTypeData } from "./testData/onePasswordCsv/multipleItems.mac.csv"; function expectIdentity(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Identity); + expect(cipher.type).toBe(CipherType.Identity); - expect(cipher.identity).toEqual(jasmine.objectContaining({ - firstName: 'first name', - middleName: 'mi', - lastName: 'last name', - username: 'userNam3', - company: 'bitwarden', - phone: '8005555555', - email: 'email@bitwarden.com', - })); + expect(cipher.identity).toEqual( + jasmine.objectContaining({ + firstName: "first name", + middleName: "mi", + lastName: "last name", + username: "userNam3", + company: "bitwarden", + phone: "8005555555", + email: "email@bitwarden.com", + }) + ); - expect(cipher.notes).toContain('address\ncity state zip\nUnited States'); + expect(cipher.notes).toContain("address\ncity state zip\nUnited States"); } function expectCreditCard(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Card); + expect(cipher.type).toBe(CipherType.Card); - expect(cipher.card).toEqual(jasmine.objectContaining({ - number: '4111111111111111', - code: '111', - cardholderName: 'test', - expMonth: '1', - expYear: '2030', - })); + expect(cipher.card).toEqual( + jasmine.objectContaining({ + number: "4111111111111111", + code: "111", + cardholderName: "test", + expMonth: "1", + expYear: "2030", + }) + ); } -describe('1Password mac CSV Importer', () => { - it('should parse identity records', async () => { - const importer = new Importer(); - const result = await importer.parse(identityData); +describe("1Password mac CSV Importer", () => { + it("should parse identity records", async () => { + const importer = new Importer(); + const result = await importer.parse(identityData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectIdentity(cipher); - }); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectIdentity(cipher); + }); - it('should parse credit card records', async () => { - const importer = new Importer(); - const result = await importer.parse(creditCardData); + it("should parse credit card records", async () => { + const importer = new Importer(); + const result = await importer.parse(creditCardData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectCreditCard(cipher); - }); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectCreditCard(cipher); + }); - it('should parse csv\'s with multiple record type', async () => { - const importer = new Importer(); - const result = await importer.parse(multiTypeData); + it("should parse csv's with multiple record type", async () => { + const importer = new Importer(); + const result = await importer.parse(multiTypeData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(4); - expectIdentity(result.ciphers[1]); - expectCreditCard(result.ciphers[2]); - }); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(4); + expectIdentity(result.ciphers[1]); + expectCreditCard(result.ciphers[2]); + }); }); diff --git a/spec/common/importers/onepasswordWinCsvImporter.spec.ts b/spec/common/importers/onepasswordWinCsvImporter.spec.ts index 3b11d15a..a8415d73 100644 --- a/spec/common/importers/onepasswordWinCsvImporter.spec.ts +++ b/spec/common/importers/onepasswordWinCsvImporter.spec.ts @@ -1,82 +1,88 @@ -import { OnePasswordWinCsvImporter as Importer } from 'jslib-common/importers/onepasswordImporters/onepasswordWinCsvImporter'; +import { OnePasswordWinCsvImporter as Importer } from "jslib-common/importers/onepasswordImporters/onepasswordWinCsvImporter"; -import { CipherType } from 'jslib-common/enums/cipherType'; -import { FieldType } from 'jslib-common/enums/fieldType'; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { FieldView } from 'jslib-common/models/view/fieldView'; +import { CipherType } from "jslib-common/enums/cipherType"; +import { FieldType } from "jslib-common/enums/fieldType"; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { FieldView } from "jslib-common/models/view/fieldView"; -import { data as creditCardData } from './testData/onePasswordCsv/creditCard.windows.csv'; -import { data as identityData } from './testData/onePasswordCsv/identity.windows.csv'; -import { data as multiTypeData } from './testData/onePasswordCsv/multipleItems.windows.csv'; +import { data as creditCardData } from "./testData/onePasswordCsv/creditCard.windows.csv"; +import { data as identityData } from "./testData/onePasswordCsv/identity.windows.csv"; +import { data as multiTypeData } from "./testData/onePasswordCsv/multipleItems.windows.csv"; function expectIdentity(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Identity); + expect(cipher.type).toBe(CipherType.Identity); - expect(cipher.identity).toEqual(jasmine.objectContaining({ - firstName: 'first name', - middleName: 'mi', - lastName: 'last name', - username: 'userNam3', - company: 'bitwarden', - phone: '8005555555', - email: 'email@bitwarden.com', - })); + expect(cipher.identity).toEqual( + jasmine.objectContaining({ + firstName: "first name", + middleName: "mi", + lastName: "last name", + username: "userNam3", + company: "bitwarden", + phone: "8005555555", + email: "email@bitwarden.com", + }) + ); - expect(cipher.fields).toEqual(jasmine.arrayContaining([ - Object.assign(new FieldView(), { - type: FieldType.Text, - name: 'address', - value: 'address city state zip us', - }), - ])); + expect(cipher.fields).toEqual( + jasmine.arrayContaining([ + Object.assign(new FieldView(), { + type: FieldType.Text, + name: "address", + value: "address city state zip us", + }), + ]) + ); } function expectCreditCard(cipher: CipherView) { - expect(cipher.type).toBe(CipherType.Card); + expect(cipher.type).toBe(CipherType.Card); - expect(cipher.card).toEqual(jasmine.objectContaining({ - number: '4111111111111111', - code: '111', - cardholderName: 'test', - expMonth: '1', - expYear: '1970', - })); + expect(cipher.card).toEqual( + jasmine.objectContaining({ + number: "4111111111111111", + code: "111", + cardholderName: "test", + expMonth: "1", + expYear: "1970", + }) + ); } -describe('1Password windows CSV Importer', () => { - let importer: Importer; - beforeEach(() => { - importer = new Importer(); - }); +describe("1Password windows CSV Importer", () => { + let importer: Importer; + beforeEach(() => { + importer = new Importer(); + }); - it('should parse identity records', async () => { - const result = await importer.parse(identityData); + it("should parse identity records", async () => { + const result = await importer.parse(identityData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectIdentity(cipher); - }); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectIdentity(cipher); + }); - it('should parse credit card records', async () => { - const result = await importer.parse(creditCardData); + it("should parse credit card records", async () => { + const result = await importer.parse(creditCardData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(1); - const cipher = result.ciphers[0]; - expectCreditCard(cipher); - }); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(1); + const cipher = result.ciphers[0]; + expectCreditCard(cipher); + }); - it('should parse csv\'s with multiple record types', async () => { - const result = await importer.parse(multiTypeData); + it("should parse csv's with multiple record types", async () => { + const result = await importer.parse(multiTypeData); - expect(result).not.toBeNull(); - expect(result.success).toBe(true); - expect(result.ciphers.length).toBe(4); + expect(result).not.toBeNull(); + expect(result.success).toBe(true); + expect(result.ciphers.length).toBe(4); - expectIdentity(result.ciphers[1]); - expectCreditCard(result.ciphers[2]); - }); + expectIdentity(result.ciphers[1]); + expectCreditCard(result.ciphers[2]); + }); }); diff --git a/spec/common/importers/testData/nordpassCsv/nordpass.secureNote.csv.ts b/spec/common/importers/testData/nordpassCsv/nordpass.secureNote.csv.ts index 7d8c2307..0e4dcb2e 100644 --- a/spec/common/importers/testData/nordpassCsv/nordpass.secureNote.csv.ts +++ b/spec/common/importers/testData/nordpassCsv/nordpass.secureNote.csv.ts @@ -1,3 +1,3 @@ export const data = `name,url,username,password,note,cardholdername,cardnumber,cvc,expirydate,zipcode,folder,full_name,phone_number,email,address1,address2,city,country,state notesFolder,,,,,,,,,,,,,,,,,, -MySuperSecureNoteTitle,,,,MySuperSecureNote,,,,,,notesFolder,,,,,,,,`; \ No newline at end of file +MySuperSecureNoteTitle,,,,MySuperSecureNote,,,,,,notesFolder,,,,,,,,`; diff --git a/spec/common/importers/testData/onePasswordCsv/creditCard.windows.csv.ts b/spec/common/importers/testData/onePasswordCsv/creditCard.windows.csv.ts index f9dd9808..927cabec 100644 --- a/spec/common/importers/testData/onePasswordCsv/creditCard.windows.csv.ts +++ b/spec/common/importers/testData/onePasswordCsv/creditCard.windows.csv.ts @@ -1,2 +1,2 @@ -export const data = `"UUID","TITLE","SCOPE","AUTOSUBMIT","1: CARDHOLDER NAME","2: NUMBER","3: VERIFICATION NUMBER","4: EXPIRY DATE","SECTION 2: SECTION_PZET7LEKRQXZUINIEGH5ABA2UY","SECTION_PZET7LEKRQXZUINIEGH5ABA2UY 1: LABEL" -"sd26pt226etnsijbl3kqzi5bmm","test card","Default","Default","test","4111111111111111","111","1/3/1970 12:23 AM","section","field (phone)"`; +export const data = `"UUID","TITLE","SCOPE","AUTOSUBMIT","1: CARDHOLDER NAME","2: NUMBER","3: VERIFICATION NUMBER","4: EXPIRY DATE","SECTION 2: SECTION_PZET7LEKRQXZUINIEGH5ABA2UY","SECTION_PZET7LEKRQXZUINIEGH5ABA2UY 1: LABEL" +"sd26pt226etnsijbl3kqzi5bmm","test card","Default","Default","test","4111111111111111","111","1/3/1970 12:23 AM","section","field (phone)"`; diff --git a/spec/common/importers/testData/onePasswordCsv/identity.windows.csv.ts b/spec/common/importers/testData/onePasswordCsv/identity.windows.csv.ts index 3e198e17..d936b42b 100644 --- a/spec/common/importers/testData/onePasswordCsv/identity.windows.csv.ts +++ b/spec/common/importers/testData/onePasswordCsv/identity.windows.csv.ts @@ -1,2 +1,2 @@ -export const data = `"UUID","TITLE","SCOPE","AUTOSUBMIT","TAGS","NOTES","SECTION 1: NAME","NAME 1: FIRST NAME","NAME 2: INITIAL","NAME 3: LAST NAME","NAME 4: BIRTH DATE","NAME 5: OCCUPATION","NAME 6: COMPANY","NAME 7: DEPARTMENT","NAME 8: JOB TITLE","SECTION 2: ADDRESS","ADDRESS 1: ADDRESS","ADDRESS 2: DEFAULT PHONE","SECTION 3: INTERNET","INTERNET 1: USERNAME","INTERNET 2: EMAIL","SECTION 4: MFJQKMWEOYDZDFH4YMR7WLJKIY","MFJQKMWEOYDZDFH4YMR7WLJKIY 1: SECTION FIELD","MFJQKMWEOYDZDFH4YMR7WLJKIY 2: SECTION FIELD" -"6v56y5z4tejwg37jsettta7d7m","Identity Item","Default","Default","Starter Kit","It’s you! 🖐 Select Edit to fill in more details, like your address and contact information.","Identification","first name","mi","last name","12/2/2020 4:01 AM","occupation","bitwarden","department","job title","Address","address city state zip us","8005555555","Internet Details","userNam3","email@bitwarden.com","💡 Did you know?","1Password can fill names and addresses into webpages:","https://support.1password.com/credit-card-address-filling/"`; +export const data = `"UUID","TITLE","SCOPE","AUTOSUBMIT","TAGS","NOTES","SECTION 1: NAME","NAME 1: FIRST NAME","NAME 2: INITIAL","NAME 3: LAST NAME","NAME 4: BIRTH DATE","NAME 5: OCCUPATION","NAME 6: COMPANY","NAME 7: DEPARTMENT","NAME 8: JOB TITLE","SECTION 2: ADDRESS","ADDRESS 1: ADDRESS","ADDRESS 2: DEFAULT PHONE","SECTION 3: INTERNET","INTERNET 1: USERNAME","INTERNET 2: EMAIL","SECTION 4: MFJQKMWEOYDZDFH4YMR7WLJKIY","MFJQKMWEOYDZDFH4YMR7WLJKIY 1: SECTION FIELD","MFJQKMWEOYDZDFH4YMR7WLJKIY 2: SECTION FIELD" +"6v56y5z4tejwg37jsettta7d7m","Identity Item","Default","Default","Starter Kit","It’s you! 🖐 Select Edit to fill in more details, like your address and contact information.","Identification","first name","mi","last name","12/2/2020 4:01 AM","occupation","bitwarden","department","job title","Address","address city state zip us","8005555555","Internet Details","userNam3","email@bitwarden.com","💡 Did you know?","1Password can fill names and addresses into webpages:","https://support.1password.com/credit-card-address-filling/"`; diff --git a/spec/common/importers/testData/onePasswordCsv/multipleItems.windows.csv.ts b/spec/common/importers/testData/onePasswordCsv/multipleItems.windows.csv.ts index 918b7a52..08733e7c 100644 --- a/spec/common/importers/testData/onePasswordCsv/multipleItems.windows.csv.ts +++ b/spec/common/importers/testData/onePasswordCsv/multipleItems.windows.csv.ts @@ -1,5 +1,5 @@ -export const data = `"UUID","TITLE","USERNAME","PASSWORD","URL","URLS","EMAIL","MASTER-PASSWORD","ACCOUNT-KEY","SCOPE","AUTOSUBMIT","TAGS","NOTES","SECTION 1: WXHDKEQREE3TH6QRFCPFPSD3AE","WXHDKEQREE3TH6QRFCPFPSD3AE 1: SECRET KEY","SECTION 1: NAME","NAME 1: FIRST NAME","NAME 2: INITIAL","NAME 3: LAST NAME","NAME 4: BIRTH DATE","NAME 5: OCCUPATION","NAME 6: COMPANY","NAME 7: DEPARTMENT","NAME 8: JOB TITLE","SECTION 2: ADDRESS","ADDRESS 1: ADDRESS","ADDRESS 2: DEFAULT PHONE","SECTION 3: INTERNET","INTERNET 1: USERNAME","INTERNET 2: EMAIL","SECTION 4: MFJQKMWEOYDZDFH4YMR7WLJKIY","MFJQKMWEOYDZDFH4YMR7WLJKIY 1: SECTION FIELD","MFJQKMWEOYDZDFH4YMR7WLJKIY 2: SECTION FIELD","1: CARDHOLDER NAME","2: NUMBER","3: VERIFICATION NUMBER","4: EXPIRY DATE","SECTION 2: SECTION_PZET7LEKRQXZUINIEGH5ABA2UY","SECTION_PZET7LEKRQXZUINIEGH5ABA2UY 1: LABEL","SECTION 1: 4PQVXPR4BMOPGC3DBMTP5U4OFY","4PQVXPR4BMOPGC3DBMTP5U4OFY 1: SECTION FIELD","4PQVXPR4BMOPGC3DBMTP5U4OFY 2: SECTION FIELD","SECTION 2: M2NTUZZBFOFTPAYXVXE6EMZ5JU","M2NTUZZBFOFTPAYXVXE6EMZ5JU 1: SECTION FIELD","M2NTUZZBFOFTPAYXVXE6EMZ5JU 2: SECTION FIELD","SECTION 3: WC3KPAWH6ZAEQB2ARJB6WYZ3DQ","WC3KPAWH6ZAEQB2ARJB6WYZ3DQ 1: SECTION FIELD","WC3KPAWH6ZAEQB2ARJB6WYZ3DQ 2: SECTION FIELD","WC3KPAWH6ZAEQB2ARJB6WYZ3DQ 3: SECTION FIELD","SECTION 4: TOHUYJEJEMGMI6GEQAZ2LJODFE","TOHUYJEJEMGMI6GEQAZ2LJODFE 1: SECTION FIELD","TOHUYJEJEMGMI6GEQAZ2LJODFE 2: SECTION FIELD","SECTION 5: O26UWJJTXRAANG3ONYYOUUJHDM","O26UWJJTXRAANG3ONYYOUUJHDM 1: SECTION FIELD","O26UWJJTXRAANG3ONYYOUUJHDM 2: WATCH VIDEOS","O26UWJJTXRAANG3ONYYOUUJHDM 3: GET SUPPORT","O26UWJJTXRAANG3ONYYOUUJHDM 4: READ THE BLOG","O26UWJJTXRAANG3ONYYOUUJHDM 5: CONTACT US" -"xjq32axcswefpcxu2mtxxqnufa","1Password Account","email@bitwarden.com","the account's password","https://my.1password.com","https://my.1password.com","email@bitwarden.com","the account's password","A3-76TR2N-NJG3TZ-9NXFX-WT8GF-6YQC9-R2659","Default","Default","Starter Kit","You can use this login to sign in to your account on 1password.com.","🔑 Secret Key","the account's secret key","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","" -"6v56y5z4tejwg37jsettta7d7m","Identity Item","","","","","","","","Default","Default","Starter Kit","It’s you! 🖐 Select Edit to fill in more details, like your address and contact information.","","","Identification","first name","mi","last name","12/2/2020 4:01 AM","occupation","bitwarden","department","job title","Address","address city state zip us","8005555555","Internet Details","userNam3","email@bitwarden.com","💡 Did you know?","1Password can fill names and addresses into webpages:","https://support.1password.com/credit-card-address-filling/","","","","","","","","","","","","","","","","","","","","","","","","","" -"sd26pt226etnsijbl3kqzi5bmm","test card","","","","","","","","Default","Default","","","","","","","","","","","","","","","","","","","","","","","test","4111111111111111","111","1/3/1970 12:23 AM","section","field (phone)","","","","","","","","","","","","","","","","","","","" -"oml2sgit3yk7737kxdis65o4xq","🎉 Welcome to 1Password!","","","","","","","","Default","Default","Starter Kit","Follow these steps to get started.","","","","","","","","","","","","","","","","","","","","","","","","","","","1️⃣ Get the apps","https://1password.com/downloads","Install 1Password everywhere you need your passwords.","2️⃣ Get 1Password in your browser","https://1password.com/downloads/#browsers","Install 1Password in your browser to save and fill passwords.","3️⃣ Save your first password","1. Sign in to your favorite website.","2. 1Password will ask to save your username and password.","3. Click Save Login.","4️⃣ Fill passwords and more","https://support.1password.com/explore/extension/","Save and fill passwords, credit cards, and addresses.","📚 Learn 1Password","Check out our videos and articles:","https://youtube.com/1PasswordVideos","https://support.1password.com/","https://blog.1password.com/","https://support.1password.com/contact-us/"`; +export const data = `"UUID","TITLE","USERNAME","PASSWORD","URL","URLS","EMAIL","MASTER-PASSWORD","ACCOUNT-KEY","SCOPE","AUTOSUBMIT","TAGS","NOTES","SECTION 1: WXHDKEQREE3TH6QRFCPFPSD3AE","WXHDKEQREE3TH6QRFCPFPSD3AE 1: SECRET KEY","SECTION 1: NAME","NAME 1: FIRST NAME","NAME 2: INITIAL","NAME 3: LAST NAME","NAME 4: BIRTH DATE","NAME 5: OCCUPATION","NAME 6: COMPANY","NAME 7: DEPARTMENT","NAME 8: JOB TITLE","SECTION 2: ADDRESS","ADDRESS 1: ADDRESS","ADDRESS 2: DEFAULT PHONE","SECTION 3: INTERNET","INTERNET 1: USERNAME","INTERNET 2: EMAIL","SECTION 4: MFJQKMWEOYDZDFH4YMR7WLJKIY","MFJQKMWEOYDZDFH4YMR7WLJKIY 1: SECTION FIELD","MFJQKMWEOYDZDFH4YMR7WLJKIY 2: SECTION FIELD","1: CARDHOLDER NAME","2: NUMBER","3: VERIFICATION NUMBER","4: EXPIRY DATE","SECTION 2: SECTION_PZET7LEKRQXZUINIEGH5ABA2UY","SECTION_PZET7LEKRQXZUINIEGH5ABA2UY 1: LABEL","SECTION 1: 4PQVXPR4BMOPGC3DBMTP5U4OFY","4PQVXPR4BMOPGC3DBMTP5U4OFY 1: SECTION FIELD","4PQVXPR4BMOPGC3DBMTP5U4OFY 2: SECTION FIELD","SECTION 2: M2NTUZZBFOFTPAYXVXE6EMZ5JU","M2NTUZZBFOFTPAYXVXE6EMZ5JU 1: SECTION FIELD","M2NTUZZBFOFTPAYXVXE6EMZ5JU 2: SECTION FIELD","SECTION 3: WC3KPAWH6ZAEQB2ARJB6WYZ3DQ","WC3KPAWH6ZAEQB2ARJB6WYZ3DQ 1: SECTION FIELD","WC3KPAWH6ZAEQB2ARJB6WYZ3DQ 2: SECTION FIELD","WC3KPAWH6ZAEQB2ARJB6WYZ3DQ 3: SECTION FIELD","SECTION 4: TOHUYJEJEMGMI6GEQAZ2LJODFE","TOHUYJEJEMGMI6GEQAZ2LJODFE 1: SECTION FIELD","TOHUYJEJEMGMI6GEQAZ2LJODFE 2: SECTION FIELD","SECTION 5: O26UWJJTXRAANG3ONYYOUUJHDM","O26UWJJTXRAANG3ONYYOUUJHDM 1: SECTION FIELD","O26UWJJTXRAANG3ONYYOUUJHDM 2: WATCH VIDEOS","O26UWJJTXRAANG3ONYYOUUJHDM 3: GET SUPPORT","O26UWJJTXRAANG3ONYYOUUJHDM 4: READ THE BLOG","O26UWJJTXRAANG3ONYYOUUJHDM 5: CONTACT US" +"xjq32axcswefpcxu2mtxxqnufa","1Password Account","email@bitwarden.com","the account's password","https://my.1password.com","https://my.1password.com","email@bitwarden.com","the account's password","A3-76TR2N-NJG3TZ-9NXFX-WT8GF-6YQC9-R2659","Default","Default","Starter Kit","You can use this login to sign in to your account on 1password.com.","🔑 Secret Key","the account's secret key","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","" +"6v56y5z4tejwg37jsettta7d7m","Identity Item","","","","","","","","Default","Default","Starter Kit","It’s you! 🖐 Select Edit to fill in more details, like your address and contact information.","","","Identification","first name","mi","last name","12/2/2020 4:01 AM","occupation","bitwarden","department","job title","Address","address city state zip us","8005555555","Internet Details","userNam3","email@bitwarden.com","💡 Did you know?","1Password can fill names and addresses into webpages:","https://support.1password.com/credit-card-address-filling/","","","","","","","","","","","","","","","","","","","","","","","","","" +"sd26pt226etnsijbl3kqzi5bmm","test card","","","","","","","","Default","Default","","","","","","","","","","","","","","","","","","","","","","","test","4111111111111111","111","1/3/1970 12:23 AM","section","field (phone)","","","","","","","","","","","","","","","","","","","" +"oml2sgit3yk7737kxdis65o4xq","🎉 Welcome to 1Password!","","","","","","","","Default","Default","Starter Kit","Follow these steps to get started.","","","","","","","","","","","","","","","","","","","","","","","","","","","1️⃣ Get the apps","https://1password.com/downloads","Install 1Password everywhere you need your passwords.","2️⃣ Get 1Password in your browser","https://1password.com/downloads/#browsers","Install 1Password in your browser to save and fill passwords.","3️⃣ Save your first password","1. Sign in to your favorite website.","2. 1Password will ask to save your username and password.","3. Click Save Login.","4️⃣ Fill passwords and more","https://support.1password.com/explore/extension/","Save and fill passwords, credit cards, and addresses.","📚 Learn 1Password","Check out our videos and articles:","https://youtube.com/1PasswordVideos","https://support.1password.com/","https://blog.1password.com/","https://support.1password.com/contact-us/"`; diff --git a/spec/common/importers/testData/safeInCloud/testData.xml.ts b/spec/common/importers/testData/safeInCloud/testData.xml.ts index 5f11612d..4c3d7b77 100644 --- a/spec/common/importers/testData/safeInCloud/testData.xml.ts +++ b/spec/common/importers/testData/safeInCloud/testData.xml.ts @@ -59,4 +59,4 @@ export const data = ` 3 -`; \ No newline at end of file +`; diff --git a/spec/common/misc/sequentialize.spec.ts b/spec/common/misc/sequentialize.spec.ts index e347a786..4165eca2 100644 --- a/spec/common/misc/sequentialize.spec.ts +++ b/spec/common/misc/sequentialize.spec.ts @@ -1,141 +1,127 @@ -import { sequentialize } from 'jslib-common/misc/sequentialize'; +import { sequentialize } from "jslib-common/misc/sequentialize"; -describe('sequentialize decorator', () => { - it('should call the function once', async () => { - const foo = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.bar(1)); - } - await Promise.all(promises); +describe("sequentialize decorator", () => { + it("should call the function once", async () => { + const foo = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.bar(1)); + } + await Promise.all(promises); - expect(foo.calls).toBe(1); - }); + expect(foo.calls).toBe(1); + }); - it('should call the function once for each instance of the object', async () => { - const foo = new Foo(); - const foo2 = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.bar(1)); - promises.push(foo2.bar(1)); - } - await Promise.all(promises); + it("should call the function once for each instance of the object", async () => { + const foo = new Foo(); + const foo2 = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.bar(1)); + promises.push(foo2.bar(1)); + } + await Promise.all(promises); - expect(foo.calls).toBe(1); - expect(foo2.calls).toBe(1); - }); + expect(foo.calls).toBe(1); + expect(foo2.calls).toBe(1); + }); - it('should call the function once with key function', async () => { - const foo = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.baz(1)); - } - await Promise.all(promises); + it("should call the function once with key function", async () => { + const foo = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.baz(1)); + } + await Promise.all(promises); - expect(foo.calls).toBe(1); - }); + expect(foo.calls).toBe(1); + }); - it('should call the function again when already resolved', async () => { - const foo = new Foo(); - await foo.bar(1); - expect(foo.calls).toBe(1); - await foo.bar(1); - expect(foo.calls).toBe(2); - }); + it("should call the function again when already resolved", async () => { + const foo = new Foo(); + await foo.bar(1); + expect(foo.calls).toBe(1); + await foo.bar(1); + expect(foo.calls).toBe(2); + }); - it('should call the function again when already resolved with a key function', async () => { - const foo = new Foo(); - await foo.baz(1); - expect(foo.calls).toBe(1); - await foo.baz(1); - expect(foo.calls).toBe(2); - }); + it("should call the function again when already resolved with a key function", async () => { + const foo = new Foo(); + await foo.baz(1); + expect(foo.calls).toBe(1); + await foo.baz(1); + expect(foo.calls).toBe(2); + }); - it('should call the function for each argument', async () => { - const foo = new Foo(); - await Promise.all([ - foo.bar(1), - foo.bar(1), - foo.bar(2), - foo.bar(2), - foo.bar(3), - foo.bar(3), - ]); - expect(foo.calls).toBe(3); - }); + it("should call the function for each argument", async () => { + const foo = new Foo(); + await Promise.all([foo.bar(1), foo.bar(1), foo.bar(2), foo.bar(2), foo.bar(3), foo.bar(3)]); + expect(foo.calls).toBe(3); + }); - it('should call the function for each argument with key function', async () => { - const foo = new Foo(); - await Promise.all([ - foo.baz(1), - foo.baz(1), - foo.baz(2), - foo.baz(2), - foo.baz(3), - foo.baz(3), - ]); - expect(foo.calls).toBe(3); - }); + it("should call the function for each argument with key function", async () => { + const foo = new Foo(); + await Promise.all([foo.baz(1), foo.baz(1), foo.baz(2), foo.baz(2), foo.baz(3), foo.baz(3)]); + expect(foo.calls).toBe(3); + }); - it('should return correct result for each call', async () => { - const foo = new Foo(); - const allRes: number[] = []; + it("should return correct result for each call", async () => { + const foo = new Foo(); + const allRes: number[] = []; - await Promise.all([ - foo.bar(1).then(res => allRes.push(res)), - foo.bar(1).then(res => allRes.push(res)), - foo.bar(2).then(res => allRes.push(res)), - foo.bar(2).then(res => allRes.push(res)), - foo.bar(3).then(res => allRes.push(res)), - foo.bar(3).then(res => allRes.push(res)), - ]); - expect(foo.calls).toBe(3); - expect(allRes.length).toBe(6); - allRes.sort(); - expect(allRes).toEqual([2, 2, 4, 4, 6, 6]); - }); + await Promise.all([ + foo.bar(1).then((res) => allRes.push(res)), + foo.bar(1).then((res) => allRes.push(res)), + foo.bar(2).then((res) => allRes.push(res)), + foo.bar(2).then((res) => allRes.push(res)), + foo.bar(3).then((res) => allRes.push(res)), + foo.bar(3).then((res) => allRes.push(res)), + ]); + expect(foo.calls).toBe(3); + expect(allRes.length).toBe(6); + allRes.sort(); + expect(allRes).toEqual([2, 2, 4, 4, 6, 6]); + }); - it('should return correct result for each call with key function', async () => { - const foo = new Foo(); - const allRes: number[] = []; + it("should return correct result for each call with key function", async () => { + const foo = new Foo(); + const allRes: number[] = []; - await Promise.all([ - foo.baz(1).then(res => allRes.push(res)), - foo.baz(1).then(res => allRes.push(res)), - foo.baz(2).then(res => allRes.push(res)), - foo.baz(2).then(res => allRes.push(res)), - foo.baz(3).then(res => allRes.push(res)), - foo.baz(3).then(res => allRes.push(res)), - ]); - expect(foo.calls).toBe(3); - expect(allRes.length).toBe(6); - allRes.sort(); - expect(allRes).toEqual([3, 3, 6, 6, 9, 9]); - }); + await Promise.all([ + foo.baz(1).then((res) => allRes.push(res)), + foo.baz(1).then((res) => allRes.push(res)), + foo.baz(2).then((res) => allRes.push(res)), + foo.baz(2).then((res) => allRes.push(res)), + foo.baz(3).then((res) => allRes.push(res)), + foo.baz(3).then((res) => allRes.push(res)), + ]); + expect(foo.calls).toBe(3); + expect(allRes.length).toBe(6); + allRes.sort(); + expect(allRes).toEqual([3, 3, 6, 6, 9, 9]); + }); }); class Foo { - calls = 0; + calls = 0; - @sequentialize(args => 'bar' + args[0]) - bar(a: number): Promise { - this.calls++; - return new Promise(res => { - setTimeout(() => { - res(a * 2); - }, Math.random() * 100); - }); - } + @sequentialize((args) => "bar" + args[0]) + bar(a: number): Promise { + this.calls++; + return new Promise((res) => { + setTimeout(() => { + res(a * 2); + }, Math.random() * 100); + }); + } - @sequentialize(args => 'baz' + args[0]) - baz(a: number): Promise { - this.calls++; - return new Promise(res => { - setTimeout(() => { - res(a * 3); - }, Math.random() * 100); - }); - } + @sequentialize((args) => "baz" + args[0]) + baz(a: number): Promise { + this.calls++; + return new Promise((res) => { + setTimeout(() => { + res(a * 3); + }, Math.random() * 100); + }); + } } diff --git a/spec/common/misc/throttle.spec.ts b/spec/common/misc/throttle.spec.ts index c61e2aef..5a8cd27e 100644 --- a/spec/common/misc/throttle.spec.ts +++ b/spec/common/misc/throttle.spec.ts @@ -1,110 +1,110 @@ -import { sequentialize } from 'jslib-common/misc/sequentialize'; -import { throttle } from 'jslib-common/misc/throttle'; +import { sequentialize } from "jslib-common/misc/sequentialize"; +import { throttle } from "jslib-common/misc/throttle"; -describe('throttle decorator', () => { - it('should call the function once at a time', async () => { - const foo = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.bar(1)); - } - await Promise.all(promises); +describe("throttle decorator", () => { + it("should call the function once at a time", async () => { + const foo = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.bar(1)); + } + await Promise.all(promises); - expect(foo.calls).toBe(10); - }); + expect(foo.calls).toBe(10); + }); - it('should call the function once at a time for each object', async () => { - const foo = new Foo(); - const foo2 = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.bar(1)); - promises.push(foo2.bar(1)); - } - await Promise.all(promises); + it("should call the function once at a time for each object", async () => { + const foo = new Foo(); + const foo2 = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.bar(1)); + promises.push(foo2.bar(1)); + } + await Promise.all(promises); - expect(foo.calls).toBe(10); - expect(foo2.calls).toBe(10); - }); + expect(foo.calls).toBe(10); + expect(foo2.calls).toBe(10); + }); - it('should call the function limit at a time', async () => { - const foo = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.baz(1)); - } - await Promise.all(promises); + it("should call the function limit at a time", async () => { + const foo = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.baz(1)); + } + await Promise.all(promises); - expect(foo.calls).toBe(10); - }); + expect(foo.calls).toBe(10); + }); - it('should call the function limit at a time for each object', async () => { - const foo = new Foo(); - const foo2 = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.baz(1)); - promises.push(foo2.baz(1)); - } - await Promise.all(promises); + it("should call the function limit at a time for each object", async () => { + const foo = new Foo(); + const foo2 = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.baz(1)); + promises.push(foo2.baz(1)); + } + await Promise.all(promises); - expect(foo.calls).toBe(10); - expect(foo2.calls).toBe(10); - }); + expect(foo.calls).toBe(10); + expect(foo2.calls).toBe(10); + }); - it('should work together with sequentialize', async () => { - const foo = new Foo(); - const promises = []; - for (let i = 0; i < 10; i++) { - promises.push(foo.qux(Math.floor(i / 2) * 2)); - } - await Promise.all(promises); + it("should work together with sequentialize", async () => { + const foo = new Foo(); + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(foo.qux(Math.floor(i / 2) * 2)); + } + await Promise.all(promises); - expect(foo.calls).toBe(5); - }); + expect(foo.calls).toBe(5); + }); }); class Foo { - calls = 0; - inflight = 0; + calls = 0; + inflight = 0; - @throttle(1, () => 'bar') - bar(a: number) { - this.calls++; - this.inflight++; - return new Promise(res => { - setTimeout(() => { - expect(this.inflight).toBe(1); - this.inflight--; - res(a * 2); - }, Math.random() * 10); - }); - } + @throttle(1, () => "bar") + bar(a: number) { + this.calls++; + this.inflight++; + return new Promise((res) => { + setTimeout(() => { + expect(this.inflight).toBe(1); + this.inflight--; + res(a * 2); + }, Math.random() * 10); + }); + } - @throttle(5, () => 'baz') - baz(a: number) { - this.calls++; - this.inflight++; - return new Promise(res => { - setTimeout(() => { - expect(this.inflight).toBeLessThanOrEqual(5); - this.inflight--; - res(a * 3); - }, Math.random() * 10); - }); - } + @throttle(5, () => "baz") + baz(a: number) { + this.calls++; + this.inflight++; + return new Promise((res) => { + setTimeout(() => { + expect(this.inflight).toBeLessThanOrEqual(5); + this.inflight--; + res(a * 3); + }, Math.random() * 10); + }); + } - @sequentialize(args => 'qux' + args[0]) - @throttle(1, () => 'qux') - qux(a: number) { - this.calls++; - this.inflight++; - return new Promise(res => { - setTimeout(() => { - expect(this.inflight).toBe(1); - this.inflight--; - res(a * 3); - }, Math.random() * 10); - }); - } + @sequentialize((args) => "qux" + args[0]) + @throttle(1, () => "qux") + qux(a: number) { + this.calls++; + this.inflight++; + return new Promise((res) => { + setTimeout(() => { + expect(this.inflight).toBe(1); + this.inflight--; + res(a * 3); + }, Math.random() * 10); + }); + } } diff --git a/spec/common/misc/utils.spec.ts b/spec/common/misc/utils.spec.ts index 0d163706..5c6f6874 100644 --- a/spec/common/misc/utils.spec.ts +++ b/spec/common/misc/utils.spec.ts @@ -1,200 +1,214 @@ -import { Utils } from 'jslib-common/misc/utils'; +import { Utils } from "jslib-common/misc/utils"; -describe('Utils Service', () => { - describe('getDomain', () => { - it('should fail for invalid urls', () => { - expect(Utils.getDomain(null)).toBeNull(); - expect(Utils.getDomain(undefined)).toBeNull(); - expect(Utils.getDomain(' ')).toBeNull(); - expect(Utils.getDomain('https://bit!:"_&ward.com')).toBeNull(); - expect(Utils.getDomain('bitwarden')).toBeNull(); - }); - - it('should fail for data urls', () => { - expect(Utils.getDomain('data:image/jpeg;base64,AAA')).toBeNull(); - }); - - it('should handle urls without protocol', () => { - expect(Utils.getDomain('bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('wrong://bitwarden.com')).toBe('bitwarden.com'); - }); - - it('should handle valid urls', () => { - expect(Utils.getDomain('bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('http://bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('https://bitwarden.com')).toBe('bitwarden.com'); - - expect(Utils.getDomain('www.bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('http://www.bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('https://www.bitwarden.com')).toBe('bitwarden.com'); - - expect(Utils.getDomain('vault.bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('http://vault.bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('https://vault.bitwarden.com')).toBe('bitwarden.com'); - - expect(Utils.getDomain('www.vault.bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('http://www.vault.bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getDomain('https://www.vault.bitwarden.com')).toBe('bitwarden.com'); - - expect(Utils.getDomain('user:password@bitwarden.com:8080/password/sites?and&query#hash')) - .toBe('bitwarden.com'); - expect(Utils.getDomain('http://user:password@bitwarden.com:8080/password/sites?and&query#hash')) - .toBe('bitwarden.com'); - expect(Utils.getDomain('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')) - .toBe('bitwarden.com'); - - expect(Utils.getDomain('bitwarden.unknown')).toBe('bitwarden.unknown'); - expect(Utils.getDomain('http://bitwarden.unknown')).toBe('bitwarden.unknown'); - expect(Utils.getDomain('https://bitwarden.unknown')).toBe('bitwarden.unknown'); - }); - - it('should handle valid urls with an underscore in subdomain', () => { - expect(Utils.getDomain('my_vault.bitwarden.com/')).toBe('bitwarden.com'); - expect(Utils.getDomain('http://my_vault.bitwarden.com/')).toBe('bitwarden.com'); - expect(Utils.getDomain('https://my_vault.bitwarden.com/')).toBe('bitwarden.com'); - }); - - it('should support urls containing umlauts', () => { - expect(Utils.getDomain('bütwarden.com')).toBe('bütwarden.com'); - expect(Utils.getDomain('http://bütwarden.com')).toBe('bütwarden.com'); - expect(Utils.getDomain('https://bütwarden.com')).toBe('bütwarden.com'); - - expect(Utils.getDomain('subdomain.bütwarden.com')).toBe('bütwarden.com'); - expect(Utils.getDomain('http://subdomain.bütwarden.com')).toBe('bütwarden.com'); - expect(Utils.getDomain('https://subdomain.bütwarden.com')).toBe('bütwarden.com'); - }); - - it('should support punycode urls', () => { - expect(Utils.getDomain('xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - expect(Utils.getDomain('xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - expect(Utils.getDomain('xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - - expect(Utils.getDomain('subdomain.xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - expect(Utils.getDomain('http://subdomain.xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - expect(Utils.getDomain('https://subdomain.xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - }); - - it('should support localhost', () => { - expect(Utils.getDomain('localhost')).toBe('localhost'); - expect(Utils.getDomain('http://localhost')).toBe('localhost'); - expect(Utils.getDomain('https://localhost')).toBe('localhost'); - }); - - it('should support localhost with subdomain', () => { - expect(Utils.getDomain('subdomain.localhost')).toBe('localhost'); - expect(Utils.getDomain('http://subdomain.localhost')).toBe('localhost'); - expect(Utils.getDomain('https://subdomain.localhost')).toBe('localhost'); - }); - - it('should support IPv4', () => { - expect(Utils.getDomain('192.168.1.1')).toBe('192.168.1.1'); - expect(Utils.getDomain('http://192.168.1.1')).toBe('192.168.1.1'); - expect(Utils.getDomain('https://192.168.1.1')).toBe('192.168.1.1'); - }); - - it('should support IPv6', () => { - expect(Utils.getDomain('[2620:fe::fe]')).toBe('2620:fe::fe'); - expect(Utils.getDomain('http://[2620:fe::fe]')).toBe('2620:fe::fe'); - expect(Utils.getDomain('https://[2620:fe::fe]')).toBe('2620:fe::fe'); - }); - - it('should reject invalid hostnames', () => { - expect(Utils.getDomain('https://mywebsite.com$.mywebsite.com')).toBeNull(); - expect(Utils.getDomain('https://mywebsite.com!.mywebsite.com')).toBeNull(); - }); +describe("Utils Service", () => { + describe("getDomain", () => { + it("should fail for invalid urls", () => { + expect(Utils.getDomain(null)).toBeNull(); + expect(Utils.getDomain(undefined)).toBeNull(); + expect(Utils.getDomain(" ")).toBeNull(); + expect(Utils.getDomain('https://bit!:"_&ward.com')).toBeNull(); + expect(Utils.getDomain("bitwarden")).toBeNull(); }); - describe('getHostname', () => { - it('should fail for invalid urls', () => { - expect(Utils.getHostname(null)).toBeNull(); - expect(Utils.getHostname(undefined)).toBeNull(); - expect(Utils.getHostname(' ')).toBeNull(); - expect(Utils.getHostname('https://bit!:"_&ward.com')).toBeNull(); - }); - - it('should handle valid urls', () => { - expect(Utils.getHostname('bitwarden')).toBe('bitwarden'); - expect(Utils.getHostname('http://bitwarden')).toBe('bitwarden'); - expect(Utils.getHostname('https://bitwarden')).toBe('bitwarden'); - - expect(Utils.getHostname('bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getHostname('http://bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getHostname('https://bitwarden.com')).toBe('bitwarden.com'); - - expect(Utils.getHostname('www.bitwarden.com')).toBe('www.bitwarden.com'); - expect(Utils.getHostname('http://www.bitwarden.com')).toBe('www.bitwarden.com'); - expect(Utils.getHostname('https://www.bitwarden.com')).toBe('www.bitwarden.com'); - - expect(Utils.getHostname('vault.bitwarden.com')).toBe('vault.bitwarden.com'); - expect(Utils.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com'); - expect(Utils.getHostname('https://vault.bitwarden.com')).toBe('vault.bitwarden.com'); - - expect(Utils.getHostname('www.vault.bitwarden.com')).toBe('www.vault.bitwarden.com'); - expect(Utils.getHostname('http://www.vault.bitwarden.com')).toBe('www.vault.bitwarden.com'); - expect(Utils.getHostname('https://www.vault.bitwarden.com')).toBe('www.vault.bitwarden.com'); - - expect(Utils.getHostname('user:password@bitwarden.com:8080/password/sites?and&query#hash')) - .toBe('bitwarden.com'); - expect(Utils.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')) - .toBe('bitwarden.com'); - expect(Utils.getHostname('https://bitwarden.unknown')).toBe('bitwarden.unknown'); - }); - - it('should handle valid urls with an underscore in subdomain', () => { - expect(Utils.getHostname('my_vault.bitwarden.com/')).toBe('my_vault.bitwarden.com'); - expect(Utils.getHostname('http://my_vault.bitwarden.com/')).toBe('my_vault.bitwarden.com'); - expect(Utils.getHostname('https://my_vault.bitwarden.com/')).toBe('my_vault.bitwarden.com'); - }); - - it('should support urls containing umlauts', () => { - expect(Utils.getHostname('bütwarden.com')).toBe('bütwarden.com'); - expect(Utils.getHostname('http://bütwarden.com')).toBe('bütwarden.com'); - expect(Utils.getHostname('https://bütwarden.com')).toBe('bütwarden.com'); - - expect(Utils.getHostname('subdomain.bütwarden.com')).toBe('subdomain.bütwarden.com'); - expect(Utils.getHostname('http://subdomain.bütwarden.com')).toBe('subdomain.bütwarden.com'); - expect(Utils.getHostname('https://subdomain.bütwarden.com')).toBe('subdomain.bütwarden.com'); - }); - - it('should support punycode urls', () => { - expect(Utils.getHostname('xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - expect(Utils.getHostname('xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - expect(Utils.getHostname('xn--btwarden-65a.com')).toBe('xn--btwarden-65a.com'); - - expect(Utils.getHostname('subdomain.xn--btwarden-65a.com')).toBe('subdomain.xn--btwarden-65a.com'); - expect(Utils.getHostname('http://subdomain.xn--btwarden-65a.com')).toBe('subdomain.xn--btwarden-65a.com'); - expect(Utils.getHostname('https://subdomain.xn--btwarden-65a.com')).toBe('subdomain.xn--btwarden-65a.com'); - }); - - it('should support localhost', () => { - expect(Utils.getHostname('localhost')).toBe('localhost'); - expect(Utils.getHostname('http://localhost')).toBe('localhost'); - expect(Utils.getHostname('https://localhost')).toBe('localhost'); - }); - - it('should support localhost with subdomain', () => { - expect(Utils.getHostname('subdomain.localhost')).toBe('subdomain.localhost'); - expect(Utils.getHostname('http://subdomain.localhost')).toBe('subdomain.localhost'); - expect(Utils.getHostname('https://subdomain.localhost')).toBe('subdomain.localhost'); - }); - - it('should support IPv4', () => { - expect(Utils.getHostname('192.168.1.1')).toBe('192.168.1.1'); - expect(Utils.getHostname('http://192.168.1.1')).toBe('192.168.1.1'); - expect(Utils.getHostname('https://192.168.1.1')).toBe('192.168.1.1'); - }); - - it('should support IPv6', () => { - expect(Utils.getHostname('[2620:fe::fe]')).toBe('2620:fe::fe'); - expect(Utils.getHostname('http://[2620:fe::fe]')).toBe('2620:fe::fe'); - expect(Utils.getHostname('https://[2620:fe::fe]')).toBe('2620:fe::fe'); - }); + it("should fail for data urls", () => { + expect(Utils.getDomain("data:image/jpeg;base64,AAA")).toBeNull(); }); - describe('newGuid', () => { - it('should create a valid guid', () => { - const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; - expect(Utils.newGuid()).toMatch(validGuid); - }); + it("should handle urls without protocol", () => { + expect(Utils.getDomain("bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("wrong://bitwarden.com")).toBe("bitwarden.com"); }); + + it("should handle valid urls", () => { + expect(Utils.getDomain("bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("http://bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("https://bitwarden.com")).toBe("bitwarden.com"); + + expect(Utils.getDomain("www.bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("http://www.bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("https://www.bitwarden.com")).toBe("bitwarden.com"); + + expect(Utils.getDomain("vault.bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("http://vault.bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("https://vault.bitwarden.com")).toBe("bitwarden.com"); + + expect(Utils.getDomain("www.vault.bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("http://www.vault.bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getDomain("https://www.vault.bitwarden.com")).toBe("bitwarden.com"); + + expect( + Utils.getDomain("user:password@bitwarden.com:8080/password/sites?and&query#hash") + ).toBe("bitwarden.com"); + expect( + Utils.getDomain("http://user:password@bitwarden.com:8080/password/sites?and&query#hash") + ).toBe("bitwarden.com"); + expect( + Utils.getDomain("https://user:password@bitwarden.com:8080/password/sites?and&query#hash") + ).toBe("bitwarden.com"); + + expect(Utils.getDomain("bitwarden.unknown")).toBe("bitwarden.unknown"); + expect(Utils.getDomain("http://bitwarden.unknown")).toBe("bitwarden.unknown"); + expect(Utils.getDomain("https://bitwarden.unknown")).toBe("bitwarden.unknown"); + }); + + it("should handle valid urls with an underscore in subdomain", () => { + expect(Utils.getDomain("my_vault.bitwarden.com/")).toBe("bitwarden.com"); + expect(Utils.getDomain("http://my_vault.bitwarden.com/")).toBe("bitwarden.com"); + expect(Utils.getDomain("https://my_vault.bitwarden.com/")).toBe("bitwarden.com"); + }); + + it("should support urls containing umlauts", () => { + expect(Utils.getDomain("bütwarden.com")).toBe("bütwarden.com"); + expect(Utils.getDomain("http://bütwarden.com")).toBe("bütwarden.com"); + expect(Utils.getDomain("https://bütwarden.com")).toBe("bütwarden.com"); + + expect(Utils.getDomain("subdomain.bütwarden.com")).toBe("bütwarden.com"); + expect(Utils.getDomain("http://subdomain.bütwarden.com")).toBe("bütwarden.com"); + expect(Utils.getDomain("https://subdomain.bütwarden.com")).toBe("bütwarden.com"); + }); + + it("should support punycode urls", () => { + expect(Utils.getDomain("xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + expect(Utils.getDomain("xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + expect(Utils.getDomain("xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + + expect(Utils.getDomain("subdomain.xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + expect(Utils.getDomain("http://subdomain.xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + expect(Utils.getDomain("https://subdomain.xn--btwarden-65a.com")).toBe( + "xn--btwarden-65a.com" + ); + }); + + it("should support localhost", () => { + expect(Utils.getDomain("localhost")).toBe("localhost"); + expect(Utils.getDomain("http://localhost")).toBe("localhost"); + expect(Utils.getDomain("https://localhost")).toBe("localhost"); + }); + + it("should support localhost with subdomain", () => { + expect(Utils.getDomain("subdomain.localhost")).toBe("localhost"); + expect(Utils.getDomain("http://subdomain.localhost")).toBe("localhost"); + expect(Utils.getDomain("https://subdomain.localhost")).toBe("localhost"); + }); + + it("should support IPv4", () => { + expect(Utils.getDomain("192.168.1.1")).toBe("192.168.1.1"); + expect(Utils.getDomain("http://192.168.1.1")).toBe("192.168.1.1"); + expect(Utils.getDomain("https://192.168.1.1")).toBe("192.168.1.1"); + }); + + it("should support IPv6", () => { + expect(Utils.getDomain("[2620:fe::fe]")).toBe("2620:fe::fe"); + expect(Utils.getDomain("http://[2620:fe::fe]")).toBe("2620:fe::fe"); + expect(Utils.getDomain("https://[2620:fe::fe]")).toBe("2620:fe::fe"); + }); + + it("should reject invalid hostnames", () => { + expect(Utils.getDomain("https://mywebsite.com$.mywebsite.com")).toBeNull(); + expect(Utils.getDomain("https://mywebsite.com!.mywebsite.com")).toBeNull(); + }); + }); + + describe("getHostname", () => { + it("should fail for invalid urls", () => { + expect(Utils.getHostname(null)).toBeNull(); + expect(Utils.getHostname(undefined)).toBeNull(); + expect(Utils.getHostname(" ")).toBeNull(); + expect(Utils.getHostname('https://bit!:"_&ward.com')).toBeNull(); + }); + + it("should handle valid urls", () => { + expect(Utils.getHostname("bitwarden")).toBe("bitwarden"); + expect(Utils.getHostname("http://bitwarden")).toBe("bitwarden"); + expect(Utils.getHostname("https://bitwarden")).toBe("bitwarden"); + + expect(Utils.getHostname("bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getHostname("http://bitwarden.com")).toBe("bitwarden.com"); + expect(Utils.getHostname("https://bitwarden.com")).toBe("bitwarden.com"); + + expect(Utils.getHostname("www.bitwarden.com")).toBe("www.bitwarden.com"); + expect(Utils.getHostname("http://www.bitwarden.com")).toBe("www.bitwarden.com"); + expect(Utils.getHostname("https://www.bitwarden.com")).toBe("www.bitwarden.com"); + + expect(Utils.getHostname("vault.bitwarden.com")).toBe("vault.bitwarden.com"); + expect(Utils.getHostname("http://vault.bitwarden.com")).toBe("vault.bitwarden.com"); + expect(Utils.getHostname("https://vault.bitwarden.com")).toBe("vault.bitwarden.com"); + + expect(Utils.getHostname("www.vault.bitwarden.com")).toBe("www.vault.bitwarden.com"); + expect(Utils.getHostname("http://www.vault.bitwarden.com")).toBe("www.vault.bitwarden.com"); + expect(Utils.getHostname("https://www.vault.bitwarden.com")).toBe("www.vault.bitwarden.com"); + + expect( + Utils.getHostname("user:password@bitwarden.com:8080/password/sites?and&query#hash") + ).toBe("bitwarden.com"); + expect( + Utils.getHostname("https://user:password@bitwarden.com:8080/password/sites?and&query#hash") + ).toBe("bitwarden.com"); + expect(Utils.getHostname("https://bitwarden.unknown")).toBe("bitwarden.unknown"); + }); + + it("should handle valid urls with an underscore in subdomain", () => { + expect(Utils.getHostname("my_vault.bitwarden.com/")).toBe("my_vault.bitwarden.com"); + expect(Utils.getHostname("http://my_vault.bitwarden.com/")).toBe("my_vault.bitwarden.com"); + expect(Utils.getHostname("https://my_vault.bitwarden.com/")).toBe("my_vault.bitwarden.com"); + }); + + it("should support urls containing umlauts", () => { + expect(Utils.getHostname("bütwarden.com")).toBe("bütwarden.com"); + expect(Utils.getHostname("http://bütwarden.com")).toBe("bütwarden.com"); + expect(Utils.getHostname("https://bütwarden.com")).toBe("bütwarden.com"); + + expect(Utils.getHostname("subdomain.bütwarden.com")).toBe("subdomain.bütwarden.com"); + expect(Utils.getHostname("http://subdomain.bütwarden.com")).toBe("subdomain.bütwarden.com"); + expect(Utils.getHostname("https://subdomain.bütwarden.com")).toBe("subdomain.bütwarden.com"); + }); + + it("should support punycode urls", () => { + expect(Utils.getHostname("xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + expect(Utils.getHostname("xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + expect(Utils.getHostname("xn--btwarden-65a.com")).toBe("xn--btwarden-65a.com"); + + expect(Utils.getHostname("subdomain.xn--btwarden-65a.com")).toBe( + "subdomain.xn--btwarden-65a.com" + ); + expect(Utils.getHostname("http://subdomain.xn--btwarden-65a.com")).toBe( + "subdomain.xn--btwarden-65a.com" + ); + expect(Utils.getHostname("https://subdomain.xn--btwarden-65a.com")).toBe( + "subdomain.xn--btwarden-65a.com" + ); + }); + + it("should support localhost", () => { + expect(Utils.getHostname("localhost")).toBe("localhost"); + expect(Utils.getHostname("http://localhost")).toBe("localhost"); + expect(Utils.getHostname("https://localhost")).toBe("localhost"); + }); + + it("should support localhost with subdomain", () => { + expect(Utils.getHostname("subdomain.localhost")).toBe("subdomain.localhost"); + expect(Utils.getHostname("http://subdomain.localhost")).toBe("subdomain.localhost"); + expect(Utils.getHostname("https://subdomain.localhost")).toBe("subdomain.localhost"); + }); + + it("should support IPv4", () => { + expect(Utils.getHostname("192.168.1.1")).toBe("192.168.1.1"); + expect(Utils.getHostname("http://192.168.1.1")).toBe("192.168.1.1"); + expect(Utils.getHostname("https://192.168.1.1")).toBe("192.168.1.1"); + }); + + it("should support IPv6", () => { + expect(Utils.getHostname("[2620:fe::fe]")).toBe("2620:fe::fe"); + expect(Utils.getHostname("http://[2620:fe::fe]")).toBe("2620:fe::fe"); + expect(Utils.getHostname("https://[2620:fe::fe]")).toBe("2620:fe::fe"); + }); + }); + + describe("newGuid", () => { + it("should create a valid guid", () => { + const validGuid = + /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + expect(Utils.newGuid()).toMatch(validGuid); + }); + }); }); diff --git a/spec/common/services/consoleLog.service.spec.ts b/spec/common/services/consoleLog.service.spec.ts index 5f0a1412..a7f7eddb 100644 --- a/spec/common/services/consoleLog.service.spec.ts +++ b/spec/common/services/consoleLog.service.spec.ts @@ -1,4 +1,4 @@ -import { ConsoleLogService } from 'jslib-common/services/consoleLog.service'; +import { ConsoleLogService } from "jslib-common/services/consoleLog.service"; const originalConsole = console; let caughtMessage: any; @@ -6,90 +6,97 @@ let caughtMessage: any; declare var console: any; export function interceptConsole(interceptions: any): object { - console = { - // tslint:disable-next-line - log: function () { - interceptions.log = arguments; - }, - // tslint:disable-next-line - warn: function () { - interceptions.warn = arguments; - }, - // tslint:disable-next-line - error: function () { - interceptions.error = arguments; - }, - }; - return interceptions; + console = { + // tslint:disable-next-line + log: function () { + interceptions.log = arguments; + }, + // tslint:disable-next-line + warn: function () { + interceptions.warn = arguments; + }, + // tslint:disable-next-line + error: function () { + interceptions.error = arguments; + }, + }; + return interceptions; } export function restoreConsole() { - console = originalConsole; + console = originalConsole; } -describe('ConsoleLogService', () => { - let logService: ConsoleLogService; - beforeEach(() => { - caughtMessage = {}; - interceptConsole(caughtMessage); - logService = new ConsoleLogService(true); +describe("ConsoleLogService", () => { + let logService: ConsoleLogService; + beforeEach(() => { + caughtMessage = {}; + interceptConsole(caughtMessage); + logService = new ConsoleLogService(true); + }); + + afterAll(() => { + restoreConsole(); + }); + + it("filters messages below the set threshold", () => { + logService = new ConsoleLogService(true, (level) => true); + logService.debug("debug"); + logService.info("info"); + logService.warning("warning"); + logService.error("error"); + + expect(caughtMessage).toEqual({}); + }); + it("only writes debug messages in dev mode", () => { + logService = new ConsoleLogService(false); + + logService.debug("debug message"); + expect(caughtMessage.log).toBeUndefined(); + }); + + it("writes debug/info messages to console.log", () => { + logService.debug("this is a debug message"); + expect(caughtMessage).toEqual({ + log: jasmine.arrayWithExactContents(["this is a debug message"]), }); - afterAll(() => { - restoreConsole(); + logService.info("this is an info message"); + expect(caughtMessage).toEqual({ + log: jasmine.arrayWithExactContents(["this is an info message"]), }); - - it('filters messages below the set threshold', () => { - logService = new ConsoleLogService(true, level => true); - logService.debug('debug'); - logService.info('info'); - logService.warning('warning'); - logService.error('error'); - - expect(caughtMessage).toEqual({}); + }); + it("writes warning messages to console.warn", () => { + logService.warning("this is a warning message"); + expect(caughtMessage).toEqual({ + warn: jasmine.arrayWithExactContents(["this is a warning message"]), }); - it('only writes debug messages in dev mode', () => { - logService = new ConsoleLogService(false); - - logService.debug('debug message'); - expect(caughtMessage.log).toBeUndefined(); + }); + it("writes error messages to console.error", () => { + logService.error("this is an error message"); + expect(caughtMessage).toEqual({ + error: jasmine.arrayWithExactContents(["this is an error message"]), }); + }); + it("times with output to info", async () => { + logService.time(); + await new Promise((r) => setTimeout(r, 250)); + const duration = logService.timeEnd(); + expect(duration[0]).toBe(0); + expect(duration[1]).toBeGreaterThan(0); + expect(duration[1]).toBeLessThan(500 * 10e6); - it('writes debug/info messages to console.log', () => { - logService.debug('this is a debug message'); - expect(caughtMessage).toEqual({ log: jasmine.arrayWithExactContents(['this is a debug message']) }); + expect(caughtMessage).toEqual(jasmine.arrayContaining([])); + expect(caughtMessage.log.length).toBe(1); + expect(caughtMessage.log[0]).toEqual(jasmine.stringMatching(/^default: \d+\.?\d*ms$/)); + }); - logService.info('this is an info message'); - expect(caughtMessage).toEqual({ log: jasmine.arrayWithExactContents(['this is an info message']) }); - }); - it('writes warning messages to console.warn', () => { - logService.warning('this is a warning message'); - expect(caughtMessage).toEqual({ warn: jasmine.arrayWithExactContents(['this is a warning message']) }); - }); - it('writes error messages to console.error', () => { - logService.error('this is an error message'); - expect(caughtMessage).toEqual({ error: jasmine.arrayWithExactContents(['this is an error message']) }); - }); + it("filters time output", async () => { + logService = new ConsoleLogService(true, (level) => true); + logService.time(); + logService.timeEnd(); - it('times with output to info', async () => { - logService.time(); - await new Promise(r => setTimeout(r, 250)); - const duration = logService.timeEnd(); - expect(duration[0]).toBe(0); - expect(duration[1]).toBeGreaterThan(0); - expect(duration[1]).toBeLessThan(500 * 10e6); - - expect(caughtMessage).toEqual(jasmine.arrayContaining([])); - expect(caughtMessage.log.length).toBe(1); - expect(caughtMessage.log[0]).toEqual(jasmine.stringMatching(/^default: \d+\.?\d*ms$/)); - }); - - it('filters time output', async () => { - logService = new ConsoleLogService(true, level => true); - logService.time(); - logService.timeEnd(); - - expect(caughtMessage).toEqual({}); - }); + expect(caughtMessage).toEqual({}); + }); }); diff --git a/spec/common/services/export.service.spec.ts b/spec/common/services/export.service.spec.ts index a9d57d2b..62402d78 100644 --- a/spec/common/services/export.service.spec.ts +++ b/spec/common/services/export.service.spec.ts @@ -1,123 +1,135 @@ -import { Substitute, SubstituteOf } from '@fluffy-spoon/substitute'; +import { Substitute, SubstituteOf } from "@fluffy-spoon/substitute"; -import { ApiService } from 'jslib-common/abstractions/api.service'; -import { CipherService } from 'jslib-common/abstractions/cipher.service'; -import { CryptoService } from 'jslib-common/abstractions/crypto.service'; -import { FolderService } from 'jslib-common/abstractions/folder.service'; +import { ApiService } from "jslib-common/abstractions/api.service"; +import { CipherService } from "jslib-common/abstractions/cipher.service"; +import { CryptoService } from "jslib-common/abstractions/crypto.service"; +import { FolderService } from "jslib-common/abstractions/folder.service"; -import { ExportService } from 'jslib-common/services/export.service'; +import { ExportService } from "jslib-common/services/export.service"; -import { Cipher } from 'jslib-common/models/domain/cipher'; -import { EncString } from 'jslib-common/models/domain/encString'; -import { Login } from 'jslib-common/models/domain/login'; -import { CipherWithIds as CipherExport } from 'jslib-common/models/export/cipherWithIds'; +import { Cipher } from "jslib-common/models/domain/cipher"; +import { EncString } from "jslib-common/models/domain/encString"; +import { Login } from "jslib-common/models/domain/login"; +import { CipherWithIds as CipherExport } from "jslib-common/models/export/cipherWithIds"; -import { CipherType } from 'jslib-common/enums/cipherType'; -import { CipherView } from 'jslib-common/models/view/cipherView'; -import { LoginView } from 'jslib-common/models/view/loginView'; +import { CipherType } from "jslib-common/enums/cipherType"; +import { CipherView } from "jslib-common/models/view/cipherView"; +import { LoginView } from "jslib-common/models/view/loginView"; -import { BuildTestObject, GetUniqueString } from '../../utils'; +import { BuildTestObject, GetUniqueString } from "../../utils"; const UserCipherViews = [ - generateCipherView(false), - generateCipherView(false), - generateCipherView(true), + generateCipherView(false), + generateCipherView(false), + generateCipherView(true), ]; const UserCipherDomains = [ - generateCipherDomain(false), - generateCipherDomain(false), - generateCipherDomain(true), + generateCipherDomain(false), + generateCipherDomain(false), + generateCipherDomain(true), ]; function generateCipherView(deleted: boolean) { - return BuildTestObject({ - id: GetUniqueString('id'), - notes: GetUniqueString('notes'), - type: CipherType.Login, - login: BuildTestObject({ - username: GetUniqueString('username'), - password: GetUniqueString('password'), - }, LoginView), - collectionIds: null, - deletedDate: deleted ? new Date() : null, - }, CipherView); + return BuildTestObject( + { + id: GetUniqueString("id"), + notes: GetUniqueString("notes"), + type: CipherType.Login, + login: BuildTestObject( + { + username: GetUniqueString("username"), + password: GetUniqueString("password"), + }, + LoginView + ), + collectionIds: null, + deletedDate: deleted ? new Date() : null, + }, + CipherView + ); } function generateCipherDomain(deleted: boolean) { - return BuildTestObject({ - id: GetUniqueString('id'), - notes: new EncString(GetUniqueString('notes')), - type: CipherType.Login, - login: BuildTestObject({ - username: new EncString(GetUniqueString('username')), - password: new EncString(GetUniqueString('password')), - }, Login), - collectionIds: null, - deletedDate: deleted ? new Date() : null, - }, Cipher); + return BuildTestObject( + { + id: GetUniqueString("id"), + notes: new EncString(GetUniqueString("notes")), + type: CipherType.Login, + login: BuildTestObject( + { + username: new EncString(GetUniqueString("username")), + password: new EncString(GetUniqueString("password")), + }, + Login + ), + collectionIds: null, + deletedDate: deleted ? new Date() : null, + }, + Cipher + ); } function expectEqualCiphers(ciphers: CipherView[] | Cipher[], jsonResult: string) { - const actual = JSON.stringify(JSON.parse(jsonResult).items); - const items: CipherExport[] = []; - ciphers.forEach((c: CipherView | Cipher) => { - const item = new CipherExport(); - item.build(c); - items.push(item); - }); + const actual = JSON.stringify(JSON.parse(jsonResult).items); + const items: CipherExport[] = []; + ciphers.forEach((c: CipherView | Cipher) => { + const item = new CipherExport(); + item.build(c); + items.push(item); + }); - expect(actual).toEqual(JSON.stringify(items)); + expect(actual).toEqual(JSON.stringify(items)); } -describe('ExportService', () => { - let exportService: ExportService; - let apiService: SubstituteOf; - let cipherService: SubstituteOf; - let folderService: SubstituteOf; - let cryptoService: SubstituteOf; +describe("ExportService", () => { + let exportService: ExportService; + let apiService: SubstituteOf; + let cipherService: SubstituteOf; + let folderService: SubstituteOf; + let cryptoService: SubstituteOf; - beforeEach(() => { - apiService = Substitute.for(); - cipherService = Substitute.for(); - folderService = Substitute.for(); - cryptoService = Substitute.for(); + beforeEach(() => { + apiService = Substitute.for(); + cipherService = Substitute.for(); + folderService = Substitute.for(); + cryptoService = Substitute.for(); - folderService.getAllDecrypted().resolves([]); - folderService.getAll().resolves([]); + folderService.getAllDecrypted().resolves([]); + folderService.getAll().resolves([]); - exportService = new ExportService(folderService, cipherService, apiService, cryptoService); - }); + exportService = new ExportService(folderService, cipherService, apiService, cryptoService); + }); - it('exports unecrypted user ciphers', async () => { - cipherService.getAllDecrypted().resolves(UserCipherViews.slice(0, 1)); + it("exports unecrypted user ciphers", async () => { + cipherService.getAllDecrypted().resolves(UserCipherViews.slice(0, 1)); - const actual = await exportService.getExport('json'); + const actual = await exportService.getExport("json"); - expectEqualCiphers(UserCipherViews.slice(0, 1), actual); - }); + expectEqualCiphers(UserCipherViews.slice(0, 1), actual); + }); - it('exports encrypted json user ciphers', async () => { - cipherService.getAll().resolves(UserCipherDomains.slice(0, 1)); + it("exports encrypted json user ciphers", async () => { + cipherService.getAll().resolves(UserCipherDomains.slice(0, 1)); - const actual = await exportService.getExport('encrypted_json'); + const actual = await exportService.getExport("encrypted_json"); - expectEqualCiphers(UserCipherDomains.slice(0, 1), actual); - }); + expectEqualCiphers(UserCipherDomains.slice(0, 1), actual); + }); - it('does not unecrypted export trashed user items', async () => { - cipherService.getAllDecrypted().resolves(UserCipherViews); + it("does not unecrypted export trashed user items", async () => { + cipherService.getAllDecrypted().resolves(UserCipherViews); - const actual = await exportService.getExport('json'); + const actual = await exportService.getExport("json"); - expectEqualCiphers(UserCipherViews.slice(0, 2), actual); - }); + expectEqualCiphers(UserCipherViews.slice(0, 2), actual); + }); - it('does not encrypted export trashed user items', async () => { - cipherService.getAll().resolves(UserCipherDomains); + it("does not encrypted export trashed user items", async () => { + cipherService.getAll().resolves(UserCipherDomains); - const actual = await exportService.getExport('encrypted_json'); + const actual = await exportService.getExport("encrypted_json"); - expectEqualCiphers(UserCipherDomains.slice(0, 2), actual); - }); + expectEqualCiphers(UserCipherDomains.slice(0, 2), actual); + }); }); diff --git a/spec/electron/services/electronLog.service.spec.ts b/spec/electron/services/electronLog.service.spec.ts index 8bbb46ee..30b52ce0 100644 --- a/spec/electron/services/electronLog.service.spec.ts +++ b/spec/electron/services/electronLog.service.spec.ts @@ -1,9 +1,9 @@ -import { ElectronLogService } from 'jslib-electron/services/electronLog.service'; +import { ElectronLogService } from "jslib-electron/services/electronLog.service"; -describe('ElectronLogService', () => { - it('sets dev based on electron method', () => { - process.env.ELECTRON_IS_DEV = '1'; - const logService = new ElectronLogService(); - expect(logService).toEqual(jasmine.objectContaining({ isDev: true }) as any); - }); +describe("ElectronLogService", () => { + it("sets dev based on electron method", () => { + process.env.ELECTRON_IS_DEV = "1"; + const logService = new ElectronLogService(); + expect(logService).toEqual(jasmine.objectContaining({ isDev: true }) as any); + }); }); diff --git a/spec/electron/utils.spec.ts b/spec/electron/utils.spec.ts index b350a82d..f9e95a2d 100644 --- a/spec/electron/utils.spec.ts +++ b/spec/electron/utils.spec.ts @@ -1,27 +1,27 @@ -import { cleanUserAgent } from 'jslib-electron/utils'; +import { cleanUserAgent } from "jslib-electron/utils"; const expectedUserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${process.versions.chrome} Safari/537.36`; -describe('cleanUserAgent', () => { - it('cleans mac agent', () => { - const initialMacAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6_0) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/${process.version} Chrome/${process.versions.chrome} Electron/${process.versions.electron} Safari/537.36`; - expect(cleanUserAgent(initialMacAgent)).toEqual(expectedUserAgent); - }); +describe("cleanUserAgent", () => { + it("cleans mac agent", () => { + const initialMacAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6_0) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/${process.version} Chrome/${process.versions.chrome} Electron/${process.versions.electron} Safari/537.36`; + expect(cleanUserAgent(initialMacAgent)).toEqual(expectedUserAgent); + }); - it('cleans windows agent', () => { - const initialWindowsAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/${process.version} Chrome/${process.versions.chrome} Electron/${process.versions.electron} Safari/537.36`; - expect(cleanUserAgent(initialWindowsAgent)).toEqual(expectedUserAgent); - }); + it("cleans windows agent", () => { + const initialWindowsAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/${process.version} Chrome/${process.versions.chrome} Electron/${process.versions.electron} Safari/537.36`; + expect(cleanUserAgent(initialWindowsAgent)).toEqual(expectedUserAgent); + }); - it('cleans linux agent', () => { - const initialWindowsAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/${process.version} Chrome/${process.versions.chrome} Electron/${process.versions.electron} Safari/537.36`; - expect(cleanUserAgent(initialWindowsAgent)).toEqual(expectedUserAgent); - }); + it("cleans linux agent", () => { + const initialWindowsAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/${process.version} Chrome/${process.versions.chrome} Electron/${process.versions.electron} Safari/537.36`; + expect(cleanUserAgent(initialWindowsAgent)).toEqual(expectedUserAgent); + }); - it('does not change version numbers', () => { - const expected = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36`; - const initialAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/1.28.3 Chrome/87.0.4280.141 Electron/11.4.5 Safari/537.36`; + it("does not change version numbers", () => { + const expected = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36`; + const initialAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Bitwarden/1.28.3 Chrome/87.0.4280.141 Electron/11.4.5 Safari/537.36`; - expect(cleanUserAgent(initialAgent)).toEqual(expected); - }); + expect(cleanUserAgent(initialAgent)).toEqual(expected); + }); }); diff --git a/spec/helpers.ts b/spec/helpers.ts index 058cc4fa..3d7aaa73 100644 --- a/spec/helpers.ts +++ b/spec/helpers.ts @@ -1,9 +1,9 @@ // tslint:disable-next-line -const TSConsoleReporter = require('jasmine-ts-console-reporter'); +const TSConsoleReporter = require("jasmine-ts-console-reporter"); jasmine.getEnv().clearReporters(); // Clear default console reporter jasmine.getEnv().addReporter(new TSConsoleReporter()); // Polyfills // tslint:disable-next-line -const jsdom: any = require('jsdom'); +const jsdom: any = require("jsdom"); (global as any).DOMParser = new jsdom.JSDOM().window.DOMParser; diff --git a/spec/node/cli/consoleLog.service.spec.ts b/spec/node/cli/consoleLog.service.spec.ts index afcdc007..a6d4529c 100644 --- a/spec/node/cli/consoleLog.service.spec.ts +++ b/spec/node/cli/consoleLog.service.spec.ts @@ -1,41 +1,42 @@ -import { ConsoleLogService } from 'jslib-node/cli/services/consoleLog.service'; -import { interceptConsole, restoreConsole } from '../../common/services/consoleLog.service.spec'; +import { ConsoleLogService } from "jslib-node/cli/services/consoleLog.service"; +import { interceptConsole, restoreConsole } from "../../common/services/consoleLog.service.spec"; const originalConsole = console; let caughtMessage: any = {}; -describe('CLI Console log service', () => { - let logService: ConsoleLogService; - beforeEach(() => { - caughtMessage = {}; - interceptConsole(caughtMessage); - logService = new ConsoleLogService(true); +describe("CLI Console log service", () => { + let logService: ConsoleLogService; + beforeEach(() => { + caughtMessage = {}; + interceptConsole(caughtMessage); + logService = new ConsoleLogService(true); + }); + + afterAll(() => { + restoreConsole(); + }); + + it("should redirect all console to error if BW_RESPONSE env is true", () => { + process.env.BW_RESPONSE = "true"; + + logService.debug("this is a debug message"); + expect(caughtMessage).toEqual({ + error: jasmine.arrayWithExactContents(["this is a debug message"]), }); + }); - afterAll(() => { - restoreConsole(); - }); - - it('should redirect all console to error if BW_RESPONSE env is true', () => { - process.env.BW_RESPONSE = 'true'; - - logService.debug('this is a debug message'); - expect(caughtMessage).toEqual({ error: jasmine.arrayWithExactContents(['this is a debug message']) }); - }); - - it('should not redirect console to error if BW_RESPONSE != true', () => { - process.env.BW_RESPONSE = 'false'; - - logService.debug('debug'); - logService.info('info'); - logService.warning('warning'); - logService.error('error'); - - expect(caughtMessage).toEqual({ - log: jasmine.arrayWithExactContents(['info']), - warn: jasmine.arrayWithExactContents(['warning']), - error: jasmine.arrayWithExactContents(['error']), - }); - + it("should not redirect console to error if BW_RESPONSE != true", () => { + process.env.BW_RESPONSE = "false"; + + logService.debug("debug"); + logService.info("info"); + logService.warning("warning"); + logService.error("error"); + + expect(caughtMessage).toEqual({ + log: jasmine.arrayWithExactContents(["info"]), + warn: jasmine.arrayWithExactContents(["warning"]), + error: jasmine.arrayWithExactContents(["error"]), }); + }); }); diff --git a/spec/node/services/nodeCryptoFunction.service.spec.ts b/spec/node/services/nodeCryptoFunction.service.spec.ts index 12b00b6e..43849b74 100644 --- a/spec/node/services/nodeCryptoFunction.service.spec.ts +++ b/spec/node/services/nodeCryptoFunction.service.spec.ts @@ -1,424 +1,519 @@ -import { NodeCryptoFunctionService } from 'jslib-node/services/nodeCryptoFunction.service'; +import { NodeCryptoFunctionService } from "jslib-node/services/nodeCryptoFunction.service"; -import { Utils } from 'jslib-common/misc/utils'; -import { SymmetricCryptoKey } from 'jslib-common/models/domain/symmetricCryptoKey'; +import { Utils } from "jslib-common/misc/utils"; +import { SymmetricCryptoKey } from "jslib-common/models/domain/symmetricCryptoKey"; -const RsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl0Vawl/toXzkEvB82FEtqHP' + - '4xlU2ab/v0crqIfXfIoWF/XXdHGIdrZeilnRXPPJT1B9dTsasttEZNnua/0Rek/cjNDHtzT52irfoZYS7X6HNIfOi54Q+egP' + - 'RQ1H7iNHVZz3K8Db9GCSKPeC8MbW6gVCzb15esCe1gGzg6wkMuWYDFYPoh/oBqcIqrGah7firqB1nDedzEjw32heP2DAffVN' + - '084iTDjiWrJNUxBJ2pDD5Z9dT3MzQ2s09ew1yMWK2z37rT3YerC7OgEDmo3WYo3xL3qYJznu3EO2nmrYjiRa40wKSjxsTlUc' + - 'xDF+F0uMW8oR9EMUHgepdepfAtLsSAQIDAQAB'; -const RsaPrivateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXRVrCX+2hfOQS8Hz' + - 'YUS2oc/jGVTZpv+/Ryuoh9d8ihYX9dd0cYh2tl6KWdFc88lPUH11Oxqy20Rk2e5r/RF6T9yM0Me3NPnaKt+hlhLtfoc0h86L' + - 'nhD56A9FDUfuI0dVnPcrwNv0YJIo94LwxtbqBULNvXl6wJ7WAbODrCQy5ZgMVg+iH+gGpwiqsZqHt+KuoHWcN53MSPDfaF4/' + - 'YMB99U3TziJMOOJask1TEEnakMPln11PczNDazT17DXIxYrbPfutPdh6sLs6AQOajdZijfEvepgnOe7cQ7aeatiOJFrjTApK' + - 'PGxOVRzEMX4XS4xbyhH0QxQeB6l16l8C0uxIBAgMBAAECggEASaWfeVDA3cVzOPFSpvJm20OTE+R6uGOU+7vh36TX/POq92q' + - 'Buwbd0h0oMD32FxsXywd2IxtBDUSiFM9699qufTVuM0Q3tZw6lHDTOVG08+tPdr8qSbMtw7PGFxN79fHLBxejjO4IrM9lapj' + - 'WpxEF+11x7r+wM+0xRZQ8sNFYG46aPfIaty4BGbL0I2DQ2y8I57iBCAy69eht59NLMm27fRWGJIWCuBIjlpfzET1j2HLXUIh' + - '5bTBNzqaN039WH49HczGE3mQKVEJZc/efk3HaVd0a1Sjzyn0QY+N1jtZN3jTRbuDWA1AknkX1LX/0tUhuS3/7C3ejHxjw4Dk' + - '1ZLo5/QKBgQDIWvqFn0+IKRSu6Ua2hDsufIHHUNLelbfLUMmFthxabcUn4zlvIscJO00Tq/ezopSRRvbGiqnxjv/mYxucvOU' + - 'BeZtlus0Q9RTACBtw9TGoNTmQbEunJ2FOSlqbQxkBBAjgGEppRPt30iGj/VjAhCATq2MYOa/X4dVR51BqQAFIEwKBgQDBSIf' + - 'TFKC/hDk6FKZlgwvupWYJyU9RkyfstPErZFmzoKhPkQ3YORo2oeAYmVUbS9I2iIYpYpYQJHX8jMuCbCz4ONxTCuSIXYQYUcU' + - 'q4PglCKp31xBAE6TN8SvhfME9/MvuDssnQinAHuF0GDAhF646T3LLS1not6Vszv7brwSoGwKBgQC88v/8cGfi80ssQZeMnVv' + - 'q1UTXIeQcQnoY5lGHJl3K8mbS3TnXE6c9j417Fdz+rj8KWzBzwWXQB5pSPflWcdZO886Xu/mVGmy9RWgLuVFhXwCwsVEPjNX' + - '5ramRb0/vY0yzenUCninBsIxFSbIfrPtLUYCc4hpxr+sr2Mg/y6jpvQKBgBezMRRs3xkcuXepuI2R+BCXL1/b02IJTUf1F+1' + - 'eLLGd7YV0H+J3fgNc7gGWK51hOrF9JBZHBGeOUPlaukmPwiPdtQZpu4QNE3l37VlIpKTF30E6mb+BqR+nht3rUjarnMXgAoE' + - 'Z18y6/KIjpSMpqC92Nnk/EBM9EYe6Cf4eA9ApAoGAeqEUg46UTlJySkBKURGpIs3v1kkf5I0X8DnOhwb+HPxNaiEdmO7ckm8' + - '+tPVgppLcG0+tMdLjigFQiDUQk2y3WjyxP5ZvXu7U96jaJRI8PFMoE06WeVYcdIzrID2HvqH+w0UQJFrLJ/0Mn4stFAEzXKZ' + - 'BokBGnjFnTnKcs7nv/O8='; +const RsaPublicKey = + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl0Vawl/toXzkEvB82FEtqHP" + + "4xlU2ab/v0crqIfXfIoWF/XXdHGIdrZeilnRXPPJT1B9dTsasttEZNnua/0Rek/cjNDHtzT52irfoZYS7X6HNIfOi54Q+egP" + + "RQ1H7iNHVZz3K8Db9GCSKPeC8MbW6gVCzb15esCe1gGzg6wkMuWYDFYPoh/oBqcIqrGah7firqB1nDedzEjw32heP2DAffVN" + + "084iTDjiWrJNUxBJ2pDD5Z9dT3MzQ2s09ew1yMWK2z37rT3YerC7OgEDmo3WYo3xL3qYJznu3EO2nmrYjiRa40wKSjxsTlUc" + + "xDF+F0uMW8oR9EMUHgepdepfAtLsSAQIDAQAB"; +const RsaPrivateKey = + "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXRVrCX+2hfOQS8Hz" + + "YUS2oc/jGVTZpv+/Ryuoh9d8ihYX9dd0cYh2tl6KWdFc88lPUH11Oxqy20Rk2e5r/RF6T9yM0Me3NPnaKt+hlhLtfoc0h86L" + + "nhD56A9FDUfuI0dVnPcrwNv0YJIo94LwxtbqBULNvXl6wJ7WAbODrCQy5ZgMVg+iH+gGpwiqsZqHt+KuoHWcN53MSPDfaF4/" + + "YMB99U3TziJMOOJask1TEEnakMPln11PczNDazT17DXIxYrbPfutPdh6sLs6AQOajdZijfEvepgnOe7cQ7aeatiOJFrjTApK" + + "PGxOVRzEMX4XS4xbyhH0QxQeB6l16l8C0uxIBAgMBAAECggEASaWfeVDA3cVzOPFSpvJm20OTE+R6uGOU+7vh36TX/POq92q" + + "Buwbd0h0oMD32FxsXywd2IxtBDUSiFM9699qufTVuM0Q3tZw6lHDTOVG08+tPdr8qSbMtw7PGFxN79fHLBxejjO4IrM9lapj" + + "WpxEF+11x7r+wM+0xRZQ8sNFYG46aPfIaty4BGbL0I2DQ2y8I57iBCAy69eht59NLMm27fRWGJIWCuBIjlpfzET1j2HLXUIh" + + "5bTBNzqaN039WH49HczGE3mQKVEJZc/efk3HaVd0a1Sjzyn0QY+N1jtZN3jTRbuDWA1AknkX1LX/0tUhuS3/7C3ejHxjw4Dk" + + "1ZLo5/QKBgQDIWvqFn0+IKRSu6Ua2hDsufIHHUNLelbfLUMmFthxabcUn4zlvIscJO00Tq/ezopSRRvbGiqnxjv/mYxucvOU" + + "BeZtlus0Q9RTACBtw9TGoNTmQbEunJ2FOSlqbQxkBBAjgGEppRPt30iGj/VjAhCATq2MYOa/X4dVR51BqQAFIEwKBgQDBSIf" + + "TFKC/hDk6FKZlgwvupWYJyU9RkyfstPErZFmzoKhPkQ3YORo2oeAYmVUbS9I2iIYpYpYQJHX8jMuCbCz4ONxTCuSIXYQYUcU" + + "q4PglCKp31xBAE6TN8SvhfME9/MvuDssnQinAHuF0GDAhF646T3LLS1not6Vszv7brwSoGwKBgQC88v/8cGfi80ssQZeMnVv" + + "q1UTXIeQcQnoY5lGHJl3K8mbS3TnXE6c9j417Fdz+rj8KWzBzwWXQB5pSPflWcdZO886Xu/mVGmy9RWgLuVFhXwCwsVEPjNX" + + "5ramRb0/vY0yzenUCninBsIxFSbIfrPtLUYCc4hpxr+sr2Mg/y6jpvQKBgBezMRRs3xkcuXepuI2R+BCXL1/b02IJTUf1F+1" + + "eLLGd7YV0H+J3fgNc7gGWK51hOrF9JBZHBGeOUPlaukmPwiPdtQZpu4QNE3l37VlIpKTF30E6mb+BqR+nht3rUjarnMXgAoE" + + "Z18y6/KIjpSMpqC92Nnk/EBM9EYe6Cf4eA9ApAoGAeqEUg46UTlJySkBKURGpIs3v1kkf5I0X8DnOhwb+HPxNaiEdmO7ckm8" + + "+tPVgppLcG0+tMdLjigFQiDUQk2y3WjyxP5ZvXu7U96jaJRI8PFMoE06WeVYcdIzrID2HvqH+w0UQJFrLJ/0Mn4stFAEzXKZ" + + "BokBGnjFnTnKcs7nv/O8="; -const Sha1Mac = '4d4c223f95dc577b665ec4ccbcb680b80a397038'; -const Sha256Mac = '6be3caa84922e12aaaaa2f16c40d44433bb081ef323db584eb616333ab4e874f'; -const Sha512Mac = '21910e341fa12106ca35758a2285374509326c9fbe0bd64e7b99c898f841dc948c58ce66d3504d8883c' + - '5ea7817a0b7c5d4d9b00364ccd214669131fc17fe4aca'; +const Sha1Mac = "4d4c223f95dc577b665ec4ccbcb680b80a397038"; +const Sha256Mac = "6be3caa84922e12aaaaa2f16c40d44433bb081ef323db584eb616333ab4e874f"; +const Sha512Mac = + "21910e341fa12106ca35758a2285374509326c9fbe0bd64e7b99c898f841dc948c58ce66d3504d8883c" + + "5ea7817a0b7c5d4d9b00364ccd214669131fc17fe4aca"; -describe('NodeCrypto Function Service', () => { - describe('pbkdf2', () => { - const regular256Key = 'pj9prw/OHPleXI6bRdmlaD+saJS4awrMiQsQiDjeu2I='; - const utf8256Key = 'yqvoFXgMRmHR3QPYr5pyR4uVuoHkltv9aHUP63p8n7I='; - const unicode256Key = 'ZdeOata6xoRpB4DLp8zHhXz5kLmkWtX5pd+TdRH8w8w='; +describe("NodeCrypto Function Service", () => { + describe("pbkdf2", () => { + const regular256Key = "pj9prw/OHPleXI6bRdmlaD+saJS4awrMiQsQiDjeu2I="; + const utf8256Key = "yqvoFXgMRmHR3QPYr5pyR4uVuoHkltv9aHUP63p8n7I="; + const unicode256Key = "ZdeOata6xoRpB4DLp8zHhXz5kLmkWtX5pd+TdRH8w8w="; - const regular512Key = 'liTi/Ke8LPU1Qv+Vl7NGEVt/XMbsBVJ2kQxtVG/Z1/JFHFKQW3ZkI81qVlwTiCpb+cFXzs+57' + - 'eyhhx5wfKo5Cg=='; - const utf8512Key = 'df0KdvIBeCzD/kyXptwQohaqUa4e7IyFUyhFQjXCANu5T+scq55hCcE4dG4T/MhAk2exw8j7ixRN' + - 'zXANiVZpnw=='; - const unicode512Key = 'FE+AnUJaxv8jh+zUDtZz4mjjcYk0/PZDZm+SLJe3XtxtnpdqqpblX6JjuMZt/dYYNMOrb2+mD' + - 'L3FiQDTROh1lg=='; + const regular512Key = + "liTi/Ke8LPU1Qv+Vl7NGEVt/XMbsBVJ2kQxtVG/Z1/JFHFKQW3ZkI81qVlwTiCpb+cFXzs+57" + + "eyhhx5wfKo5Cg=="; + const utf8512Key = + "df0KdvIBeCzD/kyXptwQohaqUa4e7IyFUyhFQjXCANu5T+scq55hCcE4dG4T/MhAk2exw8j7ixRN" + + "zXANiVZpnw=="; + const unicode512Key = + "FE+AnUJaxv8jh+zUDtZz4mjjcYk0/PZDZm+SLJe3XtxtnpdqqpblX6JjuMZt/dYYNMOrb2+mD" + + "L3FiQDTROh1lg=="; - testPbkdf2('sha256', regular256Key, utf8256Key, unicode256Key); - testPbkdf2('sha512', regular512Key, utf8512Key, unicode512Key); + testPbkdf2("sha256", regular256Key, utf8256Key, unicode256Key); + testPbkdf2("sha512", regular512Key, utf8512Key, unicode512Key); + }); + + describe("hkdf", () => { + const regular256Key = "qBUmEYtwTwwGPuw/z6bs/qYXXYNUlocFlyAuuANI8Pw="; + const utf8256Key = "6DfJwW1R3txgiZKkIFTvVAb7qVlG7lKcmJGJoxR2GBU="; + const unicode256Key = "gejGI82xthA+nKtKmIh82kjw+ttHr+ODsUoGdu5sf0A="; + + const regular512Key = "xe5cIG6ZfwGmb1FvsOedM0XKOm21myZkjL/eDeKIqqM="; + const utf8512Key = "XQMVBnxVEhlvjSFDQc77j5GDE9aorvbS0vKnjhRg0LY="; + const unicode512Key = "148GImrTbrjaGAe/iWEpclINM8Ehhko+9lB14+52lqc="; + + testHkdf("sha256", regular256Key, utf8256Key, unicode256Key); + testHkdf("sha512", regular512Key, utf8512Key, unicode512Key); + }); + + describe("hkdfExpand", () => { + const prk16Byte = "criAmKtfzxanbgea5/kelQ=="; + const prk32Byte = "F5h4KdYQnIVH4rKH0P9CZb1GrR4n16/sJrS0PsQEn0Y="; + const prk64Byte = + "ssBK0mRG17VHdtsgt8yo4v25CRNpauH+0r2fwY/E9rLyaFBAOMbIeTry+" + + "gUJ28p8y+hFh3EI9pcrEWaNvFYonQ=="; + + testHkdfExpand("sha256", prk32Byte, 32, "BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD8="); + testHkdfExpand( + "sha256", + prk32Byte, + 64, + "BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD9BV+" + + "/queOZenPNkDhmlVyL2WZ3OSU5+7ISNF5NhNfvZA==" + ); + testHkdfExpand("sha512", prk64Byte, 32, "uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlk="); + testHkdfExpand( + "sha512", + prk64Byte, + 64, + "uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlkY5Pv0sB+" + + "MqvaopmkC6sD/j89zDwTV9Ib2fpucUydO8w==" + ); + + it("should fail with prk too small", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const f = cryptoFunctionService.hkdfExpand( + Utils.fromB64ToArray(prk16Byte), + "info", + 32, + "sha256" + ); + await expectAsync(f).toBeRejectedWith(new Error("prk is too small.")); }); - describe('hkdf', () => { - const regular256Key = 'qBUmEYtwTwwGPuw/z6bs/qYXXYNUlocFlyAuuANI8Pw='; - const utf8256Key = '6DfJwW1R3txgiZKkIFTvVAb7qVlG7lKcmJGJoxR2GBU='; - const unicode256Key = 'gejGI82xthA+nKtKmIh82kjw+ttHr+ODsUoGdu5sf0A='; + it("should fail with outputByteSize is too large", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const f = cryptoFunctionService.hkdfExpand( + Utils.fromB64ToArray(prk32Byte), + "info", + 8161, + "sha256" + ); + await expectAsync(f).toBeRejectedWith(new Error("outputByteSize is too large.")); + }); + }); - const regular512Key = 'xe5cIG6ZfwGmb1FvsOedM0XKOm21myZkjL/eDeKIqqM='; - const utf8512Key = 'XQMVBnxVEhlvjSFDQc77j5GDE9aorvbS0vKnjhRg0LY='; - const unicode512Key = '148GImrTbrjaGAe/iWEpclINM8Ehhko+9lB14+52lqc='; + describe("hash", () => { + const regular1Hash = "2a241604fb921fad12bf877282457268e1dccb70"; + const utf81Hash = "85672798dc5831e96d6c48655d3d39365a9c88b6"; + const unicode1Hash = "39c975935054a3efc805a9709b60763a823a6ad4"; - testHkdf('sha256', regular256Key, utf8256Key, unicode256Key); - testHkdf('sha512', regular512Key, utf8512Key, unicode512Key); + const regular256Hash = "2b8e96031d352a8655d733d7a930b5ffbea69dc25cf65c7bca7dd946278908b2"; + const utf8256Hash = "25fe8440f5b01ed113b0a0e38e721b126d2f3f77a67518c4a04fcde4e33eeb9d"; + const unicode256Hash = "adc1c0c2afd6e92cefdf703f9b6eb2c38e0d6d1a040c83f8505c561fea58852e"; + + const regular512Hash = + "c15cf11d43bde333647e3f559ec4193bb2edeaa0e8b902772f514cdf3f785a3f49a6e02a4b87b3" + + "b47523271ad45b7e0aebb5cdcc1bc54815d256eb5dcb80da9d"; + const utf8512Hash = + "035c31a877a291af09ed2d3a1a293e69c3e079ea2cecc00211f35e6bce10474ca3ad6e30b59e26118" + + "37463f20969c5bc95282965a051a88f8cdf2e166549fcdd"; + const unicode512Hash = + "2b16a5561af8ad6fe414cc103fc8036492e1fc6d9aabe1b655497054f760fe0e34c5d100ac773d" + + "9f3030438284f22dbfa20cb2e9b019f2c98dfe38ce1ef41bae"; + + const regularMd5 = "5eceffa53a5fd58c44134211e2c5f522"; + const utf8Md5 = "3abc9433c09551b939c80aa0aa3174e1"; + const unicodeMd5 = "85ae134072c8d81257933f7045ba17ca"; + + testHash("sha1", regular1Hash, utf81Hash, unicode1Hash); + testHash("sha256", regular256Hash, utf8256Hash, unicode256Hash); + testHash("sha512", regular512Hash, utf8512Hash, unicode512Hash); + testHash("md5", regularMd5, utf8Md5, unicodeMd5); + }); + + describe("hmac", () => { + testHmac("sha1", Sha1Mac); + testHmac("sha256", Sha256Mac); + testHmac("sha512", Sha512Mac); + }); + + describe("compare", () => { + testCompare(false); + }); + + describe("hmacFast", () => { + testHmac("sha1", Sha1Mac, true); + testHmac("sha256", Sha256Mac, true); + testHmac("sha512", Sha512Mac, true); + }); + + describe("compareFast", () => { + testCompare(true); + }); + + describe("aesEncrypt", () => { + it("should successfully encrypt data", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const iv = makeStaticByteArray(16); + const key = makeStaticByteArray(32); + const data = Utils.fromUtf8ToArray("EncryptMe!"); + const encValue = await nodeCryptoFunctionService.aesEncrypt( + data.buffer, + iv.buffer, + key.buffer + ); + expect(Utils.fromBufferToB64(encValue)).toBe("ByUF8vhyX4ddU9gcooznwA=="); }); - describe('hkdfExpand', () => { - const prk16Byte = 'criAmKtfzxanbgea5/kelQ=='; - const prk32Byte = 'F5h4KdYQnIVH4rKH0P9CZb1GrR4n16/sJrS0PsQEn0Y='; - const prk64Byte = 'ssBK0mRG17VHdtsgt8yo4v25CRNpauH+0r2fwY/E9rLyaFBAOMbIeTry+' + - 'gUJ28p8y+hFh3EI9pcrEWaNvFYonQ=='; + it("should successfully encrypt and then decrypt data", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const iv = makeStaticByteArray(16); + const key = makeStaticByteArray(32); + const value = "EncryptMe!"; + const data = Utils.fromUtf8ToArray(value); + const encValue = await nodeCryptoFunctionService.aesEncrypt( + data.buffer, + iv.buffer, + key.buffer + ); + const decValue = await nodeCryptoFunctionService.aesDecrypt(encValue, iv.buffer, key.buffer); + expect(Utils.fromBufferToUtf8(decValue)).toBe(value); + }); + }); - testHkdfExpand('sha256', prk32Byte, 32, 'BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD8='); - testHkdfExpand('sha256', prk32Byte, 64, 'BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD9BV+' + - '/queOZenPNkDhmlVyL2WZ3OSU5+7ISNF5NhNfvZA=='); - testHkdfExpand('sha512', prk64Byte, 32, 'uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlk='); - testHkdfExpand('sha512', prk64Byte, 64, 'uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlkY5Pv0sB+' + - 'MqvaopmkC6sD/j89zDwTV9Ib2fpucUydO8w=='); + describe("aesDecryptFast", () => { + it("should successfully decrypt data", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const iv = Utils.fromBufferToB64(makeStaticByteArray(16).buffer); + const symKey = new SymmetricCryptoKey(makeStaticByteArray(32).buffer); + const data = "ByUF8vhyX4ddU9gcooznwA=="; + const params = nodeCryptoFunctionService.aesDecryptFastParameters(data, iv, null, symKey); + const decValue = await nodeCryptoFunctionService.aesDecryptFast(params); + expect(decValue).toBe("EncryptMe!"); + }); + }); - it('should fail with prk too small', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const f = cryptoFunctionService.hkdfExpand(Utils.fromB64ToArray(prk16Byte), 'info', 32, 'sha256'); - await expectAsync(f).toBeRejectedWith(new Error('prk is too small.')); - }); + describe("aesDecrypt", () => { + it("should successfully decrypt data", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const iv = makeStaticByteArray(16); + const key = makeStaticByteArray(32); + const data = Utils.fromB64ToArray("ByUF8vhyX4ddU9gcooznwA=="); + const decValue = await nodeCryptoFunctionService.aesDecrypt( + data.buffer, + iv.buffer, + key.buffer + ); + expect(Utils.fromBufferToUtf8(decValue)).toBe("EncryptMe!"); + }); + }); - it('should fail with outputByteSize is too large', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const f = cryptoFunctionService.hkdfExpand(Utils.fromB64ToArray(prk32Byte), 'info', 8161, 'sha256'); - await expectAsync(f).toBeRejectedWith(new Error('outputByteSize is too large.')); - }); + describe("rsaEncrypt", () => { + it("should successfully encrypt and then decrypt data", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const pubKey = Utils.fromB64ToArray(RsaPublicKey); + const privKey = Utils.fromB64ToArray(RsaPrivateKey); + const value = "EncryptMe!"; + const data = Utils.fromUtf8ToArray(value); + const encValue = await nodeCryptoFunctionService.rsaEncrypt( + data.buffer, + pubKey.buffer, + "sha1" + ); + const decValue = await nodeCryptoFunctionService.rsaDecrypt(encValue, privKey.buffer, "sha1"); + expect(Utils.fromBufferToUtf8(decValue)).toBe(value); + }); + }); + + describe("rsaDecrypt", () => { + it("should successfully decrypt data", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const privKey = Utils.fromB64ToArray(RsaPrivateKey); + const data = Utils.fromB64ToArray( + "A1/p8BQzN9UrbdYxUY2Va5+kPLyfZXF9JsZrjeEXcaclsnHurdxVAJcnbEqYMP3UXV" + + "4YAS/mpf+Rxe6/X0WS1boQdA0MAHSgx95hIlAraZYpiMLLiJRKeo2u8YivCdTM9V5vuAEJwf9Tof/qFsFci3sApdbATkorCT" + + "zFOIEPF2S1zgperEP23M01mr4dWVdYN18B32YF67xdJHMbFhp5dkQwv9CmscoWq7OE5HIfOb+JAh7BEZb+CmKhM3yWJvoR/D" + + "/5jcercUtK2o+XrzNrL4UQ7yLZcFz6Bfwb/j6ICYvqd/YJwXNE6dwlL57OfwJyCdw2rRYf0/qI00t9u8Iitw==" + ); + const decValue = await nodeCryptoFunctionService.rsaDecrypt( + data.buffer, + privKey.buffer, + "sha1" + ); + expect(Utils.fromBufferToUtf8(decValue)).toBe("EncryptMe!"); + }); + }); + + describe("rsaExtractPublicKey", () => { + it("should successfully extract key", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const privKey = Utils.fromB64ToArray(RsaPrivateKey); + const publicKey = await nodeCryptoFunctionService.rsaExtractPublicKey(privKey.buffer); + expect(Utils.fromBufferToB64(publicKey)).toBe(RsaPublicKey); + }); + }); + + describe("rsaGenerateKeyPair", () => { + testRsaGenerateKeyPair(1024); + testRsaGenerateKeyPair(2048); + + // Generating 4096 bit keys is really slow with Forge lib. + // Maybe move to something else if we ever want to generate keys of this size. + // testRsaGenerateKeyPair(4096); + }); + + describe("randomBytes", () => { + it("should make a value of the correct length", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const randomData = await nodeCryptoFunctionService.randomBytes(16); + expect(randomData.byteLength).toBe(16); }); - describe('hash', () => { - const regular1Hash = '2a241604fb921fad12bf877282457268e1dccb70'; - const utf81Hash = '85672798dc5831e96d6c48655d3d39365a9c88b6'; - const unicode1Hash = '39c975935054a3efc805a9709b60763a823a6ad4'; - - const regular256Hash = '2b8e96031d352a8655d733d7a930b5ffbea69dc25cf65c7bca7dd946278908b2'; - const utf8256Hash = '25fe8440f5b01ed113b0a0e38e721b126d2f3f77a67518c4a04fcde4e33eeb9d'; - const unicode256Hash = 'adc1c0c2afd6e92cefdf703f9b6eb2c38e0d6d1a040c83f8505c561fea58852e'; - - const regular512Hash = 'c15cf11d43bde333647e3f559ec4193bb2edeaa0e8b902772f514cdf3f785a3f49a6e02a4b87b3' + - 'b47523271ad45b7e0aebb5cdcc1bc54815d256eb5dcb80da9d'; - const utf8512Hash = '035c31a877a291af09ed2d3a1a293e69c3e079ea2cecc00211f35e6bce10474ca3ad6e30b59e26118' + - '37463f20969c5bc95282965a051a88f8cdf2e166549fcdd'; - const unicode512Hash = '2b16a5561af8ad6fe414cc103fc8036492e1fc6d9aabe1b655497054f760fe0e34c5d100ac773d' + - '9f3030438284f22dbfa20cb2e9b019f2c98dfe38ce1ef41bae'; - - const regularMd5 = '5eceffa53a5fd58c44134211e2c5f522'; - const utf8Md5 = '3abc9433c09551b939c80aa0aa3174e1'; - const unicodeMd5 = '85ae134072c8d81257933f7045ba17ca'; - - testHash('sha1', regular1Hash, utf81Hash, unicode1Hash); - testHash('sha256', regular256Hash, utf8256Hash, unicode256Hash); - testHash('sha512', regular512Hash, utf8512Hash, unicode512Hash); - testHash('md5', regularMd5, utf8Md5, unicodeMd5); - }); - - describe('hmac', () => { - testHmac('sha1', Sha1Mac); - testHmac('sha256', Sha256Mac); - testHmac('sha512', Sha512Mac); - }); - - describe('compare', () => { - testCompare(false); - }); - - describe('hmacFast', () => { - testHmac('sha1', Sha1Mac, true); - testHmac('sha256', Sha256Mac, true); - testHmac('sha512', Sha512Mac, true); - }); - - describe('compareFast', () => { - testCompare(true); - }); - - describe('aesEncrypt', () => { - it('should successfully encrypt data', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const iv = makeStaticByteArray(16); - const key = makeStaticByteArray(32); - const data = Utils.fromUtf8ToArray('EncryptMe!'); - const encValue = await nodeCryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); - expect(Utils.fromBufferToB64(encValue)).toBe('ByUF8vhyX4ddU9gcooznwA=='); - }); - - it('should successfully encrypt and then decrypt data', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const iv = makeStaticByteArray(16); - const key = makeStaticByteArray(32); - const value = 'EncryptMe!'; - const data = Utils.fromUtf8ToArray(value); - const encValue = await nodeCryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); - const decValue = await nodeCryptoFunctionService.aesDecrypt(encValue, iv.buffer, key.buffer); - expect(Utils.fromBufferToUtf8(decValue)).toBe(value); - }); - }); - - describe('aesDecryptFast', () => { - it('should successfully decrypt data', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const iv = Utils.fromBufferToB64(makeStaticByteArray(16).buffer); - const symKey = new SymmetricCryptoKey(makeStaticByteArray(32).buffer); - const data = 'ByUF8vhyX4ddU9gcooznwA=='; - const params = nodeCryptoFunctionService.aesDecryptFastParameters(data, iv, null, symKey); - const decValue = await nodeCryptoFunctionService.aesDecryptFast(params); - expect(decValue).toBe('EncryptMe!'); - }); - }); - - describe('aesDecrypt', () => { - it('should successfully decrypt data', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const iv = makeStaticByteArray(16); - const key = makeStaticByteArray(32); - const data = Utils.fromB64ToArray('ByUF8vhyX4ddU9gcooznwA=='); - const decValue = await nodeCryptoFunctionService.aesDecrypt(data.buffer, iv.buffer, key.buffer); - expect(Utils.fromBufferToUtf8(decValue)).toBe('EncryptMe!'); - }); - }); - - describe('rsaEncrypt', () => { - it('should successfully encrypt and then decrypt data', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const pubKey = Utils.fromB64ToArray(RsaPublicKey); - const privKey = Utils.fromB64ToArray(RsaPrivateKey); - const value = 'EncryptMe!'; - const data = Utils.fromUtf8ToArray(value); - const encValue = await nodeCryptoFunctionService.rsaEncrypt(data.buffer, pubKey.buffer, 'sha1'); - const decValue = await nodeCryptoFunctionService.rsaDecrypt(encValue, privKey.buffer, 'sha1'); - expect(Utils.fromBufferToUtf8(decValue)).toBe(value); - }); - }); - - describe('rsaDecrypt', () => { - it('should successfully decrypt data', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const privKey = Utils.fromB64ToArray(RsaPrivateKey); - const data = Utils.fromB64ToArray('A1/p8BQzN9UrbdYxUY2Va5+kPLyfZXF9JsZrjeEXcaclsnHurdxVAJcnbEqYMP3UXV' + - '4YAS/mpf+Rxe6/X0WS1boQdA0MAHSgx95hIlAraZYpiMLLiJRKeo2u8YivCdTM9V5vuAEJwf9Tof/qFsFci3sApdbATkorCT' + - 'zFOIEPF2S1zgperEP23M01mr4dWVdYN18B32YF67xdJHMbFhp5dkQwv9CmscoWq7OE5HIfOb+JAh7BEZb+CmKhM3yWJvoR/D' + - '/5jcercUtK2o+XrzNrL4UQ7yLZcFz6Bfwb/j6ICYvqd/YJwXNE6dwlL57OfwJyCdw2rRYf0/qI00t9u8Iitw=='); - const decValue = await nodeCryptoFunctionService.rsaDecrypt(data.buffer, privKey.buffer, 'sha1'); - expect(Utils.fromBufferToUtf8(decValue)).toBe('EncryptMe!'); - }); - }); - - describe('rsaExtractPublicKey', () => { - it('should successfully extract key', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const privKey = Utils.fromB64ToArray(RsaPrivateKey); - const publicKey = await nodeCryptoFunctionService.rsaExtractPublicKey(privKey.buffer); - expect(Utils.fromBufferToB64(publicKey)).toBe(RsaPublicKey); - }); - }); - - describe('rsaGenerateKeyPair', () => { - testRsaGenerateKeyPair(1024); - testRsaGenerateKeyPair(2048); - - // Generating 4096 bit keys is really slow with Forge lib. - // Maybe move to something else if we ever want to generate keys of this size. - // testRsaGenerateKeyPair(4096); - }); - - describe('randomBytes', () => { - it('should make a value of the correct length', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const randomData = await nodeCryptoFunctionService.randomBytes(16); - expect(randomData.byteLength).toBe(16); - }); - - it('should not make the same value twice', async () => { - const nodeCryptoFunctionService = new NodeCryptoFunctionService(); - const randomData = await nodeCryptoFunctionService.randomBytes(16); - const randomData2 = await nodeCryptoFunctionService.randomBytes(16); - expect(randomData.byteLength === randomData2.byteLength && randomData !== randomData2).toBeTruthy(); - }); + it("should not make the same value twice", async () => { + const nodeCryptoFunctionService = new NodeCryptoFunctionService(); + const randomData = await nodeCryptoFunctionService.randomBytes(16); + const randomData2 = await nodeCryptoFunctionService.randomBytes(16); + expect( + randomData.byteLength === randomData2.byteLength && randomData !== randomData2 + ).toBeTruthy(); }); + }); }); -function testPbkdf2(algorithm: 'sha256' | 'sha512', regularKey: string, utf8Key: string, unicodeKey: string) { - const regularEmail = 'user@example.com'; - const utf8Email = 'üser@example.com'; +function testPbkdf2( + algorithm: "sha256" | "sha512", + regularKey: string, + utf8Key: string, + unicodeKey: string +) { + const regularEmail = "user@example.com"; + const utf8Email = "üser@example.com"; - const regularPassword = 'password'; - const utf8Password = 'pǻssword'; - const unicodePassword = '😀password🙏'; + const regularPassword = "password"; + const utf8Password = "pǻssword"; + const unicodePassword = "😀password🙏"; - it('should create valid ' + algorithm + ' key from regular input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(regularPassword, regularEmail, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from regular input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2(regularPassword, regularEmail, algorithm, 5000); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); - it('should create valid ' + algorithm + ' key from utf8 input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(utf8Password, utf8Email, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(utf8Key); - }); + it("should create valid " + algorithm + " key from utf8 input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2(utf8Password, utf8Email, algorithm, 5000); + expect(Utils.fromBufferToB64(key)).toBe(utf8Key); + }); - it('should create valid ' + algorithm + ' key from unicode input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(unicodePassword, regularEmail, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); - }); + it("should create valid " + algorithm + " key from unicode input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2(unicodePassword, regularEmail, algorithm, 5000); + expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); + }); - it('should create valid ' + algorithm + ' key from array buffer input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(Utils.fromUtf8ToArray(regularPassword).buffer, - Utils.fromUtf8ToArray(regularEmail).buffer, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from array buffer input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2( + Utils.fromUtf8ToArray(regularPassword).buffer, + Utils.fromUtf8ToArray(regularEmail).buffer, + algorithm, + 5000 + ); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); } -function testHkdf(algorithm: 'sha256' | 'sha512', regularKey: string, utf8Key: string, unicodeKey: string) { - const ikm = Utils.fromB64ToArray('criAmKtfzxanbgea5/kelQ=='); +function testHkdf( + algorithm: "sha256" | "sha512", + regularKey: string, + utf8Key: string, + unicodeKey: string +) { + const ikm = Utils.fromB64ToArray("criAmKtfzxanbgea5/kelQ=="); - const regularSalt = 'salt'; - const utf8Salt = 'üser_salt'; - const unicodeSalt = '😀salt🙏'; + const regularSalt = "salt"; + const utf8Salt = "üser_salt"; + const unicodeSalt = "😀salt🙏"; - const regularInfo = 'info'; - const utf8Info = 'üser_info'; - const unicodeInfo = '😀info🙏'; + const regularInfo = "info"; + const utf8Info = "üser_info"; + const unicodeInfo = "😀info🙏"; - it('should create valid ' + algorithm + ' key from regular input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, regularSalt, regularInfo, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from regular input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf(ikm, regularSalt, regularInfo, 32, algorithm); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); - it('should create valid ' + algorithm + ' key from utf8 input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, utf8Salt, utf8Info, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(utf8Key); - }); + it("should create valid " + algorithm + " key from utf8 input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf(ikm, utf8Salt, utf8Info, 32, algorithm); + expect(Utils.fromBufferToB64(key)).toBe(utf8Key); + }); - it('should create valid ' + algorithm + ' key from unicode input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, unicodeSalt, unicodeInfo, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); - }); + it("should create valid " + algorithm + " key from unicode input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf(ikm, unicodeSalt, unicodeInfo, 32, algorithm); + expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); + }); - it('should create valid ' + algorithm + ' key from array buffer input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, Utils.fromUtf8ToArray(regularSalt).buffer, - Utils.fromUtf8ToArray(regularInfo).buffer, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from array buffer input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf( + ikm, + Utils.fromUtf8ToArray(regularSalt).buffer, + Utils.fromUtf8ToArray(regularInfo).buffer, + 32, + algorithm + ); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); } -function testHkdfExpand(algorithm: 'sha256' | 'sha512', b64prk: string, outputByteSize: number, - b64ExpectedOkm: string) { - const info = 'info'; +function testHkdfExpand( + algorithm: "sha256" | "sha512", + b64prk: string, + outputByteSize: number, + b64ExpectedOkm: string +) { + const info = "info"; - it('should create valid ' + algorithm + ' ' + outputByteSize + ' byte okm', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const okm = await cryptoFunctionService.hkdfExpand(Utils.fromB64ToArray(b64prk), info, outputByteSize, - algorithm); - expect(Utils.fromBufferToB64(okm)).toBe(b64ExpectedOkm); - }); + it("should create valid " + algorithm + " " + outputByteSize + " byte okm", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const okm = await cryptoFunctionService.hkdfExpand( + Utils.fromB64ToArray(b64prk), + info, + outputByteSize, + algorithm + ); + expect(Utils.fromBufferToB64(okm)).toBe(b64ExpectedOkm); + }); } -function testHash(algorithm: 'sha1' | 'sha256' | 'sha512' | 'md5', regularHash: string, - utf8Hash: string, unicodeHash: string) { - const regularValue = 'HashMe!!'; - const utf8Value = 'HǻshMe!!'; - const unicodeValue = '😀HashMe!!!🙏'; +function testHash( + algorithm: "sha1" | "sha256" | "sha512" | "md5", + regularHash: string, + utf8Hash: string, + unicodeHash: string +) { + const regularValue = "HashMe!!"; + const utf8Value = "HǻshMe!!"; + const unicodeValue = "😀HashMe!!!🙏"; - it('should create valid ' + algorithm + ' hash from regular input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(regularValue, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(regularHash); - }); + it("should create valid " + algorithm + " hash from regular input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const hash = await cryptoFunctionService.hash(regularValue, algorithm); + expect(Utils.fromBufferToHex(hash)).toBe(regularHash); + }); - it('should create valid ' + algorithm + ' hash from utf8 input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(utf8Value, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(utf8Hash); - }); + it("should create valid " + algorithm + " hash from utf8 input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const hash = await cryptoFunctionService.hash(utf8Value, algorithm); + expect(Utils.fromBufferToHex(hash)).toBe(utf8Hash); + }); - it('should create valid ' + algorithm + ' hash from unicode input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(unicodeValue, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(unicodeHash); - }); + it("should create valid " + algorithm + " hash from unicode input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const hash = await cryptoFunctionService.hash(unicodeValue, algorithm); + expect(Utils.fromBufferToHex(hash)).toBe(unicodeHash); + }); - it('should create valid ' + algorithm + ' hash from array buffer input', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(Utils.fromUtf8ToArray(regularValue).buffer, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(regularHash); - }); + it("should create valid " + algorithm + " hash from array buffer input", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const hash = await cryptoFunctionService.hash( + Utils.fromUtf8ToArray(regularValue).buffer, + algorithm + ); + expect(Utils.fromBufferToHex(hash)).toBe(regularHash); + }); } -function testHmac(algorithm: 'sha1' | 'sha256' | 'sha512', mac: string, fast = false) { - it('should create valid ' + algorithm + ' hmac', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const value = Utils.fromUtf8ToArray('SignMe!!').buffer; - const key = Utils.fromUtf8ToArray('secretkey').buffer; - let computedMac: ArrayBuffer = null; - if (fast) { - computedMac = await cryptoFunctionService.hmacFast(value, key, algorithm); - } else { - computedMac = await cryptoFunctionService.hmac(value, key, algorithm); - } - expect(Utils.fromBufferToHex(computedMac)).toBe(mac); - }); +function testHmac(algorithm: "sha1" | "sha256" | "sha512", mac: string, fast = false) { + it("should create valid " + algorithm + " hmac", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const value = Utils.fromUtf8ToArray("SignMe!!").buffer; + const key = Utils.fromUtf8ToArray("secretkey").buffer; + let computedMac: ArrayBuffer = null; + if (fast) { + computedMac = await cryptoFunctionService.hmacFast(value, key, algorithm); + } else { + computedMac = await cryptoFunctionService.hmac(value, key, algorithm); + } + expect(Utils.fromBufferToHex(computedMac)).toBe(mac); + }); } function testCompare(fast = false) { - it('should successfully compare two of the same values', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const equal = fast ? await cryptoFunctionService.compareFast(a.buffer, a.buffer) : - await cryptoFunctionService.compare(a.buffer, a.buffer); - expect(equal).toBe(true); - }); + it("should successfully compare two of the same values", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const equal = fast + ? await cryptoFunctionService.compareFast(a.buffer, a.buffer) + : await cryptoFunctionService.compare(a.buffer, a.buffer); + expect(equal).toBe(true); + }); - it('should successfully compare two different values of the same length', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const b = new Uint8Array(2); - b[0] = 3; - b[1] = 4; - const equal = fast ? await cryptoFunctionService.compareFast(a.buffer, b.buffer) : - await cryptoFunctionService.compare(a.buffer, b.buffer); - expect(equal).toBe(false); - }); + it("should successfully compare two different values of the same length", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const b = new Uint8Array(2); + b[0] = 3; + b[1] = 4; + const equal = fast + ? await cryptoFunctionService.compareFast(a.buffer, b.buffer) + : await cryptoFunctionService.compare(a.buffer, b.buffer); + expect(equal).toBe(false); + }); - it('should successfully compare two different values of different lengths', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const b = new Uint8Array(2); - b[0] = 3; - const equal = fast ? await cryptoFunctionService.compareFast(a.buffer, b.buffer) : - await cryptoFunctionService.compare(a.buffer, b.buffer); - expect(equal).toBe(false); - }); + it("should successfully compare two different values of different lengths", async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const b = new Uint8Array(2); + b[0] = 3; + const equal = fast + ? await cryptoFunctionService.compareFast(a.buffer, b.buffer) + : await cryptoFunctionService.compare(a.buffer, b.buffer); + expect(equal).toBe(false); + }); } function testRsaGenerateKeyPair(length: 1024 | 2048 | 4096) { - it('should successfully generate a ' + length + ' bit key pair', async () => { - const cryptoFunctionService = new NodeCryptoFunctionService(); - const keyPair = await cryptoFunctionService.rsaGenerateKeyPair(length); - expect(keyPair[0] == null || keyPair[1] == null).toBe(false); - const publicKey = await cryptoFunctionService.rsaExtractPublicKey(keyPair[1]); - expect(Utils.fromBufferToB64(keyPair[0])).toBe(Utils.fromBufferToB64(publicKey)); - }, 30000); + it( + "should successfully generate a " + length + " bit key pair", + async () => { + const cryptoFunctionService = new NodeCryptoFunctionService(); + const keyPair = await cryptoFunctionService.rsaGenerateKeyPair(length); + expect(keyPair[0] == null || keyPair[1] == null).toBe(false); + const publicKey = await cryptoFunctionService.rsaExtractPublicKey(keyPair[1]); + expect(Utils.fromBufferToB64(keyPair[0])).toBe(Utils.fromBufferToB64(publicKey)); + }, + 30000 + ); } function makeStaticByteArray(length: number) { - const arr = new Uint8Array(length); - for (let i = 0; i < length; i++) { - arr[i] = i; - } - return arr; + const arr = new Uint8Array(length); + for (let i = 0; i < length; i++) { + arr[i] = i; + } + return arr; } diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 96a0fe21..16cf8e93 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -1,13 +1,7 @@ { "spec_dir": "dist/spec", - "spec_files": [ - "common/**/*[sS]pec.js", - "node/**/*[sS]pec.js", - "electron/**/*[sS]pec.js" - ], - "helpers": [ - "helpers.js" - ], + "spec_files": ["common/**/*[sS]pec.js", "node/**/*[sS]pec.js", "electron/**/*[sS]pec.js"], + "helpers": ["helpers.js"], "stopSpecOnExpectationFailure": false, "random": true } diff --git a/spec/support/karma.conf.js b/spec/support/karma.conf.js index 471a3b07..3b5baa28 100644 --- a/spec/support/karma.conf.js +++ b/spec/support/karma.conf.js @@ -1,98 +1,98 @@ module.exports = (config) => { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '../../', + config.set({ + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: "../../", - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['jasmine', 'detectBrowsers'], + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ["jasmine", "detectBrowsers"], - // list of files / patterns to load in the browser - files: [ - { pattern: 'spec/utils.ts', watched: false }, - { pattern: 'spec/common/**/*.ts', watched: false }, - { pattern: 'spec/web/**/*.ts', watched: false }, + // list of files / patterns to load in the browser + files: [ + { pattern: "spec/utils.ts", watched: false }, + { pattern: "spec/common/**/*.ts", watched: false }, + { pattern: "spec/web/**/*.ts", watched: false }, + ], + + // list of files to exclude + exclude: [], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + "spec/**/*.ts": "webpack", + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ["progress", "kjhtml"], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity, + + client: { + clearContext: false, // leave Jasmine Spec Runner output visible in browser + }, + + webpack: { + resolve: { + extensions: [".js", ".ts", ".tsx"], + }, + module: { + rules: [ + { + test: /\.tsx?$/, + loader: "ts-loader", + options: { + compiler: "ttypescript", + }, + }, ], - - // list of files to exclude - exclude: [ - ], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - 'spec/**/*.ts': 'webpack' - }, - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress', 'kjhtml'], - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) + }, + stats: { colors: true, + modules: true, + reasons: true, + errorDetails: true, + }, + devtool: "inline-source-map", + }, - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, + detectBrowsers: { + usePhantomJS: false, + postDetection: (availableBrowsers) => { + const result = availableBrowsers; + function removeBrowser(browser) { + if (availableBrowsers.length > 1 && availableBrowsers.indexOf(browser) > -1) { + result.splice(result.indexOf(browser), 1); + } + } - // Concurrency level - // how many browser should be started simultaneous - concurrency: Infinity, + removeBrowser("IE"); + removeBrowser("Opera"); + removeBrowser("SafariTechPreview"); - client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, + var githubAction = + process.env.GITHUB_WORKFLOW != null && process.env.GITHUB_WORKFLOW !== ""; + if (githubAction) { + removeBrowser("Firefox"); + removeBrowser("Safari"); + } - webpack: { - resolve: { - extensions: ['.js', '.ts', '.tsx'], - }, - module: { - rules: [ - { - test: /\.tsx?$/, - loader: 'ts-loader', - options: { - compiler: 'ttypescript' - }, - }, - ], - }, - stats: { - colors: true, - modules: true, - reasons: true, - errorDetails: true, - }, - devtool: 'inline-source-map', - }, - - detectBrowsers: { - usePhantomJS: false, - postDetection: (availableBrowsers) => { - const result = availableBrowsers; - function removeBrowser(browser) { - if (availableBrowsers.length > 1 && availableBrowsers.indexOf(browser) > -1) { - result.splice(result.indexOf(browser), 1); - } - } - - removeBrowser('IE'); - removeBrowser('Opera'); - removeBrowser('SafariTechPreview'); - - var githubAction = process.env.GITHUB_WORKFLOW != null && process.env.GITHUB_WORKFLOW !== ''; - if (githubAction) { - removeBrowser('Firefox'); - removeBrowser('Safari'); - } - - return result; - } - }, - }) -} + return result; + }, + }, + }); +}; diff --git a/spec/utils.ts b/spec/utils.ts index 4df925ed..00cdcd3f 100644 --- a/spec/utils.ts +++ b/spec/utils.ts @@ -1,16 +1,19 @@ function newGuid() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { - // tslint:disable:no-bitwise - const r = Math.random() * 16 | 0; - const v = c === 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { + // tslint:disable:no-bitwise + const r = (Math.random() * 16) | 0; + const v = c === "x" ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); } -export function GetUniqueString(prefix: string = '') { - return prefix + '_' + newGuid(); +export function GetUniqueString(prefix: string = "") { + return prefix + "_" + newGuid(); } -export function BuildTestObject(def: Partial> | T, constructor?: (new () => T)): T { - return Object.assign(constructor === null ? {} : new constructor(), def) as T; +export function BuildTestObject( + def: Partial> | T, + constructor?: new () => T +): T { + return Object.assign(constructor === null ? {} : new constructor(), def) as T; } diff --git a/spec/web/services/webCryptoFunction.service.spec.ts b/spec/web/services/webCryptoFunction.service.spec.ts index 28d1082e..88ea3c0d 100644 --- a/spec/web/services/webCryptoFunction.service.spec.ts +++ b/spec/web/services/webCryptoFunction.service.spec.ts @@ -1,484 +1,567 @@ -import Substitute from '@fluffy-spoon/substitute'; +import Substitute from "@fluffy-spoon/substitute"; -import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; -import { WebCryptoFunctionService } from 'jslib-common/services/webCryptoFunction.service'; +import { WebCryptoFunctionService } from "jslib-common/services/webCryptoFunction.service"; -import { Utils } from 'jslib-common/misc/utils'; -import { SymmetricCryptoKey } from 'jslib-common/models/domain/symmetricCryptoKey'; +import { Utils } from "jslib-common/misc/utils"; +import { SymmetricCryptoKey } from "jslib-common/models/domain/symmetricCryptoKey"; -const RsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl0Vawl/toXzkEvB82FEtqHP' + - '4xlU2ab/v0crqIfXfIoWF/XXdHGIdrZeilnRXPPJT1B9dTsasttEZNnua/0Rek/cjNDHtzT52irfoZYS7X6HNIfOi54Q+egP' + - 'RQ1H7iNHVZz3K8Db9GCSKPeC8MbW6gVCzb15esCe1gGzg6wkMuWYDFYPoh/oBqcIqrGah7firqB1nDedzEjw32heP2DAffVN' + - '084iTDjiWrJNUxBJ2pDD5Z9dT3MzQ2s09ew1yMWK2z37rT3YerC7OgEDmo3WYo3xL3qYJznu3EO2nmrYjiRa40wKSjxsTlUc' + - 'xDF+F0uMW8oR9EMUHgepdepfAtLsSAQIDAQAB'; -const RsaPrivateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXRVrCX+2hfOQS8Hz' + - 'YUS2oc/jGVTZpv+/Ryuoh9d8ihYX9dd0cYh2tl6KWdFc88lPUH11Oxqy20Rk2e5r/RF6T9yM0Me3NPnaKt+hlhLtfoc0h86L' + - 'nhD56A9FDUfuI0dVnPcrwNv0YJIo94LwxtbqBULNvXl6wJ7WAbODrCQy5ZgMVg+iH+gGpwiqsZqHt+KuoHWcN53MSPDfaF4/' + - 'YMB99U3TziJMOOJask1TEEnakMPln11PczNDazT17DXIxYrbPfutPdh6sLs6AQOajdZijfEvepgnOe7cQ7aeatiOJFrjTApK' + - 'PGxOVRzEMX4XS4xbyhH0QxQeB6l16l8C0uxIBAgMBAAECggEASaWfeVDA3cVzOPFSpvJm20OTE+R6uGOU+7vh36TX/POq92q' + - 'Buwbd0h0oMD32FxsXywd2IxtBDUSiFM9699qufTVuM0Q3tZw6lHDTOVG08+tPdr8qSbMtw7PGFxN79fHLBxejjO4IrM9lapj' + - 'WpxEF+11x7r+wM+0xRZQ8sNFYG46aPfIaty4BGbL0I2DQ2y8I57iBCAy69eht59NLMm27fRWGJIWCuBIjlpfzET1j2HLXUIh' + - '5bTBNzqaN039WH49HczGE3mQKVEJZc/efk3HaVd0a1Sjzyn0QY+N1jtZN3jTRbuDWA1AknkX1LX/0tUhuS3/7C3ejHxjw4Dk' + - '1ZLo5/QKBgQDIWvqFn0+IKRSu6Ua2hDsufIHHUNLelbfLUMmFthxabcUn4zlvIscJO00Tq/ezopSRRvbGiqnxjv/mYxucvOU' + - 'BeZtlus0Q9RTACBtw9TGoNTmQbEunJ2FOSlqbQxkBBAjgGEppRPt30iGj/VjAhCATq2MYOa/X4dVR51BqQAFIEwKBgQDBSIf' + - 'TFKC/hDk6FKZlgwvupWYJyU9RkyfstPErZFmzoKhPkQ3YORo2oeAYmVUbS9I2iIYpYpYQJHX8jMuCbCz4ONxTCuSIXYQYUcU' + - 'q4PglCKp31xBAE6TN8SvhfME9/MvuDssnQinAHuF0GDAhF646T3LLS1not6Vszv7brwSoGwKBgQC88v/8cGfi80ssQZeMnVv' + - 'q1UTXIeQcQnoY5lGHJl3K8mbS3TnXE6c9j417Fdz+rj8KWzBzwWXQB5pSPflWcdZO886Xu/mVGmy9RWgLuVFhXwCwsVEPjNX' + - '5ramRb0/vY0yzenUCninBsIxFSbIfrPtLUYCc4hpxr+sr2Mg/y6jpvQKBgBezMRRs3xkcuXepuI2R+BCXL1/b02IJTUf1F+1' + - 'eLLGd7YV0H+J3fgNc7gGWK51hOrF9JBZHBGeOUPlaukmPwiPdtQZpu4QNE3l37VlIpKTF30E6mb+BqR+nht3rUjarnMXgAoE' + - 'Z18y6/KIjpSMpqC92Nnk/EBM9EYe6Cf4eA9ApAoGAeqEUg46UTlJySkBKURGpIs3v1kkf5I0X8DnOhwb+HPxNaiEdmO7ckm8' + - '+tPVgppLcG0+tMdLjigFQiDUQk2y3WjyxP5ZvXu7U96jaJRI8PFMoE06WeVYcdIzrID2HvqH+w0UQJFrLJ/0Mn4stFAEzXKZ' + - 'BokBGnjFnTnKcs7nv/O8='; +const RsaPublicKey = + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl0Vawl/toXzkEvB82FEtqHP" + + "4xlU2ab/v0crqIfXfIoWF/XXdHGIdrZeilnRXPPJT1B9dTsasttEZNnua/0Rek/cjNDHtzT52irfoZYS7X6HNIfOi54Q+egP" + + "RQ1H7iNHVZz3K8Db9GCSKPeC8MbW6gVCzb15esCe1gGzg6wkMuWYDFYPoh/oBqcIqrGah7firqB1nDedzEjw32heP2DAffVN" + + "084iTDjiWrJNUxBJ2pDD5Z9dT3MzQ2s09ew1yMWK2z37rT3YerC7OgEDmo3WYo3xL3qYJznu3EO2nmrYjiRa40wKSjxsTlUc" + + "xDF+F0uMW8oR9EMUHgepdepfAtLsSAQIDAQAB"; +const RsaPrivateKey = + "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXRVrCX+2hfOQS8Hz" + + "YUS2oc/jGVTZpv+/Ryuoh9d8ihYX9dd0cYh2tl6KWdFc88lPUH11Oxqy20Rk2e5r/RF6T9yM0Me3NPnaKt+hlhLtfoc0h86L" + + "nhD56A9FDUfuI0dVnPcrwNv0YJIo94LwxtbqBULNvXl6wJ7WAbODrCQy5ZgMVg+iH+gGpwiqsZqHt+KuoHWcN53MSPDfaF4/" + + "YMB99U3TziJMOOJask1TEEnakMPln11PczNDazT17DXIxYrbPfutPdh6sLs6AQOajdZijfEvepgnOe7cQ7aeatiOJFrjTApK" + + "PGxOVRzEMX4XS4xbyhH0QxQeB6l16l8C0uxIBAgMBAAECggEASaWfeVDA3cVzOPFSpvJm20OTE+R6uGOU+7vh36TX/POq92q" + + "Buwbd0h0oMD32FxsXywd2IxtBDUSiFM9699qufTVuM0Q3tZw6lHDTOVG08+tPdr8qSbMtw7PGFxN79fHLBxejjO4IrM9lapj" + + "WpxEF+11x7r+wM+0xRZQ8sNFYG46aPfIaty4BGbL0I2DQ2y8I57iBCAy69eht59NLMm27fRWGJIWCuBIjlpfzET1j2HLXUIh" + + "5bTBNzqaN039WH49HczGE3mQKVEJZc/efk3HaVd0a1Sjzyn0QY+N1jtZN3jTRbuDWA1AknkX1LX/0tUhuS3/7C3ejHxjw4Dk" + + "1ZLo5/QKBgQDIWvqFn0+IKRSu6Ua2hDsufIHHUNLelbfLUMmFthxabcUn4zlvIscJO00Tq/ezopSRRvbGiqnxjv/mYxucvOU" + + "BeZtlus0Q9RTACBtw9TGoNTmQbEunJ2FOSlqbQxkBBAjgGEppRPt30iGj/VjAhCATq2MYOa/X4dVR51BqQAFIEwKBgQDBSIf" + + "TFKC/hDk6FKZlgwvupWYJyU9RkyfstPErZFmzoKhPkQ3YORo2oeAYmVUbS9I2iIYpYpYQJHX8jMuCbCz4ONxTCuSIXYQYUcU" + + "q4PglCKp31xBAE6TN8SvhfME9/MvuDssnQinAHuF0GDAhF646T3LLS1not6Vszv7brwSoGwKBgQC88v/8cGfi80ssQZeMnVv" + + "q1UTXIeQcQnoY5lGHJl3K8mbS3TnXE6c9j417Fdz+rj8KWzBzwWXQB5pSPflWcdZO886Xu/mVGmy9RWgLuVFhXwCwsVEPjNX" + + "5ramRb0/vY0yzenUCninBsIxFSbIfrPtLUYCc4hpxr+sr2Mg/y6jpvQKBgBezMRRs3xkcuXepuI2R+BCXL1/b02IJTUf1F+1" + + "eLLGd7YV0H+J3fgNc7gGWK51hOrF9JBZHBGeOUPlaukmPwiPdtQZpu4QNE3l37VlIpKTF30E6mb+BqR+nht3rUjarnMXgAoE" + + "Z18y6/KIjpSMpqC92Nnk/EBM9EYe6Cf4eA9ApAoGAeqEUg46UTlJySkBKURGpIs3v1kkf5I0X8DnOhwb+HPxNaiEdmO7ckm8" + + "+tPVgppLcG0+tMdLjigFQiDUQk2y3WjyxP5ZvXu7U96jaJRI8PFMoE06WeVYcdIzrID2HvqH+w0UQJFrLJ/0Mn4stFAEzXKZ" + + "BokBGnjFnTnKcs7nv/O8="; -const Sha1Mac = '4d4c223f95dc577b665ec4ccbcb680b80a397038'; -const Sha256Mac = '6be3caa84922e12aaaaa2f16c40d44433bb081ef323db584eb616333ab4e874f'; -const Sha512Mac = '21910e341fa12106ca35758a2285374509326c9fbe0bd64e7b99c898f841dc948c58ce66d3504d8883c' + - '5ea7817a0b7c5d4d9b00364ccd214669131fc17fe4aca'; +const Sha1Mac = "4d4c223f95dc577b665ec4ccbcb680b80a397038"; +const Sha256Mac = "6be3caa84922e12aaaaa2f16c40d44433bb081ef323db584eb616333ab4e874f"; +const Sha512Mac = + "21910e341fa12106ca35758a2285374509326c9fbe0bd64e7b99c898f841dc948c58ce66d3504d8883c" + + "5ea7817a0b7c5d4d9b00364ccd214669131fc17fe4aca"; -describe('WebCrypto Function Service', () => { - describe('pbkdf2', () => { - const regular256Key = 'pj9prw/OHPleXI6bRdmlaD+saJS4awrMiQsQiDjeu2I='; - const utf8256Key = 'yqvoFXgMRmHR3QPYr5pyR4uVuoHkltv9aHUP63p8n7I='; - const unicode256Key = 'ZdeOata6xoRpB4DLp8zHhXz5kLmkWtX5pd+TdRH8w8w='; +describe("WebCrypto Function Service", () => { + describe("pbkdf2", () => { + const regular256Key = "pj9prw/OHPleXI6bRdmlaD+saJS4awrMiQsQiDjeu2I="; + const utf8256Key = "yqvoFXgMRmHR3QPYr5pyR4uVuoHkltv9aHUP63p8n7I="; + const unicode256Key = "ZdeOata6xoRpB4DLp8zHhXz5kLmkWtX5pd+TdRH8w8w="; - const regular512Key = 'liTi/Ke8LPU1Qv+Vl7NGEVt/XMbsBVJ2kQxtVG/Z1/JFHFKQW3ZkI81qVlwTiCpb+cFXzs+57' + - 'eyhhx5wfKo5Cg=='; - const utf8512Key = 'df0KdvIBeCzD/kyXptwQohaqUa4e7IyFUyhFQjXCANu5T+scq55hCcE4dG4T/MhAk2exw8j7ixRN' + - 'zXANiVZpnw=='; - const unicode512Key = 'FE+AnUJaxv8jh+zUDtZz4mjjcYk0/PZDZm+SLJe3XtxtnpdqqpblX6JjuMZt/dYYNMOrb2+mD' + - 'L3FiQDTROh1lg=='; + const regular512Key = + "liTi/Ke8LPU1Qv+Vl7NGEVt/XMbsBVJ2kQxtVG/Z1/JFHFKQW3ZkI81qVlwTiCpb+cFXzs+57" + + "eyhhx5wfKo5Cg=="; + const utf8512Key = + "df0KdvIBeCzD/kyXptwQohaqUa4e7IyFUyhFQjXCANu5T+scq55hCcE4dG4T/MhAk2exw8j7ixRN" + + "zXANiVZpnw=="; + const unicode512Key = + "FE+AnUJaxv8jh+zUDtZz4mjjcYk0/PZDZm+SLJe3XtxtnpdqqpblX6JjuMZt/dYYNMOrb2+mD" + + "L3FiQDTROh1lg=="; - testPbkdf2('sha256', regular256Key, utf8256Key, unicode256Key); - testPbkdf2('sha512', regular512Key, utf8512Key, unicode512Key); + testPbkdf2("sha256", regular256Key, utf8256Key, unicode256Key); + testPbkdf2("sha512", regular512Key, utf8512Key, unicode512Key); + }); + + describe("hkdf", () => { + const regular256Key = "qBUmEYtwTwwGPuw/z6bs/qYXXYNUlocFlyAuuANI8Pw="; + const utf8256Key = "6DfJwW1R3txgiZKkIFTvVAb7qVlG7lKcmJGJoxR2GBU="; + const unicode256Key = "gejGI82xthA+nKtKmIh82kjw+ttHr+ODsUoGdu5sf0A="; + + const regular512Key = "xe5cIG6ZfwGmb1FvsOedM0XKOm21myZkjL/eDeKIqqM="; + const utf8512Key = "XQMVBnxVEhlvjSFDQc77j5GDE9aorvbS0vKnjhRg0LY="; + const unicode512Key = "148GImrTbrjaGAe/iWEpclINM8Ehhko+9lB14+52lqc="; + + testHkdf("sha256", regular256Key, utf8256Key, unicode256Key); + testHkdf("sha512", regular512Key, utf8512Key, unicode512Key); + }); + + describe("hkdfExpand", () => { + const prk16Byte = "criAmKtfzxanbgea5/kelQ=="; + const prk32Byte = "F5h4KdYQnIVH4rKH0P9CZb1GrR4n16/sJrS0PsQEn0Y="; + const prk64Byte = + "ssBK0mRG17VHdtsgt8yo4v25CRNpauH+0r2fwY/E9rLyaFBAOMbIeTry+" + + "gUJ28p8y+hFh3EI9pcrEWaNvFYonQ=="; + + testHkdfExpand("sha256", prk32Byte, 32, "BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD8="); + testHkdfExpand( + "sha256", + prk32Byte, + 64, + "BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD9BV+" + + "/queOZenPNkDhmlVyL2WZ3OSU5+7ISNF5NhNfvZA==" + ); + testHkdfExpand("sha512", prk64Byte, 32, "uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlk="); + testHkdfExpand( + "sha512", + prk64Byte, + 64, + "uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlkY5Pv0sB+" + + "MqvaopmkC6sD/j89zDwTV9Ib2fpucUydO8w==" + ); + + it("should fail with prk too small", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const f = cryptoFunctionService.hkdfExpand( + Utils.fromB64ToArray(prk16Byte), + "info", + 32, + "sha256" + ); + await expectAsync(f).toBeRejectedWith(new Error("prk is too small.")); }); - describe('hkdf', () => { - const regular256Key = 'qBUmEYtwTwwGPuw/z6bs/qYXXYNUlocFlyAuuANI8Pw='; - const utf8256Key = '6DfJwW1R3txgiZKkIFTvVAb7qVlG7lKcmJGJoxR2GBU='; - const unicode256Key = 'gejGI82xthA+nKtKmIh82kjw+ttHr+ODsUoGdu5sf0A='; + it("should fail with outputByteSize is too large", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const f = cryptoFunctionService.hkdfExpand( + Utils.fromB64ToArray(prk32Byte), + "info", + 8161, + "sha256" + ); + await expectAsync(f).toBeRejectedWith(new Error("outputByteSize is too large.")); + }); + }); - const regular512Key = 'xe5cIG6ZfwGmb1FvsOedM0XKOm21myZkjL/eDeKIqqM='; - const utf8512Key = 'XQMVBnxVEhlvjSFDQc77j5GDE9aorvbS0vKnjhRg0LY='; - const unicode512Key = '148GImrTbrjaGAe/iWEpclINM8Ehhko+9lB14+52lqc='; + describe("hash", () => { + const regular1Hash = "2a241604fb921fad12bf877282457268e1dccb70"; + const utf81Hash = "85672798dc5831e96d6c48655d3d39365a9c88b6"; + const unicode1Hash = "39c975935054a3efc805a9709b60763a823a6ad4"; - testHkdf('sha256', regular256Key, utf8256Key, unicode256Key); - testHkdf('sha512', regular512Key, utf8512Key, unicode512Key); + const regular256Hash = "2b8e96031d352a8655d733d7a930b5ffbea69dc25cf65c7bca7dd946278908b2"; + const utf8256Hash = "25fe8440f5b01ed113b0a0e38e721b126d2f3f77a67518c4a04fcde4e33eeb9d"; + const unicode256Hash = "adc1c0c2afd6e92cefdf703f9b6eb2c38e0d6d1a040c83f8505c561fea58852e"; + + const regular512Hash = + "c15cf11d43bde333647e3f559ec4193bb2edeaa0e8b902772f514cdf3f785a3f49a6e02a4b87b3" + + "b47523271ad45b7e0aebb5cdcc1bc54815d256eb5dcb80da9d"; + const utf8512Hash = + "035c31a877a291af09ed2d3a1a293e69c3e079ea2cecc00211f35e6bce10474ca3ad6e30b59e26118" + + "37463f20969c5bc95282965a051a88f8cdf2e166549fcdd"; + const unicode512Hash = + "2b16a5561af8ad6fe414cc103fc8036492e1fc6d9aabe1b655497054f760fe0e34c5d100ac773d" + + "9f3030438284f22dbfa20cb2e9b019f2c98dfe38ce1ef41bae"; + + const regularMd5 = "5eceffa53a5fd58c44134211e2c5f522"; + const utf8Md5 = "3abc9433c09551b939c80aa0aa3174e1"; + const unicodeMd5 = "85ae134072c8d81257933f7045ba17ca"; + + testHash("sha1", regular1Hash, utf81Hash, unicode1Hash); + testHash("sha256", regular256Hash, utf8256Hash, unicode256Hash); + testHash("sha512", regular512Hash, utf8512Hash, unicode512Hash); + testHash("md5", regularMd5, utf8Md5, unicodeMd5); + }); + + describe("hmac", () => { + testHmac("sha1", Sha1Mac); + testHmac("sha256", Sha256Mac); + testHmac("sha512", Sha512Mac); + }); + + describe("compare", () => { + it("should successfully compare two of the same values", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const equal = await cryptoFunctionService.compare(a.buffer, a.buffer); + expect(equal).toBe(true); }); - describe('hkdfExpand', () => { - const prk16Byte = 'criAmKtfzxanbgea5/kelQ=='; - const prk32Byte = 'F5h4KdYQnIVH4rKH0P9CZb1GrR4n16/sJrS0PsQEn0Y='; - const prk64Byte = 'ssBK0mRG17VHdtsgt8yo4v25CRNpauH+0r2fwY/E9rLyaFBAOMbIeTry+' + - 'gUJ28p8y+hFh3EI9pcrEWaNvFYonQ=='; - - testHkdfExpand('sha256', prk32Byte, 32, 'BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD8='); - testHkdfExpand('sha256', prk32Byte, 64, 'BnIqJlfnHm0e/2iB/15cbHyR19ARPIcWRp4oNS22CD9BV+' + - '/queOZenPNkDhmlVyL2WZ3OSU5+7ISNF5NhNfvZA=='); - testHkdfExpand('sha512', prk64Byte, 32, 'uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlk='); - testHkdfExpand('sha512', prk64Byte, 64, 'uLWbMWodSBms5uGJ5WTRTesyW+MD7nlpCZvagvIRXlkY5Pv0sB+' + - 'MqvaopmkC6sD/j89zDwTV9Ib2fpucUydO8w=='); - - it('should fail with prk too small', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const f = cryptoFunctionService.hkdfExpand(Utils.fromB64ToArray(prk16Byte), 'info', 32, 'sha256'); - await expectAsync(f).toBeRejectedWith(new Error('prk is too small.')); - }); - - it('should fail with outputByteSize is too large', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const f = cryptoFunctionService.hkdfExpand(Utils.fromB64ToArray(prk32Byte), 'info', 8161, 'sha256'); - await expectAsync(f).toBeRejectedWith(new Error('outputByteSize is too large.')); - }); + it("should successfully compare two different values of the same length", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const b = new Uint8Array(2); + b[0] = 3; + b[1] = 4; + const equal = await cryptoFunctionService.compare(a.buffer, b.buffer); + expect(equal).toBe(false); }); - describe('hash', () => { - const regular1Hash = '2a241604fb921fad12bf877282457268e1dccb70'; - const utf81Hash = '85672798dc5831e96d6c48655d3d39365a9c88b6'; - const unicode1Hash = '39c975935054a3efc805a9709b60763a823a6ad4'; + it("should successfully compare two different values of different lengths", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const b = new Uint8Array(2); + b[0] = 3; + const equal = await cryptoFunctionService.compare(a.buffer, b.buffer); + expect(equal).toBe(false); + }); + }); - const regular256Hash = '2b8e96031d352a8655d733d7a930b5ffbea69dc25cf65c7bca7dd946278908b2'; - const utf8256Hash = '25fe8440f5b01ed113b0a0e38e721b126d2f3f77a67518c4a04fcde4e33eeb9d'; - const unicode256Hash = 'adc1c0c2afd6e92cefdf703f9b6eb2c38e0d6d1a040c83f8505c561fea58852e'; + describe("hmacFast", () => { + testHmacFast("sha1", Sha1Mac); + testHmacFast("sha256", Sha256Mac); + testHmacFast("sha512", Sha512Mac); + }); - const regular512Hash = 'c15cf11d43bde333647e3f559ec4193bb2edeaa0e8b902772f514cdf3f785a3f49a6e02a4b87b3' + - 'b47523271ad45b7e0aebb5cdcc1bc54815d256eb5dcb80da9d'; - const utf8512Hash = '035c31a877a291af09ed2d3a1a293e69c3e079ea2cecc00211f35e6bce10474ca3ad6e30b59e26118' + - '37463f20969c5bc95282965a051a88f8cdf2e166549fcdd'; - const unicode512Hash = '2b16a5561af8ad6fe414cc103fc8036492e1fc6d9aabe1b655497054f760fe0e34c5d100ac773d' + - '9f3030438284f22dbfa20cb2e9b019f2c98dfe38ce1ef41bae'; - - const regularMd5 = '5eceffa53a5fd58c44134211e2c5f522'; - const utf8Md5 = '3abc9433c09551b939c80aa0aa3174e1'; - const unicodeMd5 = '85ae134072c8d81257933f7045ba17ca'; - - testHash('sha1', regular1Hash, utf81Hash, unicode1Hash); - testHash('sha256', regular256Hash, utf8256Hash, unicode256Hash); - testHash('sha512', regular512Hash, utf8512Hash, unicode512Hash); - testHash('md5', regularMd5, utf8Md5, unicodeMd5); + describe("compareFast", () => { + it("should successfully compare two of the same values", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const aByteString = Utils.fromBufferToByteString(a.buffer); + const equal = await cryptoFunctionService.compareFast(aByteString, aByteString); + expect(equal).toBe(true); }); - describe('hmac', () => { - testHmac('sha1', Sha1Mac); - testHmac('sha256', Sha256Mac); - testHmac('sha512', Sha512Mac); + it("should successfully compare two different values of the same length", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const aByteString = Utils.fromBufferToByteString(a.buffer); + const b = new Uint8Array(2); + b[0] = 3; + b[1] = 4; + const bByteString = Utils.fromBufferToByteString(b.buffer); + const equal = await cryptoFunctionService.compareFast(aByteString, bByteString); + expect(equal).toBe(false); }); - describe('compare', () => { - it('should successfully compare two of the same values', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const equal = await cryptoFunctionService.compare(a.buffer, a.buffer); - expect(equal).toBe(true); - }); + it("should successfully compare two different values of different lengths", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const a = new Uint8Array(2); + a[0] = 1; + a[1] = 2; + const aByteString = Utils.fromBufferToByteString(a.buffer); + const b = new Uint8Array(2); + b[0] = 3; + const bByteString = Utils.fromBufferToByteString(b.buffer); + const equal = await cryptoFunctionService.compareFast(aByteString, bByteString); + expect(equal).toBe(false); + }); + }); - it('should successfully compare two different values of the same length', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const b = new Uint8Array(2); - b[0] = 3; - b[1] = 4; - const equal = await cryptoFunctionService.compare(a.buffer, b.buffer); - expect(equal).toBe(false); - }); - - it('should successfully compare two different values of different lengths', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const b = new Uint8Array(2); - b[0] = 3; - const equal = await cryptoFunctionService.compare(a.buffer, b.buffer); - expect(equal).toBe(false); - }); + describe("aesEncrypt", () => { + it("should successfully encrypt data", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const iv = makeStaticByteArray(16); + const key = makeStaticByteArray(32); + const data = Utils.fromUtf8ToArray("EncryptMe!"); + const encValue = await cryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); + expect(Utils.fromBufferToB64(encValue)).toBe("ByUF8vhyX4ddU9gcooznwA=="); }); - describe('hmacFast', () => { - testHmacFast('sha1', Sha1Mac); - testHmacFast('sha256', Sha256Mac); - testHmacFast('sha512', Sha512Mac); + it("should successfully encrypt and then decrypt data fast", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const iv = makeStaticByteArray(16); + const key = makeStaticByteArray(32); + const value = "EncryptMe!"; + const data = Utils.fromUtf8ToArray(value); + const encValue = await cryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); + const encData = Utils.fromBufferToB64(encValue); + const b64Iv = Utils.fromBufferToB64(iv.buffer); + const symKey = new SymmetricCryptoKey(key.buffer); + const params = cryptoFunctionService.aesDecryptFastParameters(encData, b64Iv, null, symKey); + const decValue = await cryptoFunctionService.aesDecryptFast(params); + expect(decValue).toBe(value); }); - describe('compareFast', () => { - it('should successfully compare two of the same values', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const aByteString = Utils.fromBufferToByteString(a.buffer); - const equal = await cryptoFunctionService.compareFast(aByteString, aByteString); - expect(equal).toBe(true); - }); + it("should successfully encrypt and then decrypt data", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const iv = makeStaticByteArray(16); + const key = makeStaticByteArray(32); + const value = "EncryptMe!"; + const data = Utils.fromUtf8ToArray(value); + const encValue = await cryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); + const decValue = await cryptoFunctionService.aesDecrypt(encValue, iv.buffer, key.buffer); + expect(Utils.fromBufferToUtf8(decValue)).toBe(value); + }); + }); - it('should successfully compare two different values of the same length', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const aByteString = Utils.fromBufferToByteString(a.buffer); - const b = new Uint8Array(2); - b[0] = 3; - b[1] = 4; - const bByteString = Utils.fromBufferToByteString(b.buffer); - const equal = await cryptoFunctionService.compareFast(aByteString, bByteString); - expect(equal).toBe(false); - }); + describe("aesDecryptFast", () => { + it("should successfully decrypt data", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const iv = Utils.fromBufferToB64(makeStaticByteArray(16).buffer); + const symKey = new SymmetricCryptoKey(makeStaticByteArray(32).buffer); + const data = "ByUF8vhyX4ddU9gcooznwA=="; + const params = cryptoFunctionService.aesDecryptFastParameters(data, iv, null, symKey); + const decValue = await cryptoFunctionService.aesDecryptFast(params); + expect(decValue).toBe("EncryptMe!"); + }); + }); - it('should successfully compare two different values of different lengths', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const a = new Uint8Array(2); - a[0] = 1; - a[1] = 2; - const aByteString = Utils.fromBufferToByteString(a.buffer); - const b = new Uint8Array(2); - b[0] = 3; - const bByteString = Utils.fromBufferToByteString(b.buffer); - const equal = await cryptoFunctionService.compareFast(aByteString, bByteString); - expect(equal).toBe(false); - }); + describe("aesDecrypt", () => { + it("should successfully decrypt data", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const iv = makeStaticByteArray(16); + const key = makeStaticByteArray(32); + const data = Utils.fromB64ToArray("ByUF8vhyX4ddU9gcooznwA=="); + const decValue = await cryptoFunctionService.aesDecrypt(data.buffer, iv.buffer, key.buffer); + expect(Utils.fromBufferToUtf8(decValue)).toBe("EncryptMe!"); + }); + }); + + describe("rsaEncrypt", () => { + it("should successfully encrypt and then decrypt data", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const pubKey = Utils.fromB64ToArray(RsaPublicKey); + const privKey = Utils.fromB64ToArray(RsaPrivateKey); + const value = "EncryptMe!"; + const data = Utils.fromUtf8ToArray(value); + const encValue = await cryptoFunctionService.rsaEncrypt(data.buffer, pubKey.buffer, "sha1"); + const decValue = await cryptoFunctionService.rsaDecrypt(encValue, privKey.buffer, "sha1"); + expect(Utils.fromBufferToUtf8(decValue)).toBe(value); + }); + }); + + describe("rsaDecrypt", () => { + it("should successfully decrypt data", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const privKey = Utils.fromB64ToArray(RsaPrivateKey); + const data = Utils.fromB64ToArray( + "A1/p8BQzN9UrbdYxUY2Va5+kPLyfZXF9JsZrjeEXcaclsnHurdxVAJcnbEqYMP3UXV" + + "4YAS/mpf+Rxe6/X0WS1boQdA0MAHSgx95hIlAraZYpiMLLiJRKeo2u8YivCdTM9V5vuAEJwf9Tof/qFsFci3sApdbATkorCT" + + "zFOIEPF2S1zgperEP23M01mr4dWVdYN18B32YF67xdJHMbFhp5dkQwv9CmscoWq7OE5HIfOb+JAh7BEZb+CmKhM3yWJvoR/D" + + "/5jcercUtK2o+XrzNrL4UQ7yLZcFz6Bfwb/j6ICYvqd/YJwXNE6dwlL57OfwJyCdw2rRYf0/qI00t9u8Iitw==" + ); + const decValue = await cryptoFunctionService.rsaDecrypt(data.buffer, privKey.buffer, "sha1"); + expect(Utils.fromBufferToUtf8(decValue)).toBe("EncryptMe!"); + }); + }); + + describe("rsaExtractPublicKey", () => { + it("should successfully extract key", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const privKey = Utils.fromB64ToArray(RsaPrivateKey); + const publicKey = await cryptoFunctionService.rsaExtractPublicKey(privKey.buffer); + expect(Utils.fromBufferToB64(publicKey)).toBe(RsaPublicKey); + }); + }); + + describe("rsaGenerateKeyPair", () => { + testRsaGenerateKeyPair(1024); + testRsaGenerateKeyPair(2048); + + // Generating 4096 bit keys can be slow. Commenting it out to save CI. + // testRsaGenerateKeyPair(4096); + }); + + describe("randomBytes", () => { + it("should make a value of the correct length", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const randomData = await cryptoFunctionService.randomBytes(16); + expect(randomData.byteLength).toBe(16); }); - describe('aesEncrypt', () => { - it('should successfully encrypt data', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const iv = makeStaticByteArray(16); - const key = makeStaticByteArray(32); - const data = Utils.fromUtf8ToArray('EncryptMe!'); - const encValue = await cryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); - expect(Utils.fromBufferToB64(encValue)).toBe('ByUF8vhyX4ddU9gcooznwA=='); - }); - - it('should successfully encrypt and then decrypt data fast', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const iv = makeStaticByteArray(16); - const key = makeStaticByteArray(32); - const value = 'EncryptMe!'; - const data = Utils.fromUtf8ToArray(value); - const encValue = await cryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); - const encData = Utils.fromBufferToB64(encValue); - const b64Iv = Utils.fromBufferToB64(iv.buffer); - const symKey = new SymmetricCryptoKey(key.buffer); - const params = cryptoFunctionService.aesDecryptFastParameters(encData, b64Iv, null, symKey); - const decValue = await cryptoFunctionService.aesDecryptFast(params); - expect(decValue).toBe(value); - }); - - it('should successfully encrypt and then decrypt data', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const iv = makeStaticByteArray(16); - const key = makeStaticByteArray(32); - const value = 'EncryptMe!'; - const data = Utils.fromUtf8ToArray(value); - const encValue = await cryptoFunctionService.aesEncrypt(data.buffer, iv.buffer, key.buffer); - const decValue = await cryptoFunctionService.aesDecrypt(encValue, iv.buffer, key.buffer); - expect(Utils.fromBufferToUtf8(decValue)).toBe(value); - }); - }); - - describe('aesDecryptFast', () => { - it('should successfully decrypt data', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const iv = Utils.fromBufferToB64(makeStaticByteArray(16).buffer); - const symKey = new SymmetricCryptoKey(makeStaticByteArray(32).buffer); - const data = 'ByUF8vhyX4ddU9gcooznwA=='; - const params = cryptoFunctionService.aesDecryptFastParameters(data, iv, null, symKey); - const decValue = await cryptoFunctionService.aesDecryptFast(params); - expect(decValue).toBe('EncryptMe!'); - }); - }); - - describe('aesDecrypt', () => { - it('should successfully decrypt data', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const iv = makeStaticByteArray(16); - const key = makeStaticByteArray(32); - const data = Utils.fromB64ToArray('ByUF8vhyX4ddU9gcooznwA=='); - const decValue = await cryptoFunctionService.aesDecrypt(data.buffer, iv.buffer, key.buffer); - expect(Utils.fromBufferToUtf8(decValue)).toBe('EncryptMe!'); - }); - }); - - describe('rsaEncrypt', () => { - it('should successfully encrypt and then decrypt data', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const pubKey = Utils.fromB64ToArray(RsaPublicKey); - const privKey = Utils.fromB64ToArray(RsaPrivateKey); - const value = 'EncryptMe!'; - const data = Utils.fromUtf8ToArray(value); - const encValue = await cryptoFunctionService.rsaEncrypt(data.buffer, pubKey.buffer, 'sha1'); - const decValue = await cryptoFunctionService.rsaDecrypt(encValue, privKey.buffer, 'sha1'); - expect(Utils.fromBufferToUtf8(decValue)).toBe(value); - }); - }); - - describe('rsaDecrypt', () => { - it('should successfully decrypt data', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const privKey = Utils.fromB64ToArray(RsaPrivateKey); - const data = Utils.fromB64ToArray('A1/p8BQzN9UrbdYxUY2Va5+kPLyfZXF9JsZrjeEXcaclsnHurdxVAJcnbEqYMP3UXV' + - '4YAS/mpf+Rxe6/X0WS1boQdA0MAHSgx95hIlAraZYpiMLLiJRKeo2u8YivCdTM9V5vuAEJwf9Tof/qFsFci3sApdbATkorCT' + - 'zFOIEPF2S1zgperEP23M01mr4dWVdYN18B32YF67xdJHMbFhp5dkQwv9CmscoWq7OE5HIfOb+JAh7BEZb+CmKhM3yWJvoR/D' + - '/5jcercUtK2o+XrzNrL4UQ7yLZcFz6Bfwb/j6ICYvqd/YJwXNE6dwlL57OfwJyCdw2rRYf0/qI00t9u8Iitw=='); - const decValue = await cryptoFunctionService.rsaDecrypt(data.buffer, privKey.buffer, 'sha1'); - expect(Utils.fromBufferToUtf8(decValue)).toBe('EncryptMe!'); - }); - }); - - describe('rsaExtractPublicKey', () => { - it('should successfully extract key', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const privKey = Utils.fromB64ToArray(RsaPrivateKey); - const publicKey = await cryptoFunctionService.rsaExtractPublicKey(privKey.buffer); - expect(Utils.fromBufferToB64(publicKey)).toBe(RsaPublicKey); - }); - }); - - describe('rsaGenerateKeyPair', () => { - testRsaGenerateKeyPair(1024); - testRsaGenerateKeyPair(2048); - - // Generating 4096 bit keys can be slow. Commenting it out to save CI. - // testRsaGenerateKeyPair(4096); - }); - - describe('randomBytes', () => { - it('should make a value of the correct length', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const randomData = await cryptoFunctionService.randomBytes(16); - expect(randomData.byteLength).toBe(16); - }); - - it('should not make the same value twice', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const randomData = await cryptoFunctionService.randomBytes(16); - const randomData2 = await cryptoFunctionService.randomBytes(16); - expect(randomData.byteLength === randomData2.byteLength && randomData !== randomData2).toBeTruthy(); - }); + it("should not make the same value twice", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const randomData = await cryptoFunctionService.randomBytes(16); + const randomData2 = await cryptoFunctionService.randomBytes(16); + expect( + randomData.byteLength === randomData2.byteLength && randomData !== randomData2 + ).toBeTruthy(); }); + }); }); -function testPbkdf2(algorithm: 'sha256' | 'sha512', regularKey: string, - utf8Key: string, unicodeKey: string) { - const regularEmail = 'user@example.com'; - const utf8Email = 'üser@example.com'; +function testPbkdf2( + algorithm: "sha256" | "sha512", + regularKey: string, + utf8Key: string, + unicodeKey: string +) { + const regularEmail = "user@example.com"; + const utf8Email = "üser@example.com"; - const regularPassword = 'password'; - const utf8Password = 'pǻssword'; - const unicodePassword = '😀password🙏'; + const regularPassword = "password"; + const utf8Password = "pǻssword"; + const unicodePassword = "😀password🙏"; - it('should create valid ' + algorithm + ' key from regular input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(regularPassword, regularEmail, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from regular input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2(regularPassword, regularEmail, algorithm, 5000); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); - it('should create valid ' + algorithm + ' key from utf8 input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(utf8Password, utf8Email, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(utf8Key); - }); + it("should create valid " + algorithm + " key from utf8 input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2(utf8Password, utf8Email, algorithm, 5000); + expect(Utils.fromBufferToB64(key)).toBe(utf8Key); + }); - it('should create valid ' + algorithm + ' key from unicode input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(unicodePassword, regularEmail, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); - }); + it("should create valid " + algorithm + " key from unicode input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2(unicodePassword, regularEmail, algorithm, 5000); + expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); + }); - it('should create valid ' + algorithm + ' key from array buffer input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.pbkdf2(Utils.fromUtf8ToArray(regularPassword).buffer, - Utils.fromUtf8ToArray(regularEmail).buffer, algorithm, 5000); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from array buffer input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.pbkdf2( + Utils.fromUtf8ToArray(regularPassword).buffer, + Utils.fromUtf8ToArray(regularEmail).buffer, + algorithm, + 5000 + ); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); } -function testHkdf(algorithm: 'sha256' | 'sha512', regularKey: string, utf8Key: string, unicodeKey: string) { - const ikm = Utils.fromB64ToArray('criAmKtfzxanbgea5/kelQ=='); +function testHkdf( + algorithm: "sha256" | "sha512", + regularKey: string, + utf8Key: string, + unicodeKey: string +) { + const ikm = Utils.fromB64ToArray("criAmKtfzxanbgea5/kelQ=="); - const regularSalt = 'salt'; - const utf8Salt = 'üser_salt'; - const unicodeSalt = '😀salt🙏'; + const regularSalt = "salt"; + const utf8Salt = "üser_salt"; + const unicodeSalt = "😀salt🙏"; - const regularInfo = 'info'; - const utf8Info = 'üser_info'; - const unicodeInfo = '😀info🙏'; + const regularInfo = "info"; + const utf8Info = "üser_info"; + const unicodeInfo = "😀info🙏"; - it('should create valid ' + algorithm + ' key from regular input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, regularSalt, regularInfo, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from regular input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf(ikm, regularSalt, regularInfo, 32, algorithm); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); - it('should create valid ' + algorithm + ' key from utf8 input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, utf8Salt, utf8Info, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(utf8Key); - }); + it("should create valid " + algorithm + " key from utf8 input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf(ikm, utf8Salt, utf8Info, 32, algorithm); + expect(Utils.fromBufferToB64(key)).toBe(utf8Key); + }); - it('should create valid ' + algorithm + ' key from unicode input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, unicodeSalt, unicodeInfo, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); - }); + it("should create valid " + algorithm + " key from unicode input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf(ikm, unicodeSalt, unicodeInfo, 32, algorithm); + expect(Utils.fromBufferToB64(key)).toBe(unicodeKey); + }); - it('should create valid ' + algorithm + ' key from array buffer input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const key = await cryptoFunctionService.hkdf(ikm, Utils.fromUtf8ToArray(regularSalt).buffer, - Utils.fromUtf8ToArray(regularInfo).buffer, 32, algorithm); - expect(Utils.fromBufferToB64(key)).toBe(regularKey); - }); + it("should create valid " + algorithm + " key from array buffer input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const key = await cryptoFunctionService.hkdf( + ikm, + Utils.fromUtf8ToArray(regularSalt).buffer, + Utils.fromUtf8ToArray(regularInfo).buffer, + 32, + algorithm + ); + expect(Utils.fromBufferToB64(key)).toBe(regularKey); + }); } -function testHkdfExpand(algorithm: 'sha256' | 'sha512', b64prk: string, outputByteSize: number, - b64ExpectedOkm: string) { - const info = 'info'; +function testHkdfExpand( + algorithm: "sha256" | "sha512", + b64prk: string, + outputByteSize: number, + b64ExpectedOkm: string +) { + const info = "info"; - it('should create valid ' + algorithm + ' ' + outputByteSize + ' byte okm', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const okm = await cryptoFunctionService.hkdfExpand(Utils.fromB64ToArray(b64prk), info, outputByteSize, - algorithm); - expect(Utils.fromBufferToB64(okm)).toBe(b64ExpectedOkm); - }); + it("should create valid " + algorithm + " " + outputByteSize + " byte okm", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const okm = await cryptoFunctionService.hkdfExpand( + Utils.fromB64ToArray(b64prk), + info, + outputByteSize, + algorithm + ); + expect(Utils.fromBufferToB64(okm)).toBe(b64ExpectedOkm); + }); } -function testHash(algorithm: 'sha1' | 'sha256' | 'sha512' | 'md5', regularHash: string, - utf8Hash: string, unicodeHash: string) { - const regularValue = 'HashMe!!'; - const utf8Value = 'HǻshMe!!'; - const unicodeValue = '😀HashMe!!!🙏'; +function testHash( + algorithm: "sha1" | "sha256" | "sha512" | "md5", + regularHash: string, + utf8Hash: string, + unicodeHash: string +) { + const regularValue = "HashMe!!"; + const utf8Value = "HǻshMe!!"; + const unicodeValue = "😀HashMe!!!🙏"; - it('should create valid ' + algorithm + ' hash from regular input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(regularValue, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(regularHash); - }); + it("should create valid " + algorithm + " hash from regular input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const hash = await cryptoFunctionService.hash(regularValue, algorithm); + expect(Utils.fromBufferToHex(hash)).toBe(regularHash); + }); - it('should create valid ' + algorithm + ' hash from utf8 input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(utf8Value, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(utf8Hash); - }); + it("should create valid " + algorithm + " hash from utf8 input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const hash = await cryptoFunctionService.hash(utf8Value, algorithm); + expect(Utils.fromBufferToHex(hash)).toBe(utf8Hash); + }); - it('should create valid ' + algorithm + ' hash from unicode input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(unicodeValue, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(unicodeHash); - }); + it("should create valid " + algorithm + " hash from unicode input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const hash = await cryptoFunctionService.hash(unicodeValue, algorithm); + expect(Utils.fromBufferToHex(hash)).toBe(unicodeHash); + }); - it('should create valid ' + algorithm + ' hash from array buffer input', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const hash = await cryptoFunctionService.hash(Utils.fromUtf8ToArray(regularValue).buffer, algorithm); - expect(Utils.fromBufferToHex(hash)).toBe(regularHash); - }); + it("should create valid " + algorithm + " hash from array buffer input", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const hash = await cryptoFunctionService.hash( + Utils.fromUtf8ToArray(regularValue).buffer, + algorithm + ); + expect(Utils.fromBufferToHex(hash)).toBe(regularHash); + }); } -function testHmac(algorithm: 'sha1' | 'sha256' | 'sha512', mac: string) { - it('should create valid ' + algorithm + ' hmac', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const computedMac = await cryptoFunctionService.hmac(Utils.fromUtf8ToArray('SignMe!!').buffer, - Utils.fromUtf8ToArray('secretkey').buffer, algorithm); - expect(Utils.fromBufferToHex(computedMac)).toBe(mac); - }); +function testHmac(algorithm: "sha1" | "sha256" | "sha512", mac: string) { + it("should create valid " + algorithm + " hmac", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const computedMac = await cryptoFunctionService.hmac( + Utils.fromUtf8ToArray("SignMe!!").buffer, + Utils.fromUtf8ToArray("secretkey").buffer, + algorithm + ); + expect(Utils.fromBufferToHex(computedMac)).toBe(mac); + }); } -function testHmacFast(algorithm: 'sha1' | 'sha256' | 'sha512', mac: string) { - it('should create valid ' + algorithm + ' hmac', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const keyByteString = Utils.fromBufferToByteString(Utils.fromUtf8ToArray('secretkey').buffer); - const dataByteString = Utils.fromBufferToByteString(Utils.fromUtf8ToArray('SignMe!!').buffer); - const computedMac = await cryptoFunctionService.hmacFast(dataByteString, keyByteString, algorithm); - expect(Utils.fromBufferToHex(Utils.fromByteStringToArray(computedMac).buffer)).toBe(mac); - }); +function testHmacFast(algorithm: "sha1" | "sha256" | "sha512", mac: string) { + it("should create valid " + algorithm + " hmac", async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const keyByteString = Utils.fromBufferToByteString(Utils.fromUtf8ToArray("secretkey").buffer); + const dataByteString = Utils.fromBufferToByteString(Utils.fromUtf8ToArray("SignMe!!").buffer); + const computedMac = await cryptoFunctionService.hmacFast( + dataByteString, + keyByteString, + algorithm + ); + expect(Utils.fromBufferToHex(Utils.fromByteStringToArray(computedMac).buffer)).toBe(mac); + }); } function testRsaGenerateKeyPair(length: 1024 | 2048 | 4096) { - it('should successfully generate a ' + length + ' bit key pair', async () => { - const cryptoFunctionService = getWebCryptoFunctionService(); - const keyPair = await cryptoFunctionService.rsaGenerateKeyPair(length); - expect(keyPair[0] == null || keyPair[1] == null).toBe(false); - const publicKey = await cryptoFunctionService.rsaExtractPublicKey(keyPair[1]); - expect(Utils.fromBufferToB64(keyPair[0])).toBe(Utils.fromBufferToB64(publicKey)); - }, 30000); + it( + "should successfully generate a " + length + " bit key pair", + async () => { + const cryptoFunctionService = getWebCryptoFunctionService(); + const keyPair = await cryptoFunctionService.rsaGenerateKeyPair(length); + expect(keyPair[0] == null || keyPair[1] == null).toBe(false); + const publicKey = await cryptoFunctionService.rsaExtractPublicKey(keyPair[1]); + expect(Utils.fromBufferToB64(keyPair[0])).toBe(Utils.fromBufferToB64(publicKey)); + }, + 30000 + ); } function getWebCryptoFunctionService() { - const platformUtilsMock = Substitute.for(); - platformUtilsMock.isEdge().mimicks(() => navigator.userAgent.indexOf(' Edg/') !== -1); - platformUtilsMock.isIE().mimicks(() => navigator.userAgent.indexOf(' Edg/') === -1 && - navigator.userAgent.indexOf(' Trident/') !== -1); + const platformUtilsMock = Substitute.for(); + platformUtilsMock.isEdge().mimicks(() => navigator.userAgent.indexOf(" Edg/") !== -1); + platformUtilsMock + .isIE() + .mimicks( + () => + navigator.userAgent.indexOf(" Edg/") === -1 && + navigator.userAgent.indexOf(" Trident/") !== -1 + ); - return new WebCryptoFunctionService(window, platformUtilsMock); + return new WebCryptoFunctionService(window, platformUtilsMock); } function makeStaticByteArray(length: number) { - const arr = new Uint8Array(length); - for (let i = 0; i < length; i++) { - arr[i] = i; - } - return arr; + const arr = new Uint8Array(length); + for (let i = 0; i < length; i++) { + arr[i] = i; + } + return arr; } diff --git a/tsconfig.json b/tsconfig.json index e6d3af86..5e56a682 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,18 +15,10 @@ "outDir": "dist", "baseUrl": ".", "paths": { - "jslib-common/*": [ - "common/src/*" - ], - "jslib-angular/*": [ - "angular/src/*" - ], - "jslib-electron/*": [ - "electron/src/*" - ], - "jslib-node/*": [ - "node/src/*" - ] + "jslib-common/*": ["common/src/*"], + "jslib-angular/*": ["angular/src/*"], + "jslib-electron/*": ["electron/src/*"], + "jslib-node/*": ["node/src/*"] }, "plugins": [ { @@ -34,11 +26,6 @@ } ] }, - "include": [ - "spec" - ], - "exclude": [ - "node_modules", - "dist" - ] + "include": ["spec"], + "exclude": ["node_modules", "dist"] } diff --git a/tslint.json b/tslint.json index 4122e547..4df19690 100644 --- a/tslint.json +++ b/tslint.json @@ -2,17 +2,17 @@ "extends": "tslint:recommended", "rules": { "interface-name": [false], - "align": [ true, "statements", "members" ], + "align": [true, "statements", "members"], "ban-types": { "options": [ - [ "Object", "Avoid using the `Object` type. Did you mean `object`?" ], - [ "Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?" ], - [ "Number", "Avoid using the `Number` type. Did you mean `number`?" ], - [ "String", "Avoid using the `String` type. Did you mean `string`?" ], - [ "Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?" ] + ["Object", "Avoid using the `Object` type. Did you mean `object`?"], + ["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"], + ["Number", "Avoid using the `Number` type. Did you mean `number`?"], + ["String", "Avoid using the `String` type. Did you mean `string`?"], + ["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"] ] }, - "member-access": [ true, "no-public" ], + "member-access": [true, "no-public"], "member-ordering": [ true, { @@ -35,9 +35,9 @@ ] } ], - "no-empty": [ true ], + "no-empty": [true], "object-literal-sort-keys": false, - "object-literal-shorthand": [ true, "never" ], + "object-literal-shorthand": [true, "never"], "ordered-imports": true, "prefer-for-of": false, "whitespace": [