Skip to content

Commit

Permalink
feat: added physical and electronic addresses to contact-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Brummos committed Feb 19, 2024
1 parent 1aa7c3d commit 76f78b3
Show file tree
Hide file tree
Showing 17 changed files with 2,124 additions and 301 deletions.
439 changes: 386 additions & 53 deletions packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/contact-manager/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ constants:
- cmAddContactType
- cmUpdateContactType
- cmRemoveContactType
- cmGetElectronicAddress
- cmGetElectronicAddresses
- cmAddElectronicAddress
- cmUpdateElectronicAddress
- cmRemoveElectronicAddress
- cmGetPhysicalAddress
- cmGetPhysicalAddresses
- cmAddPhysicalAddress
- cmUpdatePhysicalAddress
- cmRemovePhysicalAddress

dbConnection:
$require: typeorm?t=function#createConnection
Expand Down
166 changes: 128 additions & 38 deletions packages/contact-manager/src/agent/ContactManager.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
import {
AbstractContactStore,
ElectronicAddress,
Identity,
NonPersistedContact,
Party as Contact,
PartyRelationship as ContactRelationship,
PartyType as ContactType,
PhysicalAddress,
isNaturalPerson,
isOrganization,
} from '@sphereon/ssi-sdk.data-store'
import { IAgentPlugin } from '@veramo/core'
import { schema } from '../index'
import {
AddContactArgs,
UpdateContactArgs,
GetIdentitiesArgs,
RemoveContactArgs,
AddContactTypeArgs,
AddElectronicAddressArgs,
AddIdentityArgs,
IContactManager,
GetIdentityArgs,
RemoveIdentityArgs,
RequiredContext,
UpdateIdentityArgs,
GetContactsArgs,
GetContactArgs,
AddPhysicalAddressArgs,
AddRelationshipArgs,
RemoveRelationshipArgs,
GetRelationshipArgs,
GetRelationshipsArgs,
UpdateRelationshipArgs,
AddContactTypeArgs,
GetContactArgs,
GetContactTypeArgs,
GetContactTypesArgs,
GetContactsArgs,
GetElectronicAddressArgs,
GetElectronicAddressesArgs,
GetIdentitiesArgs,
GetIdentityArgs,
GetPhysicalAddressArgs,
GetPhysicalAddressesArgs,
GetRelationshipArgs,
GetRelationshipsArgs,
IContactManager,
RemoveContactArgs,
RemoveContactTypeArgs,
RemoveElectronicAddressArgs,
RemoveIdentityArgs,
RemovePhysicalAddressArgs,
RemoveRelationshipArgs,
RequiredContext,
UpdateContactArgs,
UpdateContactTypeArgs,
UpdateElectronicAddressArgs,
UpdateIdentityArgs,
UpdatePhysicalAddressArgs,
UpdateRelationshipArgs,
} from '../types/IContactManager'
import {
AbstractContactStore,
Party as Contact,
Identity,
PartyRelationship as ContactRelationship,
PartyType as ContactType,
NonPersistedContact,
isNaturalPerson,
isOrganization,
} from '@sphereon/ssi-sdk.data-store'

/**
* {@inheritDoc IContactManager}
Expand Down Expand Up @@ -61,6 +73,16 @@ export class ContactManager implements IAgentPlugin {
cmAddContactType: this.cmAddContactType.bind(this),
cmUpdateContactType: this.cmUpdateContactType.bind(this),
cmRemoveContactType: this.cmRemoveContactType.bind(this),
cmGetElectronicAddress: this.cmGetElectronicAddress.bind(this),
cmGetElectronicAddresses: this.cmGetElectronicAddresses.bind(this),
cmAddElectronicAddress: this.cmAddElectronicAddress.bind(this),
cmUpdateElectronicAddress: this.cmUpdateElectronicAddress.bind(this),
cmRemoveElectronicAddress: this.cmRemoveElectronicAddress.bind(this),
cmGetPhysicalAddress: this.cmGetPhysicalAddress.bind(this),
cmGetPhysicalAddresses: this.cmGetPhysicalAddresses.bind(this),
cmAddPhysicalAddress: this.cmAddPhysicalAddress.bind(this),
cmUpdatePhysicalAddress: this.cmUpdatePhysicalAddress.bind(this),
cmRemovePhysicalAddress: this.cmRemovePhysicalAddress.bind(this),
}

private readonly store: AbstractContactStore
Expand All @@ -71,7 +93,8 @@ export class ContactManager implements IAgentPlugin {

/** {@inheritDoc IContactManager.cmGetContact} */
private async cmGetContact(args: GetContactArgs, context: RequiredContext): Promise<Contact> {
return this.store.getParty({ partyId: args.contactId })
const { contactId } = args
return this.store.getParty({ partyId: contactId })
}

