-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): linking of ipex flows to contacts (#422)
* feat: rework some API in cred server * feat: add apply schema API * refactor: function and var name and dependency link * feat: add full ipex flow for idw and cred server * refactor: testing and some missing logic * feature: save linked IPEX messages for connections * refactor: change the file contruction * feat: linking of IPEX flows to contacts * fix: update unit tests * update: add isUpdate to linkedIpexMessage record * update: add credentialType to linkedIpexMessageRecord * update: get linkedIpexRecord from exchange message * update: get linkedIpexRecord id from exchange message SAID * feat: resolve schema if we fail to get the schema * feat: handle for apply and agree routes --------- Co-authored-by: Bao Hoang <bao.hoanga@sotatek.com> Co-authored-by: Martin Nguyen <tung.nguyen2a@sotatek.com>
- Loading branch information
1 parent
788167c
commit eb1932f
Showing
14 changed files
with
818 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { BaseRecord } from "../../storage/storage.types"; | ||
import { IpexMessage } from "../agent.types"; | ||
import { ConnectionHistoryType } from "../services/connection.types"; | ||
|
||
interface IpexMessageProps { | ||
id: string; | ||
credentialType: string; | ||
content: IpexMessage; | ||
historyType: ConnectionHistoryType; | ||
createdAt?: Date; | ||
connectionId: string; | ||
} | ||
|
||
class IpexMessageRecord extends BaseRecord { | ||
credentialType!: string; | ||
content!: IpexMessage; | ||
connectionId!: string; | ||
historyType!: ConnectionHistoryType; | ||
|
||
static readonly type = "IpexMessageRecord"; | ||
readonly type = IpexMessageRecord.type; | ||
|
||
constructor(props: IpexMessageProps) { | ||
super(); | ||
|
||
if (props) { | ||
this.id = props.id; | ||
this.credentialType = props.credentialType; | ||
this.content = props.content; | ||
this.connectionId = props.connectionId; | ||
this.historyType = props.historyType; | ||
this.createdAt = props.createdAt ?? new Date(); | ||
} | ||
} | ||
|
||
getTags() { | ||
return { | ||
...this._tags, | ||
connectionId: this.connectionId, | ||
}; | ||
} | ||
} | ||
|
||
export { IpexMessageRecord }; | ||
export type { IpexMessageProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { StorageService } from "../../storage/storage.types"; | ||
import { ConnectionHistoryType } from "../services/connection.types"; | ||
import { IpexMessageRecord, IpexMessageProps } from "./ipexMessageRecord"; | ||
import { IpexMessageStorage } from "./ipexMessageStorage"; | ||
|
||
const storageService = jest.mocked<StorageService<IpexMessageRecord>>({ | ||
save: jest.fn(), | ||
delete: jest.fn(), | ||
deleteById: jest.fn(), | ||
update: jest.fn(), | ||
findById: jest.fn(), | ||
findAllByQuery: jest.fn(), | ||
getAll: jest.fn(), | ||
}); | ||
|
||
const ipexMessageStorage = new IpexMessageStorage(storageService); | ||
|
||
const id1 = "id1"; | ||
const id2 = "id2"; | ||
|
||
const now = new Date(); | ||
const ipexMessage = { | ||
exn: { | ||
v: "string", | ||
d: "string", | ||
t: "string", | ||
i: "string", | ||
p: "string", | ||
dt: "string", | ||
r: "string", | ||
q: {}, | ||
a: {}, | ||
e: {}, | ||
}, | ||
pathed: { | ||
acdc: "string", | ||
iss: "string", | ||
anc: "string", | ||
}, | ||
}; | ||
const ipexMessageRecordProps: IpexMessageProps = { | ||
id: id1, | ||
credentialType: "IIW 2024 Demo Day Attendee", | ||
createdAt: now, | ||
connectionId: "connectionId", | ||
content: ipexMessage, | ||
historyType: ConnectionHistoryType.CREDENTIAL_ISSUANCE, | ||
}; | ||
|
||
const ipexMessageRecordA = new IpexMessageRecord(ipexMessageRecordProps); | ||
|
||
const ipexMessageRecordB = new IpexMessageRecord({ | ||
...ipexMessageRecordProps, | ||
id: id2, | ||
historyType: ConnectionHistoryType.CREDENTIAL_UPDATE, | ||
}); | ||
|
||
describe("ipexMessage Storage", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test("Should save ipexMessage record", async () => { | ||
storageService.save.mockResolvedValue(ipexMessageRecordA); | ||
await ipexMessageStorage.createIpexMessageRecord(ipexMessageRecordProps); | ||
expect(storageService.save).toBeCalledWith(ipexMessageRecordA); | ||
}); | ||
|
||
test("Should find ipexMessage record by id", async () => { | ||
storageService.findById.mockResolvedValue(ipexMessageRecordB); | ||
const result = await ipexMessageStorage.getIpexMessageMetadata( | ||
ipexMessageRecordB.connectionId | ||
); | ||
expect(result).toEqual(ipexMessageRecordB); | ||
}); | ||
|
||
test("Should throw error if there is no matching record", async () => { | ||
storageService.findById.mockResolvedValue(null); | ||
await expect( | ||
ipexMessageStorage.getIpexMessageMetadata("not-found-id") | ||
).rejects.toThrowError( | ||
IpexMessageStorage.IPEX_MESSAGE_METADATA_RECORD_MISSING | ||
); | ||
}); | ||
|
||
test("Should find ipexMessage record by connectionId", async () => { | ||
storageService.findAllByQuery.mockResolvedValue([ | ||
ipexMessageRecordA, | ||
ipexMessageRecordB, | ||
]); | ||
const result = | ||
await ipexMessageStorage.getIpexMessageMetadataByConnectionId( | ||
ipexMessageRecordA.connectionId | ||
); | ||
expect(result).toEqual([ipexMessageRecordA, ipexMessageRecordB]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { StorageService } from "../../storage/storage.types"; | ||
import { IpexMessageProps, IpexMessageRecord } from "./ipexMessageRecord"; | ||
|
||
class IpexMessageStorage { | ||
static readonly IPEX_MESSAGE_METADATA_RECORD_MISSING = | ||
"Ipex message metadata record does not exist"; | ||
private storageService: StorageService<IpexMessageRecord>; | ||
|
||
constructor(storageService: StorageService<IpexMessageRecord>) { | ||
this.storageService = storageService; | ||
} | ||
|
||
async createIpexMessageRecord(data: IpexMessageProps): Promise<void> { | ||
const record = new IpexMessageRecord(data); | ||
await this.storageService.save(record); | ||
} | ||
|
||
async getIpexMessageMetadata(id: string): Promise<IpexMessageRecord> { | ||
const metadata = await this.storageService.findById(id, IpexMessageRecord); | ||
if (!metadata) { | ||
throw new Error(IpexMessageStorage.IPEX_MESSAGE_METADATA_RECORD_MISSING); | ||
} | ||
return metadata; | ||
} | ||
|
||
async getIpexMessageMetadataByConnectionId( | ||
connectionId: string | ||
): Promise<IpexMessageRecord[]> { | ||
const records = await this.storageService.findAllByQuery( | ||
{ | ||
connectionId, | ||
}, | ||
IpexMessageRecord | ||
); | ||
return records; | ||
} | ||
} | ||
|
||
export { IpexMessageStorage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.