@super-protocol/sp-cli 0.0.1-alpha.42 → 0.0.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 (69) hide show
  1. package/README.md +260 -65
  2. package/bin/dev.cmd +1 -1
  3. package/bin/dev.js +5 -3
  4. package/bin/run.js +3 -2
  5. package/dist/commands/auth/login.d.ts +3 -2
  6. package/dist/commands/auth/login.js +52 -24
  7. package/dist/commands/auth/me.d.ts +3 -2
  8. package/dist/commands/auth/me.js +9 -4
  9. package/dist/commands/base.d.ts +18 -0
  10. package/dist/commands/base.js +45 -0
  11. package/dist/commands/config/add.d.ts +13 -0
  12. package/dist/commands/config/add.js +84 -0
  13. package/dist/commands/config/base.d.ts +14 -0
  14. package/dist/commands/config/base.js +62 -0
  15. package/dist/commands/config/create.d.ts +11 -0
  16. package/dist/commands/config/create.js +51 -0
  17. package/dist/commands/config/delete.d.ts +10 -0
  18. package/dist/commands/config/delete.js +25 -0
  19. package/dist/commands/config/index.d.ts +6 -0
  20. package/dist/commands/config/index.js +22 -0
  21. package/dist/commands/config/list.d.ts +6 -0
  22. package/dist/commands/config/list.js +39 -0
  23. package/dist/commands/config/show.d.ts +6 -0
  24. package/dist/commands/config/show.js +10 -0
  25. package/dist/commands/config/use.d.ts +6 -0
  26. package/dist/commands/config/use.js +25 -0
  27. package/dist/config/config-file.schema.d.ts +6 -0
  28. package/dist/config/config-file.schema.js +5 -0
  29. package/dist/config/config.schema.d.ts +2 -0
  30. package/dist/config/config.schema.js +12 -1
  31. package/dist/constants.d.ts +3 -0
  32. package/dist/constants.js +5 -0
  33. package/dist/hooks/init/init-container.d.ts +3 -0
  34. package/dist/hooks/init/init-container.js +6 -0
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.js +23 -1
  37. package/dist/interfaces/index.d.ts +0 -1
  38. package/dist/interfaces/index.js +0 -1
  39. package/dist/interfaces/manager.interface.d.ts +1 -1
  40. package/dist/lib/container.d.ts +40 -0
  41. package/dist/lib/container.js +177 -0
  42. package/dist/logger.d.ts +6 -0
  43. package/dist/logger.js +62 -0
  44. package/dist/managers/account-manager.d.ts +2 -2
  45. package/dist/managers/account-manager.js +18 -9
  46. package/dist/managers/config-file-manager.d.ts +50 -0
  47. package/dist/managers/config-file-manager.js +278 -0
  48. package/dist/managers/config-manager.d.ts +12 -6
  49. package/dist/managers/config-manager.js +38 -14
  50. package/dist/managers/index.d.ts +1 -2
  51. package/dist/managers/index.js +1 -2
  52. package/dist/middlewares/auth-middleware.d.ts +9 -0
  53. package/dist/middlewares/auth-middleware.js +87 -0
  54. package/dist/middlewares/cookies-middleware.d.ts +8 -0
  55. package/dist/middlewares/cookies-middleware.js +80 -0
  56. package/dist/utils/helper.d.ts +1 -0
  57. package/dist/utils/helper.js +1 -0
  58. package/oclif.manifest.json +545 -7
  59. package/package.json +32 -14
  60. package/dist/commands/refresh.d.ts +0 -4
  61. package/dist/commands/refresh.js +0 -7
  62. package/dist/config/constants.d.ts +0 -1
  63. package/dist/config/constants.js +0 -2
  64. package/dist/interfaces/abstract.command.d.ts +0 -16
  65. package/dist/interfaces/abstract.command.js +0 -59
  66. package/dist/managers/auth-manager.d.ts +0 -19
  67. package/dist/managers/auth-manager.js +0 -101
  68. package/dist/managers/cookies-manager.d.ts +0 -15
  69. package/dist/managers/cookies-manager.js +0 -92
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.1-alpha.42 linux-x64 node-v22.20.0
24
+ @super-protocol/sp-cli/0.0.2 linux-x64 node-v22.21.1
25
25
  $ sp --help [COMMAND]
26
26
  USAGE
27
27
  $ sp COMMAND
