@nmshd/connector-tui 2.0.2 → 2.2.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/ConnectorTUI.js +13 -4
- package/dist/ConnectorTUIBase.js +10 -1
- package/dist/IdentityDeletionProcessEndpoint.js +19 -0
- package/dist/mixins/AddIdentityDeletionProcess.js +68 -0
- package/dist/mixins/AddSendRequestByMessage.js +44 -0
- package/dist/mixins/AddShareRequestByTemplate.js +46 -2
- package/dist/mixins/ConnectorTUIBaseWithMixins.js +3 -3
- package/dist/mixins/index.js +1 -0
- package/package.json +8 -7
package/dist/ConnectorTUI.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ConnectorClient } from "@nmshd/connector-sdk";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { readFile } from "fs/promises";
|
|
4
|
+
import { DateTime } from "luxon";
|
|
4
5
|
import prompts from "prompts";
|
|
5
6
|
import { ConnectorTUIBaseWithMixins } from "./mixins/index.js";
|
|
6
7
|
export class ConnectorTUI extends ConnectorTUIBaseWithMixins {
|
|
7
8
|
static async create(baseUrl, apiKey) {
|
|
8
9
|
const client = ConnectorClient.create({ baseUrl, apiKey });
|
|
9
10
|
const address = (await client.account.getIdentityInfo()).result.address;
|
|
10
|
-
|
|
11
|
+
const support = await client.monitoring.getSupport();
|
|
12
|
+
return new ConnectorTUI(client, address, support);
|
|
11
13
|
}
|
|
12
14
|
async run() {
|
|
13
15
|
const connectorVersionInfo = await this.checkConnectorVersion();
|
|
@@ -16,11 +18,19 @@ export class ConnectorTUI extends ConnectorTUIBaseWithMixins {
|
|
|
16
18
|
await this.showStartupMessage(connectorVersionInfo);
|
|
17
19
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition
|
|
18
20
|
while (true) {
|
|
21
|
+
const activeIdentityDeletionProcess = this.isDebugMode() ? await this.identityDeletionProcessEndpoint.getActiveIdentityDeletionProcess() : undefined;
|
|
22
|
+
if (activeIdentityDeletionProcess?.isSuccess && activeIdentityDeletionProcess.result.status === "Approved") {
|
|
23
|
+
const gracePeriodEndsAtDateTime = DateTime.fromISO(activeIdentityDeletionProcess.result.gracePeriodEndsAt);
|
|
24
|
+
if (gracePeriodEndsAtDateTime.diffNow().milliseconds < 0) {
|
|
25
|
+
console.log(chalk.red("Grace period has ended. Identity is deleted."));
|
|
26
|
+
process.exit(0);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
19
29
|
const result = await prompts({
|
|
20
30
|
type: "select",
|
|
21
31
|
name: "action",
|
|
22
32
|
message: "What do you want to do?",
|
|
23
|
-
choices: this.choices,
|
|
33
|
+
choices: activeIdentityDeletionProcess?.isSuccess ? this.choicesInDeletion : this.choices,
|
|
24
34
|
});
|
|
25
35
|
if (!result.action)
|
|
26
36
|
break;
|
|
@@ -46,8 +56,7 @@ export class ConnectorTUI extends ConnectorTUIBaseWithMixins {
|
|
|
46
56
|
async showStartupMessage(connectorVersionInfo) {
|
|
47
57
|
const jsonString = (await readFile(new URL("../package.json", import.meta.url))).toString();
|
|
48
58
|
const packageJson = JSON.parse(jsonString);
|
|
49
|
-
const
|
|
50
|
-
const baseUrl = support.configuration.transportLibrary?.baseUrl;
|
|
59
|
+
const baseUrl = this.support.configuration.transportLibrary?.baseUrl;
|
|
51
60
|
console.log(`Welcome to the ${chalk.blue("enmeshed V2 TUI")}!`);
|
|
52
61
|
console.log(`TUI Version: ${chalk.yellow(packageJson.version)}`);
|
|
53
62
|
console.log(`Connector version: ${chalk.yellow(connectorVersionInfo.version)}`);
|
package/dist/ConnectorTUIBase.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { ConnectorRelationshipStatus } from "@nmshd/connector-sdk";
|
|
2
2
|
import prompts from "prompts";
|
|
3
|
+
import { IdentityDeletionProcessEndpoint } from "./IdentityDeletionProcessEndpoint";
|
|
3
4
|
export class ConnectorTUIBase {
|
|
4
5
|
connectorClient;
|
|
5
6
|
connectorAddress;
|
|
7
|
+
support;
|
|
6
8
|
choices = [];
|
|
7
|
-
|
|
9
|
+
choicesInDeletion = [];
|
|
10
|
+
identityDeletionProcessEndpoint;
|
|
11
|
+
constructor(connectorClient, connectorAddress, support) {
|
|
8
12
|
this.connectorClient = connectorClient;
|
|
9
13
|
this.connectorAddress = connectorAddress;
|
|
14
|
+
this.support = support;
|
|
15
|
+
this.identityDeletionProcessEndpoint = new IdentityDeletionProcessEndpoint(this.connectorClient.account["httpClient"]);
|
|
10
16
|
}
|
|
11
17
|
async selectRelationship(prompt, ...status) {
|
|
12
18
|
if (status.length === 0)
|
|
@@ -89,4 +95,7 @@ export class ConnectorTUIBase {
|
|
|
89
95
|
renderFile(file) {
|
|
90
96
|
return { title: file.title, value: file };
|
|
91
97
|
}
|
|
98
|
+
isDebugMode() {
|
|
99
|
+
return this.support.configuration.debug;
|
|
100
|
+
}
|
|
92
101
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Endpoint } from "@nmshd/connector-sdk/dist/endpoints/Endpoint";
|
|
2
|
+
export var IdentityDeletionProcessStatus;
|
|
3
|
+
(function (IdentityDeletionProcessStatus) {
|
|
4
|
+
IdentityDeletionProcessStatus["WaitingForApproval"] = "WaitingForApproval";
|
|
5
|
+
IdentityDeletionProcessStatus["Rejected"] = "Rejected";
|
|
6
|
+
IdentityDeletionProcessStatus["Approved"] = "Approved";
|
|
7
|
+
IdentityDeletionProcessStatus["Cancelled"] = "Cancelled";
|
|
8
|
+
})(IdentityDeletionProcessStatus || (IdentityDeletionProcessStatus = {}));
|
|
9
|
+
export class IdentityDeletionProcessEndpoint extends Endpoint {
|
|
10
|
+
async initiateIdentityDeletionProcess(lengthOfGracePeriodInDays) {
|
|
11
|
+
return await this.post("/api/v2/IdentityDeletionProcess", undefined, 200, { lengthOfGracePeriodInDays });
|
|
12
|
+
}
|
|
13
|
+
async getActiveIdentityDeletionProcess() {
|
|
14
|
+
return await this.get("/api/v2/IdentityDeletionProcess");
|
|
15
|
+
}
|
|
16
|
+
async cancelIdentityDeletionProcess() {
|
|
17
|
+
return await this.delete("/api/v2/IdentityDeletionProcess", undefined, 200);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { DateTime } from "luxon";
|
|
3
|
+
import prompts from "prompts";
|
|
4
|
+
export function AddIdentityDeletionProcess(Base) {
|
|
5
|
+
return class IdentityDeletionProcessHandler extends Base {
|
|
6
|
+
constructor(...args) {
|
|
7
|
+
super(...args);
|
|
8
|
+
if (!this.isDebugMode())
|
|
9
|
+
return;
|
|
10
|
+
const identityDeletionProcessChoices = { title: "IdentityDeletionProcess", value: this.identityDeletionProcess };
|
|
11
|
+
this.choices.push(identityDeletionProcessChoices);
|
|
12
|
+
this.choicesInDeletion.push(identityDeletionProcessChoices);
|
|
13
|
+
}
|
|
14
|
+
async identityDeletionProcess() {
|
|
15
|
+
const choices = [];
|
|
16
|
+
const activeIdentityDeletionProcess = await this.identityDeletionProcessEndpoint.getActiveIdentityDeletionProcess();
|
|
17
|
+
if (activeIdentityDeletionProcess.isSuccess) {
|
|
18
|
+
choices.push({ title: "Show IdentityDeletionProcess", value: "Show" });
|
|
19
|
+
if (activeIdentityDeletionProcess.result.status === "Approved") {
|
|
20
|
+
choices.push({ title: "Cancel IdentityDeletionProcess", value: "Cancel" });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
choices.push({ title: "Init IdentityDeletionProcess", value: "Init" });
|
|
25
|
+
}
|
|
26
|
+
const result = await prompts({
|
|
27
|
+
message: "Identity Deletion Process",
|
|
28
|
+
type: "select",
|
|
29
|
+
name: "Identity Deletion Process",
|
|
30
|
+
choices,
|
|
31
|
+
});
|
|
32
|
+
switch (result["Identity Deletion Process"]) {
|
|
33
|
+
case "Show":
|
|
34
|
+
this.showIdentityDeletionProcesses(activeIdentityDeletionProcess.result);
|
|
35
|
+
break;
|
|
36
|
+
case "Init":
|
|
37
|
+
await this.initIdentityDeletionProcess();
|
|
38
|
+
break;
|
|
39
|
+
case "Cancel":
|
|
40
|
+
await this.cancelIdentityDeletionProcess();
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async initIdentityDeletionProcess() {
|
|
45
|
+
const confirmation = await prompts({
|
|
46
|
+
message: "Do you want to delete the identity immediately (Grace period will be one second)?",
|
|
47
|
+
type: "confirm",
|
|
48
|
+
name: "IdentityDeletionProcess grace period",
|
|
49
|
+
});
|
|
50
|
+
const oneSecondInDays = 1 / (24 * 60 * 60);
|
|
51
|
+
const lengthOfGracePeriodInDays = confirmation["IdentityDeletionProcess grace period"] ? oneSecondInDays : undefined;
|
|
52
|
+
const identityDeletionProcess = (await this.identityDeletionProcessEndpoint.initiateIdentityDeletionProcess(lengthOfGracePeriodInDays)).result;
|
|
53
|
+
console.log("Identity Deletion Process initiated.");
|
|
54
|
+
this.showIdentityDeletionProcesses(identityDeletionProcess);
|
|
55
|
+
}
|
|
56
|
+
async cancelIdentityDeletionProcess() {
|
|
57
|
+
const identityDeletionProcess = (await this.identityDeletionProcessEndpoint.cancelIdentityDeletionProcess()).result;
|
|
58
|
+
console.log("Identity Deletion Process canceled.");
|
|
59
|
+
this.showIdentityDeletionProcesses(identityDeletionProcess);
|
|
60
|
+
}
|
|
61
|
+
showIdentityDeletionProcesses(identityDeletionProcess) {
|
|
62
|
+
console.log(`Identity deletion status: ${chalk.yellow(identityDeletionProcess.status)}`);
|
|
63
|
+
if (identityDeletionProcess.status === "Approved") {
|
|
64
|
+
console.log(`End of grace period: ${chalk.yellow(DateTime.fromISO(identityDeletionProcess.gracePeriodEndsAt).toLocaleString())}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -31,6 +31,10 @@ export function AddSendRequestByMessage(Base) {
|
|
|
31
31
|
title: "ProposeAttributeRequestItem",
|
|
32
32
|
value: this.createProposeAttributeRequestItem.bind(this),
|
|
33
33
|
},
|
|
34
|
+
{
|
|
35
|
+
title: "ProposeAttributeRequestItem with RelationshipAttribute",
|
|
36
|
+
value: this.createProposeRelationshipAttributeRequestItem.bind(this),
|
|
37
|
+
},
|
|
34
38
|
{
|
|
35
39
|
title: "IQLProposeAttributeRequestItem",
|
|
36
40
|
value: this.createIQLProposeAttributeRequestItem.bind(this),
|
|
@@ -301,6 +305,46 @@ export function AddSendRequestByMessage(Base) {
|
|
|
301
305
|
};
|
|
302
306
|
return requestItem;
|
|
303
307
|
}
|
|
308
|
+
async createProposeRelationshipAttributeRequestItem() {
|
|
309
|
+
const result = await prompts([
|
|
310
|
+
{
|
|
311
|
+
message: "What's the title of your Attribute?",
|
|
312
|
+
type: "text",
|
|
313
|
+
name: "title",
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
message: "What's the value of your Attribute?",
|
|
317
|
+
type: "text",
|
|
318
|
+
name: "value",
|
|
319
|
+
},
|
|
320
|
+
]);
|
|
321
|
+
const requestItem = {
|
|
322
|
+
"@type": "ProposeAttributeRequestItem",
|
|
323
|
+
mustBeAccepted: true,
|
|
324
|
+
query: {
|
|
325
|
+
"@type": "RelationshipAttributeQuery",
|
|
326
|
+
attributeCreationHints: {
|
|
327
|
+
title: result.title,
|
|
328
|
+
confidentiality: RelationshipAttributeConfidentiality.Public,
|
|
329
|
+
valueType: "ProprietaryString",
|
|
330
|
+
},
|
|
331
|
+
key: "aKey",
|
|
332
|
+
owner: "",
|
|
333
|
+
},
|
|
334
|
+
attribute: {
|
|
335
|
+
"@type": "RelationshipAttribute",
|
|
336
|
+
owner: "",
|
|
337
|
+
key: "aKey",
|
|
338
|
+
confidentiality: RelationshipAttributeConfidentiality.Public,
|
|
339
|
+
value: {
|
|
340
|
+
"@type": "ProprietaryString",
|
|
341
|
+
title: result.title,
|
|
342
|
+
value: result.value,
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
return requestItem;
|
|
347
|
+
}
|
|
304
348
|
async createIQLProposeAttributeRequestItem() {
|
|
305
349
|
const result = await prompts([
|
|
306
350
|
{
|
|
@@ -62,7 +62,8 @@ export function AddShareRequestByTemplate(Base) {
|
|
|
62
62
|
if (result.includeName)
|
|
63
63
|
request.items.push(sharedAttributes);
|
|
64
64
|
request.items.push(requestedAttributes);
|
|
65
|
-
await this.
|
|
65
|
+
const passwordProtection = await this.createPasswordProtection();
|
|
66
|
+
await this.createQRCodeForRelationshipTemplate(request, name, passwordProtection);
|
|
66
67
|
}
|
|
67
68
|
async getOrCreateConnectorDisplayName(displayName) {
|
|
68
69
|
const response = await this.connectorClient.attributes.getValidAttributes({
|
|
@@ -89,7 +90,49 @@ export function AddShareRequestByTemplate(Base) {
|
|
|
89
90
|
});
|
|
90
91
|
return createAttributeResponse.result;
|
|
91
92
|
}
|
|
92
|
-
async
|
|
93
|
+
async createPasswordProtection() {
|
|
94
|
+
const result = await prompts({
|
|
95
|
+
message: "What kind of password protection do you want to use?",
|
|
96
|
+
type: "select",
|
|
97
|
+
name: "passwordProtection",
|
|
98
|
+
choices: [
|
|
99
|
+
{ title: "None", value: "None", selected: true },
|
|
100
|
+
{ title: "Password", value: "Password" },
|
|
101
|
+
{ title: "PIN", value: "PIN" },
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
if (result.passwordProtection === "None")
|
|
105
|
+
return;
|
|
106
|
+
if (result.passwordProtection === "Password") {
|
|
107
|
+
const password = await prompts({
|
|
108
|
+
message: "Enter the password",
|
|
109
|
+
type: "text",
|
|
110
|
+
validate: (value) => {
|
|
111
|
+
if (value.length < 1)
|
|
112
|
+
return "Password must have at least 1 character";
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
name: "password",
|
|
116
|
+
});
|
|
117
|
+
return { password: password.password };
|
|
118
|
+
}
|
|
119
|
+
const password = await prompts({
|
|
120
|
+
message: "Enter the PIN",
|
|
121
|
+
type: "text",
|
|
122
|
+
validate: (value) => {
|
|
123
|
+
if (!/^\d+$/.test(value))
|
|
124
|
+
return "PIN must only contain digits";
|
|
125
|
+
if (value.length < 4)
|
|
126
|
+
return "PIN must have at least 4 digits";
|
|
127
|
+
if (value.length > 16)
|
|
128
|
+
return "PIN must have at most 16 digits";
|
|
129
|
+
return true;
|
|
130
|
+
},
|
|
131
|
+
name: "password",
|
|
132
|
+
});
|
|
133
|
+
return { password: password.password, passwordIsPin: true };
|
|
134
|
+
}
|
|
135
|
+
async createQRCodeForRelationshipTemplate(request, name, passwordProtection) {
|
|
93
136
|
const content = {
|
|
94
137
|
"@type": "RelationshipTemplateContent",
|
|
95
138
|
title: `Kontaktanfrage mit ${name}`,
|
|
@@ -101,6 +144,7 @@ export function AddShareRequestByTemplate(Base) {
|
|
|
101
144
|
const template = await this.connectorClient.relationshipTemplates.createOwnRelationshipTemplate({
|
|
102
145
|
content,
|
|
103
146
|
expiresAt: DateTime.now().plus({ days: 2 }).toISO(),
|
|
147
|
+
passwordProtection,
|
|
104
148
|
});
|
|
105
149
|
const url = `nmshd://tr#${template.result.truncatedReference}`;
|
|
106
150
|
console.log(url);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConnectorTUIBase } from "../ConnectorTUIBase.js";
|
|
2
|
-
import { AddAcceptPendingRelationships, AddAcceptPendingRequests, AddConnectorInfo, AddCreateAndShowTemplate, AddDecomposeRelationship, AddExit, AddGetAttributesOfRelationship, AddSendMail, AddSendRequestByMessage, AddShareRequestByTemplate, AddSync, AddTerminateRelationship, AddUploadFile, } from "./index.js";
|
|
2
|
+
import { AddAcceptPendingRelationships, AddAcceptPendingRequests, AddConnectorInfo, AddCreateAndShowTemplate, AddDecomposeRelationship, AddExit, AddGetAttributesOfRelationship, AddIdentityDeletionProcess, AddSendMail, AddSendRequestByMessage, AddShareRequestByTemplate, AddSync, AddTerminateRelationship, AddUploadFile, } from "./index.js";
|
|
3
3
|
export class ConnectorTUIBaseWithMixins
|
|
4
4
|
//
|
|
5
|
-
extends AddExit(AddConnectorInfo(AddDecomposeRelationship(AddTerminateRelationship(AddCreateAndShowTemplate(AddAcceptPendingRelationships(AddAcceptPendingRequests(AddGetAttributesOfRelationship(AddSendMail(AddSendRequestByMessage(AddShareRequestByTemplate(AddSync(AddUploadFile(
|
|
5
|
+
extends AddExit(AddConnectorInfo(AddDecomposeRelationship(AddTerminateRelationship(AddCreateAndShowTemplate(AddAcceptPendingRelationships(AddAcceptPendingRequests(AddGetAttributesOfRelationship(AddSendMail(AddSendRequestByMessage(AddShareRequestByTemplate(AddSync(AddUploadFile(AddIdentityDeletionProcess(
|
|
6
6
|
//
|
|
7
|
-
ConnectorTUIBase))))))))))))) {
|
|
7
|
+
ConnectorTUIBase)))))))))))))) {
|
|
8
8
|
}
|
package/dist/mixins/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./AddCreateAndShowTemplate.js";
|
|
|
5
5
|
export * from "./AddDecomposeRelationship.js";
|
|
6
6
|
export * from "./AddExit.js";
|
|
7
7
|
export * from "./AddGetAttributesOfRelationship.js";
|
|
8
|
+
export * from "./AddIdentityDeletionProcess.js";
|
|
8
9
|
export * from "./AddSendMail.js";
|
|
9
10
|
export * from "./AddSendRequestByMessage.js";
|
|
10
11
|
export * from "./AddShareRequestByTemplate.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nmshd/connector-tui",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"repository": "github:nmshd/connector-tui",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "j&s-soft GmbH",
|
|
@@ -28,26 +28,27 @@
|
|
|
28
28
|
"watch": "node --watch --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' src/index.ts"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@nmshd/connector-sdk": "^6.
|
|
31
|
+
"@nmshd/connector-sdk": "^6.7.0",
|
|
32
|
+
"axios": "^1.7.9",
|
|
32
33
|
"chalk": "^5.3.0",
|
|
33
|
-
"dotenv": "^16.4.
|
|
34
|
+
"dotenv": "^16.4.7",
|
|
34
35
|
"luxon": "^3.5.0",
|
|
35
36
|
"prompts": "^2.4.2",
|
|
36
37
|
"qrcode-terminal": "^0.12.0",
|
|
37
38
|
"yargs": "^17.7.2"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@js-soft/eslint-config-ts": "^1.6.
|
|
41
|
+
"@js-soft/eslint-config-ts": "^1.6.13",
|
|
41
42
|
"@js-soft/license-check": "^1.0.9",
|
|
42
43
|
"@types/luxon": "^3.4.2",
|
|
43
|
-
"@types/node": "^22.
|
|
44
|
+
"@types/node": "^22.10.1",
|
|
44
45
|
"@types/prompts": "^2.4.9",
|
|
45
46
|
"@types/qrcode-terminal": "^0.12.2",
|
|
46
47
|
"@types/yargs": "^17.0.33",
|
|
47
48
|
"eslint": "^8.57.0",
|
|
48
|
-
"prettier": "^3.
|
|
49
|
+
"prettier": "^3.4.2",
|
|
49
50
|
"ts-node": "^10.9.2",
|
|
50
|
-
"typescript": "^5.
|
|
51
|
+
"typescript": "^5.7.2"
|
|
51
52
|
},
|
|
52
53
|
"engines": {
|
|
53
54
|
"node": ">=19.0.0"
|