@protontech/drive-sdk 0.0.13 → 0.1.0

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 (234) hide show
  1. package/dist/cache/index.d.ts +1 -0
  2. package/dist/cache/index.js +3 -1
  3. package/dist/cache/index.js.map +1 -1
  4. package/dist/cache/memoryCache.d.ts +1 -1
  5. package/dist/cache/nullCache.d.ts +14 -0
  6. package/dist/cache/nullCache.js +37 -0
  7. package/dist/cache/nullCache.js.map +1 -0
  8. package/dist/config.d.ts +16 -1
  9. package/dist/config.js +1 -1
  10. package/dist/config.js.map +1 -1
  11. package/dist/crypto/openPGPCrypto.js +2 -0
  12. package/dist/crypto/openPGPCrypto.js.map +1 -1
  13. package/dist/diagnostic/eventsGenerator.d.ts +14 -0
  14. package/dist/diagnostic/eventsGenerator.js +49 -0
  15. package/dist/diagnostic/eventsGenerator.js.map +1 -0
  16. package/dist/diagnostic/httpClient.d.ts +16 -0
  17. package/dist/diagnostic/httpClient.js +81 -0
  18. package/dist/diagnostic/httpClient.js.map +1 -0
  19. package/dist/diagnostic/index.d.ts +10 -0
  20. package/dist/diagnostic/index.js +35 -0
  21. package/dist/diagnostic/index.js.map +1 -0
  22. package/dist/diagnostic/integrityVerificationStream.d.ts +21 -0
  23. package/dist/diagnostic/integrityVerificationStream.js +56 -0
  24. package/dist/diagnostic/integrityVerificationStream.js.map +1 -0
  25. package/dist/diagnostic/interface.d.ts +102 -0
  26. package/dist/diagnostic/interface.js +3 -0
  27. package/dist/diagnostic/interface.js.map +1 -0
  28. package/dist/diagnostic/sdkDiagnostic.d.ts +22 -0
  29. package/dist/diagnostic/sdkDiagnostic.js +216 -0
  30. package/dist/diagnostic/sdkDiagnostic.js.map +1 -0
  31. package/dist/diagnostic/sdkDiagnosticFull.d.ts +18 -0
  32. package/dist/diagnostic/sdkDiagnosticFull.js +35 -0
  33. package/dist/diagnostic/sdkDiagnosticFull.js.map +1 -0
  34. package/dist/diagnostic/telemetry.d.ts +25 -0
  35. package/dist/diagnostic/telemetry.js +70 -0
  36. package/dist/diagnostic/telemetry.js.map +1 -0
  37. package/dist/diagnostic/zipGenerators.d.ts +9 -0
  38. package/dist/diagnostic/zipGenerators.js +64 -0
  39. package/dist/diagnostic/zipGenerators.js.map +1 -0
  40. package/dist/diagnostic/zipGenerators.test.js +144 -0
  41. package/dist/diagnostic/zipGenerators.test.js.map +1 -0
  42. package/dist/errors.d.ts +2 -1
  43. package/dist/errors.js +3 -1
  44. package/dist/errors.js.map +1 -1
  45. package/dist/interface/config.d.ts +26 -0
  46. package/dist/interface/config.js +3 -0
  47. package/dist/interface/config.js.map +1 -0
  48. package/dist/interface/download.d.ts +2 -2
  49. package/dist/interface/events.d.ts +60 -20
  50. package/dist/interface/events.js +11 -1
  51. package/dist/interface/events.js.map +1 -1
  52. package/dist/interface/httpClient.d.ts +0 -14
  53. package/dist/interface/index.d.ts +8 -4
  54. package/dist/interface/index.js +2 -1
  55. package/dist/interface/index.js.map +1 -1
  56. package/dist/interface/nodes.d.ts +9 -0
  57. package/dist/interface/nodes.js.map +1 -1
  58. package/dist/interface/sharing.d.ts +1 -0
  59. package/dist/interface/upload.d.ts +6 -0
  60. package/dist/internal/download/apiService.js +32 -31
  61. package/dist/internal/download/apiService.js.map +1 -1
  62. package/dist/internal/download/fileDownloader.d.ts +2 -2
  63. package/dist/internal/download/fileDownloader.js.map +1 -1
  64. package/dist/internal/events/apiService.d.ts +4 -6
  65. package/dist/internal/events/apiService.js +15 -22
  66. package/dist/internal/events/apiService.js.map +1 -1
  67. package/dist/internal/events/coreEventManager.d.ts +7 -10
  68. package/dist/internal/events/coreEventManager.js +19 -36
  69. package/dist/internal/events/coreEventManager.js.map +1 -1
  70. package/dist/internal/events/coreEventManager.test.js +87 -0
  71. package/dist/internal/events/coreEventManager.test.js.map +1 -0
  72. package/dist/internal/events/eventManager.d.ts +11 -36
  73. package/dist/internal/events/eventManager.js +59 -105
  74. package/dist/internal/events/eventManager.js.map +1 -1
  75. package/dist/internal/events/eventManager.test.js +167 -82
  76. package/dist/internal/events/eventManager.test.js.map +1 -1
  77. package/dist/internal/events/index.d.ts +13 -33
  78. package/dist/internal/events/index.js +56 -72
  79. package/dist/internal/events/index.js.map +1 -1
  80. package/dist/internal/events/interface.d.ts +59 -14
  81. package/dist/internal/events/interface.js +13 -3
  82. package/dist/internal/events/interface.js.map +1 -1
  83. package/dist/internal/events/volumeEventManager.d.ts +7 -17
  84. package/dist/internal/events/volumeEventManager.js +58 -45
  85. package/dist/internal/events/volumeEventManager.js.map +1 -1
  86. package/dist/internal/events/volumeEventManager.test.d.ts +1 -0
  87. package/dist/internal/events/volumeEventManager.test.js +203 -0
  88. package/dist/internal/events/volumeEventManager.test.js.map +1 -0
  89. package/dist/internal/nodes/cache.d.ts +10 -1
  90. package/dist/internal/nodes/cache.js +17 -0
  91. package/dist/internal/nodes/cache.js.map +1 -1
  92. package/dist/internal/nodes/cryptoService.d.ts +1 -1
  93. package/dist/internal/nodes/cryptoService.js.map +1 -1
  94. package/dist/internal/nodes/events.d.ts +7 -83
  95. package/dist/internal/nodes/events.js +43 -217
  96. package/dist/internal/nodes/events.js.map +1 -1
  97. package/dist/internal/nodes/events.test.js +27 -277
  98. package/dist/internal/nodes/events.test.js.map +1 -1
  99. package/dist/internal/nodes/index.d.ts +3 -4
  100. package/dist/internal/nodes/index.js +5 -5
  101. package/dist/internal/nodes/index.js.map +1 -1
  102. package/dist/internal/nodes/nodesAccess.d.ts +15 -0
  103. package/dist/internal/nodes/nodesAccess.js +37 -0
  104. package/dist/internal/nodes/nodesAccess.js.map +1 -1
  105. package/dist/internal/nodes/nodesAccess.test.js +131 -93
  106. package/dist/internal/nodes/nodesAccess.test.js.map +1 -1
  107. package/dist/internal/nodes/nodesManagement.d.ts +1 -3
  108. package/dist/internal/nodes/nodesManagement.js +12 -26
  109. package/dist/internal/nodes/nodesManagement.js.map +1 -1
  110. package/dist/internal/nodes/nodesManagement.test.js +35 -14
  111. package/dist/internal/nodes/nodesManagement.test.js.map +1 -1
  112. package/dist/internal/shares/cache.d.ts +2 -0
  113. package/dist/internal/shares/cache.js +2 -0
  114. package/dist/internal/shares/cache.js.map +1 -1
  115. package/dist/internal/shares/manager.d.ts +1 -0
  116. package/dist/internal/shares/manager.js +3 -0
  117. package/dist/internal/shares/manager.js.map +1 -1
  118. package/dist/internal/sharing/apiService.js +1 -0
  119. package/dist/internal/sharing/apiService.js.map +1 -1
  120. package/dist/internal/sharing/cryptoService.js +1 -0
  121. package/dist/internal/sharing/cryptoService.js.map +1 -1
  122. package/dist/internal/sharing/events.d.ts +23 -55
  123. package/dist/internal/sharing/events.js +46 -138
  124. package/dist/internal/sharing/events.js.map +1 -1
  125. package/dist/internal/sharing/events.test.js +77 -180
  126. package/dist/internal/sharing/events.test.js.map +1 -1
  127. package/dist/internal/sharing/index.d.ts +4 -5
  128. package/dist/internal/sharing/index.js +5 -5
  129. package/dist/internal/sharing/index.js.map +1 -1
  130. package/dist/internal/sharing/interface.d.ts +3 -0
  131. package/dist/internal/sharing/sharingManagement.d.ts +2 -3
  132. package/dist/internal/sharing/sharingManagement.js +7 -9
  133. package/dist/internal/sharing/sharingManagement.js.map +1 -1
  134. package/dist/internal/sharing/sharingManagement.test.js +9 -39
  135. package/dist/internal/sharing/sharingManagement.test.js.map +1 -1
  136. package/dist/internal/upload/apiService.d.ts +2 -3
  137. package/dist/internal/upload/apiService.js +7 -4
  138. package/dist/internal/upload/apiService.js.map +1 -1
  139. package/dist/internal/upload/index.d.ts +2 -2
  140. package/dist/internal/upload/index.js +3 -3
  141. package/dist/internal/upload/index.js.map +1 -1
  142. package/dist/internal/upload/interface.d.ts +2 -0
  143. package/dist/internal/upload/manager.d.ts +5 -5
  144. package/dist/internal/upload/manager.js +19 -50
  145. package/dist/internal/upload/manager.js.map +1 -1
  146. package/dist/internal/upload/manager.test.js +68 -44
  147. package/dist/internal/upload/manager.test.js.map +1 -1
  148. package/dist/internal/upload/streamUploader.js +1 -2
  149. package/dist/internal/upload/streamUploader.js.map +1 -1
  150. package/dist/internal/upload/streamUploader.test.js +1 -1
  151. package/dist/internal/upload/streamUploader.test.js.map +1 -1
  152. package/dist/protonDriveClient.d.ts +19 -162
  153. package/dist/protonDriveClient.js +26 -190
  154. package/dist/protonDriveClient.js.map +1 -1
  155. package/dist/protonDrivePhotosClient.js +3 -2
  156. package/dist/protonDrivePhotosClient.js.map +1 -1
  157. package/package.json +3 -3
  158. package/src/cache/index.ts +1 -0
  159. package/src/cache/memoryCache.ts +1 -1
  160. package/src/cache/nullCache.ts +38 -0
  161. package/src/config.ts +17 -2
  162. package/src/crypto/openPGPCrypto.ts +2 -0
  163. package/src/diagnostic/eventsGenerator.ts +48 -0
  164. package/src/diagnostic/httpClient.ts +80 -0
  165. package/src/diagnostic/index.ts +38 -0
  166. package/src/diagnostic/integrityVerificationStream.ts +56 -0
  167. package/src/diagnostic/interface.ts +158 -0
  168. package/src/diagnostic/sdkDiagnostic.ts +238 -0
  169. package/src/diagnostic/sdkDiagnosticFull.ts +40 -0
  170. package/src/diagnostic/telemetry.ts +71 -0
  171. package/src/diagnostic/zipGenerators.test.ts +177 -0
  172. package/src/diagnostic/zipGenerators.ts +70 -0
  173. package/src/errors.ts +4 -1
  174. package/src/interface/config.ts +28 -0
  175. package/src/interface/download.ts +2 -2
  176. package/src/interface/events.ts +66 -21
  177. package/src/interface/httpClient.ts +0 -16
  178. package/src/interface/index.ts +8 -4
  179. package/src/interface/nodes.ts +21 -12
  180. package/src/interface/sharing.ts +1 -0
  181. package/src/interface/upload.ts +6 -0
  182. package/src/internal/download/apiService.ts +11 -8
  183. package/src/internal/download/fileDownloader.ts +2 -2
  184. package/src/internal/events/apiService.ts +25 -28
  185. package/src/internal/events/coreEventManager.test.ts +101 -0
  186. package/src/internal/events/coreEventManager.ts +20 -45
  187. package/src/internal/events/eventManager.test.ts +201 -88
  188. package/src/internal/events/eventManager.ts +69 -115
  189. package/src/internal/events/index.ts +54 -84
  190. package/src/internal/events/interface.ts +70 -15
  191. package/src/internal/events/volumeEventManager.test.ts +243 -0
  192. package/src/internal/events/volumeEventManager.ts +55 -53
  193. package/src/internal/nodes/cache.ts +20 -2
  194. package/src/internal/nodes/cryptoService.ts +1 -1
  195. package/src/internal/nodes/events.test.ts +29 -335
  196. package/src/internal/nodes/events.ts +45 -253
  197. package/src/internal/nodes/index.ts +6 -8
  198. package/src/internal/nodes/interface.ts +2 -2
  199. package/src/internal/nodes/nodesAccess.test.ts +132 -91
  200. package/src/internal/nodes/nodesAccess.ts +40 -1
  201. package/src/internal/nodes/nodesManagement.test.ts +39 -15
  202. package/src/internal/nodes/nodesManagement.ts +12 -30
  203. package/src/internal/shares/cache.ts +4 -2
  204. package/src/internal/shares/manager.ts +9 -5
  205. package/src/internal/sharing/apiService.ts +1 -0
  206. package/src/internal/sharing/cache.ts +1 -1
  207. package/src/internal/sharing/cryptoService.ts +1 -0
  208. package/src/internal/sharing/events.test.ts +89 -195
  209. package/src/internal/sharing/events.ts +42 -156
  210. package/src/internal/sharing/index.ts +6 -9
  211. package/src/internal/sharing/interface.ts +6 -2
  212. package/src/internal/sharing/sharingManagement.test.ts +10 -40
  213. package/src/internal/sharing/sharingManagement.ts +7 -11
  214. package/src/internal/upload/apiService.ts +5 -6
  215. package/src/internal/upload/index.ts +5 -5
  216. package/src/internal/upload/interface.ts +2 -0
  217. package/src/internal/upload/manager.test.ts +75 -45
  218. package/src/internal/upload/manager.ts +24 -54
  219. package/src/internal/upload/streamUploader.test.ts +0 -1
  220. package/src/internal/upload/streamUploader.ts +0 -2
  221. package/src/protonDriveClient.ts +75 -244
  222. package/src/protonDrivePhotosClient.ts +4 -3
  223. package/dist/internal/events/cache.d.ts +0 -28
  224. package/dist/internal/events/cache.js +0 -67
  225. package/dist/internal/events/cache.js.map +0 -1
  226. package/dist/internal/events/cache.test.js +0 -43
  227. package/dist/internal/events/cache.test.js.map +0 -1
  228. package/dist/internal/nodes/index.test.js +0 -114
  229. package/dist/internal/nodes/index.test.js.map +0 -1
  230. package/src/internal/events/cache.test.ts +0 -47
  231. package/src/internal/events/cache.ts +0 -80
  232. package/src/internal/nodes/index.test.ts +0 -137
  233. /package/dist/{internal/events/cache.test.d.ts → diagnostic/zipGenerators.test.d.ts} +0 -0
  234. /package/dist/internal/{nodes/index.test.d.ts → events/coreEventManager.test.d.ts} +0 -0
