@blocklet/did-space-js 0.5.58
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 +77 -0
- package/dist/client/index.d.ts +40 -0
- package/dist/client/index.js +110 -0
- package/dist/commands/backup/backup-blocklet.d.ts +14 -0
- package/dist/commands/backup/backup-blocklet.js +83 -0
- package/dist/commands/backup/index.d.ts +3 -0
- package/dist/commands/backup/index.js +19 -0
- package/dist/commands/backup/post-app-backup.d.ts +9 -0
- package/dist/commands/backup/post-app-backup.js +49 -0
- package/dist/commands/backup/put-app-backup.d.ts +9 -0
- package/dist/commands/backup/put-app-backup.js +49 -0
- package/dist/commands/base.d.ts +21 -0
- package/dist/commands/base.js +47 -0
- package/dist/commands/incremental-backup/backup-blocklet.d.ts +14 -0
- package/dist/commands/incremental-backup/backup-blocklet.js +90 -0
- package/dist/commands/incremental-backup/index.d.ts +1 -0
- package/dist/commands/incremental-backup/index.js +17 -0
- package/dist/commands/incremental-sync/index.d.ts +2 -0
- package/dist/commands/incremental-sync/index.js +18 -0
- package/dist/commands/incremental-sync/sync-base.d.ts +76 -0
- package/dist/commands/incremental-sync/sync-base.js +236 -0
- package/dist/commands/incremental-sync/sync-push.d.ts +30 -0
- package/dist/commands/incremental-sync/sync-push.js +202 -0
- package/dist/commands/index.d.ts +9 -0
- package/dist/commands/index.js +25 -0
- package/dist/commands/nft/index.d.ts +1 -0
- package/dist/commands/nft/index.js +17 -0
- package/dist/commands/nft/put-nft-object.d.ts +20 -0
- package/dist/commands/nft/put-nft-object.js +143 -0
- package/dist/commands/object/delete-object.d.ts +7 -0
- package/dist/commands/object/delete-object.js +38 -0
- package/dist/commands/object/get-object.d.ts +7 -0
- package/dist/commands/object/get-object.js +43 -0
- package/dist/commands/object/index.d.ts +5 -0
- package/dist/commands/object/index.js +21 -0
- package/dist/commands/object/list-object.d.ts +7 -0
- package/dist/commands/object/list-object.js +31 -0
- package/dist/commands/object/list-objects.d.ts +7 -0
- package/dist/commands/object/list-objects.js +44 -0
- package/dist/commands/object/put-object.d.ts +7 -0
- package/dist/commands/object/put-object.js +61 -0
- package/dist/commands/restore/index.d.ts +3 -0
- package/dist/commands/restore/index.js +19 -0
- package/dist/commands/restore/post-app-restore.d.ts +7 -0
- package/dist/commands/restore/post-app-restore.js +45 -0
- package/dist/commands/restore/put-app-restore.d.ts +9 -0
- package/dist/commands/restore/put-app-restore.js +49 -0
- package/dist/commands/restore/restore-blocklet.d.ts +14 -0
- package/dist/commands/restore/restore-blocklet.js +80 -0
- package/dist/commands/space/head.d.ts +8 -0
- package/dist/commands/space/head.js +52 -0
- package/dist/commands/space/index.d.ts +1 -0
- package/dist/commands/space/index.js +17 -0
- package/dist/commands/sync/index.d.ts +3 -0
- package/dist/commands/sync/index.js +19 -0
- package/dist/commands/sync/sync-folder-base.d.ts +105 -0
- package/dist/commands/sync/sync-folder-base.js +319 -0
- package/dist/commands/sync/sync-folder-pull.d.ts +13 -0
- package/dist/commands/sync/sync-folder-pull.js +151 -0
- package/dist/commands/sync/sync-folder-push.d.ts +20 -0
- package/dist/commands/sync/sync-folder-push.js +166 -0
- package/dist/did-document/did-document.d.ts +29 -0
- package/dist/did-document/did-document.js +2 -0
- package/dist/did-document/index.d.ts +3 -0
- package/dist/did-document/index.js +19 -0
- package/dist/did-document/sign-document.d.ts +3 -0
- package/dist/did-document/sign-document.js +13 -0
- package/dist/did-document/verify-document.d.ts +10 -0
- package/dist/did-document/verify-document.js +35 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/libs/api.d.ts +3 -0
- package/dist/libs/api.js +65 -0
- package/dist/libs/did.d.ts +9 -0
- package/dist/libs/did.js +34 -0
- package/dist/libs/encoding.d.ts +7 -0
- package/dist/libs/encoding.js +17 -0
- package/dist/libs/error.d.ts +4 -0
- package/dist/libs/error.js +27 -0
- package/dist/libs/hash.d.ts +1 -0
- package/dist/libs/hash.js +5 -0
- package/dist/libs/index.d.ts +11 -0
- package/dist/libs/index.js +27 -0
- package/dist/libs/logger.d.ts +2 -0
- package/dist/libs/logger.js +12 -0
- package/dist/libs/object-integrality.d.ts +1 -0
- package/dist/libs/object-integrality.js +13 -0
- package/dist/libs/performance.d.ts +7 -0
- package/dist/libs/performance.js +13 -0
- package/dist/libs/sleep.d.ts +1 -0
- package/dist/libs/sleep.js +9 -0
- package/dist/libs/space.d.ts +16 -0
- package/dist/libs/space.js +56 -0
- package/dist/libs/stream.d.ts +3 -0
- package/dist/libs/stream.js +10 -0
- package/dist/meta/backup/backup-blocklet-command.d.ts +50 -0
- package/dist/meta/backup/backup-blocklet-command.js +2 -0
- package/dist/meta/backup/index.d.ts +3 -0
- package/dist/meta/backup/index.js +19 -0
- package/dist/meta/backup/post-app-backup-command.d.ts +8 -0
- package/dist/meta/backup/post-app-backup-command.js +16 -0
- package/dist/meta/backup/put-app-backup-command.d.ts +7 -0
- package/dist/meta/backup/put-app-backup-command.js +18 -0
- package/dist/meta/incremental-backup/backup-blocklet-command.d.ts +50 -0
- package/dist/meta/incremental-backup/backup-blocklet-command.js +2 -0
- package/dist/meta/incremental-backup/index.d.ts +1 -0
- package/dist/meta/incremental-backup/index.js +17 -0
- package/dist/meta/index.d.ts +7 -0
- package/dist/meta/index.js +23 -0
- package/dist/meta/nft/index.d.ts +1 -0
- package/dist/meta/nft/index.js +17 -0
- package/dist/meta/nft/put-nft-object-command.d.ts +51 -0
- package/dist/meta/nft/put-nft-object-command.js +2 -0
- package/dist/meta/object/delete-object-command.d.ts +6 -0
- package/dist/meta/object/delete-object-command.js +2 -0
- package/dist/meta/object/get-object-command.d.ts +10 -0
- package/dist/meta/object/get-object-command.js +2 -0
- package/dist/meta/object/head-object-command.d.ts +13 -0
- package/dist/meta/object/head-object-command.js +2 -0
- package/dist/meta/object/index.d.ts +5 -0
- package/dist/meta/object/index.js +21 -0
- package/dist/meta/object/list-object-command.d.ts +6 -0
- package/dist/meta/object/list-object-command.js +2 -0
- package/dist/meta/object/list-objects-command.d.ts +8 -0
- package/dist/meta/object/list-objects-command.js +2 -0
- package/dist/meta/object/put-object-command.d.ts +29 -0
- package/dist/meta/object/put-object-command.js +2 -0
- package/dist/meta/restore/index.d.ts +3 -0
- package/dist/meta/restore/index.js +19 -0
- package/dist/meta/restore/post-app-restore-command.d.ts +8 -0
- package/dist/meta/restore/post-app-restore-command.js +13 -0
- package/dist/meta/restore/put-app-restore-command.d.ts +7 -0
- package/dist/meta/restore/put-app-restore-command.js +18 -0
- package/dist/meta/restore/restore-blocklet-command.d.ts +28 -0
- package/dist/meta/restore/restore-blocklet-command.js +2 -0
- package/dist/meta/spaces-client-options.d.ts +5 -0
- package/dist/meta/spaces-client-options.js +2 -0
- package/dist/meta/sync/incremental-sync-base-command.d.ts +7 -0
- package/dist/meta/sync/incremental-sync-base-command.js +2 -0
- package/dist/meta/sync/incremental-sync-push-command.d.ts +8 -0
- package/dist/meta/sync/incremental-sync-push-command.js +2 -0
- package/dist/meta/sync/index.d.ts +6 -0
- package/dist/meta/sync/index.js +22 -0
- package/dist/meta/sync/sync-base-command.d.ts +121 -0
- package/dist/meta/sync/sync-base-command.js +2 -0
- package/dist/meta/sync/sync-folder-base-command.d.ts +12 -0
- package/dist/meta/sync/sync-folder-base-command.js +2 -0
- package/dist/meta/sync/sync-folder-pull-command.d.ts +5 -0
- package/dist/meta/sync/sync-folder-pull-command.js +2 -0
- package/dist/meta/sync/sync-folder-push-command.d.ts +7 -0
- package/dist/meta/sync/sync-folder-push-command.js +2 -0
- package/dist/protocol/command.protocol.d.ts +68 -0
- package/dist/protocol/command.protocol.js +2 -0
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +17 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.js +17 -0
- package/dist/security/request-signature.d.ts +32 -0
- package/dist/security/request-signature.js +140 -0
- package/package.json +78 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PutNftObjectCommand = void 0;
|
|
7
|
+
const util_1 = require("@ocap/util");
|
|
8
|
+
const env_1 = __importDefault(require("@blocklet/env"));
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const fs_extra_1 = require("fs-extra");
|
|
11
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
12
|
+
const core_1 = require("@did-space/core");
|
|
13
|
+
const ufo_1 = require("ufo");
|
|
14
|
+
const did_document_1 = require("../../did-document");
|
|
15
|
+
const base_1 = require("../base");
|
|
16
|
+
const security_1 = require("../../security");
|
|
17
|
+
const libs_1 = require("../../libs");
|
|
18
|
+
class PutNftObjectCommand extends base_1.BaseCommand {
|
|
19
|
+
tempCacheObjectKey;
|
|
20
|
+
tempCacheObjectHash;
|
|
21
|
+
constructor(input) {
|
|
22
|
+
super(input);
|
|
23
|
+
this.tempCacheObjectKey = (0, path_1.join)(env_1.default.dataDir, 'temp-uploads', Date.now() + this.input.display.key);
|
|
24
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(this.tempCacheObjectKey));
|
|
25
|
+
}
|
|
26
|
+
getUrl() {
|
|
27
|
+
const { endpoint } = this.context;
|
|
28
|
+
const didObjectUrl = (0, ufo_1.joinURL)(endpoint, 'did-objects', (0, libs_1.encode)(this.input.display.key));
|
|
29
|
+
const didObjectURL = new URL(didObjectUrl);
|
|
30
|
+
didObjectURL.searchParams.set('did', this.input.did);
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
return didObjectURL.toString();
|
|
33
|
+
}
|
|
34
|
+
getDisplayUrl() {
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
return (0, ufo_1.joinURL)(this.context.endpoint.replace(/\/api\/space.*/, ''), 'resolve', (0, libs_1.toABTDid)(this.input.did), 'display');
|
|
37
|
+
}
|
|
38
|
+
async getStreams() {
|
|
39
|
+
const writeStream = (0, fs_extra_1.createWriteStream)(this.tempCacheObjectKey);
|
|
40
|
+
this.input.display.data.pipe(writeStream);
|
|
41
|
+
await (0, libs_1.streamToFile)(writeStream);
|
|
42
|
+
this.input.display.data = (0, fs_extra_1.createReadStream)(this.tempCacheObjectKey);
|
|
43
|
+
const streamForHash = (0, fs_extra_1.createReadStream)(this.tempCacheObjectKey);
|
|
44
|
+
return {
|
|
45
|
+
streamForHash,
|
|
46
|
+
streamForUpload: this.input.display.data,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async getDidDocument(streamForHash) {
|
|
50
|
+
const displayUrl = await this.getDisplayUrl();
|
|
51
|
+
const currentTime = new Date().toISOString();
|
|
52
|
+
const wallet = this.input.controller;
|
|
53
|
+
const ABTDid = (0, libs_1.toABTDid)(this.input.did);
|
|
54
|
+
const controllerAddress = (0, libs_1.toABTDid)(wallet.address);
|
|
55
|
+
const hash = await (0, core_1.getHash)(streamForHash);
|
|
56
|
+
this.tempCacheObjectHash = hash;
|
|
57
|
+
const didDocument = {
|
|
58
|
+
'@context': 'https://www.w3.org/ns/did/v1',
|
|
59
|
+
id: ABTDid,
|
|
60
|
+
controller: controllerAddress,
|
|
61
|
+
service: [
|
|
62
|
+
{
|
|
63
|
+
id: `${ABTDid}/display`,
|
|
64
|
+
type: 'NFTDisplay',
|
|
65
|
+
key: this.input.display.key,
|
|
66
|
+
// v0.2 版本开始有的
|
|
67
|
+
hash,
|
|
68
|
+
serviceEndpoint: displayUrl,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: `${ABTDid}/explorer`,
|
|
72
|
+
type: 'ArcBlockExplorerUrl',
|
|
73
|
+
serviceEndpoint: (0, ufo_1.joinURL)(this.input.chainHost, 'assets', ABTDid),
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
verificationMethod: [
|
|
77
|
+
{
|
|
78
|
+
id: `${ABTDid}#key-1`,
|
|
79
|
+
type: 'Ed25519Signature',
|
|
80
|
+
controller: controllerAddress,
|
|
81
|
+
publicKeyMultibase: (0, util_1.toBase58)(wallet.publicKey),
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
proof: {
|
|
85
|
+
type: 'Ed25519Signature',
|
|
86
|
+
created: currentTime,
|
|
87
|
+
verificationMethod: `${ABTDid}#key-1`,
|
|
88
|
+
},
|
|
89
|
+
authentication: [`${ABTDid}#key-1`],
|
|
90
|
+
created: currentTime,
|
|
91
|
+
updated: currentTime,
|
|
92
|
+
};
|
|
93
|
+
(0, did_document_1.signDidDocument)(didDocument, wallet);
|
|
94
|
+
return didDocument;
|
|
95
|
+
}
|
|
96
|
+
async getAxiosRequestConfig() {
|
|
97
|
+
try {
|
|
98
|
+
const url = await this.getUrl();
|
|
99
|
+
const method = 'PUT';
|
|
100
|
+
const { streamForUpload, streamForHash } = await this.getStreams();
|
|
101
|
+
const didDocument = await this.getDidDocument(streamForHash);
|
|
102
|
+
const formData = new form_data_1.default();
|
|
103
|
+
formData.append('data', streamForUpload);
|
|
104
|
+
formData.append('didDocument', JSON.stringify(didDocument));
|
|
105
|
+
const { headers } = (0, security_1.signRequest)({
|
|
106
|
+
url,
|
|
107
|
+
method,
|
|
108
|
+
data: formData,
|
|
109
|
+
headers: {
|
|
110
|
+
[core_1.HEADERS.X_HASH]: this.tempCacheObjectHash,
|
|
111
|
+
[core_1.HEADERS.X_SIGNATURE_VERSION]: '2',
|
|
112
|
+
},
|
|
113
|
+
wallet: this.context.wallet,
|
|
114
|
+
delegation: this.context.delegation,
|
|
115
|
+
});
|
|
116
|
+
const config = {
|
|
117
|
+
url,
|
|
118
|
+
method,
|
|
119
|
+
data: formData,
|
|
120
|
+
maxContentLength: Infinity,
|
|
121
|
+
maxBodyLength: Infinity,
|
|
122
|
+
headers: {
|
|
123
|
+
...headers,
|
|
124
|
+
'Content-Type': 'multipart/form-data',
|
|
125
|
+
...formData.getHeaders(),
|
|
126
|
+
},
|
|
127
|
+
// @FIXME: @yejianchao 后续根据文件计算出一个合理的超时时间
|
|
128
|
+
timeout: 5 * libs_1.MIN,
|
|
129
|
+
};
|
|
130
|
+
return config;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
await this.destroy();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// @ts-expect-error
|
|
137
|
+
destroy() {
|
|
138
|
+
if ((0, fs_extra_1.existsSync)(this.tempCacheObjectKey)) {
|
|
139
|
+
(0, fs_extra_1.removeSync)(this.tempCacheObjectKey);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.PutNftObjectCommand = PutNftObjectCommand;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { DeleteObjectCommandOutput, DeleteObjectCommandInput } from '../../meta';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
export declare class DeleteObjectCommand extends BaseCommand<DeleteObjectCommandInput, DeleteObjectCommandOutput> {
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any>>;
|
|
6
|
+
resolveMiddleware(res: AxiosResponse<DeleteObjectCommandOutput['data'], any>): Promise<DeleteObjectCommandOutput>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteObjectCommand = void 0;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
const core_1 = require("@did-space/core");
|
|
6
|
+
const base_1 = require("../base");
|
|
7
|
+
const security_1 = require("../../security");
|
|
8
|
+
class DeleteObjectCommand extends base_1.BaseCommand {
|
|
9
|
+
getAxiosRequestConfig() {
|
|
10
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey(this.input.key));
|
|
11
|
+
const method = 'DELETE';
|
|
12
|
+
const { headers } = (0, security_1.signRequest)({
|
|
13
|
+
url,
|
|
14
|
+
method,
|
|
15
|
+
data: {},
|
|
16
|
+
headers: {
|
|
17
|
+
[core_1.HEADERS.X_SIGNATURE_VERSION]: '2',
|
|
18
|
+
},
|
|
19
|
+
wallet: this.context.wallet,
|
|
20
|
+
delegation: this.context.delegation,
|
|
21
|
+
});
|
|
22
|
+
const axiosRequestConfig = {
|
|
23
|
+
url,
|
|
24
|
+
method,
|
|
25
|
+
headers,
|
|
26
|
+
};
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
return axiosRequestConfig;
|
|
29
|
+
}
|
|
30
|
+
resolveMiddleware(res) {
|
|
31
|
+
return Promise.resolve({
|
|
32
|
+
statusCode: res.status,
|
|
33
|
+
statusMessage: res.statusText,
|
|
34
|
+
data: undefined,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.DeleteObjectCommand = DeleteObjectCommand;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { GetObjectCommandInput, GetObjectCommandOutput } from '../../meta';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
export declare class GetObjectCommand extends BaseCommand<GetObjectCommandInput, GetObjectCommandOutput> {
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any>>;
|
|
6
|
+
resolveMiddleware(res: AxiosResponse<GetObjectCommandOutput['data'], any>): Promise<GetObjectCommandOutput>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetObjectCommand = void 0;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
const core_1 = require("@did-space/core");
|
|
6
|
+
const base_1 = require("../base");
|
|
7
|
+
const security_1 = require("../../security");
|
|
8
|
+
class GetObjectCommand extends base_1.BaseCommand {
|
|
9
|
+
getAxiosRequestConfig() {
|
|
10
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey(this.input.key));
|
|
11
|
+
const method = 'GET';
|
|
12
|
+
const { headers } = (0, security_1.signRequest)({
|
|
13
|
+
url,
|
|
14
|
+
method,
|
|
15
|
+
data: {},
|
|
16
|
+
headers: {
|
|
17
|
+
[core_1.HEADERS.X_SIGNATURE_VERSION]: '2',
|
|
18
|
+
},
|
|
19
|
+
wallet: this.context.wallet,
|
|
20
|
+
delegation: this.context.delegation,
|
|
21
|
+
});
|
|
22
|
+
const config = {
|
|
23
|
+
url,
|
|
24
|
+
method,
|
|
25
|
+
responseType: 'stream',
|
|
26
|
+
headers: {
|
|
27
|
+
'x-content-type': 'application/octet-stream',
|
|
28
|
+
...headers,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
resolveMiddleware(res) {
|
|
35
|
+
return Promise.resolve({
|
|
36
|
+
statusCode: res.status,
|
|
37
|
+
statusMessage: res.statusText,
|
|
38
|
+
headers: res.headers,
|
|
39
|
+
data: res.data,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.GetObjectCommand = GetObjectCommand;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./get-object"), exports);
|
|
18
|
+
__exportStar(require("./list-object"), exports);
|
|
19
|
+
__exportStar(require("./list-objects"), exports);
|
|
20
|
+
__exportStar(require("./put-object"), exports);
|
|
21
|
+
__exportStar(require("./delete-object"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Object } from '@did-space/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { ListObjectCommandInput, ListObjectCommandOutput } from '../../meta';
|
|
4
|
+
import { BaseCommand } from '../base';
|
|
5
|
+
export declare class ListObjectCommand extends BaseCommand<ListObjectCommandInput, ListObjectCommandOutput> {
|
|
6
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<Object>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ListObjectCommand = void 0;
|
|
4
|
+
const core_1 = require("@did-space/core");
|
|
5
|
+
const ufo_1 = require("ufo");
|
|
6
|
+
const base_1 = require("../base");
|
|
7
|
+
const security_1 = require("../../security");
|
|
8
|
+
class ListObjectCommand extends base_1.BaseCommand {
|
|
9
|
+
getAxiosRequestConfig() {
|
|
10
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'list', this.getKey(this.input.key));
|
|
11
|
+
const method = 'GET';
|
|
12
|
+
const { headers } = (0, security_1.signRequest)({
|
|
13
|
+
url,
|
|
14
|
+
method,
|
|
15
|
+
data: {},
|
|
16
|
+
headers: {
|
|
17
|
+
[core_1.HEADERS.X_SIGNATURE_VERSION]: '2',
|
|
18
|
+
},
|
|
19
|
+
wallet: this.context.wallet,
|
|
20
|
+
delegation: this.context.delegation,
|
|
21
|
+
});
|
|
22
|
+
const config = {
|
|
23
|
+
url,
|
|
24
|
+
method,
|
|
25
|
+
headers,
|
|
26
|
+
};
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ListObjectCommand = ListObjectCommand;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Object } from '@did-space/core';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { ListObjectsCommandInput, ListObjectsCommandOutput } from '../../meta';
|
|
4
|
+
import { BaseCommand } from '../base';
|
|
5
|
+
export declare class ListObjectsCommand extends BaseCommand<ListObjectsCommandInput, ListObjectsCommandOutput> {
|
|
6
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<Object>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ListObjectsCommand = void 0;
|
|
7
|
+
const core_1 = require("@did-space/core");
|
|
8
|
+
const ufo_1 = require("ufo");
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
11
|
+
const querystring_1 = __importDefault(require("querystring"));
|
|
12
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
13
|
+
const base_1 = require("../base");
|
|
14
|
+
const security_1 = require("../../security");
|
|
15
|
+
const { name, version } = require('../../../package.json');
|
|
16
|
+
const debug = (0, debug_1.default)(`${name}@${version}:list-objects`);
|
|
17
|
+
class ListObjectsCommand extends base_1.BaseCommand {
|
|
18
|
+
getAxiosRequestConfig() {
|
|
19
|
+
// TODO: 此处应该有 joi 校验
|
|
20
|
+
const options = (0, pick_1.default)(this.input, ['recursive', 'ignoreDirectories']);
|
|
21
|
+
const queryParams = (0, isEmpty_1.default)(options) ? '' : `?${querystring_1.default.stringify(options)}`;
|
|
22
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'lists', this.getKey(this.input.key), queryParams);
|
|
23
|
+
const method = 'GET';
|
|
24
|
+
debug('getAxiosRequestConfig.$url', url);
|
|
25
|
+
const { headers } = (0, security_1.signRequest)({
|
|
26
|
+
url,
|
|
27
|
+
method,
|
|
28
|
+
data: {},
|
|
29
|
+
headers: {
|
|
30
|
+
[core_1.HEADERS.X_SIGNATURE_VERSION]: '2',
|
|
31
|
+
},
|
|
32
|
+
wallet: this.context.wallet,
|
|
33
|
+
delegation: this.context.delegation,
|
|
34
|
+
});
|
|
35
|
+
const config = {
|
|
36
|
+
url,
|
|
37
|
+
method,
|
|
38
|
+
headers,
|
|
39
|
+
};
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
return config;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ListObjectsCommand = ListObjectsCommand;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { PutObjectCommandInput, PutObjectCommandOutput } from '../../meta';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
export declare class PutObjectCommand extends BaseCommand<PutObjectCommandInput, PutObjectCommandOutput> {
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any>>;
|
|
6
|
+
resolveMiddleware(): Promise<PutObjectCommandOutput>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PutObjectCommand = void 0;
|
|
7
|
+
const core_1 = require("@did-space/core");
|
|
8
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
9
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
10
|
+
const ufo_1 = require("ufo");
|
|
11
|
+
const libs_1 = require("../../libs");
|
|
12
|
+
const security_1 = require("../../security");
|
|
13
|
+
const base_1 = require("../base");
|
|
14
|
+
class PutObjectCommand extends base_1.BaseCommand {
|
|
15
|
+
// eslint-disable-next-line require-await
|
|
16
|
+
async getAxiosRequestConfig() {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
async resolveMiddleware() {
|
|
20
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey(this.input.key));
|
|
21
|
+
const method = 'PUT';
|
|
22
|
+
const body = new form_data_1.default();
|
|
23
|
+
if (!(0, isEmpty_1.default)(this.input.data)) {
|
|
24
|
+
// @see: https://stackoverflow.com/a/43914175
|
|
25
|
+
body.append('data', this.input.data, {
|
|
26
|
+
filename: this.input.key,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (!(0, isEmpty_1.default)(this.input.metadata)) {
|
|
30
|
+
body.append('metadata', JSON.stringify(this.input.metadata));
|
|
31
|
+
}
|
|
32
|
+
const { headers } = (0, security_1.signRequest)({
|
|
33
|
+
url,
|
|
34
|
+
method,
|
|
35
|
+
data: body,
|
|
36
|
+
headers: {
|
|
37
|
+
[core_1.HEADERS.X_SIGNATURE_VERSION]: '2',
|
|
38
|
+
},
|
|
39
|
+
wallet: this.context.wallet,
|
|
40
|
+
delegation: this.context.delegation,
|
|
41
|
+
});
|
|
42
|
+
const optionsOfTextResponseBody = {
|
|
43
|
+
method,
|
|
44
|
+
body,
|
|
45
|
+
headers: {
|
|
46
|
+
...headers,
|
|
47
|
+
'x-hash': this.input.hash,
|
|
48
|
+
'Content-Type': 'multipart/form-data',
|
|
49
|
+
...body.getHeaders(),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
// TODO: axios 会导致严重的内存泄漏, 之后可以考虑切换到 got, @see: https://github.com/axios/axios/issues/4763#issuecomment-1334953446
|
|
53
|
+
const response = await (0, libs_1.gotApi)(url, optionsOfTextResponseBody);
|
|
54
|
+
return {
|
|
55
|
+
statusCode: response.statusCode,
|
|
56
|
+
statusMessage: response.statusMessage,
|
|
57
|
+
data: undefined,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.PutObjectCommand = PutObjectCommand;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./post-app-restore"), exports);
|
|
18
|
+
__exportStar(require("./put-app-restore"), exports);
|
|
19
|
+
__exportStar(require("./restore-blocklet"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { PostAppRestoreCommandInput, PostAppRestoreCommandOutput } from '../../meta';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
export declare class PostAppRestoreCommand extends BaseCommand<PostAppRestoreCommandInput, PostAppRestoreCommandOutput> {
|
|
5
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any>>;
|
|
6
|
+
resolveMiddleware(): Promise<PostAppRestoreCommandOutput>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostAppRestoreCommand = void 0;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
const libs_1 = require("../../libs");
|
|
6
|
+
const meta_1 = require("../../meta");
|
|
7
|
+
const security_1 = require("../../security");
|
|
8
|
+
const base_1 = require("../base");
|
|
9
|
+
class PostAppRestoreCommand extends base_1.BaseCommand {
|
|
10
|
+
getAxiosRequestConfig() {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
async resolveMiddleware() {
|
|
14
|
+
const { error } = meta_1.PostAppRestoreCommandInputSchema.validate(this.input);
|
|
15
|
+
if (error) {
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'restore');
|
|
19
|
+
const data = this.input;
|
|
20
|
+
const method = 'POST';
|
|
21
|
+
const { headers } = (0, security_1.signRequest)({
|
|
22
|
+
url,
|
|
23
|
+
method,
|
|
24
|
+
data,
|
|
25
|
+
headers: {},
|
|
26
|
+
wallet: this.context.wallet,
|
|
27
|
+
delegation: this.context.delegation,
|
|
28
|
+
});
|
|
29
|
+
const response = await (0, libs_1.gotApi)({
|
|
30
|
+
url,
|
|
31
|
+
method,
|
|
32
|
+
json: data,
|
|
33
|
+
responseType: 'json',
|
|
34
|
+
headers: {
|
|
35
|
+
...headers,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
statusCode: response.statusCode,
|
|
40
|
+
statusMessage: response.statusMessage,
|
|
41
|
+
data: response.body,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.PostAppRestoreCommand = PostAppRestoreCommand;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { PutAppRestoreCommandInput, PutAppRestoreCommandOutput } from '../../meta';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
import type { SpaceClientOptions } from '../../protocol';
|
|
5
|
+
export declare class PutAppRestoreCommand extends BaseCommand<PutAppRestoreCommandInput, PutAppRestoreCommandOutput> {
|
|
6
|
+
constructor(input: PutAppRestoreCommandInput, context?: SpaceClientOptions);
|
|
7
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any>>;
|
|
8
|
+
resolveMiddleware(): Promise<PutAppRestoreCommandOutput>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PutAppRestoreCommand = void 0;
|
|
4
|
+
const ufo_1 = require("ufo");
|
|
5
|
+
const libs_1 = require("../../libs");
|
|
6
|
+
const meta_1 = require("../../meta");
|
|
7
|
+
const security_1 = require("../../security");
|
|
8
|
+
const base_1 = require("../base");
|
|
9
|
+
class PutAppRestoreCommand extends base_1.BaseCommand {
|
|
10
|
+
constructor(input, context) {
|
|
11
|
+
super(input, context);
|
|
12
|
+
const { error, value } = meta_1.PutAppRestoreCommandInputSchema.validate(input);
|
|
13
|
+
if (error) {
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
this.input = value;
|
|
17
|
+
}
|
|
18
|
+
getAxiosRequestConfig() {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
async resolveMiddleware() {
|
|
22
|
+
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'restore');
|
|
23
|
+
const data = this.input;
|
|
24
|
+
const method = 'PUT';
|
|
25
|
+
const { headers } = (0, security_1.signRequest)({
|
|
26
|
+
url,
|
|
27
|
+
method,
|
|
28
|
+
data,
|
|
29
|
+
headers: {},
|
|
30
|
+
wallet: this.context.wallet,
|
|
31
|
+
delegation: this.context.delegation,
|
|
32
|
+
});
|
|
33
|
+
const response = await (0, libs_1.gotApi)({
|
|
34
|
+
url,
|
|
35
|
+
method,
|
|
36
|
+
json: data,
|
|
37
|
+
responseType: 'json',
|
|
38
|
+
headers: {
|
|
39
|
+
...headers,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
statusCode: response.statusCode,
|
|
44
|
+
statusMessage: response.statusMessage,
|
|
45
|
+
data: response.body,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.PutAppRestoreCommand = PutAppRestoreCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { RestoreBlockletCommandInput, RestoreBlockletCommandOutput } from '../../meta';
|
|
3
|
+
import { BaseCommand } from '../base';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* FIXME: @yejianchao 优化点,需要支持 joi 校验
|
|
7
|
+
* @export
|
|
8
|
+
* @class RestoreBlockletCommand
|
|
9
|
+
* @extends {BaseCommand<RestoreBlockletCommandInput, RestoreBlockletCommandOutput>}
|
|
10
|
+
*/
|
|
11
|
+
export declare class RestoreBlockletCommand extends BaseCommand<RestoreBlockletCommandInput, RestoreBlockletCommandOutput> {
|
|
12
|
+
getAxiosRequestConfig(): Promise<AxiosRequestConfig<any>>;
|
|
13
|
+
resolveMiddleware(): Promise<RestoreBlockletCommandOutput>;
|
|
14
|
+
}
|