@secrecy/lib 1.62.0-feat-node-sharing.10 → 1.62.0-feat-node-sharing.12
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.
|
@@ -79,12 +79,15 @@ export class SecrecyAppClient {
|
|
|
79
79
|
async userPublicKey(input, appId) {
|
|
80
80
|
appId ??= this.appId;
|
|
81
81
|
const userIds = Array.isArray(input) ? input : [input];
|
|
82
|
+
if (userIds.length === 0) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
82
85
|
const publicKeys = Object.fromEntries(userIds
|
|
83
86
|
.map((userId) => [
|
|
84
87
|
userId,
|
|
85
88
|
publicKeysCache.get(`userPublicKey:${userId}-${appId}`),
|
|
86
89
|
])
|
|
87
|
-
.filter(([_, key]) =>
|
|
90
|
+
.filter(([_, key]) => key !== undefined));
|
|
88
91
|
const missingKeys = [
|
|
89
92
|
...new Set(userIds.filter((userId) => publicKeys[userId] === undefined)),
|
|
90
93
|
];
|
|
@@ -38,7 +38,7 @@ export class SecrecyCloudClient {
|
|
|
38
38
|
const shares = users.map(([user]) => {
|
|
39
39
|
const publicKey = userKeys[user.id];
|
|
40
40
|
if (!publicKey) {
|
|
41
|
-
throw new Error('Unable to
|
|
41
|
+
throw new Error('Unable to retrieve share by public key!');
|
|
42
42
|
}
|
|
43
43
|
return {
|
|
44
44
|
id: user.id,
|
|
@@ -345,10 +345,14 @@ export class SecrecyCloudClient {
|
|
|
345
345
|
: [nodesMap];
|
|
346
346
|
const details = await chunks.reduce(async (pendingState, nodesMap, index) => {
|
|
347
347
|
const state = await pendingState;
|
|
348
|
-
const nodesToEncrypt = Object.fromEntries(Object.entries(nodesMap)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
348
|
+
const nodesToEncrypt = Object.fromEntries(Object.entries(nodesMap)
|
|
349
|
+
.map(([userId, value]) => {
|
|
350
|
+
const filtered = value
|
|
351
|
+
.filter((node) => node.includeKeys)
|
|
352
|
+
.map((node) => node.nodeId);
|
|
353
|
+
return filtered.length > 0 ? [userId, filtered] : null;
|
|
354
|
+
})
|
|
355
|
+
.filter((entry) => entry !== null));
|
|
352
356
|
const infos = await this.encryptNodesForUsers(nodesToEncrypt, publicKeysMap);
|
|
353
357
|
const shares = Array.isArray(input)
|
|
354
358
|
? input
|
|
@@ -401,9 +405,9 @@ export class SecrecyCloudClient {
|
|
|
401
405
|
for (const [userId, nodes] of Object.entries(withKeys)) {
|
|
402
406
|
finishInput.push({
|
|
403
407
|
userId,
|
|
404
|
-
rights: nodes.rights,
|
|
405
408
|
nodes: nodes.nodes.map((node) => ({
|
|
406
409
|
id: node.id,
|
|
410
|
+
rights: nodes.rights,
|
|
407
411
|
nameKey: node.nameKey,
|
|
408
412
|
data: node.data.map((d) => ({
|
|
409
413
|
id: d.id,
|
|
@@ -415,11 +419,10 @@ export class SecrecyCloudClient {
|
|
|
415
419
|
for (const [userId, nodes] of Object.entries(nodesToUpdateRights)) {
|
|
416
420
|
finishInput.push(...nodes.map((node) => ({
|
|
417
421
|
userId,
|
|
418
|
-
rights: node.rights,
|
|
419
422
|
nodes: [
|
|
420
423
|
{
|
|
421
424
|
id: node.nodeId,
|
|
422
|
-
|
|
425
|
+
rights: node.rights,
|
|
423
426
|
data: [],
|
|
424
427
|
},
|
|
425
428
|
],
|
|
@@ -664,14 +667,17 @@ export class SecrecyCloudClient {
|
|
|
664
667
|
userPublicKeys) => {
|
|
665
668
|
const userIds = Object.keys(userNodes).map((userId) => userId);
|
|
666
669
|
const nodeIds = Object.values(userNodes).flatMap((nodeIds) => nodeIds);
|
|
670
|
+
if (nodeIds.length === 0) {
|
|
671
|
+
return {};
|
|
672
|
+
}
|
|
667
673
|
const nodes = [];
|
|
668
674
|
// Pre check to ensure we get all public keys for users!
|
|
669
675
|
for (const userId of userIds) {
|
|
670
676
|
if (userPublicKeys[userId] === undefined) {
|
|
671
|
-
throw new Error(`Unable to
|
|
677
|
+
throw new Error(`Unable to retrieve some user public keys!`);
|
|
672
678
|
}
|
|
673
679
|
}
|
|
674
|
-
//
|
|
680
|
+
// Retrieve and format nodes.
|
|
675
681
|
for (const nodeId of nodeIds) {
|
|
676
682
|
let node;
|
|
677
683
|
node ??= nodesEncryptionCache.get(nodeId);
|
|
@@ -687,14 +693,14 @@ export class SecrecyCloudClient {
|
|
|
687
693
|
access: { nameKey: node.access.nameKey },
|
|
688
694
|
history: node.history.map((data) => {
|
|
689
695
|
if (!data.key) {
|
|
690
|
-
throw new Error('Unable to
|
|
696
|
+
throw new Error('Unable to retrieve data key!');
|
|
691
697
|
}
|
|
692
698
|
return { id: data.id, key: data.key };
|
|
693
699
|
}),
|
|
694
700
|
});
|
|
695
701
|
}
|
|
696
702
|
}
|
|
697
|
-
//
|
|
703
|
+
// Retrieve all missing nodes from cache to api.
|
|
698
704
|
const missingNodeIds = nodeIds.filter((nodeId) => !nodes.some((node) => node.id === nodeId));
|
|
699
705
|
const fetchedNodes = await this.#apiClient.cloud.nodesForEncryption.query({
|
|
700
706
|
ids: missingNodeIds,
|
|
@@ -713,7 +719,7 @@ export class SecrecyCloudClient {
|
|
|
713
719
|
for (const nodeId of userNodes[userId]) {
|
|
714
720
|
const node = nodes.find((node) => node.id === nodeId);
|
|
715
721
|
if (!node) {
|
|
716
|
-
throw new Error('Unable to
|
|
722
|
+
throw new Error('Unable to retrieve node from ram');
|
|
717
723
|
}
|
|
718
724
|
if (node.type === 'FILE' &&
|
|
719
725
|
(!('history' in node) || node.history.length === 0)) {
|
package/dist/types/client.d.ts
CHANGED
|
@@ -4144,26 +4144,26 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => {
|
|
|
4144
4144
|
_ctx_out: {};
|
|
4145
4145
|
_input_in: {
|
|
4146
4146
|
userId: string;
|
|
4147
|
-
rights: "admin" | "write" | "read";
|
|
4148
4147
|
nodes: {
|
|
4149
4148
|
data: {
|
|
4150
4149
|
id: string;
|
|
4151
|
-
key
|
|
4150
|
+
key?: string | null | undefined;
|
|
4152
4151
|
}[];
|
|
4153
4152
|
id: string;
|
|
4154
|
-
|
|
4153
|
+
rights: "admin" | "write" | "read";
|
|
4154
|
+
nameKey?: string | null | undefined;
|
|
4155
4155
|
}[];
|
|
4156
4156
|
}[];
|
|
4157
4157
|
_input_out: {
|
|
4158
4158
|
userId: string;
|
|
4159
|
-
rights: "admin" | "write" | "read";
|
|
4160
4159
|
nodes: {
|
|
4161
4160
|
data: {
|
|
4162
4161
|
id: string;
|
|
4163
|
-
key
|
|
4162
|
+
key?: string | null | undefined;
|
|
4164
4163
|
}[];
|
|
4165
4164
|
id: string;
|
|
4166
|
-
|
|
4165
|
+
rights: "admin" | "write" | "read";
|
|
4166
|
+
nameKey?: string | null | undefined;
|
|
4167
4167
|
}[];
|
|
4168
4168
|
}[];
|
|
4169
4169
|
_output_in: {
|
|
@@ -5818,26 +5818,26 @@ export declare const createTRPCClient: (opts: CreateTrpcClientOptions) => {
|
|
|
5818
5818
|
_ctx_out: {};
|
|
5819
5819
|
_input_in: {
|
|
5820
5820
|
userId: string;
|
|
5821
|
-
rights: "admin" | "write" | "read";
|
|
5822
5821
|
nodes: {
|
|
5823
5822
|
data: {
|
|
5824
5823
|
id: string;
|
|
5825
|
-
key
|
|
5824
|
+
key?: string | null | undefined;
|
|
5826
5825
|
}[];
|
|
5827
5826
|
id: string;
|
|
5828
|
-
|
|
5827
|
+
rights: "admin" | "write" | "read";
|
|
5828
|
+
nameKey?: string | null | undefined;
|
|
5829
5829
|
}[];
|
|
5830
5830
|
}[];
|
|
5831
5831
|
_input_out: {
|
|
5832
5832
|
userId: string;
|
|
5833
|
-
rights: "admin" | "write" | "read";
|
|
5834
5833
|
nodes: {
|
|
5835
5834
|
data: {
|
|
5836
5835
|
id: string;
|
|
5837
|
-
key
|
|
5836
|
+
key?: string | null | undefined;
|
|
5838
5837
|
}[];
|
|
5839
5838
|
id: string;
|
|
5840
|
-
|
|
5839
|
+
rights: "admin" | "write" | "read";
|
|
5840
|
+
nameKey?: string | null | undefined;
|
|
5841
5841
|
}[];
|
|
5842
5842
|
}[];
|
|
5843
5843
|
_output_in: {
|
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.62.0-feat-node-sharing.
|
|
5
|
+
"version": "1.62.0-feat-node-sharing.12",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/anonymize-org/lib.git"
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typescript": "^5.7.2"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@secrecy/trpc-api-types": "1.33.0-feat-share-node-enhanced.
|
|
77
|
+
"@secrecy/trpc-api-types": "1.33.0-feat-share-node-enhanced.23",
|
|
78
78
|
"@trpc/client": "10.45.2",
|
|
79
79
|
"@trpc/server": "10.45.2",
|
|
80
80
|
"@types/libsodium-wrappers-sumo": "^0.7.8",
|