@sphereon/ssi-sdk.data-store 0.19.1-next.2 → 0.19.1-next.75

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 (110) hide show
  1. package/dist/digitalCredential/AbstractDigitalCredentialStore.d.ts +10 -0
  2. package/dist/digitalCredential/AbstractDigitalCredentialStore.d.ts.map +1 -0
  3. package/dist/digitalCredential/AbstractDigitalCredentialStore.js +7 -0
  4. package/dist/digitalCredential/AbstractDigitalCredentialStore.js.map +1 -0
  5. package/dist/digitalCredential/DigitalCredentialStore.d.ts +15 -0
  6. package/dist/digitalCredential/DigitalCredentialStore.d.ts.map +1 -0
  7. package/dist/digitalCredential/DigitalCredentialStore.js +118 -0
  8. package/dist/digitalCredential/DigitalCredentialStore.js.map +1 -0
  9. package/dist/entities/digitalCredential/DigitalCredentialEntity.d.ts +23 -0
  10. package/dist/entities/digitalCredential/DigitalCredentialEntity.d.ts.map +1 -0
  11. package/dist/entities/digitalCredential/DigitalCredentialEntity.js +93 -0
  12. package/dist/entities/digitalCredential/DigitalCredentialEntity.js.map +1 -0
  13. package/dist/entities/machineState/MachineStateInfoEntity.d.ts +33 -0
  14. package/dist/entities/machineState/MachineStateInfoEntity.d.ts.map +1 -0
  15. package/dist/entities/machineState/MachineStateInfoEntity.js +85 -0
  16. package/dist/entities/machineState/MachineStateInfoEntity.js.map +1 -0
  17. package/dist/index.d.ts +10 -3
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +19 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/machineState/IAbstractMachineStateStore.d.ts +52 -0
  22. package/dist/machineState/IAbstractMachineStateStore.d.ts.map +1 -0
  23. package/dist/machineState/IAbstractMachineStateStore.js +13 -0
  24. package/dist/machineState/IAbstractMachineStateStore.js.map +1 -0
  25. package/dist/machineState/MachineStateStore.d.ts +21 -0
  26. package/dist/machineState/MachineStateStore.d.ts.map +1 -0
  27. package/dist/machineState/MachineStateStore.js +137 -0
  28. package/dist/machineState/MachineStateStore.js.map +1 -0
  29. package/dist/migrations/generic/6-CreateDigitalCredential.d.ts +7 -0
  30. package/dist/migrations/generic/6-CreateDigitalCredential.d.ts.map +1 -0
  31. package/dist/migrations/generic/6-CreateDigitalCredential.js +78 -0
  32. package/dist/migrations/generic/6-CreateDigitalCredential.js.map +1 -0
  33. package/dist/migrations/generic/7-CreateMachineStateStore.d.ts +7 -0
  34. package/dist/migrations/generic/7-CreateMachineStateStore.d.ts.map +1 -0
  35. package/dist/migrations/generic/7-CreateMachineStateStore.js +78 -0
  36. package/dist/migrations/generic/7-CreateMachineStateStore.js.map +1 -0
  37. package/dist/migrations/generic/index.d.ts +4 -0
  38. package/dist/migrations/generic/index.d.ts.map +1 -1
  39. package/dist/migrations/generic/index.js +7 -1
  40. package/dist/migrations/generic/index.js.map +1 -1
  41. package/dist/migrations/index.d.ts +1 -1
  42. package/dist/migrations/index.d.ts.map +1 -1
  43. package/dist/migrations/index.js +3 -1
  44. package/dist/migrations/index.js.map +1 -1
  45. package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.d.ts +7 -0
  46. package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.d.ts.map +1 -0
  47. package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js +59 -0
  48. package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js.map +1 -0
  49. package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.d.ts +7 -0
  50. package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.d.ts.map +1 -0
  51. package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.js +45 -0
  52. package/dist/migrations/postgres/1708797018115-CreateMachineStateStore.js.map +1 -0
  53. package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.d.ts +7 -0
  54. package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.d.ts.map +1 -0
  55. package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js +50 -0
  56. package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js.map +1 -0
  57. package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.d.ts +7 -0
  58. package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.d.ts.map +1 -0
  59. package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.js +44 -0
  60. package/dist/migrations/sqlite/1708796002272-CreateMachineStateStore.js.map +1 -0
  61. package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.d.ts +42 -0
  62. package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.d.ts.map +1 -0
  63. package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.js +3 -0
  64. package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.js.map +1 -0
  65. package/dist/types/digitalCredential/digitalCredential.d.ts +42 -0
  66. package/dist/types/digitalCredential/digitalCredential.d.ts.map +1 -0
  67. package/dist/types/digitalCredential/digitalCredential.js +28 -0
  68. package/dist/types/digitalCredential/digitalCredential.js.map +1 -0
  69. package/dist/types/index.d.ts +1 -0
  70. package/dist/types/index.d.ts.map +1 -1
  71. package/dist/types/index.js +1 -0
  72. package/dist/types/index.js.map +1 -1
  73. package/dist/types/machineState/IAbstractMachineStateStore.d.ts +58 -0
  74. package/dist/types/machineState/IAbstractMachineStateStore.d.ts.map +1 -0
  75. package/dist/types/machineState/IAbstractMachineStateStore.js +3 -0
  76. package/dist/types/machineState/IAbstractMachineStateStore.js.map +1 -0
  77. package/dist/utils/SortingUtils.d.ts +3 -0
  78. package/dist/utils/SortingUtils.d.ts.map +1 -0
  79. package/dist/utils/SortingUtils.js +18 -0
  80. package/dist/utils/SortingUtils.js.map +1 -0
  81. package/dist/utils/digitalCredential/MappingUtils.d.ts +7 -0
  82. package/dist/utils/digitalCredential/MappingUtils.d.ts.map +1 -0
  83. package/dist/utils/digitalCredential/MappingUtils.js +99 -0
  84. package/dist/utils/digitalCredential/MappingUtils.js.map +1 -0
  85. package/package.json +5 -4
  86. package/src/__tests__/digitalCredential.entities.test.ts +254 -0
  87. package/src/__tests__/digitalCredential.store.test.ts +294 -0
  88. package/src/__tests__/machineState.entities.test.ts +51 -0
  89. package/src/__tests__/machineState.store.test.ts +174 -0
  90. package/src/digitalCredential/AbstractDigitalCredentialStore.ts +17 -0
  91. package/src/digitalCredential/DigitalCredentialStore.ts +127 -0
  92. package/src/entities/digitalCredential/DigitalCredentialEntity.ts +64 -0
  93. package/src/entities/machineState/MachineStateInfoEntity.ts +58 -0
  94. package/src/index.ts +18 -0
  95. package/src/machineState/IAbstractMachineStateStore.ts +65 -0
  96. package/src/machineState/MachineStateStore.ts +151 -0
  97. package/src/migrations/generic/6-CreateDigitalCredential.ts +66 -0
  98. package/src/migrations/generic/7-CreateMachineStateStore.ts +66 -0
  99. package/src/migrations/generic/index.ts +6 -0
  100. package/src/migrations/index.ts +2 -0
  101. package/src/migrations/postgres/1708525189001-CreateDigitalCredential.ts +44 -0
  102. package/src/migrations/postgres/1708797018115-CreateMachineStateStore.ts +29 -0
  103. package/src/migrations/sqlite/1708525189002-CreateDigitalCredential.ts +34 -0
  104. package/src/migrations/sqlite/1708796002272-CreateMachineStateStore.ts +28 -0
  105. package/src/types/digitalCredential/IAbstractDigitalCredentialStore.ts +37 -0
  106. package/src/types/digitalCredential/digitalCredential.ts +46 -0
  107. package/src/types/index.ts +1 -0
  108. package/src/types/machineState/IAbstractMachineStateStore.ts +68 -0
  109. package/src/utils/SortingUtils.ts +16 -0
  110. package/src/utils/digitalCredential/MappingUtils.ts +122 -0
