@nmshd/connector-tui 0.0.2 → 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.
- package/README.md +9 -0
- package/dist/index.js +13 -1
- package/dist/mixins/AddSendRequestByMessage.js +144 -111
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -22,3 +22,12 @@ If you want to execute this TUI as a package you can install it using `npm i -g
|
|
|
22
22
|
|
|
23
23
|
1. (only for the first time) `npm install` and copy `.env.example` to `.env` and fill in the values.
|
|
24
24
|
2. `npm start`
|
|
25
|
+
|
|
26
|
+
## Command line arguments
|
|
27
|
+
|
|
28
|
+
```txt
|
|
29
|
+
--version Show version number [boolean]
|
|
30
|
+
-e, --env location of the env file relative to cwd
|
|
31
|
+
[string] [default: ".env"]
|
|
32
|
+
-h, --help Show help [boolean]
|
|
33
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import dotenv from "dotenv";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import yargs from "yargs";
|
|
5
|
+
import { hideBin } from "yargs/helpers";
|
|
3
6
|
import { ConnectorTUI } from "./ConnectorTUI";
|
|
4
|
-
|
|
7
|
+
const argv = await yargs(hideBin(process.argv))
|
|
8
|
+
.option("env", {
|
|
9
|
+
alias: "e",
|
|
10
|
+
description: "location of the env file relative to cwd",
|
|
11
|
+
type: "string",
|
|
12
|
+
default: ".env",
|
|
13
|
+
})
|
|
14
|
+
.help()
|
|
15
|
+
.alias("help", "h").argv;
|
|
16
|
+
dotenv.config({ path: path.resolve(process.cwd(), argv.env) });
|
|
5
17
|
if (typeof process.env.BASE_URL === "undefined" || typeof process.env.API_KEY === "undefined") {
|
|
6
18
|
console.log(chalk.red("Please provide a BASE_URL and API_KEY in your .env file or as environment variables."));
|
|
7
19
|
process.exit(1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import prompts from "prompts";
|
|
2
2
|
export function AddSendRequestByMessage(Base) {
|
|
3
|
-
return class
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
60
|
+
const messageResponse = await this.connectorClient.messages.sendMessage({
|
|
43
61
|
recipients: [peer],
|
|
44
62
|
content: response.result.content,
|
|
45
63
|
});
|
|
46
|
-
if (
|
|
47
|
-
return console.error("Error while sending message",
|
|
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
|
|
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
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
+
"version": "0.0.4",
|
|
4
4
|
"repository": "github:nmshd/connector-tui",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "j&s-soft GmbH",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
".env.example"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"lint:prettier": "prettier --check ./src",
|
|
20
|
-
"lint:eslint": "eslint --ext .ts ./src",
|
|
21
|
-
"lint": "npm run lint:prettier && npm run lint:eslint",
|
|
22
19
|
"build": "tsc",
|
|
23
|
-
"
|
|
20
|
+
"lint": "npm run lint:prettier && npm run lint:eslint",
|
|
21
|
+
"lint:eslint": "eslint --ext .ts ./src",
|
|
22
|
+
"lint:prettier": "prettier --check ./src",
|
|
23
|
+
"start": "ts-node --esm --experimental-specifier-resolution node ./src/index.ts",
|
|
24
24
|
"test": "echo 'no test specified'"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"dotenv": "^16.0.3",
|
|
30
30
|
"luxon": "^3.1.0",
|
|
31
31
|
"prompts": "^2.4.2",
|
|
32
|
-
"qrcode-terminal": "^0.12.0"
|
|
32
|
+
"qrcode-terminal": "^0.12.0",
|
|
33
|
+
"yargs": "^17.6.2"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@js-soft/eslint-config-ts": "^1.6.1",
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"@types/node": "^18.11.9",
|
|
39
40
|
"@types/prompts": "^2.4.1",
|
|
40
41
|
"@types/qrcode-terminal": "^0.12.0",
|
|
42
|
+
"@types/yargs": "^17.0.13",
|
|
41
43
|
"eslint": "^8.26.0",
|
|
42
44
|
"prettier": "^2.7.1",
|
|
43
45
|
"ts-node": "^10.9.1",
|