@nmshd/connector-tui 2.5.0 → 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),
|
|
@@ -99,7 +103,17 @@ export function AddSendRequestByMessage(Base) {
|
|
|
99
103
|
},
|
|
100
104
|
});
|
|
101
105
|
if (response.isError) {
|
|
102
|
-
|
|
106
|
+
console.error("Error while creating LocalRequest", response.error);
|
|
107
|
+
const details = await this.connectorClient.outgoingRequests.canCreateRequest({
|
|
108
|
+
peer,
|
|
109
|
+
content: {
|
|
110
|
+
title: "The title of the Request",
|
|
111
|
+
description: "The description of the Request",
|
|
112
|
+
items: requestItems,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
console.log("Details: ", details.result);
|
|
116
|
+
return;
|
|
103
117
|
}
|
|
104
118
|
const messageResponse = await this.connectorClient.messages.sendMessage({
|
|
105
119
|
recipients: [peer],
|
|
@@ -593,14 +607,34 @@ export function AddSendRequestByMessage(Base) {
|
|
|
593
607
|
};
|
|
594
608
|
return requestItem;
|
|
595
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
|
+
}
|
|
596
623
|
async createTransferFileOwnershipRequestItem() {
|
|
597
|
-
const
|
|
598
|
-
if (!
|
|
624
|
+
const file = await this.selectFile("The ownership of which File do you want to transfer?");
|
|
625
|
+
if (!file)
|
|
599
626
|
return;
|
|
627
|
+
const result = await prompts({
|
|
628
|
+
name: "requireManualDecision",
|
|
629
|
+
message: "Do you want to require a manual decision?",
|
|
630
|
+
initial: false,
|
|
631
|
+
type: "confirm",
|
|
632
|
+
});
|
|
600
633
|
const requestItem = {
|
|
601
634
|
"@type": "TransferFileOwnershipRequestItem",
|
|
602
635
|
mustBeAccepted: true,
|
|
603
|
-
|
|
636
|
+
requireManualDecision: result.requireManualDecision,
|
|
637
|
+
fileReference: file.truncatedReference,
|
|
604
638
|
};
|
|
605
639
|
return requestItem;
|
|
606
640
|
}
|