Skip to content

Commit

Permalink
feat: Add name property to COZY_ATTRIBUTES_MAPPING
Browse files Browse the repository at this point in the history
This property matches the fieldQualifier with
the property name of a Cozy Contact.
This removes the recently created `bitwardenToCozy`,
which played much the same role.
  • Loading branch information
Merkur39 committed Sep 10, 2024
1 parent 0ad4fc9 commit c5793f2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
6 changes: 3 additions & 3 deletions apps/browser/src/autofill/background/overlay.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
import { AutofillService } from "../services/abstractions/autofill.service";
import {
ambiguousContactFieldNames,
bitwardenToCozy,
generateRandomChars,
getAmbiguousFieldsContact,
} from "../utils";
Expand Down Expand Up @@ -77,6 +76,7 @@ import { CONTACTS_DOCTYPE } from "cozy-client/dist/models/contact";
import { nameToColor } from "cozy-ui/transpiled/react/Avatar/helpers";
import { CozyClientService } from "../../popup/services/cozyClient.service";
import { AmbiguousContactFieldName, AmbiguousContactFieldValue } from "src/autofill/types";
import { COZY_ATTRIBUTES_MAPPING } from "../../../../../libs/cozy/mapping";
/* eslint-enable */
/* end Cozy imports */

Expand Down Expand Up @@ -906,7 +906,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
const ambiguousContactFields = getAmbiguousFieldsContact(ambiguousContactFieldNames, contact);

