@super-protocol/sp-cli 0.0.2-alpha.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.
Files changed (39) hide show
  1. package/README.md +144 -49
  2. package/dist/commands/account/info.d.ts +21 -0
  3. package/dist/commands/account/info.js +43 -0
  4. package/dist/commands/auth/login.d.ts +1 -10
  5. package/dist/commands/auth/login.js +23 -75
  6. package/dist/commands/base.d.ts +2 -4
  7. package/dist/commands/base.js +8 -10
  8. package/dist/commands/config/add.js +9 -5
  9. package/dist/commands/config/base.d.ts +4 -3
  10. package/dist/commands/config/base.js +12 -14
  11. package/dist/commands/config/create.js +4 -4
  12. package/dist/commands/config/list.js +2 -2
  13. package/dist/commands/config/use.js +5 -3
  14. package/dist/commands/storage/base.d.ts +8 -0
  15. package/dist/commands/storage/base.js +12 -0
  16. package/dist/commands/storage/create.d.ts +15 -0
  17. package/dist/commands/storage/create.js +169 -0
  18. package/dist/commands/storage/select.d.ts +9 -0
  19. package/dist/commands/storage/select.js +46 -0
  20. package/dist/commands/storage/update.d.ts +16 -0
  21. package/dist/commands/storage/update.js +244 -0
  22. package/dist/config/config.schema.d.ts +1 -0
  23. package/dist/config/config.schema.js +1 -0
  24. package/dist/constants.d.ts +1 -0
  25. package/dist/constants.js +1 -0
  26. package/dist/errors.d.ts +2 -0
  27. package/dist/errors.js +2 -0
  28. package/dist/lib/container.d.ts +6 -7
  29. package/dist/lib/container.js +26 -26
  30. package/dist/managers/account-manager.js +12 -2
  31. package/dist/managers/config-file-manager.d.ts +1 -1
  32. package/dist/managers/config-file-manager.js +12 -7
  33. package/dist/middlewares/auth-middleware.js +5 -1
  34. package/dist/services/auth.service.d.ts +24 -0
  35. package/dist/services/auth.service.js +93 -0
  36. package/dist/services/storage.service.d.ts +47 -0
  37. package/dist/services/storage.service.js +179 -0
  38. package/oclif.manifest.json +217 -137
  39. package/package.json +9 -3
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-alpha.1 linux-x64 node-v22.21.1
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)
@@ -52,6 +53,23 @@ USAGE
52
53
  * [`sp plugins uninstall [PLUGIN]`](#sp-plugins-uninstall-plugin)
53
54
  * [`sp plugins unlink [PLUGIN]`](#sp-plugins-unlink-plugin)
54
55
  * [`sp plugins update`](#sp-plugins-update)
56
+ * [`sp storage base`](#sp-storage-base)
57
+ * [`sp storage create`](#sp-storage-create)
58
+ * [`sp storage select`](#sp-storage-select)
59
+ * [`sp storage update`](#sp-storage-update)
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)_
55
73
 
56
74
  ## `sp auth login`
57
75
 
@@ -59,12 +77,11 @@ Authorization
59
77
 
60
78
  ```
61
79
  USAGE
62
- $ sp auth login [--json] [--config <value>] [--url <value>]
80
+ $ sp auth login [--json] [--config <value>]
63
81
 
64
82
  GLOBAL FLAGS
65
83
  --config=<value> Specify config file.
66
84
  --json Format output as json.
67
- --url=<value> Specify provider base URL.
68
85
 
69
86
  DESCRIPTION
70
87
  Authorization
@@ -73,35 +90,33 @@ EXAMPLES
73
90
  $ sp auth login
74
91
  ```
75
92
 
76
- _See code: [src/commands/auth/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/auth/login.ts)_
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)_
77
94
 
78
95
  ## `sp auth me`
79
96
 
80
97
  ```
81
98
  USAGE
82
- $ sp auth me [--json] [--config <value>] [--url <value>]
99
+ $ sp auth me [--json] [--config <value>]
83
100
 
84
101
  GLOBAL FLAGS
85
102
  --config=<value> Specify config file.
86
103
  --json Format output as json.
87
- --url=<value> Specify provider base URL.
88
104
  ```
89
105
 
90
- _See code: [src/commands/auth/me.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/auth/me.ts)_
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)_
91
107
 
92
108
  ## `sp base`
93
109
 
94
110
  ```
95
111
  USAGE
96
- $ sp base [--json] [--config <value>] [--url <value>]
112
+ $ sp base [--json] [--config <value>]
97
113
 
98
114
  GLOBAL FLAGS
99
115
  --config=<value> Specify config file.
100
116
  --json Format output as json.
101
- --url=<value> Specify provider base URL.
102
117
  ```
103
118
 
104
- _See code: [src/commands/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/base.ts)_
119
+ _See code: [src/commands/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.2/src/commands/base.ts)_
105
120
 
106
121
  ## `sp config`
107
122
 
@@ -109,12 +124,10 @@ Manage configuration configs
109
124
 
110
125
  ```
111
126
  USAGE
112
- $ sp config [--json] [--config <value>] [--url <value>]
127
+ $ sp config [--json]
113
128
 
114
129
  GLOBAL FLAGS
115
- --config=<value> Specify config file.
116
- --json Format output as json.
117
- --url=<value> Specify provider base URL.
130
+ --json Format output as json.
118
131
 
119
132
  DESCRIPTION
120
133
  Manage configuration configs
@@ -133,7 +146,7 @@ EXAMPLES
133
146
  $ sp config delete - Delete a configuration
134
147
  ```
135
148
 
136
- _See code: [src/commands/config/index.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/index.ts)_
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)_
137
150
 
138
151
  ## `sp config add [FILE]`
139
152
 
@@ -141,7 +154,7 @@ Import a configuration from a file
141
154
 
142
155
  ```
143
156
  USAGE
144
- $ sp config add [FILE] [--json] [--config <value>] [--url <value>] [-n <value>] [-y]
157
+ $ sp config add [FILE] [--json] [-n <value>] [-y]
145
158
 
146
159
  ARGUMENTS
147
160
  [FILE] Configuration file path to import
@@ -151,9 +164,7 @@ FLAGS
151
164
  -y, --yes Automatically switch to imported configuration
152
165
 
153
166
  GLOBAL FLAGS
154
- --config=<value> Specify config file.
155
- --json Format output as json.
156
- --url=<value> Specify provider base URL.
167
+ --json Format output as json.
157
168
 
158
169
  DESCRIPTION
159
170
  Import a configuration from a file
@@ -174,21 +185,19 @@ EXAMPLES
174
185
  }
175
186
  ```
176
187
 
177
- _See code: [src/commands/config/add.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/add.ts)_
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)_
178
189
 
179
190
  ## `sp config base`
180
191
 
181
192
  ```
182
193
  USAGE
183
- $ sp config base [--json] [--config <value>] [--url <value>]
194
+ $ sp config base [--json]
184
195
 
185
196
  GLOBAL FLAGS
186
- --config=<value> Specify config file.
187
- --json Format output as json.
188
- --url=<value> Specify provider base URL.
197
+ --json Format output as json.
189
198
  ```
190
199
 
191
- _See code: [src/commands/config/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/base.ts)_
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)_
192
201
 
193
202
  ## `sp config create`
194
203
 
@@ -196,7 +205,7 @@ Create a new configuration
196
205
 
197
206
  ```
198
207
  USAGE
199
- $ sp config create -n <value> [--json] [--config <value>] [-u <value>] [-y]
208
+ $ sp config create -n <value> [--json] [-u <value>] [-y]
200
209
 
201
210
  FLAGS
202
211
  -n, --name=<value> (required) Configuration name
@@ -204,8 +213,7 @@ FLAGS
204
213
  -y, --yes Switch to new config
205
214
 
206
215
  GLOBAL FLAGS
207
- --config=<value> Specify config file.
208
- --json Format output as json.
216
+ --json Format output as json.
209
217
 
210
218
  DESCRIPTION
211
219
  Create a new configuration
@@ -216,7 +224,7 @@ EXAMPLES
216
224
  $ sp config create --name "Production" --url "https://api.dp.superprotocol.com"
217
225
  ```
218
226
 
219
- _See code: [src/commands/config/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/create.ts)_
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)_
220
228
 
