@sphereon/ssi-sdk.data-store 0.24.1-unstable.9 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/contact/ContactStore.d.ts +3 -0
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/contact/ContactStore.js +84 -48
- package/dist/contact/ContactStore.js.map +1 -1
- package/dist/entities/contact/BaseContactEntity.d.ts +2 -0
- package/dist/entities/contact/BaseContactEntity.d.ts.map +1 -1
- package/dist/entities/contact/BaseContactEntity.js +12 -3
- package/dist/entities/contact/BaseContactEntity.js.map +1 -1
- package/dist/entities/contact/ConnectionEntity.d.ts +2 -0
- package/dist/entities/contact/ConnectionEntity.d.ts.map +1 -1
- package/dist/entities/contact/ConnectionEntity.js +8 -0
- package/dist/entities/contact/ConnectionEntity.js.map +1 -1
- package/dist/entities/contact/ContactMetadataItemEntity.d.ts +14 -0
- package/dist/entities/contact/ContactMetadataItemEntity.d.ts.map +1 -0
- package/dist/entities/contact/ContactMetadataItemEntity.js +88 -0
- package/dist/entities/contact/ContactMetadataItemEntity.js.map +1 -0
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts +2 -0
- package/dist/entities/contact/CorrelationIdentifierEntity.d.ts.map +1 -1
- package/dist/entities/contact/CorrelationIdentifierEntity.js +8 -0
- package/dist/entities/contact/CorrelationIdentifierEntity.js.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.d.ts +2 -0
- package/dist/entities/contact/DidAuthConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/DidAuthConfigEntity.js +8 -0
- package/dist/entities/contact/DidAuthConfigEntity.js.map +1 -1
- package/dist/entities/contact/ElectronicAddressEntity.d.ts +2 -0
- package/dist/entities/contact/ElectronicAddressEntity.d.ts.map +1 -1
- package/dist/entities/contact/ElectronicAddressEntity.js +8 -0
- package/dist/entities/contact/ElectronicAddressEntity.js.map +1 -1
- package/dist/entities/contact/IMetadataEntity.d.ts +8 -0
- package/dist/entities/contact/IMetadataEntity.d.ts.map +1 -0
- package/dist/entities/contact/IMetadataEntity.js +2 -0
- package/dist/entities/contact/IMetadataEntity.js.map +1 -0
- package/dist/entities/contact/IdentityEntity.d.ts +5 -2
- package/dist/entities/contact/IdentityEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityEntity.js +13 -0
- package/dist/entities/contact/IdentityEntity.js.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts +6 -2
- package/dist/entities/contact/IdentityMetadataItemEntity.d.ts.map +1 -1
- package/dist/entities/contact/IdentityMetadataItemEntity.js +19 -3
- package/dist/entities/contact/IdentityMetadataItemEntity.js.map +1 -1
- package/dist/entities/contact/NaturalPersonEntity.d.ts +2 -0
- package/dist/entities/contact/NaturalPersonEntity.d.ts.map +1 -1
- package/dist/entities/contact/NaturalPersonEntity.js +8 -0
- package/dist/entities/contact/NaturalPersonEntity.js.map +1 -1
- package/dist/entities/contact/OpenIdConfigEntity.d.ts +2 -0
- package/dist/entities/contact/OpenIdConfigEntity.d.ts.map +1 -1
- package/dist/entities/contact/OpenIdConfigEntity.js +8 -0
- package/dist/entities/contact/OpenIdConfigEntity.js.map +1 -1
- package/dist/entities/contact/OrganizationEntity.d.ts +2 -0
- package/dist/entities/contact/OrganizationEntity.d.ts.map +1 -1
- package/dist/entities/contact/OrganizationEntity.js +8 -0
- package/dist/entities/contact/OrganizationEntity.js.map +1 -1
- package/dist/entities/contact/PartyEntity.d.ts +2 -0
- package/dist/entities/contact/PartyEntity.d.ts.map +1 -1
- package/dist/entities/contact/PartyEntity.js +8 -0
- package/dist/entities/contact/PartyEntity.js.map +1 -1
- package/dist/entities/contact/PartyRelationshipEntity.d.ts +2 -0
- package/dist/entities/contact/PartyRelationshipEntity.d.ts.map +1 -1
- package/dist/entities/contact/PartyRelationshipEntity.js +8 -0
- package/dist/entities/contact/PartyRelationshipEntity.js.map +1 -1
- package/dist/entities/contact/PartyTypeEntity.js +4 -4
- package/dist/entities/contact/PartyTypeEntity.js.map +1 -1
- package/dist/entities/contact/PhysicalAddressEntity.d.ts +2 -0
- package/dist/entities/contact/PhysicalAddressEntity.d.ts.map +1 -1
- package/dist/entities/contact/PhysicalAddressEntity.js +10 -1
- package/dist/entities/contact/PhysicalAddressEntity.js.map +1 -1
- package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.d.ts +14 -0
- package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.d.ts.map +1 -0
- package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.js +74 -0
- package/dist/entities/presentationDefinition/PresentationDefinitionItemEntity.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/migrations/generic/10-CreatePresentationDefinitions.d.ts +7 -0
- package/dist/migrations/generic/10-CreatePresentationDefinitions.d.ts.map +1 -0
- package/dist/migrations/generic/10-CreatePresentationDefinitions.js +78 -0
- package/dist/migrations/generic/10-CreatePresentationDefinitions.js.map +1 -0
- package/dist/migrations/generic/8-CreateContacts.d.ts +7 -0
- package/dist/migrations/generic/8-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/generic/8-CreateContacts.js +78 -0
- package/dist/migrations/generic/8-CreateContacts.js.map +1 -0
- package/dist/migrations/generic/9-CreateContacts.d.ts +7 -0
- package/dist/migrations/generic/9-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/generic/9-CreateContacts.js +78 -0
- package/dist/migrations/generic/9-CreateContacts.js.map +1 -0
- package/dist/migrations/generic/index.d.ts +2 -0
- package/dist/migrations/generic/index.d.ts.map +1 -1
- package/dist/migrations/generic/index.js +12 -2
- package/dist/migrations/generic/index.js.map +1 -1
- package/dist/migrations/index.d.ts +1 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +2 -1
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/postgres/1690925872592-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/postgres/1690925872592-CreateContacts.js +40 -3
- package/dist/migrations/postgres/1690925872592-CreateContacts.js.map +1 -1
- package/dist/migrations/postgres/1710438363001-CreateContacts.d.ts +7 -0
- package/dist/migrations/postgres/1710438363001-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/postgres/1710438363001-CreateContacts.js +63 -0
- package/dist/migrations/postgres/1710438363001-CreateContacts.js.map +1 -0
- package/dist/migrations/postgres/1715761125001-CreateContacts.d.ts +7 -0
- package/dist/migrations/postgres/1715761125001-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/postgres/1715761125001-CreateContacts.js +74 -0
- package/dist/migrations/postgres/1715761125001-CreateContacts.js.map +1 -0
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.d.ts +7 -0
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.d.ts.map +1 -0
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js +41 -0
- package/dist/migrations/postgres/1716475165345-CreatePresentationDefinitions.js.map +1 -0
- package/dist/migrations/sqlite/1690925872693-CreateContacts.d.ts.map +1 -1
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js +40 -3
- package/dist/migrations/sqlite/1690925872693-CreateContacts.js.map +1 -1
- package/dist/migrations/sqlite/1710438363002-CreateContacts.d.ts +7 -0
- package/dist/migrations/sqlite/1710438363002-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/sqlite/1710438363002-CreateContacts.js +79 -0
- package/dist/migrations/sqlite/1710438363002-CreateContacts.js.map +1 -0
- package/dist/migrations/sqlite/1715761125002-CreateContacts.d.ts +7 -0
- package/dist/migrations/sqlite/1715761125002-CreateContacts.d.ts.map +1 -0
- package/dist/migrations/sqlite/1715761125002-CreateContacts.js +73 -0
- package/dist/migrations/sqlite/1715761125002-CreateContacts.js.map +1 -0
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.d.ts +7 -0
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.d.ts.map +1 -0
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js +38 -0
- package/dist/migrations/sqlite/1716475165344-CreatePresentationDefinitions.js.map +1 -0
- package/dist/presentationDefinition/AbstractPDStore.d.ts +12 -0
- package/dist/presentationDefinition/AbstractPDStore.d.ts.map +1 -0
- package/dist/presentationDefinition/AbstractPDStore.js +7 -0
- package/dist/presentationDefinition/AbstractPDStore.js.map +1 -0
- package/dist/presentationDefinition/PDStore.d.ts +19 -0
- package/dist/presentationDefinition/PDStore.d.ts.map +1 -0
- package/dist/presentationDefinition/PDStore.js +152 -0
- package/dist/presentationDefinition/PDStore.js.map +1 -0
- package/dist/types/contact/contact.d.ts +51 -15
- package/dist/types/contact/contact.d.ts.map +1 -1
- package/dist/types/contact/contact.js +12 -7
- package/dist/types/contact/contact.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/presentationDefinition/IAbstractPDStore.d.ts +17 -0
- package/dist/types/presentationDefinition/IAbstractPDStore.d.ts.map +1 -0
- package/dist/types/presentationDefinition/IAbstractPDStore.js +3 -0
- package/dist/types/presentationDefinition/IAbstractPDStore.js.map +1 -0
- package/dist/types/presentationDefinition/presentationDefinition.d.ts +16 -0
- package/dist/types/presentationDefinition/presentationDefinition.d.ts.map +1 -0
- package/dist/types/presentationDefinition/presentationDefinition.js +3 -0
- package/dist/types/presentationDefinition/presentationDefinition.js.map +1 -0
- package/dist/utils/contact/MappingUtils.d.ts +6 -4
- package/dist/utils/contact/MappingUtils.d.ts.map +1 -1
- package/dist/utils/contact/MappingUtils.js +122 -18
- package/dist/utils/contact/MappingUtils.js.map +1 -1
- package/dist/utils/presentationDefinition/MappingUtils.d.ts +6 -0
- package/dist/utils/presentationDefinition/MappingUtils.d.ts.map +1 -0
- package/dist/utils/presentationDefinition/MappingUtils.js +48 -0
- package/dist/utils/presentationDefinition/MappingUtils.js.map +1 -0
- package/package.json +7 -4
- package/src/__tests__/contact.entities.test.ts +129 -44
- package/src/__tests__/contact.store.test.ts +205 -29
- package/src/__tests__/eventLogger.entities.test.ts +2 -2
- package/src/__tests__/eventLogger.store.test.ts +2 -5
- package/src/__tests__/pd-manager.entities.test.ts +71 -0
- package/src/__tests__/pd-manager.store.test.ts +191 -0
- package/src/contact/ContactStore.ts +74 -30
- package/src/entities/contact/BaseContactEntity.ts +11 -0
- package/src/entities/contact/ConnectionEntity.ts +6 -0
- package/src/entities/contact/ContactMetadataItemEntity.ts +50 -0
- package/src/entities/contact/CorrelationIdentifierEntity.ts +6 -0
- package/src/entities/contact/DidAuthConfigEntity.ts +6 -0
- package/src/entities/contact/ElectronicAddressEntity.ts +6 -0
- package/src/entities/contact/IMetadataEntity.ts +8 -0
- package/src/entities/contact/IdentityEntity.ts +11 -2
- package/src/entities/contact/IdentityMetadataItemEntity.ts +16 -4
- package/src/entities/contact/NaturalPersonEntity.ts +6 -0
- package/src/entities/contact/OpenIdConfigEntity.ts +6 -0
- package/src/entities/contact/OrganizationEntity.ts +6 -0
- package/src/entities/contact/PartyEntity.ts +6 -0
- package/src/entities/contact/PartyRelationshipEntity.ts +6 -0
- package/src/entities/contact/PartyTypeEntity.ts +4 -4
- package/src/entities/contact/PhysicalAddressEntity.ts +9 -2
- package/src/entities/presentationDefinition/PresentationDefinitionItemEntity.ts +43 -0
- package/src/index.ts +13 -0
- package/src/migrations/generic/10-CreatePresentationDefinitions.ts +66 -0
- package/src/migrations/generic/8-CreateContacts.ts +66 -0
- package/src/migrations/generic/9-CreateContacts.ts +66 -0
- package/src/migrations/generic/index.ts +11 -1
- package/src/migrations/index.ts +1 -0
- package/src/migrations/postgres/1690925872592-CreateContacts.ts +57 -3
- package/src/migrations/postgres/1710438363001-CreateContacts.ts +63 -0
- package/src/migrations/postgres/1715761125001-CreateContacts.ts +60 -0
- package/src/migrations/postgres/1716475165345-CreatePresentationDefinitions.ts +25 -0
- package/src/migrations/sqlite/1690925872693-CreateContacts.ts +70 -3
- package/src/migrations/sqlite/1710438363002-CreateContacts.ts +83 -0
- package/src/migrations/sqlite/1715761125002-CreateContacts.ts +59 -0
- package/src/migrations/sqlite/1716475165344-CreatePresentationDefinitions.ts +24 -0
- package/src/presentationDefinition/AbstractPDStore.ts +20 -0
- package/src/presentationDefinition/PDStore.ts +185 -0
- package/src/types/contact/contact.ts +56 -15
- package/src/types/index.ts +2 -0
- package/src/types/presentationDefinition/IAbstractPDStore.ts +25 -0
- package/src/types/presentationDefinition/presentationDefinition.ts +17 -0
- package/src/utils/contact/MappingUtils.ts +128 -18
- package/src/utils/presentationDefinition/MappingUtils.ts +52 -0
|
@@ -12,6 +12,7 @@ export class CreateContacts1690925872693 implements MigrationInterface {
|
|
|
12
12
|
)
|
|
13
13
|
await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`)
|
|
14
14
|
await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`)
|
|
15
|
+
// roles not null
|
|
15
16
|
await queryRunner.query(
|
|
16
17
|
`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "contactId" varchar, CONSTRAINT "UQ_Identity_alias" UNIQUE ("alias"))`,
|
|
17
18
|
)
|
|
@@ -34,6 +35,7 @@ export class CreateContacts1690925872693 implements MigrationInterface {
|
|
|
34
35
|
)
|
|
35
36
|
await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`)
|
|
36
37
|
await queryRunner.query(`ALTER TABLE "temporary_CorrelationIdentifier" RENAME TO "CorrelationIdentifier"`)
|
|
38
|
+
// contactId -> partyId
|
|
37
39
|
await queryRunner.query(
|
|
38
40
|
`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "UQ_Identity_alias" UNIQUE ("alias"))`,
|
|
39
41
|
)
|
|
@@ -49,7 +51,7 @@ export class CreateContacts1690925872693 implements MigrationInterface {
|
|
|
49
51
|
await queryRunner.query(`DROP TABLE "Connection"`)
|
|
50
52
|
await queryRunner.query(`ALTER TABLE "temporary_Connection" RENAME TO "Connection"`)
|
|
51
53
|
await queryRunner.query(
|
|
52
|
-
`CREATE TABLE "PartyType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('naturalPerson','organization') ) NOT NULL, "origin" varchar CHECK( "origin" IN ('INTERNAL', 'EXTERNAL') ) NOT NULL
|
|
54
|
+
`CREATE TABLE "PartyType" ("id" varchar PRIMARY KEY NOT NULL, "type" varchar CHECK( "type" IN ('naturalPerson','organization') ) NOT NULL, "origin" varchar CHECK( "origin" IN ('INTERNAL', 'EXTERNAL') ) NOT NULL, "name" varchar(255) NOT NULL, "description" varchar(255), "tenant_id" varchar(255) NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "UQ_PartyType_name" UNIQUE ("name"))`,
|
|
53
55
|
)
|
|
54
56
|
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyType_type_tenant_id" ON "PartyType" ("type", "tenant_id")`)
|
|
55
57
|
await queryRunner.query(
|
|
@@ -109,6 +111,7 @@ export class CreateContacts1690925872693 implements MigrationInterface {
|
|
|
109
111
|
)
|
|
110
112
|
await queryRunner.query(`DROP TABLE "Party"`)
|
|
111
113
|
await queryRunner.query(`ALTER TABLE "temporary_Party" RENAME TO "Party"`)
|
|
114
|
+
// Restore lost FK_Identity_partyId
|
|
112
115
|
await queryRunner.query(
|
|
113
116
|
`CREATE TABLE "temporary_Identity" ("id" varchar PRIMARY KEY NOT NULL, "alias" varchar(255) NOT NULL, "roles" text NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "partyId" varchar, CONSTRAINT "UQ_Identity_alias" UNIQUE ("alias"), CONSTRAINT "FK_Identity_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
|
|
114
117
|
)
|
|
@@ -155,7 +158,71 @@ export class CreateContacts1690925872693 implements MigrationInterface {
|
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
await queryRunner.query(
|
|
162
|
+
`CREATE TABLE "Contact" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255), "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "name" varchar(255), "alias" varchar(255))`,
|
|
163
|
+
)
|
|
164
|
+
await queryRunner.query(
|
|
165
|
+
`INSERT INTO "Contact"(id, uri, created_at, last_updated_at, name, alias) SELECT id, uri, created_at, last_updated_at, (SELECT legal_name FROM "BaseContact" WHERE "BaseContact"."party_id" = "Party"."id"), (SELECT display_name FROM "BaseContact" WHERE "BaseContact"."party_id" = "Party"."id") FROM "Party" WHERE party_type_id = '3875c12e-fdaa-4ef6-a340-c936e054b627'`,
|
|
166
|
+
)
|
|
167
|
+
await queryRunner.query(`DROP TABLE "BaseContact"`)
|
|
168
|
+
await queryRunner.query(`DROP TABLE "Party"`)
|
|
169
|
+
|
|
170
|
+
await queryRunner.query(
|
|
171
|
+
`CREATE TABLE "BaseConfigEntity" ("id" varchar PRIMARY KEY NOT NULL, "identifier" varchar(255), "redirect_url" varchar(255), "session_id" varchar(255), "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" varchar NOT NULL, "connectionId" varchar)`,
|
|
172
|
+
)
|
|
173
|
+
await queryRunner.query(
|
|
174
|
+
`INSERT INTO "BaseConfigEntity"("id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connectionId") SELECT "id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id" FROM "BaseConfig"`,
|
|
175
|
+
)
|
|
176
|
+
await queryRunner.query(`DROP TABLE "BaseConfig"`)
|
|
177
|
+
|
|
178
|
+
await queryRunner.query(
|
|
179
|
+
`CREATE TABLE "temporary_Party" ("id" varchar PRIMARY KEY NOT NULL, "uri" varchar(255), "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "party_type_id" varchar NOT NULL, CONSTRAINT "FK_Party_party_type_id" FOREIGN KEY ("party_type_id") REFERENCES "PartyType" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION)`,
|
|
180
|
+
)
|
|
181
|
+
await queryRunner.query(
|
|
182
|
+
`INSERT INTO "temporary_Party"("id", "uri", "created_at", "last_updated_at", "party_type_id") SELECT "id", "uri", "created_at", "last_updated_at", "party_type_id" FROM "Party"`,
|
|
183
|
+
)
|
|
184
|
+
await queryRunner.query(`DROP TABLE "Party"`)
|
|
185
|
+
await queryRunner.query(`ALTER TABLE "temporary_Party" RENAME TO "Party"`)
|
|
186
|
+
|
|
187
|
+
await queryRunner.query(`DROP INDEX "IDX_PartyRelationship_left_right"`)
|
|
188
|
+
await queryRunner.query(
|
|
189
|
+
`CREATE TABLE "temporary_PartyRelationship" ("id" varchar PRIMARY KEY NOT NULL, "left_id" varchar NOT NULL, "right_id" varchar NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), CONSTRAINT "FK_PartyRelationship_left_id" FOREIGN KEY ("left_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_PartyRelationship_right_id" FOREIGN KEY ("right_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
|
|
190
|
+
)
|
|
191
|
+
await queryRunner.query(
|
|
192
|
+
`INSERT INTO "temporary_PartyRelationship"("id", "left_id", "right_id", "created_at", "last_updated_at") SELECT "id", "left_id", "right_id", "created_at", "last_updated_at" FROM "PartyRelationship"`,
|
|
193
|
+
)
|
|
194
|
+
await queryRunner.query(`DROP TABLE "PartyRelationship"`)
|
|
195
|
+
await queryRunner.query(`ALTER TABLE "temporary_PartyRelationship" RENAME TO "PartyRelationship"`)
|
|
196
|
+
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_PartyRelationship_left_right" ON "PartyRelationship" ("left_id", "right_id")`)
|
|
197
|
+
|
|
198
|
+
await queryRunner.query(`DROP INDEX "IDX_BaseContact_type"`)
|
|
199
|
+
await queryRunner.query(
|
|
200
|
+
`CREATE TABLE "temporary_BaseContact" ("id" varchar PRIMARY KEY NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "last_updated_at" datetime NOT NULL DEFAULT (datetime('now')), "legal_name" varchar(255), "display_name" varchar(255), "first_name" varchar(255), "middle_name" varchar(255), "last_name" varchar(255), "type" varchar NOT NULL, "party_id" varchar, CONSTRAINT "UQ_BaseContact_legal_name" UNIQUE ("legal_name"), CONSTRAINT "REL_BaseContact_party_id" UNIQUE ("party_id"), CONSTRAINT "FK_BaseContact_party_id" FOREIGN KEY ("party_id") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
|
|
201
|
+
)
|
|
202
|
+
await queryRunner.query(
|
|
203
|
+
`INSERT INTO "temporary_BaseContact"("id", "created_at", "last_updated_at", "legal_name", "display_name", "first_name", "middle_name", "last_name", "type", "party_id") SELECT "id", "created_at", "last_updated_at", "legal_name", "display_name", "first_name", "middle_name", "last_name", "type", "party_id" FROM "BaseContact"`,
|
|
204
|
+
)
|
|
205
|
+
await queryRunner.query(`DROP TABLE "BaseContact"`)
|
|
206
|
+
await queryRunner.query(`ALTER TABLE "temporary_BaseContact" RENAME TO "BaseContact"`)
|
|
207
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseContact_type" ON "BaseContact" ("type")`)
|
|
208
|
+
|
|
209
|
+
await queryRunner.query(`DROP INDEX "IDX_BaseConfig_type"`)
|
|
210
|
+
await queryRunner.query(
|
|
211
|
+
`CREATE TABLE "temporary_BaseConfig" ("id" varchar PRIMARY KEY NOT NULL, "identifier" varchar(255), "redirect_url" varchar(255), "session_id" varchar(255), "client_id" varchar(255), "client_secret" varchar(255), "scopes" text, "issuer" varchar(255), "dangerously_allow_insecure_http_requests" boolean, "client_auth_method" text, "type" varchar NOT NULL, "connection_id" varchar, CONSTRAINT "REL_BaseConfig_connection_id" UNIQUE ("connection_id"), CONSTRAINT "FK_BaseConfig_connection_id" FOREIGN KEY ("connection_id") REFERENCES "Connection" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)`,
|
|
212
|
+
)
|
|
213
|
+
await queryRunner.query(
|
|
214
|
+
`INSERT INTO "temporary_BaseConfig"("id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id") SELECT "id", "identifier", "redirect_url", "session_id", "client_id", "client_secret", "scopes", "issuer", "dangerously_allow_insecure_http_requests", "client_auth_method", "type", "connection_id" FROM "BaseConfig"`,
|
|
215
|
+
)
|
|
216
|
+
await queryRunner.query(`DROP TABLE "BaseConfig"`)
|
|
217
|
+
await queryRunner.query(`ALTER TABLE "temporary_BaseConfig" RENAME TO "BaseConfig"`)
|
|
218
|
+
await queryRunner.query(`CREATE INDEX "IDX_BaseConfig_type" ON "BaseConfig" ("type")`)
|
|
219
|
+
|
|
220
|
+
await queryRunner.query(`DROP INDEX "IDX_PartyType_type_tenant_id"`)
|
|
221
|
+
await queryRunner.query(`DROP TABLE "PartyType"`)
|
|
222
|
+
await queryRunner.query(`DROP TABLE "Connection"`)
|
|
223
|
+
await queryRunner.query(`DROP TABLE "Identity"`)
|
|
224
|
+
await queryRunner.query(`DROP TABLE "CorrelationIdentifier"`)
|
|
225
|
+
await queryRunner.query(`DROP TABLE "ElectronicAddress"`)
|
|
226
|
+
await queryRunner.query(`DROP TABLE "PhysicalAddress"`)
|
|
160
227
|
}
|
|
161
228
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export class CreateContacts1710438363002 implements MigrationInterface {
|
|
4
|
+
name = 'CreateContacts1710438363002'
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(`ALTER TABLE "Party" ADD COLUMN "owner_id" text`)
|
|
8
|
+
await queryRunner.query(`ALTER TABLE "Party" ADD COLUMN "tenant_id" text`)
|
|
9
|
+
|
|
10
|
+
// Add owner_id, tenant_id & origin
|
|
11
|
+
await queryRunner.query(
|
|
12
|
+
`CREATE TABLE "temporary_Identity" (
|
|
13
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
14
|
+
"alias" varchar(255) NOT NULL,
|
|
15
|
+
"roles" text NOT NULL,
|
|
16
|
+
"origin" text NOT NULL,
|
|
17
|
+
"created_at" datetime NOT NULL DEFAULT (datetime('now')),
|
|
18
|
+
"last_updated_at" datetime NOT NULL DEFAULT (datetime('now')),
|
|
19
|
+
"partyId" varchar,
|
|
20
|
+
"owner_id" text,
|
|
21
|
+
"tenant_id" text,
|
|
22
|
+
CONSTRAINT "UQ_Identity_alias" UNIQUE ("alias"),
|
|
23
|
+
CONSTRAINT "FK_Identity_partyId" FOREIGN KEY ("partyId") REFERENCES "Party" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
|
|
24
|
+
)`,
|
|
25
|
+
)
|
|
26
|
+
await queryRunner.query(
|
|
27
|
+
`INSERT INTO "temporary_Identity"("id", "alias", "roles", "created_at", "last_updated_at", "partyId", "owner_id", "tenant_id", "origin")
|
|
28
|
+
SELECT "id", "alias", "roles", 'EXTERNAL' as "origin", "created_at", "last_updated_at", "partyId", NULL as "owner_id", NULL as "tenant_id" FROM "Identity"`,
|
|
29
|
+
)
|
|
30
|
+
await queryRunner.query(`DROP TABLE "Identity"`)
|
|
31
|
+
await queryRunner.query(`ALTER TABLE "temporary_Identity" RENAME TO "Identity"`)
|
|
32
|
+
|
|
33
|
+
await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" ADD COLUMN "owner_id" text`)
|
|
34
|
+
await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" ADD COLUMN "tenant_id" text`)
|
|
35
|
+
|
|
36
|
+
await queryRunner.query(`ALTER TABLE "Connection" ADD COLUMN "owner_id" text`)
|
|
37
|
+
await queryRunner.query(`ALTER TABLE "Connection" ADD COLUMN "tenant_id" text`)
|
|
38
|
+
|
|
39
|
+
await queryRunner.query(`ALTER TABLE "BaseConfig" ADD COLUMN "owner_id" text`)
|
|
40
|
+
await queryRunner.query(`ALTER TABLE "BaseConfig" ADD COLUMN "tenant_id" text`)
|
|
41
|
+
|
|
42
|
+
await queryRunner.query(`ALTER TABLE "BaseContact" ADD COLUMN "owner_id" text`)
|
|
43
|
+
await queryRunner.query(`ALTER TABLE "BaseContact" ADD COLUMN "tenant_id" text`)
|
|
44
|
+
|
|
45
|
+
await queryRunner.query(`ALTER TABLE "PartyRelationship" ADD COLUMN "owner_id" text`)
|
|
46
|
+
await queryRunner.query(`ALTER TABLE "PartyRelationship" ADD COLUMN "tenant_id" text`)
|
|
47
|
+
|
|
48
|
+
await queryRunner.query(`ALTER TABLE "ElectronicAddress" ADD COLUMN "owner_id" text`)
|
|
49
|
+
await queryRunner.query(`ALTER TABLE "ElectronicAddress" ADD COLUMN "tenant_id" text`)
|
|
50
|
+
|
|
51
|
+
await queryRunner.query(`ALTER TABLE "PhysicalAddress" ADD COLUMN "owner_id" text`)
|
|
52
|
+
await queryRunner.query(`ALTER TABLE "PhysicalAddress" ADD COLUMN "tenant_id" text`)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
56
|
+
await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP COLUMN "tenant_id"`)
|
|
57
|
+
await queryRunner.query(`ALTER TABLE "PhysicalAddress" DROP COLUMN "owner_id"`)
|
|
58
|
+
|
|
59
|
+
await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP COLUMN "tenant_id"`)
|
|
60
|
+
await queryRunner.query(`ALTER TABLE "ElectronicAddress" DROP COLUMN "owner_id"`)
|
|
61
|
+
|
|
62
|
+
await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP COLUMN "tenant_id"`)
|
|
63
|
+
await queryRunner.query(`ALTER TABLE "PartyRelationship" DROP COLUMN "owner_id"`)
|
|
64
|
+
|
|
65
|
+
await queryRunner.query(`ALTER TABLE "BaseContact" DROP COLUMN "tenant_id"`)
|
|
66
|
+
await queryRunner.query(`ALTER TABLE "BaseContact" DROP COLUMN "owner_id"`)
|
|
67
|
+
|
|
68
|
+
await queryRunner.query(`ALTER TABLE "BaseConfig" DROP COLUMN "tenant_id"`)
|
|
69
|
+
await queryRunner.query(`ALTER TABLE "BaseConfig" DROP COLUMN "owner_id"`)
|
|
70
|
+
|
|
71
|
+
await queryRunner.query(`ALTER TABLE "Connection" DROP COLUMN "tenant_id"`)
|
|
72
|
+
await queryRunner.query(`ALTER TABLE "Connection" DROP COLUMN "owner_id"`)
|
|
73
|
+
|
|
74
|
+
await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP COLUMN "tenant_id"`)
|
|
75
|
+
await queryRunner.query(`ALTER TABLE "CorrelationIdentifier" DROP COLUMN "owner_id"`)
|
|
76
|
+
|
|
77
|
+
await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "tenant_id"`)
|
|
78
|
+
await queryRunner.query(`ALTER TABLE "Identity" DROP COLUMN "owner_id"`)
|
|
79
|
+
|
|
80
|
+
await queryRunner.query(`ALTER TABLE "Party" DROP COLUMN "tenant_id"`)
|
|
81
|
+
await queryRunner.query(`ALTER TABLE "Party" DROP COLUMN "owner_id"`)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export class CreateContacts1715761125002 implements MigrationInterface {
|
|
4
|
+
name = 'CreateContacts1715761125002'
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
// Upgrade IdentityMetadata table
|
|
8
|
+
await queryRunner.query(`ALTER TABLE "IdentityMetadata" RENAME TO "temporary_IdentityMetadata"`)
|
|
9
|
+
await queryRunner.query(`CREATE TABLE "IdentityMetadata"
|
|
10
|
+
(
|
|
11
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
12
|
+
"label" varchar(255) NOT NULL,
|
|
13
|
+
"valueType" varchar NOT NULL,
|
|
14
|
+
"stringValue" varchar(255),
|
|
15
|
+
"numberValue" double,
|
|
16
|
+
"dateValue" datetime,
|
|
17
|
+
"boolValue" boolean,
|
|
18
|
+
"identityId" varchar,
|
|
19
|
+
FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE)`)
|
|
20
|
+
await queryRunner.query(`INSERT INTO "IdentityMetadata" ("id", "label", "valueType", "stringValue", "identityId")
|
|
21
|
+
SELECT "id", "label", 'string', "value", "identityId"
|
|
22
|
+
FROM "temporary_IdentityMetadata"
|
|
23
|
+
`)
|
|
24
|
+
await queryRunner.query(`DROP TABLE "temporary_IdentityMetadata"`)
|
|
25
|
+
|
|
26
|
+
// Create new ContactMetadata table
|
|
27
|
+
await queryRunner.query(`CREATE TABLE "ContactMetadata"
|
|
28
|
+
(
|
|
29
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
30
|
+
"label" varchar(255) NOT NULL,
|
|
31
|
+
"valueType" varchar NOT NULL,
|
|
32
|
+
"stringValue" text,
|
|
33
|
+
"numberValue" double,
|
|
34
|
+
"dateValue" datetime,
|
|
35
|
+
"boolValue" boolean,
|
|
36
|
+
"contactId" varchar,
|
|
37
|
+
FOREIGN KEY ("contactId") REFERENCES "BaseContact" ("id") ON DELETE CASCADE)`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
41
|
+
// Drop the ContactMetadata table
|
|
42
|
+
await queryRunner.query(`DROP TABLE "ContactMetadata"`)
|
|
43
|
+
|
|
44
|
+
// Restore the IdentityMetadata table
|
|
45
|
+
await queryRunner.query(`ALTER TABLE "IdentityMetadata" RENAME TO "temporary_IdentityMetadata"`)
|
|
46
|
+
await queryRunner.query(`CREATE TABLE "IdentityMetadata"
|
|
47
|
+
(
|
|
48
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
49
|
+
"label" varchar(255) NOT NULL,
|
|
50
|
+
"value" varchar(255) NOT NULL,
|
|
51
|
+
"identityId" varchar,
|
|
52
|
+
FOREIGN KEY ("identityId") REFERENCES "Identity" ("id") ON DELETE CASCADE
|
|
53
|
+
)`)
|
|
54
|
+
await queryRunner.query(`INSERT INTO "IdentityMetadata" ("id", "label", "value", "identityId")
|
|
55
|
+
SELECT "id", "label", "stringValue", "identityId"
|
|
56
|
+
FROM "temporary_IdentityMetadata"`)
|
|
57
|
+
await queryRunner.query(`DROP TABLE "temporary_IdentityMetadata"`)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export class CreatePresentationDefinitions1716475165344 implements MigrationInterface {
|
|
4
|
+
name = 'CreatePresentationDefinitions1716475165344'
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`CREATE TABLE "PresentationDefinitionItem" (
|
|
9
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
10
|
+
"tenant_id" varchar,
|
|
11
|
+
"definition_id" varchar NOT NULL,
|
|
12
|
+
"name" varchar,
|
|
13
|
+
"version" varchar NOT NULL,
|
|
14
|
+
"purpose" varchar,
|
|
15
|
+
"definition_payload" varchar NOT NULL,
|
|
16
|
+
"created_at" datetime NOT NULL DEFAULT (datetime('now')),
|
|
17
|
+
"last_updated_at" datetime NOT NULL DEFAULT (datetime('now')))`,
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
22
|
+
await queryRunner.query(`DROP TABLE "PresentationDefinitionItem"`)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetDefinitionArgs,
|
|
3
|
+
GetDefinitionsArgs,
|
|
4
|
+
DeleteDefinitionArgs,
|
|
5
|
+
PresentationDefinitionItem,
|
|
6
|
+
AddDefinitionArgs,
|
|
7
|
+
UpdateDefinitionArgs,
|
|
8
|
+
DeleteDefinitionsArgs,
|
|
9
|
+
} from '../types'
|
|
10
|
+
|
|
11
|
+
export abstract class AbstractPDStore {
|
|
12
|
+
abstract hasDefinition(args: GetDefinitionArgs): Promise<boolean>
|
|
13
|
+
abstract hasDefinitions(args: GetDefinitionsArgs): Promise<boolean>
|
|
14
|
+
abstract getDefinition(args: GetDefinitionArgs): Promise<PresentationDefinitionItem>
|
|
15
|
+
abstract getDefinitions(args: GetDefinitionsArgs): Promise<Array<PresentationDefinitionItem>>
|
|
16
|
+
abstract addDefinition(args: AddDefinitionArgs): Promise<PresentationDefinitionItem>
|
|
17
|
+
abstract updateDefinition(args: UpdateDefinitionArgs): Promise<PresentationDefinitionItem>
|
|
18
|
+
abstract deleteDefinition(args: DeleteDefinitionArgs): Promise<void>
|
|
19
|
+
abstract deleteDefinitions(args: DeleteDefinitionsArgs): Promise<number>
|
|
20
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { OrPromise } from '@sphereon/ssi-types'
|
|
2
|
+
import { DataSource, In, Repository } from 'typeorm'
|
|
3
|
+
import { AbstractPDStore } from './AbstractPDStore'
|
|
4
|
+
import Debug from 'debug'
|
|
5
|
+
import {
|
|
6
|
+
DeleteDefinitionArgs,
|
|
7
|
+
DeleteDefinitionsArgs,
|
|
8
|
+
GetDefinitionArgs,
|
|
9
|
+
GetDefinitionsArgs,
|
|
10
|
+
HasDefinitionArgs,
|
|
11
|
+
HasDefinitionsArgs,
|
|
12
|
+
NonPersistedPresentationDefinitionItem,
|
|
13
|
+
PresentationDefinitionItem,
|
|
14
|
+
PresentationDefinitionItemFilter,
|
|
15
|
+
} from '../types'
|
|
16
|
+
import { PresentationDefinitionItemEntity } from '../entities/presentationDefinition/PresentationDefinitionItemEntity'
|
|
17
|
+
import { presentationDefinitionEntityItemFrom, presentationDefinitionItemFrom } from '../utils/presentationDefinition/MappingUtils'
|
|
18
|
+
|
|
19
|
+
const debug: Debug.Debugger = Debug('sphereon:ssi-sdk:pd-store')
|
|
20
|
+
|
|
21
|
+
export class PDStore extends AbstractPDStore {
|
|
22
|
+
private readonly dbConnection: OrPromise<DataSource>
|
|
23
|
+
|
|
24
|
+
constructor(dbConnection: OrPromise<DataSource>) {
|
|
25
|
+
super()
|
|
26
|
+
this.dbConnection = dbConnection
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getDefinition = async (args: GetDefinitionArgs): Promise<PresentationDefinitionItem> => {
|
|
30
|
+
const { itemId } = args ?? {}
|
|
31
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
32
|
+
const result: PresentationDefinitionItemEntity | null = await pdRepository.findOne({
|
|
33
|
+
where: { id: itemId },
|
|
34
|
+
})
|
|
35
|
+
if (!result) {
|
|
36
|
+
return Promise.reject(Error(`No presentation definition item found for id: ${itemId}`))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return presentationDefinitionItemFrom(result)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
hasDefinition = async (args: HasDefinitionArgs): Promise<boolean> => {
|
|
43
|
+
const { itemId } = args ?? {}
|
|
44
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
45
|
+
|
|
46
|
+
const resultCount: number = await pdRepository.count({
|
|
47
|
+
where: { id: itemId },
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
return resultCount > 0
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
hasDefinitions = async (args: HasDefinitionsArgs): Promise<boolean> => {
|
|
54
|
+
const { filter } = args
|
|
55
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
56
|
+
|
|
57
|
+
const resultCount: number = await pdRepository.count({
|
|
58
|
+
...(filter && { where: cleanFilter(filter) }),
|
|
59
|
+
})
|
|
60
|
+
return resultCount > 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getDefinitions = async (args: GetDefinitionsArgs): Promise<Array<PresentationDefinitionItem>> => {
|
|
64
|
+
const { filter } = args
|
|
65
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
66
|
+
const initialResult = await this.findIds(pdRepository, filter)
|
|
67
|
+
const result: Array<PresentationDefinitionItemEntity> = await pdRepository.find({
|
|
68
|
+
where: {
|
|
69
|
+
id: In(initialResult.map((entity: PresentationDefinitionItemEntity) => entity.id)),
|
|
70
|
+
},
|
|
71
|
+
order: {
|
|
72
|
+
version: 'DESC',
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return result.map((entity: PresentationDefinitionItemEntity) => presentationDefinitionItemFrom(entity))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
addDefinition = async (item: NonPersistedPresentationDefinitionItem): Promise<PresentationDefinitionItem> => {
|
|
80
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
81
|
+
|
|
82
|
+
const entity: PresentationDefinitionItemEntity = presentationDefinitionEntityItemFrom(item)
|
|
83
|
+
debug('Adding presentation definition entity', item)
|
|
84
|
+
const result: PresentationDefinitionItemEntity = await pdRepository.save(entity, {
|
|
85
|
+
transaction: true,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return presentationDefinitionItemFrom(result)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
updateDefinition = async (item: PresentationDefinitionItem): Promise<PresentationDefinitionItem> => {
|
|
92
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
93
|
+
|
|
94
|
+
const result: PresentationDefinitionItemEntity | null = await pdRepository.findOne({
|
|
95
|
+
where: { id: item.id },
|
|
96
|
+
})
|
|
97
|
+
if (!result) {
|
|
98
|
+
return Promise.reject(Error(`No presentation definition entity found for id: ${item.id}`))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const updatedEntity: Partial<PresentationDefinitionItemEntity> = {
|
|
102
|
+
...result,
|
|
103
|
+
}
|
|
104
|
+
updatedEntity.tenantId = item.tenantId
|
|
105
|
+
updatedEntity.definitionId = item.definitionId!
|
|
106
|
+
updatedEntity.version = item.version
|
|
107
|
+
updatedEntity.name = item.name
|
|
108
|
+
updatedEntity.purpose = item.purpose
|
|
109
|
+
updatedEntity.definitionPayload = JSON.stringify(item.definitionPayload!)
|
|
110
|
+
|
|
111
|
+
debug('Updating presentation definition entity', updatedEntity)
|
|
112
|
+
const updateResult: PresentationDefinitionItemEntity = await pdRepository.save(updatedEntity, {
|
|
113
|
+
transaction: true,
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
return presentationDefinitionItemFrom(updateResult)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
deleteDefinition = async (args: DeleteDefinitionArgs): Promise<void> => {
|
|
120
|
+
const { itemId } = args
|
|
121
|
+
|
|
122
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
123
|
+
const entity: PresentationDefinitionItemEntity | null = await pdRepository.findOne({
|
|
124
|
+
where: { id: itemId },
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
if (!entity) {
|
|
128
|
+
return Promise.reject(Error(`No presentation definition found with id: ${itemId}`))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
debug('Deleting presentation definition entity', entity)
|
|
132
|
+
await pdRepository.delete(entity.id)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
deleteDefinitions = async (args: DeleteDefinitionsArgs): Promise<number> => {
|
|
136
|
+
const { filter } = args
|
|
137
|
+
const pdRepository = (await this.dbConnection).getRepository(PresentationDefinitionItemEntity)
|
|
138
|
+
const initialResult = await this.findIds(pdRepository, filter)
|
|
139
|
+
|
|
140
|
+
const result: Array<PresentationDefinitionItemEntity> = await pdRepository.find({
|
|
141
|
+
where: {
|
|
142
|
+
id: In(initialResult.map((entity: PresentationDefinitionItemEntity) => entity.id)),
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
for (const entity of result) {
|
|
147
|
+
debug('Deleting presentation definition entity', entity.id)
|
|
148
|
+
await pdRepository.delete(entity.id)
|
|
149
|
+
}
|
|
150
|
+
return result.length
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
findIds = async (
|
|
154
|
+
pdRepository: Repository<PresentationDefinitionItemEntity>,
|
|
155
|
+
filter: Array<PresentationDefinitionItemFilter> | undefined,
|
|
156
|
+
): Promise<Array<PresentationDefinitionItemEntity>> => {
|
|
157
|
+
const idFilters = filter?.map((f) => f.id).filter((id) => id !== undefined && id !== null)
|
|
158
|
+
if (idFilters && idFilters.length > 0 && idFilters.length === filter?.length) {
|
|
159
|
+
return await pdRepository.find({
|
|
160
|
+
where: { id: In(idFilters) },
|
|
161
|
+
})
|
|
162
|
+
} else {
|
|
163
|
+
return await pdRepository.find({
|
|
164
|
+
...(filter && { where: cleanFilter(filter) }), // TODO test how mixing filters work
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const cleanFilter = (filter: Array<PresentationDefinitionItemFilter> | undefined): Array<PresentationDefinitionItemFilter> | undefined => {
|
|
171
|
+
if (filter === undefined) {
|
|
172
|
+
return undefined
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return filter.map((item) => {
|
|
176
|
+
const cleanedItem: PresentationDefinitionItemFilter = {}
|
|
177
|
+
for (const key in item) {
|
|
178
|
+
const value = item[key as keyof PresentationDefinitionItemFilter]
|
|
179
|
+
if (value !== undefined) {
|
|
180
|
+
;(cleanedItem as any)[key] = value
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return cleanedItem
|
|
184
|
+
})
|
|
185
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { IIdentifier } from '@veramo/core'
|
|
2
2
|
|
|
3
|
+
export type MetadataTypes = string | number | Date | boolean | undefined
|
|
4
|
+
|
|
3
5
|
export type Party = {
|
|
4
6
|
id: string
|
|
5
7
|
uri?: string
|
|
6
|
-
roles: Array<
|
|
8
|
+
roles: Array<CredentialRole>
|
|
9
|
+
ownerId?: string
|
|
10
|
+
tenantId?: string
|
|
7
11
|
identities: Array<Identity>
|
|
8
12
|
electronicAddresses: Array<ElectronicAddress>
|
|
9
13
|
physicalAddresses: Array<PhysicalAddress>
|
|
@@ -47,36 +51,44 @@ export type PartialParty = Partial<
|
|
|
47
51
|
export type Identity = {
|
|
48
52
|
id: string
|
|
49
53
|
alias: string
|
|
50
|
-
|
|
54
|
+
ownerId?: string
|
|
55
|
+
tenantId?: string
|
|
56
|
+
origin: IdentityOrigin
|
|
57
|
+
roles: Array<CredentialRole>
|
|
51
58
|
identifier: CorrelationIdentifier
|
|
52
59
|
connection?: Connection
|
|
53
|
-
metadata?: Array<MetadataItem
|
|
60
|
+
metadata?: Array<MetadataItem<MetadataTypes>>
|
|
54
61
|
createdAt: Date
|
|
55
62
|
lastUpdatedAt: Date
|
|
56
63
|
}
|
|
57
|
-
export type NonPersistedIdentity = Omit<Identity, 'id' | 'identifier' | 'connection' | 'metadata' | 'createdAt' | 'lastUpdatedAt'> & {
|
|
64
|
+
export type NonPersistedIdentity = Omit<Identity, 'id' | 'identifier' | 'connection' | 'metadata' | 'origin' | 'createdAt' | 'lastUpdatedAt'> & {
|
|
65
|
+
origin: IdentityOrigin
|
|
58
66
|
identifier: NonPersistedCorrelationIdentifier
|
|
59
67
|
connection?: NonPersistedConnection
|
|
60
|
-
metadata?: Array<NonPersistedMetadataItem
|
|
68
|
+
metadata?: Array<NonPersistedMetadataItem<MetadataTypes>>
|
|
61
69
|
}
|
|
62
|
-
export type PartialIdentity = Partial<Omit<Identity, 'identifier' | 'connection' | 'metadata' | 'roles'>> & {
|
|
70
|
+
export type PartialIdentity = Partial<Omit<Identity, 'identifier' | 'connection' | 'metadata' | 'origin' | 'roles'>> & {
|
|
63
71
|
identifier?: PartialCorrelationIdentifier
|
|
64
72
|
connection?: PartialConnection
|
|
65
|
-
metadata?: PartialMetadataItem
|
|
66
|
-
|
|
73
|
+
metadata?: PartialMetadataItem<MetadataTypes> // Usage: FindIdentityArgs = Array<PartialIdentity>
|
|
74
|
+
origin?: IdentityOrigin
|
|
75
|
+
roles?: CredentialRole
|
|
67
76
|
partyId?: string
|
|
68
77
|
}
|
|
69
78
|
|
|
70
|
-
export type MetadataItem = {
|
|
79
|
+
export type MetadataItem<T extends MetadataTypes> = {
|
|
71
80
|
id: string
|
|
72
81
|
label: string
|
|
73
|
-
value:
|
|
82
|
+
value: T
|
|
74
83
|
}
|
|
75
|
-
|
|
76
|
-
export type
|
|
84
|
+
|
|
85
|
+
export type NonPersistedMetadataItem<T extends MetadataTypes> = Omit<MetadataItem<T>, 'id'>
|
|
86
|
+
export type PartialMetadataItem<T extends MetadataTypes> = Partial<MetadataItem<T>>
|
|
77
87
|
|
|
78
88
|
export type CorrelationIdentifier = {
|
|
79
89
|
id: string
|
|
90
|
+
ownerId?: string
|
|
91
|
+
tenantId?: string
|
|
80
92
|
type: CorrelationIdentifierType
|
|
81
93
|
correlationId: string
|
|
82
94
|
}
|
|
@@ -85,6 +97,8 @@ export type PartialCorrelationIdentifier = Partial<CorrelationIdentifier>
|
|
|
85
97
|
|
|
86
98
|
export type Connection = {
|
|
87
99
|
id: string
|
|
100
|
+
ownerId?: string
|
|
101
|
+
tenantId?: string
|
|
88
102
|
type: ConnectionType
|
|
89
103
|
config: ConnectionConfig
|
|
90
104
|
}
|
|
@@ -99,6 +113,8 @@ export type OpenIdConfig = {
|
|
|
99
113
|
id: string
|
|
100
114
|
clientId: string
|
|
101
115
|
clientSecret: string
|
|
116
|
+
ownerId?: string
|
|
117
|
+
tenantId?: string
|
|
102
118
|
scopes: Array<string>
|
|
103
119
|
issuer: string
|
|
104
120
|
redirectUrl: string
|
|
@@ -112,6 +128,8 @@ export type DidAuthConfig = {
|
|
|
112
128
|
id: string
|
|
113
129
|
identifier: IIdentifier
|
|
114
130
|
stateId: string
|
|
131
|
+
ownerId?: string
|
|
132
|
+
tenantId?: string
|
|
115
133
|
redirectUrl: string
|
|
116
134
|
sessionId: string
|
|
117
135
|
}
|
|
@@ -130,21 +148,33 @@ export type NaturalPerson = {
|
|
|
130
148
|
lastName: string
|
|
131
149
|
middleName?: string
|
|
132
150
|
displayName: string
|
|
151
|
+
metadata?: Array<MetadataItem<MetadataTypes>>
|
|
152
|
+
ownerId?: string
|
|
153
|
+
tenantId?: string
|
|
133
154
|
createdAt: Date
|
|
134
155
|
lastUpdatedAt: Date
|
|
135
156
|
}
|
|
157
|
+
|
|
136
158
|
export type NonPersistedNaturalPerson = Omit<NaturalPerson, 'id' | 'createdAt' | 'lastUpdatedAt'>
|
|
137
|
-
|
|
159
|
+
|
|
160
|
+
export type PartialNaturalPerson = Partial<Omit<NaturalPerson, 'metadata'>> & {
|
|
161
|
+
metadata?: PartialMetadataItem<MetadataTypes>
|
|
162
|
+
}
|
|
138
163
|
|
|
139
164
|
export type Organization = {
|
|
140
165
|
id: string
|
|
141
166
|
legalName: string
|
|
142
167
|
displayName: string
|
|
168
|
+
metadata?: Array<MetadataItem<MetadataTypes>>
|
|
169
|
+
ownerId?: string
|
|
170
|
+
tenantId?: string
|
|
143
171
|
createdAt: Date
|
|
144
172
|
lastUpdatedAt: Date
|
|
145
173
|
}
|
|
146
174
|
export type NonPersistedOrganization = Omit<Organization, 'id' | 'createdAt' | 'lastUpdatedAt'>
|
|
147
|
-
export type PartialOrganization = Partial<Organization
|
|
175
|
+
export type PartialOrganization = Partial<Omit<Organization, 'metadata'>> & {
|
|
176
|
+
metadata?: PartialMetadataItem<MetadataTypes>
|
|
177
|
+
}
|
|
148
178
|
|
|
149
179
|
export type Contact = NaturalPerson | Organization
|
|
150
180
|
export type NonPersistedContact = NonPersistedNaturalPerson | NonPersistedOrganization
|
|
@@ -169,6 +199,8 @@ export type PartyRelationship = {
|
|
|
169
199
|
id: string
|
|
170
200
|
leftId: string
|
|
171
201
|
rightId: string
|
|
202
|
+
ownerId?: string
|
|
203
|
+
tenantId?: string
|
|
172
204
|
createdAt: Date
|
|
173
205
|
lastUpdatedAt: Date
|
|
174
206
|
}
|
|
@@ -179,6 +211,8 @@ export type ElectronicAddress = {
|
|
|
179
211
|
id: string
|
|
180
212
|
type: ElectronicAddressType
|
|
181
213
|
electronicAddress: string
|
|
214
|
+
ownerId?: string
|
|
215
|
+
tenantId?: string
|
|
182
216
|
createdAt: Date
|
|
183
217
|
lastUpdatedAt: Date
|
|
184
218
|
}
|
|
@@ -197,6 +231,8 @@ export type PhysicalAddress = {
|
|
|
197
231
|
provinceName: string
|
|
198
232
|
countryCode: string
|
|
199
233
|
buildingName?: string
|
|
234
|
+
ownerId?: string
|
|
235
|
+
tenantId?: string
|
|
200
236
|
createdAt: Date
|
|
201
237
|
lastUpdatedAt: Date
|
|
202
238
|
}
|
|
@@ -209,7 +245,7 @@ export type ElectronicAddressType = 'email' | 'phone'
|
|
|
209
245
|
|
|
210
246
|
export type PhysicalAddressType = 'home' | 'visit' | 'postal'
|
|
211
247
|
|
|
212
|
-
export enum
|
|
248
|
+
export enum CredentialRole {
|
|
213
249
|
ISSUER = 'issuer',
|
|
214
250
|
VERIFIER = 'verifier',
|
|
215
251
|
HOLDER = 'holder',
|
|
@@ -235,3 +271,8 @@ export enum PartyOrigin {
|
|
|
235
271
|
INTERNAL = 'INTERNAL',
|
|
236
272
|
EXTERNAL = 'EXTERNAL',
|
|
237
273
|
}
|
|
274
|
+
|
|
275
|
+
export enum IdentityOrigin {
|
|
276
|
+
INTERNAL = 'INTERNAL',
|
|
277
|
+
EXTERNAL = 'EXTERNAL',
|
|
278
|
+
}
|