@secrecy/lib 1.74.6 → 1.75.0-feat-groups-identity.2

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.
Files changed (54) hide show
  1. package/dist/lib/base-client.js +26 -2
  2. package/dist/lib/client/SecrecyAppClient.js +14 -18
  3. package/dist/lib/client/SecrecyCloudClient.js +130 -135
  4. package/dist/lib/client/SecrecyDbClient.js +1 -8
  5. package/dist/lib/client/SecrecyMailClient.js +38 -48
  6. package/dist/lib/client/SecrecyOrganizationClient.js +10 -12
  7. package/dist/lib/client/SecrecyPayClient.js +1 -5
  8. package/dist/lib/client/SecrecyPseudonymClient.js +4 -8
  9. package/dist/lib/client/SecrecyUserClient.js +11 -11
  10. package/dist/lib/client/SecrecyWalletClient.js +0 -2
  11. package/dist/lib/client/convert/data.js +8 -4
  12. package/dist/lib/client/convert/mail.js +8 -6
  13. package/dist/lib/client/convert/node.js +59 -34
  14. package/dist/lib/client/data-link.js +4 -1
  15. package/dist/lib/client/helpers.js +17 -7
  16. package/dist/lib/client/index.js +48 -12
  17. package/dist/lib/client/storage.js +3 -2
  18. package/dist/lib/client/types/identity.js +19 -0
  19. package/dist/lib/client/types/index.js +3 -7
  20. package/dist/lib/client/upload.js +20 -17
  21. package/dist/lib/crypto/data.js +4 -4
  22. package/dist/lib/crypto/domain.js +10 -10
  23. package/dist/lib/index.js +1 -0
  24. package/dist/lib/minify/lz4.js +1 -0
  25. package/dist/lib/utils/links.js +5 -5
  26. package/dist/lib/utils.js +1 -1
  27. package/dist/lib/worker/sodium.js +2 -2
  28. package/dist/types/base-client.d.ts +3 -1
  29. package/dist/types/client/SecrecyAppClient.d.ts +2 -3
  30. package/dist/types/client/SecrecyCloudClient.d.ts +19 -19
  31. package/dist/types/client/SecrecyDbClient.d.ts +1 -4
  32. package/dist/types/client/SecrecyMailClient.d.ts +2 -3
  33. package/dist/types/client/SecrecyOrganizationClient.d.ts +2 -3
  34. package/dist/types/client/SecrecyPayClient.d.ts +1 -3
  35. package/dist/types/client/SecrecyPseudonymClient.d.ts +2 -3
  36. package/dist/types/client/SecrecyUserClient.d.ts +2 -3
  37. package/dist/types/client/convert/data.d.ts +3 -3
  38. package/dist/types/client/convert/mail.d.ts +3 -5
  39. package/dist/types/client/convert/node.d.ts +5 -5
  40. package/dist/types/client/data-link.d.ts +2 -2
  41. package/dist/types/client/index.d.ts +11 -3
  42. package/dist/types/client/storage.d.ts +3 -2
  43. package/dist/types/client/types/identity.d.ts +37 -0
  44. package/dist/types/client/types/index.d.ts +17 -9
  45. package/dist/types/client/types/mail.d.ts +2 -1
  46. package/dist/types/client/types/node.d.ts +12 -9
  47. package/dist/types/client/types/user.d.ts +15 -0
  48. package/dist/types/client/upload.d.ts +8 -7
  49. package/dist/types/client.d.ts +1438 -1050
  50. package/dist/types/crypto/data.d.ts +2 -2
  51. package/dist/types/crypto/domain.d.ts +6 -4
  52. package/dist/types/crypto/index.d.ts +3 -3
  53. package/dist/types/index.d.ts +2 -1
  54. package/package.json +21 -21
@@ -13,6 +13,20 @@ async function getPublicUser(client, id) {
13
13
  usersCache.set(user.id, user);
14
14
  return user;
15
15
  }
