diff --git a/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts b/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts index cf194ab93..9a34799ff 100644 --- a/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts +++ b/packages/contact-manager/__tests__/shared/contactManagerAgentLogic.ts @@ -10,6 +10,7 @@ import { NonPersistedIdentity, NonPersistedPhysicalAddress, Party, + PartyOrigin, PartyRelationship, PartyTypeEnum, PhysicalAddress, @@ -35,6 +36,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'default_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -142,6 +144,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'new_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'new_name', description: 'new_description', @@ -170,6 +173,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro const result: Party = await agent.cmAddContact(contact) expect(result.partyType.type).toEqual(contact.contactType.type) + expect(result.partyType.origin).toEqual(contact.contactType.origin) expect(result.partyType.name).toEqual(contact.contactType.name) expect(result.partyType.description).toEqual(contact.contactType.description) expect((result.contact).firstName).toEqual(contact.firstName) @@ -317,6 +321,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'relation_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d285', name: 'relation_contact_type_name', description: 'new_description', @@ -361,6 +366,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'remove_relation_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d286', name: 'remove_relation_contact_type_name', description: 'new_description', @@ -410,6 +416,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'add_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: 'a85a8aa0-fdeb-4c00-b22e-60423f52a873', name: 'add_electronic_address_name', description: 'add_electronic_address_description', @@ -438,6 +445,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: 'f2947075-53eb-4176-b155-ab4b18715288', name: 'get_electronic_address_name', description: 'get_electronic_address_description', @@ -465,6 +473,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_all_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '5c0157ec-4678-4273-8f53-413bc6435134', name: 'get_all_electronic_address_name', description: 'get_all_electronic_address_description', @@ -493,6 +502,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'update_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '6b64c3dd-cf40-4919-b8b8-2ec3c510c5b7', name: 'update_electronic_address_name', description: 'update_electronic_address_description', @@ -528,6 +538,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'remove_electronic_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '41b45c65-971e-4c26-8115-cb8bc7c67cf3', name: 'remove_electronic_address_name', description: 'remove_electronic_address_description', @@ -561,6 +572,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'add_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '5aeb828e-16d6-4244-95a7-e12424474eb7', name: 'add_physical_address_name', description: 'add_physical_address_description', @@ -595,6 +607,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '7c5dbbd9-1721-4246-b261-44e237560a15', name: 'get_physical_address_name', description: 'get_physical_address_description', @@ -628,6 +641,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'get_all_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0c0eafd8-1e8c-44bf-8e0d-768fb11a40c3', name: 'get_all_physical_address_name', description: 'get_all_physical_address_description', @@ -662,6 +676,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'update_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: 'f2b4eb1c-e36f-4863-90b3-90720471c397', name: 'update_physical_address_name', description: 'update_physical_address_description', @@ -715,6 +730,7 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro displayName: 'remove_physical_address_display_name', contactType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '20b11d1e-6489-4258-af33-32a2cfa4dc85', name: 'remove_physical_address_name', description: 'remove_physical_address_description', diff --git a/packages/contact-manager/src/types/IContactManager.ts b/packages/contact-manager/src/types/IContactManager.ts index c88de78e7..c1f9dfe73 100644 --- a/packages/contact-manager/src/types/IContactManager.ts +++ b/packages/contact-manager/src/types/IContactManager.ts @@ -15,6 +15,7 @@ import { NonPersistedPartyType as NonPersistedContactType, NonPersistedPhysicalAddress, Party as Contact, + PartyOrigin, PartyRelationship as ContactRelationship, PartyType as ContactType, PartyTypeEnum as ContactTypeEnum, @@ -119,6 +120,7 @@ export type UpdateRelationshipArgs = { export type AddContactTypeArgs = { type: ContactTypeEnum + origin: PartyOrigin name: string tenantId: string description?: string diff --git a/packages/data-store/src/__tests__/contact.entities.test.ts b/packages/data-store/src/__tests__/contact.entities.test.ts index 582823f39..542f5e8d9 100644 --- a/packages/data-store/src/__tests__/contact.entities.test.ts +++ b/packages/data-store/src/__tests__/contact.entities.test.ts @@ -1,5 +1,5 @@ import { DataSource, FindOptionsWhere } from 'typeorm' -import { DataStoreContactEntities, DataStoreMigrations } from '../index' +import { DataStoreContactEntities, DataStoreMigrations, PartyOrigin } from '../index' import { BaseContactEntity } from '../entities/contact/BaseContactEntity' import { ConnectionEntity } from '../entities/contact/ConnectionEntity' import { CorrelationIdentifierEntity } from '../entities/contact/CorrelationIdentifierEntity' @@ -74,6 +74,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -99,6 +100,7 @@ describe('Database entities tests', (): void => { expect(fromDb?.uri).toEqual(party.uri) expect(fromDb?.partyType).toBeDefined() expect(fromDb?.partyType.type).toEqual(party.partyType.type) + expect(fromDb?.partyType.origin).toEqual(party.partyType.origin) expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) expect(fromDb?.partyType.name).toEqual(party.partyType.name) expect(fromDb?.contact).toBeDefined() @@ -113,6 +115,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -136,6 +139,7 @@ describe('Database entities tests', (): void => { expect(fromDb?.uri).toEqual(party.uri) expect(fromDb?.partyType).toBeDefined() expect(fromDb?.partyType.type).toEqual(party.partyType.type) + expect(fromDb?.partyType.origin).toEqual(party.partyType.origin) expect(fromDb?.partyType.tenantId).toEqual(party.partyType.tenantId) expect(fromDb?.partyType.name).toEqual(party.partyType.name) expect(fromDb?.contact).toBeDefined() @@ -148,6 +152,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -168,6 +173,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -212,6 +218,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -233,6 +240,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -254,6 +262,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -275,6 +284,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -296,6 +306,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -315,6 +326,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -334,6 +346,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: '', }, @@ -355,6 +368,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', description: '', @@ -377,6 +391,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '', name: 'example_name', }, @@ -772,6 +787,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -792,6 +808,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -951,6 +968,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1051,6 +1069,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1126,6 +1145,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1153,6 +1173,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1248,6 +1269,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1275,6 +1297,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1317,6 +1340,7 @@ describe('Database entities tests', (): void => { it('Should set last updated date when saving party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1335,6 +1359,7 @@ describe('Database entities tests', (): void => { it('Should set last creation date when saving party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1381,6 +1406,7 @@ describe('Database entities tests', (): void => { const name = 'non_unique_value' const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId, name, } @@ -1392,6 +1418,7 @@ describe('Database entities tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId, name, } @@ -1406,6 +1433,7 @@ describe('Database entities tests', (): void => { const name = 'non_unique_value' const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name, } @@ -1417,6 +1445,7 @@ describe('Database entities tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name, } @@ -1482,6 +1511,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1504,6 +1534,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1544,6 +1575,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1564,6 +1596,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1602,6 +1635,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1622,6 +1656,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1660,6 +1695,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1682,6 +1718,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1734,6 +1771,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1756,6 +1794,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1798,6 +1837,7 @@ describe('Database entities tests', (): void => { it('Should save party type to database', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1933,6 +1973,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1966,6 +2007,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.ORGANIZATION, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1996,6 +2038,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2029,6 +2072,7 @@ describe('Database entities tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -2051,6 +2095,7 @@ describe('Database entities tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -2092,6 +2137,7 @@ describe('Database entities tests', (): void => { it('Should delete party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -2115,6 +2161,7 @@ describe('Database entities tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2141,6 +2188,7 @@ describe('Database entities tests', (): void => { it('Should save party with existing party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -2173,6 +2221,7 @@ describe('Database entities tests', (): void => { expect(fromDb?.partyType).toBeDefined() expect(fromDb?.partyType.id).toEqual(savedPartyType.id) expect(fromDb?.partyType.type).toEqual(savedPartyType.type) + expect(fromDb?.partyType.origin).toEqual(savedPartyType.origin) expect(fromDb?.partyType.tenantId).toEqual(savedPartyType.tenantId) expect(fromDb?.partyType.name).toEqual(savedPartyType.name) }) @@ -2180,6 +2229,7 @@ describe('Database entities tests', (): void => { it('Should not update creation date when saving party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } diff --git a/packages/data-store/src/__tests__/contact.store.test.ts b/packages/data-store/src/__tests__/contact.store.test.ts index d7ba709ab..b167d6744 100644 --- a/packages/data-store/src/__tests__/contact.store.test.ts +++ b/packages/data-store/src/__tests__/contact.store.test.ts @@ -1,5 +1,5 @@ import { DataSource } from 'typeorm' -import { DataStoreMigrations, DataStoreContactEntities } from '../index' +import { DataStoreContactEntities, DataStoreMigrations, PartyOrigin } from '../index' import { ContactStore } from '../contact/ContactStore' import { CorrelationIdentifierEnum, @@ -54,6 +54,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -84,6 +85,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -101,6 +103,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -125,6 +128,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -172,6 +176,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -239,6 +244,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'something', }, @@ -282,6 +288,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -315,6 +322,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -366,6 +374,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -391,6 +400,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -434,6 +444,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'something', }, @@ -471,6 +482,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -528,6 +540,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -560,6 +573,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -594,6 +608,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -634,6 +649,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -683,6 +699,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -728,6 +745,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -778,6 +796,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -828,6 +847,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -867,6 +887,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -900,6 +921,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -935,6 +957,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -972,6 +995,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1022,6 +1046,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1039,6 +1064,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1071,6 +1097,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1088,6 +1115,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1125,6 +1153,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1142,6 +1171,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1178,6 +1208,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1195,6 +1226,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1240,6 +1272,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1257,6 +1290,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1309,6 +1343,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1326,6 +1361,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1343,6 +1379,7 @@ describe('Contact store tests', (): void => { uri: 'example3.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287', name: 'example_name3', }, @@ -1382,6 +1419,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1399,6 +1437,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1435,6 +1474,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1452,6 +1492,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1487,6 +1528,7 @@ describe('Contact store tests', (): void => { uri: 'example1.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name1', }, @@ -1504,6 +1546,7 @@ describe('Contact store tests', (): void => { uri: 'example2.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name2', }, @@ -1537,6 +1580,7 @@ describe('Contact store tests', (): void => { it('should add party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1548,6 +1592,7 @@ describe('Contact store tests', (): void => { expect(result).toBeDefined() expect(result.name).toEqual(partyType.name) expect(result.type).toEqual(partyType.type) + expect(result.origin).toEqual(partyType.origin) expect(result.tenantId).toEqual(partyType.tenantId) expect(result.description).toEqual(partyType.description) expect(result.lastUpdatedAt).toBeDefined() @@ -1557,6 +1602,7 @@ describe('Contact store tests', (): void => { it('should get party types by filter', async (): Promise => { const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name1', description: 'example_description1', @@ -1566,6 +1612,7 @@ describe('Contact store tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287', name: 'example_name2', description: 'example_description2', @@ -1590,6 +1637,7 @@ describe('Contact store tests', (): void => { it('should return no party types if filter does not match', async (): Promise => { const partyType1: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name1', description: 'example_description1', @@ -1599,6 +1647,7 @@ describe('Contact store tests', (): void => { const partyType2: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d287', name: 'example_name2', description: 'example_description2', @@ -1623,6 +1672,7 @@ describe('Contact store tests', (): void => { it('should throw error when updating party type with unknown id', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1643,6 +1693,7 @@ describe('Contact store tests', (): void => { it('should update party type by id', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1671,6 +1722,7 @@ describe('Contact store tests', (): void => { it('should remove party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d288', name: 'example_name', description: 'example_description', @@ -1698,6 +1750,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1719,6 +1772,7 @@ describe('Contact store tests', (): void => { it('Should save party with existing party type', async (): Promise => { const partyType: NonPersistedPartyType = { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', } @@ -1742,16 +1796,19 @@ describe('Contact store tests', (): void => { expect(result?.partyType).toBeDefined() expect(result?.partyType.id).toEqual(savedPartyType.id) expect(result?.partyType.type).toEqual(savedPartyType.type) + expect(result?.partyType.origin).toEqual(savedPartyType.origin) expect(result?.partyType.tenantId).toEqual(savedPartyType.tenantId) expect(result?.partyType.name).toEqual(savedPartyType.name) }) it('should throw error when adding person party with wrong contact type', async (): Promise => { const partyType = PartyTypeEnum.ORGANIZATION + const partyTypeOrigin = PartyOrigin.internal const party: NonPersistedParty = { uri: 'example.com', partyType: { type: partyType, + origin: partyTypeOrigin, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1768,10 +1825,12 @@ describe('Contact store tests', (): void => { it('should throw error when adding organization party with wrong contact type', async (): Promise => { const partyType = PartyTypeEnum.NATURAL_PERSON + const partyTypeOrigin = PartyOrigin.external const party: NonPersistedParty = { uri: 'example.com', partyType: { type: partyType, + origin: partyTypeOrigin, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1789,6 +1848,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1827,6 +1887,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1874,6 +1935,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1917,6 +1979,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1965,6 +2028,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -1994,6 +2058,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2027,6 +2092,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2067,6 +2133,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2109,6 +2176,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2168,6 +2236,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2223,6 +2292,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2283,6 +2353,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2318,6 +2389,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.internal, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, @@ -2357,6 +2429,7 @@ describe('Contact store tests', (): void => { uri: 'example.com', partyType: { type: PartyTypeEnum.NATURAL_PERSON, + origin: PartyOrigin.external, tenantId: '0605761c-4113-4ce5-a6b2-9cbae2f9d289', name: 'example_name', }, diff --git a/packages/data-store/src/entities/contact/PartyTypeEntity.ts b/packages/data-store/src/entities/contact/PartyTypeEntity.ts index 8436b615d..43782312d 100644 --- a/packages/data-store/src/entities/contact/PartyTypeEntity.ts +++ b/packages/data-store/src/entities/contact/PartyTypeEntity.ts @@ -1,6 +1,6 @@ -import { Entity, PrimaryGeneratedColumn, Column, Index, CreateDateColumn, UpdateDateColumn, OneToMany, BeforeInsert, BeforeUpdate } from 'typeorm' +import { BeforeInsert, BeforeUpdate, Column, CreateDateColumn, Entity, Index, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm' import { PartyEntity } from './PartyEntity' -import { PartyTypeEnum, ValidationConstraint } from '../../types' +import { PartyOrigin, PartyTypeEnum, ValidationConstraint } from '../../types' import { IsNotEmpty, Validate, validate, ValidationError } from 'class-validator' import { IsNonEmptyStringConstraint } from '../validators' import { getConstraint } from '../../utils/ValidatorUtils' @@ -14,6 +14,9 @@ export class PartyTypeEntity { @Column('simple-enum', { name: 'type', enum: PartyTypeEnum, nullable: false, unique: false }) type!: PartyTypeEnum + @Column('simple-enum', { name: 'origin', enum: PartyOrigin, default: 'external', nullable: false, unique: false }) + origin!: PartyOrigin + @Column({ name: 'name', length: 255, nullable: false, unique: true }) @IsNotEmpty({ message: 'Blank names are not allowed' }) name!: string diff --git a/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts b/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts index de8330c50..8ec3ebe68 100644 --- a/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts +++ b/packages/data-store/src/migrations/postgres/1690925872592-CreateContacts.ts @@ -13,8 +13,9 @@ export class CreateContacts1690925872592 implements MigrationInterface { await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" RENAME COLUMN "identityId" TO "identity_id"`) await queryRunner.query(`ALTER TABLE "Connection" RENAME COLUMN "identityId" TO "identity_id"`) await queryRunner.query(`CREATE TYPE "public"."PartyType_type_enum" AS ENUM('naturalPerson', 'organization')`) + await queryRunner.query(`CREATE TYPE "public"."PartyOrigin_type_enum" AS ENUM('internal', 'external')`) await queryRunner.query( - `CREATE TABLE "PartyType" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."PartyType_type_enum" NOT NULL, "name" character varying(255) NOT NULL, "description" character varying(255), "tenant_id" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"), CONSTRAINT "PK_PartyType_id" PRIMARY KEY ("id"))`, + `CREATE TABLE "PartyType" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."PartyType_type_enum" NOT NULL, "origin" "public"."PartyOrigin_type_enum" NOT NULL DEFAULT 'external', "name" character varying(255) NOT NULL, "description" character varying(255), "tenant_id" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"), CONSTRAINT "PK_PartyType_id" PRIMARY KEY ("id"))`, ) await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyType_type_tenant_id" ON "PartyType" ("type", "tenant_id")`) await queryRunner.query( @@ -29,7 +30,10 @@ export class CreateContacts1690925872592 implements MigrationInterface { `CREATE TABLE "ElectronicAddress" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" character varying(255) NOT NULL, "electronic_address" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "partyId" uuid, CONSTRAINT "PK_ElectronicAddress_id" PRIMARY KEY ("id"))`, ) await queryRunner.query( - `CREATE TABLE "Party" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "uri" character varying(255) NOT NULL, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "party_type_id" uuid NOT NULL, CONSTRAINT "PK_Party_id" PRIMARY KEY ("id"))`, + `CREATE TABLE "PhysicalAddress" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" character varying(255) NOT NULL, "street_name" character varying(255) NOT NULL, "street_number" character varying(255) NOT NULL, "postal_code" character varying(255) NOT NULL, "city_name" character varying(255) NOT NULL, "province_name" character varying(255) NOT NULL, "country_code" character varying(2) NOT NULL, "building_name" character varying(255), "partyId" uuid, "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_PhysicalAddress_id" PRIMARY KEY ("id"))` + ); + await queryRunner.query( + `CREATE TABLE "Party" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "uri" character varying(255), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "last_updated_at" TIMESTAMP NOT NULL DEFAULT now(), "party_type_id" uuid NOT NULL, CONSTRAINT "PK_Party_id" PRIMARY KEY ("id"))`, ) await queryRunner.query( `CREATE TABLE "BaseConfig" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "identifier" character varying(255), "redirect_url" character varying(255), "session_id" character varying(255), "client_id" character varying(255), "client_secret" character varying(255), "scopes" text, "issuer" character varying(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" character varying NOT NULL, "connection_id" uuid, CONSTRAINT "REL_BaseConfig_connection_id" UNIQUE ("connection_id"), CONSTRAINT "PK_BaseConfig_id" PRIMARY KEY ("id"))`, @@ -55,6 +59,9 @@ export class CreateContacts1690925872592 implements MigrationInterface { await queryRunner.query( `ALTER TABLE "ElectronicAddress" ADD CONSTRAINT "FK_ElectronicAddress_partyId" FOREIGN KEY ("partyId") REFERENCES "Party"("id") ON DELETE CASCADE ON UPDATE NO ACTION`, ) + await queryRunner.query( + `ALTER TABLE "PhysicalAddress" ADD CONSTRAINT "FK_PhysicalAddress_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION`, + ) await queryRunner.query( `ALTER TABLE "Party" ADD CONSTRAINT "FK_Party_party_type_id" FOREIGN KEY ("party_type_id") REFERENCES "PartyType"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, ) diff --git a/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts b/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts index 016d6de2b..7c484d280 100644 --- a/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts +++ b/packages/data-store/src/migrations/sqlite/1690925872693-CreateContacts.ts @@ -49,7 +49,7 @@ export class CreateContacts1690925872693 implements MigrationInterface { await queryRunner.query(`DROP TABLE "Connection"`) await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`) await queryRunner.query( - `CREATE TABLE "PartyType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('naturalPerson','organization') ) NOT NULL, "name" varchar(255) NOT NULL, "description" varchar(255), "tenant_id" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"))`, + `CREATE TABLE "PartyType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('naturalPerson','organization') ) NOT NULL, "origin" varchar CHECK( "origin" IN ('internal', 'external') ) NOT NULL DEFAULT 'external', "name" varchar(255) NOT NULL, "description" varchar(255), "tenant_id" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"))`, ) await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyType_type_tenant_id" ON "PartyType" ("type", "tenant_id")`) await queryRunner.query( diff --git a/packages/data-store/src/types/contact/IAbstractContactStore.ts b/packages/data-store/src/types/contact/IAbstractContactStore.ts index 6ad3eddfe..b54ad487b 100644 --- a/packages/data-store/src/types/contact/IAbstractContactStore.ts +++ b/packages/data-store/src/types/contact/IAbstractContactStore.ts @@ -13,6 +13,7 @@ import { PartialPartyType, PartialPhysicalAddress, Party, + PartyOrigin, PartyRelationship, PartyType, PartyTypeEnum, @@ -95,6 +96,7 @@ export type UpdateRelationshipArgs = { export type AddPartyTypeArgs = { type: PartyTypeEnum + origin: PartyOrigin name: string tenantId: string description?: string diff --git a/packages/data-store/src/types/contact/contact.ts b/packages/data-store/src/types/contact/contact.ts index 3d42dd873..bfa2095e1 100644 --- a/packages/data-store/src/types/contact/contact.ts +++ b/packages/data-store/src/types/contact/contact.ts @@ -150,9 +150,15 @@ export type Contact = NaturalPerson | Organization export type NonPersistedContact = NonPersistedNaturalPerson | NonPersistedOrganization export type PartialContact = PartialNaturalPerson | PartialOrganization +export enum PartyOrigin { + internal = 'internal', + external = 'external', +} + export type PartyType = { id: string type: PartyTypeEnum + origin: PartyOrigin name: string tenantId: string description?: string diff --git a/packages/data-store/src/utils/contact/MappingUtils.ts b/packages/data-store/src/utils/contact/MappingUtils.ts index 59c85810d..7347f4205 100644 --- a/packages/data-store/src/utils/contact/MappingUtils.ts +++ b/packages/data-store/src/utils/contact/MappingUtils.ts @@ -324,6 +324,7 @@ export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntit partyTypeEntity.id = args.id } partyTypeEntity.type = args.type + partyTypeEntity.origin = args.origin partyTypeEntity.name = args.name partyTypeEntity.description = args.description partyTypeEntity.tenantId = args.tenantId @@ -335,6 +336,7 @@ export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => { return { id: partyType.id, type: partyType.type, + origin: partyType.origin, name: partyType.name, tenantId: partyType.tenantId, description: partyType.description, diff --git a/packages/ssi-types/__tests__/encoding.test.ts b/packages/ssi-types/__tests__/encoding.test.ts index 2c0107e29..093351b55 100644 --- a/packages/ssi-types/__tests__/encoding.test.ts +++ b/packages/ssi-types/__tests__/encoding.test.ts @@ -110,7 +110,7 @@ describe('Encoding - Decoding', () => { it('decode sd-jwt-vc', () => { const decoded = decodeSdJwtVc( 'eyJhbGciOiJFZERTQSIsInR5cCI6InZjK3NkLWp3dCIsImtpZCI6IiN6Nk1rdHF0WE5HOENEVVk5UHJydG9TdEZ6ZUNuaHBNbWd4WUwxZ2lrY1czQnp2TlcifQ.eyJ2Y3QiOiJJZGVudGl0eUNyZWRlbnRpYWwiLCJmYW1pbHlfbmFtZSI6IkRvZSIsInBob25lX251bWJlciI6IisxLTIwMi01NTUtMDEwMSIsImFkZHJlc3MiOnsic3RyZWV0X2FkZHJlc3MiOiIxMjMgTWFpbiBTdCIsImxvY2FsaXR5IjoiQW55dG93biIsIl9zZCI6WyJOSm5tY3QwQnFCTUUxSmZCbEM2alJRVlJ1ZXZwRU9OaVl3N0E3TUh1SnlRIiwib201Wnp0WkhCLUdkMDBMRzIxQ1ZfeE00RmFFTlNvaWFPWG5UQUpOY3pCNCJdfSwiY25mIj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p4dU5XdW9CUEtqSnVIRVRFVWVITG9TcVd0OTJ2aVNzbWFXank4MnkiLCJfc2RfaGFzaCI6Ii1kTUd4OGZhUnpOQm91a2EwU0R6V2JkS3JYckw1TFVmUlNQTHN2Q2xPMFkifQ.TQQLqc4ZzoKjQfAghAzC_4aaU3KCS8YqzxAJtzT124guzkv9XSHtPN8d3z181_v-ca2ATXjTRoRciozitE6wBA', - (data, algorithm) => createHash(algorithm).update(data).digest(), + (data, algorithm) => createHash(algorithm).update(data).digest() ) expect(decoded).toEqual({ @@ -194,13 +194,23 @@ describe('Encoding - Decoding', () => { phone_number: '+1-202-555-0101', vct: 'IdentityCredential', }, + kbJwt: { + compact: + 'eyJhbGciOiJFZERTQSIsInR5cCI6ImtiK2p3dCJ9.eyJpYXQiOjE2OTgxNTE1MzIsIm5vbmNlIjoic2FsdCIsImF1ZCI6ImRpZDprZXk6elVDNzRWRXFxaEVIUWNndjR6YWdTUGtxRkp4dU5XdW9CUEtqSnVIRVRFVWVITG9TcVd0OTJ2aVNzbWFXank4MnkiLCJfc2RfaGFzaCI6Ii1kTUd4OGZhUnpOQm91a2EwU0R6V2JkS3JYckw1TFVmUlNQTHN2Q2xPMFkifQ.TQQLqc4ZzoKjQfAghAzC_4aaU3KCS8YqzxAJtzT124guzkv9XSHtPN8d3z181_v-ca2ATXjTRoRciozitE6wBA', + payload: { + _sd_hash: '-dMGx8faRzNBouka0SDzWbdKrXrL5LUfRSPLsvClO0Y', + aud: 'did:key:zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y', + iat: 1698151532, + nonce: 'salt', + }, + }, }) }) it('decode sd-jwt-vc async', async () => { const decoded = await decodeSdJwtVcAsync( 'eyJhbGciOiJFZERTQSIsInR5cCI6InZjK3NkLWp3dCIsImtpZCI6IiN6Nk1rdHF0WE5HOENEVVk5UHJydG9TdEZ6ZUNuaHBNbWd4WUwxZ2lrY1czQnp2TlcifQ.eyJ2Y3Qi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cl82NSIsdHJ1ZV0~WyJzYWx0IiwiaXNfb3Zlcl8yMSIsdHJ1ZV0~WyJzYWx0IiwiZW1haWwiLCJqb2huZG9lQGV4YW1wbGUuY29tIl0~WyJzYWx0IiwiY291bnRyeSIsIlVTIl0~WyJzYWx0IiwiZ2l2ZW5fbmFtZSIsIkpvaG4iXQ~eyJhbGciOiJFZERTQSIsInR5cCI6ImtiK2p3dCJ9.eyJpYXQiOjE2OTgxNTE1MzIsIm5vbmNlIjoic2FsdCIsImF1ZCI6ImRpZDprZXk6elVDNzRWRXFxaEVIUWNndjR6YWdTUGtxRkp4dU5XdW9CUEtqSnVIRVRFVWVITG9TcVd0OTJ2aVNzbWFXank4MnkiLCJfc2RfaGFzaCI6Ii1kTUd4OGZhUnpOQm91a2EwU0R6V2JkS3JYckw1TFVmUlNQTHN2Q2xPMFkifQ.TQQLqc4ZzoKjQfAghAzC_4aaU3KCS8YqzxAJtzT124guzkv9XSHtPN8d3z181_v-ca2ATXjTRoRciozitE6wBA', - (data, algorithm) => Promise.resolve(createHash(algorithm).update(data).digest()), + (data, algorithm) => Promise.resolve(createHash(algorithm).update(data).digest()) ) expect(decoded).toEqual({ @@ -284,6 +294,16 @@ describe('Encoding - Decoding', () => { phone_number: '+1-202-555-0101', vct: 'IdentityCredential', }, + kbJwt: { + compact: + 'eyJhbGciOiJFZERTQSIsInR5cCI6ImtiK2p3dCJ9.eyJpYXQiOjE2OTgxNTE1MzIsIm5vbmNlIjoic2FsdCIsImF1ZCI6ImRpZDprZXk6elVDNzRWRXFxaEVIUWNndjR6YWdTUGtxRkp4dU5XdW9CUEtqSnVIRVRFVWVITG9TcVd0OTJ2aVNzbWFXank4MnkiLCJfc2RfaGFzaCI6Ii1kTUd4OGZhUnpOQm91a2EwU0R6V2JkS3JYckw1TFVmUlNQTHN2Q2xPMFkifQ.TQQLqc4ZzoKjQfAghAzC_4aaU3KCS8YqzxAJtzT124guzkv9XSHtPN8d3z181_v-ca2ATXjTRoRciozitE6wBA', + payload: { + _sd_hash: '-dMGx8faRzNBouka0SDzWbdKrXrL5LUfRSPLsvClO0Y', + aud: 'did:key:zUC74VEqqhEHQcgv4zagSPkqFJxuNWuoBPKjJuHETEUeHLoSqWt92viSsmaWjy82y', + iat: 1698151532, + nonce: 'salt', + }, + }, }) }) @@ -298,8 +318,8 @@ describe('Encoding - Decoding', () => { expect(CredentialMapper.isCredential(decodedLdpVc)).toEqual(true) expect( CredentialMapper.isCredential( - 'eyJhbGciOiJFZERTQSIsInR5cCI6InZjK3NkLWp3dCIsImtpZCI6IiN6Nk1rdHF0WE5HOENEVVk5UHJydG9TdEZ6ZUNuaHBNbWd4WUwxZ2lrY1czQnp2TlcifQ.eyJ2Y3QiOiJJZGVudGl0eUNyZWRlbnRpYWwiLCJmYW1pbHlfbmFtZSI6IkRvZSIsInBob25lX251bWJlciI6IisxLTIwMi01NTUtMDEwMSIsImFkZHJlc3MiOnsic3RyZWV0X2FkZHJlc3MiOiIxMjMgTWFpbiBTdCIsImxvY2FsaXR5IjoiQW55dG93biIsIl9zZCI6WyJOSm5tY3QwQnFCTUUxSmZCbEM2alJRVlJ1ZXZwRU9OaVl3N0E3TUh1SnlRIiwib201Wnp0WkhCLUdkMDBMRzIxQ1ZfeE00RmFFTlNvaWFPWG5UQUpOY3pCNCJdfSwiY25mIjp7Imp3ayI6eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5IiwieCI6Im9FTlZzeE9VaUg1NFg4d0pMYVZraWNDUmswMHdCSVE0c1JnYms1NE44TW8ifX0sImlzcyI6ImRpZDprZXk6ejZNa3RxdFhORzhDRFVZOVBycnRvU3RGemVDbmhwTW1neFlMMWdpa2NXM0J6dk5XIiwiaWF0IjoxNjk4MTUxNTMyLCJfc2RfYWxnIjoic2hhLTI1NiIsIl9zZCI6WyIxQ3VyMmsyQTJvSUI1Q3NoU0lmX0FfS2ctbDI2dV9xS3VXUTc5UDBWZGFzIiwiUjF6VFV2T1lIZ2NlcGowakh5cEdIej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lcl82NSIsdHJ1ZV0~WyJzYWx0IiwiaXNfb3Zlcl8yMSIsdHJ1ZV0~WyJzYWx0IiwiZW1haWwiLCJqb2huZG9lQGV4YW1wbGUuY29tIl0~WyJzYWx0IiwiY291bnRyeSIsIlVTIl0~WyJzYWx0IiwiZ2l2ZW5fbmFtZSIsIkpvaG4iXQ~eyJhbGciOiJFZERTQSIsInR5cCI6ImtiK2p3dCJ9.eyJpYXQiOjE2OTgxNTE1MzIsIm5vbmNlIjoic2FsdCIsImF1ZCI6ImRpZDprZXk6elVDNzRWRXFxaEVIUWNndjR6YWdTUGtxRkp4dU5XdW9CUEtqSnVIRVRFVWVITG9TcVd0OTJ2aVNzbWFXank4MnkiLCJfc2RfaGFzaCI6Ii1kTUd4OGZhUnpOQm91a2EwU0R6V2JkS3JYckw1TFVmUlNQTHN2Q2xPMFkifQ.TQQLqc4ZzoKjQfAghAzC_4aaU3KCS8YqzxAJtzT124guzkv9XSHtPN8d3z181_v-ca2ATXjTRoRciozitE6wBA' + ) ).toEqual(true) }) @@ -315,8 +335,8 @@ describe('Encoding - Decoding', () => { // jwt-sd credentials are not presentations expect( CredentialMapper.isPresentation( - 'eyJhbGciOiJFZERTQSIsInR5cCI6InZjK3NkLWp3dCIsImtpZCI6IiN6Nk1rdHF0WE5HOENEVVk5UHJydG9TdEZ6ZUNuaHBNbWd4WUwxZ2lrY1czQnp2TlcifQ.eyJ2Y3QiOiJJZGVudGl0eUNyZWRlbnRpYWwiLCJmYW1pbHlfbmFtZSI6IkRvZSIsInBob25lX251bWJlciI6IisxLTIwMi01NTUtMDEwMSIsImFkZHJlc3MiOnsic3RyZWV0X2FkZHJlc3MiOiIxMjMgTWFpbiBTdCIsImxvY2FsaXR5IjoiQW55dG93biIsIl9zZCI6WyJOSm5tY3QwQnFCTUUxSmZCbEM2alJRVlJ1ZXZwRU9OaVl3N0E3TUh1SnlRIiwib201Wnp0WkhCLUdkMDBMRzIxQ1ZfeE00RmFFTlNvaWFPWG5UQUpO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mdDB5c3diYzlFVFBiVSIsImVEcVFwZFRYSlhiV2hmLUVzSTd6dzVYNk92WW1GTi1VWlFRTWVzWHdLUHciLCJwZERrMl9YQUtIbzdnT0Fmd0YxYjdPZENVVlRpdDJrSkhheFNFQ1E5eGZjIiwicHNhdUtVTldFaTA5bnUzQ2w4OXhLWGdtcFdFTlpsNXV5MU4xbnluX2pNayIsInNOX2dlMHBIWEY2cW1zWW5YMUE5U2R3SjhjaDhhRU5reGJPRHNUNzRZd0kiXX0.coOK8NzJmEWz4qx-qRhjo-RK7aejrSkQM9La9Cw3eWmzcja9DXrkBoQZKbIJtNoSzSPLjwK2V71W78z0miZsDQ~WyJzYWx0IiwiaXNfb3Zlcl82NSIsdHJ1ZV0~WyJzYWx0IiwiaXNfb3Zlcl8yMSIsdHJ1ZV0~WyJzYWx0IiwiZW1haWwiLCJqb2huZG9lQGV4YW1wbGUuY29tIl0~WyJzYWx0IiwiY291bnRyeSIsIlVTIl0~WyJzYWx0IiwiZ2l2ZW5fbmFtZSIsIkpvaG4iXQ~eyJhbGciOiJFZERTQSIsInR5cCI6ImtiK2p3dCJ9.eyJpYXQiOjE2OTgxNTE1MzIsIm5vbmNlIjoic2FsdCIsImF1ZCI6ImRpZDprZXk6elVDNzRWRXFxaEVIUWNndjR6YWdTUGtxRkp4dU5XdW9CUEtqSnVIRVRFVWVITG9TcVd0OTJ2aVNzbWFXank4MnkiLCJfc2RfaGFzaCI6Ii1kTUd4OGZhUnpOQm91a2EwU0R6V2JkS3JYckw1TFVmUlNQTHN2Q2xPMFkifQ.TQQLqc4ZzoKjQfAghAzC_4aaU3KCS8YqzxAJtzT124guzkv9XSHtPN8d3z181_v-ca2ATXjTRoRciozitE6wBA' + ) ).toEqual(false) }) @@ -329,8 +349,8 @@ describe('Encoding - Decoding', () => { expect(CredentialMapper.hasProof(ldpVc)).toEqual(true) expect( CredentialMapper.hasProof( - 'eyJhbGciOiJFZERTQSIsInR5cCI6InZjK3NkLWp3dCIsImtpZCI6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FxaEVIUWNndjR6YWdTUGtxRkp4dU5XdW9CUEtqSnVIRVRFVWVITG9TcVd0OTJ2aVNzbWFXank4MnkiLCJfc2RfaGFzaCI6Ii1kTUd4OGZhUnpOQm91a2EwU0R6V2JkS3JYckw1TFVmUlNQTHN2Q2xPMFkifQ.TQQLqc4ZzoKjQfAghAzC_4aaU3KCS8YqzxAJtzT124guzkv9XSHtPN8d3z181_v-ca2ATXjTRoRciozitE6wBA' + ) ).toEqual(true) }) }) diff --git a/packages/ssi-types/src/types/sd-jwt-vc.ts b/packages/ssi-types/src/types/sd-jwt-vc.ts index 17ed963fb..ebb83eca1 100644 --- a/packages/ssi-types/src/types/sd-jwt-vc.ts +++ b/packages/ssi-types/src/types/sd-jwt-vc.ts @@ -1,5 +1,6 @@ import { OriginalType, WrappedVerifiableCredential, WrappedVerifiablePresentation } from './vc' import { decodeSdJwtSync, decodeSdJwt, getClaims, getClaimsSync } from '@sd-jwt/decode' +import { CompactJWT } from './w3c-vc' type JsonValue = string | number | boolean | { [x: string]: JsonValue | undefined } | Array @@ -116,6 +117,22 @@ export interface SdJwtDecodedVerifiableCredential { * for querying the contents of the SD JWT VC using a PEX presentation definition path. */ decodedPayload: SdJwtDecodedVerifiableCredentialPayload + + /** + * Key binding JWT + */ + kbJwt?: { + compact: CompactJWT + payload: SdJwtVcKbJwtPayload + } +} + +interface SdJwtVcKbJwtPayload { + iat: number + aud: string + nonce: string + sd_hash: string + [key: string]: unknown } export interface WrappedSdJwtVerifiableCredential { @@ -189,10 +206,11 @@ export type AsyncHasher = (data: string, alg: string) => Promise * this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core) */ export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): SdJwtDecodedVerifiableCredential { - const { jwt, disclosures } = decodeSdJwtSync(compactSdJwtVc, hasher) + const { jwt, disclosures, kbJwt } = decodeSdJwtSync(compactSdJwtVc, hasher) const signedPayload = jwt.payload as SdJwtSignedVerifiableCredentialPayload const decodedPayload = getClaimsSync(signedPayload, disclosures, hasher) + const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split('~').pop() : undefined return { compactSdJwtVc, @@ -207,6 +225,13 @@ export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): S } satisfies SdJwtDisclosure }), signedPayload: signedPayload as SdJwtSignedVerifiableCredentialPayload, + kbJwt: + compactKeyBindingJwt && kbJwt + ? { + compact: compactKeyBindingJwt, + payload: kbJwt.payload as SdJwtVcKbJwtPayload, + } + : undefined, } } @@ -218,10 +243,11 @@ export function decodeSdJwtVc(compactSdJwtVc: CompactSdJwtVc, hasher: Hasher): S * this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core) */ export async function decodeSdJwtVcAsync(compactSdJwtVc: CompactSdJwtVc, hasher: AsyncHasher): Promise { - const { jwt, disclosures } = await decodeSdJwt(compactSdJwtVc, hasher) + const { jwt, disclosures, kbJwt } = await decodeSdJwt(compactSdJwtVc, hasher) const signedPayload = jwt.payload as SdJwtSignedVerifiableCredentialPayload const decodedPayload = await getClaims(signedPayload, disclosures, hasher) + const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split('~').pop() : undefined return { compactSdJwtVc, @@ -236,5 +262,12 @@ export async function decodeSdJwtVcAsync(compactSdJwtVc: CompactSdJwtVc, hasher: } satisfies SdJwtDisclosure }), signedPayload: signedPayload as SdJwtSignedVerifiableCredentialPayload, + kbJwt: + compactKeyBindingJwt && kbJwt + ? { + compact: compactKeyBindingJwt, + payload: kbJwt.payload as SdJwtVcKbJwtPayload, + } + : undefined, } }