@super-protocol/sp-cli 0.0.2-beta.1 → 0.0.2-beta.11
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 +135 -321
- package/dist/commands/account/info.d.ts +21 -0
- package/dist/commands/account/info.js +43 -0
- package/dist/commands/auth/login.d.ts +1 -10
- package/dist/commands/auth/login.js +15 -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/files/download.d.ts +15 -0
- package/dist/commands/files/download.js +53 -0
- package/dist/commands/files/upload.d.ts +18 -0
- package/dist/commands/files/upload.js +77 -0
- package/dist/commands/storage/base.d.ts +5 -0
- package/dist/commands/storage/base.js +113 -2
- package/dist/commands/storage/create.d.ts +0 -4
- package/dist/commands/storage/create.js +0 -116
- package/dist/commands/storage/select.js +12 -10
- package/dist/commands/storage/update.d.ts +0 -2
- package/dist/commands/storage/update.js +35 -87
- package/dist/config/config-file.schema.d.ts +4 -4
- package/dist/config/config-file.schema.js +1 -1
- package/dist/config/config.schema.d.ts +16 -16
- package/dist/config/config.schema.js +1 -10
- package/dist/config/resource.schema.d.ts +31 -0
- package/dist/config/resource.schema.js +14 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/lib/container.d.ts +4 -6
- package/dist/lib/container.js +21 -21
- package/dist/managers/account-manager.js +13 -3
- package/dist/managers/config-file-manager.d.ts +1 -1
- package/dist/managers/config-file-manager.js +13 -8
- package/dist/services/auth.service.d.ts +24 -0
- package/dist/services/auth.service.js +93 -0
- package/dist/services/storage.service.d.ts +44 -7
- package/dist/services/storage.service.js +207 -12
- package/dist/utils/helper.d.ts +5 -0
- package/dist/utils/helper.js +22 -0
- package/dist/utils/progress.d.ts +8 -0
- package/dist/utils/progress.js +27 -0
- package/oclif.manifest.json +180 -184
- package/package.json +9 -7
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { password, select, text } from '@clack/prompts';
|
|
2
|
+
import { StorageType } from '@super-protocol/provider-client';
|
|
1
3
|
import { BaseCommand } from '../../commands/base.js';
|
|
2
4
|
import { StorageService } from '../../services/storage.service.js';
|
|
3
5
|
export class BaseStorageCommand extends BaseCommand {
|
|
@@ -6,7 +8,116 @@ export class BaseStorageCommand extends BaseCommand {
|
|
|
6
8
|
async init() {
|
|
7
9
|
await super.init();
|
|
8
10
|
await this.container.initConfigManager().initProviderClient().build();
|
|
9
|
-
const {
|
|
10
|
-
this.storageService = new StorageService(
|
|
11
|
+
const { providerClient } = this.container;
|
|
12
|
+
this.storageService = new StorageService(providerClient, this.logger);
|
|
13
|
+
}
|
|
14
|
+
async promptS3Credentials() {
|
|
15
|
+
const region = 'us-east-1';
|
|
16
|
+
const readAccessKeyId = this.ensurePromptValue(await text({
|
|
17
|
+
message: 'Read access key ID',
|
|
18
|
+
validate(value) {
|
|
19
|
+
return value ? undefined : 'Read access key ID is required';
|
|
20
|
+
},
|
|
21
|
+
})).trim();
|
|
22
|
+
const readSecretAccessKey = this.ensurePromptValue(await password({
|
|
23
|
+
message: 'Read secret access key',
|
|
24
|
+
validate(value) {
|
|
25
|
+
return value ? undefined : 'Read secret access key is required';
|
|
26
|
+
},
|
|
27
|
+
})).trim();
|
|
28
|
+
const writeAccessKeyId = this.ensurePromptValue(await text({
|
|
29
|
+
message: 'Write access key ID',
|
|
30
|
+
validate(value) {
|
|
31
|
+
return value ? undefined : 'Write access key ID is required';
|
|
32
|
+
},
|
|
33
|
+
})).trim();
|
|
34
|
+
const writeSecretAccessKey = this.ensurePromptValue(await password({
|
|
35
|
+
message: 'Write secret access key',
|
|
36
|
+
validate(value) {
|
|
37
|
+
return value ? undefined : 'Write secret access key is required';
|
|
38
|
+
},
|
|
39
|
+
})).trim();
|
|
40
|
+
return {
|
|
41
|
+
readAccessKeyId,
|
|
42
|
+
readSecretAccessKey,
|
|
43
|
+
region,
|
|
44
|
+
writeAccessKeyId,
|
|
45
|
+
writeSecretAccessKey,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async promptStoragePayload() {
|
|
49
|
+
const storageType = this.ensurePromptValue(await select({
|
|
50
|
+
message: 'Select storage type',
|
|
51
|
+
options: [
|
|
52
|
+
{ label: 'S3', value: StorageType.S3 },
|
|
53
|
+
{ label: 'StorJ', value: StorageType.StorJ },
|
|
54
|
+
],
|
|
55
|
+
}));
|
|
56
|
+
const bucket = this.ensurePromptValue(await text({
|
|
57
|
+
message: 'Bucket name',
|
|
58
|
+
validate(value) {
|
|
59
|
+
return value ? undefined : 'Bucket is required';
|
|
60
|
+
},
|
|
61
|
+
})).trim();
|
|
62
|
+
const prefix = this.ensurePromptValue(await text({
|
|
63
|
+
defaultValue: '/',
|
|
64
|
+
message: 'Prefix',
|
|
65
|
+
validate(value) {
|
|
66
|
+
return value ? undefined : 'Prefix is required';
|
|
67
|
+
},
|
|
68
|
+
})).trim();
|
|
69
|
+
const storage = {
|
|
70
|
+
bucket,
|
|
71
|
+
prefix,
|
|
72
|
+
storageType,
|
|
73
|
+
};
|
|
74
|
+
if (storageType === StorageType.S3) {
|
|
75
|
+
storage.s3Credentials = await this.promptS3Credentials();
|
|
76
|
+
}
|
|
77
|
+
if (storageType === StorageType.StorJ) {
|
|
78
|
+
storage.storjCredentials = await this.promptStorJCredentials();
|
|
79
|
+
}
|
|
80
|
+
return storage;
|
|
81
|
+
}
|
|
82
|
+
async promptStorJCredentials() {
|
|
83
|
+
const readAccessToken = this.ensurePromptValue(await password({
|
|
84
|
+
message: 'Read access token',
|
|
85
|
+
validate(value) {
|
|
86
|
+
return value ? undefined : 'Read access token is required';
|
|
87
|
+
},
|
|
88
|
+
})).trim();
|
|
89
|
+
const writeAccessToken = this.ensurePromptValue(await password({
|
|
90
|
+
message: 'Write access token',
|
|
91
|
+
validate(value) {
|
|
92
|
+
return value ? undefined : 'Write access token is required';
|
|
93
|
+
},
|
|
94
|
+
})).trim();
|
|
95
|
+
return {
|
|
96
|
+
readAccessToken,
|
|
97
|
+
writeAccessToken,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
validateStoragePayload(payload) {
|
|
101
|
+
if (!payload || typeof payload !== 'object') {
|
|
102
|
+
this.error('Storage definition must be an object');
|
|
103
|
+
}
|
|
104
|
+
if (!payload.bucket) {
|
|
105
|
+
this.error('Storage definition missing "bucket"');
|
|
106
|
+
}
|
|
107
|
+
if (!payload.prefix) {
|
|
108
|
+
this.error('Storage definition missing "prefix"');
|
|
109
|
+
}
|
|
110
|
+
if (!payload.storageType) {
|
|
111
|
+
this.error('Storage definition missing "storageType"');
|
|
112
|
+
}
|
|
113
|
+
if (!Object.values(StorageType).includes(payload.storageType)) {
|
|
114
|
+
this.error(`Unsupported storage type: ${payload.storageType}`);
|
|
115
|
+
}
|
|
116
|
+
if (payload.storageType === StorageType.S3 && !payload.s3Credentials) {
|
|
117
|
+
this.error('S3 storage requires "s3Credentials"');
|
|
118
|
+
}
|
|
119
|
+
if (payload.storageType === StorageType.StorJ && !payload.storjCredentials) {
|
|
120
|
+
this.error('StorJ storage requires "storjCredentials"');
|
|
121
|
+
}
|
|
11
122
|
}
|
|
12
123
|
}
|
|
@@ -8,8 +8,4 @@ export default class StorageCreate extends BaseStorageCommand<typeof StorageCrea
|
|
|
8
8
|
};
|
|
9
9
|
run(): Promise<void>;
|
|
10
10
|
private loadStorageFromFile;
|
|
11
|
-
private promptS3Credentials;
|
|
12
|
-
private promptStoragePayload;
|
|
13
|
-
private promptStorJCredentials;
|
|
14
|
-
private validateStoragePayload;
|
|
15
11
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { input, password, select } from '@inquirer/prompts';
|
|
2
1
|
import { Flags } from '@oclif/core';
|
|
3
|
-
import { StorageType } from '@super-protocol/provider-client';
|
|
4
2
|
import fs from 'node:fs/promises';
|
|
5
3
|
import path from 'node:path';
|
|
6
4
|
import { BaseStorageCommand } from './base.js';
|
|
@@ -52,118 +50,4 @@ export default class StorageCreate extends BaseStorageCommand {
|
|
|
52
50
|
this.error(`Failed to load storage definition: ${error instanceof Error ? error.message : String(error)}`);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
async promptS3Credentials() {
|
|
56
|
-
const region = await input({
|
|
57
|
-
message: 'AWS region',
|
|
58
|
-
validate(value) {
|
|
59
|
-
return value ? true : 'Region is required';
|
|
60
|
-
},
|
|
61
|
-
}).then(value => value.trim());
|
|
62
|
-
const readAccessKeyId = await input({
|
|
63
|
-
message: 'Read access key ID',
|
|
64
|
-
validate(value) {
|
|
65
|
-
return value ? true : 'Read access key ID is required';
|
|
66
|
-
},
|
|
67
|
-
}).then(value => value.trim());
|
|
68
|
-
const readSecretAccessKey = await password({
|
|
69
|
-
message: 'Read secret access key',
|
|
70
|
-
validate(value) {
|
|
71
|
-
return value ? true : 'Read secret access key is required';
|
|
72
|
-
},
|
|
73
|
-
}).then(value => value.trim());
|
|
74
|
-
const writeAccessKeyId = await input({
|
|
75
|
-
message: 'Write access key ID',
|
|
76
|
-
validate(value) {
|
|
77
|
-
return value ? true : 'Write access key ID is required';
|
|
78
|
-
},
|
|
79
|
-
}).then(value => value.trim());
|
|
80
|
-
const writeSecretAccessKey = await password({
|
|
81
|
-
message: 'Write secret access key',
|
|
82
|
-
validate(value) {
|
|
83
|
-
return value ? true : 'Write secret access key is required';
|
|
84
|
-
},
|
|
85
|
-
}).then(value => value.trim());
|
|
86
|
-
return {
|
|
87
|
-
readAccessKeyId,
|
|
88
|
-
readSecretAccessKey,
|
|
89
|
-
region,
|
|
90
|
-
writeAccessKeyId,
|
|
91
|
-
writeSecretAccessKey,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async promptStoragePayload() {
|
|
95
|
-
const storageType = await select({
|
|
96
|
-
choices: [
|
|
97
|
-
{ name: 'Amazon S3', value: StorageType.S3 },
|
|
98
|
-
{ name: 'StorJ', value: StorageType.StorJ },
|
|
99
|
-
],
|
|
100
|
-
message: 'Select storage type',
|
|
101
|
-
});
|
|
102
|
-
const bucket = await input({
|
|
103
|
-
message: 'Bucket name',
|
|
104
|
-
validate(value) {
|
|
105
|
-
return value ? true : 'Bucket is required';
|
|
106
|
-
},
|
|
107
|
-
}).then(value => value.trim());
|
|
108
|
-
const prefix = await input({
|
|
109
|
-
default: '/',
|
|
110
|
-
message: 'Prefix',
|
|
111
|
-
validate(value) {
|
|
112
|
-
return value ? true : 'Prefix is required';
|
|
113
|
-
},
|
|
114
|
-
}).then(value => value.trim());
|
|
115
|
-
const storage = {
|
|
116
|
-
bucket,
|
|
117
|
-
prefix,
|
|
118
|
-
storageType,
|
|
119
|
-
};
|
|
120
|
-
if (storageType === StorageType.S3) {
|
|
121
|
-
storage.s3Credentials = await this.promptS3Credentials();
|
|
122
|
-
}
|
|
123
|
-
if (storageType === StorageType.StorJ) {
|
|
124
|
-
storage.storjCredentials = await this.promptStorJCredentials();
|
|
125
|
-
}
|
|
126
|
-
return storage;
|
|
127
|
-
}
|
|
128
|
-
async promptStorJCredentials() {
|
|
129
|
-
const readAccessToken = await password({
|
|
130
|
-
message: 'Read access token',
|
|
131
|
-
validate(value) {
|
|
132
|
-
return value ? true : 'Read access token is required';
|
|
133
|
-
},
|
|
134
|
-
}).then(value => value.trim());
|
|
135
|
-
const writeAccessToken = await password({
|
|
136
|
-
message: 'Write access token',
|
|
137
|
-
validate(value) {
|
|
138
|
-
return value ? true : 'Write access token is required';
|
|
139
|
-
},
|
|
140
|
-
}).then(value => value.trim());
|
|
141
|
-
return {
|
|
142
|
-
readAccessToken,
|
|
143
|
-
writeAccessToken,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
validateStoragePayload(payload) {
|
|
147
|
-
if (!payload || typeof payload !== 'object') {
|
|
148
|
-
this.error('Storage definition must be an object');
|
|
149
|
-
}
|
|
150
|
-
if (!payload.bucket) {
|
|
151
|
-
this.error('Storage definition missing "bucket"');
|
|
152
|
-
}
|
|
153
|
-
if (!payload.prefix) {
|
|
154
|
-
this.error('Storage definition missing "prefix"');
|
|
155
|
-
}
|
|
156
|
-
if (!payload.storageType) {
|
|
157
|
-
this.error('Storage definition missing "storageType"');
|
|
158
|
-
}
|
|
159
|
-
if (!Object.values(StorageType).includes(payload.storageType)) {
|
|
160
|
-
this.error(`Unsupported storage type: ${payload.storageType}`);
|
|
161
|
-
}
|
|
162
|
-
if (payload.storageType === StorageType.S3 && !payload.s3Credentials) {
|
|
163
|
-
this.error('S3 storage requires "s3Credentials"');
|
|
164
|
-
}
|
|
165
|
-
if (payload.storageType === StorageType.StorJ && !payload.storjCredentials) {
|
|
166
|
-
this.error('StorJ storage requires "storjCredentials"');
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { select } from '@
|
|
1
|
+
import { select } from '@clack/prompts';
|
|
2
2
|
import { Flags } from '@oclif/core';
|
|
3
|
-
import {
|
|
3
|
+
import { StoragesUndefinedError } from '../../services/storage.service.js';
|
|
4
4
|
import { BaseStorageCommand } from './base.js';
|
|
5
5
|
export default class StorageSelect extends BaseStorageCommand {
|
|
6
6
|
static description = 'Select a storage that will be used by subsequent commands.';
|
|
@@ -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');
|
|
@@ -35,10 +35,12 @@ export default class StorageSelect extends BaseStorageCommand {
|
|
|
35
35
|
this.log(`Selected storage: ${storageId}`);
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
|
-
if (error instanceof
|
|
38
|
+
if (error instanceof StoragesUndefinedError) {
|
|
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
|
}
|
|
@@ -10,7 +10,5 @@ export default class StorageUpdate extends BaseStorageCommand<typeof StorageUpda
|
|
|
10
10
|
private ensureNonEmptyString;
|
|
11
11
|
private ensureUpdatePayload;
|
|
12
12
|
private loadStorageFromFile;
|
|
13
|
-
private promptS3Credentials;
|
|
14
13
|
private promptStorageUpdate;
|
|
15
|
-
private promptStorJCredentials;
|
|
16
14
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { confirm,
|
|
1
|
+
import { confirm, 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';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import {
|
|
6
|
+
import { StoragesUndefinedError } from '../../services/storage.service.js';
|
|
7
7
|
import { BaseStorageCommand } from './base.js';
|
|
8
8
|
export default class StorageUpdate extends BaseStorageCommand {
|
|
9
9
|
static description = 'Update the configuration of an existing storage.';
|
|
@@ -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 (!
|
|
36
|
-
throw new
|
|
35
|
+
if (!options || options.length === 0) {
|
|
36
|
+
throw new StoragesUndefinedError('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);
|
|
@@ -51,10 +54,12 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
51
54
|
this.log(`Storage updated: ${storageId}`);
|
|
52
55
|
}
|
|
53
56
|
catch (error) {
|
|
54
|
-
if (error instanceof
|
|
57
|
+
if (error instanceof StoragesUndefinedError) {
|
|
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) {
|
|
@@ -125,85 +130,46 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
125
130
|
this.error(`Failed to load storage update definition: ${error instanceof Error ? error.message : String(error)}`);
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
|
-
async promptS3Credentials() {
|
|
129
|
-
const region = await input({
|
|
130
|
-
message: 'AWS region',
|
|
131
|
-
validate(value) {
|
|
132
|
-
return value ? true : 'Region is required';
|
|
133
|
-
},
|
|
134
|
-
}).then(value => value.trim());
|
|
135
|
-
const readAccessKeyId = await input({
|
|
136
|
-
message: 'Read access key ID',
|
|
137
|
-
validate(value) {
|
|
138
|
-
return value ? true : 'Read access key ID is required';
|
|
139
|
-
},
|
|
140
|
-
}).then(value => value.trim());
|
|
141
|
-
const readSecretAccessKey = await password({
|
|
142
|
-
message: 'Read secret access key',
|
|
143
|
-
validate(value) {
|
|
144
|
-
return value ? true : 'Read secret access key is required';
|
|
145
|
-
},
|
|
146
|
-
}).then(value => value.trim());
|
|
147
|
-
const writeAccessKeyId = await input({
|
|
148
|
-
message: 'Write access key ID',
|
|
149
|
-
validate(value) {
|
|
150
|
-
return value ? true : 'Write access key ID is required';
|
|
151
|
-
},
|
|
152
|
-
}).then(value => value.trim());
|
|
153
|
-
const writeSecretAccessKey = await password({
|
|
154
|
-
message: 'Write secret access key',
|
|
155
|
-
validate(value) {
|
|
156
|
-
return value ? true : 'Write secret access key is required';
|
|
157
|
-
},
|
|
158
|
-
}).then(value => value.trim());
|
|
159
|
-
return {
|
|
160
|
-
readAccessKeyId,
|
|
161
|
-
readSecretAccessKey,
|
|
162
|
-
region,
|
|
163
|
-
writeAccessKeyId,
|
|
164
|
-
writeSecretAccessKey,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
133
|
async promptStorageUpdate(existingStorage) {
|
|
168
134
|
const payload = {};
|
|
169
|
-
const bucket = await
|
|
170
|
-
|
|
135
|
+
const bucket = this.ensurePromptValue(await text({
|
|
136
|
+
defaultValue: existingStorage?.bucket ?? '',
|
|
171
137
|
message: 'Bucket name (leave empty to keep current)',
|
|
172
|
-
}).
|
|
138
|
+
})).trim();
|
|
173
139
|
if (bucket) {
|
|
174
140
|
payload.bucket = bucket;
|
|
175
141
|
}
|
|
176
|
-
const prefix = await
|
|
177
|
-
|
|
142
|
+
const prefix = this.ensurePromptValue(await text({
|
|
143
|
+
defaultValue: existingStorage?.prefix ?? '',
|
|
178
144
|
message: 'Prefix (leave empty to keep current)',
|
|
179
|
-
}).
|
|
145
|
+
})).trim();
|
|
180
146
|
if (prefix) {
|
|
181
147
|
payload.prefix = prefix;
|
|
182
148
|
}
|
|
183
149
|
let newStorageType;
|
|
184
|
-
const shouldChangeType = await confirm({
|
|
185
|
-
|
|
150
|
+
const shouldChangeType = this.ensurePromptValue(await confirm({
|
|
151
|
+
initialValue: false,
|
|
186
152
|
message: existingStorage
|
|
187
153
|
? `Change storage type? (current: ${existingStorage.storageType})`
|
|
188
154
|
: 'Change storage type?',
|
|
189
|
-
});
|
|
155
|
+
}));
|
|
190
156
|
if (shouldChangeType) {
|
|
191
|
-
newStorageType = await select({
|
|
192
|
-
choices: [
|
|
193
|
-
{ name: 'Amazon S3', value: StorageType.S3 },
|
|
194
|
-
{ name: 'StorJ', value: StorageType.StorJ },
|
|
195
|
-
],
|
|
157
|
+
newStorageType = this.ensurePromptValue(await select({
|
|
196
158
|
message: 'Select new storage type',
|
|
197
|
-
|
|
159
|
+
options: [
|
|
160
|
+
{ label: 'Amazon S3', value: StorageType.S3 },
|
|
161
|
+
{ label: 'StorJ', value: StorageType.StorJ },
|
|
162
|
+
],
|
|
163
|
+
}));
|
|
198
164
|
payload.storageType = newStorageType;
|
|
199
165
|
}
|
|
200
166
|
const effectiveType = newStorageType ?? existingStorage?.storageType;
|
|
201
167
|
const credentialsRequired = Boolean(newStorageType);
|
|
202
168
|
if (effectiveType) {
|
|
203
|
-
const updateCredentials = credentialsRequired || await confirm({
|
|
204
|
-
|
|
169
|
+
const updateCredentials = credentialsRequired || this.ensurePromptValue(await confirm({
|
|
170
|
+
initialValue: false,
|
|
205
171
|
message: `Update ${effectiveType} credentials?`,
|
|
206
|
-
});
|
|
172
|
+
}));
|
|
207
173
|
if (updateCredentials) {
|
|
208
174
|
if (effectiveType === StorageType.S3) {
|
|
209
175
|
payload.s3Credentials = await this.promptS3Credentials();
|
|
@@ -218,22 +184,4 @@ export default class StorageUpdate extends BaseStorageCommand {
|
|
|
218
184
|
}
|
|
219
185
|
return this.ensureUpdatePayload(payload);
|
|
220
186
|
}
|
|
221
|
-
async promptStorJCredentials() {
|
|
222
|
-
const readAccessToken = await password({
|
|
223
|
-
message: 'Read access token',
|
|
224
|
-
validate(value) {
|
|
225
|
-
return value ? true : 'Read access token is required';
|
|
226
|
-
},
|
|
227
|
-
}).then(value => value.trim());
|
|
228
|
-
const writeAccessToken = await password({
|
|
229
|
-
message: 'Write access token',
|
|
230
|
-
validate(value) {
|
|
231
|
-
return value ? true : 'Write access token is required';
|
|
232
|
-
},
|
|
233
|
-
}).then(value => value.trim());
|
|
234
|
-
return {
|
|
235
|
-
readAccessToken,
|
|
236
|
-
writeAccessToken,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
187
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Static } from '
|
|
2
|
-
export declare const configFileManagerSchema:
|
|
3
|
-
configs:
|
|
4
|
-
currentConfig:
|
|
1
|
+
import { Static, Type } from 'typebox';
|
|
2
|
+
export declare const configFileManagerSchema: Type.TObject<{
|
|
3
|
+
configs: Type.TArray<Type.TString>;
|
|
4
|
+
currentConfig: Type.TOptional<Type.TString>;
|
|
5
5
|
}>;
|
|
6
6
|
export type ConfigFileManagerData = Static<typeof configFileManagerSchema>;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Static } from '
|
|
2
|
-
export declare const accountSchema:
|
|
3
|
-
address:
|
|
4
|
-
privateKey:
|
|
1
|
+
import { Static, Type } from 'typebox';
|
|
2
|
+
export declare const accountSchema: Type.TObject<{
|
|
3
|
+
address: Type.TString;
|
|
4
|
+
privateKey: Type.TString;
|
|
5
5
|
}>;
|
|
6
|
-
export declare const authSchema:
|
|
7
|
-
accessKey:
|
|
6
|
+
export declare const authSchema: Type.TObject<{
|
|
7
|
+
accessKey: Type.TString;
|
|
8
8
|
}>;
|
|
9
|
-
export declare const cliConfigSchema:
|
|
10
|
-
account:
|
|
11
|
-
address:
|
|
12
|
-
privateKey:
|
|
9
|
+
export declare const cliConfigSchema: Type.TObject<{
|
|
10
|
+
account: Type.TOptional<Type.TObject<{
|
|
11
|
+
address: Type.TString;
|
|
12
|
+
privateKey: Type.TString;
|
|
13
13
|
}>>;
|
|
14
|
-
auth:
|
|
15
|
-
accessKey:
|
|
14
|
+
auth: Type.TOptional<Type.TObject<{
|
|
15
|
+
accessKey: Type.TString;
|
|
16
16
|
}>>;
|
|
17
|
-
cookies:
|
|
18
|
-
name:
|
|
19
|
-
providerUrl:
|
|
20
|
-
selectedStorage:
|
|
17
|
+
cookies: Type.TOptional<Type.TUnknown>;
|
|
18
|
+
name: Type.TOptional<Type.TString>;
|
|
19
|
+
providerUrl: Type.TOptional<Type.TString>;
|
|
20
|
+
selectedStorage: Type.TOptional<Type.TString>;
|
|
21
21
|
}>;
|
|
22
22
|
export type CliConfig = Static<typeof cliConfigSchema>;
|
|
23
23
|
export type Account = Static<typeof accountSchema>;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
});
|
|
1
|
+
import { Type } from 'typebox';
|
|
11
2
|
export const accountSchema = Type.Object({
|
|
12
3
|
address: Type.String({ pattern: '^0x[a-fA-F0-9]{40}$' }),
|
|
13
4
|
privateKey: Type.String({ pattern: '^0x[a-fA-F0-9]{64}$' }),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ResourceType, StorageType } from '@super-protocol/provider-client';
|
|
2
|
+
import { Type } from 'typebox';
|
|
3
|
+
export declare const storageResourceSchema: Type.TObject<{
|
|
4
|
+
hash: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TObject<{
|
|
5
|
+
algo: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TEnum<typeof import("@super-protocol/dto-js").HashAlgorithm>;
|
|
6
|
+
hash: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
7
|
+
encoding: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TEnum<typeof import("@super-protocol/dto-js").Encoding>;
|
|
8
|
+
}>;
|
|
9
|
+
resource: Type.TObject<{
|
|
10
|
+
credentials: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TUnion<[import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TIntersect<[import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TObject<{
|
|
11
|
+
bucket: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
12
|
+
prefix: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
13
|
+
}>, import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TObject<{
|
|
14
|
+
token: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
15
|
+
}>]>, import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TIntersect<[import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TObject<{
|
|
16
|
+
bucket: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
17
|
+
prefix: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
18
|
+
}>, import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TObject<{
|
|
19
|
+
accessKeyId: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
20
|
+
secretKey: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
21
|
+
endpoint: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
22
|
+
}>]>, import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TObject<{
|
|
23
|
+
bucket: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
24
|
+
prefix: import("@sinclair/typebox", { with: { "resolution-mode": "require" } }).TString;
|
|
25
|
+
}>]>;
|
|
26
|
+
filepath: Type.TString;
|
|
27
|
+
storageType: Type.TEnum<[StorageType.S3, StorageType.FS, StorageType.StorJ]>;
|
|
28
|
+
type: Type.TEnum<[ResourceType.StorageProvider, ResourceType.Url]>;
|
|
29
|
+
}>;
|
|
30
|
+
size: Type.TNumber;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HashSchema, StorageAccessCredentialsSchema } from '@super-protocol/dto-js';
|
|
2
|
+
import { ResourceType, StorageType } from '@super-protocol/provider-client';
|
|
3
|
+
import { Type } from 'typebox';
|
|
4
|
+
const storageProviderResourceSchema = Type.Object({
|
|
5
|
+
credentials: StorageAccessCredentialsSchema,
|
|
6
|
+
filepath: Type.String({ minLength: 1 }),
|
|
7
|
+
storageType: Type.Enum(StorageType),
|
|
8
|
+
type: Type.Enum(ResourceType),
|
|
9
|
+
});
|
|
10
|
+
export const storageResourceSchema = Type.Object({
|
|
11
|
+
hash: HashSchema,
|
|
12
|
+
resource: storageProviderResourceSchema,
|
|
13
|
+
size: Type.Number({ minimum: 0 }),
|
|
14
|
+
});
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export declare const FILE_ACCESS_PERMS = 384;
|
|
|
2
2
|
export declare const DIR_ACCESS_PERMS = 448;
|
|
3
3
|
export declare const PROVIDER_URL = "https://api.dp.superprotocol.com";
|
|
4
4
|
export declare const REFRESH_TOKEN_URI = "/api/auth/refresh-access";
|
|
5
|
+
export declare const S3_ENDPOINT = "https://gateway.storjshare.io";
|
package/dist/constants.js
CHANGED