@secrecy/lib 1.64.1 → 1.64.2-feat-share-up-to.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.
@@ -412,7 +412,7 @@ export class SecrecyCloudClient {
412
412
  .map((node) => {
413
413
  const share = shares.find((share) => share.nodeId === node.nodeId && share.userId === userId);
414
414
  if (!share) {
415
- throw new Error('Unable to retrieve rights!');
415
+ throw new Error('Unable to retrieve permissions!');
416
416
  }
417
417
  return {
418
418
  nodeId: node.nodeId,
@@ -424,12 +424,22 @@ export class SecrecyCloudClient {
424
424
  const withKeys = Object.fromEntries(Object.entries(infos).map('rights' in input
425
425
  ? ([userId, nodes]) => [
426
426
  userId,
427
- { userId, nodes, permissions: input },
427
+ {
428
+ userId,
429
+ nodes,
430
+ permissions: {
431
+ rights: input.rights,
432
+ addAccess: input.addAccess,
433
+ delAccess: input.delAccess,
434
+ sharingAddAccess: input.sharingAddAccess,
435
+ sharingDelAccess: input.sharingDelAccess,
436
+ },
437
+ },
428
438
  ]
429
439
  : ([userId, nodes]) => {
430
440
  const share = shares.find((share) => share.userId === userId && share.nodeId === nodes[0].id);
431
441
  if (!share) {
432
- throw new Error('Unable to retrieve rights!');
442
+ throw new Error('Unable to retrieve permissions!');
433
443
  }
434
444
  return [
435
445
  userId,
@@ -442,12 +452,12 @@ export class SecrecyCloudClient {
442
452
  userId,
443
453
  nodes: nodes.nodes.map((node) => ({
444
454
  id: node.id,
445
- ...nodes.permissions,
446
455
  nameKey: node.nameKey,
447
456
  data: node.data.map((d) => ({
448
457
  id: d.id,
449
458
  key: d.key,
450
459
  })),
460
+ ...nodes.permissions,
451
461
  })),
452
462
  });
453
463
  }
@@ -685,13 +695,14 @@ export class SecrecyCloudClient {
685
695
  });
686
696
  const node = await apiNodeToExternalNodeFull(saveInCloud, this.#keys);
687
697
  const me = node.parent?.users.find(([u]) => u.id === this.#client.app.userId);
688
- // TODO: Rights
689
- if (me !== undefined && ['admin', 'write'].includes(me[1]['rights'])) {
698
+ // TODO: ??
699
+ if (me !== undefined && ['delete', 'write'].includes(me[1].rights)) {
690
700
  const others = node.parent?.users.filter(([u]) => u.id !== this.#client.app.userId) ??
691
701
  [];
692
702
  if (others.length > 0) {
693
703
  await this.shareNode(others.map(([user, permissions]) => ({
694
704
  userId: user.id,
705
+ permissions,
695
706
  nodeId: node.id,
696
707
  ...permissions,
697
708
  })));
@@ -715,9 +726,7 @@ export class SecrecyCloudClient {
715
726
  }
716
727
  // Retrieve and format nodes.
717
728
  for (const nodeId of nodeIds) {
718
- let node;
719
- node ??= nodesEncryptionCache.get(nodeId);
720
- node ??= nodesCache.get(nodeId);
729
+ let node = nodesEncryptionCache.get(nodeId) ?? nodesCache.get(nodeId);
721
730
  if (node &&
722
731
  'history' in node &&
723
732
  node.history.length > 0 &&
@@ -66,8 +66,12 @@ function internalNodeToNode(internal) {
66
66
  })),
67
67
  access: {
68
68
  isRoot: internal.access.isRoot,
69
- rights: internal.access.rights,
70
69
  sharedByPubKey: internal.access.sharedByPubKey,
70
+ rights: internal.access.rights,
71
+ addAccess: internal.access.addAccess,
72
+ delAccess: internal.access.delAccess,
73
+ sharingAddAccess: internal.access.sharingAddAccess,
74
+ sharingDelAccess: internal.access.sharingDelAccess,
71
75
  },
72
76
  };
73
77
  return node;
@@ -133,21 +133,21 @@ export declare class SecrecyCloudClient {
133
133
  invalidRightsAccesses: {
134
134
  userId: string;
135
135
  current: {
136
- rights: "delete" | "read" | "write";
136
+ rights: "delete" | "write" | "read";
137
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;
138
+ addAccess?: "delete" | "write" | "read" | null | undefined;
139
+ sharingAddAccess?: "delete" | "write" | "read" | null | undefined;
140
+ delAccess?: "delete" | "write" | "read" | null | undefined;
141
+ sharingDelAccess?: "delete" | "write" | "read" | null | undefined;
142
142
  };
143
143
  nodeId: string;
144
144
  expect: {
145
- rights: "delete" | "read" | "write";
145
+ rights: "delete" | "write" | "read";
146
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;
147
+ addAccess?: "delete" | "write" | "read" | null | undefined;
148
+ sharingAddAccess?: "delete" | "write" | "read" | null | undefined;
149
+ delAccess?: "delete" | "write" | "read" | null | undefined;
150
+ sharingDelAccess?: "delete" | "write" | "read" | null | undefined;
151
151
  };
152
152
  }[];
153
153
  };
@@ -1,8 +1,8 @@
1
1
  import { type RouterOutputs } from '../../client.js';
2
2
  import type { DataMetadata, InternalData, PublicUser } from './index.js';
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 & {
3
+ export type Permissions = ApiNode['users'][number][1];
4
+ export type Rights = Permissions['rights'];
5
+ export type NodeAccess<T extends Record<string, unknown> = Record<string, unknown>> = T & Permissions & {
6
6
  isRoot: boolean;
7
7
  sharedByPubKey: string;
8
8
  };
@@ -33,7 +33,7 @@ export interface Node<T extends NodeBreadcrumbItem = NodeBreadcrumbItem, U exten
33
33
  breadcrumb: T[];
34
34
  owner: PublicUser;
35
35
  access: NodeAccess<U>;
36
- users: Array<[PublicUser, NodePermissions]>;
36
+ users: Array<[PublicUser, Permissions]>;
37
37
  currentDataId: string | null;
38
38
  parentId: string | null;
39
39
  }
@@ -82,9 +82,9 @@ export type ShareNodeDetails = {
82
82
  }[];
83
83
  invalidRightsAccesses: {
84
84
  userId: string;
85
- current: NodePermissions;
85
+ current: Permissions;
86
86
  nodeId: string;
87
- expect: NodePermissions;
87
+ expect: Permissions;
88
88
  }[];
89
89
  };
90
90
  export {};