16
+ async function getPublicUsers(client, ids) {
17
+ let users = ids
18
+ .map((id) => usersCache.get(id))
19
+ .filter((u) => u !== undefined);
20
+ const missingIds = ids.filter((id) => !usersCache.has(id));
21
+ if (missingIds.length > 0) {
22
+ const fetchedUsers = await client.user.byIds.query({
23
+ ids: missingIds,
24
+ });
25
+ fetchedUsers.forEach((user) => usersCache.set(user.id, user));
26
+ users = users.concat(fetchedUsers);
27
+ }
28
+ return users;
29
+ }
16
30
  export class BaseClient {
17
31
  static getBaseClient = (opts = {}) => createTRPCClient(opts);
18
32
  client;
@@ -76,6 +90,14 @@ export class BaseClient {
76
90
  const user = await getPublicUser(this.client, userId);
77
91
  return user;
78
92
  }
93
+ static async getUsers(userIds, opts) {
94
+ const users = await getPublicUsers(this.getBaseClient(opts), userIds);
95
+ return users;
96
+ }
97
+ async getUsers(userIds) {
98
+ const users = await getPublicUsers(this.client, userIds);
99
+ return users;
100
+ }
79
101
  async searchUsers(search) {
80
102
  const users = await this.client.user.searchMany.query({
81
103
  search,
@@ -112,10 +134,12 @@ export class BaseClient {
112
134
  const local = getStorage(false);
113
135
  const session = getStorage(true);
114
136
  local.jwt.clear();
115
- local.userAppKeys.clear();
137
+ local.identities.clear();
138
+ local.keyPairs.clear();
116
139
  local.userAppSession.clear();
117
140
  session.jwt.clear();
118
- session.userAppKeys.clear();
141
+ session.identities.clear();
142
+ session.keyPairs.clear();
119
143
  session.userAppSession.clear();
120
144
  usersCache.clear();
121
145
  };
@@ -4,15 +4,11 @@ import { publicKeysCache } from '../cache.js';
4
4
  export class SecrecyAppClient {
5
5
  jwt;
6
6
  jwtDecoded;
7
- // #client: SecrecyClient
8
- // #keys: KeyPair;
9
- #apiClient;
10
- constructor(uaJwt, _client, _keys, apiClient) {
7
+ #client;
8
+ constructor(uaJwt, client) {
11
9
  this.jwt = uaJwt;
12
10
  this.jwtDecoded = decode(uaJwt);
13
- // this.#client = client
14
- // this.#keys = keys;
15
- this.#apiClient = apiClient;
11
+ this.#client = client;
16
12
  }
17
13
  get userId() {
18
14
  const sub = this.jwtDecoded.sub;
@@ -35,8 +31,8 @@ export class SecrecyAppClient {
35
31
  // if (this.jwtDecoded.exp && this.jwtDecoded.exp * 1000 < Date.now()) {
36
32
  // return this.jwt;
37
33
  // }
38
- const { jwt } = await this.#apiClient.auth.jwt.query({
39
- includeEmail: typeof this.jwtDecoded.email === 'string',
34
+ const { jwt } = await this.#client.apiClient.auth.jwt.query({
35
+ includeEmail: typeof this.jwtDecoded['email'] === 'string',
40
36
  });
41
37
  this.jwt = jwt;
42
38
  this.jwtDecoded = decode(jwt);
@@ -53,19 +49,19 @@ export class SecrecyAppClient {
53
49
  return jwt;
54
50
  }
55
51
  async limits() {
56
- return await this.#apiClient.application.limits.query({});
52
+ return await this.#client.apiClient.application.limits.query({});
57
53
  }
58
54
  async metrics() {
59
- return await this.#apiClient.application.metrics.query({});
55
+ return await this.#client.apiClient.application.metrics.query({});
60
56
  }
61
57
  async quotas() {
62
- return await this.#apiClient.application.quotas.query({});
58
+ return await this.#client.apiClient.application.quotas.query({});
63
59
  }
64
60
  async isApplicationUser(input) {
65
- return await this.#apiClient.application.isApplicationUser.query(input);
61
+ return await this.#client.apiClient.application.isApplicationUser.query(input);
66
62
  }
67
63
  async updateNotifications(notifications) {
68
- const updateAppNotifications = await this.#apiClient.application.updateNotification.mutate({
64
+ const updateAppNotifications = await this.#client.apiClient.application.updateNotification.mutate({
69
65
  cloud: notifications.cloud,
70
66
  disableAllUntil: notifications.disableAllUntil,
71
67
  enableAll: notifications.enableAll,
@@ -74,7 +70,7 @@ export class SecrecyAppClient {
74
70
  return updateAppNotifications;
75
71
  }
76
72
  async notifications() {
77
- return await this.#apiClient.application.notification.query();
73
+ return await this.#client.apiClient.application.notification.query();
78
74
  }
79
75
  async userPublicKey(input, appId) {
80
76
  appId ??= this.appId;
@@ -92,7 +88,7 @@ export class SecrecyAppClient {
92
88
  ...new Set(userIds.filter((userId) => publicKeys[userId] === undefined)),
93
89
  ];
94
90
  if (missingKeys.length > 0) {
95
- const userKeysMap = await this.#apiClient.application.userPublicKey.query({
91
+ const userKeysMap = await this.#client.apiClient.application.userPublicKey.query({
96
92
  userIds: missingKeys,
97
93
  appId,
98
94
  });
@@ -113,11 +109,11 @@ export class SecrecyAppClient {
113
109
  return Array.isArray(input) ? publicKeys : publicKeys[input];
114
110
  }
115
111
  async settings() {
116
- const settings = await this.#apiClient.application.settings.query({});
112
+ const settings = await this.#client.apiClient.application.settings.query({});
117
113
  return settings;
118
114
  }
119
115
  async updateSettings(settings) {
120
- const updateAppSettings = await this.#apiClient.application.updateSettings.mutate({
116
+ const updateAppSettings = await this.#client.apiClient.application.updateSettings.mutate({
121
117
  cloudNodeDaysForDelete: settings.cloudNodeDaysForDelete,
122
118
  historyDataDaysForDelete: settings.historyDataDaysForDelete,
123
119
  historyDataMaxCount: settings.historyDataMaxCount,