221
229
  ## `sp config delete`
222
230
 
@@ -224,16 +232,14 @@ Delete a configuration file
224
232
 
225
233
  ```
226
234
  USAGE
227
- $ sp config delete [--json] [--config <value>] [--url <value>] [-f] [-n <value>]
235
+ $ sp config delete [--json] [-f] [-n <value>]
228
236
 
229
237
  FLAGS
230
238
  -f, --force Force deletion without confirmation
231
239
  -n, --name=<value> Configuration name to delete
232
240
 
233
241
  GLOBAL FLAGS
234
- --config=<value> Specify config file.
235
- --json Format output as json.
236
- --url=<value> Specify provider base URL.
242
+ --json Format output as json.
237
243
 
238
244
  DESCRIPTION
239
245
  Delete a configuration file
@@ -246,7 +252,7 @@ EXAMPLES
246
252
  $ sp config delete --name "My Config" --force
247
253
  ```
248
254
 
249
- _See code: [src/commands/config/delete.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/delete.ts)_
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)_
250
256
 
251
257
  ## `sp config list`
252
258
 
@@ -254,12 +260,10 @@ List all configurations
254
260
 
255
261
  ```
256
262
  USAGE
257
- $ sp config list [--json] [--config <value>] [--url <value>]
263
+ $ sp config list [--json]
258
264
 
259
265
  GLOBAL FLAGS
260
- --config=<value> Specify config file.
261
- --json Format output as json.
262
- --url=<value> Specify provider base URL.
266
+ --json Format output as json.
263
267
 
264
268
  DESCRIPTION
265
269
  List all configurations
@@ -268,7 +272,7 @@ EXAMPLES
268
272
  $ sp config list
269
273
  ```
