@secrecy/lib 1.64.0 → 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.
- package/dist/lib/client/SecrecyCloudClient.js +51 -15
- package/dist/lib/client/convert/node.js +1 -2
- package/dist/types/base-client.d.ts +1 -1
- package/dist/types/client/SecrecyCloudClient.d.ts +16 -2
- package/dist/types/client/types/node.d.ts +7 -7
- package/dist/types/client.d.ts +8245 -5883
- package/package.json +2 -2
|
@@ -305,10 +305,14 @@ export class SecrecyCloudClient {
|
|
|
305
305
|
const users = folder.parent?.users?.filter(([u]) => u.id !== this.#client.app.userId) ??
|
|
306
306
|
[];
|
|
307
307
|
if (users.length > 0) {
|
|
308
|
-
await this.shareNode(users.map(([user,
|
|
308
|
+
await this.shareNode(users.map(([user, permissions]) => ({
|
|
309
309
|
userId: user.id,
|
|
310
|
-
rights,
|
|
311
310
|
nodeId: folder.id,
|
|
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;
|
|
@@ -328,7 +332,7 @@ export class SecrecyCloudClient {
|
|
|
328
332
|
}
|
|
329
333
|
async shareNode(input, progress) {
|
|
330
334
|
// TODO: Validate input
|
|
331
|
-
const nodesMap = await this.#apiClient.cloud.shareNode.
|
|
335
|
+
const nodesMap = await this.#apiClient.cloud.shareNode.mutate(input);
|
|
332
336
|
const neededUserKey = Object.entries(nodesMap)
|
|
333
337
|
.filter(([, nodes]) => nodes.some((node) => node.includeKeys))
|
|
334
338
|
.map(([userId]) => userId);
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}));
|
|
@@ -385,21 +417,24 @@ export class SecrecyCloudClient {
|
|
|
385
417
|
return {
|
|
386
418
|
nodeId: node.nodeId,
|
|
387
419
|
userId: userId,
|
|
388
|
-
|
|
420
|
+
permissions: share.permissions,
|
|
389
421
|
};
|
|
390
422
|
}),
|
|
391
423
|
]));
|
|
392
424
|
const withKeys = Object.fromEntries(Object.entries(infos).map('rights' in input
|
|
393
425
|
? ([userId, nodes]) => [
|
|
394
426
|
userId,
|
|
395
|
-
{ userId, nodes,
|
|
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
432
|
throw new Error('Unable to retrieve rights!');
|
|
401
433
|
}
|
|
402
|
-
return [
|
|
434
|
+
return [
|
|
435
|
+
userId,
|
|
436
|
+
{ userId, nodes, permissions: share.permissions },
|
|
437
|
+
];
|
|
403
438
|
}));
|
|
404
439
|
const finishInput = [];
|
|
405
440
|
for (const [userId, nodes] of Object.entries(withKeys)) {
|
|
@@ -407,7 +442,7 @@ export class SecrecyCloudClient {
|
|
|
407
442
|
userId,
|
|
408
443
|
nodes: nodes.nodes.map((node) => ({
|
|
409
444
|
id: node.id,
|
|
410
|
-
|
|
445
|
+
...nodes.permissions,
|
|
411
446
|
nameKey: node.nameKey,
|
|
412
447
|
data: node.data.map((d) => ({
|
|
413
448
|
id: d.id,
|
|
@@ -422,8 +457,8 @@ export class SecrecyCloudClient {
|
|
|
422
457
|
nodes: [
|
|
423
458
|
{
|
|
424
459
|
id: node.nodeId,
|
|
425
|
-
rights: node.rights,
|
|
426
460
|
data: [],
|
|
461
|
+
...node.permissions,
|
|
427
462
|
},
|
|
428
463
|
],
|
|
429
464
|
})));
|
|
@@ -650,14 +685,15 @@ export class SecrecyCloudClient {
|
|
|
650
685
|
});
|
|
651
686
|
const node = await apiNodeToExternalNodeFull(saveInCloud, this.#keys);
|
|
652
687
|
const me = node.parent?.users.find(([u]) => u.id === this.#client.app.userId);
|
|
653
|
-
|
|
688
|
+
// TODO: Rights
|
|
689
|
+
if (me !== undefined && ['admin', 'write'].includes(me[1]['rights'])) {
|
|
654
690
|
const others = node.parent?.users.filter(([u]) => u.id !== this.#client.app.userId) ??
|
|
655
691
|
[];
|
|
656
692
|
if (others.length > 0) {
|
|
657
|
-
await this.shareNode(others.map(([user,
|
|
693
|
+
await this.shareNode(others.map(([user, permissions]) => ({
|
|
658
694
|
userId: user.id,
|
|
659
|
-
rights,
|
|
660
695
|
nodeId: node.id,
|
|
696
|
+
...permissions,
|
|
661
697
|
})));
|
|
662
698
|
}
|
|
663
699
|
}
|
|
@@ -11,7 +11,7 @@ async function apiNodeToInternal(apiNode, keyPair) {
|
|
|
11
11
|
name: apiNode.name,
|
|
12
12
|
isFavorite: apiNode.isFavorite,
|
|
13
13
|
breadcrumb: 'breadcrumb' in apiNode ? apiNode.breadcrumb : [],
|
|
14
|
-
|
|
14
|
+
owner: apiNode.owner,
|
|
15
15
|
sizes: 'sizes' in apiNode
|
|
16
16
|
? apiNode.sizes
|
|
17
17
|
: {
|
|
@@ -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)));
|
|
@@ -24,7 +24,7 @@ export declare class BaseClient {
|
|
|
24
24
|
static getUser(userId: string, opts?: CreateTrpcClientOptions): Promise<PublicUser>;
|
|
25
25
|
getUser(userId: string): Promise<PublicUser>;
|
|
26
26
|
searchUsers(search: string): Promise<PublicUser[]>;
|
|
27
|
-
updateProfile(data: RouterInputs['user']['updateProfile']): Promise<
|
|
27
|
+
updateProfile(data: RouterInputs['user']['updateProfile']): Promise<RouterOutputs['user']['updateProfile']>;
|
|
28
28
|
static isCryptoTransactionDone({ idOrHash, network, opts, }: {
|
|
29
29
|
idOrHash: string;
|
|
30
30
|
network?: InfuraNetwork;
|
|
@@ -132,9 +132,23 @@ export declare class SecrecyCloudClient {
|
|
|
132
132
|
}[];
|
|
133
133
|
invalidRightsAccesses: {
|
|
134
134
|
userId: string;
|
|
135
|
-
current:
|
|
135
|
+
current: {
|
|
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;
|
|
142
|
+
};
|
|
136
143
|
nodeId: string;
|
|
137
|
-
expect:
|
|
144
|
+
expect: {
|
|
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;
|
|
151
|
+
};
|
|
138
152
|
}[];
|
|
139
153
|
};
|
|
140
154
|
isMatching: false;
|
|
@@ -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
|
|
4
|
-
export type
|
|
5
|
-
|
|
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 & {
|
|
6
6
|
isRoot: boolean;
|
|
7
7
|
sharedByPubKey: string;
|
|
8
8
|
};
|
|
@@ -31,9 +31,9 @@ export interface Node<T extends NodeBreadcrumbItem = NodeBreadcrumbItem, U exten
|
|
|
31
31
|
sizes: NodeSize;
|
|
32
32
|
name: string;
|
|
33
33
|
breadcrumb: T[];
|
|
34
|
-
|
|
34
|
+
owner: PublicUser;
|
|
35
35
|
access: NodeAccess<U>;
|
|
36
|
-
users: Array<[PublicUser,
|
|
36
|
+
users: Array<[PublicUser, NodePermissions]>;
|
|
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:
|
|
85
|
+
current: NodePermissions;
|
|
86
86
|
nodeId: string;
|
|
87
|
-
expect:
|
|
87
|
+
expect: NodePermissions;
|
|
88
88
|
}[];
|
|
89
89
|
};
|
|
90
90
|
export {};
|