const isFocusedFieldAmbigous = ambiguousContactFieldNames.includes(
bitwardenToCozy[this.focusedFieldData?.fieldQualifier],
COZY_ATTRIBUTES_MAPPING[this.focusedFieldData?.fieldQualifier].name as AmbiguousContactFieldName,
);
const hasMultipleAmbiguousValueInSameField = Object.values(ambiguousContactFields).some(
(item) => item.length > 1,
Expand All @@ -915,7 +915,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
// On an ambiguous form field, the associated contact values are kept.
const ambiguousFormFieldsOfFocusedField = Object.fromEntries(
Object.entries(ambiguousContactFields).filter(
([fieldName]) => fieldName === bitwardenToCozy[this.focusedFieldData?.fieldQualifier],
([fieldName]) => fieldName === COZY_ATTRIBUTES_MAPPING[this.focusedFieldData?.fieldQualifier].name,
),
);
// On an unambiguous form field, we keep only the multiple values of an ambiguous contact field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { CipherType } from "@bitwarden/common/vault/enums";
import { InlineMenuCipherData } from "../../../../background/abstractions/overlay.background";
import {
ambiguousContactFieldNames,
bitwardenToCozy,
buildSvgDomElement,
getAmbiguousValueKey,
makeAmbiguousValueLabel,
Expand Down Expand Up @@ -36,6 +35,7 @@ import {
AmbiguousContactFieldValue,
AmbiguousContactFieldName,
} from "src/autofill/types";
import { COZY_ATTRIBUTES_MAPPING } from "../../../../../../../../libs/cozy/mapping";
/* eslint-enable */
/* end Cozy imports */

Expand Down Expand Up @@ -251,7 +251,7 @@ export class AutofillInlineMenuList extends AutofillInlineMenuPageElement {
// Cozy customization - On the contact ambiguous fields, if the field has a value, the corresponding menu is displayed directly. Unless we wish to return to the contact cypher list.
if (
this.fieldValue &&
ambiguousContactFieldNames.includes(bitwardenToCozy[this.fieldQualifier]) &&
ambiguousContactFieldNames.includes(COZY_ATTRIBUTES_MAPPING[this.fieldQualifier].name as AmbiguousContactFieldName) &&
!isBack
) {
this.postMessageToParent({
Expand Down Expand Up @@ -396,7 +396,7 @@ export class AutofillInlineMenuList extends AutofillInlineMenuPageElement {
subNameSpan.classList.add("cipher-subtitle");

// Reverse the class for the current ambiguous field
if (bitwardenToCozy[this.fieldQualifier] === ambiguousKey) {
if (COZY_ATTRIBUTES_MAPPING[this.fieldQualifier].name === ambiguousKey) {
subNameSpan.classList.replace("cipher-subtitle", "cipher-name");
nameSpan.classList.replace("cipher-name", "cipher-subtitle");
}
Expand Down Expand Up @@ -546,7 +546,7 @@ export class AutofillInlineMenuList extends AutofillInlineMenuPageElement {
});

const firstAmbiguousFieldEntries = Object.entries(ambiguousFields)?.[0];
const firstAmbiguousFieldName = firstAmbiguousFieldEntries?.[0] as AmbiguousContactFieldName || bitwardenToCozy[this.fieldQualifier];
const firstAmbiguousFieldName = firstAmbiguousFieldEntries?.[0] as AmbiguousContactFieldName || COZY_ATTRIBUTES_MAPPING[this.fieldQualifier].name as AmbiguousContactFieldName;

if (firstAmbiguousFieldEntries) {
for (const firstAmbiguousFieldValue of firstAmbiguousFieldEntries[1]) {
Expand Down
12 changes: 0 additions & 12 deletions apps/browser/src/autofill/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { IOCozyContact } from "cozy-client/types/types";

// Cozy customization
import { AutofillFieldQualifierType } from "src/autofill/enums/autofill-field.enums";
// Cozy customization end

import { AutofillPort } from "../enums/autofill-port.enum";
import {
AmbiguousContactFields,
Expand Down Expand Up @@ -384,14 +380,6 @@ export const getAmbiguousFieldsContact = (
{},
);
};
export const bitwardenToCozy: Partial<
Record<AutofillFieldQualifierType, AmbiguousContactFieldName>
> = {
identityPhone: "phone",
identityEmail: "email",
identityAddress1: "address",
identityState: "address",
};
export const ambiguousContactFieldNames: AmbiguousContactFieldName[] = [
"phone",
"email",
Expand Down
27 changes: 27 additions & 0 deletions libs/cozy/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
export type CozyAttributesModel = {
doctype: string;
path: string;
name: string;
isPathArray?: boolean;
pathAttributes?: string[]; // pathAttibutess are joined to form the final value
selector?: {
Expand All @@ -20,134 +21,160 @@ export type CozyAttributesMapping = {
export const COZY_ATTRIBUTES_MAPPING: CozyAttributesMapping = {
[AutofillFieldQualifier.identityFullName]: {
doctype: "io.cozy.contacts",
name: "displayName",
path: "displayName",
},
[AutofillFieldQualifier.identityFirstName]: {
doctype: "io.cozy.contacts",
name: "givenName",
path: "name.givenName",
},
[AutofillFieldQualifier.identityMiddleName]: {
doctype: "io.cozy.contacts",
name: "additionalName",
path: "name.additionalName",
},
[AutofillFieldQualifier.identityLastName]: {
doctype: "io.cozy.contacts",
name: "familyName",
path: "name.familyName",
},
[AutofillFieldQualifier.identityCompany]: {
doctype: "io.cozy.contacts",
name: "company",
path: "company",
},
[AutofillFieldQualifier.identityPhone]: {
doctype: "io.cozy.contacts",
path: "phone",
name: "phone",
isPathArray: true,
pathAttributes: ["number"],
},
[AutofillFieldQualifier.identityEmail]: {
doctype: "io.cozy.contacts",
path: "email",
name: "email",
isPathArray: true,
pathAttributes: ["address"],
},
[AutofillFieldQualifier.identityAddress1]: {
doctype: "io.cozy.contacts",
path: "address",
name: "address",
isPathArray: true,
pathAttributes: ["number", "street"],
},
[AutofillFieldQualifier.identityCity]: {
doctype: "io.cozy.contacts",
path: "address",
name: "address",
isPathArray: true,
pathAttributes: ["city"],
},
[AutofillFieldQualifier.identityState]: {
doctype: "io.cozy.contacts",
path: "address",
name: "address",
isPathArray: true,
pathAttributes: ["region"],
},
[AutofillFieldQualifier.identityPostalCode]: {
doctype: "io.cozy.contacts",
path: "address",
name: "address",
isPathArray: true,
pathAttributes: ["code"],
},
[AutofillFieldQualifier.identityCountry]: {
doctype: "io.cozy.contacts",
path: "address",
name: "address",
isPathArray: true,
pathAttributes: ["country"],
},
[AutofillFieldQualifier.paperIdentityCardNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "national_id_card" },
},
[AutofillFieldQualifier.paperPassportNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "passport" },
},
[AutofillFieldQualifier.paperSocialSecurityNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "national_health_insurance_card" },
},
[AutofillFieldQualifier.paperResidencePermitNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "residence_permit" },
},
[AutofillFieldQualifier.paperDrivingLicenseNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "driver_license" },
},
[AutofillFieldQualifier.paperVehicleRegistrationNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "vehicle_registration" },
},
[AutofillFieldQualifier.paperVehicleRegistrationConfidentialCode]: {
doctype: "io.cozy.files",
path: "metadata.vehicle.confidentialNumber",
name: "confidentialNumber",
selector: { "metadata.qualification.label": "vehicle_registration" },
},
[AutofillFieldQualifier.paperVehicleRegistrationLicensePlateNumber]: {
doctype: "io.cozy.files",
path: "metadata.vehicle.licenseNumber",
name: "licenseNumber",
selector: { "metadata.qualification.label": "vehicle_registration" },
},
[AutofillFieldQualifier.paperBankIbanNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "bank_details" },
},
[AutofillFieldQualifier.paperBankBicNumber]: {
doctype: "io.cozy.files",
path: "metadata.bicNumber",
name: "bicNumber",
selector: { "metadata.qualification.label": "bank_details" },
},
[AutofillFieldQualifier.paperGrossSalaryAmount]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "pay_sheet" },
},
[AutofillFieldQualifier.paperNetSalaryAmount]: {
doctype: "io.cozy.files",
path: "metadata.netSocialAmount",
name: "netSocialAmount",
selector: { "metadata.qualification.label": "pay_sheet" },
},
[AutofillFieldQualifier.paperTaxNoticeNumber]: {
doctype: "io.cozy.files",
path: "metadata.number",
name: "number",
selector: { "metadata.qualification.label": "tax_notice" },
},
[AutofillFieldQualifier.paperTaxNoticeRefTaxIncome]: {
doctype: "io.cozy.files",
path: "metadata.refTaxIncome",
name: "refTaxIncome",
selector: {
"metadata.qualification.label": "tax_notice",
"metadata.refTaxIncome": { $gt: null }, // some tax notice do not have ref tax income set
Expand Down

0 comments on commit c5793f2

Please sign in to comment.