@@ -0,0 +1,174 @@
1
+ import { DataSource } from 'typeorm'
2
+ import { DataStoreMachineStateEntities, MachineStateStore, StoreMachineStatesFindActiveArgs, StoreMachineStatePersistArgs } from '../index'
3
+ import { DataStoreMachineStateMigrations } from '../migrations'
4
+
5
+ describe('Machine State store tests', (): void => {
6
+ let dbConnection: DataSource
7
+ let store: MachineStateStore
8
+
9
+ beforeEach(async (): Promise<void> => {
10
+ dbConnection = await new DataSource({
11
+ type: 'sqlite',
12
+ database: ':memory:',
13
+ logging: 'all',
14
+ migrationsRun: false,
15
+ migrations: DataStoreMachineStateMigrations,
16
+ synchronize: false,
17
+ entities: DataStoreMachineStateEntities,
18
+ }).initialize()
19
+ await dbConnection.runMigrations()
20
+ expect(await dbConnection.showMigrations()).toBeFalsy()
21
+ store = new MachineStateStore(dbConnection)
22
+ })
23
+
24
+ afterEach(async (): Promise<void> => {
25
+ await dbConnection.destroy()
26
+ })
27
+
28
+ it('should store machine state info', async (): Promise<void> => {
29
+ const persistArgs: StoreMachineStatePersistArgs = {
30
+ instanceId: 'Onboarding1',
31
+ machineName: 'Onboarding',
32
+ updatedCount: 0,
33
+ latestStateName: 'enterPersonalDetails',
34
+ latestEventType: 'SET_PERSONAL_DATA',
35
+ state: 'test_state',
36
+ expiresAt: new Date(new Date().getDate() + 100000),
37
+ tenantId: 'test_tenant_id',
38
+ }
39
+
40
+ const persistMachineStateResult = await store.persistMachineState(persistArgs)
41
+ expect(persistMachineStateResult).toBeDefined()
42
+ })
43
+
44
+ it('should get all machines with their current state', async (): Promise<void> => {
45
+ const persistArgs: StoreMachineStatePersistArgs = {
46
+ instanceId: 'Onboarding1',
47
+ machineName: 'Onboarding',
48
+ latestStateName: 'enterPersonalDetails',
49
+ latestEventType: 'SET_PERSONAL_DATA',
50
+ updatedCount: 0,
51
+ state: 'test_state',
52
+ expiresAt: new Date(new Date().getDate() + 100000),
53
+ tenantId: 'test_tenant_id',
54
+ }
55
+
56
+ const stateEvent1 = await store.persistMachineState({ ...persistArgs })
57
+ expect(stateEvent1).toBeDefined()
58
+
59
+ const stateEvent2 = await store.persistMachineState({ ...persistArgs, instanceId: 'Onboarding2' })
60
+ expect(stateEvent2).toBeDefined()
61
+
62
+ const result = await store.findMachineStates()
63
+ expect(result).toHaveLength(2)
64
+ })
65
+
66
+ it('should retrieve a machine state', async (): Promise<void> => {
67
+ const expiresAt = new Date()
68
+ expiresAt.setTime(expiresAt.getTime() + 100000)
69
+ const persistArgs: StoreMachineStatePersistArgs = {
70
+ instanceId: 'Onboarding1',
71
+ machineName: 'Onboarding',
72
+ latestStateName: 'enterPersonalDetails',
73
+ latestEventType: 'SET_PERSONAL_DATA',
74
+ state: 'test_state',
75
+ updatedCount: 0,
76
+ expiresAt,
77
+ tenantId: 'test_tenant_id',
78
+ }
79
+
80
+ const machineStatePersisted = await store.persistMachineState(persistArgs)
81
+ expect(machineStatePersisted).toBeDefined()
82
+ const result = await store.findActiveMachineStates({ machineName: persistArgs.machineName, tenantId: persistArgs.tenantId })
83
+ expect(result).toBeDefined()
84
+ })
85
+
86
+ it('should delete a machine state', async (): Promise<void> => {
87
+ const persistArgs: StoreMachineStatePersistArgs = {
88
+ instanceId: 'Onboarding1',
89
+ machineName: 'Onboarding',
90
+ updatedCount: 0,
91
+ latestStateName: 'enterPersonalDetails',
92
+ latestEventType: 'SET_PERSONAL_DATA',
93
+ state: 'test_state',
94
+ expiresAt: new Date(new Date().getDate() + 100000),
95
+ tenantId: 'test_tenant_id',
96
+ }
97
+
98
+ const persistedState = await store.persistMachineState(persistArgs)
99
+ expect(persistedState).toBeDefined()
100
+
101
+ const result: boolean = await store.deleteMachineState({ instanceId: persistedState.instanceId })
102
+ expect(result).toBeTruthy()
103
+ })
104
+
105
+ it('should return an error if type filter does not match', async (): Promise<void> => {
106
+ const args: StoreMachineStatesFindActiveArgs = {
107
+ machineName: 'unknown_machine',
108
+ }
109
+
110
+ await expect(store.findActiveMachineStates(args)).resolves.toEqual([])
111
+ })
112
+
113
+ it('should delete the expired records', async () => {
114
+ const futureExpiresAt = new Date()
115
+ futureExpiresAt.setTime(futureExpiresAt.getTime() + 100000) // Future expiration
116
+
117
+ const pastExpiresAt = new Date()
118
+ pastExpiresAt.setTime(pastExpiresAt.getTime() - 100000) // Past expiration, already expired
119
+
120
+ const oldestXstateEvent: StoreMachineStatePersistArgs = {
121
+ instanceId: 'Onboarding1',
122
+ machineName: 'Onboarding',
123
+ latestStateName: 'enterPersonalDetails',
124
+ latestEventType: 'SET_TOC',
125
+ updatedCount: 0,
126
+ state: 'test_state',
127
+ expiresAt: futureExpiresAt,
128
+ tenantId: 'test_tenant_id',
129
+ }
130
+ const middleXstateEvent: StoreMachineStatePersistArgs = {
131
+ instanceId: 'Onboarding1',
132
+ machineName: 'Onboarding',
133
+ latestStateName: 'TOC',
134
+ latestEventType: 'SET_POLICY2',
135
+ updatedCount: 1,
136
+ state: 'test_state',
137
+ expiresAt: futureExpiresAt,
138
+ tenantId: 'test_tenant_id',
139
+ }
140
+ const newestXstateEvent: StoreMachineStatePersistArgs = {
141
+ instanceId: 'OnboardingExpired',
142
+ machineName: 'Onboarding',
143
+ latestStateName: 'POLICY',
144
+ latestEventType: 'SET_PERSONAL_DATA',
145
+ updatedCount: 0,
146
+ state: 'test_state',
147
+ expiresAt: pastExpiresAt, // This event should be already expired
148
+ tenantId: 'test_tenant_id',
149
+ }
150
+
151
+ await store.persistMachineState(oldestXstateEvent)
152
+ await store.persistMachineState(middleXstateEvent)
153
+ await store.persistMachineState(newestXstateEvent)
154
+
155
+ await expect(store.findActiveMachineStates({ machineName: 'Onboarding' })).resolves.toHaveLength(1)
156
+
157
+ await store.deleteExpiredMachineStates({})
158
+ await expect(store.findActiveMachineStates({ machineName: 'Onboarding' })).resolves.toHaveLength(1)
159
+ await expect(store.findActiveMachineStates({ machineName: 'Onboarding' })).resolves.toMatchObject([
160
+ {
161
+ completedAt: null,
162
+ createdAt: expect.anything(),
163
+ expiresAt: expect.anything(),
164
+ instanceId: 'Onboarding1',
165
+ latestEventType: 'SET_POLICY2',
166
+ latestStateName: 'TOC',
167
+ machineName: 'Onboarding',
168
+ state: 'test_state',
169
+ tenantId: 'test_tenant_id',
170
+ updatedAt: expect.anything(),
171
+ },
172
+ ])
173
+ })
174
+ })
@@ -0,0 +1,17 @@
1
+ import {
2
+ AddCredentialArgs,
3
+ GetCredentialArgs,
4
+ GetCredentialsArgs,
5
+ GetCredentialsResponse,
6
+ RemoveCredentialArgs,
7
+ UpdateCredentialStateArgs,
8
+ } from '../types/digitalCredential/IAbstractDigitalCredentialStore'
9
+ import { DigitalCredentialEntity } from '../entities/digitalCredential/DigitalCredentialEntity'
10
+
11
+ export abstract class AbstractDigitalCredentialStore {
12
+ abstract getCredential(args: GetCredentialArgs): Promise<DigitalCredentialEntity>
13
+ abstract getCredentials(args?: GetCredentialsArgs): Promise<GetCredentialsResponse>
14
+ abstract addCredential(args: AddCredentialArgs): Promise<DigitalCredentialEntity>
15
+ abstract updateCredentialState(args: UpdateCredentialStateArgs): Promise<DigitalCredentialEntity>
16
+ abstract removeCredential(args: RemoveCredentialArgs): Promise<boolean>
17
+ }
@@ -0,0 +1,127 @@
1
+ import { AbstractDigitalCredentialStore } from './AbstractDigitalCredentialStore'
2
+ import {
3
+ AddCredentialArgs,
4
+ GetCredentialArgs,
5
+ GetCredentialsArgs,
6
+ GetCredentialsResponse,
7
+ RemoveCredentialArgs,
8
+ UpdateCredentialStateArgs,
9
+ } from '../types/digitalCredential/IAbstractDigitalCredentialStore'
10
+ import { OrPromise } from '@sphereon/ssi-types'
11
+ import { DataSource, FindOptionsOrder, Repository } from 'typeorm'
12
+ import Debug from 'debug'
13
+ import { DigitalCredentialEntity } from '../entities/digitalCredential/DigitalCredentialEntity'
14
+ import { nonPersistedDigitalCredentialEntityFromAddArgs } from '../utils/digitalCredential/MappingUtils'
15
+ import { FindOptionsWhere } from 'typeorm/find-options/FindOptionsWhere'
16
+ import { CredentialStateType, DigitalCredential, NonPersistedDigitalCredential } from '../types/digitalCredential/digitalCredential'
17
+ import { parseAndValidateOrderOptions } from '../utils/SortingUtils'
18
+
19
+ const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:credential-store')
20
+
21
+ export class DigitalCredentialStore extends AbstractDigitalCredentialStore {
22
+ private readonly dbConnection: OrPromise<DataSource>
23
+
24
+ constructor(dbConnection: OrPromise<DataSource>) {
25
+ super()
26
+ this.dbConnection = dbConnection
27
+ }
28
+
29
+ addCredential = async (args: AddCredentialArgs): Promise<DigitalCredentialEntity> => {
30
+ debug('Adding credential', args)
31
+ const digitalCredentialEntityRepository: Repository<DigitalCredentialEntity> = (await this.dbConnection).getRepository(DigitalCredentialEntity)
32
+ const credentialEntity: NonPersistedDigitalCredential = nonPersistedDigitalCredentialEntityFromAddArgs(args)
33
+ const createdResult: DigitalCredentialEntity = await digitalCredentialEntityRepository.save(credentialEntity)
34
+ return Promise.resolve(createdResult)
35
+ }
36
+
37
+ getCredential = async (args: GetCredentialArgs): Promise<DigitalCredentialEntity> => {
38
+ const result: DigitalCredentialEntity | null = await (await this.dbConnection).getRepository(DigitalCredentialEntity).findOne({
39
+ where: args,
40
+ })
41
+
42
+ if (!result) {
43
+ return Promise.reject(Error(`No credential found for arg: ${args.toString()}`))
44
+ }
45
+ return result
46
+ }
47
+
48
+ getCredentials = async (args?: GetCredentialsArgs): Promise<GetCredentialsResponse> => {
49
+ const { filter = {}, offset, limit, order = 'id.asc' } = args ?? {}
50
+ const sortOptions: FindOptionsOrder<DigitalCredentialEntity> =
51
+ order && typeof order === 'string'
52
+ ? parseAndValidateOrderOptions<DigitalCredentialEntity>(order)
53
+ : <FindOptionsOrder<DigitalCredentialEntity>>order
54
+ const [result, total] = await (await this.dbConnection).getRepository(DigitalCredentialEntity).findAndCount({
55
+ where: filter,
56
+ skip: offset,
57
+ take: limit,
58
+ order: sortOptions,
59
+ })
60
+ return {
61
+ data: result,
62
+ total,
63
+ }
64
+ }
65
+
66
+ removeCredential = async (args: RemoveCredentialArgs): Promise<boolean> => {
67
+ if (!args) {
68
+ return false
69
+ }
70
+
71
+ let query: FindOptionsWhere<DigitalCredentialEntity> = {}
72
+
73
+ if ('id' in args) {
74
+ query.id = args.id
75
+ } else if ('hash' in args) {
76
+ query.hash = args.hash
77
+ } else {
78
+ return false
79
+ }
80
+ try {
81
+ const connection = await this.dbConnection
82
+ const result = await connection.getRepository(DigitalCredentialEntity).delete(query)
83
+ return result.affected === 1
84
+ } catch (error) {
85
+ console.error('Error removing digital credential:', error)
86
+ return false
87
+ }
88
+ }
89
+
90
+ updateCredentialState = async (args: UpdateCredentialStateArgs): Promise<DigitalCredentialEntity> => {
91
+ const credentialRepository: Repository<DigitalCredentialEntity> = (await this.dbConnection).getRepository(DigitalCredentialEntity)
92
+ const whereClause: Record<string, any> = {}
93
+ if ('id' in args) {
94
+ whereClause.id = args.id
95
+ } else if ('hash' in args) {
96
+ whereClause.hash = args.hash
97
+ } else {
98
+ throw new Error('No id or hash param is provided.')
99
+ }
100
+ if (!args.verifiedState) {
101
+ throw new Error('No verifiedState param is provided.')
102
+ }
103
+ if (args.verifiedState === CredentialStateType.REVOKED && !args.revokedAt) {
104
+ throw new Error('No revokedAt param is provided.')
105
+ }
106
+ if (args.verifiedState !== CredentialStateType.REVOKED && !args.verifiedAt) {
107
+ throw new Error('No verifiedAt param is provided.')
108
+ }
109
+ const credential: DigitalCredentialEntity | null = await credentialRepository.findOne({
110
+ where: whereClause,
111
+ })
112
+
113
+ if (!credential) {
114
+ return Promise.reject(Error(`No credential found for args: ${whereClause}`))
115
+ }
116
+ const updatedCredential: DigitalCredential = {
117
+ ...credential,
118
+ ...(args.verifiedState !== CredentialStateType.REVOKED && { verifiedAt: args.verifiedAt }),
119
+ ...(args.verifiedState === CredentialStateType.REVOKED && { revokedAt: args.revokedAt }),
120
+ lastUpdatedAt: new Date(),
121
+ verifiedState: args.verifiedState,
122
+ }
123
+ debug('Updating credential', credential)
124
+ const updatedResult: DigitalCredentialEntity = await credentialRepository.save(updatedCredential, { transaction: true })
125
+ return updatedResult
126
+ }
127
+ }
@@ -0,0 +1,64 @@
1
+ import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
2
+ import {
3
+ CredentialCorrelationType,
4
+ CredentialDocumentFormat,
5
+ CredentialStateType,
6
+ DocumentType,
7
+ } from '../../types/digitalCredential/digitalCredential'
8
+
9
+ @Entity('DigitalCredential')
10
+ export class DigitalCredentialEntity extends BaseEntity {
11
+ @PrimaryGeneratedColumn('uuid')
12
+ id!: string
13
+
14
+ @Column('simple-enum', { name: 'document_type', enum: DocumentType, nullable: false })
15
+ documentType!: DocumentType
16
+
17
+ @Column('simple-enum', { name: 'document_format', enum: CredentialDocumentFormat, nullable: false })
18
+ documentFormat!: CredentialDocumentFormat
19
+
20
+ @Column('text', { name: 'raw_document', nullable: false })
21
+ rawDocument!: string
22
+
23
+ @Column('text', { name: 'uniform_document', nullable: false })
24
+ uniformDocument!: string
25
+
26
+ @Column('text', { name: 'hash', nullable: false, unique: true })
27
+ hash!: string
28
+
29
+ @Column('simple-enum', { name: 'issuer_correlation_type', enum: CredentialCorrelationType, nullable: false })
30
+ issuerCorrelationType!: CredentialCorrelationType
31
+
32
+ @Column('simple-enum', { name: 'subject_correlation_type', enum: CredentialCorrelationType, nullable: true })
33
+ subjectCorrelationType?: CredentialCorrelationType
34
+
35
+ @Column('text', { name: 'issuer_correlation_id', nullable: false })
36
+ issuerCorrelationId!: string
37
+
38
+ @Column('text', { name: 'subject_correlation_id', nullable: true })
39
+ subjectCorrelationId?: string
40
+
41
+ @Column('simple-enum', { name: 'verified_state', enum: CredentialStateType, nullable: true })
42
+ verifiedState?: CredentialStateType
43
+
44
+ @Column('text', { name: 'tenant_id', nullable: true })
45
+ tenantId?: string
46
+
47
+ @CreateDateColumn({ name: 'created_at', nullable: false })
48
+ createdAt!: Date
49
+
50
+ @UpdateDateColumn({ name: 'last_updated_at', nullable: false })
51
+ lastUpdatedAt!: Date
52
+
53
+ @Column('date', { name: 'valid_until', nullable: true })
54
+ validUntil?: Date
55
+
56
+ @Column('date', { name: 'valid_from', nullable: true })
57
+ validFrom?: Date
58
+
59
+ @Column('date', { name: 'verified_at', nullable: true })
60
+ verifiedAt?: Date
61
+
62
+ @Column('date', { name: 'revoked_at', nullable: true })
63
+ revokedAt?: Date
64
+ }
@@ -0,0 +1,58 @@
1
+ import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryColumn, UpdateDateColumn } from 'typeorm'
2
+
3
+ /**
4
+ * @class MachineStateInfoEntity
5
+ * Represents a machine state. It allows to continue a machine at a later point in time at the point it was left of
6
+ *
7
+ * @param {string} instanceId - The instance ID of the machine state.
8
+ * @param {string} [sessionId] - The session ID of the machine state. (optional)
9
+ * @param {string} machineName - The name of the machine.
10
+ * @param {string} [latestStateName] - The name of the latest state. (optional)
11
+ * @param {string} latestEventType - The type of the latest event.
12
+ * @param {string} state - The current state of the machine.
13
+ * @param {Date} createdAt - The date and time when the machine state was created.
14
+ * @param {Date} updatedAt - The date and time when the machine state was last updated.
15
+ * @param {number} updatedCount - The number of times the machine state has been updated.
16
+ * @param {Date} [expiresAt] - The date and time when the machine state expires. (optional)
17
+ * @param {Date} [completedAt] - The date and time when the machine state was completed. (optional)
18
+ * @param {string} [tenantId] - The ID of the tenant associated with the machine state. (optional)
19
+ */
20
+ @Entity('MachineStateInfoEntity')
21
+ export class MachineStateInfoEntity extends BaseEntity {
22
+ @PrimaryColumn({ name: 'instance_id', type: 'varchar', nullable: false })
23
+ instanceId!: string
24
+
25
+ @Column({ name: 'session_id', type: 'varchar', nullable: true })
26
+ sessionId?: string
27
+
28
+ // Xstate moved to name instead of instanceId for V5. Also makes more sense
29
+ @Column({ name: 'machine_name', type: 'varchar', nullable: false })
30
+ machineName!: string
31
+
32
+ @Column({ name: 'latest_state_name', type: 'varchar', nullable: true })
33
+ latestStateName?: string
34
+
35
+ @Column({ name: 'latest_event_type', type: 'varchar', nullable: false })
36
+ latestEventType!: string
37
+
38
+ @Column({ name: 'state', type: 'text', nullable: false })
39
+ state!: string
40
+
41
+ @CreateDateColumn({ name: 'created_at', type: 'datetime', nullable: false })
42
+ createdAt!: Date
43
+
44
+ @UpdateDateColumn({ name: 'updated_at', type: 'datetime', nullable: false })
45
+ updatedAt!: Date
46
+
47
+ @Column({ name: 'updated_count', type: 'integer', nullable: false })
48
+ updatedCount!: number
49
+
50
+ @Column({ name: 'expires_at', type: 'datetime', nullable: true })
51
+ expiresAt?: Date
52
+
53
+ @Column({ name: 'completed_at', type: 'datetime', nullable: true })
54
+ completedAt?: Date
55
+
56
+ @Column({ name: 'tenant_id', type: 'varchar', nullable: true })
57
+ tenantId?: string
58
+ }
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ import { IssuerBrandingEntity, issuerBrandingEntityFrom } from './entities/issua
18
18
  import { TextAttributesEntity, textAttributesEntityFrom } from './entities/issuanceBranding/TextAttributesEntity'
