@secrecy/lib 1.64.1-feat-share-up-to.1 → 1.64.1

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.
@@ -308,7 +308,11 @@ export class SecrecyCloudClient {
308
308
  await this.shareNode(users.map(([user, permissions]) => ({
309
309
  userId: user.id,
310
310
  nodeId: folder.id,
311
- permissions,
311
+ rights: permissions.rights,
312
+ addAccess: permissions.addAccess,
313
+ delAccess: permissions.delAccess,
314
+ sharingAddAccess: permissions.sharingAddAccess,
315
+ sharingDelAccess: permissions.sharingDelAccess,
312
316
  })));
313
317
  }
314
318
  return folder;
@@ -355,21 +359,49 @@ export class SecrecyCloudClient {
355
359
  .filter((entry) => entry !== null));
356
360
  const infos = await this.encryptNodesForUsers(nodesToEncrypt, publicKeysMap);
357
361
  const shares = Array.isArray(input)
358
- ? input
362
+ ? input.map((opt) => ({
363
+ nodeId: opt.nodeId,
364
+ userId: opt.userId,
365
+ permissions: {
366
+ rights: opt.rights,
367
+ addAccess: opt.addAccess,
368
+ delAccess: opt.delAccess,
369
+ sharingAddAccess: opt.sharingAddAccess,
370
+ sharingDelAccess: opt.sharingDelAccess,
371
+ },
372
+ }))
359
373
  : 'userIds' in input
360
374
  ? 'nodeIds' in input
361
375
  ? input.userIds.flatMap((userId) => input.nodeIds.map((nodeId) => ({
362
- permissions: input.permissions,
376
+ permissions: {
377
+ rights: input.rights,
378
+ addAccess: input.addAccess,
379
+ delAccess: input.delAccess,
380
+ sharingAddAccess: input.sharingAddAccess,
381
+ sharingDelAccess: input.sharingDelAccess,
382
+ },
363
383
  userId,
364
384
  nodeId,
365
385
  })))
366
386
  : input.userIds.map((userId) => ({
367
- permissions: input.permissions,
387
+ permissions: {
388
+ rights: input.rights,
389
+ addAccess: input.addAccess,
390
+ delAccess: input.delAccess,
391
+ sharingAddAccess: input.sharingAddAccess,
392
+ sharingDelAccess: input.sharingDelAccess,
393
+ },
368
394
  userId,
369
395
  nodeId: input.nodeId,
370
396
  }))
371
397
  : input.nodeIds.map((nodeId) => ({
372
- permissions: input.permissions,
398
+ permissions: {
399
+ rights: input.rights,
400
+ addAccess: input.addAccess,
401
+ delAccess: input.delAccess,
402
+ sharingAddAccess: input.sharingAddAccess,
403
+ sharingDelAccess: input.sharingDelAccess,
404
+ },
373
405
  nodeId,
374
406
  userId: input.userId,
375
407
  }));
@@ -380,7 +412,7 @@ export class SecrecyCloudClient {
380
412
  .map((node) => {
381
413
  const share = shares.find((share) => share.nodeId === node.nodeId && share.userId === userId);
382
414
  if (!share) {
383
- throw new Error('Unable to retrieve permissions!');
415
+ throw new Error('Unable to retrieve rights!');
384
416
  }
385
417
  return {
386
418
  nodeId: node.nodeId,
@@ -389,15 +421,15 @@ export class SecrecyCloudClient {
389
421
  };
390
422
  }),
391
423
  ]));
