@super-protocol/sp-cli 0.0.8 → 0.0.10-beta

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 (95) hide show
  1. package/README.md +200 -167
  2. package/dist/commands/account/base.d.ts +3 -4
  3. package/dist/commands/account/base.js +12 -9
  4. package/dist/commands/account/forget.d.ts +1 -1
  5. package/dist/commands/account/forget.js +66 -17
  6. package/dist/commands/account/get-sppi.js +7 -11
  7. package/dist/commands/account/info.d.ts +1 -13
  8. package/dist/commands/account/info.js +25 -45
  9. package/dist/commands/account/list.js +6 -6
  10. package/dist/commands/account/login.d.ts +10 -3
  11. package/dist/commands/account/login.js +143 -87
  12. package/dist/commands/account/switch.d.ts +3 -0
  13. package/dist/commands/account/switch.js +31 -11
  14. package/dist/commands/assets/base.d.ts +39 -0
  15. package/dist/commands/assets/base.js +217 -0
  16. package/dist/commands/assets/create.d.ts +41 -0
  17. package/dist/commands/assets/create.js +277 -0
  18. package/dist/commands/assets/delete.d.ts +14 -0
  19. package/dist/commands/assets/delete.js +69 -0
  20. package/dist/commands/assets/get.d.ts +14 -0
  21. package/dist/commands/assets/get.js +79 -0
  22. package/dist/commands/assets/list.d.ts +7 -0
  23. package/dist/commands/assets/list.js +33 -0
  24. package/dist/commands/assets/update.d.ts +44 -0
  25. package/dist/commands/assets/update.js +321 -0
  26. package/dist/commands/base.d.ts +1 -0
  27. package/dist/commands/base.js +6 -0
  28. package/dist/config/config.schema.d.ts +2 -11
  29. package/dist/config/config.schema.js +2 -7
  30. package/dist/constants.d.ts +3 -3
  31. package/dist/constants.js +3 -3
  32. package/dist/errors.d.ts +0 -2
  33. package/dist/errors.js +0 -2
  34. package/dist/hooks/prerun/auth.js +5 -9
  35. package/dist/interfaces/config-manager.interface.d.ts +3 -1
  36. package/dist/lib/container.d.ts +4 -12
  37. package/dist/lib/container.js +28 -113
  38. package/dist/lib/swarm-client/fetch-api.d.ts +7 -0
  39. package/dist/lib/swarm-client/fetch-api.js +41 -0
  40. package/dist/lib/swarm-client/fetch-timeout.client.d.ts +1 -0
  41. package/dist/lib/swarm-client/fetch-timeout.client.js +32 -0
  42. package/dist/lib/swarm-client/index.d.ts +6 -0
  43. package/dist/lib/swarm-client/index.js +31 -0
  44. package/dist/lib/swarm-client/middlewares/authorization.middleware.d.ts +2 -0
  45. package/dist/lib/swarm-client/middlewares/authorization.middleware.js +12 -0
  46. package/dist/lib/swarm-client/middlewares/index.d.ts +6 -0
  47. package/dist/lib/swarm-client/middlewares/index.js +5 -0
  48. package/dist/lib/swarm-client/middlewares/logger.middleware.d.ts +2 -0
  49. package/dist/lib/swarm-client/middlewares/logger.middleware.js +30 -0
  50. package/dist/lib/swarm-client/middlewares/request-id.middleware.d.ts +2 -0
  51. package/dist/lib/swarm-client/middlewares/request-id.middleware.js +13 -0
  52. package/dist/lib/swarm-client/types.d.ts +23 -0
  53. package/dist/lib/swarm-client/types.js +1 -0
  54. package/dist/managers/account-manager.d.ts +1 -0
  55. package/dist/managers/account-manager.js +13 -18
  56. package/dist/managers/config-file-manager.d.ts +24 -17
  57. package/dist/managers/config-file-manager.js +285 -161
  58. package/dist/managers/config-manager.d.ts +6 -6
  59. package/dist/managers/config-manager.js +8 -8
  60. package/dist/services/account.service.d.ts +42 -0
  61. package/dist/services/account.service.js +140 -0
  62. package/dist/services/asset.service.d.ts +35 -0
  63. package/dist/services/asset.service.js +120 -0
  64. package/dist/services/auth.service.d.ts +4 -6
  65. package/dist/services/auth.service.js +108 -118
  66. package/dist/utils/helper.js +2 -2
  67. package/dist/utils/progress.js +1 -0
  68. package/dist/utils/prompt.service.d.ts +8 -1
  69. package/dist/utils/prompt.service.js +33 -1
  70. package/oclif.manifest.json +479 -215
  71. package/package.json +7 -8
  72. package/dist/commands/files/download.d.ts +0 -15
  73. package/dist/commands/files/download.js +0 -63
  74. package/dist/commands/files/upload.d.ts +0 -18
  75. package/dist/commands/files/upload.js +0 -83
  76. package/dist/commands/storage/base.d.ts +0 -13
  77. package/dist/commands/storage/base.js +0 -125
  78. package/dist/commands/storage/create.d.ts +0 -11
  79. package/dist/commands/storage/create.js +0 -53
  80. package/dist/commands/storage/select.d.ts +0 -9
  81. package/dist/commands/storage/select.js +0 -38
  82. package/dist/commands/storage/show.d.ts +0 -17
  83. package/dist/commands/storage/show.js +0 -34
  84. package/dist/commands/storage/update.d.ts +0 -14
  85. package/dist/commands/storage/update.js +0 -204
  86. package/dist/commands/workflows/extend-lease.d.ts +0 -17
  87. package/dist/commands/workflows/extend-lease.js +0 -102
  88. package/dist/hooks/finally/shutdown-blockchain.d.ts +0 -3
  89. package/dist/hooks/finally/shutdown-blockchain.js +0 -8
  90. package/dist/middlewares/auth-middleware.d.ts +0 -9
  91. package/dist/middlewares/auth-middleware.js +0 -91
  92. package/dist/middlewares/cookies-middleware.d.ts +0 -8
  93. package/dist/middlewares/cookies-middleware.js +0 -80
  94. package/dist/services/storage.service.d.ts +0 -73
  95. package/dist/services/storage.service.js +0 -378
