@human-protocol/sdk 1.1.13 → 1.1.15

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/dist/storage.d.ts CHANGED
@@ -1,6 +1,50 @@
1
1
  import { UploadFile, StorageCredentials, StorageParams } from './types';
2
2
  /**
3
+ *
3
4
  * @deprecated StorageClient is deprecated. Use Minio.Client directly.
5
+ *
6
+ * ## Introduction
7
+ *
8
+ * This client enables to interact with S3 cloud storage services like Amazon S3 Bucket, Google Cloud Storage and others.
9
+ *
10
+ * The instance creation of `StorageClient` should be made using its constructor:
11
+ *
12
+ * ```ts
13
+ * constructor(params: StorageParams, credentials?: StorageCredentials)
14
+ * ```
15
+ *
16
+ * > If credentials is not provided, it uses an anonymous access to the bucket for downloading files.
17
+ *
18
+ * ## Installation
19
+ *
20
+ * ### npm
21
+ * ```bash
22
+ * npm install @human-protocol/sdk
23
+ * ```
24
+ *
25
+ * ### yarn
26
+ * ```bash
27
+ * yarn install @human-protocol/sdk
28
+ * ```
29
+ *
30
+ * ## Code example
31
+ *
32
+ * ```ts
33
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
34
+ *
35
+ * const credentials: StorageCredentials = {
36
+ * accessKey: 'ACCESS_KEY',
37
+ * secretKey: 'SECRET_KEY',
38
+ * };
39
+ * const params: StorageParams = {
40
+ * endPoint: 'http://localhost',
41
+ * port: 9000,
42
+ * useSSL: false,
43
+ * region: 'us-east-1'
44
+ * };
45
+ *
46
+ * const storageClient = new StorageClient(params, credentials);
47
+ * ```
4
48
  */
