@nmshd/connector-tui 2.5.1 → 2.6.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/dist/ConnectorTUIBase.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConnectorRelationshipStatus } from "@nmshd/connector-sdk";
|
|
1
|
+
import { ConnectorRelationshipStatus, } from "@nmshd/connector-sdk";
|
|
2
2
|
import prompts from "prompts";
|
|
3
3
|
import { IdentityDeletionProcessEndpoint } from "./IdentityDeletionProcessEndpoint.js";
|
|
4
4
|
export class ConnectorTUIBase {
|
|
@@ -95,6 +95,32 @@ export class ConnectorTUIBase {
|
|
|
95
95
|
renderFile(file) {
|
|
96
96
|
return { title: file.title, value: file };
|
|
97
97
|
}
|
|
98
|
+
async selectAttribute(prompt, query) {
|
|
99
|
+
const choices = await this.getAttributeChoices(query);
|
|
100
|
+
if (!choices)
|
|
101
|
+
return;
|
|
102
|
+
const attributesResult = await prompts({ message: prompt, type: "select", name: "attribute", choices });
|
|
103
|
+
return attributesResult.attribute;
|
|
104
|
+
}
|
|
105
|
+
async getAttributeChoices(query) {
|
|
106
|
+
const attributesResult = await this.connectorClient.attributes.getAttributes(query ?? {});
|
|
107
|
+
if (attributesResult.isError) {
|
|
108
|
+
console.error(attributesResult.error);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const attributes = attributesResult.result;
|
|
112
|
+
if (attributes.length === 0) {
|
|
113
|
+
console.log("No matching Attributes found");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const choices = await Promise.all(attributes.map((attribute) => this.renderAttribute(attribute)));
|
|
117
|
+
return choices;
|
|
118
|
+
}
|
|
119
|
+
renderAttribute(attribute) {
|
|
120
|
+
const attributeValueType = attribute.content.value["@type"];
|
|
121
|
+
const attributeValue = "value" in attribute.content.value ? attribute.content.value.value : JSON.stringify(attribute.content.value);
|
|
122
|
+
return { title: `${attributeValueType}: ${attributeValue} `, value: attribute };
|
|
123
|
+
}
|
|
98
124
|
isDebugMode() {
|
|
99
125
|
return this.support.configuration.debug;
|
|
100
126
|
}
|
|
@@ -67,6 +67,10 @@ export function AddSendRequestByMessage(Base) {
|
|
|
67
67
|
title: "FreeTextRequestItem",
|
|
68
68
|
value: this.createFreeTextRequestItem.bind(this),
|
|
69
69
|
},
|
|
70
|
+
{
|
|
71
|
+
title: "ShareAttributeRequestItem",
|
|
72
|
+
value: this.createShareAttributeRequestItem.bind(this),
|
|
73
|
+
},
|
|
70
74
|
{
|
|
71
75
|
title: "TransferFileOwnershipRequestItem",
|
|
72
76
|
value: this.createTransferFileOwnershipRequestItem.bind(this),
|
|
@@ -603,16 +607,29 @@ export function AddSendRequestByMessage(Base) {
|
|
|
603
607
|
};
|
|
604
608
|
return requestItem;
|
|
605
609
|
}
|
|
610
|
+
async createShareAttributeRequestItem() {
|
|
611
|
+
const query = { content: { "@type": "IdentityAttribute", owner: this.connectorAddress }, shareInfo: { peer: "!" }, succeededBy: "!" };
|
|
612
|
+
const attribute = await this.selectAttribute("Which Attribute would you like to share?", query);
|
|
613
|
+
if (!attribute)
|
|
614
|
+
return;
|
|
615
|
+
const requestItem = {
|
|
616
|
+
"@type": "ShareAttributeRequestItem",
|
|
617
|
+
mustBeAccepted: true,
|
|
618
|
+
sourceAttributeId: attribute.id,
|
|
619
|
+
attribute: attribute.content,
|
|
620
|
+
};
|
|
621
|
+
return requestItem;
|
|
622
|
+
}
|
|
606
623
|
async createTransferFileOwnershipRequestItem() {
|
|
607
624
|
const file = await this.selectFile("The ownership of which File do you want to transfer?");
|
|
625
|
+
if (!file)
|
|
626
|
+
return;
|
|
608
627
|
const result = await prompts({
|
|
609
628
|
name: "requireManualDecision",
|
|
610
629
|
message: "Do you want to require a manual decision?",
|
|
611
630
|
initial: false,
|
|
612
631
|
type: "confirm",
|
|
613
632
|
});
|
|
614
|
-
if (!file)
|
|
615
|
-
return;
|
|
616
633
|
const requestItem = {
|
|
617
634
|
"@type": "TransferFileOwnershipRequestItem",
|
|
618
635
|
mustBeAccepted: true,
|