@@ -24,8 +24,6 @@ import {
24
24
  ThumbnailType,
25
25
  ThumbnailResult,
26
26
  SDKEvent,
27
- DeviceEventCallback,
28
- NodeEventCallback,
29
27
  } from './interface';
30
28
  import { DriveCrypto, SessionKey } from './crypto';
31
29
  import { DriveAPIService } from './internal/apiService';
@@ -34,17 +32,18 @@ import { initNodesModule } from './internal/nodes';
34
32
  import { initSharingModule } from './internal/sharing';
35
33
  import { initDownloadModule } from './internal/download';
36
34
  import { initUploadModule } from './internal/upload';
37
- import { DriveEventsService } from './internal/events';
35
+ import { DriveEventsService, DriveListener } from './internal/events';
38
36
  import { SDKEvents } from './internal/sdkEvents';
39
37
  import { getConfig } from './config';
40
38
  import { getUid, getUids, convertInternalNodePromise, convertInternalNodeIterator, convertInternalMissingNodeIterator, convertInternalNode } from './transformers';
41
39
  import { Telemetry } from './telemetry';
42
40
  import { initDevicesModule } from './internal/devices';
43
- import { makeNodeUid, splitNodeUid } from './internal/uids';
41
+ import { makeNodeUid } from './internal/uids';
42
+ import { EventSubscription } from './internal/events/interface';
44
43
 
