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