@sphereon/ssi-sdk.data-store 0.11.1-next.106

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 (192) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +72 -0
  3. package/dist/contact/AbstractContactStore.d.ts +14 -0
  4. package/dist/contact/AbstractContactStore.d.ts.map +1 -0
  5. package/dist/contact/AbstractContactStore.js +7 -0
  6. package/dist/contact/AbstractContactStore.js.map +1 -0
  7. package/dist/contact/ContactStore.d.ts +29 -0
  8. package/dist/contact/ContactStore.d.ts.map +1 -0
  9. package/dist/contact/ContactStore.js +281 -0
  10. package/dist/contact/ContactStore.js.map +1 -0
  11. package/dist/entities/contact/BaseConfigEntity.d.ts +5 -0
  12. package/dist/entities/contact/BaseConfigEntity.d.ts.map +1 -0
  13. package/dist/entities/contact/BaseConfigEntity.js +26 -0
  14. package/dist/entities/contact/BaseConfigEntity.js.map +1 -0
  15. package/dist/entities/contact/ConnectionEntity.d.ts +12 -0
  16. package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -0
  17. package/dist/entities/contact/ConnectionEntity.js +66 -0
  18. package/dist/entities/contact/ConnectionEntity.js.map +1 -0
  19. package/dist/entities/contact/ContactEntity.d.ts +16 -0
  20. package/dist/entities/contact/ContactEntity.d.ts.map +1 -0
  21. package/dist/entities/contact/ContactEntity.js +105 -0
  22. package/dist/entities/contact/ContactEntity.js.map +1 -0
  23. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +12 -0
  24. package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -0
  25. package/dist/entities/contact/CorrelationIdentifierEntity.js +75 -0
  26. package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -0
  27. package/dist/entities/contact/DidAuthConfigEntity.d.ts +11 -0
  28. package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -0
  29. package/dist/entities/contact/DidAuthConfigEntity.js +49 -0
  30. package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -0
  31. package/dist/entities/contact/IdentityEntity.d.ts +22 -0
  32. package/dist/entities/contact/IdentityEntity.d.ts.map +1 -0
  33. package/dist/entities/contact/IdentityEntity.js +134 -0
  34. package/dist/entities/contact/IdentityEntity.js.map +1 -0
  35. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +12 -0
  36. package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -0
  37. package/dist/entities/contact/IdentityMetadataItemEntity.js +72 -0
  38. package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -0
  39. package/dist/entities/contact/OpenIdConfigEntity.d.ts +15 -0
  40. package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -0
  41. package/dist/entities/contact/OpenIdConfigEntity.js +70 -0
  42. package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -0
  43. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.d.ts +11 -0
  44. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.d.ts.map +1 -0
  45. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.js +74 -0
  46. package/dist/entities/issuanceBranding/BackgroundAttributesEntity.js.map +1 -0
  47. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.d.ts +18 -0
  48. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.d.ts.map +1 -0
  49. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.js +120 -0
  50. package/dist/entities/issuanceBranding/BaseLocaleBrandingEntity.js.map +1 -0
  51. package/dist/entities/issuanceBranding/CredentialBrandingEntity.d.ts +15 -0
  52. package/dist/entities/issuanceBranding/CredentialBrandingEntity.d.ts.map +1 -0
  53. package/dist/entities/issuanceBranding/CredentialBrandingEntity.js +102 -0
  54. package/dist/entities/issuanceBranding/CredentialBrandingEntity.js.map +1 -0
  55. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.d.ts +9 -0
  56. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.d.ts.map +1 -0
  57. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.js +49 -0
  58. package/dist/entities/issuanceBranding/CredentialLocaleBrandingEntity.js.map +1 -0
  59. package/dist/entities/issuanceBranding/ImageAttributesEntity.d.ts +14 -0
  60. package/dist/entities/issuanceBranding/ImageAttributesEntity.d.ts.map +1 -0
  61. package/dist/entities/issuanceBranding/ImageAttributesEntity.js +92 -0
  62. package/dist/entities/issuanceBranding/ImageAttributesEntity.js.map +1 -0
  63. package/dist/entities/issuanceBranding/ImageDimensionsEntity.d.ts +9 -0
  64. package/dist/entities/issuanceBranding/ImageDimensionsEntity.d.ts.map +1 -0
  65. package/dist/entities/issuanceBranding/ImageDimensionsEntity.js +39 -0
  66. package/dist/entities/issuanceBranding/ImageDimensionsEntity.js.map +1 -0
  67. package/dist/entities/issuanceBranding/IssuerBrandingEntity.d.ts +14 -0
  68. package/dist/entities/issuanceBranding/IssuerBrandingEntity.d.ts.map +1 -0
  69. package/dist/entities/issuanceBranding/IssuerBrandingEntity.js +95 -0
  70. package/dist/entities/issuanceBranding/IssuerBrandingEntity.js.map +1 -0
  71. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.d.ts +9 -0
  72. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.d.ts.map +1 -0
  73. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.js +49 -0
  74. package/dist/entities/issuanceBranding/IssuerLocaleBrandingEntity.js.map +1 -0
  75. package/dist/entities/issuanceBranding/TextAttributesEntity.d.ts +9 -0
  76. package/dist/entities/issuanceBranding/TextAttributesEntity.d.ts.map +1 -0
  77. package/dist/entities/issuanceBranding/TextAttributesEntity.js +62 -0
  78. package/dist/entities/issuanceBranding/TextAttributesEntity.js.map +1 -0
  79. package/dist/entities/validators/index.d.ts +7 -0
  80. package/dist/entities/validators/index.d.ts.map +1 -0
  81. package/dist/entities/validators/index.js +27 -0
  82. package/dist/entities/validators/index.js.map +1 -0
  83. package/dist/index.d.ts +27 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +99 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.d.ts +20 -0
  88. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.d.ts.map +1 -0
  89. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.js +7 -0
  90. package/dist/issuanceBranding/AbstractIssuanceBrandingStore.js.map +1 -0
  91. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts +31 -0
  92. package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -0
  93. package/dist/issuanceBranding/IssuanceBrandingStore.js +375 -0
  94. package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -0
  95. package/dist/migrations/generic/1-CreateContacts.d.ts +7 -0
  96. package/dist/migrations/generic/1-CreateContacts.d.ts.map +1 -0
  97. package/dist/migrations/generic/1-CreateContacts.js +72 -0
  98. package/dist/migrations/generic/1-CreateContacts.js.map +1 -0
  99. package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts +7 -0
  100. package/dist/migrations/generic/1-CreateIssuanceBranding.d.ts.map +1 -0
  101. package/dist/migrations/generic/1-CreateIssuanceBranding.js +72 -0
  102. package/dist/migrations/generic/1-CreateIssuanceBranding.js.map +1 -0
  103. package/dist/migrations/generic/index.d.ts +10 -0
  104. package/dist/migrations/generic/index.d.ts.map +1 -0
  105. package/dist/migrations/generic/index.js +14 -0
  106. package/dist/migrations/generic/index.js.map +1 -0
  107. package/dist/migrations/index.d.ts +2 -0
  108. package/dist/migrations/index.d.ts.map +1 -0
  109. package/dist/migrations/index.js +6 -0
  110. package/dist/migrations/index.js.map +1 -0
  111. package/dist/migrations/internal-migrations-ormconfig.d.ts +6 -0
  112. package/dist/migrations/internal-migrations-ormconfig.d.ts.map +1 -0
  113. package/dist/migrations/internal-migrations-ormconfig.js +29 -0
  114. package/dist/migrations/internal-migrations-ormconfig.js.map +1 -0
  115. package/dist/migrations/postgres/1659463079428-CreateContacts.d.ts +7 -0
  116. package/dist/migrations/postgres/1659463079428-CreateContacts.d.ts.map +1 -0
  117. package/dist/migrations/postgres/1659463079428-CreateContacts.js +55 -0
  118. package/dist/migrations/postgres/1659463079428-CreateContacts.js.map +1 -0
  119. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.d.ts +7 -0
  120. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.d.ts.map +1 -0
  121. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js +67 -0
  122. package/dist/migrations/postgres/1685628974232-CreateIssuanceBranding.js.map +1 -0
  123. package/dist/migrations/sqlite/1659463069549-CreateContacts.d.ts +7 -0
  124. package/dist/migrations/sqlite/1659463069549-CreateContacts.d.ts.map +1 -0
  125. package/dist/migrations/sqlite/1659463069549-CreateContacts.js +79 -0
  126. package/dist/migrations/sqlite/1659463069549-CreateContacts.js.map +1 -0
  127. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.d.ts +7 -0
  128. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.d.ts.map +1 -0
  129. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.js +89 -0
  130. package/dist/migrations/sqlite/1685628973231-CreateIssuanceBranding.js.map +1 -0
  131. package/dist/types/contact/IAbstractContactStore.d.ts +41 -0
  132. package/dist/types/contact/IAbstractContactStore.d.ts.map +1 -0
  133. package/dist/types/contact/IAbstractContactStore.js +3 -0
  134. package/dist/types/contact/IAbstractContactStore.js.map +1 -0
  135. package/dist/types/contact/contact.d.ts +91 -0
  136. package/dist/types/contact/contact.d.ts.map +1 -0
  137. package/dist/types/contact/contact.js +21 -0
  138. package/dist/types/contact/contact.js.map +1 -0
  139. package/dist/types/index.d.ts +5 -0
  140. package/dist/types/index.d.ts.map +1 -0
  141. package/dist/types/index.js +21 -0
  142. package/dist/types/index.js.map +1 -0
  143. package/dist/types/issuanceBranding/IAbstractIssuanceBrandingStore.d.ts +59 -0
  144. package/dist/types/issuanceBranding/IAbstractIssuanceBrandingStore.d.ts.map +1 -0
  145. package/dist/types/issuanceBranding/IAbstractIssuanceBrandingStore.js +3 -0
  146. package/dist/types/issuanceBranding/IAbstractIssuanceBrandingStore.js.map +1 -0
  147. package/dist/types/issuanceBranding/issuanceBranding.d.ts +115 -0
  148. package/dist/types/issuanceBranding/issuanceBranding.d.ts.map +1 -0
  149. package/dist/types/issuanceBranding/issuanceBranding.js +3 -0
  150. package/dist/types/issuanceBranding/issuanceBranding.js.map +1 -0
  151. package/package.json +45 -0
  152. package/src/__tests__/contact.entities.test.ts +911 -0
  153. package/src/__tests__/contact.store.test.ts +743 -0
  154. package/src/__tests__/issuanceBranding.entities.test.ts +844 -0
  155. package/src/__tests__/issuanceBranding.store.test.ts +1884 -0
  156. package/src/contact/AbstractContactStore.ts +27 -0
  157. package/src/contact/ContactStore.ts +371 -0
  158. package/src/entities/contact/BaseConfigEntity.ts +8 -0
  159. package/src/entities/contact/ConnectionEntity.ts +48 -0
  160. package/src/entities/contact/ContactEntity.ts +74 -0
  161. package/src/entities/contact/CorrelationIdentifierEntity.ts +41 -0
  162. package/src/entities/contact/DidAuthConfigEntity.ts +31 -0
  163. package/src/entities/contact/IdentityEntity.ts +104 -0
  164. package/src/entities/contact/IdentityMetadataItemEntity.ts +39 -0
  165. package/src/entities/contact/OpenIdConfigEntity.ts +48 -0
  166. package/src/entities/issuanceBranding/BackgroundAttributesEntity.ts +42 -0
  167. package/src/entities/issuanceBranding/BaseLocaleBrandingEntity.ts +86 -0
  168. package/src/entities/issuanceBranding/CredentialBrandingEntity.ts +78 -0
  169. package/src/entities/issuanceBranding/CredentialLocaleBrandingEntity.ts +33 -0
  170. package/src/entities/issuanceBranding/ImageAttributesEntity.ts +57 -0
  171. package/src/entities/issuanceBranding/ImageDimensionsEntity.ts +22 -0
  172. package/src/entities/issuanceBranding/IssuerBrandingEntity.ts +72 -0
  173. package/src/entities/issuanceBranding/IssuerLocaleBrandingEntity.ts +33 -0
  174. package/src/entities/issuanceBranding/TextAttributesEntity.ts +31 -0
  175. package/src/entities/validators/index.ts +16 -0
  176. package/src/index.ts +82 -0
  177. package/src/issuanceBranding/AbstractIssuanceBrandingStore.ts +41 -0
  178. package/src/issuanceBranding/IssuanceBrandingStore.ts +544 -0
  179. package/src/migrations/generic/1-CreateContacts.ts +54 -0
  180. package/src/migrations/generic/1-CreateIssuanceBranding.ts +54 -0
  181. package/src/migrations/generic/index.ts +11 -0
  182. package/src/migrations/index.ts +1 -0
  183. package/src/migrations/internal-migrations-ormconfig.ts +28 -0
  184. package/src/migrations/postgres/1659463079428-CreateContacts.ts +61 -0
  185. package/src/migrations/postgres/1685628974232-CreateIssuanceBranding.ts +83 -0
  186. package/src/migrations/sqlite/1659463069549-CreateContacts.ts +110 -0
  187. package/src/migrations/sqlite/1685628973231-CreateIssuanceBranding.ts +119 -0
  188. package/src/types/contact/IAbstractContactStore.ts +52 -0
  189. package/src/types/contact/contact.ts +101 -0
  190. package/src/types/index.ts +4 -0
  191. package/src/types/issuanceBranding/IAbstractIssuanceBrandingStore.ts +85 -0
  192. package/src/types/issuanceBranding/issuanceBranding.ts +120 -0
