-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { ConnectorRelationshipStatus } from "@nmshd/connector-sdk" | ||
import { ShareAttributeRequestItemJSON } from "@nmshd/content" | ||
import fs from "fs" | ||
import { ConnectorTUIBaseConstructor } from "../ConnectorTUIBase.js" | ||
|
||
export function AddNMSHDS152<TBase extends ConnectorTUIBaseConstructor>(Base: TBase) { | ||
return class NMSHDS152 extends Base { | ||
public constructor(...args: any[]) { | ||
super(...args) | ||
this.choices.push({ title: "NMSHDS-152", value: this.NMSHDS152 }) | ||
} | ||
|
||
protected async NMSHDS152() { | ||
await this.connectorClient.account.sync() | ||
|
||
const relationship = await this.selectRelationship("Select relationship to test", ConnectorRelationshipStatus.Active) | ||
if (!relationship) return | ||
|
||
console.log(`Testing NMSHDS-152 with relationship ${relationship.peer}`) | ||
const title = "Schulabschlusszeugnis"; | ||
const description = "Schulabschlusszeugnis"; | ||
const expiresAt = "2030"; | ||
const filename = "Schulabschlusszeugnis.pdf"; | ||
const file = await fs.promises.readFile("__assets__/aPdf.pdf"); | ||
const fileUploadResult = this.connectorClient.files.uploadOwnFile({ title, expiresAt, file, filename, description }); | ||
const fileTruncatedReference = ((await fileUploadResult).result.truncatedReference); | ||
const createFileAttributeResponse = await this.connectorClient.attributes.createRepositoryAttribute({ | ||
content: { | ||
value: { | ||
"@type": "IdentityFileReference", | ||
value: fileTruncatedReference | ||
}, | ||
tags: ["Schulabschlusszeugnis"] | ||
} | ||
}); | ||
const schulabschlusszeugnisRequestItem: ShareAttributeRequestItemJSON = { | ||
"@type": "ShareAttributeRequestItem", | ||
mustBeAccepted: false, | ||
attribute: { | ||
"@type": "IdentityAttribute", | ||
owner: createFileAttributeResponse.result.content.owner, | ||
value: { | ||
"@type": "IdentityFileReference", | ||
value: fileTruncatedReference | ||
}, | ||
tags: ["Schulabschlusszeugnis"] | ||
}, | ||
sourceAttributeId: createFileAttributeResponse.result.id | ||
} | ||
|
||
const requstResult = await this.connectorClient.outgoingRequests.createRequest( | ||
{ | ||
content: { | ||
"@type": "Request", | ||
items: [ | ||
{ | ||
"@type": "ProposeAttributeRequestItem", | ||
"attribute": { | ||
"@type": "IdentityAttribute", | ||
"owner": "", | ||
"value": { | ||
"@type": "PersonName", | ||
"givenName": "Max", | ||
"surname": "Mustermann" | ||
} | ||
}, | ||
"mustBeAccepted": false, | ||
"query": { | ||
"@type": "IdentityAttributeQuery", | ||
"valueType": "PersonName" | ||
} | ||
}, | ||
schulabschlusszeugnisRequestItem | ||
], | ||
id: "applicationSetup" | ||
}, | ||
peer: relationship.peer, | ||
} | ||
) | ||
if (requstResult.isError) { | ||
console.error(`Failed: ${JSON.stringify(requstResult.error)}`) | ||
return | ||
} | ||
const messageResponse = await this.connectorClient.messages.sendMessage( | ||
{ | ||
content: requstResult.result.content, | ||
recipients: [relationship.peer] | ||
}, | ||
); | ||
if (messageResponse.isError) { | ||
console.error(`Failed: ${JSON.stringify(requstResult.error)}`) | ||
return | ||
} | ||
} | ||
} | ||
} |
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