@@ -5,7 +5,7 @@ export default class AccountForget extends BaseAccountCommand<typeof AccountForg
5
5
  static examples: string[];
6
6
  static flags: {
7
7
  force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
- name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
8
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  };
10
10
  private configFileManager;
11
11
  init(): Promise<void>;
@@ -1,18 +1,7 @@
1
1
  import { Flags } from '@oclif/core';
2
2
  import { AppContainer } from '../../lib/container.js';
3
+ import { promptService } from '../../utils/prompt.service.js';
3
4
  import { BaseAccountCommand } from './base.js';
4
- const buildConfigNameFlag = (options = []) => options.length
5
- ? Flags.option({
6
- char: 'n',
7
- description: 'Configuration name to delete',
8
- options,
9
- required: true,
10
- })()
11
- : Flags.string({
12
- char: 'n',
13
- description: 'Configuration name to delete',
14
- required: true,
15
- });
16
5
  export default class AccountForget extends BaseAccountCommand {
17
6
  static authenticate = false;
18
7
  static description = 'Purge all account details';
@@ -25,9 +14,12 @@ export default class AccountForget extends BaseAccountCommand {
25
14
  force: Flags.boolean({
26
15
  char: 'f',
27
16
  default: false,
28
- description: 'Force deletion without confirmation',
17
+ description: 'Force forget without confirmation',
18
+ }),
19
+ name: Flags.string({
20
+ char: 'n',
21
+ description: 'Account name to forget',
29
22
  }),
30
- name: buildConfigNameFlag(),
31
23
  };
32
24
  configFileManager;
33
25
  async init() {
@@ -38,12 +30,69 @@ export default class AccountForget extends BaseAccountCommand {
38
30
  }
39
31
  async run() {
40
32
  const { force, name } = this.flags;
41
- await this.configFileManager.deleteConfigByName(name, force);
33
+ const configs = await this.configFileManager.getConfigsWithNames();
34
+ if (configs.length === 0) {
35
+ this.error('Not found any account', { exit: 1 });
36
+ }
37
+ let configToDelete;
38
+ let displayName;
39
+ if (name) {
40
+ const config = configs.find((item) => item.name === name || item.file === name);
41
+ if (!config) {
42
+ this.error(`Account with name: ${name} not found`);
43
+ }
44
+ configToDelete = config.file;
45
+ displayName = config.name || config.file;
46
+ }
47
+ else {
48
+ const selection = await promptService.select({
49
+ message: 'Select account to forget:',
50
+ options: configs.map((config) => ({
51
+ label: config.name || config.file,
52
+ value: config.file,
53
+ })),
54
+ });
55
+ const config = configs.find((item) => item.file === selection);
56
+ configToDelete = selection;
57
+ displayName = config?.name || selection;
58
+ }
59
+ if (!force) {
60
+ const confirmed = await promptService.confirm({
61
+ initialValue: false,
62
+ message: `Are you sure you want to forget "${displayName}"?`,
63
+ });
64
+ if (!confirmed) {
65
+ this.log('Cancelled. Use --force to skip confirmation.');
66
+ return;
67
+ }
68
+ }
69
+ try {
70
+ await this.configFileManager.deleteConfigByName(configToDelete);
71
+ this.log(`Successfully forgot account: ${displayName}`);
72
+ const newCurrent = this.configFileManager.getCurrentConfigFile();
73
+ if (newCurrent) {
74
+ const configsAfter = await this.configFileManager.getConfigsWithNames();
75
+ const newCurrentConfig = configsAfter.find((c) => c.file === newCurrent);
76
+ this.log(`Current account is now: ${newCurrentConfig?.name || newCurrent}`);
77
+ }
78
+ else {
79
+ this.log('No accounts remaining');
80
+ this.log('Create a new account with: sp account login --name "Account Name" or sp account login');
81
+ }
82
+ }
83
+ catch (error) {
84
+ const message = error instanceof Error ? error.message : String(error);
85
+ this.error(`Failed to forget account: ${message}`, { exit: 1 });
86
+ }
42
87
  }
43
88
  async updateNameFlagOptions() {
44
89
  const { configFileManager } = await AppContainer.container.initConfigFileManager().build();
45
- const configs = configFileManager.getConfigsWithNames();
90
+ const configs = await configFileManager.getConfigsWithNames();
46
91
  const options = configs.map((config) => config.name);
47
- this.constructor.flags.name = buildConfigNameFlag(options);
92
+ this.constructor.flags.name = Flags.option({
93
+ char: 'n',
94
+ description: 'Account name to forget',
95
+ options,
96
+ })();
48
97
  }
49
98
  }
@@ -1,18 +1,14 @@
1
- import { formatEther } from 'viem';
1
+ //import { formatEther } from 'viem';
2
2
  import { BaseAccountCommand } from './base.js';
3
3
  export default class AccountGetSppi extends BaseAccountCommand {
4
4
  static description = 'Get SPPI (Super Protocol incentive tokens) ';
5
5
  static examples = ['<%= config.bin %> <%= command.id %>'];
6
6
  async run() {
7
- await this.initAccountContext();
8
- const { providerClient } = this.container;
9
- const { data, error } = await providerClient.POST('/api/faucet/request-tokens');
10
- if (error) {
11
- this.error(`Getting SPPI failed. Reason: ${error.message}`);
12
- }
13
- const tokens = formatEther(BigInt(data.amount || '0'));
14
- this.log('Tokens replenished');
15
- this.log(`Current balance: ${tokens} SPPI`);
16
- return { tokens };
7
+ this.error('Not implemented yet');
8
+ // await this.initAccountContext();
9
+ // const tokens = formatEther(BigInt('0'));
10
+ // this.log('Tokens replenished');
11
+ // this.log(`Current balance: ${tokens} SPPI`);
12
+ // return { tokens };
17
13
  }
18
14
  }
@@ -6,20 +6,8 @@ export declare class InfoCommand extends BaseAccountCommand<typeof InfoCommand>
6
6
  };