5
49
  export declare class StorageClient {
6
50
  private client;
@@ -13,39 +57,134 @@ export declare class StorageClient {
13
57
  */
14
58
  constructor(params: StorageParams, credentials?: StorageCredentials);
15
59
  /**
16
- * **Download files from cloud storage**
60
+ * This function downloads files from a bucket.
17
61
  *
18
- * @param {string} keys - Keys of files
19
- * @returns {Promise<File>} - Downloaded file
62
+ * @param {string[]} keys Array of filenames to download.
63
+ * @param {string} bucket Bucket name.
64
+ * @returns {any[]} Returns an array of json files downloaded and parsed into objects.
65
+ *
66
+ *
67
+ * **Code example**
68
+ *
69
+ * ```ts
70
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
71
+ *
72
+ * const params: StorageParams = {
73
+ * endPoint: 'http://localhost',
74
+ * port: 9000,
75
+ * useSSL: false,
76
+ * region: 'us-east-1'
77
+ * };
78
+ *
79
+ * const storageClient = new StorageClient(params);
80
+ *
81
+ * const keys = ['file1.json', 'file2.json'];
82
+ * const files = await storageClient.downloadFiles(keys, 'bucket-name');
83
+ * ```
20
84
  */
21
85
  downloadFiles(keys: string[], bucket: string): Promise<any[]>;
22
86
  /**
23
- * **Download files from cloud storage.*
87
+ * This function downloads files from a Url.
88
+ *
89
+ * @param {string} url Url of the file to download.
90
+ * @returns {any} Returns the JSON file downloaded and parsed into object.
24
91
  *
25
- * @param {string} url - URL to the file
26
- * @returns {Promise<File>} - Downloaded file
92
+ *
93
+ * **Code example**
94
+ *
95
+ * ```ts
96
+ * import { StorageClient } from '@human-protocol/sdk';
97
+ *
98
+ * const file = await storageClient.downloadFileFromUrl('http://localhost/file.json');
99
+ * ```
27
100
  */
28
101
  static downloadFileFromUrl(url: string): Promise<any>;
29
102
  /**
30
- * **Upload file to cloud storage**
103
+ * This function uploads files to a bucket.
104
+ *
105
+ * @param {any[]} files Array of objects to upload serialized into json.
106
+ * @param {string} bucket Bucket name.
107
+ * @returns {UploadFile[]} Returns an array of json files downloaded and parsed into objects.
108
+ *
109
+ *
110
+ * **Code example**
31
111
  *
32
- * @param {File[]} files - Files to upload
33
- * @param {string} bucket - Bucket name
34
- * @returns {Promise<UploadFile>} - Uploaded file with key/hash
112
+ * ```ts
113
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
114
+ *
115
+ * const credentials: StorageCredentials = {
116
+ * accessKey: 'ACCESS_KEY',
117
+ * secretKey: 'SECRET_KEY',
118
+ * };
119
+ * const params: StorageParams = {
120
+ * endPoint: 'http://localhost',
121
+ * port: 9000,
122
+ * useSSL: false,
123
+ * region: 'us-east-1'
124
+ * };
125
+ *
126
+ * const storageClient = new StorageClient(params, credentials);
127
+ * const file1 = { name: 'file1', description: 'description of file1' };
128
+ * const file2 = { name: 'file2', description: 'description of file2' };
129
+ * const files = [file1, file2];
130
+ * const uploadedFiles = await storageClient.uploadFiles(files, 'bucket-name');
131
+ * ```
35
132
  */
36
133
  uploadFiles(files: any[], bucket: string): Promise<UploadFile[]>;
37
134
  /**
38
- * **Checks if a bucket exists**
135
+ * This function checks if a bucket exists.
136
+ *
137
+ * @param {string} bucket Bucket name.
138
+ * @returns {boolean} Returns `true` if exists, `false` if it doesn't.
139
+ *
140
+ *
141
+ * **Code example**
142
+ *
143
+ * ```ts
144
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
39
145
  *
40
- * @param {string} bucket - Name of the bucket
41
- * @returns {Promise<boolean>} - True if bucket exists, false otherwise
146
+ * const credentials: StorageCredentials = {
147
+ * accessKey: 'ACCESS_KEY',
148
+ * secretKey: 'SECRET_KEY',
149
+ * };
150
+ * const params: StorageParams = {
151
+ * endPoint: 'http://localhost',
152
+ * port: 9000,
153
+ * useSSL: false,
154
+ * region: 'us-east-1'
155
+ * };
156
+ *
157
+ * const storageClient = new StorageClient(params, credentials);
158
+ * const exists = await storageClient.bucketExists('bucket-name');
159
+ * ```
42
160
  */
43
161
  bucketExists(bucket: string): Promise<boolean>;
44
162
  /**
45
- * **Checks if a bucket exists**
163
+ * This function list all file names contained in the bucket.
164
+ *
165
+ * @param {string} bucket Bucket name.
166
+ * @returns {boolean} Returns the list of file names contained in the bucket.
167
+ *
168
+ *
169
+ * **Code example**
170
+ *
171
+ * ```ts
172
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
173
+ *
174
+ * const credentials: StorageCredentials = {
175
+ * accessKey: 'ACCESS_KEY',
176
+ * secretKey: 'SECRET_KEY',
177
+ * };
178
+ * const params: StorageParams = {
179
+ * endPoint: 'http://localhost',
180
+ * port: 9000,
181
+ * useSSL: false,
182
+ * region: 'us-east-1'
183
+ * };
46
184
  *
47
- * @param {string} bucket - Name of the bucket
48
- * @returns {Promise<string[]>} - A list of filenames with their extensions in the bucket
185
+ * const storageClient = new StorageClient(params, credentials);
186
+ * const fileNames = await storageClient.listObjects('bucket-name');
187
+ * ```
49
188
  */
50
189
  listObjects(bucket: string): Promise<string[]>;
51
190
  }
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAgB;IAEpC;;;;;OAKG;gBACS,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,kBAAkB;IAcnE;;;;;OAKG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAoB1E;;;;;OAKG;WACiB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAsBlE;;;;;;OAMG;IACU,WAAW,CACtB,KAAK,EAAE,GAAG,EAAE,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC;IAkCxB;;;;;OAKG;IACU,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;OAKG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqB5D"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAgB;IAEpC;;;;;OAKG;gBACS,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,kBAAkB;IAcnE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAoB1E;;;;;;;;;;;;;;OAcG;WACiB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAsBlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,WAAW,CACtB,KAAK,EAAE,GAAG,EAAE,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC;IAkCxB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqB5D"}
package/dist/storage.js CHANGED
@@ -35,7 +35,51 @@ const error_1 = require("./error");
35
35
  const utils_1 = require("./utils");
36
36
  const constants_1 = require("./constants");
