@nmshd/connector-tui 0.0.4 → 0.1.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.
@@ -46,6 +46,7 @@ export class ConnectorTUI extends ConnectorTUIBaseWithMixins {
46
46
  console.log(`Welcome to the ${chalk.blue("Enmeshed V2 TUI")}!`);
47
47
  console.log(`TUI Version: ${chalk.yellow(packageJson.version)}`);
48
48
  console.log(`Connector version: ${chalk.yellow(connectorVersionInfo.version)}`);
49
+ console.log(`Connector Address: ${chalk.yellow(this.connectorAddress)}`);
49
50
  console.log("");
50
51
  }
51
52
  }
@@ -28,7 +28,12 @@ export class ConnectorTUIBase {
28
28
  return recipients;
29
29
  }
30
30
  async getRelationshipChoices(status, returnRelationship) {
31
- const relationships = (await this.connectorClient.relationships.getRelationships({ status })).result;
31
+ const relationshipsResult = await this.connectorClient.relationships.getRelationships({ status });
32
+ if (relationshipsResult.isError) {
33
+ console.error(relationshipsResult.error);
34
+ return;
35
+ }
36
+ const relationships = relationshipsResult.result;
32
37
  if (relationships.length === 0) {
33
38
  console.log(`No relationships with status '${status}' found`);
34
39
  return;
@@ -0,0 +1,51 @@
1
+ import { ConnectorRequestStatus } from "@nmshd/connector-sdk";
2
+ import prompts from "prompts";
3
+ export function AddAcceptPendingRequests(Base) {
4
+ return class Sync extends Base {
5
+ constructor(...args) {
6
+ super(...args);
7
+ this.choices.push({ title: "Accept Pending Requests", value: this.acceptPendingRequests });
8
+ }
9
+ async acceptPendingRequests() {
10
+ const result = await prompts({
11
+ message: "Do you want to sync before accepting pending requests?",
12
+ type: "confirm",
13
+ name: "sync",
14
+ });
15
+ if (result.sync) {
16
+ await this.connectorClient.account.sync();
17
+ }
18
+ const pendingRequests = (await this.connectorClient.incomingRequests.getRequests({
19
+ status: ConnectorRequestStatus.ManualDecisionRequired,
20
+ })).result;
21
+ for (const request of pendingRequests) {
22
+ const title = request.content.title ? `title ${request.content.title}` : "no title";
23
+ console.log(`Trying to accept request ${request.id} with ${title}...`);
24
+ const items = [];
25
+ for (const item of request.content.items) {
26
+ if (item["@type"] === "RequestItemGroup") {
27
+ const acceptItems = [];
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ for (const _itemOfGroup of item.items) {
30
+ acceptItems.push({ accept: true });
31
+ }
32
+ items.push({ items: acceptItems });
33
+ }
34
+ else {
35
+ items.push({ accept: true });
36
+ }
37
+ }
38
+ const canAcceptResult = await this.connectorClient.incomingRequests.canAccept(request.id, { items: items });
39
+ if (canAcceptResult.isError) {
40
+ console.log(canAcceptResult.error);
41
+ return;
42
+ }
43
+ const acceptResult = await this.connectorClient.incomingRequests.accept(request.id, { items: items });
44
+ if (acceptResult.isError) {
45
+ console.log(acceptResult.error);
46
+ return;
47
+ }
48
+ }
49
+ }
50
+ };
51
+ }
@@ -0,0 +1,36 @@
1
+ export function AddGetAttributesOfRelationship(Base) {
2
+ return class AddGetAttributesOfRelationship extends Base {
3
+ constructor(...args) {
4
+ super(...args);
5
+ this.choices.push({ title: "Get Attributes Of Relationship", value: this.getAttributesOfRelationship });
6
+ }
7
+ async getAttributesOfRelationship() {
8
+ const relationship = await this.selectRelationship("From which relationship do you want to get the attributes?");
9
+ if (!relationship)
10
+ return console.log("No recipient selected");
11
+ const attributeResult = await this.connectorClient.relationships.getAttributesForRelationship(relationship.id);
12
+ if (attributeResult.isError) {
13
+ console.log(attributeResult.error);
14
+ return;
15
+ }
16
+ const attributes = attributeResult.result.filter((a) => a.content.owner === relationship.peer || a.content["@type"] === "RelationshipAttribute");
17
+ attributes.map((attribute) => {
18
+ if (!attribute?.content?.value.value) {
19
+ console.log(`${attribute.id}: ${attribute.content.value["@type"]}`);
20
+ for (const propertyName in attribute.content.value) {
21
+ if (propertyName === "@type")
22
+ continue;
23
+ console.log(` ${propertyName}: ${attribute.content.value[propertyName]}`);
24
+ }
25
+ }
26
+ else if (attribute.content["@type"] === "RelationshipAttribute") {
27
+ console.log(`${attribute.id}: ${attribute.content.value.title} [${attribute.content.value["@type"]}] = ${attribute.content.value.value}`);
28
+ }
29
+ else {
30
+ console.log(`${attribute.id}: ${attribute.content.value["@type"]} = ${attribute.content.value.value}`);
31
+ }
32
+ return attribute;
33
+ });
34
+ }
35
+ };
36
+ }
@@ -30,6 +30,18 @@ export function AddSendRequestByMessage(Base) {
30
30
  title: "CreateRelationshipAttributeRequestItem",
31
31
  value: this.createCreateRelationshipAttributeRequestItem.bind(this),
32
32
  },
33
+ {
34
+ title: "CreateIdentityAttributeRequestItem",
35
+ value: this.createCreateIdentityAttributeRequestItem.bind(this),
36
+ },
37
+ {
38
+ title: "ConsentRequestItem",
39
+ value: this.createConsentRequestItem.bind(this),
40
+ },
41
+ {
42
+ title: "AuthenticationRequestItem",
43
+ value: this.createAuthenticationRequestItem.bind(this),
44
+ },
33
45
  {
34
46
  title: "No more items please",
35
47
  value: "no-more",
@@ -81,6 +93,10 @@ export function AddSendRequestByMessage(Base) {
81
93
  title: "Relationship Attribute",
82
94
  value: "RelationshipAttribute",
83
95
  },
96
+ {
97
+ title: "Third Party Relationship Attribute",
98
+ value: "ThirdPartyRelationshipAttribute",
99
+ },
84
100
  ],
85
101
  });