7
7
  init(): Promise<void>;
8
8
  run(): Promise<{
9
- address: string;
9
+ address: string | undefined;
10
10
  balance: string;
11
- storage: {
12
- bucket: string;
13
- createdAt: string;
14
- id: string;
15
- isCentralized: boolean;
16
- prefix: string;
17
- s3Credentials?: import("@super-protocol/provider-client").components["schemas"]["S3CredentialsResponseDto"];
18
- storageType: import("@super-protocol/provider-client").components["schemas"]["StorageType"];
19
- storjCredentials?: import("@super-protocol/provider-client").components["schemas"]["StorJCredentialsResponseDto"];
20
- updatedAt: string;
21
- userId: string;
22
- };
23
11
  wallet: string;
24
12
  }>;
25
13
  }
@@ -1,7 +1,6 @@
1
1
  import { Flags } from '@oclif/core';
2
2
  import { formatEther } from 'viem';
3
- import { PROVIDER_URL } from '../../constants.js';
4
- import { StorageService } from '../../services/storage.service.js';
3
+ import { SWARM_URL } from '../../constants.js';
5
4
  import { BaseAccountCommand } from './base.js';
6
5
  export class InfoCommand extends BaseAccountCommand {
7
6
  static description = 'Information about current authorized user';
@@ -17,54 +16,36 @@ export class InfoCommand extends BaseAccountCommand {
17
16
  }
18
17
  async run() {
19
18
  const { flags } = await this.parse(InfoCommand);
20
- const { providerClient } = this.container;
21
- const storageService = new StorageService(providerClient, this.logger);
22
- const { data, error } = await providerClient.GET('/api/auth/me');
23
- if (error) {
24
- this.error(error.message);
19
+ const { accountManager, configFileManager } = this.container;
20
+ const current = configFileManager.getCurrentConfigFile();
21
+ let address;
22
+ try {
23
+ address = accountManager.getAddress();
25
24
  }
26
- if (!data) {
27
- this.error('Failed to retrieve account information');
28
- }
29
- const { data: wallet } = await providerClient.GET('/api/users/me/wallet');
30
- if (!wallet) {
31
- this.error('Failed to retrieve wallet information');
32
- }
33
- const storage = await storageService.getCurrentStorage();
34
- const balance = formatEther(BigInt(wallet?.teeBalance || '0'));
35
- this.log(`Login: ${data.address}`);
36
- this.log(`Super Wallet: ${data.internalAddress}`);
25
+ catch { }
26
+ const walletAddress = 'N/A';
27
+ const balance = formatEther(0n);
28
+ this.log(`Login: ${address || 'N/A'}`);
29
+ this.log(`Super Wallet: ${walletAddress}`);
37
30
  this.log(`Balance: ${balance} SPPI`);
38
- if (storage.isCentralized) {
39
- this.log('Storage: Super cloud');
40
- }
41
- else {
42
- this.log('Active storage:');
43
- this.log(` bucket: ${storage.bucket}`);
44
- if (storage.prefix) {
45
- this.log(` prefix: ${storage.prefix}`);
46
- }
47
- }
48
31
  if (flags.detail) {
49
- const { configFileManager } = this.container;
50
- const current = configFileManager.getCurrentConfigFile();
51
32
  const configDir = configFileManager.getConfigDir();
52
33
  this.log('\n-----------------(DETAILS)-----------------------');
53
34
  if (current) {
54
- const configs = configFileManager.getConfigsWithNames();
35
+ const configs = await configFileManager.getConfigsWithNames();
55
36
  const currentConfig = configs.find((c) => c.file === current);
56
37
  const displayName = currentConfig?.name || current;
57
- const configData = configFileManager.getConfigData(current);
58
- this.log(`Current configuration: ${displayName}`);
38
+ const configData = await configFileManager.getConfigData(current);
39
+ this.log(`Current account: ${displayName}`);
59
40
  this.log(`Configuration file: ${current}`);
60
41
  this.log(`Configuration directory: ${configDir}`);
61
42
  if (configData) {
62
- this.log('\nConfiguration details:');
63
- if (configData.providerUrl) {
64
- this.log(` Provider URL: ${configData.providerUrl}`);
43
+ this.log('\nAccount details:');
44
+ if (configData.swarmUrl) {
45
+ this.log(` Swarm URL: ${configData.swarmUrl}`);
65
46
  }
66
47
  else {
67
- this.log(` Provider URL: ${PROVIDER_URL} (using default)`);
48
+ this.log(` Swarm URL: ${SWARM_URL} (using default)`);
68
49
  }
69
50
  if (configData.auth?.accessKey) {
70
51
  this.log(' Authorization: Configured');
@@ -72,8 +53,8 @@ export class InfoCommand extends BaseAccountCommand {
72
53
  else {
73
54
  this.log(' Authorization: Unauthorized');
74
55
  }
75
- if (configData.account?.address) {
76
- this.log(` Account: ${configData.account.address}`);
56
+ if (address) {
57
+ this.log(` Account: ${address}`);
77
58
  }
78
59
  else {
79
60
  this.log(' Account: Not configured');
@@ -81,16 +62,15 @@ export class InfoCommand extends BaseAccountCommand {
81
62
  }
82
63
  }
83
64
  else {
84
- this.log('No configuration is currently set');
85
- this.log(`Configuration directory: ${configDir}`);
86
- this.log('Create a new configuration with: sp account login --privateKey "<PRIVATE_KEY>" --name "Account Name"');
65
+ this.log('No account is currently set');
66
+ this.log(`Account directory: ${configDir}`);
67
+ this.log('Create a new account with: sp account login --privateKey "<PRIVATE_KEY>" --name "Account Name"');
87
68
  }
88
69
  }
89
70
  return {
90
- address: data.address,
71
+ address,
91
72
  balance,
92
- storage,
93
- wallet: data.internalAddress,
73
+ wallet: walletAddress,
94
74
  };
95
75
  }
96
76
  }
@@ -1,5 +1,5 @@
1
1
  import { printTable } from 'console-table-printer';
2
- import { PROVIDER_URL } from '../../constants.js';
2
+ import { SWARM_URL } from '../../constants.js';
3
3
  import { BaseCommand } from '../base.js';
4
4
  export default class AccountListCommand extends BaseCommand {
5
5
  static authenticate = false;
@@ -13,23 +13,23 @@ export default class AccountListCommand extends BaseCommand {
13
13
  await this.container.initConfigManager().build();
14
14
  }
15
15
  async run() {
16
- const configs = this.configFileManager.getConfigsWithNames();
16
+ const configs = await this.configFileManager.getConfigsWithNames();
17
17
  const current = this.configFileManager.getCurrentConfigFile();
18
18
  if (configs.length === 0) {
19
19
  this.log('No Accounts found');
20
- this.log('Create a new account with: sp account login --privateKey "<PRIVATE_KEY>" --url "<PROVIDER_URL>" --name "Account Name"');
20
+ this.log('Create a new account with: sp account login --privateKey "<PRIVATE_KEY>" --url "<SWARM_URL>" --name "Account Name"');
21
21
  return;
22
22
  }
23
23
  const rows = [];
24
24
  for (const config of configs) {
25
25
  const marker = config.file === current ? '* ' : ' ';
26
- const configData = this.configFileManager.getConfigData(config.file);
26
+ const configData = await this.configFileManager.getConfigData(config.file);
27
27
  const row = {
28
28
  account: configData?.account?.address ?? '[not found in config file]',
29
29
  current: marker,
30
30
  file: config.file,
31
31
  name: config.name,
32
- url: configData?.providerUrl ?? PROVIDER_URL,
32
+ url: configData?.swarmUrl ?? SWARM_URL,
33
33
  };
34
34
  rows.push(row);
35
35
  }
@@ -38,7 +38,7 @@ export default class AccountListCommand extends BaseCommand {
38
38
  { name: 'current', title: 'Current' },
39
39
  { name: 'name', title: 'Config name' },
40
40
  { name: 'account', title: 'Account' },
41
- { name: 'url', title: 'Provider Url' },
41
+ { name: 'url', title: 'Swarm Url' },
42
42
  { name: 'file', title: 'Configuration File' },
43
43
  ],
44
44
  title: 'Available Accounts',
@@ -2,15 +2,18 @@ import { BaseAccountCommand } from './base.js';
2
2
  export default class AccountLoginCommand extends BaseAccountCommand<typeof AccountLoginCommand> {
3
3
  static aliases: string[];
4
4
  static authenticate: boolean;
5
+ static summary: string;
5
6
  static description: string;
6
7
  static examples: string[];
7
8
  static flags: {
8
9
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  privateKey: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ path: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
12
  url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ authUrl: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
14
  yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
15
  };
13
- private configFileManager;
16
+ private accountService;
14
17
  private shouldSkipLogin;
15
18
  private inputPrompt;
16
19
  private checkStorage;
@@ -25,10 +28,14 @@ export default class AccountLoginCommand extends BaseAccountCommand<typeof Accou
25
28
  private askName;
26
29
  private confirmPrompt;
27
30
  private createAccountFromKey;
28
- private createConfigIfMissing;
29
- private findConfigsByPrivateKey;
31
+ private updateConfigDisplayName;
32
+ private setCurrentAndAuth;
33
+ private applySelectionWithDisplayName;
34
+ private selectMatchedConfig;
30
35
  private getPrivateKeyOrGenerate;
31
36
  private resolveByName;
37
+ private loadConfigFromPath;
38
+ private resolveByPath;
32
39
  private resolveByPrivateKey;
33
40
  private resolveConfiguration;
34
41
  private static maskPrivateKey;