@sphereon/ssi-sdk.data-store 0.37.1 → 0.37.2-next.14
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/dist/index.cjs +1544 -502
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -5
- package/dist/index.d.ts +84 -5
- package/dist/index.js +1457 -415
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/credential-design-store.test.ts +419 -0
- package/src/__tests__/credential-design.entities.test.ts +205 -0
- package/src/__tests__/issuanceBranding.entities.test.ts +1 -1
- package/src/__tests__/issuanceBranding.store.test.ts +1 -1
- package/src/credentialDesign/CredentialDesignStore.ts +201 -0
- package/src/entities/credentialDesign/CredentialDesignBrandingEntity.ts +39 -0
- package/src/entities/credentialDesign/FormStepEntity.ts +32 -0
- package/src/entities/credentialDesign/MetaDataKeyEntity.ts +30 -0
- package/src/entities/credentialDesign/MetaDataSetEntity.ts +39 -0
- package/src/entities/credentialDesign/MetaDataValueEntity.ts +30 -0
- package/src/entities/credentialDesign/SchemaDefinitionEntity.ts +36 -0
- package/src/entities/credentialDesign/index.ts +6 -0
- package/src/index.ts +26 -0
- package/src/migrations/generic/18-AddCredentialDesigns.ts +64 -0
- package/src/migrations/generic/index.ts +5 -2
- package/src/migrations/index.ts +1 -0
- package/src/migrations/postgres/1773657426000-AddCredentialDesigns.ts +208 -0
- package/src/migrations/sqlite/1773657426000-AddCredentialDesigns.ts +55 -0
- package/src/utils/credentialDesign/MappingUtils.ts +147 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.data-store",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.2-next.14+b7a013bb",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@sphereon/kmp-mdoc-core": "0.2.0-SNAPSHOT.26",
|
|
30
30
|
"@sphereon/pex": "5.0.0-unstable.28",
|
|
31
|
-
"@sphereon/ssi-sdk-ext.did-utils": "0.37.
|
|
32
|
-
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.37.
|
|
33
|
-
"@sphereon/ssi-sdk.agent-config": "0.37.
|
|
34
|
-
"@sphereon/ssi-sdk.core": "0.37.
|
|
35
|
-
"@sphereon/ssi-sdk.data-store-types": "0.37.
|
|
36
|
-
"@sphereon/ssi-types": "0.37.
|
|
31
|
+
"@sphereon/ssi-sdk-ext.did-utils": "0.37.2-next.14+b7a013bb",
|
|
32
|
+
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.37.2-next.14+b7a013bb",
|
|
33
|
+
"@sphereon/ssi-sdk.agent-config": "0.37.2-next.14+b7a013bb",
|
|
34
|
+
"@sphereon/ssi-sdk.core": "0.37.2-next.14+b7a013bb",
|
|
35
|
+
"@sphereon/ssi-sdk.data-store-types": "0.37.2-next.14+b7a013bb",
|
|
36
|
+
"@sphereon/ssi-types": "0.37.2-next.14+b7a013bb",
|
|
37
37
|
"@veramo/core": "4.2.0",
|
|
38
38
|
"@veramo/data-store": "4.2.0",
|
|
39
39
|
"@veramo/utils": "4.2.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"PostgreSQL",
|
|
68
68
|
"Contact Store"
|
|
69
69
|
],
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "b7a013bb77cba07e43a97bb2fed6d085ece4d65f"
|
|
71
71
|
}
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
+
import {
|
|
3
|
+
AddCredentialDesignArgs,
|
|
4
|
+
CredentialDesign,
|
|
5
|
+
GetCredentialDesignsArgs,
|
|
6
|
+
UpdateCredentialDesignArgs,
|
|
7
|
+
ValueType,
|
|
8
|
+
} from '@sphereon/ssi-sdk.data-store-types'
|
|
9
|
+
import { DataSource } from 'typeorm'
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
11
|
+
import { CredentialDesignStore } from '../credentialDesign/CredentialDesignStore'
|
|
12
|
+
import { DataStoreEntities, DataStoreMigrations } from '../index'
|
|
13
|
+
|
|
14
|
+
describe('Credential Design store tests', (): void => {
|
|
15
|
+
let dbConnection: DataSource
|
|
16
|
+
let store: CredentialDesignStore
|
|
17
|
+
|
|
18
|
+
beforeEach(async (): Promise<void> => {
|
|
19
|
+
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
20
|
+
dbConnection = await new DataSource({
|
|
21
|
+
type: 'sqlite',
|
|
22
|
+
database: ':memory:',
|
|
23
|
+
logging: ['info'],
|
|
24
|
+
migrationsRun: false,
|
|
25
|
+
migrations: DataStoreMigrations,
|
|
26
|
+
synchronize: false,
|
|
27
|
+
entities: DataStoreEntities,
|
|
28
|
+
}).initialize()
|
|
29
|
+
await dbConnection.runMigrations()
|
|
30
|
+
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
31
|
+
store = new CredentialDesignStore(dbConnection)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
afterEach(async (): Promise<void> => {
|
|
35
|
+
await dbConnection.destroy()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should get a credential design by id', async (): Promise<void> => {
|
|
39
|
+
const args: AddCredentialDesignArgs = {
|
|
40
|
+
name: 'GetByIdDesign',
|
|
41
|
+
tenantId: 'tenant-get-by-id',
|
|
42
|
+
design: {
|
|
43
|
+
label: 'GetByIdDesign',
|
|
44
|
+
tenantId: 'tenant-get-by-id',
|
|
45
|
+
metaDataKeys: [
|
|
46
|
+
{
|
|
47
|
+
key: 'credentialType',
|
|
48
|
+
valueType: ValueType.Text,
|
|
49
|
+
metaDataValues: [{ index: 0, textValue: 'VerifiableCredential' }],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
schemaDefinitions: [
|
|
53
|
+
{
|
|
54
|
+
correlationId: 'GetByIdDesign',
|
|
55
|
+
schemaType: 'Data',
|
|
56
|
+
entityType: 'VC',
|
|
57
|
+
schema: JSON.stringify({ type: 'object' }),
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const savedDesign: CredentialDesign = await store.addCredentialDesign(args)
|
|
64
|
+
expect(savedDesign).toBeDefined()
|
|
65
|
+
|
|
66
|
+
const result: CredentialDesign = await store.getCredentialDesign({ credentialDesignId: savedDesign.id })
|
|
67
|
+
|
|
68
|
+
expect(result).toBeDefined()
|
|
69
|
+
expect(result.id).toEqual(savedDesign.id)
|
|
70
|
+
expect(result.label).toEqual('GetByIdDesign')
|
|
71
|
+
expect(result.tenantId).toEqual('tenant-get-by-id')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should throw error when getting credential design with unknown id', async (): Promise<void> => {
|
|
75
|
+
const credentialDesignId = 'unknownCredentialDesignId'
|
|
76
|
+
|
|
77
|
+
await expect(store.getCredentialDesign({ credentialDesignId })).rejects.toThrow(
|
|
78
|
+
`No credential design found for id: ${credentialDesignId}`,
|
|
79
|
+
)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('should get all credential designs', async (): Promise<void> => {
|
|
83
|
+
const design1: AddCredentialDesignArgs = {
|
|
84
|
+
name: 'Design1',
|
|
85
|
+
tenantId: 'tenant-1',
|
|
86
|
+
design: {
|
|
87
|
+
label: 'Design1',
|
|
88
|
+
tenantId: 'tenant-1',
|
|
89
|
+
metaDataKeys: [
|
|
90
|
+
{
|
|
91
|
+
key: 'credentialType',
|
|
92
|
+
valueType: ValueType.Text,
|
|
93
|
+
metaDataValues: [{ index: 0, textValue: 'VerifiableCredential' }],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
schemaDefinitions: [
|
|
97
|
+
{
|
|
98
|
+
correlationId: 'Design1',
|
|
99
|
+
schemaType: 'Data',
|
|
100
|
+
entityType: 'VC',
|
|
101
|
+
schema: JSON.stringify({ type: 'object' }),
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
const savedDesign1: CredentialDesign = await store.addCredentialDesign(design1)
|
|
107
|
+
expect(savedDesign1).toBeDefined()
|
|
108
|
+
|
|
109
|
+
const design2: AddCredentialDesignArgs = {
|
|
110
|
+
name: 'Design2',
|
|
111
|
+
tenantId: 'tenant-2',
|
|
112
|
+
design: {
|
|
113
|
+
label: 'Design2',
|
|
114
|
+
tenantId: 'tenant-2',
|
|
115
|
+
metaDataKeys: [
|
|
116
|
+
{
|
|
117
|
+
key: 'credentialFormat',
|
|
118
|
+
valueType: ValueType.Text,
|
|
119
|
+
metaDataValues: [{ index: 0, textValue: 'sd-jwt' }],
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
schemaDefinitions: [
|
|
123
|
+
{
|
|
124
|
+
correlationId: 'Design2',
|
|
125
|
+
schemaType: 'Data',
|
|
126
|
+
entityType: 'VC',
|
|
127
|
+
schema: JSON.stringify({ type: 'object' }),
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
const savedDesign2: CredentialDesign = await store.addCredentialDesign(design2)
|
|
133
|
+
expect(savedDesign2).toBeDefined()
|
|
134
|
+
|
|
135
|
+
const result: Array<CredentialDesign> = await store.getCredentialDesigns()
|
|
136
|
+
|
|
137
|
+
expect(result).toBeDefined()
|
|
138
|
+
expect(result.length).toEqual(2)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('should get credential designs by filter', async (): Promise<void> => {
|
|
142
|
+
await store.addCredentialDesign({ name: 'FilterDesign1', tenantId: 'tenant-filter' })
|
|
143
|
+
await store.addCredentialDesign({ name: 'FilterDesign2', tenantId: 'tenant-other' })
|
|
144
|
+
|
|
145
|
+
const args: GetCredentialDesignsArgs = {
|
|
146
|
+
filter: {
|
|
147
|
+
tenantId: 'tenant-filter',
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
const result: Array<CredentialDesign> = await store.getCredentialDesigns(args)
|
|
151
|
+
|
|
152
|
+
expect(result.length).toEqual(1)
|
|
153
|
+
expect(result[0].label).toEqual('FilterDesign1')
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('should get whole credential design with all relations by filter', async (): Promise<void> => {
|
|
157
|
+
const args: AddCredentialDesignArgs = {
|
|
158
|
+
name: 'WholeDesign',
|
|
159
|
+
tenantId: 'tenant-whole',
|
|
160
|
+
design: {
|
|
161
|
+
label: 'WholeDesign',
|
|
162
|
+
tenantId: 'tenant-whole',
|
|
163
|
+
metaDataKeys: [
|
|
164
|
+
{
|
|
165
|
+
key: 'credentialType',
|
|
166
|
+
valueType: ValueType.Text,
|
|
167
|
+
metaDataValues: [
|
|
168
|
+
{ index: 0, textValue: 'VerifiableCredential' },
|
|
169
|
+
{ index: 1, textValue: 'WholeDesign' },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
key: 'credentialFormat',
|
|
174
|
+
valueType: ValueType.Text,
|
|
175
|
+
metaDataValues: [{ index: 0, textValue: 'jwt_vc_json' }],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
key: 'advancedSchema',
|
|
179
|
+
valueType: ValueType.Boolean,
|
|
180
|
+
metaDataValues: [{ index: 0, booleanValue: false }],
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
schemaDefinitions: [
|
|
184
|
+
{
|
|
185
|
+
correlationId: 'WholeDesign',
|
|
186
|
+
schemaType: 'Data',
|
|
187
|
+
entityType: 'VC',
|
|
188
|
+
schema: JSON.stringify({ type: 'object', properties: { name: { type: 'string' } } }),
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
correlationId: 'WholeDesign',
|
|
192
|
+
schemaType: 'UI_Form',
|
|
193
|
+
entityType: 'VC',
|
|
194
|
+
schema: JSON.stringify({ type: 'VerticalLayout', elements: [] }),
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
branding: {
|
|
198
|
+
textColor: '#FFFFFF',
|
|
199
|
+
backgroundColor: '#003399',
|
|
200
|
+
logo: {
|
|
201
|
+
uri: 'https://example.com/logo.png',
|
|
202
|
+
mediaType: 'image/png',
|
|
203
|
+
alt: 'Company Logo',
|
|
204
|
+
dimensions: { width: 200, height: 100 },
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
await store.addCredentialDesign(args)
|
|
210
|
+
await store.addCredentialDesign({ name: 'OtherDesign', tenantId: 'tenant-other' })
|
|
211
|
+
|
|
212
|
+
const result: Array<CredentialDesign> = await store.getCredentialDesigns({ filter: { tenantId: 'tenant-whole' } })
|
|
213
|
+
|
|
214
|
+
expect(result.length).toEqual(1)
|
|
215
|
+
expect(result[0].metaDataKeys.length).toEqual(3)
|
|
216
|
+
expect(result[0].schemaDefinitions.length).toEqual(2)
|
|
217
|
+
expect(result[0].branding).toBeDefined()
|
|
218
|
+
expect(result[0].branding!.logo).toBeDefined()
|
|
219
|
+
expect(result[0].branding!.logo!.uri).toEqual('https://example.com/logo.png')
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('should return no credential designs if filter does not match', async (): Promise<void> => {
|
|
223
|
+
await store.addCredentialDesign({ name: 'SomeDesign', tenantId: 'tenant-exists' })
|
|
224
|
+
|
|
225
|
+
const result: Array<CredentialDesign> = await store.getCredentialDesigns({ filter: { tenantId: 'non-existent-tenant' } })
|
|
226
|
+
|
|
227
|
+
expect(result.length).toEqual(0)
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('should add credential design', async (): Promise<void> => {
|
|
231
|
+
const args: AddCredentialDesignArgs = {
|
|
232
|
+
name: 'AddDesign',
|
|
233
|
+
tenantId: 'tenant-add',
|
|
234
|
+
design: {
|
|
235
|
+
label: 'AddDesign',
|
|
236
|
+
tenantId: 'tenant-add',
|
|
237
|
+
metaDataKeys: [
|
|
238
|
+
{
|
|
239
|
+
key: 'credentialType',
|
|
240
|
+
valueType: ValueType.Text,
|
|
241
|
+
metaDataValues: [
|
|
242
|
+
{ index: 0, textValue: 'VerifiableCredential' },
|
|
243
|
+
{ index: 1, textValue: 'AddDesign' },
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
key: 'credentialFormat',
|
|
248
|
+
valueType: ValueType.Text,
|
|
249
|
+
metaDataValues: [{ index: 0, textValue: 'jwt_vc_json' }],
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
schemaDefinitions: [
|
|
253
|
+
{
|
|
254
|
+
correlationId: 'AddDesign',
|
|
255
|
+
schemaType: 'Data',
|
|
256
|
+
entityType: 'VC',
|
|
257
|
+
schema: JSON.stringify({ type: 'object', properties: { name: { type: 'string' } } }),
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
correlationId: 'AddDesign',
|
|
261
|
+
schemaType: 'UI_Form',
|
|
262
|
+
entityType: 'VC',
|
|
263
|
+
schema: JSON.stringify({ type: 'VerticalLayout', elements: [] }),
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
branding: {
|
|
267
|
+
textColor: '#FFFFFF',
|
|
268
|
+
backgroundColor: '#003399',
|
|
269
|
+
logo: {
|
|
270
|
+
uri: 'https://example.com/logo.png',
|
|
271
|
+
mediaType: 'image/png',
|
|
272
|
+
alt: 'Company Logo',
|
|
273
|
+
dimensions: { width: 200, height: 100 },
|
|
274
|
+
},
|
|
275
|
+
backgroundImage: {
|
|
276
|
+
uri: 'https://example.com/bg.jpg',
|
|
277
|
+
mediaType: 'image/jpeg',
|
|
278
|
+
alt: 'Background',
|
|
279
|
+
dimensions: { width: 1920, height: 1080 },
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const result: CredentialDesign = await store.addCredentialDesign(args)
|
|
286
|
+
|
|
287
|
+
expect(result).toBeDefined()
|
|
288
|
+
expect(result.id).toBeDefined()
|
|
289
|
+
expect(result.label).toEqual(args.name)
|
|
290
|
+
expect(result.tenantId).toEqual(args.tenantId)
|
|
291
|
+
expect(result.metaDataKeys.length).toEqual(2)
|
|
292
|
+
expect(result.schemaDefinitions.length).toEqual(2)
|
|
293
|
+
expect(result.branding).toBeDefined()
|
|
294
|
+
expect(result.branding!.textColor).toEqual('#FFFFFF')
|
|
295
|
+
expect(result.branding!.logo).toBeDefined()
|
|
296
|
+
expect(result.branding!.logo!.uri).toEqual('https://example.com/logo.png')
|
|
297
|
+
expect(result.branding!.logo!.dimensions).toBeDefined()
|
|
298
|
+
expect(result.branding!.logo!.dimensions!.width).toEqual(200)
|
|
299
|
+
expect(result.branding!.backgroundImage).toBeDefined()
|
|
300
|
+
expect(result.branding!.backgroundImage!.uri).toEqual('https://example.com/bg.jpg')
|
|
301
|
+
expect(result.branding!.backgroundImage!.dimensions).toBeDefined()
|
|
302
|
+
expect(result.branding!.backgroundImage!.dimensions!.width).toEqual(1920)
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
it('should update credential design by id', async (): Promise<void> => {
|
|
306
|
+
const created: CredentialDesign = await store.addCredentialDesign({
|
|
307
|
+
name: 'OriginalDesign',
|
|
308
|
+
tenantId: 'tenant-original',
|
|
309
|
+
design: {
|
|
310
|
+
label: 'OriginalDesign',
|
|
311
|
+
tenantId: 'tenant-original',
|
|
312
|
+
metaDataKeys: [
|
|
313
|
+
{
|
|
314
|
+
key: 'credentialType',
|
|
315
|
+
valueType: ValueType.Text,
|
|
316
|
+
metaDataValues: [{ index: 0, textValue: 'VerifiableCredential' }],
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
key: 'credentialFormat',
|
|
320
|
+
valueType: ValueType.Text,
|
|
321
|
+
metaDataValues: [{ index: 0, textValue: 'jwt_vc_json' }],
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
schemaDefinitions: [
|
|
325
|
+
{
|
|
326
|
+
correlationId: 'OriginalDesign',
|
|
327
|
+
schemaType: 'Data',
|
|
328
|
+
entityType: 'VC',
|
|
329
|
+
schema: JSON.stringify({ type: 'object' }),
|
|
330
|
+
},
|
|
331
|
+
],
|
|
332
|
+
branding: {
|
|
333
|
+
textColor: '#000000',
|
|
334
|
+
backgroundColor: '#FFFFFF',
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
})
|
|
338
|
+
expect(created).toBeDefined()
|
|
339
|
+
|
|
340
|
+
const updateArgs: UpdateCredentialDesignArgs = {
|
|
341
|
+
credentialDesignId: created.id,
|
|
342
|
+
name: 'UpdatedDesign',
|
|
343
|
+
design: {
|
|
344
|
+
metaDataKeys: [
|
|
345
|
+
{
|
|
346
|
+
key: 'credentialType',
|
|
347
|
+
valueType: ValueType.Text,
|
|
348
|
+
metaDataValues: [
|
|
349
|
+
{ index: 0, textValue: 'VerifiableCredential' },
|
|
350
|
+
{ index: 1, textValue: 'UpdatedDesign' },
|
|
351
|
+
],
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
key: 'credentialFormat',
|
|
355
|
+
valueType: ValueType.Text,
|
|
356
|
+
metaDataValues: [{ index: 0, textValue: 'sd-jwt' }],
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
key: 'vct',
|
|
360
|
+
valueType: ValueType.Text,
|
|
361
|
+
metaDataValues: [{ index: 0, textValue: 'https://example.com/vct' }],
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
},
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
await store.updateCredentialDesign(updateArgs)
|
|
368
|
+
const result: CredentialDesign = await store.getCredentialDesign({ credentialDesignId: created.id })
|
|
369
|
+
|
|
370
|
+
expect(result).toBeDefined()
|
|
371
|
+
expect(result.label).toEqual('UpdatedDesign')
|
|
372
|
+
expect(result.metaDataKeys.length).toEqual(3)
|
|
373
|
+
|
|
374
|
+
const credentialFormatKey = result.metaDataKeys.find((k) => k.key === 'credentialFormat')
|
|
375
|
+
expect(credentialFormatKey).toBeDefined()
|
|
376
|
+
expect(credentialFormatKey!.metaDataValues[0].textValue).toEqual('sd-jwt')
|
|
377
|
+
|
|
378
|
+
const vctKey = result.metaDataKeys.find((k) => k.key === 'vct')
|
|
379
|
+
expect(vctKey).toBeDefined()
|
|
380
|
+
expect(vctKey!.metaDataValues[0].textValue).toEqual('https://example.com/vct')
|
|
381
|
+
|
|
382
|
+
// Branding should remain untouched since we only updated metaDataKeys
|
|
383
|
+
expect(result.branding).toBeDefined()
|
|
384
|
+
expect(result.branding!.textColor).toEqual('#000000')
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
it('should throw error when updating credential design with unknown id', async (): Promise<void> => {
|
|
388
|
+
const credentialDesignId = 'unknownCredentialDesignId'
|
|
389
|
+
|
|
390
|
+
await expect(store.updateCredentialDesign({ credentialDesignId, name: 'ShouldFail' })).rejects.toThrow(
|
|
391
|
+
`No credential design found for id: ${credentialDesignId}`,
|
|
392
|
+
)
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
it('should remove credential design', async (): Promise<void> => {
|
|
396
|
+
const created: CredentialDesign = await store.addCredentialDesign({
|
|
397
|
+
name: 'ToBeRemoved',
|
|
398
|
+
tenantId: 'tenant-remove',
|
|
399
|
+
})
|
|
400
|
+
expect(created).toBeDefined()
|
|
401
|
+
|
|
402
|
+
const beforeRemove: Array<CredentialDesign> = await store.getCredentialDesigns()
|
|
403
|
+
expect(beforeRemove.length).toEqual(1)
|
|
404
|
+
|
|
405
|
+
await store.removeCredentialDesign({ credentialDesignId: created.id })
|
|
406
|
+
|
|
407
|
+
const afterRemove: Array<CredentialDesign> = await store.getCredentialDesigns()
|
|
408
|
+
expect(afterRemove).toBeDefined()
|
|
409
|
+
expect(afterRemove.length).toEqual(0)
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
it('should throw error when removing credential design with unknown id', async (): Promise<void> => {
|
|
413
|
+
const credentialDesignId = 'unknownCredentialDesignId'
|
|
414
|
+
|
|
415
|
+
await expect(store.removeCredentialDesign({ credentialDesignId })).rejects.toThrow(
|
|
416
|
+
`No credential design found for id: ${credentialDesignId}`,
|
|
417
|
+
)
|
|
418
|
+
})
|
|
419
|
+
})
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { DataSources } from '@sphereon/ssi-sdk.agent-config'
|
|
2
|
+
import { NonPersistedCredentialDesign, ValueType } from '@sphereon/ssi-sdk.data-store-types'
|
|
3
|
+
import { DataSource } from 'typeorm'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
5
|
+
import { MetaDataSetEntity, MetaDataKeyEntity, MetaDataValueEntity } from '../entities/credentialDesign'
|
|
6
|
+
import { DataStoreEntities, DataStoreMigrations } from '../index'
|
|
7
|
+
import {
|
|
8
|
+
credentialDesignBrandingEntityFrom,
|
|
9
|
+
credentialDesignFrom,
|
|
10
|
+
metaDataKeyEntityFrom,
|
|
11
|
+
schemaDefinitionEntityFrom,
|
|
12
|
+
} from '../utils/credentialDesign/MappingUtils'
|
|
13
|
+
|
|
14
|
+
describe('Credential Design entities tests', (): void => {
|
|
15
|
+
let dbConnection: DataSource
|
|
16
|
+
|
|
17
|
+
beforeEach(async (): Promise<void> => {
|
|
18
|
+
DataSources.singleInstance().defaultDbType = 'sqlite'
|
|
19
|
+
dbConnection = await new DataSource({
|
|
20
|
+
type: 'sqlite',
|
|
21
|
+
database: ':memory:',
|
|
22
|
+
logging: ['info'],
|
|
23
|
+
migrationsRun: false,
|
|
24
|
+
migrations: DataStoreMigrations,
|
|
25
|
+
synchronize: false,
|
|
26
|
+
entities: DataStoreEntities,
|
|
27
|
+
}).initialize()
|
|
28
|
+
await dbConnection.runMigrations()
|
|
29
|
+
expect(await dbConnection.showMigrations()).toBeFalsy()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
afterEach(async (): Promise<void> => {
|
|
33
|
+
await dbConnection.destroy()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('Should save credential design to database', async (): Promise<void> => {
|
|
37
|
+
const design: NonPersistedCredentialDesign = {
|
|
38
|
+
label: 'TestCredentialDesign',
|
|
39
|
+
tenantId: 'tenant-entity-test',
|
|
40
|
+
metaDataKeys: [
|
|
41
|
+
{
|
|
42
|
+
key: 'credentialType',
|
|
43
|
+
valueType: ValueType.Text,
|
|
44
|
+
metaDataValues: [
|
|
45
|
+
{ index: 0, textValue: 'VerifiableCredential' },
|
|
46
|
+
{ index: 1, textValue: 'TestCredentialDesign' },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
key: 'credentialFormat',
|
|
51
|
+
valueType: ValueType.Text,
|
|
52
|
+
metaDataValues: [{ index: 0, textValue: 'jwt_vc_json' }],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
key: 'advancedSchema',
|
|
56
|
+
valueType: ValueType.Boolean,
|
|
57
|
+
metaDataValues: [{ index: 0, booleanValue: false }],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
schemaDefinitions: [
|
|
61
|
+
{
|
|
62
|
+
correlationId: 'TestCredentialDesign',
|
|
63
|
+
schemaType: 'Data',
|
|
64
|
+
entityType: 'VC',
|
|
65
|
+
schema: JSON.stringify({ type: 'object', properties: { name: { type: 'string' } } }),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
correlationId: 'TestCredentialDesign',
|
|
69
|
+
schemaType: 'UI_Form',
|
|
70
|
+
entityType: 'VC',
|
|
71
|
+
schema: JSON.stringify({ type: 'VerticalLayout', elements: [] }),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
branding: {
|
|
75
|
+
textColor: '#FFFFFF',
|
|
76
|
+
backgroundColor: '#003399',
|
|
77
|
+
logo: {
|
|
78
|
+
uri: 'https://example.com/logo.png',
|
|
79
|
+
mediaType: 'image/png',
|
|
80
|
+
alt: 'Company Logo',
|
|
81
|
+
dimensions: { width: 200, height: 100 },
|
|
82
|
+
},
|
|
83
|
+
backgroundImage: {
|
|
84
|
+
uri: 'https://example.com/bg.jpg',
|
|
85
|
+
mediaType: 'image/jpeg',
|
|
86
|
+
alt: 'Background',
|
|
87
|
+
dimensions: { width: 1920, height: 1080 },
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Build entity graph using mappers
|
|
93
|
+
const metaDataSetEntity = new MetaDataSetEntity()
|
|
94
|
+
metaDataSetEntity.name = design.label
|
|
95
|
+
metaDataSetEntity.tenantId = design.tenantId
|
|
96
|
+
metaDataSetEntity.metaDataKeys = design.metaDataKeys!.map(metaDataKeyEntityFrom)
|
|
97
|
+
metaDataSetEntity.schemaDefinitions = design.schemaDefinitions!.map(schemaDefinitionEntityFrom)
|
|
98
|
+
metaDataSetEntity.credentialDesignBranding = credentialDesignBrandingEntityFrom(design.branding!)
|
|
99
|
+
|
|
100
|
+
// Save to DB
|
|
101
|
+
const savedEntity = await dbConnection.getRepository(MetaDataSetEntity).save(metaDataSetEntity)
|
|
102
|
+
|
|
103
|
+
// Map back to type
|
|
104
|
+
const fromDb = credentialDesignFrom(savedEntity)
|
|
105
|
+
|
|
106
|
+
// ── Root level ──
|
|
107
|
+
expect(fromDb).toBeDefined()
|
|
108
|
+
expect(fromDb.id).toBeDefined()
|
|
109
|
+
expect(fromDb.label).toEqual(design.label)
|
|
110
|
+
expect(fromDb.tenantId).toEqual(design.tenantId)
|
|
111
|
+
|
|
112
|
+
// ── MetaDataKeys ──
|
|
113
|
+
expect(fromDb.metaDataKeys).toBeDefined()
|
|
114
|
+
expect(fromDb.metaDataKeys.length).toEqual(3)
|
|
115
|
+
|
|
116
|
+
const credentialTypeKey = fromDb.metaDataKeys.find((k) => k.key === 'credentialType')
|
|
117
|
+
expect(credentialTypeKey).toBeDefined()
|
|
118
|
+
expect(credentialTypeKey!.id).toBeDefined()
|
|
119
|
+
expect(credentialTypeKey!.valueType).toEqual(ValueType.Text)
|
|
120
|
+
expect(credentialTypeKey!.metaDataValues.length).toEqual(2)
|
|
121
|
+
expect(credentialTypeKey!.metaDataValues[0].id).toBeDefined()
|
|
122
|
+
expect(credentialTypeKey!.metaDataValues[0].index).toEqual(0)
|
|
123
|
+
expect(credentialTypeKey!.metaDataValues[0].textValue).toEqual('VerifiableCredential')
|
|
124
|
+
expect(credentialTypeKey!.metaDataValues[1].index).toEqual(1)
|
|
125
|
+
expect(credentialTypeKey!.metaDataValues[1].textValue).toEqual('TestCredentialDesign')
|
|
126
|
+
|
|
127
|
+
const credentialFormatKey = fromDb.metaDataKeys.find((k) => k.key === 'credentialFormat')
|
|
128
|
+
expect(credentialFormatKey).toBeDefined()
|
|
129
|
+
expect(credentialFormatKey!.valueType).toEqual(ValueType.Text)
|
|
130
|
+
expect(credentialFormatKey!.metaDataValues.length).toEqual(1)
|
|
131
|
+
expect(credentialFormatKey!.metaDataValues[0].textValue).toEqual('jwt_vc_json')
|
|
132
|
+
|
|
133
|
+
const advancedSchemaKey = fromDb.metaDataKeys.find((k) => k.key === 'advancedSchema')
|
|
134
|
+
expect(advancedSchemaKey).toBeDefined()
|
|
135
|
+
expect(advancedSchemaKey!.valueType).toEqual(ValueType.Boolean)
|
|
136
|
+
expect(advancedSchemaKey!.metaDataValues.length).toEqual(1)
|
|
137
|
+
expect(advancedSchemaKey!.metaDataValues[0].booleanValue).toEqual(false)
|
|
138
|
+
|
|
139
|
+
// ── SchemaDefinitions ──
|
|
140
|
+
expect(fromDb.schemaDefinitions).toBeDefined()
|
|
141
|
+
expect(fromDb.schemaDefinitions.length).toEqual(2)
|
|
142
|
+
|
|
143
|
+
const dataSchema = fromDb.schemaDefinitions.find((s) => s.schemaType === 'Data')
|
|
144
|
+
expect(dataSchema).toBeDefined()
|
|
145
|
+
expect(dataSchema!.id).toBeDefined()
|
|
146
|
+
expect(dataSchema!.correlationId).toEqual('TestCredentialDesign')
|
|
147
|
+
expect(dataSchema!.entityType).toEqual('VC')
|
|
148
|
+
expect(dataSchema!.schema).toEqual(design.schemaDefinitions![0].schema)
|
|
149
|
+
|
|
150
|
+
const uiSchema = fromDb.schemaDefinitions.find((s) => s.schemaType === 'UI_Form')
|
|
151
|
+
expect(uiSchema).toBeDefined()
|
|
152
|
+
expect(uiSchema!.id).toBeDefined()
|
|
153
|
+
expect(uiSchema!.correlationId).toEqual('TestCredentialDesign')
|
|
154
|
+
expect(uiSchema!.schema).toEqual(design.schemaDefinitions![1].schema)
|
|
155
|
+
|
|
156
|
+
// ── Branding ──
|
|
157
|
+
expect(fromDb.branding).toBeDefined()
|
|
158
|
+
expect(fromDb.branding!.id).toBeDefined()
|
|
159
|
+
expect(fromDb.branding!.textColor).toEqual('#FFFFFF')
|
|
160
|
+
expect(fromDb.branding!.backgroundColor).toEqual('#003399')
|
|
161
|
+
|
|
162
|
+
// ── Branding > Logo ──
|
|
163
|
+
expect(fromDb.branding!.logo).toBeDefined()
|
|
164
|
+
expect(fromDb.branding!.logo!.id).toBeDefined()
|
|
165
|
+
expect(fromDb.branding!.logo!.uri).toEqual(design.branding!.logo!.uri)
|
|
166
|
+
expect(fromDb.branding!.logo!.mediaType).toEqual(design.branding!.logo!.mediaType)
|
|
167
|
+
expect(fromDb.branding!.logo!.alt).toEqual(design.branding!.logo!.alt)
|
|
168
|
+
expect(fromDb.branding!.logo!.dimensions).toBeDefined()
|
|
169
|
+
expect(fromDb.branding!.logo!.dimensions!.width).toEqual(design.branding!.logo!.dimensions!.width)
|
|
170
|
+
expect(fromDb.branding!.logo!.dimensions!.height).toEqual(design.branding!.logo!.dimensions!.height)
|
|
171
|
+
|
|
172
|
+
// ── Branding > BackgroundImage ──
|
|
173
|
+
expect(fromDb.branding!.backgroundImage).toBeDefined()
|
|
174
|
+
expect(fromDb.branding!.backgroundImage!.id).toBeDefined()
|
|
175
|
+
expect(fromDb.branding!.backgroundImage!.uri).toEqual(design.branding!.backgroundImage!.uri)
|
|
176
|
+
expect(fromDb.branding!.backgroundImage!.mediaType).toEqual(design.branding!.backgroundImage!.mediaType)
|
|
177
|
+
expect(fromDb.branding!.backgroundImage!.alt).toEqual(design.branding!.backgroundImage!.alt)
|
|
178
|
+
expect(fromDb.branding!.backgroundImage!.dimensions).toBeDefined()
|
|
179
|
+
expect(fromDb.branding!.backgroundImage!.dimensions!.width).toEqual(design.branding!.backgroundImage!.dimensions!.width)
|
|
180
|
+
expect(fromDb.branding!.backgroundImage!.dimensions!.height).toEqual(design.branding!.backgroundImage!.dimensions!.height)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('should cascade delete keys and values when removing MetaDataSet', async (): Promise<void> => {
|
|
184
|
+
const metaDataSetEntity = new MetaDataSetEntity()
|
|
185
|
+
metaDataSetEntity.name = 'cascade_test'
|
|
186
|
+
metaDataSetEntity.metaDataKeys = [
|
|
187
|
+
metaDataKeyEntityFrom({
|
|
188
|
+
key: 'testKey',
|
|
189
|
+
valueType: ValueType.Text,
|
|
190
|
+
metaDataValues: [{ index: 0, textValue: 'test_value' }],
|
|
191
|
+
}),
|
|
192
|
+
]
|
|
193
|
+
metaDataSetEntity.schemaDefinitions = []
|
|
194
|
+
|
|
195
|
+
const saved = await dbConnection.getRepository(MetaDataSetEntity).save(metaDataSetEntity)
|
|
196
|
+
expect(saved.metaDataKeys.length).toEqual(1)
|
|
197
|
+
|
|
198
|
+
await dbConnection.getRepository(MetaDataSetEntity).remove(saved)
|
|
199
|
+
|
|
200
|
+
const keys = await dbConnection.getRepository(MetaDataKeyEntity).find()
|
|
201
|
+
const values = await dbConnection.getRepository(MetaDataValueEntity).find()
|
|
202
|
+
expect(keys.length).toEqual(0)
|
|
203
|
+
expect(values.length).toEqual(0)
|
|
204
|
+
})
|
|
205
|
+
})
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
credentialBrandingEntityFrom,
|
|
7
7
|
CredentialLocaleBrandingEntity,
|
|
8
8
|
credentialLocaleBrandingEntityFrom,
|
|
9
|
-
|
|
9
|
+
DataStoreEntitiesWithVeramo,
|
|
10
10
|
IBasicCredentialBranding,
|
|
11
11
|
IBasicCredentialLocaleBranding,
|
|
12
12
|
IBasicIssuerBranding,
|
|
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
|
4
4
|
import {
|
|
5
5
|
BackgroundAttributesEntity,
|
|
6
6
|
CredentialLocaleBrandingEntity,
|
|
7
|
-
|
|
7
|
+
DataStoreEntitiesWithVeramo,
|
|
8
8
|
IAddCredentialLocaleBrandingArgs,
|
|
9
9
|
IAddIssuerLocaleBrandingArgs,
|
|
10
10
|
IBasicCredentialBranding,
|