@sphereon/ssi-sdk.data-store 0.18.2-next.9 → 0.18.2-next.94

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.
Files changed (55) hide show
  1. package/dist/contact/AbstractContactStore.d.ts +11 -1
  2. package/dist/contact/AbstractContactStore.d.ts.map +1 -1
  3. package/dist/contact/AbstractContactStore.js.map +1 -1
  4. package/dist/contact/ContactStore.d.ts +27 -15
  5. package/dist/contact/ContactStore.d.ts.map +1 -1
  6. package/dist/contact/ContactStore.js +201 -32
  7. package/dist/contact/ContactStore.js.map +1 -1
  8. package/dist/entities/contact/ElectronicAddressEntity.d.ts +1 -0
  9. package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -1
  10. package/dist/entities/contact/ElectronicAddressEntity.js +4 -0
  11. package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -1
  12. package/dist/entities/contact/IdentityEntity.d.ts +1 -1
  13. package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
  14. package/dist/entities/contact/PartyEntity.d.ts +2 -0
  15. package/dist/entities/contact/PartyEntity.d.ts.map +1 -1
  16. package/dist/entities/contact/PartyEntity.js +12 -1
  17. package/dist/entities/contact/PartyEntity.js.map +1 -1
  18. package/dist/entities/contact/PhysicalAddressEntity.d.ts +21 -0
  19. package/dist/entities/contact/PhysicalAddressEntity.d.ts.map +1 -0
  20. package/dist/entities/contact/PhysicalAddressEntity.js +126 -0
  21. package/dist/entities/contact/PhysicalAddressEntity.js.map +1 -0
  22. package/dist/index.d.ts +2 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
  27. package/dist/issuanceBranding/IssuanceBrandingStore.js +76 -60
  28. package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -1
  29. package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -1
  30. package/dist/migrations/sqlite/1690925872693-CreateContacts.js +3 -6
  31. package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
  32. package/dist/types/contact/IAbstractContactStore.d.ts +36 -1
  33. package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -1
  34. package/dist/types/contact/contact.d.ts +27 -4
  35. package/dist/types/contact/contact.d.ts.map +1 -1
  36. package/dist/types/contact/contact.js.map +1 -1
  37. package/dist/utils/contact/MappingUtils.d.ts +4 -1
  38. package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
  39. package/dist/utils/contact/MappingUtils.js +37 -1
  40. package/dist/utils/contact/MappingUtils.js.map +1 -1
  41. package/package.json +4 -4
  42. package/src/__tests__/contact.entities.test.ts +340 -23
  43. package/src/__tests__/contact.store.test.ts +629 -10
  44. package/src/contact/AbstractContactStore.ts +38 -16
  45. package/src/contact/ContactStore.ts +278 -58
  46. package/src/entities/contact/ElectronicAddressEntity.ts +3 -0
  47. package/src/entities/contact/IdentityEntity.ts +1 -1
  48. package/src/entities/contact/PartyEntity.ts +11 -1
  49. package/src/entities/contact/PhysicalAddressEntity.ts +87 -0
  50. package/src/index.ts +3 -0
  51. package/src/issuanceBranding/IssuanceBrandingStore.ts +83 -69
  52. package/src/migrations/sqlite/1690925872693-CreateContacts.ts +3 -8
  53. package/src/types/contact/IAbstractContactStore.ts +58 -8
  54. package/src/types/contact/contact.ts +40 -4
  55. package/src/utils/contact/MappingUtils.ts +39 -0
