@simplito/privmx-webendpoint 2.0.5 → 2.2.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 (86) hide show
  1. package/Types.d.ts +407 -0
  2. package/Types.js +27 -0
  3. package/api/Api.d.ts +20 -0
  4. package/api/Api.js +48 -0
  5. package/api/BaseNative.d.ts +20 -0
  6. package/api/BaseNative.js +35 -0
  7. package/api/ConnectionNative.d.ts +24 -0
  8. package/api/ConnectionNative.js +51 -0
  9. package/api/CryptoApiNative.d.ts +25 -0
  10. package/api/CryptoApiNative.js +54 -0
  11. package/api/EventQueueNative.d.ts +20 -0
  12. package/api/EventQueueNative.js +37 -0
  13. package/api/IdGenerator.d.ts +14 -0
  14. package/api/IdGenerator.js +21 -0
  15. package/api/InboxApiNative.d.ts +38 -0
  16. package/api/InboxApiNative.js +90 -0
  17. package/api/StoreApiNative.d.ts +37 -0
  18. package/api/StoreApiNative.js +87 -0
  19. package/api/ThreadApiNative.d.ts +31 -0
  20. package/api/ThreadApiNative.js +69 -0
  21. package/assets/endpoint-wasm-module.js +20 -0
  22. package/assets/endpoint-wasm-module.wasm +0 -0
  23. package/bundle/privmx-endpoint-web.js +2 -0
  24. package/bundle/privmx-endpoint-web.js.LICENSE.txt +10 -0
  25. package/bundle.d.ts +12 -0
  26. package/bundle.js +16 -0
  27. package/extra/__tests__/__mocks__/constants.d.ts +36 -0
  28. package/extra/__tests__/__mocks__/constants.js +42 -0
  29. package/extra/__tests__/__mocks__/mockContainerSubscriber.d.ts +12 -0
  30. package/extra/__tests__/__mocks__/mockContainerSubscriber.js +25 -0
  31. package/extra/__tests__/__mocks__/mockEventAPIs.d.ts +30 -0
  32. package/extra/__tests__/__mocks__/mockEventAPIs.js +70 -0
  33. package/extra/__tests__/__mocks__/mockEventQueue.d.ts +13 -0
  34. package/extra/__tests__/__mocks__/mockEventQueue.js +45 -0
  35. package/extra/__tests__/__mocks__/utils.d.ts +8 -0
  36. package/extra/__tests__/__mocks__/utils.js +21 -0
  37. package/extra/__tests__/eventsManager.test.d.ts +1 -0
  38. package/extra/__tests__/eventsManager.test.js +73 -0
  39. package/extra/__tests__/inboxEventManager.test.d.ts +1 -0
  40. package/extra/__tests__/inboxEventManager.test.js +56 -0
  41. package/extra/__tests__/storeEventManager.test.d.ts +1 -0
  42. package/extra/__tests__/storeEventManager.test.js +56 -0
  43. package/extra/__tests__/threadEventManager.test.d.ts +1 -0
  44. package/extra/__tests__/threadEventManager.test.js +60 -0
  45. package/extra/__tests__/utils.test.d.ts +1 -0
  46. package/extra/__tests__/utils.test.js +52 -0
  47. package/extra/events.d.ts +234 -0
  48. package/extra/events.js +270 -0
  49. package/extra/files.d.ts +120 -0
  50. package/extra/files.js +216 -0
  51. package/extra/generics.d.ts +19 -0
  52. package/extra/generics.js +2 -0
  53. package/extra/inbox.d.ts +38 -0
  54. package/extra/inbox.js +35 -0
  55. package/extra/index.d.ts +8 -0
  56. package/extra/index.js +23 -0
  57. package/extra/utils.d.ts +24 -0
  58. package/extra/utils.js +68 -0
  59. package/index.d.ts +14 -0
  60. package/index.js +25 -0
  61. package/package.json +45 -3
  62. package/service/BaseApi.d.ts +16 -0
  63. package/service/BaseApi.js +29 -0
  64. package/service/Connection.d.ts +45 -0
  65. package/service/Connection.js +57 -0
  66. package/service/CryptoApi.d.ts +83 -0
  67. package/service/CryptoApi.js +113 -0
  68. package/service/EndpointFactory.d.ts +89 -0
  69. package/service/EndpointFactory.js +173 -0
  70. package/service/EventQueue.d.ts +20 -0
  71. package/service/EventQueue.js +37 -0
  72. package/service/InboxApi.d.ts +183 -0
  73. package/service/InboxApi.js +262 -0
  74. package/service/StoreApi.d.ts +170 -0
  75. package/service/StoreApi.js +246 -0
  76. package/service/ThreadApi.d.ts +124 -0
  77. package/service/ThreadApi.js +186 -0
  78. package/service/index.d.ts +9 -0
  79. package/service/index.js +19 -0
  80. package/README.md +0 -13
  81. package/webAssets/LICENSE.md +0 -76
  82. package/webAssets/endpoint-wasm-module.js +0 -20
  83. package/webAssets/endpoint-wasm-module.wasm +0 -0
  84. package/webAssets/privmx-endpoint-web.js +0 -2
  85. /package/{webAssets → assets}/driver-web-context.js +0 -0
  86. /package/{webAssets → assets}/endpoint-wasm-module.worker.js +0 -0