37
37
  /**
38
+ *
38
39
  * @deprecated StorageClient is deprecated. Use Minio.Client directly.
40
+ *
41
+ * ## Introduction
42
+ *
43
+ * This client enables to interact with S3 cloud storage services like Amazon S3 Bucket, Google Cloud Storage and others.
44
+ *
45
+ * The instance creation of `StorageClient` should be made using its constructor:
46
+ *
47
+ * ```ts
48
+ * constructor(params: StorageParams, credentials?: StorageCredentials)
49
+ * ```
50
+ *
51
+ * > If credentials is not provided, it uses an anonymous access to the bucket for downloading files.
52
+ *
53
+ * ## Installation
54
+ *
55
+ * ### npm
56
+ * ```bash
57
+ * npm install @human-protocol/sdk
58
+ * ```
59
+ *
60
+ * ### yarn
61
+ * ```bash
62
+ * yarn install @human-protocol/sdk
63
+ * ```
64
+ *
65
+ * ## Code example
66
+ *
67
+ * ```ts
68
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
69
+ *
70
+ * const credentials: StorageCredentials = {
71
+ * accessKey: 'ACCESS_KEY',
72
+ * secretKey: 'SECRET_KEY',
73
+ * };
74
+ * const params: StorageParams = {
75
+ * endPoint: 'http://localhost',
76
+ * port: 9000,
77
+ * useSSL: false,
78
+ * region: 'us-east-1'
79
+ * };
80
+ *
81
+ * const storageClient = new StorageClient(params, credentials);
82
+ * ```
39
83
  */
40
84
  class StorageClient {
41
85
  /**
@@ -58,10 +102,30 @@ class StorageClient {
58
102
  }
59
103
  }
60
104
  /**
61
- * **Download files from cloud storage**
105
+ * This function downloads files from a bucket.
62
106
  *
63
- * @param {string} keys - Keys of files
64
- * @returns {Promise<File>} - Downloaded file
107
+ * @param {string[]} keys Array of filenames to download.
108
+ * @param {string} bucket Bucket name.
109
+ * @returns {any[]} Returns an array of json files downloaded and parsed into objects.
110
+ *
111
+ *
112
+ * **Code example**
113
+ *
114
+ * ```ts
115
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
116
+ *
117
+ * const params: StorageParams = {
118
+ * endPoint: 'http://localhost',
119
+ * port: 9000,
120
+ * useSSL: false,
121
+ * region: 'us-east-1'
122
+ * };
123
+ *
124
+ * const storageClient = new StorageClient(params);
125
+ *
126
+ * const keys = ['file1.json', 'file2.json'];
127
+ * const files = await storageClient.downloadFiles(keys, 'bucket-name');
128
+ * ```
65
129
  */
66
130
  async downloadFiles(keys, bucket) {
67
131
  const isBucketExists = await this.client.bucketExists(bucket);
@@ -80,10 +144,19 @@ class StorageClient {
80
144
  }));
81
145
  }
82
146
  /**
83
- * **Download files from cloud storage.*
147
+ * This function downloads files from a Url.
148
+ *
149
+ * @param {string} url Url of the file to download.
150
+ * @returns {any} Returns the JSON file downloaded and parsed into object.
84
151
  *
85
- * @param {string} url - URL to the file
86
- * @returns {Promise<File>} - Downloaded file
152
+ *
153
+ * **Code example**
154
+ *
155
+ * ```ts
156
+ * import { StorageClient } from '@human-protocol/sdk';
157
+ *
158
+ * const file = await storageClient.downloadFileFromUrl('http://localhost/file.json');
159
+ * ```
87
160
  */
88
161
  static async downloadFileFromUrl(url) {
89
162
  if (!(0, utils_1.isValidUrl)(url)) {
@@ -105,11 +178,35 @@ class StorageClient {
105
178
  }
106
179
  }
107
180
  /**
108
- * **Upload file to cloud storage**
181
+ * This function uploads files to a bucket.
182
+ *
183
+ * @param {any[]} files Array of objects to upload serialized into json.
184
+ * @param {string} bucket Bucket name.
185
+ * @returns {UploadFile[]} Returns an array of json files downloaded and parsed into objects.
186
+ *
187
+ *
188
+ * **Code example**
109
189
  *
110
- * @param {File[]} files - Files to upload
111
- * @param {string} bucket - Bucket name
112
- * @returns {Promise<UploadFile>} - Uploaded file with key/hash
190
+ * ```ts
191
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
192
+ *
193
+ * const credentials: StorageCredentials = {
194
+ * accessKey: 'ACCESS_KEY',
195
+ * secretKey: 'SECRET_KEY',
196
+ * };
197
+ * const params: StorageParams = {
198
+ * endPoint: 'http://localhost',
199
+ * port: 9000,
200
+ * useSSL: false,
201
+ * region: 'us-east-1'
202
+ * };
203
+ *
204
+ * const storageClient = new StorageClient(params, credentials);
205
+ * const file1 = { name: 'file1', description: 'description of file1' };
206
+ * const file2 = { name: 'file2', description: 'description of file2' };
207
+ * const files = [file1, file2];
208
+ * const uploadedFiles = await storageClient.uploadFiles(files, 'bucket-name');
209
+ * ```
113
210
  */
114
211
  async uploadFiles(files, bucket) {
115
212
  const isBucketExists = await this.client.bucketExists(bucket);
@@ -136,19 +233,61 @@ class StorageClient {
136
233
  }));