45
44
  /**
46
45
  * ProtonDriveClient is the main interface for the ProtonDrive SDK.
47
- *
46
+ *
48
47
  * The client provides high-level operations for managing nodes, sharing,
49
48
  * and downloading/uploading files. It is the main entry point for using
50
49
  * the ProtonDrive SDK.
@@ -63,9 +62,9 @@ export class ProtonDriveClient {
63
62
  public experimental: {
64
63
  /**
65
64
  * Experimental feature to return the URL of the node.
66
- *
65
+ *
67
66
  * Use it when you want to open the node in the ProtonDrive web app.
68
- *
67
+ *
69
68
  * It has hardcoded URLs to open in production client only.
70
69
  */
71
70
  getNodeUrl: (nodeUid: NodeOrUid) => Promise<string>;
@@ -86,6 +85,7 @@ export class ProtonDriveClient {
86
85
  srpModule,
87
86
  config,
88
87
  telemetry,
88
+ latestEventIdProvider,
89
89
  }: ProtonDriveClientContructorParameters) {
90
90
  if (!telemetry) {
91
91
  telemetry = new Telemetry();
@@ -96,13 +96,16 @@ export class ProtonDriveClient {
96
96
  this.sdkEvents = new SDKEvents(telemetry);
97
97
  const cryptoModule = new DriveCrypto(openPGPCryptoModule, srpModule);
98
98
  const apiService = new DriveAPIService(telemetry, this.sdkEvents, httpClient, fullConfig.baseUrl, fullConfig.language);
99
- this.events = new DriveEventsService(telemetry, apiService, entitiesCache);
100
99
  this.shares = initSharesModule(telemetry, apiService, entitiesCache, cryptoCache, account, cryptoModule);
101
- this.nodes = initNodesModule(telemetry, apiService, entitiesCache, cryptoCache, account, cryptoModule, this.events, this.shares);
102
- this.sharing = initSharingModule(telemetry, apiService, entitiesCache, account, cryptoModule, this.events, this.shares, this.nodes.access, this.nodes.events);
100
+ this.nodes = initNodesModule(telemetry, apiService, entitiesCache, cryptoCache, account, cryptoModule, this.shares);
101
+ this.sharing = initSharingModule(telemetry, apiService, entitiesCache, account, cryptoModule, this.shares, this.nodes.access);
103
102
  this.download = initDownloadModule(telemetry, apiService, cryptoModule, account, this.shares, this.nodes.access, this.nodes.revisions);
104
- this.upload = initUploadModule(telemetry, apiService, cryptoModule, this.shares, this.nodes.access, this.nodes.events);
103
+ this.upload = initUploadModule(telemetry, apiService, cryptoModule, this.shares, this.nodes.access, fullConfig.clientUid);
105
104
  this.devices = initDevicesModule(telemetry, apiService, cryptoModule, this.shares, this.nodes.access, this.nodes.management);
105
+ // These are used to keep the internal cache up to date
106
+ const cacheEventListeners: DriveListener[] = [this.nodes.eventHandler.updateNodesCacheOnEvent, this.sharing.eventHandler.handleDriveEvent];
107
+ this.events = new DriveEventsService(telemetry, apiService, this.shares, cacheEventListeners, latestEventIdProvider);
108
+
106
109
  this.experimental = {
107
110
  getNodeUrl: async (nodeUid: NodeOrUid) => {
108
111
  this.logger.debug(`Getting node URL for ${getUid(nodeUid)}`);
@@ -121,7 +124,7 @@ export class ProtonDriveClient {
121
124
 
122
125
  /**
123
126
  * Subscribes to the general SDK events.
124
- *
127
+ *
125
128
  * This is not connected to the remote data updates. For that, use
126
129
  * and see `subscribeToRemoteDataUpdates`.
127
130
  *
@@ -135,197 +138,39 @@ export class ProtonDriveClient {
135
138
  }
136
139
 
137
140
  /**
138
- * Subscribes to the remote data updates.
139
- *
140
- * By default, SDK doesn't subscribe to remote data updates. If you
141
- * cache the data locally, you need to call this method so the SDK
142
- * keeps the local cache in sync with the remote data.
143
- *
144
- * Only one instance of the SDK should subscribe to remote data updates.
141
+ * Subscribes to the remote data updates for all files and folders in a
142
+ * tree.
145
143
  *
146
- * Once subscribed, the SDK will poll for events for core user events and
147
- * for own data at minimum. Updates to nodes from other users are polled
148
- * with lower frequency depending on the number of subscriptions, and only
149
- * after accessing them for the first time via `iterateSharedNodesWithMe`.
150
- */
151
- async subscribeToRemoteDataUpdates(): Promise<void> {
152
- this.logger.debug('Subscribing to remote data updates');
153
- await this.events.subscribeToRemoteDataUpdates();
154
-
155
- const { volumeId } = await this.shares.getMyFilesIDs();
156
- await this.events.listenToVolume(volumeId, true);
157
- }
158
-
159
- /**
160
- * Subscribe to updates of the devices.
161
- *
162
- * Clients should subscribe to this before beginning to list devices
163
- * to ensure that updates are reflected once a device is in the cache.
164
- * Subscribing before listing is also required to ensure that devices
165
- * that are created during the listing will be recognized.
166
- *
167
- * ```typescript
168
- * const unsubscribe = sdk.subscribeToDevices((event) => {
169
- * if (event.type === 'update') {
170
- * // Update the device in the UI
171
- * } else if (event.type === 'remove') {
172
- * // Remove the device from the UI
173
- * }
174
- * });
175
- *
176
- * const devices = await Array.fromAsync(sdk.iterateDevices());
177
- * // Render the devices in the UI
178
- *
179
- * // Unsubscribe from the updates when the component is unmounted
180
- * unsubscribe();
181
- * ```
144
+ * In order to keep local data up to date, the client must call this method
145
+ * to receive events on update and to keep the SDK cache in sync.
182
146
  *
183
- * @param callback - Callback to be called when the event is emitted.
184
- * @returns Callback to unsubscribe from the event.
185
- */
186
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
187
- subscribeToDevices(callback: DeviceEventCallback): () => void {
188
- this.logger.debug('Subscribing to devices');
189
- throw new Error('Method not implemented');
190
- }
191
-
192
- /**
193
- * Subscribe to updates of the children of the given parent node.
194
- *
195
- * Clients should subscribe to this before beginning to list children
196
- * to ensure that updates are reflected once a node is in the cache.
197
- * Subscribing before listing is also required to ensure that nodes
198
- * that are created during the listing will be recognized.
199
- *
200
- * ```typescript
201
- * const unsubscribe = sdk.subscribeToChildren(parentNodeUid, (event) => {
202
- * if (event.type === 'update') {
203
- * // Update the node in the UI
204
- * } else if (event.type === 'remove') {
205
- * // Remove the node from the UI
206
- * }
207
- * });
208
- *
209
- * const nodes = await Array.fromAsync(sdk.iterateChildren(parentNodeUid));
210
- * // Render the nodes in the UI
211
- *
212
- * // Unsubscribe from the updates when the component is unmounted
213
- * unsubscribe();
214
- * ```
147
+ * The `treeEventScopeId` can be obtained from node properties.
215
148
  *
216
- * @param parentNodeUid - Node entity or its UID string.
217
- * @param callback - Callback to be called when the event is emitted.
218
- * @returns Callback to unsubscribe from the event.
149
+ * Only one instance of the SDK should subscribe to updates.
219
150
  */
220
- subscribeToFolder(parentNodeUid: NodeOrUid, callback: NodeEventCallback): () => void {
221
- this.logger.debug(`Subscribing to children of ${getUid(parentNodeUid)}`);
222
- return this.nodes.events.subscribeToChildren(getUid(parentNodeUid), callback);
151
+ async subscribeToTreeEvents(treeEventScopeId: string, callback: DriveListener): Promise<EventSubscription> {
152
+ this.logger.debug('Subscribing to node updates');
153
+ return this.events.subscribeToTreeEvents(treeEventScopeId, callback)
223
154
  }
224
155
 
225
156
  /**
226
- * Subscribe to updates of the trashed nodes.
227
- *
228
- * Clients should subscribe to this before beginning to list trashed
229
- * nodes to ensure that updates are reflected once a node is in the cache.
230
- * Subscribing before listing is also required to ensure that nodes
231
- * that are trashed during the listing will be recognized.
232
- *
233
- * ```typescript
234
- * const unsubscribe = sdk.subscribeToTrashedNodes((event) => {
235
- * if (event.type === 'update') {
236
- * // Update the node in the UI
237
- * } else if (event.type === 'remove') {
238
- * // Remove the node from the UI
239
- * }
240
- * });
241
- *
242
- * const nodes = await Array.fromAsync(sdk.iterateTrashedNodes());
243
- * // Render the nodes in the UI
244
- *
245
- * // Unsubscribe from the updates when the component is unmounted
246
- * unsubscribe();
247
- * ```
157
+ * Subscribes to sharing updates.
248
158
  *
249
- * @param callback - Callback to be called when the event is emitted.
250
- * @returns Callback to unsubscribe from the event.
251
- */
252
- subscribeToTrashedNodes(callback: NodeEventCallback): () => void {
253
- this.logger.debug('Subscribing to trashed nodes');
254
- return this.nodes.events.subscribeToTrashedNodes(callback);
255
- }
256
-
257
- /**
258
- * Subscribe to updates of the nodes shared by the user.
259
- *
260
- * Clients should subscribe to this before beginning to list shared
261
- * nodes to ensure that updates are reflected once a node is in the cache.
262
- * Subscribing before listing is also required to ensure that nodes
263
- * that are shared during the listing will be recognized.
264
- *
265
- * ```typescript
266
- * const unsubscribe = sdk.subscribeToSharedNodesByMe((event) => {
267
- * if (event.type === 'update') {
268
- * // Update the node in the UI
269
- * } else if (event.type === 'remove') {
270
- * // Remove the node from the UI
271
- * }
272
- * });
273
- *
274
- * const nodes = await Array.fromAsync(sdk.iterateSharedNodes());
275
- * // Render the nodes in the UI
276
- *
277
- * // Unsubscribe from the updates when the component is unmounted
278
- * unsubscribe();
279
- * ```
280
- *
281
- * @param callback - Callback to be called when the event is emitted.
282
- * @returns Callback to unsubscribe from the event.
159
+ * Only one instance of the SDK should subscribe to updates.
283
160
  */
284
- subscribeToSharedNodesByMe(callback: NodeEventCallback): () => void {
285
- this.logger.debug('Subscribing to shared nodes by me');
286
- return this.sharing.events.subscribeToSharedNodesByMe(callback);
287
- }
288
-
289
- /**
290
- * Subscribe to updates of the nodes shared with the user.
291
- *
292
- * Clients should subscribe to this before beginning to list shared
293
- * nodes to ensure that updates are reflected once a node is in the cache.
294
- * Subscribing before listing is also required to ensure that nodes
295
- * that are shared during the listing will be recognized.
296
- *
297
- * ```typescript
298
- * const unsubscribe = sdk.subscribeToSharedNodesWithMe((event) => {
299
- * if (event.type === 'update') {
300
- * // Update the node in the UI
301
- * } else if (event.type === 'remove') {
302
- * // Remove the node from the UI
303
- * }
304
- * });
305
- *
306
- * const nodes = await Array.fromAsync(sdk.iterateSharedNodesWithMe());
307
- * // Render the nodes in the UI
308
- *
309
- * // Unsubscribe from the updates when the component is unmounted
310
- * unsubscribe();
311
- * ```
312
- *
313
- * @param callback - Callback to be called when the event is emitted.
314
- * @returns Callback to unsubscribe from the event.
315
- */
316
- subscribeToSharedNodesWithMe(callback: NodeEventCallback): () => void {
317
- this.logger.debug('Subscribing to shared nodes with me');
318
- return this.sharing.events.subscribeToSharedNodesWithMe(callback);
161
+ async subscribeToDriveEvents(callback: DriveListener): Promise<EventSubscription> {
162
+ this.logger.debug('Subscribing to core updates');
163
+ return this.events.subscribeToCoreEvents(callback)
319
164
  }
320
165
 
321
166
  /**
322
167
  * Provides the node UID for the given raw share and node IDs.
323
- *
168
+ *
324
169
  * This is required only for the internal implementation to provide
325
170
  * backward compatibility with the old Drive web setup.
326
- *
171
+ *
327
172
  * If you are having volume ID, use `generateNodeUid` instead.
328
- *
173
+ *
329
174
  * @deprecated This method is not part of the public API.
330
175
  * @param shareId - Context share of the node.
331
176
  * @param nodeId - Node/link ID (not UID).
@@ -347,10 +192,8 @@ export class ProtonDriveClient {
347
192
 
348
193
  /**
349
194
  * Iterates the children of the given parent node.
350
- *
351
- * The output is not sorted and the order of the children is not guaranteed.
352
195
  *
353
- * You can listen to updates via `subscribeToChildren`.
196
+ * The output is not sorted and the order of the children is not guaranteed.
354
197
  *
355
198
  * @param parentNodeUid - Node entity or its UID string.
356
199
  * @param signal - Signal to abort the operation.
@@ -363,13 +206,11 @@ export class ProtonDriveClient {
363
206
 
364
207
  /**
365
208
  * Iterates the trashed nodes.
366
- *
209
+ *
367
210
  * The list of trashed nodes is not cached and is fetched from the server
368
211
  * on each call. The node data itself are served from cached if available.
369
- *
370
- * The output is not sorted and the order of the trashed nodes is not guaranteed.
371
212
  *
372
- * You can listen to updates via `subscribeToTrashedNodes`.
213
+ * The output is not sorted and the order of the trashed nodes is not guaranteed.
373
214
  *
374
215
  * @param signal - Signal to abort the operation.
375
216
  * @returns An async generator of the trashed nodes.
@@ -381,7 +222,7 @@ export class ProtonDriveClient {
381
222
 
382
223
  /**
383
224
  * Iterates the nodes by their UIDs.
384
- *
225
+ *
385
226
  * The output is not sorted and the order of the nodes is not guaranteed.
386
227
  *
387
228
  * @param nodeUids - List of node entities or their UIDs.
@@ -419,13 +260,13 @@ export class ProtonDriveClient {
419
260
 
420
261
  /**
421
262
  * Move the nodes to a new parent node.
422
- *
263
+ *
423
264
  * The operation is performed node by node and the results are yielded
424
265
  * as they are available. Order of the results is not guaranteed.
425
- *
266
+ *
426
267
  * If one of the nodes fails to move, the operation continues with the
427
268
  * rest of the nodes. Use `NodeResult` to check the status of the action.
428
- *
269
+ *
429
270
  * Only move withing the same section is supported at this moment.
430
271
  * That means that the new parent node must be in the same section
431
272
  * as the nodes being moved. E.g., moving from My files to Shared with
@@ -443,10 +284,10 @@ export class ProtonDriveClient {
443
284
 
444
285
  /**
445
286
  * Trash the nodes.
446
- *
287
+ *
447
288
  * The operation is performed in batches and the results are yielded
448
289
  * as they are available. Order of the results is not guaranteed.
449
- *
290
+ *
450
291
  * If one of the nodes fails to trash, the operation continues with the
451
292
  * rest of the nodes. Use `NodeResult` to check the status of the action.
452
293
  *
@@ -461,10 +302,10 @@ export class ProtonDriveClient {
461
302
 
462
303
  /**
463
304
  * Restore the nodes from the trash to their original place.
464
- *
305
+ *
465
306
  * The operation is performed in batches and the results are yielded
466
307
  * as they are available. Order of the results is not guaranteed.
467
- *
308
+ *
468
309
  * If one of the nodes fails to restore, the operation continues with the
469
310
  * rest of the nodes. Use `NodeResult` to check the status of the action.
470
311
  *
@@ -479,10 +320,10 @@ export class ProtonDriveClient {
479
320
 
480
321
  /**
481
322
  * Delete the nodes permanently.
482
- *
323
+ *
483
324
  * The operation is performed in batches and the results are yielded
484
325
  * as they are available. Order of the results is not guaranteed.
485
- *
326
+ *
486
327
  * If one of the nodes fails to delete, the operation continues with the
487
328
  * rest of the nodes. Use `NodeResult` to check the status of the action.
488
329
  *
@@ -502,7 +343,7 @@ export class ProtonDriveClient {
502
343
 
503
344
  /**
504
345
  * Create a new folder.
505
- *
346
+ *
506
347
  * The folder is created in the given parent node.
507
348
  *
508
349
  * @param parentNodeUid - Node entity or its UID string of the parent folder.
@@ -520,10 +361,10 @@ export class ProtonDriveClient {
520
361
 
521
362
  /**
522
363
  * Iterates the revisions of given node.
523
- *
364
+ *
524
365
  * The list of node revisions is not cached and is fetched and decrypted
525
366
  * from the server on each call.
526
- *
367
+ *
527
368
  * The output is sorted by the revision date in descending order (newest
528
369
  * first).
529
370
  *
@@ -565,8 +406,6 @@ export class ProtonDriveClient {
565
406
  * Iterates the nodes shared by the user.
566
407
  *
567
408
  * The output is not sorted and the order of the shared nodes is not guaranteed.
568
- *
569
- * You can listen to updates via `subscribeToSharedNodesByMe`.
570
409
  *
571
410
  * @param signal - Signal to abort the operation.
572
411
  * @returns An async generator of the shared nodes.
@@ -580,12 +419,10 @@ export class ProtonDriveClient {
580
419
  * Iterates the nodes shared with the user.
581
420
  *
582
421
  * The output is not sorted and the order of the shared nodes is not guaranteed.
583
- *
584
- * At the end of the iteration, if `subscribeToRemoteDataUpdates` was called,
585
- * the SDK will listen to updates for the shared nodes to keep the local cache
586
- * in sync with the remote data.
587
- *
588
- * You can listen to updates via `subscribeToSharedNodesWithMe`.
422
+ *
423
+ * Clients can subscribe to drive events in order to receive a
424
+ * `SharedWithMeUpdated` event when there are changes to the user's
425
+ * access to shared nodes.
589
426
  *
590
427
  * @param signal - Signal to abort the operation.
591
428
  * @returns An async generator of the shared nodes.
@@ -593,15 +430,8 @@ export class ProtonDriveClient {
593
430
  async* iterateSharedNodesWithMe(signal?: AbortSignal): AsyncGenerator<MaybeNode> {
594
431
  this.logger.info('Iterating shared nodes with me');
595
432
 
596
- const uniqueVolumeIds = new Set<string>();
597
433
  for await (const node of this.sharing.access.iterateSharedNodesWithMe(signal)) {
598
434
  yield convertInternalNode(node);
599
- const { volumeId } = splitNodeUid(node.uid);
600
- uniqueVolumeIds.add(volumeId);
601
- }
602
-
603
- for (const volumeId of uniqueVolumeIds) {
604
- await this.events.listenToVolume(volumeId, false);
605
435
  }
606
436
  }
607
437
 
@@ -673,7 +503,7 @@ export class ProtonDriveClient {
673
503
 
674
504
  /**
675
505
  * Get sharing info of the node.
676
- *
506
+ *
677
507
  * The sharing info contains the list of invitations, members,
678
508
  * public link and permission for each.
679
509
  *
@@ -690,7 +520,7 @@ export class ProtonDriveClient {
690
520
 
691
521
  /**
692
522
  * Share or update sharing of the node.
693
- *
523
+ *
694
524
  * If the node is already shared, the sharing settings are updated.
695
525
  * If the member is already present but with different role, the role
696
526
  * is updated. If the sharing settings is identical, the sharing info
@@ -731,37 +561,37 @@ export class ProtonDriveClient {
731
561
  * Get the file downloader to download the node content of the active
732
562
  * revision. For downloading specific revision of the file, use
733
563
  * `getFileRevisionDownloader`.
734
- *
564
+ *
735
565
  * The number of ongoing downloads is limited. If the limit is reached,
736
566
  * the download is queued and started when the slot is available. It is
737
567
  * recommended to not start too many downloads at once to avoid having
738
568
  * many open promises.
739
- *
569
+ *
740
570
  * The file downloader is not reusable. If the download is interrupted,
741
571
  * a new file downloader must be created.
742
- *
572
+ *
743
573
  * Before download, the authorship of the node should be checked and
744
574
  * reported to the user if there is any signature issue, notably on the
745
575
  * content author on the revision.
746
- *
576
+ *
747
577
  * Client should not automatically retry the download if it fails. The
748
578
  * download should be initiated by the user again. The downloader does
749
579
  * automatically retry the download if it fails due to network issues,
750
- * or if the server is temporarily unavailable.
751
- *
580
+ * or if the server is temporarily unavailable.
581
+ *
752
582
  * Once download is initiated, the download can fail, besides network
753
583
  * issues etc., only when there is integrity error. It should be considered
754
584
  * a bug and reported to the Drive developers. The SDK provides option
755
585
  * to bypass integrity checks, but that should be used only for debugging
756
586
  * purposes, not available to the end users.
757
- *
587
+ *
758
588
  * Example usage:
759
- *
589
+ *
760
590
  * ```typescript
761
591
  * const downloader = await client.getFileDownloader(nodeUid, signal);
762
592
  * const claimedSize = fileDownloader.getClaimedSizeInBytes();
763
593
  * const downloadController = fileDownloader.writeToStream(stream, (downloadedBytes) => { ... });
764
- *
594
+ *
765
595
  * signalController.abort(); // to cancel
766
596
  * downloadController.pause(); // to pause
767
597
  * downloadController.resume(); // to resume
@@ -798,26 +628,26 @@ export class ProtonDriveClient {
798
628
  /**
799
629
  * Get the file uploader to upload a new file. For uploading a new
800
630
  * revision, use `getFileRevisionUploader` instead.
801
- *
631
+ *
802
632
  * The number of ongoing uploads is limited. If the limit is reached,
803
633
  * the upload is queued and started when the slot is available. It is
804
634
  * recommended to not start too many uploads at once to avoid having
805
635
  * many open promises.
806
- *
636
+ *
807
637
  * The file uploader is not reusable. If the upload is interrupted,
808
638
  * a new file uploader must be created.
809
- *
639
+ *
810
640
  * Client should not automatically retry the upload if it fails. The
811
641
  * upload should be initiated by the user again. The uploader does
812
642
  * automatically retry the upload if it fails due to network issues,
813
643
  * or if the server is temporarily unavailable.
814
- *
644
+ *
815
645
  * Example usage:
816
- *
646
+ *
817
647
  * ```typescript
818
648
  * const uploader = await client.getFileUploader(parentFolderUid, name, metadata, signal);
819
649
  * const uploadController = await uploader.writeStream(stream, thumbnails, (uploadedBytes) => { ... });
820
- *
650
+ *
821
651
  * signalController.abort(); // to cancel
822
652
  * uploadController.pause(); // to pause
823
653
  * uploadController.resume(); // to resume
@@ -839,10 +669,11 @@ export class ProtonDriveClient {
839
669
 
840
670
  /**
841
671
  * Iterates the devices of the user.
842
- *
672
+ *
843
673
  * The output is not sorted and the order of the devices is not guaranteed.
844
674
  *
845
- * You can listen to updates via `subscribeToDevices`.
675
+ * New devices can be registered by listening to events in the
676
+ * event scope of "My Files" and filtering on nodes with null `ParentLinkId`.
846
677
  *
847
678
  * @returns An async generator of devices.
848
679
  */
@@ -853,7 +684,7 @@ export class ProtonDriveClient {
853
684
 
854
685
  /**
855
686
  * Creates a new device.
856
- *
687
+ *
857
688
  * @param nodeUid - Device entity or its UID string.
858
689
  * @returns The created device entity.
859
690
  * @throws {@link ValidationError} If the name is empty, too long, or contains a slash.
@@ -865,7 +696,7 @@ export class ProtonDriveClient {
865
696
 
866
697
  /**
867
698
  * Renames a device.
868
- *
699
+ *
869
700
  * @param deviceOrUid - Device entity or its UID string.
870
701
  * @returns The updated device entity.
871
702
  * @throws {@link ValidationError} If the name is empty, too long, or contains a slash.
@@ -877,7 +708,7 @@ export class ProtonDriveClient {
877
708
 
878
709
  /**
879
710
  * Deletes a device.
880
- *
711
+ *
881
712
  * @param deviceOrUid - Device entity or its UID string.
882
713
  */
883
714
  async deleteDevice(deviceOrUid: DeviceOrUid): Promise<void> {
@@ -1,5 +1,5 @@
1
1
  import { DriveAPIService } from './internal/apiService';
2
- import { ProtonDriveClientContructorParameters } from './interface';
2
+ import { DriveListener, ProtonDriveClientContructorParameters } from './interface';
3
3
  import { DriveCrypto } from './crypto';
4
4
  import { initSharesModule } from './internal/shares';
5
5
  import { initNodesModule } from './internal/nodes';
@@ -32,9 +32,10 @@ export class ProtonDrivePhotosClient {
32
32
  const sdkEvents = new SDKEvents(telemetry);
33
33
  const cryptoModule = new DriveCrypto(openPGPCryptoModule, srpModule);
34
34
  const apiService = new DriveAPIService(telemetry, sdkEvents, httpClient, fullConfig.baseUrl, fullConfig.language);
35
- const events = new DriveEventsService(telemetry, apiService, entitiesCache);
36
35
  const shares = initSharesModule(telemetry, apiService, entitiesCache, cryptoCache, account, cryptoModule);
37
- this.nodes = initNodesModule(telemetry, apiService, entitiesCache, cryptoCache, account, cryptoModule, events, shares);
36
+ this.nodes = initNodesModule(telemetry, apiService, entitiesCache, cryptoCache, account, cryptoModule, shares);
37
+ const cacheEventListeners: DriveListener[] = [this.nodes.eventHandler.updateNodesCacheOnEvent];
38
+ new DriveEventsService(telemetry, apiService, shares, cacheEventListeners);
38
39
  this.photos = initPhotosModule(apiService, entitiesCache, this.nodes.access);
39
40
  }
40
41
 
@@ -1,28 +0,0 @@
1
- import { ProtonDriveEntitiesCache } from "../../interface";
2
- interface EventsData {
3
- lastEventId: string;
4
- pollingIntervalInSeconds: number;
5
- isOwnVolume: boolean;
6
- }
7
- /**
8
- * Provides caching for events IDs.
9
- */
10
- export declare class EventsCache {
11
- private driveCache;
12
- /**
13
- * Locally cached events data to avoid unnecessary reads from the cache.
14
- * Data about last event ID or interval might be accessed often by events
15
- * managers.
16
- */
17
- private events?;
18
- constructor(driveCache: ProtonDriveEntitiesCache);
19
- setLastEventId(volumeIdOrCore: string, eventsData: EventsData): Promise<void>;
20
- getLastEventId(volumeIdOrCore: string): Promise<string | undefined>;
21
- getPollingIntervalInSeconds(volumeIdOrCore: string): Promise<number | undefined>;
22
- isOwnVolume(volumeIdOrCore: string): Promise<boolean | undefined>;
23
- getSubscribedVolumeIds(): Promise<string[]>;
24
- private getEvents;
25
- private getCachedEvents;
26
- private cacheEvents;
27
- }
28
- export {};