@nmshd/connector-tui 1.2.5 → 2.0.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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  > A terminal user interface for Demos.
4
4
  >
5
- > Showcase how to integrate Enmeshed and use the TypeScript Connector SDK.
5
+ > Showcase how to integrate enmeshed and use the TypeScript Connector SDK.
6
6
  >
7
- > This TUI only works with Enmeshed v2 (Connector version 3.0.0+)
7
+ > This TUI only works with enmeshed v5 (Connector version 5.0.0+)
8
8
 
9
9
  ## Installation
10
10
 
@@ -37,8 +37,8 @@ export class ConnectorTUI extends ConnectorTUIBaseWithMixins {
37
37
  // allow connector in debugging mode to be used
38
38
  if (connectorVersionInfo.version === "{{version}}")
39
39
  return connectorVersionInfo;
40
- if (!(connectorVersionInfo.version.startsWith("3.") || connectorVersionInfo.version.startsWith("4."))) {
41
- console.log(`This TUI is made for Enmeshed V2 connectors (starting with version 3.0.0 of the connector). Current version: ${connectorVersionInfo.version}`);
40
+ if (!connectorVersionInfo.version.startsWith("5.")) {
41
+ console.log(`This TUI is made for enmeshed V5 connectors (starting with version 5.0.0 of the connector). Current version: ${connectorVersionInfo.version}`);
42
42
  return;
43
43
  }
44
44
  return connectorVersionInfo;
@@ -48,7 +48,7 @@ export class ConnectorTUI extends ConnectorTUIBaseWithMixins {
48
48
  const packageJson = JSON.parse(jsonString);
49
49
  const support = await this.connectorClient.monitoring.getSupport();
50
50
  const baseUrl = support.configuration.transportLibrary?.baseUrl;
51
- console.log(`Welcome to the ${chalk.blue("Enmeshed V2 TUI")}!`);
51
+ console.log(`Welcome to the ${chalk.blue("enmeshed V2 TUI")}!`);
52
52
  console.log(`TUI Version: ${chalk.yellow(packageJson.version)}`);
53
53
  console.log(`Connector version: ${chalk.yellow(connectorVersionInfo.version)}`);
54
54
  console.log(`Connector Address: ${chalk.yellow(this.connectorAddress)}`);
@@ -8,14 +8,18 @@ export class ConnectorTUIBase {
8
8
  this.connectorClient = connectorClient;
9
9
  this.connectorAddress = connectorAddress;
10
10
  }
11
- async selectRelationship(prompt, status = ConnectorRelationshipStatus.ACTIVE) {
11
+ async selectRelationship(prompt, ...status) {
12
+ if (status.length === 0)
13
+ status.push(ConnectorRelationshipStatus.Active);
12
14
  const choices = await this.getRelationshipChoices(status, true);
13
15
  if (!choices)
14
16
  return;
15
17
  const recipientsResult = await prompts({ message: prompt, type: "select", name: "recipient", choices });
16
18
  return recipientsResult.recipient;
17
19
  }
18
- async selectRelationships(prompt, status = ConnectorRelationshipStatus.ACTIVE) {
20
+ async selectRelationships(prompt, ...status) {
21
+ if (status.length === 0)
22
+ status.push(ConnectorRelationshipStatus.Active);
19
23
  const choices = await this.getRelationshipChoices(status, false);
20
24
  if (!choices)
21
25
  return;
@@ -35,7 +39,7 @@ export class ConnectorTUIBase {
35
39
  }
36
40
  const relationships = relationshipsResult.result;
37
41
  if (relationships.length === 0) {
38
- console.log(`No relationships with status '${status}' found`);
42
+ console.log(`No relationships with status ${new Intl.ListFormat("en", { style: "long", type: "disjunction" }).format(status.map((s) => `'${s}'`))} found`);
39
43
  return;
40
44
  }
41
45
  const choices = await Promise.all(relationships.map((relationship) => this.renderRelationship(relationship, returnRelationship)));
@@ -52,7 +56,7 @@ export class ConnectorTUIBase {
52
56
  const surname = relationshipAttributes.find((a) => a.content.value["@type"] === "Surname");
53
57
  const givenName = relationshipAttributes.find((a) => a.content.value["@type"] === "GivenName");
54
58
  if (!!surname || givenName) {
55
- const name = `${surname?.content.value.value || ""} ${givenName?.content.value.value || ""}`.trim();
59
+ const name = `${(surname?.content.value).value || ""} ${(givenName?.content.value).value || ""}`.trim();
56
60
  return {
57
61
  title: `${relationship.peer} (${name})`,
58
62
  value,
@@ -1,7 +1,7 @@
1
1
  import { ConnectorRelationshipStatus } from "@nmshd/connector-sdk";
2
2
  import prompts from "prompts";
3
3
  export function AddAcceptPendingRelationships(Base) {
4
- return class Sync extends Base {
4
+ return class AcceptPendingRelationships extends Base {
5
5
  constructor(...args) {
6
6
  super(...args);
7
7
  this.choices.push({ title: "Accept Pending Relationships", value: this.acceptPendingRelationships });
@@ -15,12 +15,10 @@ export function AddAcceptPendingRelationships(Base) {
15
15
  if (result.sync) {
16
16
  await this.connectorClient.account.sync();
17
17
  }
18
- const pendingRelationships = (await this.connectorClient.relationships.getRelationships({
19
- status: ConnectorRelationshipStatus.PENDING,
20
- })).result;
18
+ const pendingRelationships = (await this.connectorClient.relationships.getRelationships({ status: ConnectorRelationshipStatus.Pending })).result;
21
19
  for (const relationship of pendingRelationships) {
22
20
  console.log(`Accepting relationship ${relationship.id}`);
23
- await this.connectorClient.relationships.acceptRelationshipChange(relationship.id, relationship.changes[0].id);
21
+ await this.connectorClient.relationships.acceptRelationship(relationship.id);
24
22
  }
25
23
  }
26
24
  };
@@ -2,7 +2,7 @@ import { ConnectorRequestStatus } from "@nmshd/connector-sdk";
2
2
  import { DateTime } from "luxon";
3
3
  import prompts from "prompts";
4
4
  export function AddAcceptPendingRequests(Base) {
5
- return class Sync extends Base {
5
+ return class AcceptPendingRequests extends Base {
6
6
  constructor(...args) {
7
7
  super(...args);
8
8
  this.choices.push({ title: "Accept Pending Requests", value: this.acceptPendingRequests });
@@ -8,7 +8,7 @@ export function AddCreateAndShowTemplate(Base) {
8
8
  }
9
9
  async createAndShowTemplate() {
10
10
  const template = await this.connectorClient.relationshipTemplates.createOwnRelationshipTemplate({
11
- content: {},
11
+ content: { "@type": "ArbitraryRelationshipTemplateContent", value: {} },
12
12
  expiresAt: DateTime.now().plus({ days: 2 }).toISO(),
13
13
  });
14
14
  const url = `nmshd://tr#${template.result.truncatedReference}`;
@@ -0,0 +1,21 @@
1
+ import { ConnectorRelationshipStatus } from "@nmshd/connector-sdk";
2
+ export function AddDecomposeRelationship(Base) {
3
+ return class DecomposeRelationship extends Base {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.choices.push({ title: "Decompose Relationship", value: this.decomposeRelationship });
7
+ }
8
+ async decomposeRelationship() {
9
+ await this.connectorClient.account.sync();
10
+ const relationship = await this.selectRelationship("Select relationship to decompose", ConnectorRelationshipStatus.Terminated, ConnectorRelationshipStatus.DeletionProposed);
11
+ if (!relationship)
12
+ return;
13
+ console.log(`Decomposing relationship ${relationship.id}`);
14
+ const decomposeResult = await this.connectorClient.relationships.decomposeRelationship(relationship.id);
15
+ if (decomposeResult.isError) {
16
+ console.error(`Failed to decompose relationship ${relationship.id}: ${JSON.stringify(decomposeResult.error)}`);
17
+ return;
18
+ }
19
+ }
20
+ };
21
+ }
@@ -1,5 +1,5 @@
1
1
  export function AddExit(Base) {
2
- return class Sync extends Base {
2
+ return class Exit extends Base {
3
3
  constructor(...args) {
4
4
  super(...args);
5
5
  this.choices.push({ title: "Exit", value: this.exit });
@@ -1,11 +1,12 @@
1
+ import { ConnectorRelationshipStatus } from "@nmshd/connector-sdk";
1
2
  export function AddGetAttributesOfRelationship(Base) {
2
- return class AddGetAttributesOfRelationship extends Base {
3
+ return class GetAttributesOfRelationship extends Base {
3
4
  constructor(...args) {
4
5
  super(...args);
5
6
  this.choices.push({ title: "Get Attributes Of Relationship", value: this.getAttributesOfRelationship });
6
7
  }
7
8
  async getAttributesOfRelationship() {
8
- const relationship = await this.selectRelationship("From which relationship do you want to get the attributes?");
9
+ const relationship = await this.selectRelationship("From which relationship do you want to get the attributes?", ConnectorRelationshipStatus.Active, ConnectorRelationshipStatus.Pending, ConnectorRelationshipStatus.Terminated, ConnectorRelationshipStatus.DeletionProposed);
9
10
  if (!relationship)
10
11
  return console.log("No recipient selected");
11
12
  const attributeResult = await this.connectorClient.relationships.getAttributesForRelationship(relationship.id);
@@ -1,3 +1,4 @@
1
+ import { RelationshipAttributeConfidentiality, } from "@nmshd/content";
1
2
  import prompts from "prompts";
2
3
  export function AddSendRequestByMessage(Base) {
3
4
  return class SendRequestByMessage extends Base {
@@ -153,8 +154,13 @@ export function AddSendRequestByMessage(Base) {
153
154
  },
154
155
  {
155
156
  message: "Who is the owner of the RelationshipAttribute?",
156
- type: "text",
157
+ type: "select",
157
158
  name: "owner",
159
+ choices: [
160
+ { title: "The other side or a third party", value: "" },
161
+ { title: "The other side", value: "recipient" },
162
+ { title: "A third party", value: "thirdParty" },
163
+ ],
158
164
  },
159
165
  {
160
166
  message: "What are the third party addresses? (comma-separated, optional)",
@@ -172,7 +178,7 @@ export function AddSendRequestByMessage(Base) {
172
178
  attributeCreationHints: {
173
179
  title: title,
174
180
  description: result.attributeDescription,
175
- confidentiality: "public",
181
+ confidentiality: RelationshipAttributeConfidentiality.Public,
176
182
  valueType: result.attributeType,
177
183
  },
178
184
  key: result.key,
@@ -358,7 +364,7 @@ export function AddSendRequestByMessage(Base) {
358
364
  "@type": "RelationshipAttribute",
359
365
  owner: "",
360
366
  key: result.key,
361
- confidentiality: "public",
367
+ confidentiality: RelationshipAttributeConfidentiality.Public,
362
368
  value: {
363
369
  "@type": "ProprietaryString",
364
370
  value: result.value,
@@ -404,7 +410,7 @@ export function AddSendRequestByMessage(Base) {
404
410
  "@type": "RelationshipAttribute",
405
411
  owner: result.owner,
406
412
  key: result.key,
407
- confidentiality: "public",
413
+ confidentiality: RelationshipAttributeConfidentiality.Public,
408
414
  isTechnical: true,
409
415
  value: {
410
416
  "@type": "ProprietaryBoolean",
@@ -467,7 +473,7 @@ export function AddSendRequestByMessage(Base) {
467
473
  mustBeAccepted: true,
468
474
  consent: result.consent,
469
475
  link,
470
- responseMetadata,
476
+ metadata: responseMetadata,
471
477
  };
472
478
  return requestItem;
473
479
  }
@@ -507,7 +513,7 @@ export function AddSendRequestByMessage(Base) {
507
513
  "@type": "AuthenticationRequestItem",
508
514
  mustBeAccepted: true,
509
515
  title: result.title,
510
- responseMetadata,
516
+ metadata: responseMetadata,
511
517
  };
512
518
  return requestItem;
513
519
  }
@@ -1,62 +1,67 @@
1
1
  import { DateTime } from "luxon";
2
+ import prompts from "prompts";
2
3
  import qrcode from "qrcode-terminal";
3
4
  export function AddShareRequestByTemplate(Base) {
4
- return class Sync extends Base {
5
+ return class ShareRequestByTemplate extends Base {
5
6
  constructor(...args) {
6
7
  super(...args);
7
8
  this.choices.push({ title: "Share Request By Template", value: this.shareRequestByTemplate });
8
9
  }
9
10
  async shareRequestByTemplate() {
10
- const name = process.env.CONNECTOR_DISPLAY_NAME ?? "ConnectorV2 Demo";
11
+ const name = process.env.CONNECTOR_DISPLAY_NAME ?? "Connector TUI";
11
12
  const displayName = await this.getOrCreateConnectorDisplayName(name);
12
- const request = {
13
+ const sharedAttributes = {
14
+ "@type": "RequestItemGroup",
15
+ title: "Shared Attributes",
13
16
  items: [
14
17
  {
15
- "@type": "RequestItemGroup",
18
+ "@type": "ShareAttributeRequestItem",
16
19
  mustBeAccepted: true,
17
- title: "Shared Attributes",
18
- items: [
19
- {
20
- "@type": "ShareAttributeRequestItem",
21
- mustBeAccepted: true,
22
- attribute: displayName.content,
23
- sourceAttributeId: displayName.id,
24
- },
25
- ],
20
+ attribute: displayName.content,
21
+ sourceAttributeId: displayName.id,
26
22
  },
23
+ ],
24
+ };
25
+ const requestedAttributes = {
26
+ "@type": "RequestItemGroup",
27
+ title: "Requested Attributes",
28
+ items: [
27
29
  {
28
- "@type": "RequestItemGroup",
30
+ "@type": "ReadAttributeRequestItem",
29
31
  mustBeAccepted: true,
30
- title: "Requested Attributes",
31
- items: [
32
- {
33
- "@type": "ReadAttributeRequestItem",
34
- mustBeAccepted: true,
35
- query: {
36
- "@type": "IdentityAttributeQuery",
37
- valueType: "Surname",
38
- },
39
- },
40
- {
41
- "@type": "ReadAttributeRequestItem",
42
- mustBeAccepted: true,
43
- query: {
44
- "@type": "IdentityAttributeQuery",
45
- valueType: "GivenName",
46
- },
47
- },
48
- {
49
- "@type": "ReadAttributeRequestItem",
50
- mustBeAccepted: false,
51
- query: {
52
- "@type": "IdentityAttributeQuery",
53
- valueType: "EMailAddress",
54
- },
55
- },
56
- ],
32
+ query: {
33
+ "@type": "IdentityAttributeQuery",
34
+ valueType: "Surname",
35
+ },
36
+ },
37
+ {
38
+ "@type": "ReadAttributeRequestItem",
39
+ mustBeAccepted: true,
40
+ query: {
41
+ "@type": "IdentityAttributeQuery",
42
+ valueType: "GivenName",
43
+ },
44
+ },
45
+ {
46
+ "@type": "ReadAttributeRequestItem",
47
+ mustBeAccepted: false,
48
+ query: {
49
+ "@type": "IdentityAttributeQuery",
50
+ valueType: "EMailAddress",
51
+ },
57
52
  },
58
53
  ],
59
54
  };
55
+ const request = { "@type": "Request", items: [] };
56
+ const result = await prompts({
57
+ message: "Do you want to send your connector's name?",
58
+ type: "confirm",
59
+ name: "includeName",
60
+ initial: true,
61
+ });
62
+ if (result.includeName)
63
+ request.items.push(sharedAttributes);
64
+ request.items.push(requestedAttributes);
60
65
  await this.createQRCodeForRelationshipTemplate(request, name);
61
66
  }
62
67
  async getOrCreateConnectorDisplayName(displayName) {
@@ -10,7 +10,7 @@ export function AddSync(Base) {
10
10
  console.error(syncRequest.error);
11
11
  return;
12
12
  }
13
- console.log(syncRequest.result);
13
+ console.log("Successfully synced the connector.");
14
14
  }
15
15
  };
16
16
  }
@@ -0,0 +1,21 @@
1
+ import { ConnectorRelationshipStatus } from "@nmshd/connector-sdk";
2
+ export function AddTerminateRelationship(Base) {
3
+ return class TerminateRelationship extends Base {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.choices.push({ title: "Terminate Relationship", value: this.terminateRelationship });
7
+ }
8
+ async terminateRelationship() {
9
+ await this.connectorClient.account.sync();
10
+ const relationship = await this.selectRelationship("Select relationship to terminate", ConnectorRelationshipStatus.Active);
11
+ if (!relationship)
12
+ return;
13
+ console.log(`Terminating relationship ${relationship.id}`);
14
+ const terminationResult = await this.connectorClient.relationships.terminateRelationship(relationship.id);
15
+ if (terminationResult.isError) {
16
+ console.error(`Failed to terminate relationship ${relationship.id}: ${JSON.stringify(terminationResult.error)}`);
17
+ return;
18
+ }
19
+ }
20
+ };
21
+ }
@@ -5,7 +5,7 @@ import prompts from "prompts";
5
5
  import qrcode from "qrcode-terminal";
6
6
  import url from "url";
7
7
  export function AddUploadFile(Base) {
8
- return class Sync extends Base {
8
+ return class UploadFile extends Base {
9
9
  assetFolder = path.resolve(url.fileURLToPath(new URL(".", import.meta.url)), "../../__assets__");
10
10
  constructor(...args) {
11
11
  super(...args);
@@ -1,8 +1,8 @@
1
1
  import { ConnectorTUIBase } from "../ConnectorTUIBase.js";
2
- import { AddAcceptPendingRelationships, AddAcceptPendingRequests, AddConnectorInfo, AddCreateAndShowTemplate, AddExit, AddGetAttributesOfRelationship, AddSendMail, AddSendRequestByMessage, AddShareRequestByTemplate, AddSync, AddUploadFile, } from "./index.js";
2
+ import { AddAcceptPendingRelationships, AddAcceptPendingRequests, AddConnectorInfo, AddCreateAndShowTemplate, AddDecomposeRelationship, AddExit, AddGetAttributesOfRelationship, AddSendMail, AddSendRequestByMessage, AddShareRequestByTemplate, AddSync, AddTerminateRelationship, AddUploadFile, } from "./index.js";
3
3
  export class ConnectorTUIBaseWithMixins
4
4
  //
5
- extends AddExit(AddConnectorInfo(AddCreateAndShowTemplate(AddAcceptPendingRelationships(AddAcceptPendingRequests(AddGetAttributesOfRelationship(AddSendMail(AddSendRequestByMessage(AddShareRequestByTemplate(AddSync(AddUploadFile(
5
+ extends AddExit(AddConnectorInfo(AddDecomposeRelationship(AddTerminateRelationship(AddCreateAndShowTemplate(AddAcceptPendingRelationships(AddAcceptPendingRequests(AddGetAttributesOfRelationship(AddSendMail(AddSendRequestByMessage(AddShareRequestByTemplate(AddSync(AddUploadFile(
6
6
  //
7
- ConnectorTUIBase))))))))))) {
7
+ ConnectorTUIBase))))))))))))) {
8
8
  }
@@ -2,11 +2,13 @@ export * from "./AddAcceptPendingRelationships.js";
2
2
  export * from "./AddAcceptPendingRequests.js";
3
3
  export * from "./AddConnectorInfo.js";
4
4
  export * from "./AddCreateAndShowTemplate.js";
5
+ export * from "./AddDecomposeRelationship.js";
5
6
  export * from "./AddExit.js";
6
7
  export * from "./AddGetAttributesOfRelationship.js";
7
8
  export * from "./AddSendMail.js";
8
9
  export * from "./AddSendRequestByMessage.js";
9
10
  export * from "./AddShareRequestByTemplate.js";
10
11
  export * from "./AddSync.js";
12
+ export * from "./AddTerminateRelationship.js";
11
13
  export * from "./AddUploadFile.js";
12
14
  export * from "./ConnectorTUIBaseWithMixins.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmshd/connector-tui",
3
- "version": "1.2.5",
3
+ "version": "2.0.0",
4
4
  "repository": "github:nmshd/connector-tui",
5
5
  "license": "MIT",
6
6
  "author": "j&s-soft GmbH",
@@ -23,15 +23,15 @@
23
23
  "lint:tsc": "tsc --noEmit",
24
24
  "lint:eslint": "eslint --ext .ts ./src",
25
25
  "lint:prettier": "prettier --check ./src",
26
- "start": "node --loader ts-node/esm src/index.ts",
26
+ "start": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' src/index.ts",
27
27
  "test": "echo 'no test specified'",
28
- "watch": "node --watch --loader ts-node/esm src/index.ts"
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": "^4.6.1",
31
+ "@nmshd/connector-sdk": "^5.0.1",
32
32
  "chalk": "^5.3.0",
33
33
  "dotenv": "^16.4.5",
34
- "luxon": "^3.4.4",
34
+ "luxon": "^3.5.0",
35
35
  "prompts": "^2.4.2",
36
36
  "qrcode-terminal": "^0.12.0",
37
37
  "yargs": "^17.7.2"
@@ -40,14 +40,14 @@
40
40
  "@js-soft/eslint-config-ts": "^1.6.9",
41
41
  "@js-soft/license-check": "^1.0.9",
42
42
  "@types/luxon": "^3.4.2",
43
- "@types/node": "^20.14.11",
43
+ "@types/node": "^22.5.3",
44
44
  "@types/prompts": "^2.4.9",
45
45
  "@types/qrcode-terminal": "^0.12.2",
46
- "@types/yargs": "^17.0.32",
46
+ "@types/yargs": "^17.0.33",
47
47
  "eslint": "^8.57.0",
48
48
  "prettier": "^3.3.3",
49
49
  "ts-node": "^10.9.2",
50
- "typescript": "^5.5.3"
50
+ "typescript": "^5.5.4"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=19.0.0"