@nmshd/connector-tui 0.0.3 → 0.0.4

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.
@@ -1,6 +1,6 @@
1
1
  import prompts from "prompts";
2
2
  export function AddSendRequestByMessage(Base) {
3
- return class Sync extends Base {
3
+ return class SendRequestByMessage extends Base {
4
4
  constructor(...args) {
5
5
  super(...args);
6
6
  this.choices.push({ title: "Send Request By Message", value: this.sendRequestByMessage });
@@ -10,45 +10,89 @@ export function AddSendRequestByMessage(Base) {
10
10
  if (!recipient)
11
11
  return console.log("No recipient selected");
12
12
  const peer = recipient.peer;
13
- const whatRequest = await prompts({
14
- message: "What kind of request do you want to send?",
15
- type: "select",
16
- name: "requestMethod",
17
- choices: [
18
- {
19
- title: "ReadRelationshipAttributeRequest",
20
- value: this.createReadRelationshipAttributeRequest.bind(this),
21
- },
22
- {
23
- title: "ReadIdentityAttributeRequest",
24
- value: this.createReadIdentityAttributeRequest.bind(this),
25
- },
26
- {
27
- title: "ProposeAttributeRequest",
28
- value: this.createProposeAttributeRequest.bind(this),
29
- },
30
- {
31
- title: "CreateRelationshipAttributeRequest",
32
- value: this.createCreateRelationshipAttributeRequest.bind(this),
33
- },
34
- ],
13
+ const requestItems = [];
14
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,no-constant-condition
15
+ while (true) {
16
+ const whatRequest = await prompts({
17
+ message: "What kind of request do you want to send?",
18
+ type: "select",
19
+ name: "requestMethod",
20
+ choices: [
21
+ {
22
+ title: "ReadAttributeRequestItem",
23
+ value: this.createReadAttributeRequestItem.bind(this),
24
+ },
25
+ {
26
+ title: "ProposeAttributeRequestItem",
27
+ value: this.createProposeAttributeRequestItem.bind(this),
28
+ },
29
+ {
30
+ title: "CreateRelationshipAttributeRequestItem",
31
+ value: this.createCreateRelationshipAttributeRequestItem.bind(this),
32
+ },
33
+ {
34
+ title: "No more items please",
35
+ value: "no-more",
36
+ },
37
+ ],
38
+ });
39
+ if (!whatRequest.requestMethod)
40
+ return;
41
+ if (typeof whatRequest.requestMethod !== "function") {
42
+ break;
43
+ }
44
+ const requestItemJSON = await whatRequest.requestMethod(peer);
45
+ requestItems.push(requestItemJSON);
46
+ }
47
+ if (requestItems.length === 0) {
48
+ console.error("You have to add at least one item.");
49
+ return;
50
+ }
51
+ const response = await this.connectorClient.outgoingRequests.createRequest({
52
+ peer,
53
+ content: {
54
+ items: requestItems,
55
+ },
35
56
  });
36
- if (!whatRequest.requestMethod)
37
- return console.log("No request method selected");
38
- const response = await whatRequest.requestMethod(peer);
39
57
  if (response.isError) {
40
58
  return console.error("Error while creating LocalRequest", response.error);
41
59
  }
42
- const messageResult = await this.connectorClient.messages.sendMessage({
60
+ const messageResponse = await this.connectorClient.messages.sendMessage({
43
61
  recipients: [peer],
44
62
  content: response.result.content,
45
63
  });
46
- if (messageResult.isError) {
47
- return console.error("Error while sending message", messageResult.error);
64
+ if (messageResponse.isError) {
65
+ return console.error("Error while sending message", messageResponse.error);
48
66
  }
67
+ console.log("The following Request was sent:", JSON.stringify(response.result.content, null, 2));
49
68
  console.log(`Request sent to '${peer}'`);
50
69
  }
51
- async createReadRelationshipAttributeRequest(peer) {
70
+ async createReadAttributeRequestItem() {
71
+ const whatAttribute = await prompts({
72
+ message: "What kind of Attribute do you want to read?",
73
+ type: "select",
74
+ name: "attributeType",
75
+ choices: [
76
+ {
77
+ title: "Identity Attribute",
78
+ value: "IdentityAttribute",
79
+ },
80
+ {
81
+ title: "Relationship Attribute",
82
+ value: "RelationshipAttribute",
83
+ },
84
+ ],
85
+ });
86
+ switch (whatAttribute.attributeType) {
87
+ case "IdentityAttribute":
88
+ return await this.createReadIdentityAttributeRequestItem();
89
+ case "RelationshipAttribute":
90
+ return await this.createReadRelationshipAttributeRequestItem();
91
+ default:
92
+ return console.log("Invalid attribute type");
93
+ }
94
+ }
95
+ async createReadRelationshipAttributeRequestItem() {
52
96
  const result = await prompts([
53
97
  {
54
98
  message: "Whats the attribute type you would like to query?",
@@ -63,35 +107,42 @@ export function AddSendRequestByMessage(Base) {
63
107
  initial: "Key of RelationshipAttribute",
64
108
  },
65
109
  {
66
- message: "Whats the third party address?",
110
+ message: "Whats the title?",
111
+ type: "text",
112
+ name: "title",
113
+ initial: "Attribute Title",
114
+ },
115
+ {
116
+ message: "Whats the description?",
117
+ type: "text",
118
+ name: "description",
119
+ initial: "Attribute Description",
120
+ },
121
+ {
122
+ message: "Whats the third party address? (optional)",
67
123
  type: "text",
68
124
  name: "thirdParty",
69
125
  initial: "Third party address",
70
126
  },
71
127
  ]);
72
- return await this.connectorClient.outgoingRequests.createRequest({
73
- peer,
74
- content: {
75
- items: [
76
- {
77
- "@type": "ReadAttributeRequestItem",
78
- mustBeAccepted: true,
79
- query: {
80
- "@type": "RelationshipAttributeQuery",
81
- owner: "",
82
- attributeCreationHints: {
83
- title: `A ${result.attributeType} attribute`,
84
- confidentiality: "public",
85
- valueType: result.attributeType,
86
- },
87
- key: result.key,
88
- },
89
- },
90
- ],
128
+ const requestItem = {
129
+ "@type": "ReadAttributeRequestItem",
130
+ mustBeAccepted: true,
131
+ query: {
132
+ "@type": "RelationshipAttributeQuery",
133
+ owner: "",
134
+ attributeCreationHints: {
135
+ title: result.title,
136
+ description: result.description,
137
+ confidentiality: "public",
138
+ valueType: result.attributeType,
139
+ },
140
+ key: result.key,
91
141
  },
92
- });
142
+ };
143
+ return requestItem;
93
144
  }
94
- async createReadIdentityAttributeRequest(peer) {
145
+ async createReadIdentityAttributeRequestItem() {
95
146
  const result = await prompts([
96
147
  {
97
148
  message: "Whats the attribute type you would like to query?",
@@ -100,23 +151,17 @@ export function AddSendRequestByMessage(Base) {
100
151
  initial: "An attribute type",
101
152
  },
102
153
  ]);
103
- return await this.connectorClient.outgoingRequests.createRequest({
104
- peer,
105
- content: {
106
- items: [
107
- {
108
- "@type": "ReadAttributeRequestItem",
109
- mustBeAccepted: true,
110
- query: {
111
- "@type": "IdentityAttributeQuery",
112
- valueType: result.attributeType,
113
- },
114
- },
115
- ],
154
+ const requestItem = {
155
+ "@type": "ReadAttributeRequestItem",
156
+ mustBeAccepted: true,
157
+ query: {
158
+ "@type": "IdentityAttributeQuery",
159
+ valueType: result.attributeType,
116
160
  },
117
- });
161
+ };
162
+ return requestItem;
118
163
  }
119
- async createProposeAttributeRequest(peer) {
164
+ async createProposeAttributeRequestItem() {
120
165
  const result = await prompts([
121
166
  {
122
167
  message: "Whats the attribute type you would like to create?",
@@ -131,31 +176,25 @@ export function AddSendRequestByMessage(Base) {
131
176
  initial: "Value",
132
177
  },
133
178
  ]);
134
- return await this.connectorClient.outgoingRequests.createRequest({
135
- peer,
136
- content: {
137
- items: [
138
- {
139
- "@type": "ProposeAttributeRequestItem",
140
- mustBeAccepted: true,
141
- query: {
142
- "@type": "IdentityAttributeQuery",
143
- valueType: result.attributeType,
144
- },
145
- attribute: {
146
- "@type": "IdentityAttribute",
147
- owner: "",
148
- value: {
149
- "@type": result.attributeType,
150
- value: result.value,
151
- },
152
- },
153
- },
154
- ],
179
+ const requestItem = {
180
+ "@type": "ProposeAttributeRequestItem",
181
+ mustBeAccepted: true,
182
+ query: {
183
+ "@type": "IdentityAttributeQuery",
184
+ valueType: result.attributeType,
155
185
  },
156
- });
186
+ attribute: {
187
+ "@type": "IdentityAttribute",
188
+ owner: "",
189
+ value: {
190
+ "@type": result.attributeType,
191
+ value: result.value,
192
+ },
193
+ },
194
+ };
195
+ return requestItem;
157
196
  }
158
- async createCreateRelationshipAttributeRequest(peer) {
197
+ async createCreateRelationshipAttributeRequestItem() {
159
198
  const result = await prompts([
160
199
  {
161
200
  message: "Whats the title of the RelationshipAttribute you would like to create?",
@@ -176,28 +215,22 @@ export function AddSendRequestByMessage(Base) {
176
215
  initial: "Value",
177
216
  },
178
217
  ]);
179
- return await this.connectorClient.outgoingRequests.createRequest({
180
- peer,
181
- content: {
182
- items: [
183
- {
184
- "@type": "CreateAttributeRequestItem",
185
- mustBeAccepted: true,
186
- attribute: {
187
- "@type": "RelationshipAttribute",
188
- owner: "",
189
- key: result.key,
190
- confidentiality: "public",
191
- value: {
192
- "@type": "ProprietaryString",
193
- value: result.value,
194
- title: result.title,
195
- },
196
- },
197
- },
198
- ],
218
+ const requestItem = {
219
+ "@type": "CreateAttributeRequestItem",
220
+ mustBeAccepted: true,
221
+ attribute: {
222
+ "@type": "RelationshipAttribute",
223
+ owner: "",
224
+ key: result.key,
225
+ confidentiality: "public",
226
+ value: {
227
+ "@type": "ProprietaryString",
228
+ value: result.value,
229
+ title: result.title,
230
+ },
199
231
  },
200
- });
232
+ };
233
+ return requestItem;
201
234
  }
202
235
  };
203
236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmshd/connector-tui",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "repository": "github:nmshd/connector-tui",
5
5
  "license": "MIT",
6
6
  "author": "j&s-soft GmbH",
@@ -20,7 +20,7 @@
20
20
  "lint": "npm run lint:prettier && npm run lint:eslint",
21
21
  "lint:eslint": "eslint --ext .ts ./src",
22
22
  "lint:prettier": "prettier --check ./src",
23
- "start": "clear && ts-node --esm --experimental-specifier-resolution node ./src/index.ts",
23
+ "start": "ts-node --esm --experimental-specifier-resolution node ./src/index.ts",
24
24
  "test": "echo 'no test specified'"
25
25
  },
26
26
  "dependencies": {