19
19
  import { StatusListEntity } from './entities/statusList2021/StatusList2021Entity'
20
20
  import { StatusListEntryEntity } from './entities/statusList2021/StatusList2021EntryEntity'
21
+ import { MachineStateInfoEntity } from './entities/machineState/MachineStateInfoEntity'
21
22
  import { IStatusListEntity, IStatusListEntryEntity } from './types'
22
23
  import { PartyRelationshipEntity } from './entities/contact/PartyRelationshipEntity'
23
24
  import { PartyTypeEntity } from './entities/contact/PartyTypeEntity'
@@ -31,14 +32,20 @@ export { AbstractIssuanceBrandingStore } from './issuanceBranding/AbstractIssuan
31
32
  export { IssuanceBrandingStore } from './issuanceBranding/IssuanceBrandingStore'
32
33
  export { StatusListStore } from './statusList/StatusListStore'
33
34
  import { AuditEventEntity, auditEventEntityFrom } from './entities/eventLogger/AuditEventEntity'
35
+ import { DigitalCredentialEntity } from './entities/digitalCredential/DigitalCredentialEntity'
36
+ import { digitalCredentialFrom, digitalCredentialsFrom, nonPersistedDigitalCredentialEntityFromAddArgs } from './utils/digitalCredential/MappingUtils'
34
37
  export { AbstractEventLoggerStore } from './eventLogger/AbstractEventLoggerStore'