@@ -0,0 +1,183 @@
1
+ /*!
2
+ PrivMX Web Endpoint.
3
+ Copyright © 2024 Simplito sp. z o.o.
4
+
5
+ This file is part of the PrivMX Platform (https://privmx.dev).
6
+ This software is Licensed under the PrivMX Free License.
7
+
8
+ See the License for the specific language governing permissions and
9
+ limitations under the License.
10
+ */
11
+ import { BaseApi } from "./BaseApi";
12
+ import { InboxApiNative } from "../api/InboxApiNative";
13
+ import { PagingQuery, PagingList, UserWithPubKey, Inbox, InboxPublicView, InboxEntry, FilesConfig, ContainerWithoutItemPolicy } from "../Types";
14
+ export declare class InboxApi extends BaseApi {
15
+ private native;
16
+ constructor(native: InboxApiNative, ptr: number);
17
+ /**
18
+ * Creates a new Inbox.
19
+ *
20
+ * @param {string} contextId ID of the Context of the new Inbox
21
+ * @param {UserWithPubKey[]} users vector of UserWithPubKey structs which indicates who will have access to the created Inbox
22
+ * @param {UserWithPubKey[]} managers vector of UserWithPubKey structs which indicates who will have access (and management rights) to
23
+ * the created Inbox
24
+ * @param {Uint8Array} publicMeta public (unencrypted) metadata
25
+ * @param {Uint8Array} privateMeta private (encrypted) metadata
26
+ * @param {FilesConfig} filesConfig struct to override default file configuration
27
+ * @param {ContainerWithoutItemPolicy} policies Inbox policies
28
+ * @returns {string} ID of the created Inbox
29
+ */
30
+ createInbox(contextId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, filesConfig?: FilesConfig, policies?: ContainerWithoutItemPolicy): Promise<string>;
31
+ /**
32
+ * Updates an existing Inbox.
33
+ *
34
+ * @param {string} inboxId ID of the Inbox to update
35
+ * @param {UserWithPubKey[]} users vector of UserWithPubKey structs which indicates who will have access to the created Inbox
36
+ * @param {UserWithPubKey[]} managers vector of UserWithPubKey structs which indicates who will have access (and management rights) to
37
+ * the created Inbox
38
+ * @param {Uint8Array} publicMeta public (unencrypted) metadata
39
+ * @param {Uint8Array} privateMeta private (encrypted) metadata
40
+ * @param {FilesConfig} filesConfig struct to override default files configuration
41
+ * @param {number} version current version of the updated Inbox
42
+ * @param {boolean} force force update (without checking version)
43
+ * @param {boolean} forceGenerateNewKey force to regenerate a key for the Inbox
44
+ * @param {ContainerWithoutItemPolicy} policies Inbox policies
45
+ */
46
+ updateInbox(inboxId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, filesConfig: FilesConfig | undefined, version: number, force: boolean, forceGenerateNewKey: boolean, policies?: ContainerWithoutItemPolicy): Promise<void>;
47
+ /**
48
+ * Gets a single Inbox by given Inbox ID.
49
+ *
50
+ * @param {string} inboxId ID of the Inbox to get
51
+ * @returns {Inbox} struct containing information about the Inbox
52
+ */
53
+ getInbox(inboxId: string): Promise<Inbox>;
54
+ /**
55
+ * Gets s list of Inboxes in given Context.
56
+ *
57
+ * @param {string} contextId ID of the Context to get Inboxes from
58
+ * @param {PagingQuery} pagingQuery struct with list query parameters
59
+ * @returns {PagingList<Inbox>} struct containing list of Inboxes
60
+ */
61
+ listInboxes(contextId: string, pagingQuery: PagingQuery): Promise<PagingList<Inbox>>;
62
+ /**
63
+ * Gets public data of given Inbox.
64
+ * You do not have to be logged in to call this function.
65
+ *
66
+ * @param {string} inboxId ID of the Inbox to get
67
+ * @returns {InboxPublicView} struct containing public accessible information about the Inbox
68
+ */
69
+ getInboxPublicView(inboxId: string): Promise<InboxPublicView>;
70
+ /**
71
+ * Deletes an Inbox by given Inbox ID.
72
+ *
73
+ * @param {string} inboxId ID of the Inbox to delete
74
+ */
75
+ deleteInbox(inboxId: string): Promise<void>;
76
+ /**
77
+ * Prepares a request to send data to an Inbox.
78
+ * You do not have to be logged in to call this function.
79
+ *
80
+ * @param {string} inboxId ID of the Inbox to which the request applies
81
+ * @param {Uint8Array} data entry data to send
82
+ * @param {number[]} [inboxFileHandles] optional list of file handles that will be sent with the request
83
+ * @param {string} [userPrivKey] optional sender's private key which can be used later to encrypt data for that sender
84
+ * @returns {number} Inbox handle
85
+ */
86
+ prepareEntry(inboxId: string, data: Uint8Array, inboxFileHandles: number[], userPrivKey?: string | undefined): Promise<number>;
87
+ /**
88
+ * Sends data to an Inbox.
89
+ * You do not have to be logged in to call this function.
90
+ *
91
+ * @param {string} inboxHandle ID of the Inbox to which the request applies
92
+ */
93
+ sendEntry(inboxHandle: number): Promise<void>;
94
+ /**
95
+ * Gets an entry from an Inbox.
96
+ *
97
+ * @param {string} inboxEntryId ID of an entry to read from the Inbox
98
+ * @returns {InboxEntry} struct containing data of the selected entry stored in the Inbox
99
+ */
100
+ readEntry(inboxEntryId: string): Promise<InboxEntry>;
101
+ /**
102
+ * Gets list of entries in given Inbox.
103
+ *
104
+ * @param {string} inboxId ID of the Inbox
105
+ * @param {PagingQuery} pagingQuery struct with list query parameters
106
+ * @returns {PagingList<InboxEntry>} struct containing list of entries
107
+ */
108
+ listEntries(inboxId: string, pagingQuery: PagingQuery): Promise<PagingList<InboxEntry>>;
109
+ /**
110
+ * Delete an entry from an Inbox.
111
+ *
112
+ * @param {string} inboxEntryId ID of an entry to delete from the Inbox
113
+ */
114
+ deleteEntry(inboxEntryId: string): Promise<void>;
115
+ /**
116
+ * Creates a file handle to send a file to an Inbox.
117
+ * You do not have to be logged in to call this function.
118
+ *
119
+ * @param {Uint8Array} publicMeta public file metadata
120
+ * @param {Uint8Array} privateMeta private file metadata
121
+ * @param {number} fileSize size of the file to send
122
+ * @returns {number} file handle
123
+ */
124
+ createFileHandle(publicMeta: Uint8Array, privateMeta: Uint8Array, fileSize: number): Promise<number>;
125
+ /**
126
+ * Sends a file's data chunk to an Inbox.
127
+ * (note: To send the entire file - divide it into pieces of the desired size and call the function for each fragment.)
128
+ * You do not have to be logged in to call this function.
129
+ *
130
+ * @param {number} inboxHandle Handle to the prepared Inbox entry
131
+ * @param {number} inboxFileHandle handle to the file where the uploaded chunk belongs
132
+ * @param {Uint8Array} dataChunk - file chunk to send
133
+ */
134
+ writeToFile(inboxHandle: number, inboxFileHandle: number, dataChunk: Uint8Array): Promise<void>;
135
+ /**
136
+ * Opens a file to read.
137
+ *
138
+ * @param {string} fileId ID of the file to read
139
+ * @returns {number} handle to read file data
140
+ */
141
+ openFile(fileId: string): Promise<number>;
142
+ /**
143
+ * Reads file data.
144
+ * Single read call moves the files's cursor position by declared length or set it at the end of the file.
145
+ *
146
+ * @param {number} fileHandle handle to the file
147
+ * @param {number} length size of data to read
148
+ * @returns {Uint8Array} buffer with file data chunk
149
+ */
150
+ readFromFile(fileHandle: number, length: number): Promise<Uint8Array>;
151
+ /**
152
+ * Moves file's read cursor.
153
+ *
154
+ * @param {number} fileHandle handle to the file
155
+ * @param {number} position sets new cursor position
156
+ */
157
+ seekInFile(fileHandle: number, position: number): Promise<void>;
158
+ /**
159
+ * Closes a file by given handle.
160
+ *
161
+ * @param {number} fileHandle handle to the file
162
+ * @returns {string} ID of closed file
163
+ */
164
+ closeFile(fileHandle: number): Promise<string>;
165
+ /**
166
+ * Subscribes for the Inbox module main events.
167
+ */
168
+ subscribeForInboxEvents(): Promise<void>;
169
+ /**
170
+ * Unsubscribes from the Inbox module main events.
171
+ */
172
+ unsubscribeFromInboxEvents(): Promise<void>;
173
+ /**
174
+ * Subscribes for events in given Inbox.
175
+ * @param {string} inboxId ID of the Inbox to subscribe
176
+ */
177
+ subscribeForEntryEvents(inboxId: string): Promise<void>;
178
+ /**
179
+ * Unsubscribes from events in given Inbox.
180
+ * @param {string} inboxId ID of the Inbox to unsubscribe
181
+ */
182
+ unsubscribeFromEntryEvents(inboxId: string): Promise<void>;
183
+ }
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ /*!
3
+ PrivMX Web Endpoint.
4
+ Copyright © 2024 Simplito sp. z o.o.
5
+
6
+ This file is part of the PrivMX Platform (https://privmx.dev).
7
+ This software is Licensed under the PrivMX Free License.
8
+
9
+ See the License for the specific language governing permissions and
10
+ limitations under the License.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.InboxApi = void 0;
14
+ const BaseApi_1 = require("./BaseApi");
15
+ class InboxApi extends BaseApi_1.BaseApi {
16
+ native;
17
+ constructor(native, ptr) {
18
+ super(ptr);
19
+ this.native = native;
20
+ }
21
+ /**
22
+ * Creates a new Inbox.
23
+ *
24
+ * @param {string} contextId ID of the Context of the new Inbox
25
+ * @param {UserWithPubKey[]} users vector of UserWithPubKey structs which indicates who will have access to the created Inbox
26
+ * @param {UserWithPubKey[]} managers vector of UserWithPubKey structs which indicates who will have access (and management rights) to
27
+ * the created Inbox
28
+ * @param {Uint8Array} publicMeta public (unencrypted) metadata
29
+ * @param {Uint8Array} privateMeta private (encrypted) metadata
30
+ * @param {FilesConfig} filesConfig struct to override default file configuration
31
+ * @param {ContainerWithoutItemPolicy} policies Inbox policies
32
+ * @returns {string} ID of the created Inbox
33
+ */
34
+ async createInbox(contextId, users, managers, publicMeta, privateMeta, filesConfig, policies) {
35
+ return this.native.createInbox(this.servicePtr, [
36
+ contextId,
37
+ users,
38
+ managers,
39
+ publicMeta,
40
+ privateMeta,
41
+ filesConfig,
42
+ policies,
43
+ ]);
44
+ }
45
+ /**
46
+ * Updates an existing Inbox.
47
+ *
48
+ * @param {string} inboxId ID of the Inbox to update
49
+ * @param {UserWithPubKey[]} users vector of UserWithPubKey structs which indicates who will have access to the created Inbox
50
+ * @param {UserWithPubKey[]} managers vector of UserWithPubKey structs which indicates who will have access (and management rights) to
51
+ * the created Inbox
52
+ * @param {Uint8Array} publicMeta public (unencrypted) metadata
53
+ * @param {Uint8Array} privateMeta private (encrypted) metadata
54
+ * @param {FilesConfig} filesConfig struct to override default files configuration
55
+ * @param {number} version current version of the updated Inbox
56
+ * @param {boolean} force force update (without checking version)
57
+ * @param {boolean} forceGenerateNewKey force to regenerate a key for the Inbox
58
+ * @param {ContainerWithoutItemPolicy} policies Inbox policies
59
+ */
60
+ async updateInbox(inboxId, users, managers, publicMeta, privateMeta, filesConfig, version, force, forceGenerateNewKey, policies) {
61
+ return this.native.updateInbox(this.servicePtr, [
62
+ inboxId,
63
+ users,
64
+ managers,
65
+ publicMeta,
66
+ privateMeta,
67
+ filesConfig,
68
+ version,
69
+ force,
70
+ forceGenerateNewKey,
71
+ policies,
72
+ ]);
73
+ }
74
+ /**
75
+ * Gets a single Inbox by given Inbox ID.
76
+ *
77
+ * @param {string} inboxId ID of the Inbox to get
78
+ * @returns {Inbox} struct containing information about the Inbox
79
+ */
80
+ async getInbox(inboxId) {
81
+ return this.native.getInbox(this.servicePtr, [inboxId]);
82
+ }
83
+ /**
84
+ * Gets s list of Inboxes in given Context.
85
+ *
86
+ * @param {string} contextId ID of the Context to get Inboxes from
87
+ * @param {PagingQuery} pagingQuery struct with list query parameters
88
+ * @returns {PagingList<Inbox>} struct containing list of Inboxes
89
+ */
90
+ async listInboxes(contextId, pagingQuery) {
91
+ return this.native.listInboxes(this.servicePtr, [contextId, pagingQuery]);
92
+ }
93
+ /**
94
+ * Gets public data of given Inbox.
95
+ * You do not have to be logged in to call this function.
96
+ *
97
+ * @param {string} inboxId ID of the Inbox to get
98
+ * @returns {InboxPublicView} struct containing public accessible information about the Inbox
99
+ */
100
+ async getInboxPublicView(inboxId) {
101
+ return this.native.getInboxPublicView(this.servicePtr, [inboxId]);
102
+ }
103
+ /**
104
+ * Deletes an Inbox by given Inbox ID.
105
+ *
106
+ * @param {string} inboxId ID of the Inbox to delete
107
+ */
108
+ async deleteInbox(inboxId) {
109
+ return this.native.deleteInbox(this.servicePtr, [inboxId]);
110
+ }
111
+ /**
112
+ * Prepares a request to send data to an Inbox.
113
+ * You do not have to be logged in to call this function.
114
+ *
115
+ * @param {string} inboxId ID of the Inbox to which the request applies
116
+ * @param {Uint8Array} data entry data to send
117
+ * @param {number[]} [inboxFileHandles] optional list of file handles that will be sent with the request
118
+ * @param {string} [userPrivKey] optional sender's private key which can be used later to encrypt data for that sender
119
+ * @returns {number} Inbox handle
120
+ */
121
+ async prepareEntry(inboxId, data, inboxFileHandles, userPrivKey) {
122
+ return this.native.prepareEntry(this.servicePtr, [
123
+ inboxId,
124
+ data,
125
+ inboxFileHandles,
126
+ userPrivKey,
127
+ ]);
128
+ }
129
+ /**
130
+ * Sends data to an Inbox.
131
+ * You do not have to be logged in to call this function.
132
+ *
133
+ * @param {string} inboxHandle ID of the Inbox to which the request applies
134
+ */
135
+ async sendEntry(inboxHandle) {
136
+ return this.native.sendEntry(this.servicePtr, [inboxHandle]);
137
+ }
138
+ /**
139
+ * Gets an entry from an Inbox.
140
+ *
141
+ * @param {string} inboxEntryId ID of an entry to read from the Inbox
142
+ * @returns {InboxEntry} struct containing data of the selected entry stored in the Inbox
143
+ */
144
+ async readEntry(inboxEntryId) {
145
+ return this.native.readEntry(this.servicePtr, [inboxEntryId]);
146
+ }
147
+ /**
148
+ * Gets list of entries in given Inbox.
149
+ *
150
+ * @param {string} inboxId ID of the Inbox
151
+ * @param {PagingQuery} pagingQuery struct with list query parameters
152
+ * @returns {PagingList<InboxEntry>} struct containing list of entries
153
+ */
154
+ async listEntries(inboxId, pagingQuery) {
155
+ return this.native.listEntries(this.servicePtr, [inboxId, pagingQuery]);
156
+ }
157
+ /**
158
+ * Delete an entry from an Inbox.
159
+ *
160
+ * @param {string} inboxEntryId ID of an entry to delete from the Inbox
161
+ */
162
+ async deleteEntry(inboxEntryId) {
163
+ return this.native.deleteEntry(this.servicePtr, [inboxEntryId]);
164
+ }
165
+ /**
166
+ * Creates a file handle to send a file to an Inbox.
167
+ * You do not have to be logged in to call this function.
168
+ *
169
+ * @param {Uint8Array} publicMeta public file metadata
170
+ * @param {Uint8Array} privateMeta private file metadata
171
+ * @param {number} fileSize size of the file to send
172
+ * @returns {number} file handle
173
+ */
174
+ async createFileHandle(publicMeta, privateMeta, fileSize) {
175
+ return this.native.createFileHandle(this.servicePtr, [
176
+ publicMeta,
177
+ privateMeta,
178
+ fileSize,
179
+ ]);
180
+ }
181
+ /**
182
+ * Sends a file's data chunk to an Inbox.
183
+ * (note: To send the entire file - divide it into pieces of the desired size and call the function for each fragment.)
184
+ * You do not have to be logged in to call this function.
185
+ *
186
+ * @param {number} inboxHandle Handle to the prepared Inbox entry
187
+ * @param {number} inboxFileHandle handle to the file where the uploaded chunk belongs
188
+ * @param {Uint8Array} dataChunk - file chunk to send
189
+ */
190
+ async writeToFile(inboxHandle, inboxFileHandle, dataChunk) {
191
+ return this.native.writeToFile(this.servicePtr, [
192
+ inboxHandle,
193
+ inboxFileHandle,
194
+ dataChunk,
195
+ ]);
196
+ }
197
+ /**
198
+ * Opens a file to read.
199
+ *
200
+ * @param {string} fileId ID of the file to read
201
+ * @returns {number} handle to read file data
202
+ */
203
+ async openFile(fileId) {
204
+ return this.native.openFile(this.servicePtr, [fileId]);
205
+ }
206
+ /**
207
+ * Reads file data.
208
+ * Single read call moves the files's cursor position by declared length or set it at the end of the file.
209
+ *
210
+ * @param {number} fileHandle handle to the file
211
+ * @param {number} length size of data to read
212
+ * @returns {Uint8Array} buffer with file data chunk
213
+ */
214
+ async readFromFile(fileHandle, length) {
215
+ return this.native.readFromFile(this.servicePtr, [fileHandle, length]);
216
+ }
217
+ /**
218
+ * Moves file's read cursor.
219
+ *
220
+ * @param {number} fileHandle handle to the file
221
+ * @param {number} position sets new cursor position
222
+ */
223
+ async seekInFile(fileHandle, position) {
224
+ return this.native.seekInFile(this.servicePtr, [fileHandle, position]);
225
+ }
226
+ /**
227
+ * Closes a file by given handle.
228
+ *
229
+ * @param {number} fileHandle handle to the file
230
+ * @returns {string} ID of closed file
231
+ */
232
+ async closeFile(fileHandle) {
233
+ return this.native.closeFile(this.servicePtr, [fileHandle]);
234
+ }
235
+ /**
236
+ * Subscribes for the Inbox module main events.
237
+ */
238
+ async subscribeForInboxEvents() {
239
+ return this.native.subscribeForInboxEvents(this.servicePtr, []);
240
+ }
241
+ /**
242
+ * Unsubscribes from the Inbox module main events.
243
+ */
244
+ async unsubscribeFromInboxEvents() {
245
+ return this.native.unsubscribeFromInboxEvents(this.servicePtr, []);
246
+ }
247
+ /**
248
+ * Subscribes for events in given Inbox.
249
+ * @param {string} inboxId ID of the Inbox to subscribe
250
+ */
251
+ async subscribeForEntryEvents(inboxId) {
252
+ return this.native.subscribeForEntryEvents(this.servicePtr, [inboxId]);
253
+ }
254
+ /**
255
+ * Unsubscribes from events in given Inbox.
256
+ * @param {string} inboxId ID of the Inbox to unsubscribe
257
+ */
258
+ async unsubscribeFromEntryEvents(inboxId) {
259
+ return this.native.unsubscribeFromEntryEvents(this.servicePtr, [inboxId]);
260
+ }
261
+ }
262
+ exports.InboxApi = InboxApi;
@@ -0,0 +1,170 @@
1
+ /*!
2
+ PrivMX Web Endpoint.
3
+ Copyright © 2024 Simplito sp. z o.o.
4
+
5
+ This file is part of the PrivMX Platform (https://privmx.dev).
6
+ This software is Licensed under the PrivMX Free License.
7
+
8
+ See the License for the specific language governing permissions and
9
+ limitations under the License.
10
+ */
11
+ import { BaseApi } from "./BaseApi";
12
+ import { StoreApiNative } from "../api/StoreApiNative";
13
+ import { PagingQuery, PagingList, UserWithPubKey, Store, File, ContainerPolicy } from "../Types";
14
+ export declare class StoreApi extends BaseApi {
15
+ private native;
16
+ constructor(native: StoreApiNative, ptr: number);
17
+ /**
18
+ * Creates a new Store in given Context.
19
+ *
20
+ * @param {string} contextId ID of the Context to create the Store in
21
+ * @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Store
22
+ * @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the
23
+ * created Store
24
+ * @param {Uint8Array} publicMeta public (unencrypted) metadata
25
+ * @param {Uint8Array} privateMeta private (encrypted) metadata
26
+ * @param {ContainerPolicy} policies Store's policies
27
+ * @returns {string} created Store ID
28
+ */
29
+ createStore(contextId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, policies?: ContainerPolicy): Promise<string>;
30
+ /**
31
+ * Updates an existing Store.
32
+ *
33
+ * @param {string} storeId ID of the Store to update
34
+ * @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Store
35
+ * @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the
36
+ * created Store
37
+ * @param {Uint8Array} publicMeta public (unencrypted) metadata
38
+ * @param {Uint8Array} privateMeta private (encrypted) metadata
39
+ * @param {number} version current version of the updated Store
40
+ * @param {boolean} force force update (without checking version)
41
+ * @param {boolean} forceGenerateNewKey force to regenerate a key for the Store
42
+ * @param {ContainerPolicy} policies Store's policies
43
+ */
44
+ updateStore(storeId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, version: number, force: boolean, forceGenerateNewKey: boolean, policies?: ContainerPolicy): Promise<void>;
45
+ /**
46
+ * Deletes a Store by given Store ID.
47
+ *
48
+ * @param {string} storeId ID of the Store to delete
49
+ */
50
+ deleteStore(storeId: string): Promise<void>;
51
+ /**
52
+ * Gets a single Store by given Store ID.
53
+ *
54
+ * @param {string} storeId ID of the Store to get
55
+ * @returns {Store} struct containing information about the Store
56
+ */
57
+ getStore(storeId: string): Promise<Store>;
58
+ /**
59
+ * Gets a list of Stores in given Context.
60
+ *
61
+ * @param {string} contextId ID of the Context to get the Stores from
62
+ * @param {PagingQuery} pagingQuery struct with list query parameters
63
+ * @returns {PagingList<Store>} struct containing list of Stores
64
+ */
65
+ listStores(contextId: string, pagingQuery: PagingQuery): Promise<PagingList<Store>>;
66
+ /**
67
+ * Creates a new file in a Store.
68
+ *
69
+ * @param {string} storeId ID of the Store to create the file in
70
+ * @param {Uint8Array} publicMeta public file metadata
71
+ * @param {Uint8Array} privateMeta private file metadata
72
+ * @param {number} size size of the file
73
+ * @returns {number} handle to write data
74
+ */
75
+ createFile(storeId: string, publicMeta: Uint8Array, privateMeta: Uint8Array, size: number): Promise<number>;
76
+ /**
77
+ * Update an existing file in a Store.
78
+ *
79
+ * @param {string} fileId ID of the file to update
80
+ * @param {Uint8Array} publicMeta public file metadata
81
+ * @param {Uint8Array} privateMeta private file metadata
82
+ * @param {number} size size of the file
83
+ * @returns {number} handle to write file data
84
+ */
85
+ updateFile(fileId: string, publicMeta: Uint8Array, privateMeta: Uint8Array, size: number): Promise<number>;
86
+ /**
87
+ * Update metadata of an existing file in a Store.
88
+ *
89
+ * @param {string} fileId ID of the file to update
90
+ * @param {Uint8Array} publicMeta public file metadata
91
+ * @param {Uint8Array} privateMeta private file metadata
92
+ */
93
+ updateFileMeta(fileId: string, publicMeta: Uint8Array, privateMeta: Uint8Array): Promise<void>;
94
+ /**
95
+ * Writes a file data.
96
+ *
97
+ * @param {number} fileHandle handle to write file data
98
+ * @param {Uint8Array} dataChunk file data chunk
99
+ */
100
+ writeToFile(fileHandle: number, dataChunk: Uint8Array): Promise<void>;
101
+ /**
102
+ * Deletes a file by given ID.
103
+ *
104
+ * @param {string} fileId ID of the file to delete
105
+ */
106
+ deleteFile(fileId: string): Promise<void>;
107
+ /**
108
+ * Gets a single file by the given file ID.
109
+ *
110
+ * @param {string} fileId ID of the file to get
111
+ * @returns {File} struct containing information about the file
112
+ */
113
+ getFile(fileId: string): Promise<File>;
114
+ /**
115
+ * Gets a list of files in given Store.
116
+ *
117
+ * @param {string} storeId ID of the Store to get files from
118
+ * @param {PagingQuery} pagingQuery struct with list query parameters
119
+ * @returns {PagingList<File>} struct containing list of files
120
+ */
121
+ listFiles(storeId: string, pagingQuery: PagingQuery): Promise<PagingList<File>>;
122
+ /**
123
+ * Opens a file to read.
124
+ *
125
+ * @param {string} fileId ID of the file to read
126
+ * @returns {number} handle to read file data
127
+ */
128
+ openFile(fileId: string): Promise<number>;
129
+ /**
130
+ * Reads file data.
131
+ * Single read call moves the files's cursor position by declared length or set it at the end of the file.
132
+ *
133
+ * @param {string} fileHandle handle to write file data
134
+ * @param {number} length size of data to read
135
+ * @returns {Uint8Array} array buffer with file data chunk
136
+ */
137
+ readFromFile(fileHandle: number, length: number): Promise<Uint8Array>;
138
+ /**
139
+ * Moves read cursor.
140
+ *
141
+ * @param {string} fileHandle handle to write file data
142
+ * @param {number} position new cursor position
143
+ */
144
+ seekInFile(fileHandle: number, position: number): Promise<void>;
145
+ /**
146
+ * Closes the file handle.
147
+ *
148
+ * @param {string} fileHandle handle to read/write file data
149
+ * @returns {string} ID of closed file
150
+ */
151
+ closeFile(fileHandle: number): Promise<string>;
152
+ /**
153
+ * Subscribes for the Store module main events.
154
+ */
155
+ subscribeForStoreEvents(): Promise<void>;
156
+ /**
157
+ * Unsubscribes from the Store module main events.
158
+ */
159
+ unsubscribeFromStoreEvents(): Promise<void>;
160
+ /**
161
+ * Subscribes for events in given Store.
162
+ * @param {string} storeId ID of the Store to subscribe
163
+ */
164
+ subscribeForFileEvents(storeId: string): Promise<void>;
165
+ /**
166
+ * Unsubscribes from events in given Store.
167
+ * @param {string} storeId ID of the Store to unsubscribe
168
+ */
169
+ unsubscribeFromFileEvents(storeId: string): Promise<void>;
170
+ }