270
274
 
271
- _See code: [src/commands/config/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/list.ts)_
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)_
272
276
 
273
277
  ## `sp config show`
274
278
 
@@ -276,12 +280,10 @@ Show current configuration
276
280
 
277
281
  ```
278
282
  USAGE
279
- $ sp config show [--json] [--config <value>] [--url <value>]
283
+ $ sp config show [--json]
280
284
 
281
285
  GLOBAL FLAGS
282
- --config=<value> Specify config file.
283
- --json Format output as json.
284
- --url=<value> Specify provider base URL.
286
+ --json Format output as json.
285
287
 
286
288
  DESCRIPTION
287
289
  Show current configuration
@@ -290,7 +292,7 @@ EXAMPLES
290
292
  $ sp config show
291
293
  ```
292
294
 
293
- _See code: [src/commands/config/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/show.ts)_
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)_
294
296
 
295
297
  ## `sp config use`
296
298
 
@@ -298,12 +300,10 @@ Switch to a different configuration file
298
300
 
299
301
  ```
300
302
  USAGE
301
- $ sp config use [--json] [--config <value>] [--url <value>]
303
+ $ sp config use [--json]
302
304
 
303
305
  GLOBAL FLAGS
304
- --config=<value> Specify config file.
305
- --json Format output as json.
306
- --url=<value> Specify provider base URL.
306
+ --json Format output as json.
307
307
 
308
308
  DESCRIPTION
309
309
  Switch to a different configuration file
@@ -312,7 +312,7 @@ EXAMPLES
312
312
  $ sp config use
313
313
  ```
314
314
 
315
- _See code: [src/commands/config/use.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-alpha.1/src/commands/config/use.ts)_
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)_
316
316
 
317
317
  ## `sp help [COMMAND]`
318
318
 