137
234
  }
138
235
  /**
139
- * **Checks if a bucket exists**
236
+ * This function checks if a bucket exists.
237
+ *
238
+ * @param {string} bucket Bucket name.
239
+ * @returns {boolean} Returns `true` if exists, `false` if it doesn't.
240
+ *
241
+ *
242
+ * **Code example**
243
+ *
244
+ * ```ts
245
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
140
246
  *
141
- * @param {string} bucket - Name of the bucket
142
- * @returns {Promise<boolean>} - True if bucket exists, false otherwise
247
+ * const credentials: StorageCredentials = {
248
+ * accessKey: 'ACCESS_KEY',
249
+ * secretKey: 'SECRET_KEY',
250
+ * };
251
+ * const params: StorageParams = {
252
+ * endPoint: 'http://localhost',
253
+ * port: 9000,
254
+ * useSSL: false,
255
+ * region: 'us-east-1'
256
+ * };
257
+ *
258
+ * const storageClient = new StorageClient(params, credentials);
259
+ * const exists = await storageClient.bucketExists('bucket-name');
260
+ * ```
143
261
  */
144
262
  async bucketExists(bucket) {
145
263
  return this.client.bucketExists(bucket);
146
264
  }
147
265
  /**
148
- * **Checks if a bucket exists**
266
+ * This function list all file names contained in the bucket.
267
+ *
268
+ * @param {string} bucket Bucket name.
269
+ * @returns {boolean} Returns the list of file names contained in the bucket.
270
+ *
271
+ *
272
+ * **Code example**
273
+ *
274
+ * ```ts
275
+ * import { StorageClient, StorageCredentials, StorageParams } from '@human-protocol/sdk';
276
+ *
277
+ * const credentials: StorageCredentials = {
278
+ * accessKey: 'ACCESS_KEY',
279
+ * secretKey: 'SECRET_KEY',
280
+ * };
281
+ * const params: StorageParams = {
282
+ * endPoint: 'http://localhost',
283
+ * port: 9000,
284
+ * useSSL: false,
285
+ * region: 'us-east-1'
286
+ * };
149
287
  *
150
- * @param {string} bucket - Name of the bucket
151
- * @returns {Promise<string[]>} - A list of filenames with their extensions in the bucket
288
+ * const storageClient = new StorageClient(params, credentials);
289
+ * const fileNames = await storageClient.listObjects('bucket-name');
290
+ * ```
152
291
  */
153
292
  async listObjects(bucket) {
154
293
  const isBucketExists = await this.client.bucketExists(bucket);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "1.1.13",
4
+ "version": "1.1.15",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -10,8 +10,10 @@
10
10
  "types": "dist/index.d.ts",
11
11
  "scripts": {
12
12
  "clean": "rm -rf ./dist",
13
+ "clean:doc": "rm -rf ../../../../docs/sdk/typescript/",
13
14
  "prebuild": "yarn workspace @human-protocol/core build",
14
15
  "build": "npm run clean && tsc",
16
+ "build:doc": "npm run clean:doc && npx typedoc --plugin typedoc-plugin-markdown --out ../../../../docs/sdk/typescript/",
15
17
  "prepublish": "npm run build",
16
18
  "test": "vitest -u",
17
19
  "lint": "eslint .",
@@ -49,5 +51,19 @@
49
51
  "secp256k1": "^4.0.3",
50
52
  "vitest": "^0.30.1",
51
53
  "winston": "^3.8.2"
54
+ },
55
+ "devDependencies": {
56
+ "typedoc": "^0.25.1",
57
+ "typedoc-plugin-markdown": "^3.16.0"
58
+ },
59
+ "typedocOptions": {
60
+ "entryPoints": [
61
+ "./src/encryption.ts",
62
+ "./src/escrow.ts",
63
+ "./src/kvstore.ts",
64
+ "./src/staking.ts",
65
+ "./src/storage.ts",
66
+ "./src/statistics.ts"
67
+ ]
52
68
  }
53
69
  }