@secrecy/lib 1.62.0-feat-node-sharing.10 → 1.62.0-feat-node-sharing.11

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]) => !!key));
90
+ .filter(([_, key]) => key !== undefined));
88
91
  const missingKeys = [
89
92
  ...new Set(userIds.filter((userId) => publicKeys[userId] === undefined)),
90
93
  ];
@@ -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).map(([key, value]) => [
349
- key,
350
- value.filter((node) => node.includeKeys).map((node) => node.nodeId),
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,10 +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,
425
+ rights: node.rights,
422
426
  nameKey: null,
423
427
  data: [],
424
428
  },
@@ -664,11 +668,14 @@ export class SecrecyCloudClient {
664
668
  userPublicKeys) => {
665
669
  const userIds = Object.keys(userNodes).map((userId) => userId);
666
670
  const nodeIds = Object.values(userNodes).flatMap((nodeIds) => nodeIds);
671
+ if (nodeIds.length === 0) {
672
+ return {};
673
+ }
667
674
  const nodes = [];
668
675
  // Pre check to ensure we get all public keys for users!
669
676
  for (const userId of userIds) {
670
677
  if (userPublicKeys[userId] === undefined) {
671
- throw new Error(`Unable to retreive some user public keys!`);
678
+ throw new Error(`Unable to retrieve some user public keys!`);
672
679
  }
673
680
  }
674
681
  // Retreive and format nodes.
@@ -4144,25 +4144,25 @@ 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
4150
  key: string | null;
4152
4151
  }[];
4153
4152
  id: string;
4153
+ rights: "admin" | "write" | "read";
4154
4154
  nameKey: string | null;
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
4162
  key: string | null;
4164
4163
  }[];
4165
4164
  id: string;
4165
+ rights: "admin" | "write" | "read";
4166
4166
  nameKey: string | null;
4167
4167
  }[];
4168
4168
  }[];
@@ -5818,25 +5818,25 @@ 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
5824
  key: string | null;
5826
5825
  }[];
5827
5826
  id: string;
5827
+ rights: "admin" | "write" | "read";
5828
5828
  nameKey: string | null;
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
5836
  key: string | null;
5838
5837
  }[];
5839
5838
  id: string;
5839
+ rights: "admin" | "write" | "read";
5840
5840
  nameKey: string | null;
5841
5841
  }[];
5842
5842
  }[];
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.10",
5
+ "version": "1.62.0-feat-node-sharing.11",
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.20",
77
+ "@secrecy/trpc-api-types": "1.33.0-feat-share-node-enhanced.21",
78
78
  "@trpc/client": "10.45.2",
79
79
  "@trpc/server": "10.45.2",
80
80
  "@types/libsodium-wrappers-sumo": "^0.7.8",