@simplito/privmx-webendpoint 2.1.1 → 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 (85) 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/{webAssets → 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/privmx-endpoint-web.js +0 -2
  84. /package/{webAssets → assets}/driver-web-context.js +0 -0
  85. /package/{webAssets → assets}/endpoint-wasm-module.worker.js +0 -0
@@ -0,0 +1,57 @@
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.Connection = void 0;
14
+ const BaseApi_1 = require("./BaseApi");
15
+ class Connection extends BaseApi_1.BaseApi {
16
+ native;
17
+ apisRefs = {};
18
+ nativeApisDeps = {};
19
+ constructor(native, ptr) {
20
+ super(ptr);
21
+ this.native = native;
22
+ }
23
+ /**
24
+ * Gets the ID of the current connection.
25
+ *
26
+ * @returns {number} ID of the connection
27
+ */
28
+ async getConnectionId() {
29
+ return this.native.getConnectionId(this.servicePtr, []);
30
+ }
31
+ /**
32
+ * Gets a list of Contexts available for the user.
33
+ *
34
+ * @param pagingQuery struct with list query parameters
35
+ * @returns {PagingList<Context>} struct containing a list of Contexts
36
+ */
37
+ async listContexts(pagingQuery) {
38
+ return this.native.listContexts(this.servicePtr, [pagingQuery]);
39
+ }
40
+ /**
41
+ * Disconnects from the Platform backend.
42
+ *
43
+ */
44
+ async disconnect() {
45
+ await this.native.disconnect(this.servicePtr, []);
46
+ await this.freeApis();
47
+ await this.native.deleteConnection(this.servicePtr);
48
+ }
49
+ async freeApis() {
50
+ for (const apiId in this.apisRefs) {
51
+ if (this.nativeApisDeps[apiId]) {
52
+ await this.nativeApisDeps[apiId].deleteApi(this.apisRefs[apiId]._apiServicePtr);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ exports.Connection = Connection;
@@ -0,0 +1,83 @@
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 { CryptoApiNative } from "../api/CryptoApiNative";
13
+ export declare class CryptoApi extends BaseApi {
14
+ private native;
15
+ constructor(native: CryptoApiNative, ptr: number);
16
+ /**
17
+ * Creates a signature of data using given key.
18
+ *
19
+ * @param {Uint8Array} data buffer to sign
20
+ * @param {string} privateKey key used to sign data
21
+ * @returns {Uint8Array} signature
22
+ */
23
+ signData(data: Uint8Array, privateKey: string): Promise<Uint8Array>;
24
+ /**
25
+ * Generates a new private ECC key.
26
+ *
27
+ * @param {string} [randomSeed] optional string used as the base to generate the new key
28
+ * @returns {string} generated ECC key in WIF format
29
+ */
30
+ generatePrivateKey(randomSeed?: string | undefined): Promise<string>;
31
+ /**
32
+ * (deprecated) Generates a new private ECC key from a password using pbkdf2.
33
+ *
34
+ * @param {string} password the password used to generate the new key
35
+ * @param {string} salt random string (additional input for the hashing function)
36
+
37
+ * @returns {string} generated ECC key in WIF format
38
+ */
39
+ derivePrivateKey(password: string, salt: string): Promise<string>;
40
+ /**
41
+ * Generates a new private ECC key from a password using pbkdf2.
42
+ *
43
+ * @param {string} password the password used to generate the new key
44
+ * @param {string} salt random string (additional input for the hashing function)
45
+
46
+ * @returns {string} generated ECC key in WIF format
47
+ */
48
+ derivePrivateKey2(password: string, salt: string): Promise<string>;
49
+ /**
50
+ * Generates a new public ECC key as a pair to an existing private key.
51
+ * @param {string} privateKey private ECC key in WIF format
52
+ * @returns {string} generated ECC key in BASE58DER format
53
+ */
54
+ derivePublicKey(privateKey: string): Promise<string>;
55
+ /**
56
+ * Generates a new symmetric key.
57
+ * @returns {Uint8Array} generated key.
58
+ */
59
+ generateKeySymmetric(): Promise<Uint8Array>;
60
+ /**
61
+ * Encrypts buffer with a given key using AES.
62
+ *
63
+ * @param {Uint8Array} data buffer to encrypt
64
+ * @param {Uint8Array} symmetricKey key used to encrypt data
65
+ * @returns {Uint8Array} encrypted data buffer
66
+ */
67
+ encryptDataSymmetric(data: Uint8Array, symmetricKey: Uint8Array): Promise<Uint8Array>;
68
+ /**
69
+ * Decrypts buffer with a given key using AES.
70
+ *
71
+ * @param {Uint8Array} data buffer to decrypt
72
+ * @param {Uint8Array} symmetricKey key used to decrypt data
73
+ * @returns {Uint8Array} plain (decrypted) data buffer
74
+ */
75
+ decryptDataSymmetric(data: Uint8Array, symmetricKey: Uint8Array): Promise<Uint8Array>;
76
+ /**
77
+ * Converts given private key in PEM format to its WIF format.
78
+ *
79
+ * @param {string} pemKey private key to convert
80
+ * @returns {string} private key in WIF format
81
+ */
82
+ convertPEMKeytoWIFKey(pemKey: string): Promise<string>;
83
+ }
@@ -0,0 +1,113 @@
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.CryptoApi = void 0;
14
+ const BaseApi_1 = require("./BaseApi");
15
+ class CryptoApi extends BaseApi_1.BaseApi {
16
+ native;
17
+ constructor(native, ptr) {
18
+ super(ptr);
19
+ this.native = native;
20
+ }
21
+ /**
22
+ * Creates a signature of data using given key.
23
+ *
24
+ * @param {Uint8Array} data buffer to sign
25
+ * @param {string} privateKey key used to sign data
26
+ * @returns {Uint8Array} signature
27
+ */
28
+ async signData(data, privateKey) {
29
+ return this.native.signData(this.servicePtr, [data, privateKey]);
30
+ }
31
+ /**
32
+ * Generates a new private ECC key.
33
+ *
34
+ * @param {string} [randomSeed] optional string used as the base to generate the new key
35
+ * @returns {string} generated ECC key in WIF format
36
+ */
37
+ async generatePrivateKey(randomSeed) {
38
+ return this.native.generatePrivateKey(this.servicePtr, [randomSeed]);
39
+ }
40
+ /**
41
+ * (deprecated) Generates a new private ECC key from a password using pbkdf2.
42
+ *
43
+ * @param {string} password the password used to generate the new key
44
+ * @param {string} salt random string (additional input for the hashing function)
45
+
46
+ * @returns {string} generated ECC key in WIF format
47
+ */
48
+ async derivePrivateKey(password, salt) {
49
+ return this.native.derivePrivateKey(this.servicePtr, [password, salt]);
50
+ }
51
+ /**
52
+ * Generates a new private ECC key from a password using pbkdf2.
53
+ *
54
+ * @param {string} password the password used to generate the new key
55
+ * @param {string} salt random string (additional input for the hashing function)
56
+
57
+ * @returns {string} generated ECC key in WIF format
58
+ */
59
+ async derivePrivateKey2(password, salt) {
60
+ return this.native.derivePrivateKey2(this.servicePtr, [password, salt]);
61
+ }
62
+ /**
63
+ * Generates a new public ECC key as a pair to an existing private key.
64
+ * @param {string} privateKey private ECC key in WIF format
65
+ * @returns {string} generated ECC key in BASE58DER format
66
+ */
67
+ async derivePublicKey(privateKey) {
68
+ return this.native.derivePublicKey(this.servicePtr, [privateKey]);
69
+ }
70
+ /**
71
+ * Generates a new symmetric key.
72
+ * @returns {Uint8Array} generated key.
73
+ */
74
+ async generateKeySymmetric() {
75
+ return this.native.generateKeySymmetric(this.servicePtr, []);
76
+ }
77
+ /**
78
+ * Encrypts buffer with a given key using AES.
79
+ *
80
+ * @param {Uint8Array} data buffer to encrypt
81
+ * @param {Uint8Array} symmetricKey key used to encrypt data
82
+ * @returns {Uint8Array} encrypted data buffer
83
+ */
84
+ async encryptDataSymmetric(data, symmetricKey) {
85
+ return this.native.encryptDataSymmetric(this.servicePtr, [
86
+ data,
87
+ symmetricKey,
88
+ ]);
89
+ }
90
+ /**
91
+ * Decrypts buffer with a given key using AES.
92
+ *
93
+ * @param {Uint8Array} data buffer to decrypt
94
+ * @param {Uint8Array} symmetricKey key used to decrypt data
95
+ * @returns {Uint8Array} plain (decrypted) data buffer
96
+ */
97
+ async decryptDataSymmetric(data, symmetricKey) {
98
+ return this.native.decryptDataSymmetric(this.servicePtr, [
99
+ data,
100
+ symmetricKey,
101
+ ]);
102
+ }
103
+ /**
104
+ * Converts given private key in PEM format to its WIF format.
105
+ *
106
+ * @param {string} pemKey private key to convert
107
+ * @returns {string} private key in WIF format
108
+ */
109
+ async convertPEMKeytoWIFKey(pemKey) {
110
+ return this.native.convertPEMKeytoWIFKey(this.servicePtr, [pemKey]);
111
+ }
112
+ }
113
+ exports.CryptoApi = CryptoApi;
@@ -0,0 +1,89 @@
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 { Connection } from "./Connection";
12
+ import { CryptoApi } from "./CryptoApi";
13
+ import { EventQueue } from "./EventQueue";
14
+ import { InboxApi } from "./InboxApi";
15
+ import { StoreApi } from "./StoreApi";
16
+ import { ThreadApi } from "./ThreadApi";
17
+ /**
18
+ * Contains static factory methods - generators for Connection and APIs.
19
+ */
20
+ export declare class EndpointFactory {
21
+ private static api;
22
+ private static eventQueueInstance;
23
+ /**
24
+ * Load the Endpoint's WASM assets and initialize the Endpoint library.
25
+ *
26
+ * @param {string} [assetsBasePath] base path/url to the Endpoint's WebAssembly assets (like: endpoint-wasm-module.js, driver-web-context.js and others)
27
+ */
28
+ static setup(assetsBasePath?: string): Promise<void>;
29
+ private static loadScript;
30
+ /**
31
+ * //doc-gen:ignore
32
+ */
33
+ private static init;
34
+ /**
35
+ * Gets the EventQueue instance.
36
+ *
37
+ * @returns {EventQueue} instance of EventQueue
38
+ */
39
+ static getEventQueue(): Promise<EventQueue>;
40
+ /**
41
+ * Connects to the platform backend.
42
+ *
43
+ * @param {string} userPrivKey user's private key
44
+ * @param {string} solutionId ID of the Solution
45
+ * @param {string} bridgeUrl the Bridge Server URL
46
+ * @returns {Connection} instance of Connection
47
+ */
48
+ static connect(userPrivKey: string, solutionId: string, bridgeUrl: string): Promise<Connection>;
49
+ /**
50
+ * Connects to the Platform backend as a guest user.
51
+ *
52
+ * @param {string} solutionId ID of the Solution
53
+ * @param {string} bridgeUrl the Bridge Server URL
54
+ *
55
+ * @returns {Connection} instance of Connection
56
+ */
57
+ static connectPublic(solutionId: string, bridgeUrl: string): Promise<Connection>;
58
+ /**
59
+ * Creates an instance of the Thread API.
60
+ *
61
+ * @param {Connection} connection instance of Connection
62
+ *
63
+ * @returns {ThreadApi} instance of ThreadApi
64
+ */
65
+ static createThreadApi(connection: Connection): Promise<ThreadApi>;
66
+ /**
67
+ * Creates an instance of the Store API.
68
+ *
69
+ * @param {Connection} connection instance of Connection
70
+ *
71
+ * @returns {StoreApi} instance of StoreApi
72
+ */
73
+ static createStoreApi(connection: Connection): Promise<StoreApi>;
74
+ /**
75
+ * Creates an instance of the Inbox API.
76
+ *
77
+ * @param {Connection} connection instance of Connection
78
+ * @param {ThreadApi} threadApi instance of ThreadApi
79
+ * @param {StoreApi} storeApi instance of StoreApi
80
+ * @returns {InboxApi} instance of InboxApi
81
+ */
82
+ static createInboxApi(connection: Connection, threadApi: ThreadApi, storeApi: StoreApi): Promise<InboxApi>;
83
+ /**
84
+ * Creates an instance of the Crypto API.
85
+ *
86
+ * @returns {CryptoApi} instance of CryptoApi
87
+ */
88
+ static createCryptoApi(): Promise<CryptoApi>;
89
+ }
@@ -0,0 +1,173 @@
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.EndpointFactory = void 0;
14
+ const Api_1 = require("../api/Api");
15
+ const ConnectionNative_1 = require("../api/ConnectionNative");
16
+ const CryptoApiNative_1 = require("../api/CryptoApiNative");
17
+ const EventQueueNative_1 = require("../api/EventQueueNative");
18
+ const InboxApiNative_1 = require("../api/InboxApiNative");
19
+ const StoreApiNative_1 = require("../api/StoreApiNative");
20
+ const ThreadApiNative_1 = require("../api/ThreadApiNative");
21
+ const Connection_1 = require("./Connection");
22
+ const CryptoApi_1 = require("./CryptoApi");
23
+ const EventQueue_1 = require("./EventQueue");
24
+ const InboxApi_1 = require("./InboxApi");
25
+ const StoreApi_1 = require("./StoreApi");
26
+ const ThreadApi_1 = require("./ThreadApi");
27
+ /**
28
+ * Contains static factory methods - generators for Connection and APIs.
29
+ */
30
+ class EndpointFactory {
31
+ static api;
32
+ static eventQueueInstance;
33
+ /**
34
+ * Load the Endpoint's WASM assets and initialize the Endpoint library.
35
+ *
36
+ * @param {string} [assetsBasePath] base path/url to the Endpoint's WebAssembly assets (like: endpoint-wasm-module.js, driver-web-context.js and others)
37
+ */
38
+ static async setup(assetsBasePath) {
39
+ const basePath = assetsBasePath || document.currentScript.src.split("/").slice(0, -1).join("/");
40
+ const assets = ["driver-web-context.js", "endpoint-wasm-module.js"];
41
+ for (const asset of assets) {
42
+ await this.loadScript(basePath + "/" + asset);
43
+ }
44
+ const lib = await endpointWasmModule();
45
+ EndpointFactory.init(lib);
46
+ }
47
+ static async loadScript(url) {
48
+ return new Promise(resolve => {
49
+ const head = document.getElementsByTagName('head')[0];
50
+ const script = document.createElement('script');
51
+ script.type = 'text/javascript';
52
+ script.src = url;
53
+ script.onload = () => {
54
+ resolve();
55
+ };
56
+ head.appendChild(script);
57
+ });
58
+ }
59
+ /**
60
+ * //doc-gen:ignore
61
+ */
62
+ static init(lib) {
63
+ this.api = new Api_1.Api(lib);
64
+ }
65
+ /**
66
+ * Gets the EventQueue instance.
67
+ *
68
+ * @returns {EventQueue} instance of EventQueue
69
+ */
70
+ static async getEventQueue() {
71
+ if (!this.eventQueueInstance) {
72
+ const nativeApi = new EventQueueNative_1.EventQueueNative(this.api);
73
+ const ptr = await nativeApi.newEventQueue();
74
+ this.eventQueueInstance = new EventQueue_1.EventQueue(nativeApi, ptr);
75
+ }
76
+ return this.eventQueueInstance;
77
+ }
78
+ /**
79
+ * Connects to the platform backend.
80
+ *
81
+ * @param {string} userPrivKey user's private key
82
+ * @param {string} solutionId ID of the Solution
83
+ * @param {string} bridgeUrl the Bridge Server URL
84
+ * @returns {Connection} instance of Connection
85
+ */
86
+ static async connect(userPrivKey, solutionId, bridgeUrl) {
87
+ const nativeApi = new ConnectionNative_1.ConnectionNative(this.api);
88
+ const ptr = await nativeApi.newConnection();
89
+ await nativeApi.connect(ptr, [userPrivKey, solutionId, bridgeUrl]);
90
+ return new Connection_1.Connection(nativeApi, ptr);
91
+ }
92
+ /**
93
+ * Connects to the Platform backend as a guest user.
94
+ *
95
+ * @param {string} solutionId ID of the Solution
96
+ * @param {string} bridgeUrl the Bridge Server URL
97
+ *
98
+ * @returns {Connection} instance of Connection
99
+ */
100
+ static async connectPublic(solutionId, bridgeUrl) {
101
+ const nativeApi = new ConnectionNative_1.ConnectionNative(this.api);
102
+ const ptr = await nativeApi.newConnection();
103
+ await nativeApi.connectPublic(ptr, [solutionId, bridgeUrl]);
104
+ return new Connection_1.Connection(nativeApi, ptr);
105
+ }
106
+ /**
107
+ * Creates an instance of the Thread API.
108
+ *
109
+ * @param {Connection} connection instance of Connection
110
+ *
111
+ * @returns {ThreadApi} instance of ThreadApi
112
+ */
113
+ static async createThreadApi(connection) {
114
+ if ("threads" in connection.apisRefs) {
115
+ throw new Error("ThreadApi already registered for given connection.");
116
+ }
117
+ const nativeApi = new ThreadApiNative_1.ThreadApiNative(this.api);
118
+ const ptr = await nativeApi.newApi(connection.servicePtr);
119
+ await nativeApi.create(ptr, []);
120
+ connection.apisRefs["threads"] = { _apiServicePtr: ptr };
121
+ connection.nativeApisDeps["threads"] = nativeApi;
122
+ return new ThreadApi_1.ThreadApi(nativeApi, ptr);
123
+ }
124
+ /**
125
+ * Creates an instance of the Store API.
126
+ *
127
+ * @param {Connection} connection instance of Connection
128
+ *
129
+ * @returns {StoreApi} instance of StoreApi
130
+ */
131
+ static async createStoreApi(connection) {
132
+ if ("stores" in connection.apisRefs) {
133
+ throw new Error("StoreApi already registered for given connection.");
134
+ }
135
+ const nativeApi = new StoreApiNative_1.StoreApiNative(this.api);
136
+ const ptr = await nativeApi.newApi(connection.servicePtr);
137
+ connection.apisRefs["stores"] = { _apiServicePtr: ptr };
138
+ connection.nativeApisDeps["stores"] = nativeApi;
139
+ await nativeApi.create(ptr, []);
140
+ return new StoreApi_1.StoreApi(nativeApi, ptr);
141
+ }
142
+ /**
143
+ * Creates an instance of the Inbox API.
144
+ *
145
+ * @param {Connection} connection instance of Connection
146
+ * @param {ThreadApi} threadApi instance of ThreadApi
147
+ * @param {StoreApi} storeApi instance of StoreApi
148
+ * @returns {InboxApi} instance of InboxApi
149
+ */
150
+ static async createInboxApi(connection, threadApi, storeApi) {
151
+ if ("inboxes" in connection.apisRefs) {
152
+ throw new Error("InboxApi already registered for given connection.");
153
+ }
154
+ const nativeApi = new InboxApiNative_1.InboxApiNative(this.api);
155
+ const ptr = await nativeApi.newApi(connection.servicePtr, threadApi.servicePtr, storeApi.servicePtr);
156
+ connection.apisRefs["inboxes"] = { _apiServicePtr: ptr };
157
+ connection.nativeApisDeps["inboxes"] = nativeApi;
158
+ await nativeApi.create(ptr, []);
159
+ return new InboxApi_1.InboxApi(nativeApi, ptr);
160
+ }
161
+ /**
162
+ * Creates an instance of the Crypto API.
163
+ *
164
+ * @returns {CryptoApi} instance of CryptoApi
165
+ */
166
+ static async createCryptoApi() {
167
+ const nativeApi = new CryptoApiNative_1.CryptoApiNative(this.api);
168
+ const ptr = await nativeApi.newApi();
169
+ await nativeApi.create(ptr, []);
170
+ return new CryptoApi_1.CryptoApi(nativeApi, ptr);
171
+ }
172
+ }
173
+ exports.EndpointFactory = EndpointFactory;
@@ -0,0 +1,20 @@
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 { EventQueueNative } from '../api/EventQueueNative';
13
+ import { Event } from '../Types';
14
+ export declare class EventQueue extends BaseApi {
15
+ private native;
16
+ private isPending;
17
+ constructor(native: EventQueueNative, ptr: number);
18
+ waitEvent(): Promise<Event>;
19
+ emitBreakEvent(): Promise<void>;
20
+ }
@@ -0,0 +1,37 @@
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.EventQueue = void 0;
14
+ const BaseApi_1 = require("./BaseApi");
15
+ class EventQueue extends BaseApi_1.BaseApi {
16
+ native;
17
+ isPending = false;
18
+ constructor(native, ptr) {
19
+ super(ptr);
20
+ this.native = native;
21
+ }
22
+ async waitEvent() {
23
+ if (this.isPending) {
24
+ throw ("WaitEvent() is already in a pending state waiting for new events");
25
+ }
26
+ try {
27
+ return await this.native.waitEvent(this.servicePtr, []);
28
+ }
29
+ finally {
30
+ this.isPending = false;
31
+ }
32
+ }
33
+ async emitBreakEvent() {
34
+ return this.native.emitBreakEvent(this.servicePtr, []);
35
+ }
36
+ }
37
+ exports.EventQueue = EventQueue;