@nmshd/connector-tui 2.5.1 → 2.7.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),
|
|
@@ -519,32 +523,55 @@ export function AddSendRequestByMessage(Base) {
|
|
|
519
523
|
message: "What's the consent the peer should agree to?",
|
|
520
524
|
type: "text",
|
|
521
525
|
name: "consent",
|
|
526
|
+
format: (value) => value.replaceAll("\\n", "\n"),
|
|
527
|
+
validate: (value) => (value.length < 1 ? "Consent must not be empty" : true),
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
message: "[Optional] Enter a description for the consent",
|
|
531
|
+
type: "text",
|
|
532
|
+
name: "description",
|
|
533
|
+
format: (value) => (value.length > 0 ? value.replaceAll("\\n", "\n") : undefined),
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
message: "Does the consent have to be accepted?",
|
|
537
|
+
type: "confirm",
|
|
538
|
+
name: "mustBeAccepted",
|
|
539
|
+
initial: true,
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
message: "Do you want to require a manual decision?",
|
|
543
|
+
type: "confirm",
|
|
544
|
+
name: "requireManualDecision",
|
|
545
|
+
initial: false,
|
|
522
546
|
},
|
|
523
547
|
{
|
|
524
548
|
message: "[Optional] Enter the URL to to the consent details?",
|
|
525
549
|
type: "text",
|
|
526
550
|
name: "link",
|
|
551
|
+
format: (value) => (value.length > 0 ? value : undefined),
|
|
527
552
|
},
|
|
528
553
|
{
|
|
529
554
|
message: "[Optional] Enter a link display text",
|
|
530
555
|
type: "text",
|
|
531
556
|
name: "linkDisplayText",
|
|
557
|
+
format: (value) => (value.length > 0 ? value : undefined),
|
|
532
558
|
},
|
|
533
559
|
{
|
|
534
560
|
message: "[Optional] Enter a consentKey to know which consent the user agreed to",
|
|
535
561
|
type: "text",
|
|
536
|
-
name: "
|
|
562
|
+
name: "responseMetadata",
|
|
563
|
+
format: (value) => (value.length > 0 ? { consentKey: value } : undefined),
|
|
537
564
|
},
|
|
538
565
|
]);
|
|
539
|
-
const responseMetadata = result.consentKey ? { consentKey: result.consentKey } : undefined;
|
|
540
|
-
const link = result.link ?? undefined;
|
|
541
566
|
const requestItem = {
|
|
542
567
|
"@type": "ConsentRequestItem",
|
|
543
|
-
mustBeAccepted:
|
|
568
|
+
mustBeAccepted: result.mustBeAccepted,
|
|
569
|
+
requireManualDecision: result.requireManualDecision,
|
|
544
570
|
consent: result.consent,
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
571
|
+
description: result.description,
|
|
572
|
+
link: result.link,
|
|
573
|
+
linkDisplayText: result.link ? result.linkDisplayText : undefined,
|
|
574
|
+
metadata: result.responseMetadata,
|
|
548
575
|
};
|
|
549
576
|
return requestItem;
|
|
550
577
|
}
|
|
@@ -576,15 +603,15 @@ export function AddSendRequestByMessage(Base) {
|
|
|
576
603
|
{
|
|
577
604
|
message: "[Optional] Enter an unique authenticationToken to know which authentication did the user grant",
|
|
578
605
|
type: "text",
|
|
579
|
-
name: "
|
|
606
|
+
name: "responseMetadata",
|
|
607
|
+
format: (value) => (value.length > 0 ? { authenticationToken: value } : undefined),
|
|
580
608
|
},
|
|
581
609
|
]);
|
|
582
|
-
const responseMetadata = result.authenticationToken ? { authenticationToken: result.authenticationToken } : undefined;
|
|
583
610
|
const requestItem = {
|
|
584
611
|
"@type": "AuthenticationRequestItem",
|
|
585
612
|
mustBeAccepted: true,
|
|
586
613
|
title: result.title,
|
|
587
|
-
metadata: responseMetadata,
|
|
614
|
+
metadata: result.responseMetadata,
|
|
588
615
|
};
|
|
589
616
|
return requestItem;
|
|
590
617
|
}
|
|
@@ -603,16 +630,29 @@ export function AddSendRequestByMessage(Base) {
|
|
|
603
630
|
};
|
|
604
631
|
return requestItem;
|
|
605
632
|
}
|
|
633
|
+
async createShareAttributeRequestItem() {
|
|
634
|
+
const query = { content: { "@type": "IdentityAttribute", owner: this.connectorAddress }, shareInfo: { peer: "!" }, succeededBy: "!" };
|
|
635
|
+
const attribute = await this.selectAttribute("Which Attribute would you like to share?", query);
|
|
636
|
+
if (!attribute)
|
|
637
|
+
return;
|
|
638
|
+
const requestItem = {
|
|
639
|
+
"@type": "ShareAttributeRequestItem",
|
|
640
|
+
mustBeAccepted: true,
|
|
641
|
+
sourceAttributeId: attribute.id,
|
|
642
|
+
attribute: attribute.content,
|
|
643
|
+
};
|
|
644
|
+
return requestItem;
|
|
645
|
+
}
|
|
606
646
|
async createTransferFileOwnershipRequestItem() {
|
|
607
647
|
const file = await this.selectFile("The ownership of which File do you want to transfer?");
|
|
648
|
+
if (!file)
|
|
649
|
+
return;
|
|
608
650
|
const result = await prompts({
|
|
609
651
|
name: "requireManualDecision",
|
|
610
652
|
message: "Do you want to require a manual decision?",
|
|
611
653
|
initial: false,
|
|
612
654
|
type: "confirm",
|
|
613
655
|
});
|
|
614
|
-
if (!file)
|
|
615
|
-
return;
|
|
616
656
|
const requestItem = {
|
|
617
657
|
"@type": "TransferFileOwnershipRequestItem",
|
|
618
658
|
mustBeAccepted: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nmshd/connector-tui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"repository": "github:nmshd/connector-tui",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "j&s-soft AG",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"watch": "node --watch --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' src/run.ts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nmshd/connector-sdk": "^6.
|
|
32
|
+
"@nmshd/connector-sdk": "^6.23.0",
|
|
33
33
|
"axios": "^1.8.4",
|
|
34
34
|
"chalk": "^5.4.1",
|
|
35
|
-
"dotenv": "^16.
|
|
35
|
+
"dotenv": "^16.5.0",
|
|
36
36
|
"luxon": "^3.6.1",
|
|
37
37
|
"prompts": "^2.4.2",
|
|
38
38
|
"qrcode-terminal": "^0.12.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@js-soft/eslint-config-ts": "^1.6.14",
|
|
43
43
|
"@js-soft/license-check": "^1.0.9",
|
|
44
44
|
"@types/luxon": "^3.6.2",
|
|
45
|
-
"@types/node": "^22.14.
|
|
45
|
+
"@types/node": "^22.14.1",
|
|
46
46
|
"@types/prompts": "^2.4.9",
|
|
47
47
|
"@types/qrcode-terminal": "^0.12.2",
|
|
48
48
|
"@types/yargs": "^17.0.33",
|