@secrecy/lib 1.65.0-feat-next15.3 → 1.65.0-feat-next15.4

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.
@@ -14,6 +14,7 @@ import { kiloToBytes } from '../utils.js';
14
14
  import { fileTypeFromBuffer } from 'file-type';
15
15
  import { encryptName, generateAndEncryptNameAndKey } from '../crypto/domain.js';
16
16
  import { chunkByTotalItems } from '../utils/object.js';
17
+ import axios from 'axios';
17
18
  export class SecrecyCloudClient {
18
19
  #client;
19
20
  #keys;
@@ -24,10 +25,7 @@ export class SecrecyCloudClient {
24
25
  this.#apiClient = apiClient;
25
26
  }
26
27
  async addDataToHistory({ dataId, nodeId, }) {
27
- const addDataToHistory = await this.#apiClient.cloud.addDataToHistory.mutate({
28
- dataId,
29
- nodeId,
30
- });
28
+ const addDataToHistory = await this.#apiClient.cloud.addDataToHistory.mutate({ dataId, nodeId });
31
29
  const node = await apiNodeFullToInternalFull(addDataToHistory, this.#keys);
32
30
  const data = node.history.find((d) => d.id === dataId);
33
31
  if (data !== undefined) {
@@ -73,10 +71,7 @@ export class SecrecyCloudClient {
73
71
  const dataKey = encrypted ? secretStreamKeygen() : null;
74
72
  const { data: encryptedData, md5: md5Data, md5Encrypted, } = dataKey
75
73
  ? await encrypt(dataKey, compressed, encryptProgress, signal)
76
- : {
77
- data: compressed,
78
- md5: await md5(compressed),
79
- };
74
+ : { data: compressed, md5: await md5(compressed) };
80
75
  const encryptedDataKey = dataKey
81
76
  ? encryptCryptoBox(dataKey, this.#keys.publicKey, this.#keys.privateKey)
82
77
  : null;
@@ -167,11 +162,7 @@ export class SecrecyCloudClient {
167
162
  return localData;
168
163
  }
169
164
  const uploadDataPartEnd = async (md5, order) => {
170
- return this.#apiClient.cloud.uploadDataPartEnd.mutate({
171
- dataId: uploadData.id,
172
- md5,
173
- order,
174
- }, { signal });
165
+ return this.#apiClient.cloud.uploadDataPartEnd.mutate({ dataId: uploadData.id, md5, order }, { signal });
175
166
  };
176
167
  const chunkParts = new Array();
177
168
  for (const [index, chunk] of enumerate(chunks(encryptedData, Number(uploadData.partSize)))) {
@@ -201,11 +192,14 @@ export class SecrecyCloudClient {
201
192
  formData.append(key, value);
202
193
  }
203
194
  formData.append('file', new Blob([chunk.data.slice(0)], { type: filetype?.mime }), `${uploadData.id}-${chunk.order}`);
204
- await ky.post(part.url, {
195
+ await axios.post(part.url, formData, {
205
196
  signal,
206
- body: formData,
207
197
  onUploadProgress: (progressEvent) => {
208
- onProgress(part.order, progressEvent);
198
+ onProgress(part.order, {
199
+ percent: progressEvent.progress ?? 0,
200
+ totalBytes: progressEvent.total ?? 0,
201
+ transferredBytes: progressEvent.loaded ?? 0,
202
+ });
209
203
  },
210
204
  });
211
205
  return uploadDataPartEnd(chunk.md5, chunk.order);
@@ -234,11 +228,7 @@ export class SecrecyCloudClient {
234
228
  uploadProgress,
235
229
  signal,
236
230
  });
237
- return await this.saveInCloud({
238
- dataId: uploadedData.id,
239
- name,
240
- nodeId,
241
- });
231
+ return await this.saveInCloud({ dataId: uploadedData.id, name, nodeId });
242
232
  }
243
233
  async deletedNodes() {
244
234
  const deletedNodes = await this.#apiClient.cloud.nodesDeleted.query({});
@@ -249,9 +239,7 @@ export class SecrecyCloudClient {
249
239
  return await Promise.all(nodesShared.map(async (node) => await apiNodeToExternal(node, this.#keys)));
250
240
  }
251
241
  async nodesSharedWithMe(type = 'FOLDER') {
252
- const nodesSharedWithMe = await this.#apiClient.cloud.nodesSharedWithMe.query({
253
- type,
254
- });
242
+ const nodesSharedWithMe = await this.#apiClient.cloud.nodesSharedWithMe.query({ type });
255
243
  return await Promise.all(nodesSharedWithMe.map(async (node) => await apiNodeToExternal(node, this.#keys)));
256
244
  }
257
245
  async deleteNodeSharing({ nodeId, userId, }) {
@@ -285,9 +273,7 @@ export class SecrecyCloudClient {
285
273
  return isDuplicated;
286
274
  }
287
275
  async deleteNodeCloudTrash({ ids }) {
288
- const { isDeleted } = await this.#apiClient.cloud.deleteNodeCloudTrash.mutate({
289
- ids,
290
- });
276
+ const { isDeleted } = await this.#apiClient.cloud.deleteNodeCloudTrash.mutate({ ids });
291
277
  return isDeleted;
292
278
  }
293
279
  async createFolder({ name, parentFolderId, }) {
@@ -318,16 +304,11 @@ export class SecrecyCloudClient {
318
304
  return folder;
319
305
  }
320
306
  async node({ id, deleted, } = {}) {
321
- const node = await this.#apiClient.cloud.nodeFullById.query({
322
- id,
323
- deleted,
324
- });
307
+ const node = await this.#apiClient.cloud.nodeFullById.query({ id, deleted });
325
308
  return await apiNodeToExternalNodeFull(node, this.#keys);
326
309
  }
327
310
  async dataMetadata({ id }) {
328
- const data = await this.#apiClient.cloud.dataById.query({
329
- id,
330
- });
311
+ const data = await this.#apiClient.cloud.dataById.query({ id });
331
312
  return apiDataToExternal(data, this.#keys);
332
313
  }
333
314
  async shareNode(input, progress) {
@@ -339,11 +320,7 @@ export class SecrecyCloudClient {
339
320
  const publicKeysMap = await this.#client.app.userPublicKey(neededUserKey);
340
321
  const maxNodesBatchSize = 1000;
341
322
  const totalNodesToShare = Object.values(nodesMap).reduce((size, ids) => size + ids.length, 0);
342
- progress?.({
343
- total: totalNodesToShare,
344
- current: 0,
345
- percent: 0,
346
- });
323
+ progress?.({ total: totalNodesToShare, current: 0, percent: 0 });
347
324
  const chunks = totalNodesToShare > maxNodesBatchSize
348
325
  ? chunkByTotalItems(nodesMap, maxNodesBatchSize)
349
326
  : [nodesMap];
@@ -444,23 +421,14 @@ export class SecrecyCloudClient {
444
421
  id: node.id,
445
422
  ...nodes.permissions,
446
423
  nameKey: node.nameKey,
447
- data: node.data.map((d) => ({
448
- id: d.id,
449
- key: d.key,
450
- })),
424
+ data: node.data.map((d) => ({ id: d.id, key: d.key })),
451
425
  })),
452
426
  });
453
427
  }
454
428
  for (const [userId, nodes] of Object.entries(nodesToUpdateRights)) {
455
429
  finishInput.push(...nodes.map((node) => ({
456
430
  userId,
457
- nodes: [
458
- {
459
- id: node.nodeId,
460
- data: [],
461
- ...node.permissions,
462
- },
463
- ],
431
+ nodes: [{ id: node.nodeId, data: [], ...node.permissions }],
464
432
  })));
465
433
  }
466
434
  const subState = await this.#apiClient.cloud.shareNodeFinish.mutate(finishInput);
@@ -498,10 +466,7 @@ export class SecrecyCloudClient {
498
466
  const errorDetailsLength = details.invalidRightsAccesses.length +
499
467
  details.missingDataAccesses.length +
500
468
  details.missingNodeAccesses.length;
501
- return {
502
- isFinished: errorDetailsLength === 0,
503
- details: details,
504
- };
469
+ return { isFinished: errorDetailsLength === 0, details: details };
505
470
  }
506
471
  async updateNode({ nodeId, name, isFavorite, deletedAt, }) {
507
472
  let node = nodesCache.get(nodeId);
@@ -584,9 +549,7 @@ export class SecrecyCloudClient {
584
549
  }));
585
550
  }
586
551
  async deleteNodes({ nodeIds, }) {
587
- return this.#apiClient.cloud.deleteNodes.mutate({
588
- ids: nodeIds,
589
- });
552
+ return this.#apiClient.cloud.deleteNodes.mutate({ ids: nodeIds });
590
553
  }
591
554
  async deleteData({ dataId, nodeId, }) {
592
555
  const { isDeleted } = await this.#apiClient.cloud.deleteData.mutate({
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@secrecy/lib",
3
3
  "author": "Anonymize <anonymize@gmail.com>",
4
4
  "description": "Anonymize Secrecy Library",
5
- "version": "1.65.0-feat-next15.3",
5
+ "version": "1.65.0-feat-next15.4",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/anonymize-org/lib.git"
@@ -79,6 +79,7 @@
79
79
  "@trpc/client": "11.5.0",
80
80
  "@trpc/server": "11.5.0",
81
81
  "@types/libsodium-wrappers-sumo": "^0.7.8",
82
+ "axios": "^1.11.0",
82
83
  "bson": "^6.10.4",
83
84
  "ethers": "^6.15.0",
84
85
  "file-type": "^21.0.0",