package/src/index.ts ADDED
@@ -0,0 +1,82 @@
1
+ import { BaseConfigEntity } from './entities/contact/BaseConfigEntity'
2
+ import { BaseLocaleBrandingEntity } from './entities/issuanceBranding/BaseLocaleBrandingEntity'
3
+ import { ConnectionEntity, connectionEntityFrom } from './entities/contact/ConnectionEntity'
4
+ import { ContactEntity, contactEntityFrom } from './entities/contact/ContactEntity'
5
+ import { CorrelationIdentifierEntity, correlationIdentifierEntityFrom } from './entities/contact/CorrelationIdentifierEntity'
6
+ import { DidAuthConfigEntity, didAuthConfigEntityFrom } from './entities/contact/DidAuthConfigEntity'
7
+ import { IdentityEntity, identityEntityFrom } from './entities/contact/IdentityEntity'
8
+ import { IdentityMetadataItemEntity, metadataItemEntityFrom } from './entities/contact/IdentityMetadataItemEntity'
9
+ import { OpenIdConfigEntity, openIdConfigEntityFrom } from './entities/contact/OpenIdConfigEntity'
10
+ import { BackgroundAttributesEntity, backgroundAttributesEntityFrom } from './entities/issuanceBranding/BackgroundAttributesEntity'
11
+ import { CredentialBrandingEntity, credentialBrandingEntityFrom } from './entities/issuanceBranding/CredentialBrandingEntity'
12
+ import { CredentialLocaleBrandingEntity, credentialLocaleBrandingEntityFrom } from './entities/issuanceBranding/CredentialLocaleBrandingEntity'
13
+ import { ImageAttributesEntity, imageAttributesEntityFrom } from './entities/issuanceBranding/ImageAttributesEntity'
14
+ import { ImageDimensionsEntity, imageDimensionsEntityFrom } from './entities/issuanceBranding/ImageDimensionsEntity'
15
+ import { IssuerLocaleBrandingEntity, issuerLocaleBrandingEntityFrom } from './entities/issuanceBranding/IssuerLocaleBrandingEntity'
16
+ import { IssuerBrandingEntity, issuerBrandingEntityFrom } from './entities/issuanceBranding/IssuerBrandingEntity'
17
+ import { TextAttributesEntity, textAttributesEntityFrom } from './entities/issuanceBranding/TextAttributesEntity'
18
+
19
+ export { ContactStore } from './contact/ContactStore'
20
+ export { AbstractContactStore } from './contact/AbstractContactStore'
21
+ export { AbstractIssuanceBrandingStore } from './issuanceBranding/AbstractIssuanceBrandingStore'
22
+ export { IssuanceBrandingStore } from './issuanceBranding/IssuanceBrandingStore'
23
+ export { DataStoreMigrations } from './migrations'
24
+ export * from './types'
25
+
26
+ export const DataStoreContactEntities = [
27
+ BaseConfigEntity,
28
+ ConnectionEntity,
29
+ ContactEntity,
30
+ IdentityEntity,
31
+ IdentityMetadataItemEntity,
32
+ CorrelationIdentifierEntity,
33
+ DidAuthConfigEntity,
34
+ OpenIdConfigEntity,
35
+ ]
36
+
37
+ export const DataStoreIssuanceBrandingEntities = [
38
+ BackgroundAttributesEntity,
39
+ CredentialBrandingEntity,
40
+ ImageAttributesEntity,
41
+ ImageDimensionsEntity,
42
+ BaseLocaleBrandingEntity,
43
+ IssuerBrandingEntity,
44
+ TextAttributesEntity,
45
+ CredentialLocaleBrandingEntity,
46
+ IssuerLocaleBrandingEntity,
47
+ ]
48
+
49
+ export {
50
+ BaseConfigEntity,
51
+ ConnectionEntity,
52
+ ContactEntity,
53
+ CorrelationIdentifierEntity,
54
+ DidAuthConfigEntity,
55
+ IdentityEntity,
56
+ IdentityMetadataItemEntity,
57
+ OpenIdConfigEntity,
58
+ BackgroundAttributesEntity,
59
+ CredentialBrandingEntity,
60
+ ImageAttributesEntity,
61
+ ImageDimensionsEntity,
62
+ BaseLocaleBrandingEntity,
63
+ IssuerBrandingEntity,
64
+ TextAttributesEntity,
65
+ CredentialLocaleBrandingEntity,
66
+ IssuerLocaleBrandingEntity,
67
+ metadataItemEntityFrom,
68
+ connectionEntityFrom,
69
+ contactEntityFrom,
70
+ correlationIdentifierEntityFrom,
71
+ identityEntityFrom,
72
+ didAuthConfigEntityFrom,
73
+ openIdConfigEntityFrom,
74
+ backgroundAttributesEntityFrom,
75
+ credentialBrandingEntityFrom,
76
+ imageAttributesEntityFrom,
77
+ imageDimensionsEntityFrom,
78
+ issuerBrandingEntityFrom,
79
+ textAttributesEntityFrom,
80
+ issuerLocaleBrandingEntityFrom,
81
+ credentialLocaleBrandingEntityFrom,
82
+ }
@@ -0,0 +1,41 @@
1
+ import {
2
+ IAddCredentialBrandingArgs,
3
+ IAddCredentialLocaleBrandingArgs,
4
+ IAddIssuerBrandingArgs,
5
+ IAddIssuerLocaleBrandingArgs,
6
+ ICredentialBranding,
7
+ ICredentialLocaleBranding,
8
+ IGetCredentialBrandingArgs,
9
+ IGetCredentialLocaleBrandingArgs,
10
+ IGetIssuerBrandingArgs,
11
+ IGetIssuerLocaleBrandingArgs,
12
+ IIssuerBranding,
13
+ IIssuerLocaleBranding,
14
+ IRemoveCredentialBrandingArgs,
15
+ IRemoveCredentialLocaleBrandingArgs,
16
+ IRemoveIssuerBrandingArgs,
17
+ IRemoveIssuerLocaleBrandingArgs,
18
+ IUpdateCredentialBrandingArgs,
19
+ IUpdateCredentialLocaleBrandingArgs,
20
+ IUpdateIssuerBrandingArgs,
21
+ IUpdateIssuerLocaleBrandingArgs,
22
+ } from '../types'
23
+
24
+ export abstract class AbstractIssuanceBrandingStore {
25
+ public abstract addCredentialBranding(args: IAddCredentialBrandingArgs): Promise<ICredentialBranding>
26
+ public abstract getCredentialBranding(args?: IGetCredentialBrandingArgs): Promise<Array<ICredentialBranding>>
27
+ public abstract updateCredentialBranding(args: IUpdateCredentialBrandingArgs): Promise<ICredentialBranding>
28
+ public abstract removeCredentialBranding(args: IRemoveCredentialBrandingArgs): Promise<void>
29
+ public abstract addCredentialLocaleBranding(args: IAddCredentialLocaleBrandingArgs): Promise<ICredentialBranding>
30
+ public abstract getCredentialLocaleBranding(args?: IGetCredentialLocaleBrandingArgs): Promise<Array<ICredentialLocaleBranding>>
31
+ public abstract updateCredentialLocaleBranding(args: IUpdateCredentialLocaleBrandingArgs): Promise<ICredentialLocaleBranding>
32
+ public abstract removeCredentialLocaleBranding(args: IRemoveCredentialLocaleBrandingArgs): Promise<void>
33
+ public abstract addIssuerBranding(args: IAddIssuerBrandingArgs): Promise<IIssuerBranding>
34
+ public abstract getIssuerBranding(args?: IGetIssuerBrandingArgs): Promise<Array<IIssuerBranding>>
35
+ public abstract updateIssuerBranding(args: IUpdateIssuerBrandingArgs): Promise<IIssuerBranding>
36
+ public abstract removeIssuerBranding(args: IRemoveIssuerBrandingArgs): Promise<void>
37
+ public abstract addIssuerLocaleBranding(args: IAddIssuerLocaleBrandingArgs): Promise<IIssuerBranding>
38
+ public abstract getIssuerLocaleBranding(args?: IGetIssuerLocaleBrandingArgs): Promise<Array<IIssuerLocaleBranding>>
39
+ public abstract updateIssuerLocaleBranding(args: IUpdateIssuerLocaleBrandingArgs): Promise<IIssuerLocaleBranding>
40
+ public abstract removeIssuerLocaleBranding(args: IRemoveIssuerLocaleBrandingArgs): Promise<void>
41
+ }
@@ -0,0 +1,544 @@
1
+ import Debug from 'debug'
2
+ import { DataSource, DeleteResult, In, Not, Repository } from 'typeorm'
3
+ import { OrPromise } from '@sphereon/ssi-types'
4
+ import { BackgroundAttributesEntity } from '../entities/issuanceBranding/BackgroundAttributesEntity'
5
+ import { ImageAttributesEntity } from '../entities/issuanceBranding/ImageAttributesEntity'
6
+ import { ImageDimensionsEntity } from '../entities/issuanceBranding/ImageDimensionsEntity'
7
+ import { IssuerBrandingEntity, issuerBrandingEntityFrom } from '../entities/issuanceBranding/IssuerBrandingEntity'
8
+ import { CredentialBrandingEntity, credentialBrandingEntityFrom } from '../entities/issuanceBranding/CredentialBrandingEntity'
9
+ import { CredentialLocaleBrandingEntity, credentialLocaleBrandingEntityFrom } from '../entities/issuanceBranding/CredentialLocaleBrandingEntity'
10
+ import { IssuerLocaleBrandingEntity, issuerLocaleBrandingEntityFrom } from '../entities/issuanceBranding/IssuerLocaleBrandingEntity'
11
+ import { BaseLocaleBrandingEntity } from '../entities/issuanceBranding/BaseLocaleBrandingEntity'
12
+ import { TextAttributesEntity } from '../entities/issuanceBranding/TextAttributesEntity'
13
+ import { AbstractIssuanceBrandingStore } from './AbstractIssuanceBrandingStore'
14
+ import {
15
+ IAddCredentialBrandingArgs,
16
+ IAddCredentialLocaleBrandingArgs,
17
+ IAddIssuerBrandingArgs,
18
+ IAddIssuerLocaleBrandingArgs,
19
+ IBasicCredentialLocaleBranding,
20
+ IBasicIssuerLocaleBranding,
21
+ ICredentialBranding,
22
+ IPartialCredentialBranding,
23
+ ICredentialLocaleBranding,
24
+ ICredentialLocaleBrandingFilter,
25
+ IGetCredentialBrandingArgs,
26
+ IGetCredentialLocaleBrandingArgs,
27
+ IGetIssuerBrandingArgs,
28
+ IGetIssuerLocaleBrandingArgs,
29
+ IIssuerBranding,
30
+ IIssuerBrandingFilter,
31
+ IIssuerLocaleBranding,
32
+ IIssuerLocaleBrandingFilter,
33
+ ILocaleBranding,
34
+ IRemoveCredentialBrandingArgs,
35
+ IRemoveCredentialLocaleBrandingArgs,
36
+ IRemoveIssuerBrandingArgs,
37
+ IRemoveIssuerLocaleBrandingArgs,
38
+ IUpdateCredentialBrandingArgs,
39
+ IUpdateCredentialLocaleBrandingArgs,
40
+ IUpdateIssuerBrandingArgs,
41
+ IUpdateIssuerLocaleBrandingArgs,
42
+ ICredentialBrandingFilter,
43
+ } from '../types'
44
+
45
+ const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:issuance-branding-store')
46
+
47
+ export class IssuanceBrandingStore extends AbstractIssuanceBrandingStore {
48
+ private readonly dbConnection: OrPromise<DataSource>
49
+
50
+ constructor(dbConnection: OrPromise<DataSource>) {
51
+ super()
52
+ this.dbConnection = dbConnection
53
+ }
54
+
55
+ public addCredentialBranding = async (args: IAddCredentialBrandingArgs): Promise<ICredentialBranding> => {
56
+ const repository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
57
+ const result: CredentialBrandingEntity | null = await repository.findOne({
58
+ where: [{ vcHash: args.vcHash }],
59
+ })
60
+
61
+ if (result) {
62
+ return Promise.reject(Error(`Credential branding already present for vc with hash: ${args.vcHash}`))
63
+ }
64
+
65
+ if (await this.hasDuplicateLocales(args.localeBranding)) {
66
+ return Promise.reject(Error(`Credential branding contains duplicate locales`))
67
+ }
68
+
69
+ const credentialBrandingEntity: CredentialBrandingEntity = credentialBrandingEntityFrom(args)
70
+ debug('Adding credential branding', credentialBrandingEntity)
71
+ const createdResult: CredentialBrandingEntity = await repository.save(credentialBrandingEntity)
72
+
73
+ return this.credentialBrandingFrom(createdResult)
74
+ }
75
+
76
+ public getCredentialBranding = async (args?: IGetCredentialBrandingArgs): Promise<Array<ICredentialBranding>> => {
77
+ if (args?.filter) {
78
+ args?.filter.forEach((filter: IPartialCredentialBranding): void => {
79
+ if (filter.localeBranding && 'locale' in filter.localeBranding && filter.localeBranding.locale === undefined) {
80
+ filter.localeBranding.locale = ''
81
+ }
82
+ })
83
+ }
84
+
85
+ debug('Getting credential branding', args)
86
+ const result: Array<CredentialBrandingEntity> = await (await this.dbConnection).getRepository(CredentialBrandingEntity).find({
87
+ ...(args?.filter && { where: args?.filter }),
88
+ })
89
+
90
+ return result.map((credentialBranding: CredentialBrandingEntity) => this.credentialBrandingFrom(credentialBranding))
91
+ }
92
+
93
+ public removeCredentialBranding = async (args: IRemoveCredentialBrandingArgs): Promise<void> => {
94
+ const repository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
95
+ const credentialBranding: Array<CredentialBrandingEntity> = await repository.find({
96
+ where: args.filter,
97
+ })
98
+
99
+ debug('Removing credential locale branding', args)
100
+ const localeBrandingDeletions: Array<Array<Promise<void>>> = credentialBranding.map((credentialBranding: CredentialBrandingEntity) =>
101
+ credentialBranding.localeBranding.map(
102
+ async (localeBranding: CredentialLocaleBrandingEntity): Promise<void> => this.removeLocaleBranding(localeBranding)
103
+ )
104
+ )
105
+ await Promise.all(localeBrandingDeletions)
106
+
107
+ debug('Removing credential branding', args)
108
+ const credentialBrandingDeletions: Array<Promise<DeleteResult>> = args.filter.map(
109
+ async (filter: ICredentialBrandingFilter): Promise<DeleteResult> => await repository.delete(filter)
110
+ )
111
+ await Promise.all(credentialBrandingDeletions)
112
+ }
113
+
114
+ public updateCredentialBranding = async (args: IUpdateCredentialBrandingArgs): Promise<ICredentialBranding> => {
115
+ const repository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
116
+ const credentialBrandingEntity: CredentialBrandingEntity | null = await repository.findOne({
117
+ where: { id: args.credentialBranding.id },
118
+ })
119
+
120
+ if (!credentialBrandingEntity) {
121
+ return Promise.reject(Error(`No credential branding found for id: ${args.credentialBranding.id}`))
122
+ }
123
+
124
+ const credentialBranding: Omit<ICredentialBranding, 'createdAt' | 'lastUpdatedAt'> = {
125
+ ...args.credentialBranding,
126
+ localeBranding: credentialBrandingEntity.localeBranding,
127
+ }
128
+
129
+ debug('Updating credential branding', credentialBranding)
130
+ const result: CredentialBrandingEntity = await repository.save(credentialBranding, { transaction: true })
131
+
132
+ return this.credentialBrandingFrom(result)
133
+ }
134
+
135
+ public addCredentialLocaleBranding = async (args: IAddCredentialLocaleBrandingArgs): Promise<ICredentialBranding> => {
136
+ const credentialBrandingRepository: Repository<CredentialBrandingEntity> = (await this.dbConnection).getRepository(CredentialBrandingEntity)
137
+ const credentialBranding: CredentialBrandingEntity | null = await credentialBrandingRepository.findOne({
138
+ where: { id: args.credentialBrandingId },
139
+ })
140
+
141
+ if (!credentialBranding) {
142
+ return Promise.reject(Error(`No credential branding found for id: ${args.credentialBrandingId}`))
143
+ }
144
+
145
+ const locales: Array<CredentialLocaleBrandingEntity> | null = await (await this.dbConnection).getRepository(CredentialLocaleBrandingEntity).find({
146
+ where: {
147
+ credentialBranding: {
148
+ id: args.credentialBrandingId,
149
+ },
150
+ locale: In(args.localeBranding.map((localeBranding: IBasicCredentialLocaleBranding) => localeBranding.locale)),
151
+ },
152
+ })
153
+
154
+ if (locales && locales.length > 0) {
155
+ return Promise.reject(
156
+ Error(
157
+ `Credential branding already contains locales: ${locales?.map(
158
+ (credentialLocaleBrandingEntity: CredentialLocaleBrandingEntity) => credentialLocaleBrandingEntity.locale
159
+ )}`
160
+ )
161
+ )
162
+ }
163
+
164
+ const credentialLocaleBrandingRepository: Repository<CredentialLocaleBrandingEntity> = (await this.dbConnection).getRepository(
165
+ CredentialLocaleBrandingEntity
166
+ )
167
+ const addCredentialLocaleBranding: Array<Promise<void>> = args.localeBranding.map(
168
+ async (localeBranding: IBasicCredentialLocaleBranding): Promise<void> => {
169
+ const credentialLocaleBrandingEntity: CredentialLocaleBrandingEntity = credentialLocaleBrandingEntityFrom(localeBranding)
170
+ debug('Adding credential locale branding', credentialLocaleBrandingEntity)
171
+ credentialLocaleBrandingEntity.credentialBranding = credentialBranding
172
+ await credentialLocaleBrandingRepository.save(credentialLocaleBrandingEntity, { transaction: true })
173
+ }
174
+ )
175
+
176
+ await Promise.all(addCredentialLocaleBranding)
177
+
178
+ const result: CredentialBrandingEntity | null = await credentialBrandingRepository.findOne({
179
+ where: { id: args.credentialBrandingId },
180
+ })
181
+
182
+ if (!result) {
183
+ return Promise.reject(Error('Unable to get updated credential branding'))
184
+ }
185
+
186
+ return this.credentialBrandingFrom(result)
187
+ }
188
+
189
+ public getCredentialLocaleBranding = async (args?: IGetCredentialLocaleBrandingArgs): Promise<Array<ICredentialLocaleBranding>> => {
190
+ if (args?.filter) {
191
+ args?.filter.forEach((filter: ICredentialLocaleBrandingFilter): void => {
192
+ if ('locale' in filter && filter.locale === undefined) {
193
+ filter.locale = ''
194
+ }
195
+ })
196
+ }
197
+
198
+ debug('Getting credential locale branding', args)
199
+ const credentialBrandingLocale: Array<CredentialLocaleBrandingEntity> | null = await (await this.dbConnection)
200
+ .getRepository(CredentialLocaleBrandingEntity)
201
+ .find({
202
+ ...(args?.filter && { where: args?.filter }),
203
+ })
204
+
205
+ return credentialBrandingLocale
206
+ ? credentialBrandingLocale.map(
207
+ (credentialLocaleBranding: CredentialLocaleBrandingEntity) => this.localeBrandingFrom(credentialLocaleBranding) as ICredentialLocaleBranding
208
+ )
209
+ : []
210
+ }
211
+
212
+ public removeCredentialLocaleBranding = async (args: IRemoveCredentialLocaleBrandingArgs): Promise<void> => {
213
+ const credentialLocaleBranding: Array<CredentialLocaleBrandingEntity> = await (await this.dbConnection)
214
+ .getRepository(CredentialLocaleBrandingEntity)
215
+ .find({
216
+ where: args.filter,
217
+ })
218
+
219
+ debug('Removing credential locale branding', args)
220
+ const localeBrandingDeletions: Array<Promise<void>> = credentialLocaleBranding.map(
221
+ async (localeBranding: CredentialLocaleBrandingEntity): Promise<void> => this.removeLocaleBranding(localeBranding)
222
+ )
223
+ await Promise.all(localeBrandingDeletions)
224
+ }
225
+
226
+ public updateCredentialLocaleBranding = async (args: IUpdateCredentialLocaleBrandingArgs): Promise<ICredentialLocaleBranding> => {
227
+ const repository: Repository<CredentialLocaleBrandingEntity> = (await this.dbConnection).getRepository(CredentialLocaleBrandingEntity)
228
+ const result: CredentialLocaleBrandingEntity | null = await repository.findOne({
229
+ where: { id: args.localeBranding.id },
230
+ })
231
+
232
+ if (!result) {
233
+ return Promise.reject(Error(`No credential locale branding found for id: ${args.localeBranding.id}`))
234
+ }
235
+
236
+ const locales: Array<CredentialLocaleBrandingEntity> | null = await repository.find({
237
+ where: {
238
+ credentialBranding: {
239
+ id: result.credentialBrandingId,
240
+ },
241
+ id: Not(In([args.localeBranding.id])),
242
+ locale: args.localeBranding.locale,
243
+ },
244
+ })
245
+
246
+ if (locales && locales.length > 0) {
247
+ return Promise.reject(Error(`Credential branding: ${result.credentialBrandingId} already contains locale: ${args.localeBranding.locale}`))
248
+ }
249
+
250
+ debug('Updating credential locale branding', args.localeBranding)
251
+ const updatedResult: CredentialLocaleBrandingEntity = await repository.save(args.localeBranding, { transaction: true })
252
+
253
+ return this.localeBrandingFrom(updatedResult) as ICredentialLocaleBranding
254
+ }
255
+
256
+ public addIssuerBranding = async (args: IAddIssuerBrandingArgs): Promise<IIssuerBranding> => {
257
+ const repository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
258
+ const result: IssuerBrandingEntity | null = await repository.findOne({
259
+ where: [{ issuerCorrelationId: args.issuerCorrelationId }],
260
+ })
261
+
262
+ if (result) {
263
+ return Promise.reject(Error(`Issuer branding already present for issuer with correlation id: ${args.issuerCorrelationId}`))
264
+ }
265
+
266
+ if (await this.hasDuplicateLocales(args.localeBranding)) {
267
+ return Promise.reject(Error(`Issuer branding contains duplicate locales`))
268
+ }
269
+
270
+ const issuerBrandingEntity: IssuerBrandingEntity = issuerBrandingEntityFrom(args)
271
+ debug('Adding issuer branding', issuerBrandingEntity)
272
+ const createdResult: IssuerBrandingEntity = await repository.save(issuerBrandingEntity)
273
+
274
+ return this.issuerBrandingFrom(createdResult)
275
+ }
276
+
277
+ public getIssuerBranding = async (args?: IGetIssuerBrandingArgs): Promise<Array<IIssuerBranding>> => {
278
+ if (args?.filter) {
279
+ args?.filter.forEach((filter: IIssuerBrandingFilter): void => {
280
+ if (filter.localeBranding && 'locale' in filter.localeBranding && filter.localeBranding.locale === undefined) {
281
+ filter.localeBranding.locale = ''
282
+ }
283
+ })
284
+ }
285
+
286
+ debug('Getting issuer branding', args)
287
+ const result: Array<IssuerBrandingEntity> = await (await this.dbConnection).getRepository(IssuerBrandingEntity).find({
288
+ ...(args?.filter && { where: args?.filter }),
289
+ })
290
+
291
+ return result.map((issuerBranding: IssuerBrandingEntity) => this.issuerBrandingFrom(issuerBranding))
292
+ }
293
+
294
+ public removeIssuerBranding = async (args: IRemoveIssuerBrandingArgs): Promise<void> => {
295
+ const repository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
296
+ const issuerBranding: Array<IssuerBrandingEntity> = await repository.find({
297
+ where: args.filter,
298
+ })
299
+
300
+ debug('Removing issuer locale branding', args)
301
+ const localeBrandingDeletions: Array<Array<Promise<void>>> = issuerBranding.map((issuerBranding: IssuerBrandingEntity) =>
302
+ issuerBranding.localeBranding.map(
303
+ async (localeBranding: IssuerLocaleBrandingEntity): Promise<void> => this.removeLocaleBranding(localeBranding)
304
+ )
305
+ )
306
+ await Promise.all(localeBrandingDeletions)
307
+
308
+ debug('Removing issuer branding', args)
309
+ const issuerBrandingDeletions: Array<Promise<DeleteResult>> = args.filter.map(
310
+ async (filter: IIssuerBrandingFilter): Promise<DeleteResult> => await repository.delete(filter)
311
+ )
312
+ await Promise.all(issuerBrandingDeletions)
313
+ }
314
+
315
+ public updateIssuerBranding = async (args: IUpdateIssuerBrandingArgs): Promise<IIssuerBranding> => {
316
+ const repository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
317
+ const issuerBrandingEntity: IssuerBrandingEntity | null = await repository.findOne({
318
+ where: { id: args.issuerBranding.id },
319
+ })
320
+
321
+ if (!issuerBrandingEntity) {
322
+ return Promise.reject(Error(`No issuer branding found for id: ${args.issuerBranding.id}`))
323
+ }
324
+
325
+ const issuerBranding: Omit<IIssuerBranding, 'createdAt' | 'lastUpdatedAt'> = {
326
+ ...args.issuerBranding,
327
+ localeBranding: issuerBrandingEntity.localeBranding,
328
+ }
329
+
330
+ debug('Updating issuer branding', issuerBranding)
331
+ const result: IssuerBrandingEntity = await repository.save(issuerBranding, { transaction: true })
332
+
333
+ return this.issuerBrandingFrom(result)
334
+ }
335
+
336
+ public addIssuerLocaleBranding = async (args: IAddIssuerLocaleBrandingArgs): Promise<IIssuerBranding> => {
337
+ const issuerBrandingRepository: Repository<IssuerBrandingEntity> = (await this.dbConnection).getRepository(IssuerBrandingEntity)
338
+ const issuerBranding: IssuerBrandingEntity | null = await issuerBrandingRepository.findOne({
339
+ where: { id: args.issuerBrandingId },
340
+ })
341
+
342
+ if (!issuerBranding) {
343
+ return Promise.reject(Error(`No issuer branding found for id: ${args.issuerBrandingId}`))
344
+ }
345
+
346
+ const locales: Array<IssuerLocaleBrandingEntity> | null = await (await this.dbConnection).getRepository(IssuerLocaleBrandingEntity).find({
347
+ where: {
348
+ issuerBranding: {
349
+ id: args.issuerBrandingId,
350
+ },
351
+ locale: In(args.localeBranding.map((localeBranding: IBasicIssuerLocaleBranding) => localeBranding.locale)),
352
+ },
353
+ })
354
+
355
+ if (locales && locales.length > 0) {
356
+ return Promise.reject(
357
+ Error(
358
+ `Issuer branding already contains locales: ${locales?.map(
359
+ (issuerLocaleBrandingEntity: IssuerLocaleBrandingEntity) => issuerLocaleBrandingEntity.locale
360
+ )}`
361
+ )
362
+ )
363
+ }
364
+
365
+ 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
+ )
374
+
375
+ await Promise.all(addIssuerLocaleBranding)
376
+
377
+ const result: IssuerBrandingEntity | null = await issuerBrandingRepository.findOne({
378
+ where: { id: args.issuerBrandingId },
379
+ })
380
+
381
+ if (!result) {
382
+ return Promise.reject(Error('Unable to get updated issuer branding'))
383
+ }
384
+
385
+ return this.issuerBrandingFrom(result)
386
+ }
387
+
388
+ public getIssuerLocaleBranding = async (args?: IGetIssuerLocaleBrandingArgs): Promise<Array<IIssuerLocaleBranding>> => {
389
+ if (args?.filter) {
390
+ args?.filter.forEach((filter: IIssuerLocaleBrandingFilter): void => {
391
+ if ('locale' in filter && filter.locale === undefined) {
392
+ filter.locale = ''
393
+ }
394
+ })
395
+ }
396
+
397
+ debug('Getting issuer locale branding', args)
398
+ const issuerLocaleBranding: Array<IssuerLocaleBrandingEntity> | null = await (await this.dbConnection)
399
+ .getRepository(IssuerLocaleBrandingEntity)
400
+ .find({
401
+ ...(args?.filter && { where: args?.filter }),
402
+ })
403
+
404
+ return issuerLocaleBranding
405
+ ? issuerLocaleBranding.map(
406
+ (issuerLocaleBranding: IssuerLocaleBrandingEntity) => this.localeBrandingFrom(issuerLocaleBranding) as IIssuerLocaleBranding
407
+ )
408
+ : []
409
+ }
410
+
411
+ public removeIssuerLocaleBranding = async (args: IRemoveIssuerLocaleBrandingArgs): Promise<void> => {
412
+ const issuerLocaleBranding: Array<IssuerLocaleBrandingEntity> = await (await this.dbConnection).getRepository(IssuerLocaleBrandingEntity).find({
413
+ where: args.filter,
414
+ })
415
+
416
+ debug('Removing credential locale branding', args)
417
+ const localeBrandingDeletions: Array<Promise<void>> = issuerLocaleBranding.map(
418
+ async (localeBranding: IssuerLocaleBrandingEntity): Promise<void> => this.removeLocaleBranding(localeBranding)
419
+ )
420
+ await Promise.all(localeBrandingDeletions)
421
+ }
422
+
423
+ public updateIssuerLocaleBranding = async (args: IUpdateIssuerLocaleBrandingArgs): Promise<IIssuerLocaleBranding> => {
424
+ const repository: Repository<IssuerLocaleBrandingEntity> = (await this.dbConnection).getRepository(IssuerLocaleBrandingEntity)
425
+ const result: IssuerLocaleBrandingEntity | null = await repository.findOne({
426
+ where: { id: args.localeBranding.id },
427
+ })
428
+
429
+ if (!result) {
430
+ return Promise.reject(Error(`No issuer locale branding found for id: ${args.localeBranding.id}`))
431
+ }
432
+
433
+ const locales: Array<IssuerLocaleBrandingEntity> | null = await repository.find({
434
+ where: {
435
+ issuerBranding: {
436
+ id: result.issuerBrandingId,
437
+ },
438
+ id: Not(In([args.localeBranding.id])),
439
+ locale: args.localeBranding.locale,
440
+ },
441
+ })
442
+
443
+ if (locales && locales.length > 0) {
444
+ return Promise.reject(Error(`Issuer branding: ${result.issuerBrandingId} already contains locale: ${args.localeBranding.locale}`))
445
+ }
446
+
447
+ debug('Updating issuer locale branding', args.localeBranding)
448
+ const updatedResult: IssuerLocaleBrandingEntity = await repository.save(args.localeBranding, { transaction: true })
449
+
450
+ return this.localeBrandingFrom(updatedResult) as IIssuerLocaleBranding
451
+ }
452
+
453
+ private credentialBrandingFrom = (credentialBranding: CredentialBrandingEntity): ICredentialBranding => {
454
+ const result: ICredentialBranding = {
455
+ ...credentialBranding,
456
+ localeBranding: credentialBranding.localeBranding.map((localeBranding: BaseLocaleBrandingEntity) => this.localeBrandingFrom(localeBranding)),
457
+ }
458
+
459
+ return this.replaceNullWithUndefined(result)
460
+ }
461
+
462
+ private issuerBrandingFrom = (issuerBranding: IssuerBrandingEntity): IIssuerBranding => {
463
+ const result: IIssuerBranding = {
464
+ ...issuerBranding,
465
+ localeBranding: issuerBranding.localeBranding.map((localeBranding: BaseLocaleBrandingEntity) => this.localeBrandingFrom(localeBranding)),
466
+ }
467
+
468
+ return this.replaceNullWithUndefined(result)
469
+ }
470
+
471
+ private localeBrandingFrom = (localeBranding: BaseLocaleBrandingEntity): ILocaleBranding => {
472
+ const result: ILocaleBranding = {
473
+ ...localeBranding,
474
+ locale: localeBranding.locale === '' ? undefined : localeBranding.locale,
475
+ }
476
+
477
+ return this.replaceNullWithUndefined(result)
478
+ }
479
+
480
+ private replaceNullWithUndefined(obj: any): any {
481
+ if (obj === null) {
482
+ return undefined
483
+ }
484
+
485
+ if (typeof obj !== 'object' || obj instanceof Date) {
486
+ return obj
487
+ }
488
+
489
+ if (Array.isArray(obj)) {
490
+ return obj.map((value: any) => this.replaceNullWithUndefined(value))
491
+ }
492
+
493
+ const result: any = {}
494
+ for (const key in obj) {
495
+ if (obj.hasOwnProperty(key)) {
496
+ result[key] = this.replaceNullWithUndefined(obj[key])
497
+ }
498
+ }
499
+ return result
500
+ }
501
+
502
+ private hasDuplicateLocales = async (localeBranding: Array<IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding>): Promise<boolean> => {
503
+ let seen: Set<string | undefined> = new Set()
504
+ return localeBranding.some((localeBranding: IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding): boolean => {
505
+ return seen.size === seen.add(localeBranding.locale).size
506
+ })
507
+ }
508
+
509
+ private removeLocaleBranding = async (localeBranding: BaseLocaleBrandingEntity): Promise<void> => {
510
+ debug('Removing credential locale branding', localeBranding)
511
+ // Delete background image dimensions
512
+ if (localeBranding.background?.image?.dimensions) {
513
+ await (await this.dbConnection).getRepository(ImageDimensionsEntity).delete({ id: localeBranding.background?.image?.dimensions?.id })
514
+ }
515
+
516
+ // Delete background image
517
+ if (localeBranding.background?.image) {
518
+ await (await this.dbConnection).getRepository(ImageAttributesEntity).delete({ id: localeBranding.background?.image?.id })
519
+ }
520
+
521
+ // Delete background
522
+ if (localeBranding.background) {
523
+ await (await this.dbConnection).getRepository(BackgroundAttributesEntity).delete({ id: localeBranding.background?.id })
524
+ }
525
+
526
+ // Delete logo image dimensions
527
+ if (localeBranding.logo?.dimensions) {
528
+ await (await this.dbConnection).getRepository(ImageDimensionsEntity).delete({ id: localeBranding.logo?.dimensions?.id })
529
+ }
530
+
531
+ // Delete logo
532
+ if (localeBranding.logo) {
533
+ await (await this.dbConnection).getRepository(ImageAttributesEntity).delete({ id: localeBranding.logo?.id })
534
+ }
535
+
536
+ // Delete text
537
+ if (localeBranding.text) {
538
+ await (await this.dbConnection).getRepository(TextAttributesEntity).delete({ id: localeBranding.text?.id })
539
+ }
540
+
541
+ // Delete locale branding
542
+ await (await this.dbConnection).getRepository(CredentialLocaleBrandingEntity).delete({ id: localeBranding.id })
543
+ }
544
+ }