/** {@inheritDoc IContactManager.cmGetContacts} */
Expand All @@ -81,23 +104,34 @@ export class ContactManager implements IAgentPlugin {

/** {@inheritDoc IContactManager.cmAddContact} */
private async cmAddContact(args: AddContactArgs, context: RequiredContext): Promise<Contact> {
const {
uri,
contactType,
identities,
electronicAddresses,
physicalAddresses
} = args

return this.store.addParty({
uri: args.uri,
partyType: args.contactType,
uri,
partyType: contactType,
contact: this.getContactInformationFrom(args),
identities: args.identities,
electronicAddresses: args.electronicAddresses,
identities,
electronicAddresses,
physicalAddresses, // TODO test adding this
})
}

/** {@inheritDoc IContactManager.cmUpdateContact} */
private async cmUpdateContact(args: UpdateContactArgs, context: RequiredContext): Promise<Contact> {
return this.store.updateParty({ party: args.contact })
const { contact } = args
return this.store.updateParty({ party: contact })
}

/** {@inheritDoc IContactManager.cmRemoveContact} */
private async cmRemoveContact(args: RemoveContactArgs, context: RequiredContext): Promise<boolean> {
return this.store.removeParty({ partyId: args.contactId }).then(() => true)
const { contactId } = args
return this.store.removeParty({ partyId: contactId }).then((): boolean => true)
}

/** {@inheritDoc IContactManager.cmGetIdentity} */
Expand All @@ -112,7 +146,8 @@ export class ContactManager implements IAgentPlugin {

/** {@inheritDoc IContactManager.cmAddIdentity} */
private async cmAddIdentity(args: AddIdentityArgs, context: RequiredContext): Promise<Identity> {
return this.store.addIdentity({ partyId: args.contactId, identity: args.identity })
const { contactId, identity } = args
return this.store.addIdentity({ partyId: contactId, identity })
}

/** {@inheritDoc IContactManager.cmUpdateIdentity} */
Expand All @@ -122,7 +157,7 @@ export class ContactManager implements IAgentPlugin {

/** {@inheritDoc IContactManager.cmRemoveIdentity} */
private async cmRemoveIdentity(args: RemoveIdentityArgs, context: RequiredContext): Promise<boolean> {
return this.store.removeIdentity(args).then(() => true)
return this.store.removeIdentity(args).then((): boolean => true)
}

/** {@inheritDoc IContactManager.cmAddRelationship} */
Expand All @@ -132,7 +167,7 @@ export class ContactManager implements IAgentPlugin {

/** {@inheritDoc IContactManager.cmRemoveRelationship} */
private async cmRemoveRelationship(args: RemoveRelationshipArgs, context: RequiredContext): Promise<boolean> {
return this.store.removeRelationship(args).then(() => true)
return this.store.removeRelationship(args).then((): boolean => true)
}

/** {@inheritDoc IContactManager.cmGetRelationship} */
Expand All @@ -152,7 +187,8 @@ export class ContactManager implements IAgentPlugin {

/** {@inheritDoc IContactManager.cmGetContactType} */
private async cmGetContactType(args: GetContactTypeArgs, context: RequiredContext): Promise<ContactType> {
return this.store.getPartyType({ partyTypeId: args.contactTypeId })
const { contactTypeId } = args
return this.store.getPartyType({ partyTypeId: contactTypeId })
}

/** {@inheritDoc IContactManager.cmGetContactTypes} */
Expand All @@ -167,12 +203,66 @@ export class ContactManager implements IAgentPlugin {

/** {@inheritDoc IContactManager.cmUpdateContactType} */
private async cmUpdateContactType(args: UpdateContactTypeArgs, context: RequiredContext): Promise<ContactType> {
return this.store.updatePartyType({ partyType: args.contactType })
const { contactType } = args
return this.store.updatePartyType({ partyType: contactType })
}

/** {@inheritDoc IContactManager.cmRemoveContactType} */
private async cmRemoveContactType(args: RemoveContactTypeArgs, context: RequiredContext): Promise<boolean> {
return this.store.removePartyType({ partyTypeId: args.contactTypeId }).then(() => true)
const { contactTypeId } = args
return this.store.removePartyType({ partyTypeId: contactTypeId }).then((): boolean => true)
}

/** {@inheritDoc IContactManager.cmGetElectronicAddress} */
private async cmGetElectronicAddress(args: GetElectronicAddressArgs, context: RequiredContext): Promise<ElectronicAddress> {
return this.store.getElectronicAddress(args)
}

/** {@inheritDoc IContactManager.cmGetElectronicAddresses} */
private async cmGetElectronicAddresses(args?: GetElectronicAddressesArgs): Promise<Array<ElectronicAddress>> {
return this.store.getElectronicAddresses(args)
}

/** {@inheritDoc IContactManager.cmAddElectronicAddress} */
private async cmAddElectronicAddress(args: AddElectronicAddressArgs): Promise<ElectronicAddress> {
const { contactId, electronicAddress } = args
return this.store.addElectronicAddress({ partyId: contactId, electronicAddress })
}

/** {@inheritDoc IContactManager.cmUpdateElectronicAddress} */
private async cmUpdateElectronicAddress(args: UpdateElectronicAddressArgs): Promise<ElectronicAddress> {
return this.store.updateElectronicAddress(args)
}

/** {@inheritDoc IContactManager.cmRemoveElectronicAddress} */
private async cmRemoveElectronicAddress(args: RemoveElectronicAddressArgs): Promise<boolean> {
return this.store.removeElectronicAddress(args).then((): boolean => true)
}

/** {@inheritDoc IContactManager.cmGetPhysicalAddress} */
private async cmGetPhysicalAddress(args: GetPhysicalAddressArgs): Promise<PhysicalAddress> {
return this.store.getPhysicalAddress(args)
}

/** {@inheritDoc IContactManager.cmGetPhysicalAddresses} */
private async cmGetPhysicalAddresses(args?: GetPhysicalAddressesArgs): Promise<Array<PhysicalAddress>> {
return this.store.getPhysicalAddresses(args)
}

/** {@inheritDoc IContactManager.cmAddPhysicalAddress} */
private async cmAddPhysicalAddress(args: AddPhysicalAddressArgs): Promise<PhysicalAddress> {
const { contactId, physicalAddress } = args
return this.store.addPhysicalAddress({ partyId: contactId, physicalAddress })
}

/** {@inheritDoc IContactManager.cmUpdatePhysicalAddress} */
private async cmUpdatePhysicalAddress(args: UpdatePhysicalAddressArgs): Promise<PhysicalAddress> {
return this.store.updatePhysicalAddress(args)
}

/** {@inheritDoc IContactManager.cmRemovePhysicalAddress} */
private async cmRemovePhysicalAddress(args: RemovePhysicalAddressArgs): Promise<boolean> {
return this.store.removePhysicalAddress(args).then((): boolean => true)
}

private getContactInformationFrom(contact: any): NonPersistedContact {
Expand Down
80 changes: 66 additions & 14 deletions packages/contact-manager/src/types/IContactManager.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { IAgentContext, IPluginMethodMap } from '@veramo/core'
import {
Identity,
NonPersistedIdentity,
FindRelationshipArgs,
ElectronicAddress,
FindElectronicAddressArgs,
FindIdentityArgs,
FindPartyArgs as FindContactArgs,
FindPartyTypeArgs as FindContactTypeArgs,
FindPhysicalAddressArgs,
FindRelationshipArgs,
Identity,
NonPersistedContact,
PartyTypeEnum as ContactTypeEnum,
NonPersistedElectronicAddress,
NonPersistedIdentity,
NonPersistedParty,
NonPersistedPartyType as NonPersistedContactType,
FindPartyTypeArgs as FindContactTypeArgs,
FindPartyArgs as FindContactArgs,
NonPersistedPhysicalAddress,
Party as Contact,
PartyRelationship as ContactRelationship,
PartyType as ContactType,
Party as Contact,
NonPersistedParty,
PartyTypeEnum as ContactTypeEnum,
PhysicalAddress,
} from '@sphereon/ssi-sdk.data-store'

export interface IContactManager extends IPluginMethodMap {
Expand All @@ -36,6 +42,16 @@ export interface IContactManager extends IPluginMethodMap {
cmAddContactType(args: AddContactTypeArgs, context: RequiredContext): Promise<ContactType>
cmUpdateContactType(args: UpdateContactTypeArgs, context: RequiredContext): Promise<ContactType>
cmRemoveContactType(args: RemoveContactTypeArgs, context: RequiredContext): Promise<boolean>
cmGetElectronicAddress(args: GetElectronicAddressArgs, context: RequiredContext): Promise<ElectronicAddress>
cmGetElectronicAddresses(args?: GetElectronicAddressesArgs): Promise<Array<ElectronicAddress>>
cmAddElectronicAddress(args: AddElectronicAddressArgs): Promise<ElectronicAddress>
cmUpdateElectronicAddress(args: UpdateElectronicAddressArgs): Promise<ElectronicAddress>
cmRemoveElectronicAddress(args: RemoveElectronicAddressArgs): Promise<boolean>
cmGetPhysicalAddress(args: GetPhysicalAddressArgs): Promise<PhysicalAddress>
cmGetPhysicalAddresses(args?: GetPhysicalAddressesArgs): Promise<Array<PhysicalAddress>>
cmAddPhysicalAddress(args: AddPhysicalAddressArgs): Promise<PhysicalAddress>
cmUpdatePhysicalAddress(args: UpdatePhysicalAddressArgs): Promise<PhysicalAddress>
cmRemovePhysicalAddress(args: RemovePhysicalAddressArgs): Promise<boolean>
}

export type GetContactArgs = {
Expand All @@ -46,12 +62,6 @@ export type GetContactsArgs = {
filter?: FindContactArgs
}

// export type AddContactArgs = {
// uri?: string
// contactType: NonPersistedContactType
// identities?: Array<NonPersistedIdentity>
// } & NonPersistedNaturalPerson | NonPersistedOrganization

export type AddContactArgs = Omit<NonPersistedParty, 'contact' | 'partyType'> &
NonPersistedContact & {
contactType: NonPersistedContactType
Expand Down Expand Up @@ -130,4 +140,46 @@ export type RemoveContactTypeArgs = {
contactTypeId: string
}

export type GetElectronicAddressArgs = {
electronicAddressId: string
}

export type GetElectronicAddressesArgs = {
filter?: FindElectronicAddressArgs
}

export type AddElectronicAddressArgs = {
contactId: string
electronicAddress: NonPersistedElectronicAddress
}

export type UpdateElectronicAddressArgs = {
electronicAddress: ElectronicAddress
}

export type RemoveElectronicAddressArgs = {
electronicAddressId: string
}

export type GetPhysicalAddressArgs = {
physicalAddressId: string
}

export type GetPhysicalAddressesArgs = {
filter?: FindPhysicalAddressArgs
}

export type AddPhysicalAddressArgs = {
contactId: string
physicalAddress: NonPersistedPhysicalAddress
}

export type UpdatePhysicalAddressArgs = {
physicalAddress: PhysicalAddress
}

export type RemovePhysicalAddressArgs = {
physicalAddressId: string
}

export type RequiredContext = IAgentContext<never>
Loading

0 comments on commit 76f78b3

Please sign in to comment.