@@ -32,6 +32,15 @@ USAGE
32
32
  <!-- commands -->
33
33
  * [`sp auth login`](#sp-auth-login)
34
34
  * [`sp auth me`](#sp-auth-me)
35
+ * [`sp base`](#sp-base)
36
+ * [`sp config`](#sp-config)
37
+ * [`sp config add [FILE]`](#sp-config-add-file)
38
+ * [`sp config base`](#sp-config-base)
39
+ * [`sp config create`](#sp-config-create)
40
+ * [`sp config delete`](#sp-config-delete)
41
+ * [`sp config list`](#sp-config-list)
42
+ * [`sp config show`](#sp-config-show)
43
+ * [`sp config use`](#sp-config-use)
35
44
  * [`sp help [COMMAND]`](#sp-help-command)
36
45
  * [`sp plugins`](#sp-plugins)
37
46
  * [`sp plugins add PLUGIN`](#sp-plugins-add-plugin)
@@ -43,8 +52,6 @@ USAGE
43
52
  * [`sp plugins uninstall [PLUGIN]`](#sp-plugins-uninstall-plugin)
44
53
  * [`sp plugins unlink [PLUGIN]`](#sp-plugins-unlink-plugin)
45
54
  * [`sp plugins update`](#sp-plugins-update)
46
- * [`sp refresh`](#sp-refresh)
47
- * [`sp update [CHANNEL]`](#sp-update-channel)
48
55
 
49
56
  ## `sp auth login`
50
57
 
@@ -52,7 +59,12 @@ Authorization
52
59
 
53
60
  ```
54
61
  USAGE
55
- $ sp auth login
62
+ $ sp auth login [--json] [--config <value>] [--url <value>]
63
+
64
+ GLOBAL FLAGS
65
+ --config=<value> Specify config file.
66
+ --json Format output as json.
67
+ --url=<value> Specify provider base URL.
56
68
 
57
69
  DESCRIPTION
58
70
  Authorization
@@ -61,16 +73,246 @@ EXAMPLES
61
73
  $ sp auth login
62
74
  ```
63
75
 
64
- _See code: [src/commands/auth/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.1-alpha.42/src/commands/auth/login.ts)_
76
+ _See code: [src/commands/auth/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/auth/login.ts)_
65
77
 
66
78
  ## `sp auth me`
67
79
 
68
80
  ```
69
81
  USAGE
70
- $ sp auth me
82
+ $ sp auth me [--json] [--config <value>] [--url <value>]
83
+
84
+ GLOBAL FLAGS
85
+ --config=<value> Specify config file.
86
+ --json Format output as json.
87
+ --url=<value> Specify provider base URL.
88
+ ```
89
+
90
+ _See code: [src/commands/auth/me.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/auth/me.ts)_
91
+
92
+ ## `sp base`
93
+
94
+ ```
95
+ USAGE
96
+ $ sp base [--json] [--config <value>] [--url <value>]
97
+
98
+ GLOBAL FLAGS
99
+ --config=<value> Specify config file.
100
+ --json Format output as json.
101
+ --url=<value> Specify provider base URL.
102
+ ```
103
+
104
+ _See code: [src/commands/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/base.ts)_
105
+
106
+ ## `sp config`
107
+
108
+ Manage configuration configs
109
+
110
+ ```
111
+ USAGE
112
+ $ sp config [--json] [--config <value>] [--url <value>]
113
+
114
+ GLOBAL FLAGS
115
+ --config=<value> Specify config file.
116
+ --json Format output as json.
117
+ --url=<value> Specify provider base URL.
118
+
119
+ DESCRIPTION
120
+ Manage configuration configs
121
+
122
+ EXAMPLES
123
+ $ sp config show - Show current configuration details
124
+
125
+ $ sp config list - List all configurations
126
+
127
+ $ sp config use - Switch to a configuration
128
+
129
+ $ sp config create --name "My Config" - Create new configuration
130
+
131
+ $ sp config add ./config.json - Import configuration from file
132
+
133
+ $ sp config delete - Delete a configuration
134
+ ```
135
+
136
+ _See code: [src/commands/config/index.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/index.ts)_
137
+
138
+ ## `sp config add [FILE]`
139
+
140
+ Import a configuration from a file
141
+
142
+ ```
143
+ USAGE
144
+ $ sp config add [FILE] [--json] [--config <value>] [--url <value>] [-n <value>] [-y]
145
+
146
+ ARGUMENTS
147
+ [FILE] Configuration file path to import
148
+
149
+ FLAGS
150
+ -n, --name=<value> Custom name for the imported configuration
151
+ -y, --yes Automatically switch to imported configuration
152
+
153
+ GLOBAL FLAGS
154
+ --config=<value> Specify config file.
155
+ --json Format output as json.
156
+ --url=<value> Specify provider base URL.
157
+
158
+ DESCRIPTION
159
+ Import a configuration from a file
160
+
161
+ EXAMPLES
162
+ $ sp config add ./my-config.json
163
+
164
+ $ sp config add ./my-config.json --name "Imported"
165
+
166
+ Configuration files must follow this schema:
167
+ {
168
+ "providerUrl": "https://api.dp.superprotocol.com",
169
+ "name": "Some name",
170
+ "account": {
171
+ "address": "0x111222333444555....",
172
+ "privateKey": "0x000011122233344555..."
173
+ }
174
+ }
175
+ ```
176
+
177
+ _See code: [src/commands/config/add.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/add.ts)_
178
+
179
+ ## `sp config base`
180
+
181
+ ```
182
+ USAGE
183
+ $ sp config base [--json] [--config <value>] [--url <value>]
184
+
185
+ GLOBAL FLAGS
186
+ --config=<value> Specify config file.
187
+ --json Format output as json.
188
+ --url=<value> Specify provider base URL.
189
+ ```
190
+
191
+ _See code: [src/commands/config/base.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/base.ts)_
192
+
193
+ ## `sp config create`
194
+
195
+ Create a new configuration
196
+
197
+ ```
198
+ USAGE
199
+ $ sp config create -n <value> [--json] [--config <value>] [-u <value>] [-y]
200
+
201
+ FLAGS
202
+ -n, --name=<value> (required) Configuration name
203
+ -u, --url=<value> Provider base URL
204
+ -y, --yes Switch to new config
205
+
206
+ GLOBAL FLAGS
207
+ --config=<value> Specify config file.
208
+ --json Format output as json.
209
+
210
+ DESCRIPTION
211
+ Create a new configuration
212
+
213
+ EXAMPLES
214
+ $ sp config create --name "My Config"
215
+
216
+ $ sp config create --name "Production" --url "https://api.dp.superprotocol.com"
217
+ ```
218
+
219
+ _See code: [src/commands/config/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/create.ts)_
220
+
221
+ ## `sp config delete`
222
+
223
+ Delete a configuration file
224
+
225
+ ```
226
+ USAGE
227
+ $ sp config delete [--json] [--config <value>] [--url <value>] [-f] [-n <value>]
228
+
229
+ FLAGS
230
+ -f, --force Force deletion without confirmation
231
+ -n, --name=<value> Configuration name to delete
232
+
233
+ GLOBAL FLAGS
234
+ --config=<value> Specify config file.
235
+ --json Format output as json.
236
+ --url=<value> Specify provider base URL.
237
+
238
+ DESCRIPTION
239
+ Delete a configuration file
240
+
241
+ EXAMPLES
242
+ $ sp config delete
243
+
244
+ $ sp config delete --name "My Config"
245
+
246
+ $ sp config delete --name "My Config" --force
247
+ ```
248
+
249
+ _See code: [src/commands/config/delete.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/delete.ts)_
250
+
251
+ ## `sp config list`
252
+
253
+ List all configurations
254
+
71
255
  ```
256
+ USAGE
257
+ $ sp config list [--json] [--config <value>] [--url <value>]
258
+
259
+ GLOBAL FLAGS
260
+ --config=<value> Specify config file.
261
+ --json Format output as json.
262
+ --url=<value> Specify provider base URL.
263
+
264
+ DESCRIPTION
265
+ List all configurations
266
+
267
+ EXAMPLES
268
+ $ sp config list
269
+ ```
270
+
271
+ _See code: [src/commands/config/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/list.ts)_
272
+
273
+ ## `sp config show`
274
+
275
+ Show current configuration
276
+
277
+ ```
278
+ USAGE
279
+ $ sp config show [--json] [--config <value>] [--url <value>]
280
+
281
+ GLOBAL FLAGS
282
+ --config=<value> Specify config file.
283
+ --json Format output as json.
284
+ --url=<value> Specify provider base URL.
285
+
286
+ DESCRIPTION
287
+ Show current configuration
288
+
289
+ EXAMPLES
290
+ $ sp config show
291
+ ```
292
+
293
+ _See code: [src/commands/config/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/show.ts)_
72
294
 
73
- _See code: [src/commands/auth/me.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.1-alpha.42/src/commands/auth/me.ts)_
295
+ ## `sp config use`
296
+
297
+ Switch to a different configuration file
298
+
299
+ ```
300
+ USAGE
301
+ $ sp config use [--json] [--config <value>] [--url <value>]
302
+
303
+ GLOBAL FLAGS
304
+ --config=<value> Specify config file.
305
+ --json Format output as json.
306
+ --url=<value> Specify provider base URL.
307
+
308
+ DESCRIPTION
309
+ Switch to a different configuration file
310
+
311
+ EXAMPLES
312
+ $ sp config use
313
+ ```
314
+
315
+ _See code: [src/commands/config/use.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2/src/commands/config/use.ts)_
74
316
 
75
317
  ## `sp help [COMMAND]`
76
318
 
@@ -81,7 +323,7 @@ USAGE
81
323
  $ sp help [COMMAND...] [-n]
82
324
 
83
325
  ARGUMENTS
84
- COMMAND... Command to show help for.
326
+ [COMMAND...] Command to show help for.
85
327
 
86
328
  FLAGS
87
329
  -n, --nested-commands Include all nested commands in the output.
@@ -113,7 +355,7 @@ EXAMPLES
113
355
  $ sp plugins
114
356
  ```
115
357
 
116
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.49/src/commands/plugins/index.ts)_
358
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/index.ts)_
117
359
 
118
360
  ## `sp plugins add PLUGIN`
119
361
 
@@ -187,7 +429,7 @@ EXAMPLES
187
429
  $ sp plugins inspect myplugin
188
430
  ```
189
431
 
190
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.49/src/commands/plugins/inspect.ts)_
432
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/inspect.ts)_
191
433
 
192
434
  ## `sp plugins install PLUGIN`
193
435
 
@@ -236,7 +478,7 @@ EXAMPLES
236
478
  $ sp plugins install someuser/someplugin
237
479
  ```
238
480
 
239
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.49/src/commands/plugins/install.ts)_
481
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/install.ts)_
240
482
 
241
483
  ## `sp plugins link PATH`
242
484
 
@@ -267,7 +509,7 @@ EXAMPLES
267
509
  $ sp plugins link myplugin
268
510
  ```
269
511
 
270
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.49/src/commands/plugins/link.ts)_
512
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/link.ts)_
271
513
 
272
514
  ## `sp plugins remove [PLUGIN]`
273
515
 
@@ -278,7 +520,7 @@ USAGE
278
520
  $ sp plugins remove [PLUGIN...] [-h] [-v]
279
521
 
280
522
  ARGUMENTS
281
- PLUGIN... plugin to uninstall
523
+ [PLUGIN...] plugin to uninstall
282
524
 
283
525
  FLAGS
284
526
  -h, --help Show CLI help.
@@ -308,7 +550,7 @@ FLAGS
308
550
  --reinstall Reinstall all plugins after uninstalling.
309
551
  ```
310
552
 
311
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.49/src/commands/plugins/reset.ts)_
553
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/reset.ts)_
312
554
 
313
555
  ## `sp plugins uninstall [PLUGIN]`
314
556
 
@@ -319,7 +561,7 @@ USAGE
319
561
  $ sp plugins uninstall [PLUGIN...] [-h] [-v]
320
562
 
321
563
  ARGUMENTS
322
- PLUGIN... plugin to uninstall
564
+ [PLUGIN...] plugin to uninstall
323
565
 
324
566
  FLAGS
325
567
  -h, --help Show CLI help.
@@ -336,7 +578,7 @@ EXAMPLES
336
578
  $ sp plugins uninstall myplugin
337
579
  ```
338
580
 
339
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.49/src/commands/plugins/uninstall.ts)_
581
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/uninstall.ts)_
340
582
 
341
583
  ## `sp plugins unlink [PLUGIN]`
342
584
 
@@ -347,7 +589,7 @@ USAGE
347
589
  $ sp plugins unlink [PLUGIN...] [-h] [-v]
348
590
 
349
591
  ARGUMENTS
350
- PLUGIN... plugin to uninstall
592
+ [PLUGIN...] plugin to uninstall
351
593
 
352
594
  FLAGS
353
595
  -h, --help Show CLI help.
@@ -380,52 +622,5 @@ DESCRIPTION
380
622
  Update installed plugins.
381
623
  ```
382
624
 
383
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.49/src/commands/plugins/update.ts)_
384
-
385
- ## `sp refresh`
386
-
387
- ```
388
- USAGE
389
- $ sp refresh
390
- ```
391
-
392
- _See code: [src/commands/refresh.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.1-alpha.42/src/commands/refresh.ts)_
393
-
394
- ## `sp update [CHANNEL]`
395
-
396
- update the sp CLI
397
-
398
- ```
399
- USAGE
400
- $ sp update [CHANNEL] [--force | | [-a | -v <value> | -i]] [-b ]
401
-
402
- FLAGS
403
- -a, --available See available versions.
404
- -b, --verbose Show more details about the available versions.
405
- -i, --interactive Interactively select version to install. This is ignored if a channel is provided.
406
- -v, --version=<value> Install a specific version.
407
- --force Force a re-download of the requested version.
408
-
409
- DESCRIPTION
410
- update the sp CLI
411
-
412
- EXAMPLES
413
- Update to the stable channel:
414
-
415
- $ sp update stable
416
-
417
- Update to a specific version:
418
-
419
- $ sp update --version 1.0.0
420
-
421
- Interactively select version:
422
-
423
- $ sp update --interactive
424
-
425
- See available versions:
426
-
427
- $ sp update --available
428
- ```
429
-
430
- _See code: [@oclif/plugin-update](https://github.com/oclif/plugin-update/blob/v4.7.11/src/commands/update.ts)_
625
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.50/src/commands/plugins/update.ts)_
431
626
  <!-- commandsstop -->
package/bin/dev.cmd CHANGED
@@ -1,3 +1,3 @@
1
1
  @echo off
2
2
 
3
- node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
3
+ node --import tsx "%~dp0\dev" %*
package/bin/dev.js CHANGED
@@ -1,5 +1,7 @@
1
- #!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning
2
-
1
+ #!/usr/bin/env -S node --import tsx
3
2
  import { execute } from '@oclif/core';
4
3
 
5
- await execute({ development: true, dir: import.meta.url });
4
+ await execute({
5
+ development: true,
6
+ dir: import.meta.url,
7
+ });
package/bin/run.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  import { execute } from '@oclif/core';
4
3
 
5
- await execute({ dir: import.meta.url });
4
+ await execute({
5
+ dir: import.meta.url,
6
+ });
@@ -1,5 +1,5 @@
1
- import { SpCommand } from '../../interfaces/index.js';
2
- export default class SpLogin extends SpCommand {
1
+ import { BaseCommand } from '../base.js';
2
+ export default class SpLogin extends BaseCommand<typeof SpLogin> {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  getTokens(nonce: string): Promise<void>;
@@ -12,5 +12,6 @@ export default class SpLogin extends SpCommand {
12
12
  nonce?: string;
13
13
  } | undefined;
14
14
  }>;
15
+ init(): Promise<void>;
15
16
  run(): Promise<void>;
16
17
  }
@@ -1,45 +1,66 @@
1
1
  import { ux } from '@oclif/core';
2
- import { SpCommand } from '../../interfaces/index.js';
3
- export default class SpLogin extends SpCommand {
2
+ import { BaseCommand } from '../base.js';
3
+ export default class SpLogin extends BaseCommand {
4
4
  static description = 'Authorization';
5
5
  static examples = [
6
6
  `<%= config.bin %> <%= command.id %>
7
7
  `,
8
8
  ];
9
9
  async getTokens(nonce) {
10
- const signature = await this.accountManager.createSign(nonce);
11
- const { data: tokenResponse, error, } = await this.providerClient.POST('/api/auth/token', {
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', {
12
13
  body: {
13
- address: this.accountManager.getAddress(),
14
+ address: accountManager.getAddress(),
14
15
  provider: 'sp-cli',
15
16
  signature,
16
17
  },
17
18
  });
18
19
  if (error) {
19
- ux.stderr(error.message);
20
- return;
20
+ this.logger.error({ err: error }, 'Token exchange failed');
21
+ ux.error('Authorization failed please try again later.');
21
22
  }
22
- const { accessToken } = tokenResponse;
23
- await this.authManager.setCredentials({ accessKey: accessToken });
24
- ux.stdout('Authorization successful');
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');
25
30
  }
26
31
  async getUserNonce(address) {
27
- const { data, error } = await this.providerClient.GET('/api/users/nonce/{address}', {
28
- params: {
29
- path: {
30
- address,
32
+ const { providerClient } = this.container;
33
+ try {
34
+ const { data, error } = await providerClient.GET('/api/users/nonce/{address}', {
35
+ params: {
36
+ path: {
37
+ address,
38
+ },
31
39
  },
32
- },
33
- });
34
- this.logger.debug({ data, error }, 'Getting user nonce');
35
- return { error, user: data };
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');
47
+ }
48
+ }
49
+ async init() {
50
+ await super.init();
51
+ await this.container
52
+ .initConfigManager()
53
+ .initAccountManager()
54
+ .initProviderClient({ enableAuth: false })
55
+ .build();
36
56
  }
37
57
  async run() {
38
- const address = this.accountManager.getAddress();
58
+ const { accountManager, providerClient } = this.container;
59
+ const address = accountManager.getAddress();
39
60
  const { error: nonceError, user } = await this.getUserNonce(address);
40
61
  if (nonceError && nonceError.statusCode === 404) {
41
62
  this.logger.debug('Nonce error call sign up');
42
- const { data: nonceResponse, error: signUpError } = await this.providerClient.POST('/api/auth/sign-up', {
63
+ const { data: nonceResponse, error: signUpError } = await providerClient.POST('/api/auth/sign-up', {
43
64
  body: {
44
65
  address,
45
66
  },
@@ -51,11 +72,18 @@ export default class SpLogin extends SpCommand {
51
72
  if (user && user.nonce)
52
73
  await this.getTokens(user.nonce);
53
74
  else
54
- throw new Error('Cannot complete login');
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.');
55
80
  }
56
81
  else {
57
- // TODO: fix this changeset on @super-protocol/provider-client side
58
- const { nonce } = nonceResponse;
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
+ }
59
87
  await this.getTokens(nonce);
60
88
  }
61
89
  }
@@ -64,7 +92,7 @@ export default class SpLogin extends SpCommand {
64
92
  await this.getTokens(user.nonce);
65
93
  }
66
94
  else {
67
- ux.error('Something went wrong');
95
+ ux.error('Unable to retrieve authentication nonce. Please try again later or contact support if the issue persists.');
68
96
  }
69
97
  }
70
98
  }
@@ -1,4 +1,5 @@
1
- import { SpCommand } from '../../interfaces/abstract.command.js';
2
- export default class Me extends SpCommand {
1
+ import { BaseCommand } from '../base.js';
2
+ export default class Me extends BaseCommand<typeof Me> {
3
+ init(): Promise<void>;
3
4
  run(): Promise<void>;
4
5
  }
@@ -1,11 +1,16 @@
1
- import { SpCommand } from '../../interfaces/abstract.command.js';
2
- export default class Me extends SpCommand {
1
+ import { BaseCommand } from '../base.js';
2
+ export default class Me extends BaseCommand {
3
+ async init() {
4
+ await super.init();
5
+ await this.container.initProviderClient().build();
6
+ }
3
7
  async run() {
4
- const { data, error } = await this.providerClient.GET('/api/auth/me');
8
+ const { providerClient } = this.container;
9
+ const { data, error } = await providerClient.GET('/api/auth/me');
5
10
  if (error) {
6
11
  this.error(error.message);
7
12
  }
8
- this.log('Requested me ');
13
+ this.log('Requested me');
9
14
  this.logJson(data);
10
15
  }
11
16
  }
@@ -0,0 +1,18 @@
1
+ import { Command, Config, Interfaces } from '@oclif/core';
2
+ import pino from 'pino';
3
+ import { AppContainer } from '../lib/container.js';
4
+ export type CommandFlags<T extends typeof Command> = Interfaces.InferredFlags<T['flags'] & typeof BaseCommand['baseFlags']>;
5
+ export type CommandArgs<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
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
+ };
11
+ static enableJsonFlag: boolean;
12
+ protected args: CommandArgs<T>;
13
+ protected container: AppContainer;
14
+ protected flags: CommandFlags<T>;
15
+ protected logger: pino.BaseLogger;
16
+ constructor(argv: string[], config: Config);
17
+ init(): Promise<void>;
18
+ }