@@ -623,4 +623,99 @@ DESCRIPTION
623
623
  ```
624
624
 
625
625
  _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/update.ts)_
626
+
627
+ ## `sp storage base`
628
+
629
+ ```
630
+ USAGE
631
+ $ sp storage base [--json] [--config <value>]
632
+
633
+ GLOBAL FLAGS
634
+ --config=<value> Specify config file.
635
+ --json Format output as json.
636
+ ```
637
+
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)_
639
+
640
+ ## `sp storage create`
641
+
642
+ Create a new storage entry from file or interactive prompts.
643
+
644
+ ```
645
+ USAGE
646
+ $ sp storage create [--json] [--config <value>] [-f <value>] [--notDefault]
647
+
648
+ FLAGS
649
+ -f, --fromFile=<value> Path to a JSON file that contains AddStorageDto payload.
650
+ --notDefault Skip setting the created storage as default.
651
+
652
+ GLOBAL FLAGS
653
+ --config=<value> Specify config file.
654
+ --json Format output as json.
655
+
656
+ DESCRIPTION
657
+ Create a new storage entry from file or interactive prompts.
658
+
659
+ EXAMPLES
660
+ $ sp storage create
661
+
662
+ $ sp storage create --fromFile ./storage.json
663
+
664
+ $ sp storage create --not-default
665
+ ```
666
+
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)_
668
+
669
+ ## `sp storage select`
670
+
671
+ Select a storage that will be used by subsequent commands.
672
+
673
+ ```
674
+ USAGE
675
+ $ sp storage select [--json] [--config <value>] [-i <value>]
676
+
677
+ FLAGS
678
+ -i, --id=<value> Storage ID to select
679
+
680
+ GLOBAL FLAGS
681
+ --config=<value> Specify config file.
682
+ --json Format output as json.
683
+
684
+ DESCRIPTION
685
+ Select a storage that will be used by subsequent commands.
686
+
687
+ EXAMPLES
688
+ $ sp storage select
689
+
690
+ $ sp storage select --id=2de3e3a4-0000-1111-2222-333344445555
691
+ ```
692
+
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)_
694
+
695
+ ## `sp storage update`
696
+
697
+ Update the configuration of an existing storage.
698
+
699
+ ```
700
+ USAGE
701
+ $ sp storage update [--json] [--config <value>] [-f <value>] [-i <value>]
702
+
703
+ FLAGS
704
+ -f, --fromFile=<value> Path to a JSON file that contains UpdateStorageDto payload.
705
+ -i, --id=<value> Storage ID to update
706
+
707
+ GLOBAL FLAGS
708
+ --config=<value> Specify config file.
709
+ --json Format output as json.
710
+
711
+ DESCRIPTION
712
+ Update the configuration of an existing storage.
713
+
714
+ EXAMPLES
715
+ $ sp storage update --id=2de3e3a4-0000-1111-2222-333344445555 --fromFile ./storage-update.json
716
+
717
+ $ sp storage update --id=2de3e3a4-0000-1111-2222-333344445555
718
+ ```
719
+
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)_
626
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
+ }
@@ -2,16 +2,7 @@ import { BaseCommand } from '../base.js';
2
2
  export default class SpLogin extends BaseCommand<typeof SpLogin> {
3
3
  static description: string;
4
4
  static examples: string[];
5
- getTokens(nonce: string): Promise<void>;
6
- getUserNonce(address: string): Promise<{
7
- error: {
8
- message: string;
9
- statusCode: number;
10
- } | undefined;
11
- user: {
12
- nonce?: string;
13
- } | undefined;
14
- }>;
5
+ checkStorage(): Promise<void>;
15
6
  init(): Promise<void>;
16
7
  run(): Promise<void>;
17
8
  }
@@ -1,4 +1,5 @@
1
- import { ux } from '@oclif/core';
1
+ import { AuthService } from '../../services/auth.service.js';
2
+ import { StorageService } from '../../services/storage.service.js';
2
3
  import { BaseCommand } from '../base.js';
3
4
  export default class SpLogin extends BaseCommand {
4
5
  static description = 'Authorization';
@@ -6,44 +7,15 @@ export default class SpLogin extends BaseCommand {
6
7
  `<%= config.bin %> <%= command.id %>