392
- const withKeys = Object.fromEntries(Object.entries(infos).map('permissions' in input
424
+ const withKeys = Object.fromEntries(Object.entries(infos).map('rights' in input
393
425
  ? ([userId, nodes]) => [
394
426
  userId,
395
- { userId, nodes, permissions: input.permissions },
427
+ { userId, nodes, permissions: input },
396
428
  ]
397
429
  : ([userId, nodes]) => {
398
430
  const share = shares.find((share) => share.userId === userId && share.nodeId === nodes[0].id);
399
431
  if (!share) {
400
- throw new Error('Unable to retrieve permissions!');
432
+ throw new Error('Unable to retrieve rights!');
401
433
  }
402
434
  return [
403
435
  userId,
@@ -410,7 +442,7 @@ export class SecrecyCloudClient {
410
442
  userId,
411
443
  nodes: nodes.nodes.map((node) => ({
412
444
  id: node.id,
413
- permissions: nodes.permissions,
445
+ ...nodes.permissions,
414
446
  nameKey: node.nameKey,
415
447
  data: node.data.map((d) => ({
416
448
  id: d.id,
@@ -425,8 +457,8 @@ export class SecrecyCloudClient {
425
457
  nodes: [
426
458
  {
427
459
  id: node.nodeId,
428
- permissions: node.permissions,
429
460
  data: [],
461
+ ...node.permissions,
430
462
  },
431
463
  ],
432
464
  })));
@@ -653,15 +685,15 @@ export class SecrecyCloudClient {
653
685
  });
654
686
  const node = await apiNodeToExternalNodeFull(saveInCloud, this.#keys);
655
687
  const me = node.parent?.users.find(([u]) => u.id === this.#client.app.userId);
656
- // TODO: ??
657
- if (me !== undefined && ['delete', 'write'].includes(me[1].rights)) {
688
+ // TODO: Rights
689
+ if (me !== undefined && ['admin', 'write'].includes(me[1]['rights'])) {
658
690
  const others = node.parent?.users.filter(([u]) => u.id !== this.#client.app.userId) ??
659
691
  [];
660
692
  if (others.length > 0) {
661
693
  await this.shareNode(others.map(([user, permissions]) => ({
662
694
  userId: user.id,
663
- permissions,
664
695
  nodeId: node.id,
696
+ ...permissions,
665
697
  })));
666
698
  }
667
699
  }
@@ -25,7 +25,6 @@ async function apiNodeToInternal(apiNode, keyPair) {
25
25
  parentId: apiNode.parentId ?? null,
26
26
  currentDataId: apiNode.currentDataId ?? null,
27
27
  };
28
- internal.access = { ...apiNode.access };
29
28
  if (apiNode.access.nameKey !== null) {
30
29
  const key = decryptCryptoBox(sodium.from_hex(apiNode.access.nameKey), apiNode.access.sharedByPubKey, keyPair.privateKey);
31
30
  internal.name = sodium.to_string(await decryptSecretStream(key, sodium.from_hex(internal.name)));
@@ -67,8 +66,8 @@ function internalNodeToNode(internal) {
67
66
  })),
68
67
  access: {
69
68
  isRoot: internal.access.isRoot,
69
+ rights: internal.access.rights,
70
70
  sharedByPubKey: internal.access.sharedByPubKey,
71
- permissions: internal.access.permissions,
72
71
  },
73
72
  };
74
73
  return node;
@@ -133,19 +133,21 @@ export declare class SecrecyCloudClient {
133
133
  invalidRightsAccesses: {
134
134
  userId: string;
135
135
  current: {
136
- rights: "delete" | "write" | "read";
137
- addAccess: "delete" | "write" | "read" | null;
138
- sharingAddAccess: "delete" | "write" | "read" | null;
139
- delAccess: "delete" | "write" | "read" | null;
140
- sharingDelAccess: "delete" | "write" | "read" | null;
136
+ rights: "delete" | "read" | "write";
137
+ } & {
138
+ addAccess?: "delete" | "read" | "write" | null | undefined;
139
+ sharingAddAccess?: "delete" | "read" | "write" | null | undefined;
140
+ delAccess?: "delete" | "read" | "write" | null | undefined;
141
+ sharingDelAccess?: "delete" | "read" | "write" | null | undefined;
141
142
  };
142
143
  nodeId: string;
143
144
  expect: {
144
- rights: "delete" | "write" | "read";
145
- addAccess: "delete" | "write" | "read" | null;
146
- sharingAddAccess: "delete" | "write" | "read" | null;
147
- delAccess: "delete" | "write" | "read" | null;
148
- sharingDelAccess: "delete" | "write" | "read" | null;
145
+ rights: "delete" | "read" | "write";
146
+ } & {
147
+ addAccess?: "delete" | "read" | "write" | null | undefined;
148
+ sharingAddAccess?: "delete" | "read" | "write" | null | undefined;
149
+ delAccess?: "delete" | "read" | "write" | null | undefined;
150
+ sharingDelAccess?: "delete" | "read" | "write" | null | undefined;
149
151
  };
150
152
  }[];
151
153
  };
@@ -1,9 +1,8 @@
1
1
  import { type RouterOutputs } from '../../client.js';
2
2
  import type { DataMetadata, InternalData, PublicUser } from './index.js';
3
- export type NodeRights = ApiNode['users'][number][1];
4
- export type Permissions = Pick<ApiNode['access']['permissions'], 'rights'> & Partial<Omit<ApiNode['access']['permissions'], 'rights'>>;
5
- export type NodeAccess<T extends Record<string, unknown> = Record<string, unknown>> = T & {
6
- permissions: Permissions;
3
+ export type NodePermissions = ApiNode['users'][number][1];
4
+ export type Rights = NodePermissions['rights'];
5
+ export type NodeAccess<T extends Record<string, unknown> = Record<string, unknown>> = T & NodePermissions & {
7
6
  isRoot: boolean;
8
7
  sharedByPubKey: string;
9
8
  };
@@ -34,7 +33,7 @@ export interface Node<T extends NodeBreadcrumbItem = NodeBreadcrumbItem, U exten
34
33
  breadcrumb: T[];
35
34
  owner: PublicUser;
36
35
  access: NodeAccess<U>;
37
- users: Array<[PublicUser, NodeRights]>;
36
+ users: Array<[PublicUser, NodePermissions]>;
38
37
  currentDataId: string | null;
39
38
  parentId: string | null;
40
39
  }
@@ -83,9 +82,9 @@ export type ShareNodeDetails = {
83
82
  }[];
84
83
  invalidRightsAccesses: {
85
84
  userId: string;
86
- current: NodeRights;
85
+ current: NodePermissions;
87
86
  nodeId: string;
88
- expect: NodeRights;
87
+ expect: NodePermissions;
89
88
  }[];
90
89
  };
91
90
  export {};