@sphereon/ssi-sdk.data-store 0.23.5-unstable.88 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +77 -77
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -15
- package/dist/index.js.map +1 -1
- package/dist/migrations/generic/index.d.ts +0 -2
- package/dist/migrations/generic/index.d.ts.map +1 -1
- package/dist/migrations/generic/index.js +1 -4
- package/dist/migrations/generic/index.js.map +1 -1
- package/dist/migrations/index.d.ts +1 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +1 -2
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/postgres/1690925872592-CreateContacts.js +1 -1
- package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -1
- package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js +22 -22
- package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.js +16 -16
- package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js +21 -21
- package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.js +15 -15
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +1 -1
- package/package.json +4 -5
- package/src/__tests__/contact.entities.test.ts +2542 -2542
- package/src/__tests__/contact.store.test.ts +2471 -2471
- package/src/__tests__/digitalCredential.entities.test.ts +254 -254
- package/src/__tests__/digitalCredential.store.test.ts +294 -294
- package/src/__tests__/eventLogger.entities.test.ts +73 -73
- package/src/__tests__/eventLogger.store.test.ts +136 -136
- package/src/__tests__/issuanceBranding.entities.test.ts +844 -844
- package/src/__tests__/issuanceBranding.store.test.ts +1884 -1884
- package/src/__tests__/machineState.entities.test.ts +51 -51
- package/src/__tests__/machineState.store.test.ts +174 -174
- package/src/contact/AbstractContactStore.ts +71 -71
- package/src/contact/ContactStore.ts +723 -723
- package/src/digitalCredential/AbstractDigitalCredentialStore.ts +17 -17
- package/src/digitalCredential/DigitalCredentialStore.ts +127 -127
- package/src/entities/contact/BaseContactEntity.ts +39 -39
- package/src/entities/contact/ConnectionEntity.ts +29 -29
- package/src/entities/contact/CorrelationIdentifierEntity.ts +37 -37
- package/src/entities/contact/DidAuthConfigEntity.ts +14 -14
- package/src/entities/contact/ElectronicAddressEntity.ts +63 -63
- package/src/entities/contact/IdentityEntity.ts +97 -97
- package/src/entities/contact/IdentityMetadataItemEntity.ts +35 -35
- package/src/entities/contact/NaturalPersonEntity.ts +38 -38
- package/src/entities/contact/OpenIdConfigEntity.ts +26 -26
- package/src/entities/contact/OrganizationEntity.ts +34 -34
- package/src/entities/contact/PartyEntity.ts +110 -110
- package/src/entities/contact/PartyRelationshipEntity.ts +61 -61
- package/src/entities/contact/PartyTypeEntity.ts +62 -62
- package/src/entities/contact/PhysicalAddressEntity.ts +87 -87
- package/src/entities/digitalCredential/DigitalCredentialEntity.ts +64 -64
- package/src/entities/eventLogger/AuditEventEntity.ts +99 -99
- package/src/entities/issuanceBranding/CredentialBrandingEntity.ts +78 -78
- package/src/entities/issuanceBranding/ImageAttributesEntity.ts +57 -57
- package/src/entities/issuanceBranding/IssuerBrandingEntity.ts +72 -72
- package/src/entities/machineState/MachineStateInfoEntity.ts +58 -58
- package/src/entities/statusList2021/StatusList2021Entity.ts +96 -96
- package/src/eventLogger/AbstractEventLoggerStore.ts +7 -7
- package/src/eventLogger/EventLoggerStore.ts +62 -62
- package/src/index.ts +141 -154
- package/src/issuanceBranding/IssuanceBrandingStore.ts +559 -559
- package/src/machineState/IAbstractMachineStateStore.ts +65 -65
- package/src/machineState/MachineStateStore.ts +149 -149
- package/src/migrations/generic/1-CreateContacts.ts +66 -66
- package/src/migrations/generic/2-CreateIssuanceBranding.ts +64 -64
- package/src/migrations/generic/3-CreateContacts.ts +66 -66
- package/src/migrations/generic/4-CreateStatusList.ts +54 -54
- package/src/migrations/generic/5-CreateAuditEvents.ts +66 -66
- package/src/migrations/generic/6-CreateDigitalCredential.ts +66 -66
- package/src/migrations/generic/7-CreateMachineStateStore.ts +66 -66
- package/src/migrations/generic/index.ts +33 -36
- package/src/migrations/index.ts +9 -10
- package/src/migrations/postgres/1659463079428-CreateContacts.ts +63 -63
- package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +85 -85
- package/src/migrations/postgres/1690925872592-CreateContacts.ts +104 -104
- package/src/migrations/postgres/1693866470001-CreateStatusList.ts +24 -24
- package/src/migrations/postgres/1701634812183-CreateAuditEvents.ts +33 -33
- package/src/migrations/postgres/1708525189001-CreateDigitalCredential.ts +44 -44
- package/src/migrations/postgres/1708797018115-CreateMachineStateStore.ts +29 -29
- package/src/migrations/sqlite/1659463069549-CreateContacts.ts +110 -110
- package/src/migrations/sqlite/1685628973231-CreateIssuanceBranding.ts +119 -119
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +161 -161
- package/src/migrations/sqlite/1693866470000-CreateStatusList.ts +24 -24
- package/src/migrations/sqlite/1701634819487-CreateAuditEvents.ts +15 -15
- package/src/migrations/sqlite/1708525189002-CreateDigitalCredential.ts +34 -34
- package/src/migrations/sqlite/1708796002272-CreateMachineStateStore.ts +28 -28
- package/src/statusList/StatusListStore.ts +237 -237
- package/src/types/contact/IAbstractContactStore.ts +161 -161
- package/src/types/contact/contact.ts +237 -237
- package/src/types/digitalCredential/IAbstractDigitalCredentialStore.ts +37 -37
- package/src/types/digitalCredential/digitalCredential.ts +46 -46
- package/src/types/eventLogger/IAbstractEventLoggerStore.ts +12 -12
- package/src/types/eventLogger/eventLogger.ts +3 -3
- package/src/types/index.ts +10 -12
- package/src/types/machineState/IAbstractMachineStateStore.ts +68 -68
- package/src/utils/SortingUtils.ts +16 -16
- package/src/utils/contact/MappingUtils.ts +385 -385
- package/src/utils/digitalCredential/MappingUtils.ts +122 -122
- package/dist/entities/presentationDefinitions/PresentationDefinitionItemEntity.d.ts +0 -13
- package/dist/entities/presentationDefinitions/PresentationDefinitionItemEntity.d.ts.map +0 -1
- package/dist/entities/presentationDefinitions/PresentationDefinitionItemEntity.js +0 -71
- package/dist/entities/presentationDefinitions/PresentationDefinitionItemEntity.js.map +0 -1
- package/dist/migrations/generic/8-CreatePresentationDefinitions.d.ts +0 -7
- package/dist/migrations/generic/8-CreatePresentationDefinitions.d.ts.map +0 -1
- package/dist/migrations/generic/8-CreatePresentationDefinitions.js +0 -78
- package/dist/migrations/generic/8-CreatePresentationDefinitions.js.map +0 -1
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.d.ts +0 -7
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.d.ts.map +0 -1
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js +0 -40
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js.map +0 -1
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.d.ts +0 -7
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.d.ts.map +0 -1
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js +0 -37
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js.map +0 -1
- package/dist/pd/AbstractPDStore.d.ts +0 -10
- package/dist/pd/AbstractPDStore.d.ts.map +0 -1
- package/dist/pd/AbstractPDStore.js +0 -7
- package/dist/pd/AbstractPDStore.js.map +0 -1
- package/dist/pd/PDStore.d.ts +0 -14
- package/dist/pd/PDStore.d.ts.map +0 -1
- package/dist/pd/PDStore.js +0 -90
- package/dist/pd/PDStore.js.map +0 -1
- package/dist/types/pd/IAbstractPDStore.d.ts +0 -14
- package/dist/types/pd/IAbstractPDStore.d.ts.map +0 -1
- package/dist/types/pd/IAbstractPDStore.js +0 -3
- package/dist/types/pd/IAbstractPDStore.js.map +0 -1
- package/dist/types/pd/pd.d.ts +0 -15
- package/dist/types/pd/pd.d.ts.map +0 -1
- package/dist/types/pd/pd.js +0 -3
- package/dist/types/pd/pd.js.map +0 -1
- package/dist/utils/presentationDefinitions/MappingUtils.d.ts +0 -6
- package/dist/utils/presentationDefinitions/MappingUtils.d.ts.map +0 -1
- package/dist/utils/presentationDefinitions/MappingUtils.js +0 -50
- package/dist/utils/presentationDefinitions/MappingUtils.js.map +0 -1
- package/src/entities/presentationDefinitions/PresentationDefinitionItemEntity.ts +0 -41
- package/src/migrations/generic/8-CreatePresentationDefinitions.ts +0 -66
- package/src/migrations/postgres/1716475165345-CreatePresentationDefinitions.ts +0 -24
- package/src/migrations/sqlite/1716475165344-CreatePresentationDefinitions.ts +0 -23
- package/src/pd/AbstractPDStore.ts +0 -10
- package/src/pd/PDStore.ts +0 -103
- package/src/types/pd/IAbstractPDStore.ts +0 -19
- package/src/types/pd/pd.ts +0 -16
- package/src/utils/presentationDefinitions/MappingUtils.ts +0 -54
|
@@ -1,385 +1,385 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Connection,
|
|
3
|
-
ConnectionConfig,
|
|
4
|
-
Contact,
|
|
5
|
-
CorrelationIdentifier,
|
|
6
|
-
DidAuthConfig,
|
|
7
|
-
ElectronicAddress,
|
|
8
|
-
Identity,
|
|
9
|
-
MetadataItem,
|
|
10
|
-
NaturalPerson,
|
|
11
|
-
NonPersistedConnection,
|
|
12
|
-
NonPersistedConnectionConfig,
|
|
13
|
-
NonPersistedContact,
|
|
14
|
-
NonPersistedCorrelationIdentifier,
|
|
15
|
-
NonPersistedDidAuthConfig,
|
|
16
|
-
NonPersistedElectronicAddress,
|
|
17
|
-
NonPersistedIdentity,
|
|
18
|
-
NonPersistedMetadataItem,
|
|
19
|
-
NonPersistedNaturalPerson,
|
|
20
|
-
NonPersistedOpenIdConfig,
|
|
21
|
-
NonPersistedOrganization,
|
|
22
|
-
NonPersistedParty,
|
|
23
|
-
NonPersistedPartyRelationship,
|
|
24
|
-
NonPersistedPartyType,
|
|
25
|
-
NonPersistedPhysicalAddress,
|
|
26
|
-
OpenIdConfig,
|
|
27
|
-
Organization,
|
|
28
|
-
Party,
|
|
29
|
-
PartyRelationship,
|
|
30
|
-
PartyType,
|
|
31
|
-
PhysicalAddress
|
|
32
|
-
} from '../../types'
|
|
33
|
-
import { PartyEntity } from '../../entities/contact/PartyEntity'
|
|
34
|
-
import { IdentityEntity } from '../../entities/contact/IdentityEntity'
|
|
35
|
-
import { ElectronicAddressEntity } from '../../entities/contact/ElectronicAddressEntity'
|
|
36
|
-
import { PartyRelationshipEntity } from '../../entities/contact/PartyRelationshipEntity'
|
|
37
|
-
import { BaseContactEntity } from '../../entities/contact/BaseContactEntity'
|
|
38
|
-
import { NaturalPersonEntity } from '../../entities/contact/NaturalPersonEntity'
|
|
39
|
-
import { OrganizationEntity } from '../../entities/contact/OrganizationEntity'
|
|
40
|
-
import { ConnectionEntity } from '../../entities/contact/ConnectionEntity'
|
|
41
|
-
import { BaseConfigEntity } from '../../entities/contact/BaseConfigEntity'
|
|
42
|
-
import { CorrelationIdentifierEntity } from '../../entities/contact/CorrelationIdentifierEntity'
|
|
43
|
-
import { DidAuthConfigEntity } from '../../entities/contact/DidAuthConfigEntity'
|
|
44
|
-
import { IdentityMetadataItemEntity } from '../../entities/contact/IdentityMetadataItemEntity'
|
|
45
|
-
import { OpenIdConfigEntity } from '../../entities/contact/OpenIdConfigEntity'
|
|
46
|
-
import { PartyTypeEntity } from '../../entities/contact/PartyTypeEntity'
|
|
47
|
-
import { PhysicalAddressEntity } from '../../entities/contact/PhysicalAddressEntity'
|
|
48
|
-
|
|
49
|
-
export const partyEntityFrom = (party: NonPersistedParty): PartyEntity => {
|
|
50
|
-
const partyEntity: PartyEntity = new PartyEntity()
|
|
51
|
-
partyEntity.uri = party.uri
|
|
52
|
-
partyEntity.identities = party.identities ? party.identities.map((identity: NonPersistedIdentity) => identityEntityFrom(identity)) : []
|
|
53
|
-
partyEntity.electronicAddresses = party.electronicAddresses
|
|
54
|
-
? party.electronicAddresses.map((electronicAddress: NonPersistedElectronicAddress) => electronicAddressEntityFrom(electronicAddress))
|
|
55
|
-
: []
|
|
56
|
-
partyEntity.physicalAddresses = party.physicalAddresses
|
|
57
|
-
? party.physicalAddresses.map((physicalAddress: NonPersistedPhysicalAddress) => physicalAddressEntityFrom(physicalAddress))
|
|
58
|
-
: []
|
|
59
|
-
partyEntity.partyType = partyTypeEntityFrom(party.partyType)
|
|
60
|
-
partyEntity.contact = contactEntityFrom(party.contact)
|
|
61
|
-
|
|
62
|
-
return partyEntity
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const partyFrom = (party: PartyEntity): Party => {
|
|
66
|
-
return {
|
|
67
|
-
id: party.id,
|
|
68
|
-
uri: party.uri,
|
|
69
|
-
roles: [...new Set(party.identities?.flatMap((identity: IdentityEntity) => identity.roles))] ?? [],
|
|
70
|
-
identities: party.identities ? party.identities.map((identity: IdentityEntity) => identityFrom(identity)) : [],
|
|
71
|
-
electronicAddresses: party.electronicAddresses
|
|
72
|
-
? party.electronicAddresses.map((electronicAddress: ElectronicAddressEntity) => electronicAddressFrom(electronicAddress))
|
|
73
|
-
: [],
|
|
74
|
-
physicalAddresses: party.physicalAddresses
|
|
75
|
-
? party.physicalAddresses.map((physicalAddress: PhysicalAddressEntity) => physicalAddressFrom(physicalAddress))
|
|
76
|
-
: [],
|
|
77
|
-
relationships: party.relationships ? party.relationships.map((relationship: PartyRelationshipEntity) => partyRelationshipFrom(relationship)) : [],
|
|
78
|
-
partyType: partyTypeFrom(party.partyType),
|
|
79
|
-
contact: contactFrom(party.contact),
|
|
80
|
-
createdAt: party.createdAt,
|
|
81
|
-
lastUpdatedAt: party.lastUpdatedAt,
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const contactEntityFrom = (contact: NonPersistedContact): BaseContactEntity => {
|
|
86
|
-
if (isNaturalPerson(contact)) {
|
|
87
|
-
return naturalPersonEntityFrom(<NonPersistedNaturalPerson>contact)
|
|
88
|
-
} else if (isOrganization(contact)) {
|
|
89
|
-
return organizationEntityFrom(<NonPersistedOrganization>contact)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
throw new Error('Contact not supported')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const contactFrom = (contact: BaseContactEntity): Contact => {
|
|
96
|
-
if (isNaturalPerson(contact)) {
|
|
97
|
-
return naturalPersonFrom(<NaturalPersonEntity>contact)
|
|
98
|
-
} else if (isOrganization(contact)) {
|
|
99
|
-
return organizationFrom(<OrganizationEntity>contact)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
throw new Error(`Contact type not supported`)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export const isNaturalPerson = (contact: NonPersistedContact | BaseContactEntity): contact is NonPersistedNaturalPerson | NaturalPersonEntity =>
|
|
106
|
-
'firstName' in contact && 'lastName' in contact
|
|
107
|
-
|
|
108
|
-
export const isOrganization = (contact: NonPersistedContact | BaseContactEntity): contact is NonPersistedOrganization | OrganizationEntity =>
|
|
109
|
-
'legalName' in contact
|
|
110
|
-
|
|
111
|
-
export const connectionEntityFrom = (connection: NonPersistedConnection): ConnectionEntity => {
|
|
112
|
-
const connectionEntity: ConnectionEntity = new ConnectionEntity()
|
|
113
|
-
connectionEntity.type = connection.type
|
|
114
|
-
connectionEntity.config = configEntityFrom(connection.config)
|
|
115
|
-
|
|
116
|
-
return connectionEntity
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export const connectionFrom = (connection: ConnectionEntity): Connection => {
|
|
120
|
-
return {
|
|
121
|
-
id: connection.id,
|
|
122
|
-
type: connection.type,
|
|
123
|
-
config: configFrom(connection.config),
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const configEntityFrom = (config: NonPersistedConnectionConfig): BaseConfigEntity => {
|
|
128
|
-
if (isOpenIdConfig(config)) {
|
|
129
|
-
return openIdConfigEntityFrom(<NonPersistedOpenIdConfig>config)
|
|
130
|
-
} else if (isDidAuthConfig(config)) {
|
|
131
|
-
return didAuthConfigEntityFrom(<NonPersistedDidAuthConfig>config)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
throw new Error('config type not supported')
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export const correlationIdentifierEntityFrom = (identifier: NonPersistedCorrelationIdentifier): CorrelationIdentifierEntity => {
|
|
138
|
-
const identifierEntity: CorrelationIdentifierEntity = new CorrelationIdentifierEntity()
|
|
139
|
-
identifierEntity.type = identifier.type
|
|
140
|
-
identifierEntity.correlationId = identifier.correlationId
|
|
141
|
-
|
|
142
|
-
return identifierEntity
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export const correlationIdentifierFrom = (identifier: CorrelationIdentifierEntity): CorrelationIdentifier => {
|
|
146
|
-
return {
|
|
147
|
-
id: identifier.id,
|
|
148
|
-
type: identifier.type,
|
|
149
|
-
correlationId: identifier.correlationId,
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export const didAuthConfigEntityFrom = (config: NonPersistedDidAuthConfig): DidAuthConfigEntity => {
|
|
154
|
-
const didAuthConfig: DidAuthConfigEntity = new DidAuthConfigEntity()
|
|
155
|
-
didAuthConfig.identifier = config.identifier.did
|
|
156
|
-
didAuthConfig.redirectUrl = config.redirectUrl
|
|
157
|
-
didAuthConfig.sessionId = config.sessionId
|
|
158
|
-
|
|
159
|
-
return didAuthConfig
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export const electronicAddressEntityFrom = (electronicAddress: NonPersistedElectronicAddress): ElectronicAddressEntity => {
|
|
163
|
-
const electronicAddressEntity: ElectronicAddressEntity = new ElectronicAddressEntity()
|
|
164
|
-
electronicAddressEntity.type = electronicAddress.type
|
|
165
|
-
electronicAddressEntity.electronicAddress = electronicAddress.electronicAddress
|
|
166
|
-
|
|
167
|
-
return electronicAddressEntity
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export const electronicAddressFrom = (electronicAddress: ElectronicAddressEntity): ElectronicAddress => {
|
|
171
|
-
return {
|
|
172
|
-
id: electronicAddress.id,
|
|
173
|
-
type: electronicAddress.type,
|
|
174
|
-
electronicAddress: electronicAddress.electronicAddress,
|
|
175
|
-
createdAt: electronicAddress.createdAt,
|
|
176
|
-
lastUpdatedAt: electronicAddress.lastUpdatedAt,
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export const physicalAddressEntityFrom = (physicalAddress: NonPersistedPhysicalAddress): PhysicalAddressEntity => {
|
|
181
|
-
const physicalAddressEntity: PhysicalAddressEntity = new PhysicalAddressEntity()
|
|
182
|
-
physicalAddressEntity.type = physicalAddress.type
|
|
183
|
-
physicalAddressEntity.streetName = physicalAddress.streetName
|
|
184
|
-
physicalAddressEntity.streetNumber = physicalAddress.streetNumber
|
|
185
|
-
physicalAddressEntity.postalCode = physicalAddress.postalCode
|
|
186
|
-
physicalAddressEntity.cityName = physicalAddress.cityName
|
|
187
|
-
physicalAddressEntity.provinceName = physicalAddress.provinceName
|
|
188
|
-
physicalAddressEntity.countryCode = physicalAddress.countryCode
|
|
189
|
-
physicalAddressEntity.buildingName = physicalAddress.buildingName
|
|
190
|
-
|
|
191
|
-
return physicalAddressEntity
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export const physicalAddressFrom = (physicalAddress: PhysicalAddressEntity): PhysicalAddress => {
|
|
195
|
-
return {
|
|
196
|
-
id: physicalAddress.id,
|
|
197
|
-
type: physicalAddress.type,
|
|
198
|
-
streetName: physicalAddress.streetName,
|
|
199
|
-
streetNumber: physicalAddress.streetNumber,
|
|
200
|
-
postalCode: physicalAddress.postalCode,
|
|
201
|
-
cityName: physicalAddress.cityName,
|
|
202
|
-
provinceName: physicalAddress.provinceName,
|
|
203
|
-
countryCode: physicalAddress.countryCode,
|
|
204
|
-
buildingName: physicalAddress.buildingName,
|
|
205
|
-
createdAt: physicalAddress.createdAt,
|
|
206
|
-
lastUpdatedAt: physicalAddress.lastUpdatedAt,
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export const identityEntityFrom = (args: NonPersistedIdentity): IdentityEntity => {
|
|
211
|
-
const identityEntity: IdentityEntity = new IdentityEntity()
|
|
212
|
-
identityEntity.alias = args.alias
|
|
213
|
-
identityEntity.roles = args.roles
|
|
214
|
-
identityEntity.identifier = correlationIdentifierEntityFrom(args.identifier)
|
|
215
|
-
identityEntity.connection = args.connection ? connectionEntityFrom(args.connection) : undefined
|
|
216
|
-
identityEntity.metadata = args.metadata ? args.metadata.map((item: NonPersistedMetadataItem) => metadataItemEntityFrom(item)) : []
|
|
217
|
-
|
|
218
|
-
return identityEntity
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export const identityFrom = (identity: IdentityEntity): Identity => {
|
|
222
|
-
return {
|
|
223
|
-
id: identity.id,
|
|
224
|
-
alias: identity.alias,
|
|
225
|
-
roles: identity.roles,
|
|
226
|
-
identifier: correlationIdentifierFrom(identity.identifier),
|
|
227
|
-
...(identity.connection && { connection: connectionFrom(identity.connection) }),
|
|
228
|
-
metadata: identity.metadata ? identity.metadata.map((item: IdentityMetadataItemEntity) => metadataItemFrom(item)) : [],
|
|
229
|
-
createdAt: identity.createdAt,
|
|
230
|
-
lastUpdatedAt: identity.createdAt,
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export const metadataItemEntityFrom = (item: NonPersistedMetadataItem): IdentityMetadataItemEntity => {
|
|
235
|
-
const metadataItemEntity: IdentityMetadataItemEntity = new IdentityMetadataItemEntity()
|
|
236
|
-
metadataItemEntity.label = item.label
|
|
237
|
-
metadataItemEntity.value = item.value
|
|
238
|
-
|
|
239
|
-
return metadataItemEntity
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export const metadataItemFrom = (item: IdentityMetadataItemEntity): MetadataItem => {
|
|
243
|
-
return {
|
|
244
|
-
id: item.id,
|
|
245
|
-
label: item.label,
|
|
246
|
-
value: item.value,
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export const naturalPersonEntityFrom = (naturalPerson: NonPersistedNaturalPerson): NaturalPersonEntity => {
|
|
251
|
-
const naturalPersonEntity: NaturalPersonEntity = new NaturalPersonEntity()
|
|
252
|
-
naturalPersonEntity.firstName = naturalPerson.firstName
|
|
253
|
-
naturalPersonEntity.middleName = naturalPerson.middleName
|
|
254
|
-
naturalPersonEntity.lastName = naturalPerson.lastName
|
|
255
|
-
naturalPersonEntity.displayName = naturalPerson.displayName
|
|
256
|
-
|
|
257
|
-
return naturalPersonEntity
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export const naturalPersonFrom = (naturalPerson: NaturalPersonEntity): NaturalPerson => {
|
|
261
|
-
return {
|
|
262
|
-
id: naturalPerson.id,
|
|
263
|
-
firstName: naturalPerson.firstName,
|
|
264
|
-
middleName: naturalPerson.middleName,
|
|
265
|
-
lastName: naturalPerson.lastName,
|
|
266
|
-
displayName: naturalPerson.displayName,
|
|
267
|
-
createdAt: naturalPerson.createdAt,
|
|
268
|
-
lastUpdatedAt: naturalPerson.lastUpdatedAt,
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export const openIdConfigEntityFrom = (config: NonPersistedOpenIdConfig): OpenIdConfigEntity => {
|
|
273
|
-
const openIdConfig: OpenIdConfigEntity = new OpenIdConfigEntity()
|
|
274
|
-
openIdConfig.clientId = config.clientId
|
|
275
|
-
openIdConfig.clientSecret = config.clientSecret
|
|
276
|
-
openIdConfig.scopes = config.scopes
|
|
277
|
-
openIdConfig.issuer = config.issuer
|
|
278
|
-
openIdConfig.redirectUrl = config.redirectUrl
|
|
279
|
-
openIdConfig.dangerouslyAllowInsecureHttpRequests = config.dangerouslyAllowInsecureHttpRequests
|
|
280
|
-
openIdConfig.clientAuthMethod = config.clientAuthMethod
|
|
281
|
-
|
|
282
|
-
return openIdConfig
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export const organizationEntityFrom = (organization: NonPersistedOrganization): OrganizationEntity => {
|
|
286
|
-
const organizationEntity: OrganizationEntity = new OrganizationEntity()
|
|
287
|
-
organizationEntity.legalName = organization.legalName
|
|
288
|
-
organizationEntity.displayName = organization.displayName
|
|
289
|
-
|
|
290
|
-
return organizationEntity
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export const organizationFrom = (organization: OrganizationEntity): Organization => {
|
|
294
|
-
return {
|
|
295
|
-
id: organization.id,
|
|
296
|
-
legalName: organization.legalName,
|
|
297
|
-
displayName: organization.displayName,
|
|
298
|
-
createdAt: organization.createdAt,
|
|
299
|
-
lastUpdatedAt: organization.lastUpdatedAt,
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export const partyRelationshipEntityFrom = (relationship: NonPersistedPartyRelationship): PartyRelationshipEntity => {
|
|
304
|
-
const partyRelationshipEntity: PartyRelationshipEntity = new PartyRelationshipEntity()
|
|
305
|
-
partyRelationshipEntity.leftId = relationship.leftId
|
|
306
|
-
partyRelationshipEntity.rightId = relationship.rightId
|
|
307
|
-
|
|
308
|
-
return partyRelationshipEntity
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export const partyRelationshipFrom = (relationship: PartyRelationshipEntity): PartyRelationship => {
|
|
312
|
-
return {
|
|
313
|
-
id: relationship.id,
|
|
314
|
-
leftId: relationship.leftId,
|
|
315
|
-
rightId: relationship.rightId,
|
|
316
|
-
createdAt: relationship.createdAt,
|
|
317
|
-
lastUpdatedAt: relationship.lastUpdatedAt,
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntity => {
|
|
322
|
-
const partyTypeEntity: PartyTypeEntity = new PartyTypeEntity()
|
|
323
|
-
if (args.id) {
|
|
324
|
-
partyTypeEntity.id = args.id
|
|
325
|
-
}
|
|
326
|
-
partyTypeEntity.type = args.type
|
|
327
|
-
partyTypeEntity.origin = args.origin
|
|
328
|
-
partyTypeEntity.name = args.name
|
|
329
|
-
partyTypeEntity.description = args.description
|
|
330
|
-
partyTypeEntity.tenantId = args.tenantId
|
|
331
|
-
|
|
332
|
-
return partyTypeEntity
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => {
|
|
336
|
-
return {
|
|
337
|
-
id: partyType.id,
|
|
338
|
-
type: partyType.type,
|
|
339
|
-
origin: partyType.origin,
|
|
340
|
-
name: partyType.name,
|
|
341
|
-
tenantId: partyType.tenantId,
|
|
342
|
-
description: partyType.description,
|
|
343
|
-
createdAt: partyType.createdAt,
|
|
344
|
-
lastUpdatedAt: partyType.lastUpdatedAt,
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export const configFrom = (config: BaseConfigEntity): ConnectionConfig => {
|
|
349
|
-
if (isOpenIdConfig(config)) {
|
|
350
|
-
return openIdConfigFrom(<OpenIdConfigEntity>config)
|
|
351
|
-
} else if (isDidAuthConfig(config)) {
|
|
352
|
-
return didAuthConfigFrom(<DidAuthConfigEntity>config)
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
throw new Error('config type not supported')
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export const openIdConfigFrom = (config: OpenIdConfigEntity): OpenIdConfig => {
|
|
359
|
-
return {
|
|
360
|
-
id: config.id,
|
|
361
|
-
clientId: config.clientId,
|
|
362
|
-
clientSecret: config.clientSecret,
|
|
363
|
-
scopes: config.scopes,
|
|
364
|
-
issuer: config.issuer,
|
|
365
|
-
redirectUrl: config.redirectUrl,
|
|
366
|
-
dangerouslyAllowInsecureHttpRequests: config.dangerouslyAllowInsecureHttpRequests,
|
|
367
|
-
clientAuthMethod: config.clientAuthMethod,
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export const didAuthConfigFrom = (config: DidAuthConfigEntity): DidAuthConfig => {
|
|
372
|
-
return {
|
|
373
|
-
id: config.id,
|
|
374
|
-
identifier: { did: config.identifier, provider: '', keys: [], services: [] },
|
|
375
|
-
stateId: '', // FIXME
|
|
376
|
-
redirectUrl: config.redirectUrl,
|
|
377
|
-
sessionId: config.sessionId,
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export const isOpenIdConfig = (config: NonPersistedConnectionConfig | BaseConfigEntity): config is OpenIdConfig | OpenIdConfigEntity =>
|
|
382
|
-
'clientSecret' in config && 'issuer' in config && 'redirectUrl' in config
|
|
383
|
-
|
|
384
|
-
export const isDidAuthConfig = (config: NonPersistedConnectionConfig | BaseConfigEntity): config is DidAuthConfig | DidAuthConfigEntity =>
|
|
385
|
-
'identifier' in config && 'redirectUrl' in config && 'sessionId' in config
|
|
1
|
+
import {
|
|
2
|
+
Connection,
|
|
3
|
+
ConnectionConfig,
|
|
4
|
+
Contact,
|
|
5
|
+
CorrelationIdentifier,
|
|
6
|
+
DidAuthConfig,
|
|
7
|
+
ElectronicAddress,
|
|
8
|
+
Identity,
|
|
9
|
+
MetadataItem,
|
|
10
|
+
NaturalPerson,
|
|
11
|
+
NonPersistedConnection,
|
|
12
|
+
NonPersistedConnectionConfig,
|
|
13
|
+
NonPersistedContact,
|
|
14
|
+
NonPersistedCorrelationIdentifier,
|
|
15
|
+
NonPersistedDidAuthConfig,
|
|
16
|
+
NonPersistedElectronicAddress,
|
|
17
|
+
NonPersistedIdentity,
|
|
18
|
+
NonPersistedMetadataItem,
|
|
19
|
+
NonPersistedNaturalPerson,
|
|
20
|
+
NonPersistedOpenIdConfig,
|
|
21
|
+
NonPersistedOrganization,
|
|
22
|
+
NonPersistedParty,
|
|
23
|
+
NonPersistedPartyRelationship,
|
|
24
|
+
NonPersistedPartyType,
|
|
25
|
+
NonPersistedPhysicalAddress,
|
|
26
|
+
OpenIdConfig,
|
|
27
|
+
Organization,
|
|
28
|
+
Party,
|
|
29
|
+
PartyRelationship,
|
|
30
|
+
PartyType,
|
|
31
|
+
PhysicalAddress,
|
|
32
|
+
} from '../../types'
|
|
33
|
+
import { PartyEntity } from '../../entities/contact/PartyEntity'
|
|
34
|
+
import { IdentityEntity } from '../../entities/contact/IdentityEntity'
|
|
35
|
+
import { ElectronicAddressEntity } from '../../entities/contact/ElectronicAddressEntity'
|
|
36
|
+
import { PartyRelationshipEntity } from '../../entities/contact/PartyRelationshipEntity'
|
|
37
|
+
import { BaseContactEntity } from '../../entities/contact/BaseContactEntity'
|
|
38
|
+
import { NaturalPersonEntity } from '../../entities/contact/NaturalPersonEntity'
|
|
39
|
+
import { OrganizationEntity } from '../../entities/contact/OrganizationEntity'
|
|
40
|
+
import { ConnectionEntity } from '../../entities/contact/ConnectionEntity'
|
|
41
|
+
import { BaseConfigEntity } from '../../entities/contact/BaseConfigEntity'
|
|
42
|
+
import { CorrelationIdentifierEntity } from '../../entities/contact/CorrelationIdentifierEntity'
|
|
43
|
+
import { DidAuthConfigEntity } from '../../entities/contact/DidAuthConfigEntity'
|
|
44
|
+
import { IdentityMetadataItemEntity } from '../../entities/contact/IdentityMetadataItemEntity'
|
|
45
|
+
import { OpenIdConfigEntity } from '../../entities/contact/OpenIdConfigEntity'
|
|
46
|
+
import { PartyTypeEntity } from '../../entities/contact/PartyTypeEntity'
|
|
47
|
+
import { PhysicalAddressEntity } from '../../entities/contact/PhysicalAddressEntity'
|
|
48
|
+
|
|
49
|
+
export const partyEntityFrom = (party: NonPersistedParty): PartyEntity => {
|
|
50
|
+
const partyEntity: PartyEntity = new PartyEntity()
|
|
51
|
+
partyEntity.uri = party.uri
|
|
52
|
+
partyEntity.identities = party.identities ? party.identities.map((identity: NonPersistedIdentity) => identityEntityFrom(identity)) : []
|
|
53
|
+
partyEntity.electronicAddresses = party.electronicAddresses
|
|
54
|
+
? party.electronicAddresses.map((electronicAddress: NonPersistedElectronicAddress) => electronicAddressEntityFrom(electronicAddress))
|
|
55
|
+
: []
|
|
56
|
+
partyEntity.physicalAddresses = party.physicalAddresses
|
|
57
|
+
? party.physicalAddresses.map((physicalAddress: NonPersistedPhysicalAddress) => physicalAddressEntityFrom(physicalAddress))
|
|
58
|
+
: []
|
|
59
|
+
partyEntity.partyType = partyTypeEntityFrom(party.partyType)
|
|
60
|
+
partyEntity.contact = contactEntityFrom(party.contact)
|
|
61
|
+
|
|
62
|
+
return partyEntity
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const partyFrom = (party: PartyEntity): Party => {
|
|
66
|
+
return {
|
|
67
|
+
id: party.id,
|
|
68
|
+
uri: party.uri,
|
|
69
|
+
roles: [...new Set(party.identities?.flatMap((identity: IdentityEntity) => identity.roles))] ?? [],
|
|
70
|
+
identities: party.identities ? party.identities.map((identity: IdentityEntity) => identityFrom(identity)) : [],
|
|
71
|
+
electronicAddresses: party.electronicAddresses
|
|
72
|
+
? party.electronicAddresses.map((electronicAddress: ElectronicAddressEntity) => electronicAddressFrom(electronicAddress))
|
|
73
|
+
: [],
|
|
74
|
+
physicalAddresses: party.physicalAddresses
|
|
75
|
+
? party.physicalAddresses.map((physicalAddress: PhysicalAddressEntity) => physicalAddressFrom(physicalAddress))
|
|
76
|
+
: [],
|
|
77
|
+
relationships: party.relationships ? party.relationships.map((relationship: PartyRelationshipEntity) => partyRelationshipFrom(relationship)) : [],
|
|
78
|
+
partyType: partyTypeFrom(party.partyType),
|
|
79
|
+
contact: contactFrom(party.contact),
|
|
80
|
+
createdAt: party.createdAt,
|
|
81
|
+
lastUpdatedAt: party.lastUpdatedAt,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const contactEntityFrom = (contact: NonPersistedContact): BaseContactEntity => {
|
|
86
|
+
if (isNaturalPerson(contact)) {
|
|
87
|
+
return naturalPersonEntityFrom(<NonPersistedNaturalPerson>contact)
|
|
88
|
+
} else if (isOrganization(contact)) {
|
|
89
|
+
return organizationEntityFrom(<NonPersistedOrganization>contact)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
throw new Error('Contact not supported')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const contactFrom = (contact: BaseContactEntity): Contact => {
|
|
96
|
+
if (isNaturalPerson(contact)) {
|
|
97
|
+
return naturalPersonFrom(<NaturalPersonEntity>contact)
|
|
98
|
+
} else if (isOrganization(contact)) {
|
|
99
|
+
return organizationFrom(<OrganizationEntity>contact)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
throw new Error(`Contact type not supported`)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const isNaturalPerson = (contact: NonPersistedContact | BaseContactEntity): contact is NonPersistedNaturalPerson | NaturalPersonEntity =>
|
|
106
|
+
'firstName' in contact && 'lastName' in contact
|
|
107
|
+
|
|
108
|
+
export const isOrganization = (contact: NonPersistedContact | BaseContactEntity): contact is NonPersistedOrganization | OrganizationEntity =>
|
|
109
|
+
'legalName' in contact
|
|
110
|
+
|
|
111
|
+
export const connectionEntityFrom = (connection: NonPersistedConnection): ConnectionEntity => {
|
|
112
|
+
const connectionEntity: ConnectionEntity = new ConnectionEntity()
|
|
113
|
+
connectionEntity.type = connection.type
|
|
114
|
+
connectionEntity.config = configEntityFrom(connection.config)
|
|
115
|
+
|
|
116
|
+
return connectionEntity
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export const connectionFrom = (connection: ConnectionEntity): Connection => {
|
|
120
|
+
return {
|
|
121
|
+
id: connection.id,
|
|
122
|
+
type: connection.type,
|
|
123
|
+
config: configFrom(connection.config),
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const configEntityFrom = (config: NonPersistedConnectionConfig): BaseConfigEntity => {
|
|
128
|
+
if (isOpenIdConfig(config)) {
|
|
129
|
+
return openIdConfigEntityFrom(<NonPersistedOpenIdConfig>config)
|
|
130
|
+
} else if (isDidAuthConfig(config)) {
|
|
131
|
+
return didAuthConfigEntityFrom(<NonPersistedDidAuthConfig>config)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
throw new Error('config type not supported')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const correlationIdentifierEntityFrom = (identifier: NonPersistedCorrelationIdentifier): CorrelationIdentifierEntity => {
|
|
138
|
+
const identifierEntity: CorrelationIdentifierEntity = new CorrelationIdentifierEntity()
|
|
139
|
+
identifierEntity.type = identifier.type
|
|
140
|
+
identifierEntity.correlationId = identifier.correlationId
|
|
141
|
+
|
|
142
|
+
return identifierEntity
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const correlationIdentifierFrom = (identifier: CorrelationIdentifierEntity): CorrelationIdentifier => {
|
|
146
|
+
return {
|
|
147
|
+
id: identifier.id,
|
|
148
|
+
type: identifier.type,
|
|
149
|
+
correlationId: identifier.correlationId,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const didAuthConfigEntityFrom = (config: NonPersistedDidAuthConfig): DidAuthConfigEntity => {
|
|
154
|
+
const didAuthConfig: DidAuthConfigEntity = new DidAuthConfigEntity()
|
|
155
|
+
didAuthConfig.identifier = config.identifier.did
|
|
156
|
+
didAuthConfig.redirectUrl = config.redirectUrl
|
|
157
|
+
didAuthConfig.sessionId = config.sessionId
|
|
158
|
+
|
|
159
|
+
return didAuthConfig
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const electronicAddressEntityFrom = (electronicAddress: NonPersistedElectronicAddress): ElectronicAddressEntity => {
|
|
163
|
+
const electronicAddressEntity: ElectronicAddressEntity = new ElectronicAddressEntity()
|
|
164
|
+
electronicAddressEntity.type = electronicAddress.type
|
|
165
|
+
electronicAddressEntity.electronicAddress = electronicAddress.electronicAddress
|
|
166
|
+
|
|
167
|
+
return electronicAddressEntity
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export const electronicAddressFrom = (electronicAddress: ElectronicAddressEntity): ElectronicAddress => {
|
|
171
|
+
return {
|
|
172
|
+
id: electronicAddress.id,
|
|
173
|
+
type: electronicAddress.type,
|
|
174
|
+
electronicAddress: electronicAddress.electronicAddress,
|
|
175
|
+
createdAt: electronicAddress.createdAt,
|
|
176
|
+
lastUpdatedAt: electronicAddress.lastUpdatedAt,
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const physicalAddressEntityFrom = (physicalAddress: NonPersistedPhysicalAddress): PhysicalAddressEntity => {
|
|
181
|
+
const physicalAddressEntity: PhysicalAddressEntity = new PhysicalAddressEntity()
|
|
182
|
+
physicalAddressEntity.type = physicalAddress.type
|
|
183
|
+
physicalAddressEntity.streetName = physicalAddress.streetName
|
|
184
|
+
physicalAddressEntity.streetNumber = physicalAddress.streetNumber
|
|
185
|
+
physicalAddressEntity.postalCode = physicalAddress.postalCode
|
|
186
|
+
physicalAddressEntity.cityName = physicalAddress.cityName
|
|
187
|
+
physicalAddressEntity.provinceName = physicalAddress.provinceName
|
|
188
|
+
physicalAddressEntity.countryCode = physicalAddress.countryCode
|
|
189
|
+
physicalAddressEntity.buildingName = physicalAddress.buildingName
|
|
190
|
+
|
|
191
|
+
return physicalAddressEntity
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export const physicalAddressFrom = (physicalAddress: PhysicalAddressEntity): PhysicalAddress => {
|
|
195
|
+
return {
|
|
196
|
+
id: physicalAddress.id,
|
|
197
|
+
type: physicalAddress.type,
|
|
198
|
+
streetName: physicalAddress.streetName,
|
|
199
|
+
streetNumber: physicalAddress.streetNumber,
|
|
200
|
+
postalCode: physicalAddress.postalCode,
|
|
201
|
+
cityName: physicalAddress.cityName,
|
|
202
|
+
provinceName: physicalAddress.provinceName,
|
|
203
|
+
countryCode: physicalAddress.countryCode,
|
|
204
|
+
buildingName: physicalAddress.buildingName,
|
|
205
|
+
createdAt: physicalAddress.createdAt,
|
|
206
|
+
lastUpdatedAt: physicalAddress.lastUpdatedAt,
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export const identityEntityFrom = (args: NonPersistedIdentity): IdentityEntity => {
|
|
211
|
+
const identityEntity: IdentityEntity = new IdentityEntity()
|
|
212
|
+
identityEntity.alias = args.alias
|
|
213
|
+
identityEntity.roles = args.roles
|
|
214
|
+
identityEntity.identifier = correlationIdentifierEntityFrom(args.identifier)
|
|
215
|
+
identityEntity.connection = args.connection ? connectionEntityFrom(args.connection) : undefined
|
|
216
|
+
identityEntity.metadata = args.metadata ? args.metadata.map((item: NonPersistedMetadataItem) => metadataItemEntityFrom(item)) : []
|
|
217
|
+
|
|
218
|
+
return identityEntity
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export const identityFrom = (identity: IdentityEntity): Identity => {
|
|
222
|
+
return {
|
|
223
|
+
id: identity.id,
|
|
224
|
+
alias: identity.alias,
|
|
225
|
+
roles: identity.roles,
|
|
226
|
+
identifier: correlationIdentifierFrom(identity.identifier),
|
|
227
|
+
...(identity.connection && { connection: connectionFrom(identity.connection) }),
|
|
228
|
+
metadata: identity.metadata ? identity.metadata.map((item: IdentityMetadataItemEntity) => metadataItemFrom(item)) : [],
|
|
229
|
+
createdAt: identity.createdAt,
|
|
230
|
+
lastUpdatedAt: identity.createdAt,
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export const metadataItemEntityFrom = (item: NonPersistedMetadataItem): IdentityMetadataItemEntity => {
|
|
235
|
+
const metadataItemEntity: IdentityMetadataItemEntity = new IdentityMetadataItemEntity()
|
|
236
|
+
metadataItemEntity.label = item.label
|
|
237
|
+
metadataItemEntity.value = item.value
|
|
238
|
+
|
|
239
|
+
return metadataItemEntity
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export const metadataItemFrom = (item: IdentityMetadataItemEntity): MetadataItem => {
|
|
243
|
+
return {
|
|
244
|
+
id: item.id,
|
|
245
|
+
label: item.label,
|
|
246
|
+
value: item.value,
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export const naturalPersonEntityFrom = (naturalPerson: NonPersistedNaturalPerson): NaturalPersonEntity => {
|
|
251
|
+
const naturalPersonEntity: NaturalPersonEntity = new NaturalPersonEntity()
|
|
252
|
+
naturalPersonEntity.firstName = naturalPerson.firstName
|
|
253
|
+
naturalPersonEntity.middleName = naturalPerson.middleName
|
|
254
|
+
naturalPersonEntity.lastName = naturalPerson.lastName
|
|
255
|
+
naturalPersonEntity.displayName = naturalPerson.displayName
|
|
256
|
+
|
|
257
|
+
return naturalPersonEntity
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export const naturalPersonFrom = (naturalPerson: NaturalPersonEntity): NaturalPerson => {
|
|
261
|
+
return {
|
|
262
|
+
id: naturalPerson.id,
|
|
263
|
+
firstName: naturalPerson.firstName,
|
|
264
|
+
middleName: naturalPerson.middleName,
|
|
265
|
+
lastName: naturalPerson.lastName,
|
|
266
|
+
displayName: naturalPerson.displayName,
|
|
267
|
+
createdAt: naturalPerson.createdAt,
|
|
268
|
+
lastUpdatedAt: naturalPerson.lastUpdatedAt,
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export const openIdConfigEntityFrom = (config: NonPersistedOpenIdConfig): OpenIdConfigEntity => {
|
|
273
|
+
const openIdConfig: OpenIdConfigEntity = new OpenIdConfigEntity()
|
|
274
|
+
openIdConfig.clientId = config.clientId
|
|
275
|
+
openIdConfig.clientSecret = config.clientSecret
|
|
276
|
+
openIdConfig.scopes = config.scopes
|
|
277
|
+
openIdConfig.issuer = config.issuer
|
|
278
|
+
openIdConfig.redirectUrl = config.redirectUrl
|
|
279
|
+
openIdConfig.dangerouslyAllowInsecureHttpRequests = config.dangerouslyAllowInsecureHttpRequests
|
|
280
|
+
openIdConfig.clientAuthMethod = config.clientAuthMethod
|
|
281
|
+
|
|
282
|
+
return openIdConfig
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export const organizationEntityFrom = (organization: NonPersistedOrganization): OrganizationEntity => {
|
|
286
|
+
const organizationEntity: OrganizationEntity = new OrganizationEntity()
|
|
287
|
+
organizationEntity.legalName = organization.legalName
|
|
288
|
+
organizationEntity.displayName = organization.displayName
|
|
289
|
+
|
|
290
|
+
return organizationEntity
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export const organizationFrom = (organization: OrganizationEntity): Organization => {
|
|
294
|
+
return {
|
|
295
|
+
id: organization.id,
|
|
296
|
+
legalName: organization.legalName,
|
|
297
|
+
displayName: organization.displayName,
|
|
298
|
+
createdAt: organization.createdAt,
|
|
299
|
+
lastUpdatedAt: organization.lastUpdatedAt,
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export const partyRelationshipEntityFrom = (relationship: NonPersistedPartyRelationship): PartyRelationshipEntity => {
|
|
304
|
+
const partyRelationshipEntity: PartyRelationshipEntity = new PartyRelationshipEntity()
|
|
305
|
+
partyRelationshipEntity.leftId = relationship.leftId
|
|
306
|
+
partyRelationshipEntity.rightId = relationship.rightId
|
|
307
|
+
|
|
308
|
+
return partyRelationshipEntity
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export const partyRelationshipFrom = (relationship: PartyRelationshipEntity): PartyRelationship => {
|
|
312
|
+
return {
|
|
313
|
+
id: relationship.id,
|
|
314
|
+
leftId: relationship.leftId,
|
|
315
|
+
rightId: relationship.rightId,
|
|
316
|
+
createdAt: relationship.createdAt,
|
|
317
|
+
lastUpdatedAt: relationship.lastUpdatedAt,
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export const partyTypeEntityFrom = (args: NonPersistedPartyType): PartyTypeEntity => {
|
|
322
|
+
const partyTypeEntity: PartyTypeEntity = new PartyTypeEntity()
|
|
323
|
+
if (args.id) {
|
|
324
|
+
partyTypeEntity.id = args.id
|
|
325
|
+
}
|
|
326
|
+
partyTypeEntity.type = args.type
|
|
327
|
+
partyTypeEntity.origin = args.origin
|
|
328
|
+
partyTypeEntity.name = args.name
|
|
329
|
+
partyTypeEntity.description = args.description
|
|
330
|
+
partyTypeEntity.tenantId = args.tenantId
|
|
331
|
+
|
|
332
|
+
return partyTypeEntity
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export const partyTypeFrom = (partyType: PartyTypeEntity): PartyType => {
|
|
336
|
+
return {
|
|
337
|
+
id: partyType.id,
|
|
338
|
+
type: partyType.type,
|
|
339
|
+
origin: partyType.origin,
|
|
340
|
+
name: partyType.name,
|
|
341
|
+
tenantId: partyType.tenantId,
|
|
342
|
+
description: partyType.description,
|
|
343
|
+
createdAt: partyType.createdAt,
|
|
344
|
+
lastUpdatedAt: partyType.lastUpdatedAt,
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export const configFrom = (config: BaseConfigEntity): ConnectionConfig => {
|
|
349
|
+
if (isOpenIdConfig(config)) {
|
|
350
|
+
return openIdConfigFrom(<OpenIdConfigEntity>config)
|
|
351
|
+
} else if (isDidAuthConfig(config)) {
|
|
352
|
+
return didAuthConfigFrom(<DidAuthConfigEntity>config)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
throw new Error('config type not supported')
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export const openIdConfigFrom = (config: OpenIdConfigEntity): OpenIdConfig => {
|
|
359
|
+
return {
|
|
360
|
+
id: config.id,
|
|
361
|
+
clientId: config.clientId,
|
|
362
|
+
clientSecret: config.clientSecret,
|
|
363
|
+
scopes: config.scopes,
|
|
364
|
+
issuer: config.issuer,
|
|
365
|
+
redirectUrl: config.redirectUrl,
|
|
366
|
+
dangerouslyAllowInsecureHttpRequests: config.dangerouslyAllowInsecureHttpRequests,
|
|
367
|
+
clientAuthMethod: config.clientAuthMethod,
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export const didAuthConfigFrom = (config: DidAuthConfigEntity): DidAuthConfig => {
|
|
372
|
+
return {
|
|
373
|
+
id: config.id,
|
|
374
|
+
identifier: { did: config.identifier, provider: '', keys: [], services: [] },
|
|
375
|
+
stateId: '', // FIXME
|
|
376
|
+
redirectUrl: config.redirectUrl,
|
|
377
|
+
sessionId: config.sessionId,
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export const isOpenIdConfig = (config: NonPersistedConnectionConfig | BaseConfigEntity): config is OpenIdConfig | OpenIdConfigEntity =>
|
|
382
|
+
'clientSecret' in config && 'issuer' in config && 'redirectUrl' in config
|
|
383
|
+
|
|
384
|
+
export const isDidAuthConfig = (config: NonPersistedConnectionConfig | BaseConfigEntity): config is DidAuthConfig | DidAuthConfigEntity =>
|
|
385
|
+
'identifier' in config && 'redirectUrl' in config && 'sessionId' in config
|