7
8
  `,
8
9
  ];
9
- async getTokens(nonce) {
10
- const { accountManager, configManager, providerClient } = this.container;
11
- const signature = await accountManager.createSign(nonce);
12
- const { data: tokenResponse, error, } = await providerClient.POST('/api/auth/token', {
13
- body: {
14
- address: accountManager.getAddress(),
15
- provider: 'sp-cli',
16
- signature,
17
- },
18
- });
19
- if (error) {
20
- this.logger.error({ err: error }, 'Token exchange failed');
21
- ux.error('Authorization failed please try again later.');
22
- }
23
- const { accessToken } = tokenResponse || {};
24
- if (!accessToken) {
25
- this.logger.error({ response: tokenResponse }, 'Unexpected token response');
26
- ux.error('Provider returned an unexpected token response.');
27
- }
28
- await configManager.setCredentials({ accessKey: accessToken });
29
- this.log('Authorization successful');
30
- }
31
- async getUserNonce(address) {
10
+ async checkStorage() {
11
+ await this.container.initProviderClient({ enableAuth: true, enableCookies: true, rebuild: true }).build();
32
12
  const { providerClient } = this.container;
33
- try {
34
- const { data, error } = await providerClient.GET('/api/users/nonce/{address}', {
35
- params: {
36
- path: {
37
- address,
38
- },
39
- },
40
- });
41
- this.logger.debug({ data, error }, 'Getting user nonce');
42
- return { error, user: data };
43
- }
44
- catch (error) {
45
- this.logger.error({ err: error }, 'Error request nonce');
46
- ux.error('Connection failure, please try again later');
13
+ const storageService = new StorageService(providerClient, this.logger);
14
+ if (!await storageService.hasStorage()) {
15
+ this.logger.info('Requesting default storage');
16
+ const { id, isCentralized, storageType } = await storageService.initStorage();
17
+ this.logger.info({ id, isCentralized, storageType }, 'Requested new storage');
18
+ await storageService.saveStorage(id);
47
19
  }
48
20
  }
49
21
  async init() {
@@ -51,48 +23,24 @@ export default class SpLogin extends BaseCommand {
51
23
  await this.container
52
24
  .initConfigManager()
53
25
  .initAccountManager()
54
- .initProviderClient({ enableAuth: false })
26
+ .initProviderClient({ enableAuth: false, enableCookies: true })
55
27
  .build();
56
28
  }
57
29
  async run() {
58
- const { accountManager, providerClient } = this.container;
59
- const address = accountManager.getAddress();
60
- const { error: nonceError, user } = await this.getUserNonce(address);
61
- if (nonceError && nonceError.statusCode === 404) {
62
- this.logger.debug('Nonce error call sign up');
63
- const { data: nonceResponse, error: signUpError } = await providerClient.POST('/api/auth/sign-up', {
64
- body: {
65
- address,
66
- },
67
- });
68
- if (signUpError && signUpError.statusCode === 409) {
69
- this.logger.debug({ signUpError }, 'Error signing up');
70
- const { error: nonceError, user } = await this.getUserNonce(address);
71
- this.logger.debug({ nonceError, user }, 'Requesting nonce again');
72
- if (user && user.nonce)
73
- await this.getTokens(user.nonce);
74
- else
75
- ux.error('User exists but nonce is unavailable. Please try again or contact support.');
76
- }
77
- else if (signUpError) {
78
- this.logger.error({ signUpError }, 'Sign-up failed');
79
- ux.error('Sign-up failed. Please try again later.');
80
- }
81
- else {
82
- const nonce = nonceResponse?.nonce;
83
- if (!nonce) {
84
- this.logger.error({ response: nonceResponse }, 'Unexpected sign-up response');
85
- ux.error('Provider did not return a nonce.');
86
- }
87
- await this.getTokens(nonce);
88
- }
30
+ const { accountManager, configManager, providerClient } = this.container;
31
+ const authService = new AuthService(accountManager, configManager, providerClient, this.logger);
32
+ try {
33
+ await authService.auth();
34
+ }
35
+ catch (error) {
36
+ this.error(error, { exit: 1 });
89
37
  }
90
- else if (user && user.nonce) {
91
- this.logger.debug({ user }, 'Requesting for existed user');
92
- await this.getTokens(user.nonce);
38
+ try {
39
+ await this.checkStorage();
93
40
  }
94
- else {
95
- ux.error('Unable to retrieve authentication nonce. Please try again later or contact support if the issue persists.');
41
+ catch (error) {
42
+ this.logger.error({ err: error }, 'Storage initialization failed');
43
+ this.warn('Storage initialization failed. You can set up storage later using "sp storage create" or "sp storage select".');
96
44
  }
97
45
  }
98
46
  }
@@ -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
  }
@@ -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
  }