@super-protocol/sp-cli 0.0.2-beta.1 → 0.0.2-beta.2
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 +53 -61
- package/dist/commands/account/info.d.ts +21 -0
- package/dist/commands/account/info.js +43 -0
- package/dist/commands/auth/login.d.ts +0 -10
- package/dist/commands/auth/login.js +13 -84
- package/dist/commands/base.d.ts +2 -4
- package/dist/commands/base.js +8 -10
- package/dist/commands/config/add.js +9 -5
- package/dist/commands/config/base.d.ts +4 -3
- package/dist/commands/config/base.js +12 -14
- package/dist/commands/config/create.js +4 -4
- package/dist/commands/config/list.js +2 -2
- package/dist/commands/config/use.js +5 -3
- package/dist/commands/storage/base.js +2 -2
- package/dist/commands/storage/create.js +35 -35
- package/dist/commands/storage/select.js +10 -8
- package/dist/commands/storage/update.js +53 -48
- package/dist/lib/container.d.ts +4 -6
- package/dist/lib/container.js +21 -21
- package/dist/managers/account-manager.js +12 -2
- package/dist/managers/config-file-manager.d.ts +1 -1
- package/dist/managers/config-file-manager.js +12 -7
- package/dist/services/auth.service.d.ts +24 -0
- package/dist/services/auth.service.js +93 -0
- package/dist/services/storage.service.d.ts +17 -4
- package/dist/services/storage.service.js +72 -6
- package/oclif.manifest.json +39 -200
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ $ npm install -g @super-protocol/sp-cli
|
|
|
21
21
|
$ sp COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ sp (--version)
|
|
24
|
-
@super-protocol/sp-cli/0.0.2-beta.
|
|
24
|
+
@super-protocol/sp-cli/0.0.2-beta.2 linux-x64 node-v22.21.1
|
|
25
25
|
$ sp --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ sp COMMAND
|
|
@@ -30,6 +30,7 @@ USAGE
|
|
|
30
30
|
<!-- usagestop -->
|
|
31
31
|
# Commands
|
|
32
32
|
<!-- commands -->
|
|
33
|
+
* [`sp account info`](#sp-account-info)
|
|
33
34
|
* [`sp auth login`](#sp-auth-login)
|
|
34
35
|
* [`sp auth me`](#sp-auth-me)
|
|
35
36
|
* [`sp base`](#sp-base)
|
|
@@ -57,18 +58,30 @@ USAGE
|
|
|
57
58
|
* [`sp storage select`](#sp-storage-select)
|
|
58
59
|
* [`sp storage update`](#sp-storage-update)
|
|
59
60
|
|
|
61
|
+
## `sp account info`
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
USAGE
|
|
65
|
+
$ sp account info [--json] [--config <value>]
|
|
66
|
+
|
|
67
|
+
GLOBAL FLAGS
|
|
68
|
+
--config=<value> Specify config file.
|
|
69
|
+
--json Format output as json.
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
_See code: [src/commands/account/info.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/account/info.ts)_
|
|
73
|
+
|
|
60
74
|
## `sp auth login`
|
|
61
75
|
|
|
62
76
|
Authorization
|
|
63
77
|
|
|
64
78
|
```
|
|
65
79
|
USAGE
|
|
66
|
-
$ sp auth login [--json] [--config <value>]
|
|
80
|
+
$ sp auth login [--json] [--config <value>]
|
|
67
81
|
|
|
68
82
|
GLOBAL FLAGS
|
|
69
83
|
--config=<value> Specify config file.
|
|
70
84
|
--json Format output as json.
|
|
71
|
-
--url=<value> Specify provider base URL.
|
|
72
85
|
|
|
73
86
|
DESCRIPTION
|
|
74
87
|
Authorization
|
|
@@ -77,35 +90,33 @@ EXAMPLES
|
|
|
77
90
|
$ sp auth login
|
|
78
91
|
```
|
|
79
92
|
|
|
80
|
-
_See code: [src/commands/auth/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
93
|
+
_See code: [src/commands/auth/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/auth/login.ts)_
|
|
81
94
|
|
|
82
95
|
## `sp auth me`
|
|
83
96
|
|
|
84
97
|
```
|
|
85
98
|
USAGE
|
|
86
|
-
$ sp auth me [--json] [--config <value>]
|
|
99
|
+
$ sp auth me [--json] [--config <value>]
|
|
87
100
|
|
|
88
101
|
GLOBAL FLAGS
|
|
89
102
|
--config=<value> Specify config file.
|
|
90
103
|
--json Format output as json.
|
|
91
|
-
--url=<value> Specify provider base URL.
|
|
92
104
|
```
|
|
93
105
|
|
|
94
|
-
_See code: [src/commands/auth/me.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
106
|
+
_See code: [src/commands/auth/me.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/auth/me.ts)_
|
|
95
107
|
|
|
96
108
|
## `sp base`
|
|
97
109
|
|
|
98
110
|
```
|
|
99
111
|
USAGE
|
|
100
|
-
$ sp base [--json] [--config <value>]
|
|
112
|
+
$ sp base [--json] [--config <value>]
|
|
101
113
|
|
|
102
114
|
GLOBAL FLAGS
|
|
103
115
|
--config=<value> Specify config file.
|
|
104
116
|
--json Format output as json.
|
|
105
|
-
--url=<value> Specify provider base URL.
|
|
106
117
|
```
|
|
107
118
|
|
|
108
|
-
_See code: [src/commands/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
119
|
+
_See code: [src/commands/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/base.ts)_
|
|
109
120
|
|
|
110
121
|
## `sp config`
|
|
111
122
|
|
|
@@ -113,12 +124,10 @@ Manage configuration configs
|
|
|
113
124
|
|
|
114
125
|
```
|
|
115
126
|
USAGE
|
|
116
|
-
$ sp config [--json]
|
|
127
|
+
$ sp config [--json]
|
|
117
128
|
|
|
118
129
|
GLOBAL FLAGS
|
|
119
|
-
--
|
|
120
|
-
--json Format output as json.
|
|
121
|
-
--url=<value> Specify provider base URL.
|
|
130
|
+
--json Format output as json.
|
|
122
131
|
|
|
123
132
|
DESCRIPTION
|
|
124
133
|
Manage configuration configs
|
|
@@ -137,7 +146,7 @@ EXAMPLES
|
|
|
137
146
|
$ sp config delete - Delete a configuration
|
|
138
147
|
```
|
|
139
148
|
|
|
140
|
-
_See code: [src/commands/config/index.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
149
|
+
_See code: [src/commands/config/index.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/index.ts)_
|
|
141
150
|
|
|
142
151
|
## `sp config add [FILE]`
|
|
143
152
|
|
|
@@ -145,7 +154,7 @@ Import a configuration from a file
|
|
|
145
154
|
|
|
146
155
|
```
|
|
147
156
|
USAGE
|
|
148
|
-
$ sp config add [FILE] [--json] [
|
|
157
|
+
$ sp config add [FILE] [--json] [-n <value>] [-y]
|
|
149
158
|
|
|
150
159
|
ARGUMENTS
|
|
151
160
|
[FILE] Configuration file path to import
|
|
@@ -155,9 +164,7 @@ FLAGS
|
|
|
155
164
|
-y, --yes Automatically switch to imported configuration
|
|
156
165
|
|
|
157
166
|
GLOBAL FLAGS
|
|
158
|
-
--
|
|
159
|
-
--json Format output as json.
|
|
160
|
-
--url=<value> Specify provider base URL.
|
|
167
|
+
--json Format output as json.
|
|
161
168
|
|
|
162
169
|
DESCRIPTION
|
|
163
170
|
Import a configuration from a file
|
|
@@ -178,21 +185,19 @@ EXAMPLES
|
|
|
178
185
|
}
|
|
179
186
|
```
|
|
180
187
|
|
|
181
|
-
_See code: [src/commands/config/add.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
188
|
+
_See code: [src/commands/config/add.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/add.ts)_
|
|
182
189
|
|
|
183
190
|
## `sp config base`
|
|
184
191
|
|
|
185
192
|
```
|
|
186
193
|
USAGE
|
|
187
|
-
$ sp config base [--json]
|
|
194
|
+
$ sp config base [--json]
|
|
188
195
|
|
|
189
196
|
GLOBAL FLAGS
|
|
190
|
-
--
|
|
191
|
-
--json Format output as json.
|
|
192
|
-
--url=<value> Specify provider base URL.
|
|
197
|
+
--json Format output as json.
|
|
193
198
|
```
|
|
194
199
|
|
|
195
|
-
_See code: [src/commands/config/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
200
|
+
_See code: [src/commands/config/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/base.ts)_
|
|
196
201
|
|
|
197
202
|
## `sp config create`
|
|
198
203
|
|
|
@@ -200,7 +205,7 @@ Create a new configuration
|
|
|
200
205
|
|
|
201
206
|
```
|
|
202
207
|
USAGE
|
|
203
|
-
$ sp config create -n <value> [--json] [
|
|
208
|
+
$ sp config create -n <value> [--json] [-u <value>] [-y]
|
|
204
209
|
|
|
205
210
|
FLAGS
|
|
206
211
|
-n, --name=<value> (required) Configuration name
|
|
@@ -208,8 +213,7 @@ FLAGS
|
|
|
208
213
|
-y, --yes Switch to new config
|
|
209
214
|
|
|
210
215
|
GLOBAL FLAGS
|
|
211
|
-
--
|
|
212
|
-
--json Format output as json.
|
|
216
|
+
--json Format output as json.
|
|
213
217
|
|
|
214
218
|
DESCRIPTION
|
|
215
219
|
Create a new configuration
|
|
@@ -220,7 +224,7 @@ EXAMPLES
|
|
|
220
224
|
$ sp config create --name "Production" --url "https://api.dp.superprotocol.com"
|
|
221
225
|
```
|
|
222
226
|
|
|
223
|
-
_See code: [src/commands/config/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
227
|
+
_See code: [src/commands/config/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/create.ts)_
|
|
224
228
|
|
|
225
229
|
## `sp config delete`
|
|
226
230
|
|
|
@@ -228,16 +232,14 @@ Delete a configuration file
|
|
|
228
232
|
|
|
229
233
|
```
|
|
230
234
|
USAGE
|
|
231
|
-
$ sp config delete [--json] [
|
|
235
|
+
$ sp config delete [--json] [-f] [-n <value>]
|
|
232
236
|
|
|
233
237
|
FLAGS
|
|
234
238
|
-f, --force Force deletion without confirmation
|
|
235
239
|
-n, --name=<value> Configuration name to delete
|
|
236
240
|
|
|
237
241
|
GLOBAL FLAGS
|
|
238
|
-
--
|
|
239
|
-
--json Format output as json.
|
|
240
|
-
--url=<value> Specify provider base URL.
|
|
242
|
+
--json Format output as json.
|
|
241
243
|
|
|
242
244
|
DESCRIPTION
|
|
243
245
|
Delete a configuration file
|
|
@@ -250,7 +252,7 @@ EXAMPLES
|
|
|
250
252
|
$ sp config delete --name "My Config" --force
|
|
251
253
|
```
|
|
252
254
|
|
|
253
|
-
_See code: [src/commands/config/delete.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
255
|
+
_See code: [src/commands/config/delete.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/delete.ts)_
|
|
254
256
|
|
|
255
257
|
## `sp config list`
|
|
256
258
|
|
|
@@ -258,12 +260,10 @@ List all configurations
|
|
|
258
260
|
|
|
259
261
|
```
|
|
260
262
|
USAGE
|
|
261
|
-
$ sp config list [--json]
|
|
263
|
+
$ sp config list [--json]
|
|
262
264
|
|
|
263
265
|
GLOBAL FLAGS
|
|
264
|
-
--
|
|
265
|
-
--json Format output as json.
|
|
266
|
-
--url=<value> Specify provider base URL.
|
|
266
|
+
--json Format output as json.
|
|
267
267
|
|
|
268
268
|
DESCRIPTION
|
|
269
269
|
List all configurations
|
|
@@ -272,7 +272,7 @@ EXAMPLES
|
|
|
272
272
|
$ sp config list
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
-
_See code: [src/commands/config/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
275
|
+
_See code: [src/commands/config/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/list.ts)_
|
|
276
276
|
|
|
277
277
|
## `sp config show`
|
|
278
278
|
|
|
@@ -280,12 +280,10 @@ Show current configuration
|
|
|
280
280
|
|
|
281
281
|
```
|
|
282
282
|
USAGE
|
|
283
|
-
$ sp config show [--json]
|
|
283
|
+
$ sp config show [--json]
|
|
284
284
|
|
|
285
285
|
GLOBAL FLAGS
|
|
286
|
-
--
|
|
287
|
-
--json Format output as json.
|
|
288
|
-
--url=<value> Specify provider base URL.
|
|
286
|
+
--json Format output as json.
|
|
289
287
|
|
|
290
288
|
DESCRIPTION
|
|
291
289
|
Show current configuration
|
|
@@ -294,7 +292,7 @@ EXAMPLES
|
|
|
294
292
|
$ sp config show
|
|
295
293
|
```
|
|
296
294
|
|
|
297
|
-
_See code: [src/commands/config/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
295
|
+
_See code: [src/commands/config/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/show.ts)_
|
|
298
296
|
|
|
299
297
|
## `sp config use`
|
|
300
298
|
|
|
@@ -302,12 +300,10 @@ Switch to a different configuration file
|
|
|
302
300
|
|
|
303
301
|
```
|
|
304
302
|
USAGE
|
|
305
|
-
$ sp config use [--json]
|
|
303
|
+
$ sp config use [--json]
|
|
306
304
|
|
|
307
305
|
GLOBAL FLAGS
|
|
308
|
-
--
|
|
309
|
-
--json Format output as json.
|
|
310
|
-
--url=<value> Specify provider base URL.
|
|
306
|
+
--json Format output as json.
|
|
311
307
|
|
|
312
308
|
DESCRIPTION
|
|
313
309
|
Switch to a different configuration file
|
|
@@ -316,7 +312,7 @@ EXAMPLES
|
|
|
316
312
|
$ sp config use
|
|
317
313
|
```
|
|
318
314
|
|
|
319
|
-
_See code: [src/commands/config/use.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
315
|
+
_See code: [src/commands/config/use.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/config/use.ts)_
|
|
320
316
|
|
|
321
317
|
## `sp help [COMMAND]`
|
|
322
318
|
|
|
@@ -632,15 +628,14 @@ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
|
|
|
632
628
|
|
|
633
629
|
```
|
|
634
630
|
USAGE
|
|
635
|
-
$ sp storage base [--json] [--config <value>]
|
|
631
|
+
$ sp storage base [--json] [--config <value>]
|
|
636
632
|
|
|
637
633
|
GLOBAL FLAGS
|
|
638
634
|
--config=<value> Specify config file.
|
|
639
635
|
--json Format output as json.
|
|
640
|
-
--url=<value> Specify provider base URL.
|
|
641
636
|
```
|
|
642
637
|
|
|
643
|
-
_See code: [src/commands/storage/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
638
|
+
_See code: [src/commands/storage/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/storage/base.ts)_
|
|
644
639
|
|
|
645
640
|
## `sp storage create`
|
|
646
641
|
|
|
@@ -648,7 +643,7 @@ Create a new storage entry from file or interactive prompts.
|
|
|
648
643
|
|
|
649
644
|
```
|
|
650
645
|
USAGE
|
|
651
|
-
$ sp storage create [--json] [--config <value>] [
|
|
646
|
+
$ sp storage create [--json] [--config <value>] [-f <value>] [--notDefault]
|
|
652
647
|
|
|
653
648
|
FLAGS
|
|
654
649
|
-f, --fromFile=<value> Path to a JSON file that contains AddStorageDto payload.
|
|
@@ -657,7 +652,6 @@ FLAGS
|
|
|
657
652
|
GLOBAL FLAGS
|
|
658
653
|
--config=<value> Specify config file.
|
|
659
654
|
--json Format output as json.
|
|
660
|
-
--url=<value> Specify provider base URL.
|
|
661
655
|
|
|
662
656
|
DESCRIPTION
|
|
663
657
|
Create a new storage entry from file or interactive prompts.
|
|
@@ -670,7 +664,7 @@ EXAMPLES
|
|
|
670
664
|
$ sp storage create --not-default
|
|
671
665
|
```
|
|
672
666
|
|
|
673
|
-
_See code: [src/commands/storage/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
667
|
+
_See code: [src/commands/storage/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/storage/create.ts)_
|
|
674
668
|
|
|
675
669
|
## `sp storage select`
|
|
676
670
|
|
|
@@ -678,7 +672,7 @@ Select a storage that will be used by subsequent commands.
|
|
|
678
672
|
|
|
679
673
|
```
|
|
680
674
|
USAGE
|
|
681
|
-
$ sp storage select [--json] [--config <value>] [
|
|
675
|
+
$ sp storage select [--json] [--config <value>] [-i <value>]
|
|
682
676
|
|
|
683
677
|
FLAGS
|
|
684
678
|
-i, --id=<value> Storage ID to select
|
|
@@ -686,7 +680,6 @@ FLAGS
|
|
|
686
680
|
GLOBAL FLAGS
|
|
687
681
|
--config=<value> Specify config file.
|
|
688
682
|
--json Format output as json.
|
|
689
|
-
--url=<value> Specify provider base URL.
|
|
690
683
|
|
|
691
684
|
DESCRIPTION
|
|
692
685
|
Select a storage that will be used by subsequent commands.
|
|
@@ -697,7 +690,7 @@ EXAMPLES
|
|
|
697
690
|
$ sp storage select --id=2de3e3a4-0000-1111-2222-333344445555
|
|
698
691
|
```
|
|
699
692
|
|
|
700
|
-
_See code: [src/commands/storage/select.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
693
|
+
_See code: [src/commands/storage/select.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/storage/select.ts)_
|
|
701
694
|
|
|
702
695
|
## `sp storage update`
|
|
703
696
|
|
|
@@ -705,7 +698,7 @@ Update the configuration of an existing storage.
|
|
|
705
698
|
|
|
706
699
|
```
|
|
707
700
|
USAGE
|
|
708
|
-
$ sp storage update [--json] [--config <value>] [
|
|
701
|
+
$ sp storage update [--json] [--config <value>] [-f <value>] [-i <value>]
|
|
709
702
|
|
|
710
703
|
FLAGS
|
|
711
704
|
-f, --fromFile=<value> Path to a JSON file that contains UpdateStorageDto payload.
|
|
@@ -714,7 +707,6 @@ FLAGS
|
|
|
714
707
|
GLOBAL FLAGS
|
|
715
708
|
--config=<value> Specify config file.
|
|
716
709
|
--json Format output as json.
|
|
717
|
-
--url=<value> Specify provider base URL.
|
|
718
710
|
|
|
719
711
|
DESCRIPTION
|
|
720
712
|
Update the configuration of an existing storage.
|
|
@@ -725,5 +717,5 @@ EXAMPLES
|
|
|
725
717
|
$ sp storage update --id=2de3e3a4-0000-1111-2222-333344445555
|
|
726
718
|
```
|
|
727
719
|
|
|
728
|
-
_See code: [src/commands/storage/update.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
720
|
+
_See code: [src/commands/storage/update.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/storage/update.ts)_
|
|
729
721
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseCommand } from '../base.js';
|
|
2
|
+
export declare class InfoCommand extends BaseCommand<typeof InfoCommand> {
|
|
3
|
+
init(): Promise<void>;
|
|
4
|
+
run(): Promise<{
|
|
5
|
+
address: string;
|
|
6
|
+
balance: string;
|
|
7
|
+
storage: {
|
|
8
|
+
bucket: string;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
id: string;
|
|
11
|
+
isCentralized: boolean;
|
|
12
|
+
prefix: string;
|
|
13
|
+
s3Credentials?: import("@super-protocol/provider-client").components["schemas"]["S3CredentialsResponseDto"];
|
|
14
|
+
storageType: import("@super-protocol/provider-client").components["schemas"]["StorageType"];
|
|
15
|
+
storjCredentials?: import("@super-protocol/provider-client").components["schemas"]["StorJCredentialsResponseDto"];
|
|
16
|
+
updatedAt: string;
|
|
17
|
+
userId: string;
|
|
18
|
+
};
|
|
19
|
+
wallet: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { formatEther } from 'viem';
|
|
2
|
+
import { StorageService } from '../../services/storage.service.js';
|
|
3
|
+
import { BaseCommand } from '../base.js';
|
|
4
|
+
export class InfoCommand extends BaseCommand {
|
|
5
|
+
async init() {
|
|
6
|
+
await super.init();
|
|
7
|
+
await this.container.initProviderClient().initAccountManager().initConfigManager().build();
|
|
8
|
+
}
|
|
9
|
+
async run() {
|
|
10
|
+
const { providerClient } = this.container;
|
|
11
|
+
const storageService = new StorageService(providerClient, this.logger);
|
|
12
|
+
const { data, error } = await providerClient.GET('/api/auth/me');
|
|
13
|
+
if (error) {
|
|
14
|
+
this.error(error.message);
|
|
15
|
+
}
|
|
16
|
+
if (!data) {
|
|
17
|
+
this.error('Failed to retrieve account information');
|
|
18
|
+
}
|
|
19
|
+
const { data: wallet } = await providerClient.GET('/api/users/me/wallet');
|
|
20
|
+
if (!wallet) {
|
|
21
|
+
this.error('Failed to retrieve wallet information');
|
|
22
|
+
}
|
|
23
|
+
const storage = await storageService.getCurrentStorage();
|
|
24
|
+
const balance = formatEther(BigInt(wallet?.teeBalance || '0'), 'wei');
|
|
25
|
+
this.log(`Login: ${data.address}`);
|
|
26
|
+
this.log(`Super Wallet: ${data.internalAddress}`);
|
|
27
|
+
this.log(`Balance: ${balance} SPPI`);
|
|
28
|
+
if (storage.isCentralized) {
|
|
29
|
+
this.log('Storage: Super cloud');
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.log('Active storage:');
|
|
33
|
+
this.log(` bucket: ${storage.bucket}`);
|
|
34
|
+
this.log(` prefix: ${storage.prefix}`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
address: data.address,
|
|
38
|
+
balance,
|
|
39
|
+
storage,
|
|
40
|
+
wallet: data.internalAddress,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -3,16 +3,6 @@ export default class SpLogin extends BaseCommand<typeof SpLogin> {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
checkStorage(): Promise<void>;
|
|
6
|
-
getTokens(nonce: string): Promise<void>;
|
|
7
|
-
getUserNonce(address: string): Promise<{
|
|
8
|
-
error: {
|
|
9
|
-
message: string;
|
|
10
|
-
statusCode: number;
|
|
11
|
-
} | undefined;
|
|
12
|
-
user: {
|
|
13
|
-
nonce?: string;
|
|
14
|
-
} | undefined;
|
|
15
|
-
}>;
|
|
16
6
|
init(): Promise<void>;
|
|
17
7
|
run(): Promise<void>;
|
|
18
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AuthService } from '../../services/auth.service.js';
|
|
2
2
|
import { StorageService } from '../../services/storage.service.js';
|
|
3
3
|
import { BaseCommand } from '../base.js';
|
|
4
4
|
export default class SpLogin extends BaseCommand {
|
|
@@ -9,53 +9,13 @@ export default class SpLogin extends BaseCommand {
|
|
|
9
9
|
];
|
|
10
10
|
async checkStorage() {
|
|
11
11
|
await this.container.initProviderClient({ enableAuth: true, enableCookies: true, rebuild: true }).build();
|
|
12
|
-
const {
|
|
13
|
-
const storageService = new StorageService(
|
|
12
|
+
const { providerClient } = this.container;
|
|
13
|
+
const storageService = new StorageService(providerClient, this.logger);
|
|
14
14
|
if (!await storageService.hasStorage()) {
|
|
15
15
|
this.logger.info('Requesting default storage');
|
|
16
|
-
const
|
|
17
|
-
this.logger.info({
|
|
18
|
-
await storageService.saveStorage(
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
async getTokens(nonce) {
|
|
22
|
-
const { accountManager, configManager, providerClient } = this.container;
|
|
23
|
-
const signature = await accountManager.createSign(nonce);
|
|
24
|
-
const { data: tokenResponse, error, } = await providerClient.POST('/api/auth/token', {
|
|
25
|
-
body: {
|
|
26
|
-
address: accountManager.getAddress(),
|
|
27
|
-
provider: 'sp-cli',
|
|
28
|
-
signature,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
if (error) {
|
|
32
|
-
this.logger.error({ err: error }, 'Token exchange failed');
|
|
33
|
-
ux.error('Authorization failed please try again later.');
|
|
34
|
-
}
|
|
35
|
-
const { accessToken } = tokenResponse || {};
|
|
36
|
-
if (!accessToken) {
|
|
37
|
-
this.logger.error({ response: tokenResponse }, 'Unexpected token response');
|
|
38
|
-
ux.error('Provider returned an unexpected token response.');
|
|
39
|
-
}
|
|
40
|
-
await configManager.setCredentials({ accessKey: accessToken });
|
|
41
|
-
this.log('Authorization successful');
|
|
42
|
-
}
|
|
43
|
-
async getUserNonce(address) {
|
|
44
|
-
const { providerClient } = this.container;
|
|
45
|
-
try {
|
|
46
|
-
const { data, error } = await providerClient.GET('/api/users/nonce/{address}', {
|
|
47
|
-
params: {
|
|
48
|
-
path: {
|
|
49
|
-
address,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
this.logger.debug({ data, error }, 'Getting user nonce');
|
|
54
|
-
return { error, user: data };
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
this.logger.error({ err: error }, 'Error request nonce');
|
|
58
|
-
ux.error('Connection failure, please try again later');
|
|
16
|
+
const { id, isCentralized, storageType } = await storageService.initStorage();
|
|
17
|
+
this.logger.info({ id, isCentralized, storageType }, 'Requested new storage');
|
|
18
|
+
await storageService.saveStorage(id);
|
|
59
19
|
}
|
|
60
20
|
}
|
|
61
21
|
async init() {
|
|
@@ -63,48 +23,17 @@ export default class SpLogin extends BaseCommand {
|
|
|
63
23
|
await this.container
|
|
64
24
|
.initConfigManager()
|
|
65
25
|
.initAccountManager()
|
|
66
|
-
.initProviderClient({ enableAuth: false })
|
|
26
|
+
.initProviderClient({ enableAuth: false, enableCookies: true })
|
|
67
27
|
.build();
|
|
68
28
|
}
|
|
69
29
|
async run() {
|
|
70
|
-
const { accountManager, providerClient } = this.container;
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.logger.debug('Nonce error call sign up');
|
|
75
|
-
const { data: nonceResponse, error: signUpError } = await providerClient.POST('/api/auth/sign-up', {
|
|
76
|
-
body: {
|
|
77
|
-
address,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
if (signUpError && signUpError.statusCode === 409) {
|
|
81
|
-
this.logger.debug({ signUpError }, 'Error signing up');
|
|
82
|
-
const { error: nonceError, user } = await this.getUserNonce(address);
|
|
83
|
-
this.logger.debug({ nonceError, user }, 'Requesting nonce again');
|
|
84
|
-
if (user && user.nonce)
|
|
85
|
-
await this.getTokens(user.nonce);
|
|
86
|
-
else
|
|
87
|
-
ux.error('User exists but nonce is unavailable. Please try again or contact support.');
|
|
88
|
-
}
|
|
89
|
-
else if (signUpError) {
|
|
90
|
-
this.logger.error({ signUpError }, 'Sign-up failed');
|
|
91
|
-
ux.error('Sign-up failed. Please try again later.');
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const nonce = nonceResponse?.nonce;
|
|
95
|
-
if (!nonce) {
|
|
96
|
-
this.logger.error({ response: nonceResponse }, 'Unexpected sign-up response');
|
|
97
|
-
ux.error('Provider did not return a nonce.');
|
|
98
|
-
}
|
|
99
|
-
await this.getTokens(nonce);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (user && user.nonce) {
|
|
103
|
-
this.logger.debug({ user }, 'Requesting for existed user');
|
|
104
|
-
await this.getTokens(user.nonce);
|
|
30
|
+
const { accountManager, configManager, providerClient } = this.container;
|
|
31
|
+
const authService = new AuthService(accountManager, configManager, providerClient, this.logger);
|
|
32
|
+
try {
|
|
33
|
+
await authService.auth();
|
|
105
34
|
}
|
|
106
|
-
|
|
107
|
-
|
|
35
|
+
catch (error) {
|
|
36
|
+
this.error(error, { exit: 1 });
|
|
108
37
|
}
|
|
109
38
|
try {
|
|
110
39
|
await this.checkStorage();
|
package/dist/commands/base.d.ts
CHANGED
|
@@ -4,15 +4,13 @@ import { AppContainer } from '../lib/container.js';
|
|
|
4
4
|
export type CommandFlags<T extends typeof Command> = Interfaces.InferredFlags<T['flags'] & typeof BaseCommand['baseFlags']>;
|
|
5
5
|
export type CommandArgs<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
|
|
6
6
|
export declare abstract class BaseCommand<T extends typeof Command> extends Command {
|
|
7
|
-
static baseFlags:
|
|
8
|
-
config: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
9
|
-
url: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
10
|
-
};
|
|
7
|
+
static baseFlags: typeof Command.baseFlags;
|
|
11
8
|
static enableJsonFlag: boolean;
|
|
12
9
|
protected args: CommandArgs<T>;
|
|
13
10
|
protected container: AppContainer;
|
|
14
11
|
protected flags: CommandFlags<T>;
|
|
15
12
|
protected logger: pino.BaseLogger;
|
|
16
13
|
constructor(argv: string[], config: Config);
|
|
14
|
+
protected ensurePromptValue<T>(value: symbol | T, errorMessage?: string): T;
|
|
17
15
|
init(): Promise<void>;
|
|
18
16
|
}
|
package/dist/commands/base.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isCancel } from '@clack/prompts';
|
|
1
2
|
import { Command, Flags, } from '@oclif/core';
|
|
2
3
|
import { AppContainer } from '../lib/container.js';
|
|
3
4
|
import logger from '../logger.js';
|
|
@@ -8,11 +9,6 @@ export class BaseCommand extends Command {
|
|
|
8
9
|
required: false,
|
|
9
10
|
summary: 'Specify config file.',
|
|
10
11
|
}),
|
|
11
|
-
url: Flags.string({
|
|
12
|
-
helpGroup: 'GLOBAL',
|
|
13
|
-
required: false,
|
|
14
|
-
summary: 'Specify provider base URL.',
|
|
15
|
-
}),
|
|
16
12
|
};
|
|
17
13
|
static enableJsonFlag = true;
|
|
18
14
|
args;
|
|
@@ -23,14 +19,17 @@ export class BaseCommand extends Command {
|
|
|
23
19
|
super(argv, config);
|
|
24
20
|
this.logger = logger.getPino();
|
|
25
21
|
}
|
|
22
|
+
ensurePromptValue(value, errorMessage = 'Operation cancelled.') {
|
|
23
|
+
if (isCancel(value)) {
|
|
24
|
+
this.error(errorMessage);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
26
28
|
async init() {
|
|
27
29
|
await super.init();
|
|
28
30
|
const { args, flags } = await this.parse({
|
|
29
31
|
args: this.ctor.args,
|
|
30
|
-
baseFlags:
|
|
31
|
-
...BaseCommand.baseFlags,
|
|
32
|
-
...super.ctor.baseFlags,
|
|
33
|
-
},
|
|
32
|
+
baseFlags: super.ctor.baseFlags,
|
|
34
33
|
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
35
34
|
flags: this.ctor.flags,
|
|
36
35
|
strict: this.ctor.strict,
|
|
@@ -39,7 +38,6 @@ export class BaseCommand extends Command {
|
|
|
39
38
|
this.args = args;
|
|
40
39
|
this.container = AppContainer.container.setupRuntimeConfig({
|
|
41
40
|
configFile: flags.config,
|
|
42
|
-
url: flags.url,
|
|
43
41
|
});
|
|
44
42
|
}
|
|
45
43
|
}
|
|
@@ -48,7 +48,6 @@ export default class ConfigAdd extends BaseConfigCommand {
|
|
|
48
48
|
if (!existsSync(testPath)) {
|
|
49
49
|
return 'File does not exist';
|
|
50
50
|
}
|
|
51
|
-
return true;
|
|
52
51
|
},
|
|
53
52
|
});
|
|
54
53
|
}
|
|
@@ -66,15 +65,20 @@ export default class ConfigAdd extends BaseConfigCommand {
|
|
|
66
65
|
this.log(`Successfully imported configuration: ${displayName}`);
|
|
67
66
|
this.log(`Configuration file: ${importedFileName}`);
|
|
68
67
|
const shouldSwitch = this.flags.yes || await this.selectPrompt({
|
|
69
|
-
choices: [
|
|
70
|
-
{ name: 'Yes', value: true },
|
|
71
|
-
{ name: 'No', value: false },
|
|
72
|
-
],
|
|
73
68
|
message: 'Switch to this configuration now?',
|
|
69
|
+
options: [
|
|
70
|
+
{ label: 'Yes', value: true },
|
|
71
|
+
{ label: 'No', value: false },
|
|
72
|
+
],
|
|
74
73
|
});
|
|
75
74
|
if (shouldSwitch) {
|
|
76
75
|
await this.configFileManager.setCurrentConfig(importedFileName);
|
|
77
76
|
this.log(`Switched to configuration: ${displayName}`);
|
|
77
|
+
await this.container
|
|
78
|
+
.initConfigFileManager(true)
|
|
79
|
+
.initConfigManager(true)
|
|
80
|
+
.initAccountManager(true)
|
|
81
|
+
.build();
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
catch (error) {
|