@super-protocol/sp-cli 0.0.1-alpha.35 → 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.
- package/README.md +260 -65
- package/bin/dev.cmd +1 -1
- package/bin/dev.js +5 -3
- package/bin/run.js +3 -2
- package/dist/commands/auth/login.d.ts +3 -2
- package/dist/commands/auth/login.js +52 -24
- package/dist/commands/auth/me.d.ts +3 -2
- package/dist/commands/auth/me.js +9 -4
- package/dist/commands/base.d.ts +18 -0
- package/dist/commands/base.js +45 -0
- package/dist/commands/config/add.d.ts +13 -0
- package/dist/commands/config/add.js +84 -0
- package/dist/commands/config/base.d.ts +14 -0
- package/dist/commands/config/base.js +62 -0
- package/dist/commands/config/create.d.ts +11 -0
- package/dist/commands/config/create.js +51 -0
- package/dist/commands/config/delete.d.ts +10 -0
- package/dist/commands/config/delete.js +25 -0
- package/dist/commands/config/index.d.ts +6 -0
- package/dist/commands/config/index.js +22 -0
- package/dist/commands/config/list.d.ts +6 -0
- package/dist/commands/config/list.js +39 -0
- package/dist/commands/config/show.d.ts +6 -0
- package/dist/commands/config/show.js +10 -0
- package/dist/commands/config/use.d.ts +6 -0
- package/dist/commands/config/use.js +25 -0
- package/dist/config/config-file.schema.d.ts +6 -0
- package/dist/config/config-file.schema.js +5 -0
- package/dist/config/config.schema.d.ts +2 -0
- package/dist/config/config.schema.js +12 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +5 -0
- package/dist/hooks/init/init-container.d.ts +3 -0
- package/dist/hooks/init/init-container.js +6 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +23 -1
- package/dist/interfaces/index.d.ts +0 -1
- package/dist/interfaces/index.js +0 -1
- package/dist/interfaces/manager.interface.d.ts +1 -1
- package/dist/lib/container.d.ts +40 -0
- package/dist/lib/container.js +177 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.js +62 -0
- package/dist/managers/account-manager.d.ts +2 -2
- package/dist/managers/account-manager.js +18 -9
- package/dist/managers/config-file-manager.d.ts +50 -0
- package/dist/managers/config-file-manager.js +278 -0
- package/dist/managers/config-manager.d.ts +12 -6
- package/dist/managers/config-manager.js +38 -14
- package/dist/managers/index.d.ts +1 -2
- package/dist/managers/index.js +1 -2
- package/dist/middlewares/auth-middleware.d.ts +9 -0
- package/dist/middlewares/auth-middleware.js +87 -0
- package/dist/middlewares/cookies-middleware.d.ts +8 -0
- package/dist/middlewares/cookies-middleware.js +80 -0
- package/dist/utils/helper.d.ts +1 -0
- package/dist/utils/helper.js +1 -0
- package/oclif.manifest.json +545 -7
- package/package.json +32 -14
- package/dist/commands/refresh.d.ts +0 -4
- package/dist/commands/refresh.js +0 -7
- package/dist/config/constants.d.ts +0 -1
- package/dist/config/constants.js +0 -2
- package/dist/interfaces/abstract.command.d.ts +0 -16
- package/dist/interfaces/abstract.command.js +0 -59
- package/dist/managers/auth-manager.d.ts +0 -19
- package/dist/managers/auth-manager.js +0 -101
- package/dist/managers/cookies-manager.d.ts +0 -15
- package/dist/managers/cookies-manager.js +0 -92
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Command, Flags, } from '@oclif/core';
|
|
2
|
+
import { AppContainer } from '../lib/container.js';
|
|
3
|
+
import logger from '../logger.js';
|
|
4
|
+
export class BaseCommand extends Command {
|
|
5
|
+
static baseFlags = {
|
|
6
|
+
config: Flags.string({
|
|
7
|
+
helpGroup: 'GLOBAL',
|
|
8
|
+
required: false,
|
|
9
|
+
summary: 'Specify config file.',
|
|
10
|
+
}),
|
|
11
|
+
url: Flags.string({
|
|
12
|
+
helpGroup: 'GLOBAL',
|
|
13
|
+
required: false,
|
|
14
|
+
summary: 'Specify provider base URL.',
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
static enableJsonFlag = true;
|
|
18
|
+
args;
|
|
19
|
+
container;
|
|
20
|
+
flags;
|
|
21
|
+
logger;
|
|
22
|
+
constructor(argv, config) {
|
|
23
|
+
super(argv, config);
|
|
24
|
+
this.logger = logger.getPino();
|
|
25
|
+
}
|
|
26
|
+
async init() {
|
|
27
|
+
await super.init();
|
|
28
|
+
const { args, flags } = await this.parse({
|
|
29
|
+
args: this.ctor.args,
|
|
30
|
+
baseFlags: {
|
|
31
|
+
...BaseCommand.baseFlags,
|
|
32
|
+
...super.ctor.baseFlags,
|
|
33
|
+
},
|
|
34
|
+
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
35
|
+
flags: this.ctor.flags,
|
|
36
|
+
strict: this.ctor.strict,
|
|
37
|
+
});
|
|
38
|
+
this.flags = flags;
|
|
39
|
+
this.args = args;
|
|
40
|
+
this.container = AppContainer.container.setupRuntimeConfig({
|
|
41
|
+
configFile: flags.config,
|
|
42
|
+
url: flags.url,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseConfigCommand } from './base.js';
|
|
2
|
+
export default class ConfigAdd extends BaseConfigCommand<typeof ConfigAdd> {
|
|
3
|
+
static args: {
|
|
4
|
+
file: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { BaseConfigCommand } from './base.js';
|
|
5
|
+
export default class ConfigAdd extends BaseConfigCommand {
|
|
6
|
+
static args = {
|
|
7
|
+
file: Args.string({
|
|
8
|
+
description: 'Configuration file path to import',
|
|
9
|
+
required: false,
|
|
10
|
+
}),
|
|
11
|
+
};
|
|
12
|
+
static description = 'Import a configuration from a file';
|
|
13
|
+
static examples = [
|
|
14
|
+
'<%= config.bin %> <%= command.id %> ./my-config.json',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> ./my-config.json --name "Imported"',
|
|
16
|
+
`Configuration files must follow this schema:
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
"providerUrl": "https://api.dp.superprotocol.com",
|
|
20
|
+
"name": "Some name",
|
|
21
|
+
"account": {
|
|
22
|
+
"address": "0x111222333444555....",
|
|
23
|
+
"privateKey": "0x000011122233344555..."
|
|
24
|
+
}
|
|
25
|
+
}`,
|
|
26
|
+
];
|
|
27
|
+
static flags = {
|
|
28
|
+
name: Flags.string({
|
|
29
|
+
char: 'n',
|
|
30
|
+
description: 'Custom name for the imported configuration',
|
|
31
|
+
}),
|
|
32
|
+
yes: Flags.boolean({
|
|
33
|
+
char: 'y',
|
|
34
|
+
default: false,
|
|
35
|
+
description: 'Automatically switch to imported configuration',
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
async run() {
|
|
39
|
+
const { cwdDir } = this.container;
|
|
40
|
+
let filePath = this.args.file;
|
|
41
|
+
if (!filePath) {
|
|
42
|
+
filePath = await this.inputPrompt({
|
|
43
|
+
message: 'Enter path to configuration file:',
|
|
44
|
+
validate(value) {
|
|
45
|
+
if (!value)
|
|
46
|
+
return 'File path is required';
|
|
47
|
+
const testPath = path.isAbsolute(value) ? value : path.join(cwdDir, value);
|
|
48
|
+
if (!existsSync(testPath)) {
|
|
49
|
+
return 'File does not exist';
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
56
|
+
? filePath
|
|
57
|
+
: path.join(cwdDir, filePath);
|
|
58
|
+
if (!existsSync(absolutePath)) {
|
|
59
|
+
this.error('File does not exist');
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const importedFileName = await this.configFileManager.importConfig(absolutePath, this.flags.name);
|
|
63
|
+
const configs = this.configFileManager.getConfigsWithNames();
|
|
64
|
+
const importedConfig = configs.find(c => c.file === importedFileName);
|
|
65
|
+
const displayName = importedConfig?.name || importedFileName;
|
|
66
|
+
this.log(`Successfully imported configuration: ${displayName}`);
|
|
67
|
+
this.log(`Configuration file: ${importedFileName}`);
|
|
68
|
+
const shouldSwitch = this.flags.yes || await this.selectPrompt({
|
|
69
|
+
choices: [
|
|
70
|
+
{ name: 'Yes', value: true },
|
|
71
|
+
{ name: 'No', value: false },
|
|
72
|
+
],
|
|
73
|
+
message: 'Switch to this configuration now?',
|
|
74
|
+
});
|
|
75
|
+
if (shouldSwitch) {
|
|
76
|
+
await this.configFileManager.setCurrentConfig(importedFileName);
|
|
77
|
+
this.log(`Switched to configuration: ${displayName}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
this.error(`Failed to import configuration: ${error instanceof Error ? error.message : String(error)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Command } from '@oclif/core';
|
|
2
|
+
import { input, select } from '@inquirer/prompts';
|
|
3
|
+
import type { ConfigFileManager } from '../../managers/config-file-manager.js';
|
|
4
|
+
import { BaseCommand } from '../base.js';
|
|
5
|
+
type InputOptions = Parameters<typeof input>[0];
|
|
6
|
+
type SelectOptions<T> = Parameters<typeof select<T>>[0];
|
|
7
|
+
export declare abstract class BaseConfigCommand<T extends typeof Command> extends BaseCommand<T> {
|
|
8
|
+
protected configFileManager: ConfigFileManager;
|
|
9
|
+
protected displayCurrentConfig(): void;
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
protected inputPrompt(options: InputOptions): Promise<string>;
|
|
12
|
+
protected selectPrompt<Value>(options: SelectOptions<Value>): Promise<Value>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { input, select } from '@inquirer/prompts';
|
|
2
|
+
import { BaseCommand } from '../base.js';
|
|
3
|
+
export class BaseConfigCommand extends BaseCommand {
|
|
4
|
+
configFileManager;
|
|
5
|
+
displayCurrentConfig() {
|
|
6
|
+
const current = this.configFileManager.getCurrentConfigFile();
|
|
7
|
+
const configDir = this.configFileManager.getConfigDir();
|
|
8
|
+
if (current) {
|
|
9
|
+
const configs = this.configFileManager.getConfigsWithNames();
|
|
10
|
+
const currentConfig = configs.find(c => c.file === current);
|
|
11
|
+
const displayName = currentConfig?.name || current;
|
|
12
|
+
const configData = this.configFileManager.getConfigData(current);
|
|
13
|
+
this.log(`Current configuration: ${displayName}`);
|
|
14
|
+
this.log(`Configuration file: ${current}`);
|
|
15
|
+
this.log(`Configuration directory: ${configDir}`);
|
|
16
|
+
if (configData) {
|
|
17
|
+
this.log('');
|
|
18
|
+
this.log('Configuration details:');
|
|
19
|
+
if (configData.providerUrl) {
|
|
20
|
+
this.log(` Provider URL: ${configData.providerUrl}`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.log(' Provider URL: (using default)');
|
|
24
|
+
}
|
|
25
|
+
if (configData.auth?.accessKey) {
|
|
26
|
+
this.log(' Authorization: ✓ Configured');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.log(' Authorization: ✗ Not configured');
|
|
30
|
+
}
|
|
31
|
+
if (configData.account?.address) {
|
|
32
|
+
this.log(` Account: ✓ ${configData.account.address}`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.log(' Account: ✗ Not configured');
|
|
36
|
+
}
|
|
37
|
+
if (configData.cookies) {
|
|
38
|
+
this.log(' Cookies: ✓ Stored');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.log(' Cookies: ✗ None');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.log('No configuration is currently set');
|
|
47
|
+
this.log(`Configuration directory: ${configDir}`);
|
|
48
|
+
this.log('Create a new configuration with: sp config create --name "Config Name"');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async init() {
|
|
52
|
+
await super.init();
|
|
53
|
+
await this.container.initConfigFileManager().build();
|
|
54
|
+
this.configFileManager = this.container.configFileManager;
|
|
55
|
+
}
|
|
56
|
+
async inputPrompt(options) {
|
|
57
|
+
return input(options);
|
|
58
|
+
}
|
|
59
|
+
async selectPrompt(options) {
|
|
60
|
+
return select(options);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseConfigCommand } from './base.js';
|
|
2
|
+
export default class ConfigCreate extends BaseConfigCommand<typeof ConfigCreate> {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { getConfigName } from '../../utils/helper.js';
|
|
3
|
+
import { BaseConfigCommand } from './base.js';
|
|
4
|
+
export default class ConfigCreate extends BaseConfigCommand {
|
|
5
|
+
static description = 'Create a new configuration';
|
|
6
|
+
static examples = [
|
|
7
|
+
'<%= config.bin %> <%= command.id %> --name "My Config"',
|
|
8
|
+
'<%= config.bin %> <%= command.id %> --name "Production" --url "https://api.dp.superprotocol.com"',
|
|
9
|
+
];
|
|
10
|
+
static flags = {
|
|
11
|
+
name: Flags.string({
|
|
12
|
+
char: 'n',
|
|
13
|
+
description: 'Configuration name',
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
url: Flags.string({
|
|
17
|
+
char: 'u',
|
|
18
|
+
description: 'Provider base URL',
|
|
19
|
+
}),
|
|
20
|
+
yes: Flags.boolean({
|
|
21
|
+
char: 'y',
|
|
22
|
+
description: 'Switch to new config',
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
async run() {
|
|
26
|
+
const { name, url, yes } = this.flags;
|
|
27
|
+
const fileName = getConfigName(name);
|
|
28
|
+
try {
|
|
29
|
+
await this.configFileManager.createConfig(fileName, name, url);
|
|
30
|
+
this.log(`Created new configuration: ${name}`);
|
|
31
|
+
this.log(`Configuration file: ${fileName}`);
|
|
32
|
+
if (url) {
|
|
33
|
+
this.log(`Provider URL: ${url}`);
|
|
34
|
+
}
|
|
35
|
+
const shouldSwitch = yes || await this.selectPrompt({
|
|
36
|
+
choices: [
|
|
37
|
+
{ name: 'Yes', value: true },
|
|
38
|
+
{ name: 'No', value: false },
|
|
39
|
+
],
|
|
40
|
+
message: 'Switch to this configuration now?',
|
|
41
|
+
});
|
|
42
|
+
if (shouldSwitch) {
|
|
43
|
+
await this.configFileManager.setCurrentConfig(fileName);
|
|
44
|
+
this.log(`Switched to configuration: ${name}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
this.error(`Failed to create configuration: ${error instanceof Error ? error.message : String(error)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseConfigCommand } from './base.js';
|
|
2
|
+
export default class ConfigDelete extends BaseConfigCommand<typeof ConfigDelete> {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseConfigCommand } from './base.js';
|
|
3
|
+
export default class ConfigDelete extends BaseConfigCommand {
|
|
4
|
+
static description = 'Delete a configuration file';
|
|
5
|
+
static examples = [
|
|
6
|
+
'<%= config.bin %> <%= command.id %>',
|
|
7
|
+
'<%= config.bin %> <%= command.id %> --name "My Config"',
|
|
8
|
+
'<%= config.bin %> <%= command.id %> --name "My Config" --force',
|
|
9
|
+
];
|
|
10
|
+
static flags = {
|
|
11
|
+
force: Flags.boolean({
|
|
12
|
+
char: 'f',
|
|
13
|
+
default: false,
|
|
14
|
+
description: 'Force deletion without confirmation',
|
|
15
|
+
}),
|
|
16
|
+
name: Flags.string({
|
|
17
|
+
char: 'n',
|
|
18
|
+
description: 'Configuration name to delete',
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
async run() {
|
|
22
|
+
const { force, name } = this.flags;
|
|
23
|
+
await this.configFileManager.deleteConfigByName(name, force);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseConfigCommand } from './base.js';
|
|
2
|
+
export default class Config extends BaseConfigCommand {
|
|
3
|
+
static description = 'Manage configuration configs';
|
|
4
|
+
static examples = [
|
|
5
|
+
'<%= config.bin %> <%= command.id %> show - Show current configuration details',
|
|
6
|
+
'<%= config.bin %> <%= command.id %> list - List all configurations',
|
|
7
|
+
'<%= config.bin %> <%= command.id %> use - Switch to a configuration',
|
|
8
|
+
'<%= config.bin %> <%= command.id %> create --name "My Config" - Create new configuration',
|
|
9
|
+
'<%= config.bin %> <%= command.id %> add ./config.json - Import configuration from file',
|
|
10
|
+
'<%= config.bin %> <%= command.id %> delete - Delete a configuration',
|
|
11
|
+
];
|
|
12
|
+
async run() {
|
|
13
|
+
this.displayCurrentConfig();
|
|
14
|
+
this.log('\nAvailable commands:');
|
|
15
|
+
this.log(' sp config show - Show current configuration');
|
|
16
|
+
this.log(' sp config list - List all configurations');
|
|
17
|
+
this.log(' sp config use - Switch configuration');
|
|
18
|
+
this.log(' sp config create - Create new configuration');
|
|
19
|
+
this.log(' sp config add - Import configuration');
|
|
20
|
+
this.log(' sp config delete - Delete configuration');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseConfigCommand } from './base.js';
|
|
2
|
+
export default class ConfigList extends BaseConfigCommand {
|
|
3
|
+
static description = 'List all configurations';
|
|
4
|
+
static examples = [
|
|
5
|
+
'<%= config.bin %> <%= command.id %>',
|
|
6
|
+
];
|
|
7
|
+
async run() {
|
|
8
|
+
const configs = this.configFileManager.getConfigsWithNames();
|
|
9
|
+
const current = this.configFileManager.getCurrentConfigFile();
|
|
10
|
+
if (configs.length === 0) {
|
|
11
|
+
this.log('No configurations found');
|
|
12
|
+
this.log('Create a new configuration with: sp config create --name "Config Name"');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.log('Available configurations:\n');
|
|
16
|
+
for (const config of configs) {
|
|
17
|
+
const marker = config.file === current ? '* ' : ' ';
|
|
18
|
+
const configData = this.configFileManager.getConfigData(config.file);
|
|
19
|
+
let statusInfo = '';
|
|
20
|
+
if (configData) {
|
|
21
|
+
const parts = [];
|
|
22
|
+
if (configData.providerUrl) {
|
|
23
|
+
parts.push(`URL: ${configData.providerUrl}`);
|
|
24
|
+
}
|
|
25
|
+
if (configData.auth) {
|
|
26
|
+
parts.push('Auth: ✓');
|
|
27
|
+
}
|
|
28
|
+
if (configData.account) {
|
|
29
|
+
parts.push('Account: ✓');
|
|
30
|
+
}
|
|
31
|
+
if (parts.length > 0) {
|
|
32
|
+
statusInfo = ` | ${parts.join(', ')}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.log(`${marker}${config.name}${statusInfo}`);
|
|
36
|
+
this.log(` File: ${config.file}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseConfigCommand } from './base.js';
|
|
2
|
+
export default class ConfigShow extends BaseConfigCommand {
|
|
3
|
+
static description = 'Show current configuration';
|
|
4
|
+
static examples = [
|
|
5
|
+
'<%= config.bin %> <%= command.id %>',
|
|
6
|
+
];
|
|
7
|
+
async run() {
|
|
8
|
+
this.displayCurrentConfig();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseConfigCommand } from './base.js';
|
|
2
|
+
export default class ConfigUse extends BaseConfigCommand {
|
|
3
|
+
static description = 'Switch to a different configuration file';
|
|
4
|
+
static examples = [
|
|
5
|
+
'<%= config.bin %> <%= command.id %>',
|
|
6
|
+
];
|
|
7
|
+
async run() {
|
|
8
|
+
const configs = this.configFileManager.getConfigsWithNames();
|
|
9
|
+
if (configs.length === 0) {
|
|
10
|
+
this.log('No configurations found');
|
|
11
|
+
this.log('Create a new configuration with: sp config create --name "Config Name"');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const selected = await this.selectPrompt({
|
|
15
|
+
choices: configs.map(config => ({
|
|
16
|
+
name: config.name ?? config.file,
|
|
17
|
+
value: config.file,
|
|
18
|
+
})),
|
|
19
|
+
message: 'Select a configuration:',
|
|
20
|
+
});
|
|
21
|
+
await this.configFileManager.setCurrentConfig(selected);
|
|
22
|
+
const selectedConfig = configs.find(c => c.file === selected);
|
|
23
|
+
this.log(`Switched to configuration: ${selectedConfig?.name || selected}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Static } from '@sinclair/typebox';
|
|
2
|
+
export declare const configFileManagerSchema: import("@sinclair/typebox").TObject<{
|
|
3
|
+
configs: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
|
4
|
+
currentConfig: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
5
|
+
}>;
|
|
6
|
+
export type ConfigFileManagerData = Static<typeof configFileManagerSchema>;
|
|
@@ -15,6 +15,8 @@ export declare const cliConfigSchema: import("@sinclair/typebox").TObject<{
|
|
|
15
15
|
accessKey: import("@sinclair/typebox").TString;
|
|
16
16
|
}>>;
|
|
17
17
|
cookies: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnknown>;
|
|
18
|
+
name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
19
|
+
providerUrl: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
18
20
|
}>;
|
|
19
21
|
export type CliConfig = Static<typeof cliConfigSchema>;
|
|
20
22
|
export type Account = Static<typeof accountSchema>;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { Type } from '@sinclair/typebox';
|
|
1
|
+
import { FormatRegistry, Type } from '@sinclair/typebox';
|
|
2
|
+
FormatRegistry.Set('url', (value) => {
|
|
3
|
+
try {
|
|
4
|
+
const u = new URL(value);
|
|
5
|
+
return u.protocol === 'http:' || u.protocol === 'https:';
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
2
11
|
export const accountSchema = Type.Object({
|
|
3
12
|
address: Type.String({ pattern: '^0x[a-fA-F0-9]{40}$' }),
|
|
4
13
|
privateKey: Type.String({ pattern: '^0x[a-fA-F0-9]{64}$' }),
|
|
@@ -10,4 +19,6 @@ export const cliConfigSchema = Type.Object({
|
|
|
10
19
|
account: Type.Optional(accountSchema),
|
|
11
20
|
auth: Type.Optional(authSchema),
|
|
12
21
|
cookies: Type.Optional(Type.Unknown()),
|
|
22
|
+
name: Type.Optional(Type.String()),
|
|
23
|
+
providerUrl: Type.Optional(Type.String({ format: 'url' })),
|
|
13
24
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Interfaces, run as oclifRun } from '@oclif/core';
|
|
2
|
+
export declare const run: (argv: string[], loadOptions?: Interfaces.LoadOptions | URL) => ReturnType<typeof oclifRun>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
import { run as oclifRun } from '@oclif/core';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import logger from './logger.js';
|
|
4
|
+
const normalizeLoadOptions = (loadOptions) => {
|
|
5
|
+
if (!loadOptions) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (loadOptions instanceof URL) {
|
|
9
|
+
return fileURLToPath(loadOptions);
|
|
10
|
+
}
|
|
11
|
+
return loadOptions;
|
|
12
|
+
};
|
|
13
|
+
export const run = async (argv, loadOptions) => {
|
|
14
|
+
const resolved = normalizeLoadOptions(loadOptions);
|
|
15
|
+
if (typeof resolved === 'string') {
|
|
16
|
+
return oclifRun(argv, { logger, root: resolved });
|
|
17
|
+
}
|
|
18
|
+
if (!resolved) {
|
|
19
|
+
const defaultRoot = fileURLToPath(new URL('..', import.meta.url));
|
|
20
|
+
return oclifRun(argv, { logger, root: defaultRoot });
|
|
21
|
+
}
|
|
22
|
+
return oclifRun(argv, { ...resolved, logger });
|
|
23
|
+
};
|
package/dist/interfaces/index.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Config } from '@oclif/core';
|
|
2
|
+
import { ProviderClient } from '@super-protocol/provider-client';
|
|
3
|
+
import { AccountManager, ConfigFileManager, ConfigManager } from '../managers/index.js';
|
|
4
|
+
interface RuntimeConfig {
|
|
5
|
+
configFile?: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class AppContainer {
|
|
9
|
+
readonly cwdDir: string;
|
|
10
|
+
private readonly oclifConfig;
|
|
11
|
+
private static appContainer?;
|
|
12
|
+
private _accountManager?;
|
|
13
|
+
private _configFileManager?;
|
|
14
|
+
private _configManager?;
|
|
15
|
+
private _providerClient?;
|
|
16
|
+
private initPromises;
|
|
17
|
+
private readonly initQueue;
|
|
18
|
+
private logger;
|
|
19
|
+
private runtimeConfigFile?;
|
|
20
|
+
private runtimeProviderUrl?;
|
|
21
|
+
private constructor();
|
|
22
|
+
static initialize(currentDir: string, config: Config): AppContainer;
|
|
23
|
+
get accountManager(): AccountManager;
|
|
24
|
+
get configFileManager(): ConfigFileManager;
|
|
25
|
+
get configManager(): ConfigManager;
|
|
26
|
+
static get container(): AppContainer;
|
|
27
|
+
get providerClient(): ProviderClient;
|
|
28
|
+
build(): Promise<void>;
|
|
29
|
+
initAccountManager(): this;
|
|
30
|
+
initConfigFileManager(): this;
|
|
31
|
+
initConfigManager(): this;
|
|
32
|
+
initProviderClient({ enableAuth, enableCookies }?: {
|
|
33
|
+
enableAuth?: boolean;
|
|
34
|
+
enableCookies?: boolean;
|
|
35
|
+
}): this;
|
|
36
|
+
setupRuntimeConfig(config: RuntimeConfig): this;
|
|
37
|
+
private queueInit;
|
|
38
|
+
private waitFor;
|
|
39
|
+
}
|
|
40
|
+
export {};
|