@@ -0,0 +1,87 @@
1
+ import { IsNotEmpty, validate, ValidationError } from 'class-validator'
2
+ import {
3
+ BaseEntity,
4
+ BeforeInsert,
5
+ BeforeUpdate,
6
+ Column,
7
+ CreateDateColumn,
8
+ Entity,
9
+ ManyToOne,
10
+ PrimaryGeneratedColumn,
11
+ UpdateDateColumn,
12
+ } from 'typeorm'
13
+ import { getConstraint } from '../../utils/ValidatorUtils'
14
+ import { PhysicalAddressType, ValidationConstraint } from '../../types'
15
+ import { PartyEntity } from './PartyEntity'
16
+
17
+ @Entity('PhysicalAddress')
18
+ export class PhysicalAddressEntity extends BaseEntity {
19
+ @PrimaryGeneratedColumn('uuid')
20
+ id!: string
21
+
22
+ @Column({ name: 'type', length: 255, nullable: false })
23
+ @IsNotEmpty({ message: 'Blank physical address types are not allowed' })
24
+ type!: PhysicalAddressType
25
+
26
+ @Column({ name: 'street_name', length: 255, nullable: false })
27
+ @IsNotEmpty({ message: 'Blank street names are not allowed' })
28
+ streetName!: string
29
+
30
+ @Column({ name: 'street_number', length: 255, nullable: false })
31
+ @IsNotEmpty({ message: 'Blank street numbers are not allowed' })
32
+ streetNumber!: string
33
+
34
+ @Column({ name: 'postal_code', length: 255, nullable: false })
35
+ @IsNotEmpty({ message: 'Blank postal codes are not allowed' })
36
+ postalCode!: string
37
+
38
+ @Column({ name: 'city_name', length: 255, nullable: false })
39
+ @IsNotEmpty({ message: 'Blank city names are not allowed' })
40
+ cityName!: string
41
+
42
+ @Column({ name: 'province_name', length: 255, nullable: false })
43
+ @IsNotEmpty({ message: 'Blank province names are not allowed' })
44
+ provinceName!: string
45
+
46
+ @Column({ name: 'country_code', length: 2, nullable: false })
47
+ @IsNotEmpty({ message: 'Blank country codes are not allowed' })
48
+ countryCode!: string
49
+
50
+ @Column({ name: 'building_name', length: 255, nullable: true })
51
+ @IsNotEmpty({ message: 'Blank building names are not allowed' })
52
+ buildingName?: string
53
+
54
+ @ManyToOne(() => PartyEntity, (party: PartyEntity) => party.physicalAddresses, {
55
+ onDelete: 'CASCADE',
56
+ })
57
+ party!: PartyEntity
58
+
59
+ @Column({ name: 'partyId', nullable: true })
60
+ partyId?: string
61
+
62
+ @CreateDateColumn({ name: 'created_at', nullable: false })
63
+ createdAt!: Date
64
+
65
+ @UpdateDateColumn({ name: 'last_updated_at', nullable: false })
66
+ lastUpdatedAt!: Date
67
+
68
+ // By default, @UpdateDateColumn in TypeORM updates the timestamp only when the entity's top-level properties change.
69
+ @BeforeInsert()
70
+ @BeforeUpdate()
71
+ updateUpdatedDate(): void {
72
+ this.lastUpdatedAt = new Date()
73
+ }
74
+
75
+ @BeforeInsert()
76
+ @BeforeUpdate()
77
+ async validate(): Promise<void> {
78
+ const validation: Array<ValidationError> = await validate(this)
79
+ if (validation.length > 0) {
80
+ const constraint: ValidationConstraint | undefined = getConstraint(validation[0])
81
+ if (constraint) {
82
+ const message: string = Object.values(constraint!)[0]
83
+ return Promise.reject(Error(message))
84
+ }
85
+ }
86
+ }
87
+ }
package/src/index.ts CHANGED
@@ -24,6 +24,7 @@ import { PartyTypeEntity } from './entities/contact/PartyTypeEntity'
24
24
  import { OrganizationEntity } from './entities/contact/OrganizationEntity'
25
25
  import { NaturalPersonEntity } from './entities/contact/NaturalPersonEntity'
26
26
  import { ElectronicAddressEntity } from './entities/contact/ElectronicAddressEntity'
27
+ import { PhysicalAddressEntity } from './entities/contact/PhysicalAddressEntity'
27
28
  export { ContactStore } from './contact/ContactStore'
28
29
  export { AbstractContactStore } from './contact/AbstractContactStore'
29
30
  export { AbstractIssuanceBrandingStore } from './issuanceBranding/AbstractIssuanceBrandingStore'
@@ -57,6 +58,7 @@ export const DataStoreContactEntities = [
57
58
  OrganizationEntity,
58
59
  NaturalPersonEntity,
59
60
  ElectronicAddressEntity,
61
+ PhysicalAddressEntity,
60
62
  ]
61
63
 
