@super-protocol/sp-cli 0.0.2-beta.1 → 0.0.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -61
- package/dist/commands/account/info.d.ts +21 -0
- package/dist/commands/account/info.js +43 -0
- package/dist/commands/auth/login.d.ts +0 -10
- package/dist/commands/auth/login.js +13 -84
- package/dist/commands/base.d.ts +2 -4
- package/dist/commands/base.js +8 -10
- package/dist/commands/config/add.js +9 -5
- package/dist/commands/config/base.d.ts +4 -3
- package/dist/commands/config/base.js +12 -14
- package/dist/commands/config/create.js +4 -4
- package/dist/commands/config/list.js +2 -2
- package/dist/commands/config/use.js +5 -3
- package/dist/commands/storage/base.js +2 -2
- package/dist/commands/storage/create.js +35 -35
- package/dist/commands/storage/select.js +10 -8
- package/dist/commands/storage/update.js +53 -48
- package/dist/lib/container.d.ts +4 -6
- package/dist/lib/container.js +21 -21
- package/dist/managers/account-manager.js +12 -2
- package/dist/managers/config-file-manager.d.ts +1 -1
- package/dist/managers/config-file-manager.js +12 -7
- package/dist/services/auth.service.d.ts +24 -0
- package/dist/services/auth.service.js +93 -0
- package/dist/services/storage.service.d.ts +17 -4
- package/dist/services/storage.service.js +72 -6
- package/oclif.manifest.json +39 -200
- package/package.json +3 -2
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { Command } from '@oclif/core';
|
|
2
|
-
import {
|
|
2
|
+
import { select, text } from '@clack/prompts';
|
|
3
3
|
import type { ConfigFileManager } from '../../managers/config-file-manager.js';
|
|
4
4
|
import { BaseCommand } from '../base.js';
|
|
5
|
-
type
|
|
5
|
+
type TextOptions = Parameters<typeof text>[0];
|
|
6
6
|
type SelectOptions<T> = Parameters<typeof select<T>>[0];
|
|
7
7
|
export declare abstract class BaseConfigCommand<T extends typeof Command> extends BaseCommand<T> {
|
|
8
|
+
static baseFlags: {};
|
|
8
9
|
protected configFileManager: ConfigFileManager;
|
|
9
10
|
protected displayCurrentConfig(): void;
|
|
10
11
|
init(): Promise<void>;
|
|
11
|
-
protected inputPrompt(options:
|
|
12
|
+
protected inputPrompt(options: TextOptions): Promise<string>;
|
|
12
13
|
protected selectPrompt<Value>(options: SelectOptions<Value>): Promise<Value>;
|
|
13
14
|
}
|
|
14
15
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { select, text } from '@clack/prompts';
|
|
2
|
+
import { PROVIDER_URL } from '../../constants.js';
|
|
2
3
|
import { BaseCommand } from '../base.js';
|
|
3
4
|
export class BaseConfigCommand extends BaseCommand {
|
|
5
|
+
static baseFlags = {};
|
|
4
6
|
configFileManager;
|
|
5
7
|
displayCurrentConfig() {
|
|
6
8
|
const current = this.configFileManager.getCurrentConfigFile();
|
|
@@ -20,25 +22,19 @@ export class BaseConfigCommand extends BaseCommand {
|
|
|
20
22
|
this.log(` Provider URL: ${configData.providerUrl}`);
|
|
21
23
|
}
|
|
22
24
|
else {
|
|
23
|
-
this.log(
|
|
25
|
+
this.log(` Provider URL: ${PROVIDER_URL} (using default)`);
|
|
24
26
|
}
|
|
25
27
|
if (configData.auth?.accessKey) {
|
|
26
|
-
this.log(' Authorization:
|
|
28
|
+
this.log(' Authorization: [OK] Configured');
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
this.log(' Authorization:
|
|
31
|
+
this.log(' Authorization: [--] Not configured');
|
|
30
32
|
}
|
|
31
33
|
if (configData.account?.address) {
|
|
32
|
-
this.log(` Account:
|
|
34
|
+
this.log(` Account: [OK] ${configData.account.address}`);
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
|
-
this.log(' Account:
|
|
36
|
-
}
|
|
37
|
-
if (configData.cookies) {
|
|
38
|
-
this.log(' Cookies: ✓ Stored');
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.log(' Cookies: ✗ None');
|
|
37
|
+
this.log(' Account: [--] Not configured');
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
}
|
|
@@ -54,9 +50,11 @@ export class BaseConfigCommand extends BaseCommand {
|
|
|
54
50
|
this.configFileManager = this.container.configFileManager;
|
|
55
51
|
}
|
|
56
52
|
async inputPrompt(options) {
|
|
57
|
-
|
|
53
|
+
const result = await text(options);
|
|
54
|
+
return this.ensurePromptValue(result);
|
|
58
55
|
}
|
|
59
56
|
async selectPrompt(options) {
|
|
60
|
-
|
|
57
|
+
const result = await select(options);
|
|
58
|
+
return this.ensurePromptValue(result);
|
|
61
59
|
}
|
|
62
60
|
}
|
|
@@ -33,11 +33,11 @@ export default class ConfigCreate extends BaseConfigCommand {
|
|
|
33
33
|
this.log(`Provider URL: ${url}`);
|
|
34
34
|
}
|
|
35
35
|
const shouldSwitch = yes || await this.selectPrompt({
|
|
36
|
-
choices: [
|
|
37
|
-
{ name: 'Yes', value: true },
|
|
38
|
-
{ name: 'No', value: false },
|
|
39
|
-
],
|
|
40
36
|
message: 'Switch to this configuration now?',
|
|
37
|
+
options: [
|
|
38
|
+
{ label: 'Yes', value: true },
|
|
39
|
+
{ label: 'No', value: false },
|
|
40
|
+
],
|
|
41
41
|
});
|
|
42
42
|
if (shouldSwitch) {
|
|
43
43
|
await this.configFileManager.setCurrentConfig(fileName);
|
|
@@ -23,10 +23,10 @@ export default class ConfigList extends BaseConfigCommand {
|
|
|
23
23
|
parts.push(`URL: ${configData.providerUrl}`);
|
|
24
24
|
}
|
|
25
25
|
if (configData.auth) {
|
|
26
|
-
parts.push('Auth:
|
|
26
|
+
parts.push('Auth: [OK]');
|
|
27
27
|
}
|
|
28
28
|
if (configData.account) {
|
|
29
|
-
parts.push(
|
|
29
|
+
parts.push(`Account: [OK] ${configData.account.address} `);
|
|
30
30
|
}
|
|
31
31
|
if (parts.length > 0) {
|
|
32
32
|
statusInfo = ` | ${parts.join(', ')}`;
|
|
@@ -6,17 +6,19 @@ export default class ConfigUse extends BaseConfigCommand {
|
|
|
6
6
|
];
|
|
7
7
|
async run() {
|
|
8
8
|
const configs = this.configFileManager.getConfigsWithNames();
|
|
9
|
+
const currentConfig = this.configFileManager.getCurrentConfigFile();
|
|
9
10
|
if (configs.length === 0) {
|
|
10
11
|
this.log('No configurations found');
|
|
11
12
|
this.log('Create a new configuration with: sp config create --name "Config Name"');
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
const selected = await this.selectPrompt({
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
initialValue: currentConfig,
|
|
17
|
+
message: 'Select a configuration:',
|
|
18
|
+
options: configs.map(config => ({
|
|
19
|
+
label: config.name ?? config.file,
|
|
17
20
|
value: config.file,
|
|
18
21
|
})),
|
|
19
|
-
message: 'Select a configuration:',
|
|
20
22
|
});
|
|
21
23
|
await this.configFileManager.setCurrentConfig(selected);
|
|
22
24
|
const selectedConfig = configs.find(c => c.file === selected);
|
|
@@ -6,7 +6,7 @@ export class BaseStorageCommand extends BaseCommand {
|
|
|
6
6
|
async init() {
|
|
7
7
|
await super.init();
|
|
8
8
|
await this.container.initConfigManager().initProviderClient().build();
|
|
9
|
-
const {
|
|
10
|
-
this.storageService = new StorageService(
|
|
9
|
+
const { providerClient } = this.container;
|
|
10
|
+
this.storageService = new StorageService(providerClient, this.logger);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { password, select, text } from '@clack/prompts';
|
|
2
2
|
import { Flags } from '@oclif/core';
|
|
3
3
|
import { StorageType } from '@super-protocol/provider-client';
|
|
4
4
|
import fs from 'node:fs/promises';
|
|
@@ -53,36 +53,36 @@ export default class StorageCreate extends BaseStorageCommand {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
async promptS3Credentials() {
|
|
56
|
-
const region = await
|
|
56
|
+
const region = this.ensurePromptValue(await text({
|
|
57
57
|
message: 'AWS region',
|
|
58
58
|
validate(value) {
|
|
59
|
-
return value ?
|
|
59
|
+
return value ? undefined : 'Region is required';
|
|
60
60
|
},
|
|
61
|
-
}).
|
|
62
|
-
const readAccessKeyId = await
|
|
61
|
+
})).trim();
|
|
62
|
+
const readAccessKeyId = this.ensurePromptValue(await text({
|
|
63
63
|
message: 'Read access key ID',
|
|
64
64
|
validate(value) {
|
|
65
|
-
return value ?
|
|
65
|
+
return value ? undefined : 'Read access key ID is required';
|
|
66
66
|
},
|
|
67
|
-
}).
|
|
68
|
-
const readSecretAccessKey = await password({
|
|
67
|
+
})).trim();
|
|
68
|
+
const readSecretAccessKey = this.ensurePromptValue(await password({
|
|
69
69
|
message: 'Read secret access key',
|
|
70
70
|
validate(value) {
|
|
71
|
-
return value ?
|
|
71
|
+
return value ? undefined : 'Read secret access key is required';
|
|
72
72
|
},
|
|
73
|
-
}).
|
|
74
|
-
const writeAccessKeyId = await
|
|
73
|
+
})).trim();
|
|
74
|
+
const writeAccessKeyId = this.ensurePromptValue(await text({
|
|
75
75
|
message: 'Write access key ID',
|
|
76
76
|
validate(value) {
|
|
77
|
-
return value ?
|
|
77
|
+
return value ? undefined : 'Write access key ID is required';
|
|
78
78
|
},
|
|
79
|
-
}).
|
|
80
|
-
const writeSecretAccessKey = await password({
|
|
79
|
+
})).trim();
|
|
80
|
+
const writeSecretAccessKey = this.ensurePromptValue(await password({
|
|
81
81
|
message: 'Write secret access key',
|
|
82
82
|
validate(value) {
|
|
83
|
-
return value ?
|
|
83
|
+
return value ? undefined : 'Write secret access key is required';
|
|
84
84
|
},
|
|
85
|
-
}).
|
|
85
|
+
})).trim();
|
|
86
86
|
return {
|
|
87
87
|
readAccessKeyId,
|
|
88
88
|
readSecretAccessKey,
|
|
@@ -92,26 +92,26 @@ export default class StorageCreate extends BaseStorageCommand {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
async promptStoragePayload() {
|
|
95
|
-
const storageType = await select({
|
|
96
|
-
choices: [
|
|
97
|
-
{ name: 'Amazon S3', value: StorageType.S3 },
|
|
98
|
-
{ name: 'StorJ', value: StorageType.StorJ },
|
|
99
|
-
],
|
|
95
|
+
const storageType = this.ensurePromptValue(await select({
|
|
100
96
|
message: 'Select storage type',
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
options: [
|
|
98
|
+
{ label: 'Amazon S3', value: StorageType.S3 },
|
|
99
|
+
{ label: 'StorJ', value: StorageType.StorJ },
|
|
100
|
+
],
|
|
101
|
+
}));
|
|
102
|
+
const bucket = this.ensurePromptValue(await text({
|
|
103
103
|
message: 'Bucket name',
|
|
104
104
|
validate(value) {
|
|
105
|
-
return value ?
|
|
105
|
+
return value ? undefined : 'Bucket is required';
|
|
106
106
|
},
|
|
107
|
-
}).
|
|
108
|
-
const prefix = await
|
|
109
|
-
|
|
107
|
+
})).trim();
|
|
108
|
+
const prefix = this.ensurePromptValue(await text({
|
|
109
|
+
defaultValue: '/',
|
|
110
110
|
message: 'Prefix',
|
|
111
111
|
validate(value) {
|
|
112
|
-
return value ?
|
|
112
|
+
return value ? undefined : 'Prefix is required';
|
|
113
113
|
},
|
|
114
|
-
}).
|
|
114
|
+
})).trim();
|
|
115
115
|
const storage = {
|
|
116
116
|
bucket,
|
|
117
117
|
prefix,
|
|
@@ -126,18 +126,18 @@ export default class StorageCreate extends BaseStorageCommand {
|
|
|
126
126
|
return storage;
|
|
127
127
|
}
|
|
128
128
|
async promptStorJCredentials() {
|
|
129
|
-
const readAccessToken = await password({
|
|
129
|
+
const readAccessToken = this.ensurePromptValue(await password({
|
|
130
130
|
message: 'Read access token',
|
|
131
131
|
validate(value) {
|
|
132
|
-
return value ?
|
|
132
|
+
return value ? undefined : 'Read access token is required';
|
|
133
133
|
},
|
|
134
|
-
}).
|
|
135
|
-
const writeAccessToken = await password({
|
|
134
|
+
})).trim();
|
|
135
|
+
const writeAccessToken = this.ensurePromptValue(await password({
|
|
136
136
|
message: 'Write access token',
|
|
137
137
|
validate(value) {
|
|
138
|
-
return value ?
|
|
138
|
+
return value ? undefined : 'Write access token is required';
|
|
139
139
|
},
|
|
140
|
-
}).
|
|
140
|
+
})).trim();
|
|
141
141
|
return {
|
|
142
142
|
readAccessToken,
|
|
143
143
|
writeAccessToken,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { select } from '@
|
|
1
|
+
import { select } from '@clack/prompts';
|
|
2
2
|
import { Flags } from '@oclif/core';
|
|
3
3
|
import { StoragesEmptyError } from '../../services/storage.service.js';
|
|
4
4
|
import { BaseStorageCommand } from './base.js';
|
|
@@ -19,14 +19,14 @@ export default class StorageSelect extends BaseStorageCommand {
|
|
|
19
19
|
try {
|
|
20
20
|
let storageId = flags.id;
|
|
21
21
|
if (!storageId) {
|
|
22
|
-
const storages = await this.storageService.
|
|
23
|
-
storageId = await select({
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const storages = await this.storageService.requestStorages();
|
|
23
|
+
storageId = this.ensurePromptValue(await select({
|
|
24
|
+
message: 'Select storage',
|
|
25
|
+
options: storages.map(storage => ({
|
|
26
|
+
label: `${storage.id} (${storage.storageType}) ${storage.bucket}/${storage.prefix} `,
|
|
26
27
|
value: storage.id,
|
|
27
28
|
})),
|
|
28
|
-
|
|
29
|
-
});
|
|
29
|
+
}));
|
|
30
30
|
}
|
|
31
31
|
if (!storageId) {
|
|
32
32
|
this.error('Storage ID is required');
|
|
@@ -38,7 +38,9 @@ export default class StorageSelect extends BaseStorageCommand {
|
|
|
38
38
|
if (error instanceof StoragesEmptyError) {
|
|
39
39
|
this.error('No storages available. Run "sp storage create" first.');
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
else {
|
|
42
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { confirm,
|
|
1
|
+
import { confirm, password, select, text, } from '@clack/prompts';
|
|
2
2
|
import { Flags } from '@oclif/core';
|
|
3
3
|
import { StorageType } from '@super-protocol/provider-client';
|
|
4
4
|
import fs from 'node:fs/promises';
|
|
@@ -25,25 +25,28 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
25
25
|
const { flags } = await this.parse(StorageUpdate);
|
|
26
26
|
try {
|
|
27
27
|
const shouldRequestStorages = !flags.fromFile || !flags.id;
|
|
28
|
-
const storages = shouldRequestStorages ? await this.storageService.
|
|
28
|
+
const storages = shouldRequestStorages ? await this.storageService.requestStorages() : undefined;
|
|
29
29
|
let storageId = flags.id;
|
|
30
30
|
if (!storageId) {
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const options = (storages || []).filter(cp => !cp.isCentralized).map(storage => ({
|
|
32
|
+
label: `${storage.id} (${storage.storageType}) ${storage.bucket}/${storage.prefix} `,
|
|
33
33
|
value: storage.id,
|
|
34
34
|
}));
|
|
35
|
-
if (!
|
|
35
|
+
if (!options || options.length === 0) {
|
|
36
36
|
throw new StoragesEmptyError('No storages available to update');
|
|
37
37
|
}
|
|
38
|
-
storageId = await select({
|
|
39
|
-
choices,
|
|
38
|
+
storageId = this.ensurePromptValue(await select({
|
|
40
39
|
message: 'Select storage to update',
|
|
41
|
-
|
|
40
|
+
options,
|
|
41
|
+
}));
|
|
42
42
|
}
|
|
43
43
|
if (!storageId) {
|
|
44
44
|
this.error('Storage ID is required');
|
|
45
45
|
}
|
|
46
46
|
const storageToUpdate = storages?.find(storage => storage.id === storageId);
|
|
47
|
+
if (flags.id && storages && !storageToUpdate) {
|
|
48
|
+
this.error(`Storage with ID ${storageId} not found`);
|
|
49
|
+
}
|
|
47
50
|
const updatePayload = flags.fromFile
|
|
48
51
|
? await this.loadStorageFromFile(flags.fromFile)
|
|
49
52
|
: await this.promptStorageUpdate(storageToUpdate);
|
|
@@ -54,7 +57,9 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
54
57
|
if (error instanceof StoragesEmptyError) {
|
|
55
58
|
this.error('No storages available. Run "sp storage create" first.');
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
else {
|
|
61
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
ensureNonEmptyString(value, fieldName) {
|
|
@@ -126,36 +131,36 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
133
|
async promptS3Credentials() {
|
|
129
|
-
const region = await
|
|
134
|
+
const region = this.ensurePromptValue(await text({
|
|
130
135
|
message: 'AWS region',
|
|
131
136
|
validate(value) {
|
|
132
|
-
return value ?
|
|
137
|
+
return value ? undefined : 'Region is required';
|
|
133
138
|
},
|
|
134
|
-
}).
|
|
135
|
-
const readAccessKeyId = await
|
|
139
|
+
})).trim();
|
|
140
|
+
const readAccessKeyId = this.ensurePromptValue(await text({
|
|
136
141
|
message: 'Read access key ID',
|
|
137
142
|
validate(value) {
|
|
138
|
-
return value ?
|
|
143
|
+
return value ? undefined : 'Read access key ID is required';
|
|
139
144
|
},
|
|
140
|
-
}).
|
|
141
|
-
const readSecretAccessKey = await password({
|
|
145
|
+
})).trim();
|
|
146
|
+
const readSecretAccessKey = this.ensurePromptValue(await password({
|
|
142
147
|
message: 'Read secret access key',
|
|
143
148
|
validate(value) {
|
|
144
|
-
return value ?
|
|
149
|
+
return value ? undefined : 'Read secret access key is required';
|
|
145
150
|
},
|
|
146
|
-
}).
|
|
147
|
-
const writeAccessKeyId = await
|
|
151
|
+
})).trim();
|
|
152
|
+
const writeAccessKeyId = this.ensurePromptValue(await text({
|
|
148
153
|
message: 'Write access key ID',
|
|
149
154
|
validate(value) {
|
|
150
|
-
return value ?
|
|
155
|
+
return value ? undefined : 'Write access key ID is required';
|
|
151
156
|
},
|
|
152
|
-
}).
|
|
153
|
-
const writeSecretAccessKey = await password({
|
|
157
|
+
})).trim();
|
|
158
|
+
const writeSecretAccessKey = this.ensurePromptValue(await password({
|
|
154
159
|
message: 'Write secret access key',
|
|
155
160
|
validate(value) {
|
|
156
|
-
return value ?
|
|
161
|
+
return value ? undefined : 'Write secret access key is required';
|
|
157
162
|
},
|
|
158
|
-
}).
|
|
163
|
+
})).trim();
|
|
159
164
|
return {
|
|
160
165
|
readAccessKeyId,
|
|
161
166
|
readSecretAccessKey,
|
|
@@ -166,44 +171,44 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
166
171
|
}
|
|
167
172
|
async promptStorageUpdate(existingStorage) {
|
|
168
173
|
const payload = {};
|
|
169
|
-
const bucket = await
|
|
170
|
-
|
|
174
|
+
const bucket = this.ensurePromptValue(await text({
|
|
175
|
+
defaultValue: existingStorage?.bucket ?? '',
|
|
171
176
|
message: 'Bucket name (leave empty to keep current)',
|
|
172
|
-
}).
|
|
177
|
+
})).trim();
|
|
173
178
|
if (bucket) {
|
|
174
179
|
payload.bucket = bucket;
|
|
175
180
|
}
|
|
176
|
-
const prefix = await
|
|
177
|
-
|
|
181
|
+
const prefix = this.ensurePromptValue(await text({
|
|
182
|
+
defaultValue: existingStorage?.prefix ?? '',
|
|
178
183
|
message: 'Prefix (leave empty to keep current)',
|
|
179
|
-
}).
|
|
184
|
+
})).trim();
|
|
180
185
|
if (prefix) {
|
|
181
186
|
payload.prefix = prefix;
|
|
182
187
|
}
|
|
183
188
|
let newStorageType;
|
|
184
|
-
const shouldChangeType = await confirm({
|
|
185
|
-
|
|
189
|
+
const shouldChangeType = this.ensurePromptValue(await confirm({
|
|
190
|
+
initialValue: false,
|
|
186
191
|
message: existingStorage
|
|
187
192
|
? `Change storage type? (current: ${existingStorage.storageType})`
|
|
188
193
|
: 'Change storage type?',
|
|
189
|
-
});
|
|
194
|
+
}));
|
|
190
195
|
if (shouldChangeType) {
|
|
191
|
-
newStorageType = await select({
|
|
192
|
-
choices: [
|
|
193
|
-
{ name: 'Amazon S3', value: StorageType.S3 },
|
|
194
|
-
{ name: 'StorJ', value: StorageType.StorJ },
|
|
195
|
-
],
|
|
196
|
+
newStorageType = this.ensurePromptValue(await select({
|
|
196
197
|
message: 'Select new storage type',
|
|
197
|
-
|
|
198
|
+
options: [
|
|
199
|
+
{ label: 'Amazon S3', value: StorageType.S3 },
|
|
200
|
+
{ label: 'StorJ', value: StorageType.StorJ },
|
|
201
|
+
],
|
|
202
|
+
}));
|
|
198
203
|
payload.storageType = newStorageType;
|
|
199
204
|
}
|
|
200
205
|
const effectiveType = newStorageType ?? existingStorage?.storageType;
|
|
201
206
|
const credentialsRequired = Boolean(newStorageType);
|
|
202
207
|
if (effectiveType) {
|
|
203
|
-
const updateCredentials = credentialsRequired || await confirm({
|
|
204
|
-
|
|
208
|
+
const updateCredentials = credentialsRequired || this.ensurePromptValue(await confirm({
|
|
209
|
+
initialValue: false,
|
|
205
210
|
message: `Update ${effectiveType} credentials?`,
|
|
206
|
-
});
|
|
211
|
+
}));
|
|
207
212
|
if (updateCredentials) {
|
|
208
213
|
if (effectiveType === StorageType.S3) {
|
|
209
214
|
payload.s3Credentials = await this.promptS3Credentials();
|
|
@@ -219,18 +224,18 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
219
224
|
return this.ensureUpdatePayload(payload);
|
|
220
225
|
}
|
|
221
226
|
async promptStorJCredentials() {
|
|
222
|
-
const readAccessToken = await password({
|
|
227
|
+
const readAccessToken = this.ensurePromptValue(await password({
|
|
223
228
|
message: 'Read access token',
|
|
224
229
|
validate(value) {
|
|
225
|
-
return value ?
|
|
230
|
+
return value ? undefined : 'Read access token is required';
|
|
226
231
|
},
|
|
227
|
-
}).
|
|
228
|
-
const writeAccessToken = await password({
|
|
232
|
+
})).trim();
|
|
233
|
+
const writeAccessToken = this.ensurePromptValue(await password({
|
|
229
234
|
message: 'Write access token',
|
|
230
235
|
validate(value) {
|
|
231
|
-
return value ?
|
|
236
|
+
return value ? undefined : 'Write access token is required';
|
|
232
237
|
},
|
|
233
|
-
}).
|
|
238
|
+
})).trim();
|
|
234
239
|
return {
|
|
235
240
|
readAccessToken,
|
|
236
241
|
writeAccessToken,
|
package/dist/lib/container.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { ProviderClient } from '@super-protocol/provider-client';
|
|
|
3
3
|
import { AccountManager, ConfigFileManager, ConfigManager } from '../managers/index.js';
|
|
4
4
|
interface RuntimeConfig {
|
|
5
5
|
configFile?: string;
|
|
6
|
-
url?: string;
|
|
7
6
|
}
|
|
8
7
|
export declare class AppContainer {
|
|
9
8
|
readonly cwdDir: string;
|
|
@@ -17,7 +16,6 @@ export declare class AppContainer {
|
|
|
17
16
|
private readonly initQueue;
|
|
18
17
|
private logger;
|
|
19
18
|
private runtimeConfigFile?;
|
|
20
|
-
private runtimeProviderUrl?;
|
|
21
19
|
private constructor();
|
|
22
20
|
static initialize(currentDir: string, config: Config): AppContainer;
|
|
23
21
|
get accountManager(): AccountManager;
|
|
@@ -25,10 +23,10 @@ export declare class AppContainer {
|
|
|
25
23
|
get configManager(): ConfigManager;
|
|
26
24
|
static get container(): AppContainer;
|
|
27
25
|
get providerClient(): ProviderClient;
|
|
28
|
-
build(): Promise<
|
|
29
|
-
initAccountManager(): this;
|
|
30
|
-
initConfigFileManager(): this;
|
|
31
|
-
initConfigManager(): this;
|
|
26
|
+
build(): Promise<this>;
|
|
27
|
+
initAccountManager(rebuild?: boolean): this;
|
|
28
|
+
initConfigFileManager(rebuild?: boolean): this;
|
|
29
|
+
initConfigManager(rebuild?: boolean): this;
|
|
32
30
|
initProviderClient({ enableAuth, enableCookies, rebuild }?: {
|
|
33
31
|
enableAuth?: boolean;
|
|
34
32
|
enableCookies?: boolean;
|
package/dist/lib/container.js
CHANGED
|
@@ -17,7 +17,6 @@ export class AppContainer {
|
|
|
17
17
|
initQueue = new Map();
|
|
18
18
|
logger;
|
|
19
19
|
runtimeConfigFile;
|
|
20
|
-
runtimeProviderUrl;
|
|
21
20
|
constructor(cwdDir, oclifConfig) {
|
|
22
21
|
this.cwdDir = cwdDir;
|
|
23
22
|
this.oclifConfig = oclifConfig;
|
|
@@ -61,9 +60,10 @@ export class AppContainer {
|
|
|
61
60
|
}
|
|
62
61
|
async build() {
|
|
63
62
|
await Promise.all(this.initPromises);
|
|
63
|
+
return this;
|
|
64
64
|
}
|
|
65
|
-
initAccountManager() {
|
|
66
|
-
this.initConfigManager();
|
|
65
|
+
initAccountManager(rebuild = true) {
|
|
66
|
+
this.initConfigManager(rebuild);
|
|
67
67
|
return this.queueInit('accountManager', async () => {
|
|
68
68
|
await this.waitFor('configManager');
|
|
69
69
|
if (this._accountManager) {
|
|
@@ -73,9 +73,9 @@ export class AppContainer {
|
|
|
73
73
|
const accountManager = new AccountManager(this.configManager, this.logger);
|
|
74
74
|
await accountManager.init();
|
|
75
75
|
this._accountManager = accountManager;
|
|
76
|
-
});
|
|
76
|
+
}, rebuild);
|
|
77
77
|
}
|
|
78
|
-
initConfigFileManager() {
|
|
78
|
+
initConfigFileManager(rebuild = false) {
|
|
79
79
|
return this.queueInit('configFileManager', async () => {
|
|
80
80
|
if (this._configFileManager) {
|
|
81
81
|
return;
|
|
@@ -85,10 +85,10 @@ export class AppContainer {
|
|
|
85
85
|
});
|
|
86
86
|
await configFileManager.init();
|
|
87
87
|
this._configFileManager = configFileManager;
|
|
88
|
-
});
|
|
88
|
+
}, rebuild);
|
|
89
89
|
}
|
|
90
|
-
initConfigManager() {
|
|
91
|
-
this.initConfigFileManager();
|
|
90
|
+
initConfigManager(rebuild = false) {
|
|
91
|
+
this.initConfigFileManager(rebuild);
|
|
92
92
|
return this.queueInit('configManager', async () => {
|
|
93
93
|
await this.waitFor('configFileManager');
|
|
94
94
|
if (this._configManager) {
|
|
@@ -102,7 +102,7 @@ export class AppContainer {
|
|
|
102
102
|
const configManager = new ConfigManager(configFilePath, this.logger);
|
|
103
103
|
await configManager.init();
|
|
104
104
|
this._configManager = configManager;
|
|
105
|
-
});
|
|
105
|
+
}, rebuild);
|
|
106
106
|
}
|
|
107
107
|
initProviderClient({ enableAuth = true, enableCookies = true, rebuild = false } = {}) {
|
|
108
108
|
this.initConfigManager();
|
|
@@ -111,13 +111,23 @@ export class AppContainer {
|
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
113
|
await this.waitFor('configManager');
|
|
114
|
-
const providerUrl =
|
|
114
|
+
const providerUrl = await this.configManager.get('providerUrl') || PROVIDER_URL;
|
|
115
115
|
this.logger.info('Initializing provider client');
|
|
116
116
|
const providerClient = createProviderClient({
|
|
117
117
|
baseUrl: providerUrl,
|
|
118
118
|
logger: this.logger,
|
|
119
119
|
middlewares: [requestIdMiddleware, loggerMiddleware],
|
|
120
120
|
});
|
|
121
|
+
if (enableCookies) {
|
|
122
|
+
this.logger.info('Initializing cookie middleware');
|
|
123
|
+
const cookiesMiddleware = await createCookieMiddleware(this.configManager, this.logger, providerUrl);
|
|
124
|
+
providerClient.use(cookiesMiddleware);
|
|
125
|
+
}
|
|
126
|
+
if (enableAuth) {
|
|
127
|
+
this.logger.info('Initializing auth middleware');
|
|
128
|
+
const authMiddleware = await createAuthMiddleware(this.configManager, providerClient, this.logger);
|
|
129
|
+
providerClient.use(authMiddleware);
|
|
130
|
+
}
|
|
121
131
|
providerClient.use({
|
|
122
132
|
onRequest: async ({ request }) => {
|
|
123
133
|
const req = request.clone();
|
|
@@ -128,20 +138,11 @@ export class AppContainer {
|
|
|
128
138
|
}
|
|
129
139
|
this.logger.debug({
|
|
130
140
|
body,
|
|
141
|
+
token: req.headers.get('Authorization'),
|
|
131
142
|
url: req.url,
|
|
132
143
|
}, 'Requesting');
|
|
133
144
|
},
|
|
134
145
|
});
|
|
135
|
-
if (enableCookies) {
|
|
136
|
-
this.logger.info('Initializing cookie middleware');
|
|
137
|
-
const cookiesMiddleware = await createCookieMiddleware(this.configManager, this.logger, providerUrl);
|
|
138
|
-
providerClient.use(cookiesMiddleware);
|
|
139
|
-
}
|
|
140
|
-
if (enableAuth) {
|
|
141
|
-
this.logger.info('Initializing auth middleware');
|
|
142
|
-
const authMiddleware = await createAuthMiddleware(this.configManager, providerClient, this.logger);
|
|
143
|
-
providerClient.use(authMiddleware);
|
|
144
|
-
}
|
|
145
146
|
this._providerClient = providerClient;
|
|
146
147
|
}, rebuild);
|
|
147
148
|
}
|
|
@@ -149,7 +150,6 @@ export class AppContainer {
|
|
|
149
150
|
if (this.initQueue.size > 0) {
|
|
150
151
|
throw new Error('Cannot change runtime config after initialization has started');
|
|
151
152
|
}
|
|
152
|
-
this.runtimeProviderUrl = config.url;
|
|
153
153
|
if (config.configFile) {
|
|
154
154
|
this.runtimeConfigFile = path.isAbsolute(config.configFile)
|
|
155
155
|
? config.configFile
|