35
38
  export { EventLoggerStore } from './eventLogger/EventLoggerStore'
39
+ export { IAbstractMachineStateStore } from './machineState/IAbstractMachineStateStore'
40
+ export { MachineStateStore } from './machineState/MachineStateStore'
41
+
36
42
  export {
37
43
  DataStoreMigrations,
38
44
  DataStoreEventLoggerMigrations,
39
45
  DataStoreContactMigrations,
40
46
  DataStoreIssuanceBrandingMigrations,
41
47
  DataStoreStatusListMigrations,
48
+ DataStoreMachineStateMigrations,
42
49
  } from './migrations'
43
50
  export * from './types'
44
51
  export * from './utils/contact/MappingUtils'
@@ -77,12 +84,18 @@ export const DataStoreStatusListEntities = [StatusListEntity, StatusListEntryEnt
77
84
 
78
85
  export const DataStoreEventLoggerEntities = [AuditEventEntity]
79
86
 
87
+ export const DataStoreDigitalCredentialEntities = [DigitalCredentialEntity]
88
+
89
+ export const DataStoreMachineStateEntities = [MachineStateInfoEntity]
90
+
80
91
  // All entities combined if a party wants to enable them all at once
81
92
  export const DataStoreEntities = [
82
93
  ...DataStoreContactEntities,
83
94
  ...DataStoreIssuanceBrandingEntities,
84
95
  ...DataStoreStatusListEntities,
85
96
  ...DataStoreEventLoggerEntities,
97
+ ...DataStoreDigitalCredentialEntities,
98
+ ...DataStoreMachineStateEntities,
86
99
  ]
87
100
 
88
101
  export {
@@ -119,4 +132,9 @@ export {
119
132
  StatusListEntryEntity,
120
133
  AuditEventEntity,
121
134
  auditEventEntityFrom,
135
+ DigitalCredentialEntity,
136
+ digitalCredentialFrom,
137
+ digitalCredentialsFrom,
138
+ nonPersistedDigitalCredentialEntityFromAddArgs,
139
+ MachineStateInfoEntity,
122
140
  }
@@ -0,0 +1,65 @@
1
+ import {
2
+ StoreMachineStateDeleteExpiredArgs,
3
+ StoreMachineStateDeleteArgs,
4
+ StoreMachineStatesFindActiveArgs,
5
+ StoreFindMachineStatesArgs,
6
+ StoreMachineStatePersistArgs,
7
+ StoreMachineStateInfo,
8
+ StoreMachineStateGetArgs,
9
+ } from '../types'
10
+
11
+ /**
12
+ * Represents an abstract class for storing machine states.
13
+ * This class provides methods for persisting, retrieving, and deleting machine states.
14
+ *
15
+ * @interface
16
+ */
17
+ export abstract class IAbstractMachineStateStore {
18
+ /**
19
+ * Persists the machine state.
20
+ *
21
+ * @param {StoreMachineStatePersistArgs} state - The object containing the machine state to persist.
22
+ * @return {Promise<StoreMachineStateInfo>} - A Promise that resolves to the information about the persisted machine state.
23
+ */
24
+ abstract persistMachineState(state: StoreMachineStatePersistArgs): Promise<StoreMachineStateInfo>
25
+
26
+ /**
27
+ * Finds active machine states based on the given arguments.
28
+ *
29
+ * @param {StoreMachineStatesFindActiveArgs} args - The arguments for finding active machine states.
30
+ * @return {Promise<Array<StoreMachineStateInfo>>} - A promise that resolves with an array of active machine states.
31
+ */
32
+ abstract findActiveMachineStates(args: StoreMachineStatesFindActiveArgs): Promise<Array<StoreMachineStateInfo>>
33
+
34
+ /**
35
+ * Retrieves the state of a particular machine.
36
+ *
37
+ * @param {StoreMachineStateGetArgs} args - The arguments for retrieving the machine state.
38
+ * @returns {Promise<StoreMachineStateInfo>} - A promise that resolves to the machine state information.
39
+ */
40
+ abstract getMachineState(args: StoreMachineStateGetArgs): Promise<StoreMachineStateInfo>
41
+
42
+ /**
43
+ * Finds the machine states based on the given arguments.
44
+ *
45
+ * @param {StoreFindMachineStatesArgs} [args] - The arguments to filter the machine states.
46
+ * @returns {Promise<Array<StoreMachineStateInfo>>} - A promise that resolves to an array of machine state information.
47
+ */
48
+ abstract findMachineStates(args?: StoreFindMachineStatesArgs): Promise<Array<StoreMachineStateInfo>>
49
+
50
+ /**
51
+ * Deletes a machine state.
52
+ *
53
+ * @param {StoreMachineStateDeleteArgs} args - The arguments for deleting the machine state.
54
+ * @return {Promise<boolean>} - A promise that resolves to a boolean indicating if the machine state was successfully deleted or not.
55
+ */
56
+ abstract deleteMachineState(args: StoreMachineStateDeleteArgs): Promise<boolean>
57
+
58
+ /**
59
+ * Deletes expired machine states from the database.
60
+ *
61
+ * @param {StoreMachineStateDeleteExpiredArgs} args - The arguments for deleting expired machine states.
62
+ * @return {Promise<number>} - A promise that resolves to the number of deleted machine states.
63
+ */
64
+ abstract deleteExpiredMachineStates(args: StoreMachineStateDeleteExpiredArgs): Promise<number>
65
+ }