86
102
  switch (whatAttribute.attributeType) {
@@ -88,6 +104,8 @@ export function AddSendRequestByMessage(Base) {
88
104
  return await this.createReadIdentityAttributeRequestItem();
89
105
  case "RelationshipAttribute":
90
106
  return await this.createReadRelationshipAttributeRequestItem();
107
+ case "ThirdPartyRelationshipAttribute":
108
+ return await this.createReadThirdPartyRelationshipAttributeRequestItem();
91
109
  default:
92
110
  return console.log("Invalid attribute type");
93
111
  }
@@ -95,45 +113,49 @@ export function AddSendRequestByMessage(Base) {
95
113
  async createReadRelationshipAttributeRequestItem() {
96
114
  const result = await prompts([
97
115
  {
98
- message: "Whats the attribute type you would like to query?",
116
+ message: "What's the attribute type you would like to query?",
99
117
  type: "text",
100
118
  name: "attributeType",
101
- initial: "An attribute type",
102
119
  },
103
120
  {
104
- message: "Whats the key of the attribute you would like to query?",
121
+ message: "What's the title of the RelationshipAttribute?",
105
122
  type: "text",
106
- name: "key",
107
- initial: "Key of RelationshipAttribute",
123
+ name: "attributeTitle",
124
+ initial: "Attribute Title",
108
125
  },
109
126
  {
110
- message: "Whats the title?",
127
+ message: "What's the description of the RelationshipAttribute?",
111
128
  type: "text",
112
- name: "title",
129
+ name: "attributeDescription",
113
130
  initial: "Attribute Title",
114
131
  },
115
132
  {
116
- message: "Whats the description?",
133
+ message: "What's the key of the attribute you would like to query?",
117
134
  type: "text",
118
- name: "description",
119
- initial: "Attribute Description",
135
+ name: "key",
136
+ initial: "Key of RelationshipAttribute",
137
+ },
138
+ {
139
+ message: "Who is the owner of the RelationshipAttribute?",
140
+ type: "text",
141
+ name: "owner",
120
142
  },
121
143
  {
122
- message: "Whats the third party address? (optional)",
144
+ message: "What are the third party addresses? (comma-separated, optional)",
123
145
  type: "text",
124
- name: "thirdParty",
125
- initial: "Third party address",
146
+ name: "thirdParties",
126
147
  },
127
148
  ]);
149
+ const title = result.attributeTitle ? result.attributeTitle : `A ${result.attributeType} attribute`;
128
150
  const requestItem = {
129
151
  "@type": "ReadAttributeRequestItem",
130
152
  mustBeAccepted: true,
131
153
  query: {
132
154
  "@type": "RelationshipAttributeQuery",
133
- owner: "",
155
+ owner: result.owner ? result.owner : "",
134
156
  attributeCreationHints: {
135
- title: result.title,
136
- description: result.description,
157
+ title: title,
158
+ description: result.attributeDescription,
137
159
  confidentiality: "public",
138
160
  valueType: result.attributeType,
139
161
  },
@@ -142,13 +164,52 @@ export function AddSendRequestByMessage(Base) {
142
164
  };
143
165
  return requestItem;
144
166
  }
167
+ async createReadThirdPartyRelationshipAttributeRequestItem() {
168
+ const result = await prompts([
169
+ {
170
+ message: "What's the attribute type you would like to query?",
171
+ type: "text",
172
+ name: "attributeType",
173
+ },
174
+ {
175
+ message: "What's the key of the attribute you would like to query?",
176
+ type: "text",
177
+ name: "key",
178
+ initial: "Key of RelationshipAttribute",
179
+ },
180
+ {
181
+ message: "Who is the owner of the RelationshipAttribute?",
182
+ type: "text",
183
+ name: "owner",
184
+ },
185
+ {
186
+ message: "What are the third party addresses? (comma-separated)",
187
+ type: "text",
188
+ name: "thirdParties",
189
+ },
190
+ ]);
191
+ const thirdParties = result.thirdParties
192
+ .split(",")
193
+ .map((address) => address.trim())
194
+ .filter((address) => address.length > 0);
195
+ const requestItem = {
196
+ "@type": "ReadAttributeRequestItem",
197
+ mustBeAccepted: true,
198
+ query: {
199
+ "@type": "ThirdPartyRelationshipAttributeQuery",
200
+ owner: result.owner ? result.owner : "",
201
+ key: result.key,
202
+ thirdParty: thirdParties,
203
+ },
204
+ };
205
+ return requestItem;
206
+ }
145
207
  async createReadIdentityAttributeRequestItem() {
146
208
  const result = await prompts([
147
209
  {
148
- message: "Whats the attribute type you would like to query?",
210
+ message: "What's the attribute type you would like to query?",
149
211
  type: "text",
150
212
  name: "attributeType",
151
- initial: "An attribute type",
152
213
  },
153
214
  ]);
154
215
  const requestItem = {
@@ -164,16 +225,14 @@ export function AddSendRequestByMessage(Base) {
164
225
  async createProposeAttributeRequestItem() {
165
226
  const result = await prompts([
166
227
  {
167
- message: "Whats the attribute type you would like to create?",
228
+ message: "What's the attribute type you would like to create?",
168
229
  type: "text",
169
230
  name: "attributeType",
170
- initial: "An attribute type",
171
231
  },
172
232
  {
173
- message: "Whats the value of your Attribute?",
233
+ message: "What's the value of your Attribute?",
174
234
  type: "text",
175
235
  name: "value",
176
- initial: "Value",
177
236
  },
178
237
  ]);
179
238
  const requestItem = {
@@ -197,22 +256,21 @@ export function AddSendRequestByMessage(Base) {
197
256
  async createCreateRelationshipAttributeRequestItem() {
198
257
  const result = await prompts([
199
258
  {
200
- message: "Whats the title of the RelationshipAttribute you would like to create?",
259
+ message: "What's the title of the RelationshipAttribute you would like to create?",
201
260
  type: "text",
202
261
  name: "title",
203
262
  initial: "Title of RelationshipAttribute",
204
263
  },
205
264
  {
206
- message: "Whats the key of the RelationshipAttribute you would like to create?",
265
+ message: "What's the key of the RelationshipAttribute you would like to create?",
207
266
  type: "text",
208
267
  name: "key",
209
268
  initial: "Key of RelationshipAttribute",
210
269
  },
211
270
  {
212
- message: "Whats the value of your Attribute?",
271
+ message: "What's the value of your Attribute?",
213
272
  type: "text",
214
273
  name: "value",
215
- initial: "Value",
216
274
  },
217
275
  ]);
218
276
  const requestItem = {
@@ -232,5 +290,101 @@ export function AddSendRequestByMessage(Base) {
232
290
  };
233
291
  return requestItem;
234
292
  }
293
+ async createCreateIdentityAttributeRequestItem(peer) {
294
+ const result = await prompts([
295
+ {
296
+ message: "What's the value type of the IdentityAttribute you would like to create?",
297
+ type: "text",
298
+ name: "valueType",
299
+ },
300
+ {
301
+ message: "What's the value of the Attribute?",
302
+ type: "text",
303
+ name: "value",
304
+ },
305
+ ]);
306
+ return await this.connectorClient.outgoingRequests.createRequest({
307
+ peer,
308
+ content: {
309
+ items: [
310
+ {
311
+ "@type": "CreateAttributeRequestItem",
312
+ mustBeAccepted: true,
313
+ attribute: {
314
+ "@type": "IdentityAttribute",
315
+ owner: peer,
316
+ value: {
317
+ "@type": result.valueType,
318
+ value: result.value,
319
+ },
320
+ },
321
+ },
322
+ ],
323
+ },
324
+ });
325
+ }
326
+ async createConsentRequestItem(peer) {
327
+ const result = await prompts([
328
+ {
329
+ message: "What's the consent the peer should agree to?",
330
+ type: "text",
331
+ name: "consent",
332
+ },
333
+ {
334
+ message: "[Optional] Enter the URL to to the consent details?",
335
+ type: "text",
336
+ name: "link",
337
+ },
338
+ {
339
+ message: "[Optional] Enter a consentKey to know which consent the user agreed to",
340
+ type: "text",
341
+ name: "consentKey",
342
+ },
343
+ ]);
344
+ const responseMetadata = result.consentKey ? { consentKey: result.consentKey } : undefined;
345
+ const link = result.link ? result.link : undefined;
346
+ return await this.connectorClient.outgoingRequests.createRequest({
347
+ peer,
348
+ content: {
349
+ items: [
350
+ {
351
+ "@type": "ConsentRequestItem",
352
+ mustBeAccepted: true,
353
+ consent: result.consent,
354
+ link,
355
+ responseMetadata,
356
+ },
357
+ ],
358
+ },
359
+ });
360
+ }
361
+ async createAuthenticationRequestItem(peer) {
362
+ const result = await prompts([
363
+ {
364
+ message: "Enter a title of the authentication",
365
+ type: "text",
366
+ name: "title",
367
+ },
368
+ {
369
+ message: "[Optional] Enter an unique authenticationToken to know which authentication did the user grant",
370
+ type: "text",
371
+ name: "authenticationToken",
372
+ },
373
+ ]);
374
+ const responseMetadata = result.authenticationToken ? { authenticationToken: result.authenticationToken } : undefined;
375
+ return await this.connectorClient.outgoingRequests.createRequest({
376
+ peer,
377
+ content: {
378
+ items: [
379
+ {
380
+ "@type": "AuthenticationRequestItem",
381
+ mustBeAccepted: true,
382
+ title: result.title,
383
+ responseMetadata,
384
+ },
385
+ ],
386
+ },
387
+ });
388
+ }
235
389
  };
236
390
  }
@@ -1,7 +1,8 @@
1
1
  import { ConnectorTUIBase } from "../ConnectorTUIBase";
2
2
  import { AddAcceptPendingRelationships } from "./AddAcceptPendingRelationships";
3
+ import { AddAcceptPendingRequests } from "./AddAcceptPendingRequests";
3
4
  import { AddExit } from "./AddExit";
4
- import { AddGetAttributesOfContact } from "./AddGetAttributesOfContact";
5
+ import { AddGetAttributesOfRelationship } from "./AddGetAttributesOfRelationship";
5
6
  import { AddSendMail } from "./AddSendMail";
6
7
  import { AddSendRequestByMessage } from "./AddSendRequestByMessage";
7
8
  import { AddShareRequestByTemplate } from "./AddShareRequestByTemplate";
@@ -11,9 +12,9 @@ export class ConnectorTUIBaseWithMixins
11
12
  //
12
13
  extends AddExit(
13
14
  //
14
- AddAcceptPendingRelationships(
15
+ AddAcceptPendingRelationships(AddAcceptPendingRequests(
15
16
  //
16
- AddGetAttributesOfContact(
17
+ AddGetAttributesOfRelationship(
17
18
  //
18
19
  AddSendMail(
19
20
  //
@@ -25,5 +26,5 @@ AddSync(
25
26
  //
26
27
  AddUploadFile(
27
28
  //
28
- ConnectorTUIBase)))))))) {
29
+ ConnectorTUIBase))))))))) {
29
30
  }
@@ -1,6 +1,7 @@
1
1
  export * from "./AddAcceptPendingRelationships";
2
+ export * from "./AddAcceptPendingRequests";
2
3
  export * from "./AddExit";
3
- export * from "./AddGetAttributesOfContact";
4
+ export * from "./AddGetAttributesOfRelationship";
4
5
  export * from "./AddSendMail";
5
6
  export * from "./AddSendRequestByMessage";
6
7
  export * from "./AddShareRequestByTemplate";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmshd/connector-tui",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "repository": "github:nmshd/connector-tui",
5
5
  "license": "MIT",
6
6
  "author": "j&s-soft GmbH",
@@ -24,26 +24,26 @@
24
24
  "test": "echo 'no test specified'"
25
25
  },
26
26
  "dependencies": {
27
- "@nmshd/connector-sdk": "^2.0.4",
27
+ "@nmshd/connector-sdk": "^2.1.1",
28
28
  "chalk": "^5.1.2",
29
29
  "dotenv": "^16.0.3",
30
- "luxon": "^3.1.0",
30
+ "luxon": "^3.1.1",
31
31
  "prompts": "^2.4.2",
32
32
  "qrcode-terminal": "^0.12.0",
33
33
  "yargs": "^17.6.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@js-soft/eslint-config-ts": "^1.6.1",
37
- "@js-soft/license-check": "^1.0.5",
38
- "@types/luxon": "^3.0.2",
39
- "@types/node": "^18.11.9",
37
+ "@js-soft/license-check": "^1.0.6",
38
+ "@types/luxon": "^3.1.0",
39
+ "@types/node": "^18.11.10",
40
40
  "@types/prompts": "^2.4.1",
41
41
  "@types/qrcode-terminal": "^0.12.0",
42
- "@types/yargs": "^17.0.13",
43
- "eslint": "^8.26.0",
44
- "prettier": "^2.7.1",
42
+ "@types/yargs": "^17.0.15",
43
+ "eslint": "^8.29.0",
44
+ "prettier": "^2.8.0",
45
45
  "ts-node": "^10.9.1",
46
- "typescript": "^4.8.4"
46
+ "typescript": "^4.9.3"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -1,16 +0,0 @@
1
- export function AddGetAttributesOfContact(Base) {
2
- return class Sync extends Base {
3
- constructor(...args) {
4
- super(...args);
5
- this.choices.push({ title: "Get Attributes Of Contact", value: this.getAttributesOfContact });
6
- }
7
- async getAttributesOfContact() {
8
- const relationship = await this.selectRelationship("From which contact do you want to get the attributes?");
9
- if (!relationship)
10
- return console.log("No recipient selected");
11
- const attributeResult = await this.connectorClient.relationships.getAttributesForRelationship(relationship.id);
12
- const attributes = attributeResult.result.filter((a) => a.content.owner === relationship.peer);
13
- attributes.map((attribute) => console.log(`${attribute.id}: ${attribute.content.value["@type"]} = ${attribute.content.value.value}`));
14
- }
15
- };
16
- }