62
64
  export const DataStoreIssuanceBrandingEntities = [
@@ -102,6 +104,7 @@ export {
102
104
  CredentialLocaleBrandingEntity,
103
105
  IssuerLocaleBrandingEntity,
104
106
  ElectronicAddressEntity,
107
+ PhysicalAddressEntity,
105
108
  backgroundAttributesEntityFrom,
106
109
  credentialBrandingEntityFrom,
107
110
  imageAttributesEntityFrom,
@@ -53,16 +53,17 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
53
53
  }
54
54
 
55
55
  public addCredentialBranding = async (args: IAddCredentialBrandingArgs): Promise<ICredentialBranding> => {
56
+ const { localeBranding, vcHash } = args
56
57
  const repository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
57
58
  const result: CredentialBrandingEntity | null = await repository.findOne({
58
- where: [{ vcHash: args.vcHash }],
59
+ where: [{ vcHash }],
59
60
  })
60
61
 
61
62
  if (result) {
62
- return Promise.reject(Error(`Credential branding already present for vc with hash: ${args.vcHash}`))
63
+ return Promise.reject(Error(`Credential branding already present for vc with hash: ${vcHash}`))
63
64
  }
64
65
 
65
- if (await this.hasDuplicateLocales(args.localeBranding)) {
66
+ if (await this.hasDuplicateLocales(localeBranding)) {
66
67
  return Promise.reject(Error(`Credential branding contains duplicate locales`))
67
68
  }
68
69
 
@@ -74,8 +75,9 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
74
75
  }
75
76
 
76
77
  public getCredentialBranding = async (args?: IGetCredentialBrandingArgs): Promise<Array<ICredentialBranding>> => {
77
- if (args?.filter) {
78
- args?.filter.forEach((filter: IPartialCredentialBranding): void => {
78
+ const { filter } = args ?? {}
79
+ if (filter) {
80
+ filter.forEach((filter: IPartialCredentialBranding): void => {
79
81
  if (filter.localeBranding && 'locale' in filter.localeBranding && filter.localeBranding.locale === undefined) {
80
82
  filter.localeBranding.locale = ''
81
83
  }
@@ -84,16 +86,17 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
84
86
 
85
87
  debug('Getting credential branding', args)
86
88
  const result: Array<CredentialBrandingEntity> = await (await this.dbConnection).getRepository(CredentialBrandingEntity).find({
87
- ...(args?.filter && { where: args?.filter }),
89
+ ...(filter && { where: filter }),
88
90
  })
89
91
 
90
92
  return result.map((credentialBranding: CredentialBrandingEntity) => this.credentialBrandingFrom(credentialBranding))
91
93
  }
92
94
 
93
95
  public removeCredentialBranding = async (args: IRemoveCredentialBrandingArgs): Promise<void> => {
96
+ const { filter } = args
94
97
  const repository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
95
98
  const credentialBranding: Array<CredentialBrandingEntity> = await repository.find({
96
- where: args.filter,
99
+ where: filter,
97
100
  })
98
101
 
99
102
  debug('Removing credential locale branding', args)
@@ -105,49 +108,51 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
105
108
  await Promise.all(localeBrandingDeletions)
106
109
 
107
110
  debug('Removing credential branding', args)
108
- const credentialBrandingDeletions: Array<Promise<DeleteResult>> = args.filter.map(
111
+ const credentialBrandingDeletions: Array<Promise<DeleteResult>> = filter.map(
109
112
  async (filter: ICredentialBrandingFilter): Promise<DeleteResult> => await repository.delete(filter)
110
113
  )
111
114
  await Promise.all(credentialBrandingDeletions)
112
115
  }
113
116
 
114
117
  public updateCredentialBranding = async (args: IUpdateCredentialBrandingArgs): Promise<ICredentialBranding> => {
118
+ const { credentialBranding } = args
115
119
  const repository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
116
120
  const credentialBrandingEntity: CredentialBrandingEntity | null = await repository.findOne({
117
- where: { id: args.credentialBranding.id },
121
+ where: { id: credentialBranding.id },
118
122
  })
119
123
 
120
124
  if (!credentialBrandingEntity) {
121
- return Promise.reject(Error(`No credential branding found for id: ${args.credentialBranding.id}`))
125
+ return Promise.reject(Error(`No credential branding found for id: ${credentialBranding.id}`))
122
126
  }
123
127
 
124
- const credentialBranding: Omit<ICredentialBranding, 'createdAt' | 'lastUpdatedAt'> = {
125
- ...args.credentialBranding,
128
+ const branding: Omit<ICredentialBranding, 'createdAt' | 'lastUpdatedAt'> = {
129
+ ...credentialBranding,
126
130
  localeBranding: credentialBrandingEntity.localeBranding,
127
131
  }
128
132
 
129
- debug('Updating credential branding', credentialBranding)
130
- const result: CredentialBrandingEntity = await repository.save(credentialBranding, { transaction: true })
133
+ debug('Updating credential branding', branding)
134
+ const result: CredentialBrandingEntity = await repository.save(branding, { transaction: true })
131
135
 
132
136
  return this.credentialBrandingFrom(result)
133
137
  }
134
138
 
135
139
  public addCredentialLocaleBranding = async (args: IAddCredentialLocaleBrandingArgs): Promise<ICredentialBranding> => {
140
+ const { credentialBrandingId, localeBranding } = args
136
141
  const credentialBrandingRepository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
137
142
  const credentialBranding: CredentialBrandingEntity | null = await credentialBrandingRepository.findOne({
138
- where: { id: args.credentialBrandingId },
143
+ where: { id: credentialBrandingId },
139
144
  })
140
145
 
141
146
  if (!credentialBranding) {
142
- return Promise.reject(Error(`No credential branding found for id: ${args.credentialBrandingId}`))
147
+ return Promise.reject(Error(`No credential branding found for id: ${credentialBrandingId}`))
143
148
  }
144
149
 
145
150
  const locales: Array<CredentialLocaleBrandingEntity> | null = await (await this.dbConnection).getRepository(CredentialLocaleBrandingEntity).find({
146
151
  where: {
147
152
  credentialBranding: {
148
- id: args.credentialBrandingId,
153
+ id: credentialBrandingId,
149
154
  },
150
- locale: In(args.localeBranding.map((localeBranding: IBasicCredentialLocaleBranding) => localeBranding.locale)),
155
+ locale: In(localeBranding.map((localeBranding: IBasicCredentialLocaleBranding) => localeBranding.locale)),
151
156
  },
152
157
  })
153
158
 
@@ -164,7 +169,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
164
169
  const credentialLocaleBrandingRepository: Repository<CredentialLocaleBrandingEntity> = (await this.dbConnection).getRepository(
165
170
  CredentialLocaleBrandingEntity
166
171
  )
167
- const addCredentialLocaleBranding: Array<Promise<void>> = args.localeBranding.map(
172
+ const addCredentialLocaleBranding: Array<Promise<void>> = localeBranding.map(
168
173
  async (localeBranding: IBasicCredentialLocaleBranding): Promise<void> => {
169
174
  const credentialLocaleBrandingEntity: CredentialLocaleBrandingEntity = credentialLocaleBrandingEntityFrom(localeBranding)
170
175
  debug('Adding credential locale branding', credentialLocaleBrandingEntity)
@@ -176,7 +181,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
176
181
  await Promise.all(addCredentialLocaleBranding)
177
182
 
178
183
  const result: CredentialBrandingEntity | null = await credentialBrandingRepository.findOne({
179
- where: { id: args.credentialBrandingId },
184
+ where: { id: credentialBrandingId },
180
185
  })
181
186
 
182
187
  if (!result) {
@@ -187,8 +192,9 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
187
192
  }
188
193
 
189
194
  public getCredentialLocaleBranding = async (args?: IGetCredentialLocaleBrandingArgs): Promise<Array<ICredentialLocaleBranding>> => {
190
- if (args?.filter) {
191
- args?.filter.forEach((filter: ICredentialLocaleBrandingFilter): void => {
195
+ const { filter } = args ?? {}
196
+ if (filter) {
197
+ filter.forEach((filter: ICredentialLocaleBrandingFilter): void => {
192
198
  if ('locale' in filter && filter.locale === undefined) {
193
199
  filter.locale = ''
194
200
  }
@@ -199,7 +205,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
199
205
  const credentialBrandingLocale: Array<CredentialLocaleBrandingEntity> | null = await (await this.dbConnection)
200
206
  .getRepository(CredentialLocaleBrandingEntity)
201
207
  .find({
202
- ...(args?.filter && { where: args?.filter }),
208
+ ...(filter && { where: filter }),
203
209
  })
204
210
 
205
211
  return credentialBrandingLocale
@@ -210,10 +216,11 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
210
216
  }
211
217
 
212
218
  public removeCredentialLocaleBranding = async (args: IRemoveCredentialLocaleBrandingArgs): Promise<void> => {
219
+ const { filter } = args
213
220
  const credentialLocaleBranding: Array<CredentialLocaleBrandingEntity> = await (await this.dbConnection)
214
221
  .getRepository(CredentialLocaleBrandingEntity)
215
222
  .find({
216
- where: args.filter,
223
+ where: filter,
217
224
  })
218
225
 
219
226
  debug('Removing credential locale branding', args)
@@ -224,13 +231,14 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
224
231
  }
225
232
 
226
233
  public updateCredentialLocaleBranding = async (args: IUpdateCredentialLocaleBrandingArgs): Promise<ICredentialLocaleBranding> => {
234
+ const { localeBranding } = args
227
235
  const repository: Repository<CredentialLocaleBrandingEntity> = (await this.dbConnection).getRepository(CredentialLocaleBrandingEntity)
228
236
  const result: CredentialLocaleBrandingEntity | null = await repository.findOne({
229
- where: { id: args.localeBranding.id },
237
+ where: { id: localeBranding.id },
230
238
  })
231
239
 
232
240
  if (!result) {
233
- return Promise.reject(Error(`No credential locale branding found for id: ${args.localeBranding.id}`))
241
+ return Promise.reject(Error(`No credential locale branding found for id: ${localeBranding.id}`))
234
242
  }
235
243
 
236
244
  const locales: Array<CredentialLocaleBrandingEntity> | null = await repository.find({
@@ -238,32 +246,33 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
238
246
  credentialBranding: {
239
247
  id: result.credentialBrandingId,
240
248
  },
241
- id: Not(In([args.localeBranding.id])),
242
- locale: args.localeBranding.locale,
249
+ id: Not(In([localeBranding.id])),
250
+ locale: localeBranding.locale,
243
251
  },
244
252
  })
245
253
 
246
254
  if (locales && locales.length > 0) {
247
- return Promise.reject(Error(`Credential branding: ${result.credentialBrandingId} already contains locale: ${args.localeBranding.locale}`))
255
+ return Promise.reject(Error(`Credential branding: ${result.credentialBrandingId} already contains locale: ${localeBranding.locale}`))
248
256
  }
249
257
 
250
- debug('Updating credential locale branding', args.localeBranding)
251
- const updatedResult: CredentialLocaleBrandingEntity = await repository.save(args.localeBranding, { transaction: true })
258
+ debug('Updating credential locale branding', localeBranding)
259
+ const updatedResult: CredentialLocaleBrandingEntity = await repository.save(localeBranding, { transaction: true })
252
260
 
253
261
  return this.localeBrandingFrom(updatedResult) as ICredentialLocaleBranding
254
262
  }
255
263
 
256
264
  public addIssuerBranding = async (args: IAddIssuerBrandingArgs): Promise<IIssuerBranding> => {
265
+ const { localeBranding, issuerCorrelationId } = args
257
266
  const repository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
258
267
  const result: IssuerBrandingEntity | null = await repository.findOne({
259
- where: [{ issuerCorrelationId: args.issuerCorrelationId }],
268
+ where: [{ issuerCorrelationId }],
260
269
  })
261
270
 
262
271
  if (result) {
263
- return Promise.reject(Error(`Issuer branding already present for issuer with correlation id: ${args.issuerCorrelationId}`))
272
+ return Promise.reject(Error(`Issuer branding already present for issuer with correlation id: ${issuerCorrelationId}`))
264
273
  }
265
274
 
266
- if (await this.hasDuplicateLocales(args.localeBranding)) {
275
+ if (await this.hasDuplicateLocales(localeBranding)) {
267
276
  return Promise.reject(Error(`Issuer branding contains duplicate locales`))
268
277
  }
269
278
 
@@ -275,8 +284,9 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
275
284
  }
276
285
 
277
286
  public getIssuerBranding = async (args?: IGetIssuerBrandingArgs): Promise<Array<IIssuerBranding>> => {
278
- if (args?.filter) {
279
- args?.filter.forEach((filter: IIssuerBrandingFilter): void => {
287
+ const { filter } = args ?? {}
288
+ if (filter) {
289
+ filter.forEach((filter: IIssuerBrandingFilter): void => {
280
290
  if (filter.localeBranding && 'locale' in filter.localeBranding && filter.localeBranding.locale === undefined) {
281
291
  filter.localeBranding.locale = ''
282
292
  }
@@ -285,16 +295,17 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
285
295
 
286
296
  debug('Getting issuer branding', args)
287
297
  const result: Array<IssuerBrandingEntity> = await (await this.dbConnection).getRepository(IssuerBrandingEntity).find({
288
- ...(args?.filter && { where: args?.filter }),
298
+ ...(filter && { where: filter }),
289
299
  })
290
300
 
291
301
  return result.map((issuerBranding: IssuerBrandingEntity) => this.issuerBrandingFrom(issuerBranding))
292
302
  }
293
303
 
294
304
  public removeIssuerBranding = async (args: IRemoveIssuerBrandingArgs): Promise<void> => {
305
+ const { filter } = args
295
306
  const repository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
296
307
  const issuerBranding: Array<IssuerBrandingEntity> = await repository.find({
297
- where: args.filter,
308
+ where: filter,
298
309
  })
299
310
 
300
311
  debug('Removing issuer locale branding', args)
@@ -306,49 +317,51 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
306
317
  await Promise.all(localeBrandingDeletions)
307
318
 
308
319
  debug('Removing issuer branding', args)
309
- const issuerBrandingDeletions: Array<Promise<DeleteResult>> = args.filter.map(
320
+ const issuerBrandingDeletions: Array<Promise<DeleteResult>> = filter.map(
310
321
  async (filter: IIssuerBrandingFilter): Promise<DeleteResult> => await repository.delete(filter)
311
322
  )
312
323
  await Promise.all(issuerBrandingDeletions)
313
324
  }
314
325
 
315
326
  public updateIssuerBranding = async (args: IUpdateIssuerBrandingArgs): Promise<IIssuerBranding> => {
327
+ const { issuerBranding } = args
316
328
  const repository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
317
329
  const issuerBrandingEntity: IssuerBrandingEntity | null = await repository.findOne({
318
- where: { id: args.issuerBranding.id },
330
+ where: { id: issuerBranding.id },
319
331
  })
320
332
 
321
333
  if (!issuerBrandingEntity) {
322
- return Promise.reject(Error(`No issuer branding found for id: ${args.issuerBranding.id}`))
334
+ return Promise.reject(Error(`No issuer branding found for id: ${issuerBranding.id}`))
323
335
  }
324
336
 
325
- const issuerBranding: Omit<IIssuerBranding, 'createdAt' | 'lastUpdatedAt'> = {
326
- ...args.issuerBranding,
337
+ const branding: Omit<IIssuerBranding, 'createdAt' | 'lastUpdatedAt'> = {
338
+ ...issuerBranding,
327
339
  localeBranding: issuerBrandingEntity.localeBranding,
328
340
  }
329
341
 
330
- debug('Updating issuer branding', issuerBranding)
331
- const result: IssuerBrandingEntity = await repository.save(issuerBranding, { transaction: true })
342
+ debug('Updating issuer branding', branding)
343
+ const result: IssuerBrandingEntity = await repository.save(branding, { transaction: true })
332
344
 
333
345
  return this.issuerBrandingFrom(result)
334
346
  }
335
347
 
336
348
  public addIssuerLocaleBranding = async (args: IAddIssuerLocaleBrandingArgs): Promise<IIssuerBranding> => {
349
+ const { localeBranding, issuerBrandingId } = args
337
350
  const issuerBrandingRepository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
338
351
  const issuerBranding: IssuerBrandingEntity | null = await issuerBrandingRepository.findOne({
339
- where: { id: args.issuerBrandingId },
352
+ where: { id: issuerBrandingId },
340
353
  })
341
354
 
342
355
  if (!issuerBranding) {
343
- return Promise.reject(Error(`No issuer branding found for id: ${args.issuerBrandingId}`))
356
+ return Promise.reject(Error(`No issuer branding found for id: ${issuerBrandingId}`))
344
357
  }
345
358
 
346
359
  const locales: Array<IssuerLocaleBrandingEntity> | null = await (await this.dbConnection).getRepository(IssuerLocaleBrandingEntity).find({
347
360
  where: {
348
361
  issuerBranding: {
349
- id: args.issuerBrandingId,
362
+ id: issuerBrandingId,
350
363
  },
351
- locale: In(args.localeBranding.map((localeBranding: IBasicIssuerLocaleBranding) => localeBranding.locale)),
364
+ locale: In(localeBranding.map((localeBranding: IBasicIssuerLocaleBranding) => localeBranding.locale)),
352
365
  },
353
366
  })
354
367
 
@@ -363,19 +376,17 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
363
376
  }
364
377
 
365
378
  const issuerLocaleBrandingRepository: Repository<IssuerLocaleBrandingEntity> = (await this.dbConnection).getRepository(IssuerLocaleBrandingEntity)
366
- const addIssuerLocaleBranding: Array<Promise<void>> = args.localeBranding.map(
367
- async (localeBranding: IBasicIssuerLocaleBranding): Promise<void> => {
368
- const issuerLocaleBrandingEntity: IssuerLocaleBrandingEntity = issuerLocaleBrandingEntityFrom(localeBranding)
369
- debug('Adding issuer locale branding', issuerLocaleBrandingEntity)
370
- issuerLocaleBrandingEntity.issuerBranding = issuerBranding
371
- await issuerLocaleBrandingRepository.save(issuerLocaleBrandingEntity, { transaction: true })
372
- }
373
- )
379
+ const addIssuerLocaleBranding: Array<Promise<void>> = localeBranding.map(async (localeBranding: IBasicIssuerLocaleBranding): Promise<void> => {
380
+ const issuerLocaleBrandingEntity: IssuerLocaleBrandingEntity = issuerLocaleBrandingEntityFrom(localeBranding)
381
+ debug('Adding issuer locale branding', issuerLocaleBrandingEntity)
382
+ issuerLocaleBrandingEntity.issuerBranding = issuerBranding
383
+ await issuerLocaleBrandingRepository.save(issuerLocaleBrandingEntity, { transaction: true })
384
+ })
374
385
 
375
386
  await Promise.all(addIssuerLocaleBranding)
376
387
 
377
388
  const result: IssuerBrandingEntity | null = await issuerBrandingRepository.findOne({
378
- where: { id: args.issuerBrandingId },
389
+ where: { id: issuerBrandingId },
379
390
  })
380
391
 
381
392
  if (!result) {
@@ -386,8 +397,9 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
386
397
  }
387
398
 
388
399
  public getIssuerLocaleBranding = async (args?: IGetIssuerLocaleBrandingArgs): Promise<Array<IIssuerLocaleBranding>> => {
389
- if (args?.filter) {
390
- args?.filter.forEach((filter: IIssuerLocaleBrandingFilter): void => {
400
+ const { filter } = args ?? {}
401
+ if (filter) {
402
+ filter.forEach((filter: IIssuerLocaleBrandingFilter): void => {
391
403
  if ('locale' in filter && filter.locale === undefined) {
392
404
  filter.locale = ''
393
405
  }
@@ -398,7 +410,7 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
398
410
  const issuerLocaleBranding: Array<IssuerLocaleBrandingEntity> | null = await (await this.dbConnection)
399
411
  .getRepository(IssuerLocaleBrandingEntity)
400
412
  .find({
401
- ...(args?.filter && { where: args?.filter }),
413
+ ...(filter && { where: filter }),
402
414
  })
403
415
 
404
416
  return issuerLocaleBranding
@@ -409,8 +421,9 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
409
421
  }
410
422
 
411
423
  public removeIssuerLocaleBranding = async (args: IRemoveIssuerLocaleBrandingArgs): Promise<void> => {
424
+ const { filter } = args
412
425
  const issuerLocaleBranding: Array<IssuerLocaleBrandingEntity> = await (await this.dbConnection).getRepository(IssuerLocaleBrandingEntity).find({
413
- where: args.filter,
426
+ where: filter,
414
427
  })
415
428
 
416
429
  debug('Removing credential locale branding', args)
@@ -421,13 +434,14 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
421
434
  }
422
435
 
423
436
  public updateIssuerLocaleBranding = async (args: IUpdateIssuerLocaleBrandingArgs): Promise<IIssuerLocaleBranding> => {
437
+ const { localeBranding } = args
424
438
  const repository: Repository<IssuerLocaleBrandingEntity> = (await this.dbConnection).getRepository(IssuerLocaleBrandingEntity)
425
439
  const result: IssuerLocaleBrandingEntity | null = await repository.findOne({
426
- where: { id: args.localeBranding.id },
440
+ where: { id: localeBranding.id },
427
441
  })
428
442
 
429
443
  if (!result) {
430
- return Promise.reject(Error(`No issuer locale branding found for id: ${args.localeBranding.id}`))
444
+ return Promise.reject(Error(`No issuer locale branding found for id: ${localeBranding.id}`))
431
445
  }
432
446
 
433
447
  const locales: Array<IssuerLocaleBrandingEntity> | null = await repository.find({
@@ -435,17 +449,17 @@ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
435
449
  issuerBranding: {
436
450
  id: result.issuerBrandingId,
437
451
  },
438
- id: Not(In([args.localeBranding.id])),
439
- locale: args.localeBranding.locale,
452
+ id: Not(In([localeBranding.id])),
453
+ locale: localeBranding.locale,
440
454
  },
441
455
  })
442
456
 
443
457
  if (locales && locales.length > 0) {
444
- return Promise.reject(Error(`Issuer branding: ${result.issuerBrandingId} already contains locale: ${args.localeBranding.locale}`))
458
+ return Promise.reject(Error(`Issuer branding: ${result.issuerBrandingId} already contains locale: ${localeBranding.locale}`))
445
459
  }
446
460
 
447
- debug('Updating issuer locale branding', args.localeBranding)
448
- const updatedResult: IssuerLocaleBrandingEntity = await repository.save(args.localeBranding, { transaction: true })
461
+ debug('Updating issuer locale branding', localeBranding)
462
+ const updatedResult: IssuerLocaleBrandingEntity = await repository.save(localeBranding, { transaction: true })
449
463
 
450
464
  return this.localeBrandingFrom(updatedResult) as IIssuerLocaleBranding
451
465
  }
@@ -60,9 +60,6 @@ export class CreateContacts1690925872693 implements MigrationInterface {
60
60
  `CREATE TABLE "PartyRelationship" ("id" varchar PRIMARY KEY NOT NULL, "left_id" varchar NOT NULL, "right_id" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`
61
61
  )
62
62
  await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationship_left_right" ON "PartyRelationship" ("left_id", "right_id")`)
63
- await queryRunner.query(
64
- `CREATE TABLE "ElectronicAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "electronic_address" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar)`
65
- )
66
63
  await queryRunner.query(
67
64
  `CREATE TABLE "Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL)`
68
65
  )
@@ -99,15 +96,13 @@ export class CreateContacts1690925872693 implements MigrationInterface {
99
96
  await queryRunner.query(`ALTER TABLE "temporary_PartyRelationship" RENAME TO "PartyRelationship"`)
100
97
  await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationship_left_right" ON "PartyRelationship" ("left_id", "right_id")`)
101
98
  await queryRunner.query(
102
- `CREATE TABLE "temporary_ElectronicAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "electronic_address" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "FK_ElectronicAddress_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
99
+ `CREATE TABLE "ElectronicAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "electronic_address" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "FK_ElectronicAddress_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
103
100
  )
104
101
  await queryRunner.query(
105
- `INSERT INTO "temporary_ElectronicAddress"("id", "type", "electronic_address", "created_at", "last_updated_at", "partyId") SELECT "id", "type", "electronic_address", "created_at", "last_updated_at", "partyId" FROM "ElectronicAddress"`
102
+ `CREATE TABLE "PhysicalAddress" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar(255) NOT NULL, "street_name" varchar(255) NOT NULL, "street_number" varchar(255) NOT NULL, "postal_code" varchar(255) NOT NULL, "city_name" varchar(255) NOT NULL, "province_name" varchar(255) NOT NULL, "country_code" varchar(2) NOT NULL, "building_name" varchar(255), "partyId" varchar, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_PhysicalAddressEntity_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`
106
103
  )
107
- await queryRunner.query(`DROP TABLE "ElectronicAddress"`)
108
- await queryRunner.query(`ALTER TABLE "temporary_ElectronicAddress" RENAME TO "ElectronicAddress"`)
109
104
  await queryRunner.query(
110
- `CREATE TABLE "temporary_Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL, CONSTRAINT "FK_Party_party_type_id" FOREIGN KEY ("party_type_id") REFERENCES "PartyType" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`
105
+ `CREATE TABLE "temporary_Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255), "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL, CONSTRAINT "FK_Party_party_type_id" FOREIGN KEY ("party_type_id") REFERENCES "PartyType" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`
111
106
  )
112
107
  await queryRunner.query(
113
108
  `INSERT INTO "temporary_Party"("id", "uri", "created_at", "last_updated_at", "party_type_id") SELECT "id", "uri", "created_at", "last_updated_at", "party_type_id" FROM "Party"`
@@ -1,23 +1,30 @@
1
1
  import {
2
- NonPersistedPartyType,
2
+ ElectronicAddress,
3
+ Identity,
3
4
  NonPersistedContact,
5
+ NonPersistedElectronicAddress,
4
6
  NonPersistedIdentity,
5
- Party,
6
- Identity,
7
- PartialParty,
7
+ NonPersistedPartyType,
8
+ NonPersistedPhysicalAddress,
9
+ PartialElectronicAddress,
8
10
  PartialIdentity,
9
- PartyTypeEnum,
10
- PartyType,
11
- PartyRelationship,
11
+ PartialParty,
12
12
  PartialPartyRelationship,
13
13
  PartialPartyType,
14
- NonPersistedElectronicAddress,
14
+ PartialPhysicalAddress,
15
+ Party,
16
+ PartyRelationship,
17
+ PartyType,
18
+ PartyTypeEnum,
19
+ PhysicalAddress,
15
20
  } from './contact'
16
21
 
17
22
  export type FindPartyArgs = Array<PartialParty>
18
23
  export type FindIdentityArgs = Array<PartialIdentity>
19
24
  export type FindPartyTypeArgs = Array<PartialPartyType>
20
25
  export type FindRelationshipArgs = Array<PartialPartyRelationship>
26
+ export type FindElectronicAddressArgs = Array<PartialElectronicAddress>
27
+ export type FindPhysicalAddressArgs = Array<PartialPhysicalAddress>
21
28
 
22
29
  export type GetPartyArgs = {
23
30
  partyId: string
@@ -33,6 +40,7 @@ export type AddPartyArgs = {
33
40
  contact: NonPersistedContact
34
41
  identities?: Array<NonPersistedIdentity>
35
42
  electronicAddresses?: Array<NonPersistedElectronicAddress>
43
+ physicalAddresses?: Array<NonPersistedPhysicalAddress>
36
44
  }
37
45
 
38
46
  export type UpdatePartyArgs = {
@@ -107,3 +115,45 @@ export type UpdatePartyTypeArgs = {
107
115
  export type RemovePartyTypeArgs = {
108
116
  partyTypeId: string
109
117
  }
118
+
119
+ export type GetElectronicAddressArgs = {
120
+ electronicAddressId: string
121
+ }
122
+
123
+ export type GetElectronicAddressesArgs = {
124
+ filter?: FindElectronicAddressArgs
125
+ }
126
+
127
+ export type AddElectronicAddressArgs = {
128
+ partyId: string
129
+ electronicAddress: NonPersistedElectronicAddress
130
+ }
131
+
132
+ export type UpdateElectronicAddressArgs = {
133
+ electronicAddress: ElectronicAddress
134
+ }
135
+
136
+ export type RemoveElectronicAddressArgs = {
137
+ electronicAddressId: string
138
+ }
139
+
140
+ export type GetPhysicalAddressArgs = {
141
+ physicalAddressId: string
142
+ }
143
+
144
+ export type GetPhysicalAddressesArgs = {
145
+ filter?: FindPhysicalAddressArgs
146
+ }
147
+
148
+ export type AddPhysicalAddressArgs = {
149
+ partyId: string
150
+ physicalAddress: NonPersistedPhysicalAddress
151
+ }
152
+
153
+ export type UpdatePhysicalAddressArgs = {
154
+ physicalAddress: PhysicalAddress
155
+ }
156
+
157
+ export type RemovePhysicalAddressArgs = {
158
+ physicalAddressId: string
159
+ }