@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.
- package/Types.d.ts +407 -0
- package/Types.js +27 -0
- package/api/Api.d.ts +20 -0
- package/api/Api.js +48 -0
- package/api/BaseNative.d.ts +20 -0
- package/api/BaseNative.js +35 -0
- package/api/ConnectionNative.d.ts +24 -0
- package/api/ConnectionNative.js +51 -0
- package/api/CryptoApiNative.d.ts +25 -0
- package/api/CryptoApiNative.js +54 -0
- package/api/EventQueueNative.d.ts +20 -0
- package/api/EventQueueNative.js +37 -0
- package/api/IdGenerator.d.ts +14 -0
- package/api/IdGenerator.js +21 -0
- package/api/InboxApiNative.d.ts +38 -0
- package/api/InboxApiNative.js +90 -0
- package/api/StoreApiNative.d.ts +37 -0
- package/api/StoreApiNative.js +87 -0
- package/api/ThreadApiNative.d.ts +31 -0
- package/api/ThreadApiNative.js +69 -0
- package/assets/endpoint-wasm-module.js +20 -0
- package/{webAssets → assets}/endpoint-wasm-module.wasm +0 -0
- package/bundle/privmx-endpoint-web.js +2 -0
- package/bundle/privmx-endpoint-web.js.LICENSE.txt +10 -0
- package/bundle.d.ts +12 -0
- package/bundle.js +16 -0
- package/extra/__tests__/__mocks__/constants.d.ts +36 -0
- package/extra/__tests__/__mocks__/constants.js +42 -0
- package/extra/__tests__/__mocks__/mockContainerSubscriber.d.ts +12 -0
- package/extra/__tests__/__mocks__/mockContainerSubscriber.js +25 -0
- package/extra/__tests__/__mocks__/mockEventAPIs.d.ts +30 -0
- package/extra/__tests__/__mocks__/mockEventAPIs.js +70 -0
- package/extra/__tests__/__mocks__/mockEventQueue.d.ts +13 -0
- package/extra/__tests__/__mocks__/mockEventQueue.js +45 -0
- package/extra/__tests__/__mocks__/utils.d.ts +8 -0
- package/extra/__tests__/__mocks__/utils.js +21 -0
- package/extra/__tests__/eventsManager.test.d.ts +1 -0
- package/extra/__tests__/eventsManager.test.js +73 -0
- package/extra/__tests__/inboxEventManager.test.d.ts +1 -0
- package/extra/__tests__/inboxEventManager.test.js +56 -0
- package/extra/__tests__/storeEventManager.test.d.ts +1 -0
- package/extra/__tests__/storeEventManager.test.js +56 -0
- package/extra/__tests__/threadEventManager.test.d.ts +1 -0
- package/extra/__tests__/threadEventManager.test.js +60 -0
- package/extra/__tests__/utils.test.d.ts +1 -0
- package/extra/__tests__/utils.test.js +52 -0
- package/extra/events.d.ts +234 -0
- package/extra/events.js +270 -0
- package/extra/files.d.ts +120 -0
- package/extra/files.js +216 -0
- package/extra/generics.d.ts +19 -0
- package/extra/generics.js +2 -0
- package/extra/inbox.d.ts +38 -0
- package/extra/inbox.js +35 -0
- package/extra/index.d.ts +8 -0
- package/extra/index.js +23 -0
- package/extra/utils.d.ts +24 -0
- package/extra/utils.js +68 -0
- package/index.d.ts +14 -0
- package/index.js +25 -0
- package/package.json +45 -3
- package/service/BaseApi.d.ts +16 -0
- package/service/BaseApi.js +29 -0
- package/service/Connection.d.ts +45 -0
- package/service/Connection.js +57 -0
- package/service/CryptoApi.d.ts +83 -0
- package/service/CryptoApi.js +113 -0
- package/service/EndpointFactory.d.ts +89 -0
- package/service/EndpointFactory.js +173 -0
- package/service/EventQueue.d.ts +20 -0
- package/service/EventQueue.js +37 -0
- package/service/InboxApi.d.ts +183 -0
- package/service/InboxApi.js +262 -0
- package/service/StoreApi.d.ts +170 -0
- package/service/StoreApi.js +246 -0
- package/service/ThreadApi.d.ts +124 -0
- package/service/ThreadApi.js +186 -0
- package/service/index.d.ts +9 -0
- package/service/index.js +19 -0
- package/README.md +0 -13
- package/webAssets/LICENSE.md +0 -76
- package/webAssets/endpoint-wasm-module.js +0 -20
- package/webAssets/privmx-endpoint-web.js +0 -2
- /package/{webAssets → assets}/driver-web-context.js +0 -0
- /package/{webAssets → assets}/endpoint-wasm-module.worker.js +0 -0
package/extra/files.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadFile = exports.FileUploader = exports.StreamReader = exports.FILE_DEFAULT_CHUNK_SIZE = void 0;
|
|
4
|
+
exports.FILE_DEFAULT_CHUNK_SIZE = 1_048_576;
|
|
5
|
+
class StreamReader {
|
|
6
|
+
_handle;
|
|
7
|
+
_offset;
|
|
8
|
+
_api;
|
|
9
|
+
chunkSize;
|
|
10
|
+
hasDataToRead = true;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of StreamReader.
|
|
13
|
+
*
|
|
14
|
+
* @param {number} handle - The file handle.
|
|
15
|
+
* @param {StoreApi} api {@link StoreApi `StoreApi`} instance
|
|
16
|
+
*/
|
|
17
|
+
constructor(handle, api, chunkSize) {
|
|
18
|
+
this._handle = handle;
|
|
19
|
+
this._offset = 0;
|
|
20
|
+
this._api = api;
|
|
21
|
+
this.chunkSize = chunkSize ?? exports.FILE_DEFAULT_CHUNK_SIZE;
|
|
22
|
+
}
|
|
23
|
+
static async readFile(api, fileID, chunkSize) {
|
|
24
|
+
const fileHandle = await api.openFile(fileID);
|
|
25
|
+
const reader = new StreamReader(fileHandle, api, chunkSize);
|
|
26
|
+
return reader;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reads the next chunk of the file.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<boolean>} A promise that resolves to true if there are more chunks to read, or false if the end of the file is reached.
|
|
32
|
+
*/
|
|
33
|
+
async *[Symbol.asyncIterator]() {
|
|
34
|
+
while (this.hasDataToRead) {
|
|
35
|
+
const chunk = await this.readNextChunk();
|
|
36
|
+
yield [chunk, this._offset];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async readNextChunk() {
|
|
40
|
+
const chunkSizeToRead = this.chunkSize ?? exports.FILE_DEFAULT_CHUNK_SIZE;
|
|
41
|
+
const chunk = await this._api.readFromFile(this._handle, chunkSizeToRead);
|
|
42
|
+
//if chunk length is lesser than requested, the end of the file is reached
|
|
43
|
+
this.hasDataToRead = chunk.length === chunkSizeToRead;
|
|
44
|
+
return chunk;
|
|
45
|
+
}
|
|
46
|
+
async getFileContent() {
|
|
47
|
+
const chunks = [];
|
|
48
|
+
while (this.hasDataToRead) {
|
|
49
|
+
chunks.push(await this.readNextChunk());
|
|
50
|
+
}
|
|
51
|
+
await this.close();
|
|
52
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
53
|
+
const fileBuffer = new Uint8Array(totalLength);
|
|
54
|
+
let offset = 0;
|
|
55
|
+
for (const chunk of chunks) {
|
|
56
|
+
fileBuffer.set(chunk, offset);
|
|
57
|
+
offset += chunk.length;
|
|
58
|
+
}
|
|
59
|
+
return fileBuffer;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Aborts the reading process and closes the file handle.
|
|
63
|
+
*
|
|
64
|
+
* @returns {Promise<string>} A promise that resolves when the file handle is closed.
|
|
65
|
+
*/
|
|
66
|
+
async abort() {
|
|
67
|
+
return this._api.closeFile(this._handle);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Closes the file handle.
|
|
71
|
+
*
|
|
72
|
+
* @returns {Promise<string>} A promise that resolves when the file handle is closed and returns file ID.
|
|
73
|
+
*/
|
|
74
|
+
async close() {
|
|
75
|
+
return this._api.closeFile(this._handle);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.StreamReader = StreamReader;
|
|
79
|
+
class FileUploader {
|
|
80
|
+
_size;
|
|
81
|
+
offset = 0;
|
|
82
|
+
_api;
|
|
83
|
+
_reader;
|
|
84
|
+
/**
|
|
85
|
+
* Creates an instance of FileUploader.
|
|
86
|
+
*
|
|
87
|
+
* @param {number} handle - The file handle.
|
|
88
|
+
* @param {File} file - The data (file content) to upload.
|
|
89
|
+
* @param {StoreApi} api {@link StoreApi `StoreApi`} instance
|
|
90
|
+
*/
|
|
91
|
+
constructor(file, api) {
|
|
92
|
+
this._size = file.size;
|
|
93
|
+
this._api = api;
|
|
94
|
+
this._reader = file.stream().getReader();
|
|
95
|
+
}
|
|
96
|
+
static async uploadStoreFile({ storeApi, storeId, file, privateMeta, publicMeta }) {
|
|
97
|
+
const meta = {
|
|
98
|
+
publicMeta: publicMeta || new Uint8Array(),
|
|
99
|
+
privateMeta: privateMeta || new Uint8Array()
|
|
100
|
+
};
|
|
101
|
+
const handle = await storeApi.createFile(storeId, meta.publicMeta, meta.privateMeta, file.size);
|
|
102
|
+
const streamer = new FileUploader(file, {
|
|
103
|
+
closeFile() {
|
|
104
|
+
return storeApi.closeFile(handle);
|
|
105
|
+
},
|
|
106
|
+
writeToFile(chunk) {
|
|
107
|
+
return storeApi.writeToFile(handle, chunk);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return streamer;
|
|
111
|
+
}
|
|
112
|
+
static async uploadInboxFile({ inboxApi, inboxHandle, preparedFileUpload }) {
|
|
113
|
+
const streamer = new FileUploader(preparedFileUpload.file, {
|
|
114
|
+
closeFile() {
|
|
115
|
+
return inboxApi.closeFile(preparedFileUpload.handle);
|
|
116
|
+
},
|
|
117
|
+
writeToFile(chunk) {
|
|
118
|
+
return inboxApi.writeToFile(inboxHandle, preparedFileUpload.handle, chunk);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return streamer;
|
|
122
|
+
}
|
|
123
|
+
static async prepareInboxUpload({ inboxApi, file, privateMeta, publicMeta }) {
|
|
124
|
+
const meta = {
|
|
125
|
+
publicMeta: publicMeta || new Uint8Array(),
|
|
126
|
+
privateMeta: privateMeta || new Uint8Array()
|
|
127
|
+
};
|
|
128
|
+
const handle = await inboxApi.createFileHandle(meta.publicMeta, meta.privateMeta, file.size);
|
|
129
|
+
return { file: file, handle };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the progress of uploading the file as a percentage.
|
|
133
|
+
*
|
|
134
|
+
* @returns {number} The progress percentage.
|
|
135
|
+
*/
|
|
136
|
+
get progress() {
|
|
137
|
+
if (this._size === 0)
|
|
138
|
+
return 100;
|
|
139
|
+
return (this.offset / this._size) * 100;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Sends the next chunk of the file data to the server.
|
|
143
|
+
*
|
|
144
|
+
* @returns {Promise<boolean>} A promise that resolves to true if there are more chunks to send, or false if all data has been sent.
|
|
145
|
+
*/
|
|
146
|
+
async sendNextChunk() {
|
|
147
|
+
const { done, value } = await this._reader.read();
|
|
148
|
+
if (done) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
await this._api.writeToFile(value);
|
|
152
|
+
this.offset += value?.length;
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
async uploadFileContent() {
|
|
156
|
+
while (await this.sendNextChunk()) { }
|
|
157
|
+
return this.close();
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Aborts the uploading process, closes the file handle, and deletes the uploaded part of the file.
|
|
161
|
+
*
|
|
162
|
+
* @returns {Promise<void>} A promise that resolves when the file handle is closed and the uploaded part is deleted.
|
|
163
|
+
*/
|
|
164
|
+
async abort() {
|
|
165
|
+
await this._api.closeFile();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Closes the file handle.
|
|
169
|
+
*
|
|
170
|
+
* @returns {Promise<string>} A promise that resolves when the file handle is closed and returns file ID.
|
|
171
|
+
*/
|
|
172
|
+
async close() {
|
|
173
|
+
this._reader.releaseLock();
|
|
174
|
+
return this._api.closeFile();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.FileUploader = FileUploader;
|
|
178
|
+
/**
|
|
179
|
+
* Downloads a file from the server.
|
|
180
|
+
*
|
|
181
|
+
* @param {StoreApi|InboxApi} api - The API instance used for file operations.
|
|
182
|
+
* @param {string} fileId - The ID of the file to download.
|
|
183
|
+
* @param {string} [targetFileName] - The target file name for saving the downloaded file.
|
|
184
|
+
* @returns {Promise<void>} A promise that resolves when the download is complete.
|
|
185
|
+
*/
|
|
186
|
+
async function downloadFile(api, fileId, targetFileName) {
|
|
187
|
+
const filename = targetFileName || fileId;
|
|
188
|
+
const apiReader = await StreamReader.readFile(api, fileId);
|
|
189
|
+
if ('showSaveFilePicker' in window && window.isSecureContext) {
|
|
190
|
+
//@ts-ignore
|
|
191
|
+
const systemHandle = (await window.showSaveFilePicker({
|
|
192
|
+
id: 0,
|
|
193
|
+
suggestedName: filename,
|
|
194
|
+
startIn: 'downloads'
|
|
195
|
+
}));
|
|
196
|
+
const accessHandle = await systemHandle.createWritable();
|
|
197
|
+
for await (const [file] of apiReader) {
|
|
198
|
+
await accessHandle.write(file);
|
|
199
|
+
}
|
|
200
|
+
await accessHandle.close();
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const fileBuffer = await apiReader.getFileContent();
|
|
204
|
+
const anchor = document.createElement('a');
|
|
205
|
+
const reader = new FileReader();
|
|
206
|
+
reader.onload = (e) => {
|
|
207
|
+
if (!e.target)
|
|
208
|
+
return;
|
|
209
|
+
anchor.href = e.target.result;
|
|
210
|
+
anchor.download = filename;
|
|
211
|
+
anchor.click();
|
|
212
|
+
};
|
|
213
|
+
reader.readAsDataURL(new Blob([fileBuffer]));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.downloadFile = downloadFile;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Types } from '..';
|
|
2
|
+
export interface CreateContainerPayload {
|
|
3
|
+
contextId: string;
|
|
4
|
+
users: Types.UserWithPubKey[];
|
|
5
|
+
managers: Types.UserWithPubKey[];
|
|
6
|
+
publicMeta?: Uint8Array;
|
|
7
|
+
privateMeta?: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export interface UpdateContainerPayload {
|
|
10
|
+
users: Types.UserWithPubKey[];
|
|
11
|
+
managers: Types.UserWithPubKey[];
|
|
12
|
+
publicMeta?: Uint8Array;
|
|
13
|
+
privateMeta?: Uint8Array;
|
|
14
|
+
version: number;
|
|
15
|
+
options?: {
|
|
16
|
+
force?: boolean;
|
|
17
|
+
forceGenerateNewKey?: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
package/extra/inbox.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Endpoint } from '..';
|
|
2
|
+
/**
|
|
3
|
+
* Represents payload that is sent to an Inbox.
|
|
4
|
+
*/
|
|
5
|
+
export interface InboxEntryPayload {
|
|
6
|
+
/**
|
|
7
|
+
* Content of the entry.
|
|
8
|
+
*/
|
|
9
|
+
data: Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Optional files associated with the entry.
|
|
12
|
+
*/
|
|
13
|
+
files?: Array<{
|
|
14
|
+
/**
|
|
15
|
+
*Optional, contains confidential data that will be encrypted before being sent to server.
|
|
16
|
+
*/
|
|
17
|
+
privateMeta?: Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
*Optional, contains data that can be accessed by everyone and is not encrypted.
|
|
20
|
+
*/
|
|
21
|
+
publicMeta?: Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Content of the file.
|
|
24
|
+
*/
|
|
25
|
+
content: File;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sends an entry to the specified inbox.
|
|
30
|
+
*
|
|
31
|
+
* @param {Awaited<ReturnType<typeof Endpoint.createInboxApi>>} inboxApi - The API instance used to interact with the inbox.
|
|
32
|
+
* @param {string} inboxId - The ID of the target inbox where the entry will be sent.
|
|
33
|
+
* @param {InboxEntryPayload} payload - The data payload for the inbox entry, including files, metadata, and other information.
|
|
34
|
+
*
|
|
35
|
+
* @returns {Promise<void>} A promise that resolves when the entry has been successfully sent.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
export declare function sendEntry(inboxApi: Awaited<ReturnType<typeof Endpoint.createInboxApi>>, inboxId: string, payload: InboxEntryPayload): Promise<void>;
|
package/extra/inbox.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendEntry = void 0;
|
|
4
|
+
const files_1 = require("./files");
|
|
5
|
+
/**
|
|
6
|
+
* Sends an entry to the specified inbox.
|
|
7
|
+
*
|
|
8
|
+
* @param {Awaited<ReturnType<typeof Endpoint.createInboxApi>>} inboxApi - The API instance used to interact with the inbox.
|
|
9
|
+
* @param {string} inboxId - The ID of the target inbox where the entry will be sent.
|
|
10
|
+
* @param {InboxEntryPayload} payload - The data payload for the inbox entry, including files, metadata, and other information.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Promise<void>} A promise that resolves when the entry has been successfully sent.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
async function sendEntry(inboxApi, inboxId, payload) {
|
|
16
|
+
const preparedFiles = payload.files
|
|
17
|
+
? await Promise.all(payload.files.map((file) => {
|
|
18
|
+
return files_1.FileUploader.prepareInboxUpload({
|
|
19
|
+
inboxApi,
|
|
20
|
+
file: file.content,
|
|
21
|
+
privateMeta: file.privateMeta,
|
|
22
|
+
publicMeta: file.publicMeta
|
|
23
|
+
});
|
|
24
|
+
}))
|
|
25
|
+
: [];
|
|
26
|
+
const inboxEntryHandle = await inboxApi.prepareEntry(inboxId, payload.data, preparedFiles.map((file) => file.handle));
|
|
27
|
+
const uploaders = await Promise.all(preparedFiles.map((file) => files_1.FileUploader.uploadInboxFile({
|
|
28
|
+
inboxApi,
|
|
29
|
+
inboxHandle: inboxEntryHandle,
|
|
30
|
+
preparedFileUpload: file
|
|
31
|
+
})));
|
|
32
|
+
await Promise.all(uploaders.map((uploader) => uploader.uploadFileContent()));
|
|
33
|
+
await inboxApi.sendEntry(inboxEntryHandle);
|
|
34
|
+
}
|
|
35
|
+
exports.sendEntry = sendEntry;
|
package/extra/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as Files from "./files";
|
|
2
|
+
import * as Events from "./events";
|
|
3
|
+
import { EventManager, ThreadEventsManager, StoreEventsManager, InboxEventsManager, BaseEventManager } from "./events";
|
|
4
|
+
import * as Utils from "./utils";
|
|
5
|
+
import * as Generics from "./generics";
|
|
6
|
+
import * as Inboxes from "./inbox";
|
|
7
|
+
import { FileUploader, StreamReader, downloadFile } from "./files";
|
|
8
|
+
export { Files, Inboxes, Events, Utils, Generics, FileUploader, downloadFile, EventManager, ThreadEventsManager, StoreEventsManager, InboxEventsManager, BaseEventManager, StreamReader };
|
package/extra/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamReader = exports.BaseEventManager = exports.InboxEventsManager = exports.StoreEventsManager = exports.ThreadEventsManager = exports.EventManager = exports.downloadFile = exports.FileUploader = exports.Generics = exports.Utils = exports.Events = exports.Inboxes = exports.Files = void 0;
|
|
4
|
+
const Files = require("./files");
|
|
5
|
+
exports.Files = Files;
|
|
6
|
+
const Events = require("./events");
|
|
7
|
+
exports.Events = Events;
|
|
8
|
+
const events_1 = require("./events");
|
|
9
|
+
Object.defineProperty(exports, "EventManager", { enumerable: true, get: function () { return events_1.EventManager; } });
|
|
10
|
+
Object.defineProperty(exports, "ThreadEventsManager", { enumerable: true, get: function () { return events_1.ThreadEventsManager; } });
|
|
11
|
+
Object.defineProperty(exports, "StoreEventsManager", { enumerable: true, get: function () { return events_1.StoreEventsManager; } });
|
|
12
|
+
Object.defineProperty(exports, "InboxEventsManager", { enumerable: true, get: function () { return events_1.InboxEventsManager; } });
|
|
13
|
+
Object.defineProperty(exports, "BaseEventManager", { enumerable: true, get: function () { return events_1.BaseEventManager; } });
|
|
14
|
+
const Utils = require("./utils");
|
|
15
|
+
exports.Utils = Utils;
|
|
16
|
+
const Generics = require("./generics");
|
|
17
|
+
exports.Generics = Generics;
|
|
18
|
+
const Inboxes = require("./inbox");
|
|
19
|
+
exports.Inboxes = Inboxes;
|
|
20
|
+
const files_1 = require("./files");
|
|
21
|
+
Object.defineProperty(exports, "FileUploader", { enumerable: true, get: function () { return files_1.FileUploader; } });
|
|
22
|
+
Object.defineProperty(exports, "StreamReader", { enumerable: true, get: function () { return files_1.StreamReader; } });
|
|
23
|
+
Object.defineProperty(exports, "downloadFile", { enumerable: true, get: function () { return files_1.downloadFile; } });
|
package/extra/utils.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to convert objects to Uint8Array
|
|
3
|
+
* @param {Record<string, any>} object - The object to serialize
|
|
4
|
+
* @returns {Uint8Array} object serialized to `Uint8Array`
|
|
5
|
+
*/
|
|
6
|
+
export declare function serializeObject(object: Record<string, any>): Uint8Array;
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to convert Uint8Array to objects
|
|
9
|
+
* @param {Uint8Array} data - The data to deserialize
|
|
10
|
+
* @returns {Record<string, any>} parsed JSON object
|
|
11
|
+
*/
|
|
12
|
+
export declare function deserializeObject(data: Uint8Array): Record<string, any>;
|
|
13
|
+
/**
|
|
14
|
+
* Convert Uint8Array to a string
|
|
15
|
+
* @param {Uint8Array} arr - The array to convert
|
|
16
|
+
* @returns {string} The resulting string
|
|
17
|
+
*/
|
|
18
|
+
export declare function uint8ToStr(arr: Uint8Array): string;
|
|
19
|
+
/**
|
|
20
|
+
* Convert a string to Uint8Array
|
|
21
|
+
* @param {string} text - The text to convert
|
|
22
|
+
* @returns {Uint8Array} The resulting Uint8Array
|
|
23
|
+
*/
|
|
24
|
+
export declare function strToUint8(text: string): Uint8Array;
|
package/extra/utils.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strToUint8 = exports.uint8ToStr = exports.deserializeObject = exports.serializeObject = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Helper function to convert objects to Uint8Array
|
|
6
|
+
* @param {Record<string, any>} object - The object to serialize
|
|
7
|
+
* @returns {Uint8Array} object serialized to `Uint8Array`
|
|
8
|
+
*/
|
|
9
|
+
function serializeObject(object) {
|
|
10
|
+
if (object === null || typeof object !== 'object') {
|
|
11
|
+
throw new TypeError('Input must be a non-null object.');
|
|
12
|
+
}
|
|
13
|
+
const encoder = new TextEncoder();
|
|
14
|
+
const parsed = JSON.stringify(object);
|
|
15
|
+
return encoder.encode(parsed);
|
|
16
|
+
}
|
|
17
|
+
exports.serializeObject = serializeObject;
|
|
18
|
+
/**
|
|
19
|
+
* Helper function to convert Uint8Array to objects
|
|
20
|
+
* @param {Uint8Array} data - The data to deserialize
|
|
21
|
+
* @returns {Record<string, any>} parsed JSON object
|
|
22
|
+
*/
|
|
23
|
+
function deserializeObject(data) {
|
|
24
|
+
if (!(data instanceof Uint8Array)) {
|
|
25
|
+
throw new TypeError('Input must be a Uint8Array.');
|
|
26
|
+
}
|
|
27
|
+
const decoder = new TextDecoder();
|
|
28
|
+
const decodedData = decoder.decode(data);
|
|
29
|
+
if (decodedData.trim() === '') {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(decodedData);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof SyntaxError) {
|
|
37
|
+
throw new SyntaxError('Failed to parse JSON: ' + error.message);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new Error('An unexpected error occurred: ' + String(error));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.deserializeObject = deserializeObject;
|
|
45
|
+
/**
|
|
46
|
+
* Convert Uint8Array to a string
|
|
47
|
+
* @param {Uint8Array} arr - The array to convert
|
|
48
|
+
* @returns {string} The resulting string
|
|
49
|
+
*/
|
|
50
|
+
function uint8ToStr(arr) {
|
|
51
|
+
if (!(arr instanceof Uint8Array)) {
|
|
52
|
+
throw new TypeError('Input must be a Uint8Array.');
|
|
53
|
+
}
|
|
54
|
+
return new TextDecoder().decode(arr);
|
|
55
|
+
}
|
|
56
|
+
exports.uint8ToStr = uint8ToStr;
|
|
57
|
+
/**
|
|
58
|
+
* Convert a string to Uint8Array
|
|
59
|
+
* @param {string} text - The text to convert
|
|
60
|
+
* @returns {Uint8Array} The resulting Uint8Array
|
|
61
|
+
*/
|
|
62
|
+
function strToUint8(text) {
|
|
63
|
+
if (typeof text !== 'string') {
|
|
64
|
+
throw new TypeError('Input must be a string.');
|
|
65
|
+
}
|
|
66
|
+
return new TextEncoder().encode(text);
|
|
67
|
+
}
|
|
68
|
+
exports.strToUint8 = strToUint8;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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 { EndpointFactory } from "./service/EndpointFactory";
|
|
12
|
+
import { EventQueue, StoreApi, ThreadApi, InboxApi, Connection, CryptoApi, BaseApi } from "./service";
|
|
13
|
+
import * as Types from "./Types";
|
|
14
|
+
export { EndpointFactory as Endpoint, Types, EventQueue, StoreApi, ThreadApi, InboxApi, CryptoApi, Connection, BaseApi, };
|
package/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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.BaseApi = exports.Connection = exports.CryptoApi = exports.InboxApi = exports.ThreadApi = exports.StoreApi = exports.EventQueue = exports.Types = exports.Endpoint = void 0;
|
|
14
|
+
const EndpointFactory_1 = require("./service/EndpointFactory");
|
|
15
|
+
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return EndpointFactory_1.EndpointFactory; } });
|
|
16
|
+
const service_1 = require("./service");
|
|
17
|
+
Object.defineProperty(exports, "EventQueue", { enumerable: true, get: function () { return service_1.EventQueue; } });
|
|
18
|
+
Object.defineProperty(exports, "StoreApi", { enumerable: true, get: function () { return service_1.StoreApi; } });
|
|
19
|
+
Object.defineProperty(exports, "ThreadApi", { enumerable: true, get: function () { return service_1.ThreadApi; } });
|
|
20
|
+
Object.defineProperty(exports, "InboxApi", { enumerable: true, get: function () { return service_1.InboxApi; } });
|
|
21
|
+
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return service_1.Connection; } });
|
|
22
|
+
Object.defineProperty(exports, "CryptoApi", { enumerable: true, get: function () { return service_1.CryptoApi; } });
|
|
23
|
+
Object.defineProperty(exports, "BaseApi", { enumerable: true, get: function () { return service_1.BaseApi; } });
|
|
24
|
+
const Types = require("./Types");
|
|
25
|
+
exports.Types = Types;
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplito/privmx-webendpoint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "PrivMX Web Endpoint library",
|
|
5
5
|
"author": "Simplito",
|
|
6
|
-
"homepage": "https://privmx.dev",
|
|
7
6
|
"license": "PrivMX Free License",
|
|
8
7
|
"keywords": [
|
|
9
8
|
"privmx",
|
|
@@ -29,5 +28,48 @@
|
|
|
29
28
|
"privacy",
|
|
30
29
|
"privacy-protection",
|
|
31
30
|
"security"
|
|
32
|
-
]
|
|
31
|
+
],
|
|
32
|
+
"type": "commonjs",
|
|
33
|
+
"main": "index.js",
|
|
34
|
+
"types": "index.d.ts",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
37
|
+
"compile": "tsc",
|
|
38
|
+
"build": "npm run clean && npm run build:bundle && npm run build:mjs && npm run build:fixup",
|
|
39
|
+
"clean": "rm -rf ./dist",
|
|
40
|
+
"build:bundle": "webpack",
|
|
41
|
+
"build:mjs": "tsc -p tsconfig.mjs.json",
|
|
42
|
+
"build:fixup": "node fixup-package-json.js",
|
|
43
|
+
"watch": "tsc -w"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=4"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^20.9.0",
|
|
50
|
+
"@types/webpack": "^5.28.5",
|
|
51
|
+
"assert": "^2.1.0",
|
|
52
|
+
"buffer": "^6.0.3",
|
|
53
|
+
"crypto-browserify": "^3.12.0",
|
|
54
|
+
"process": "^0.11.10",
|
|
55
|
+
"stream-browserify": "^3.0.0",
|
|
56
|
+
"ts-loader": "^9.5.1",
|
|
57
|
+
"ts-node": "^10.9.1",
|
|
58
|
+
"tslib": "^2.6.2",
|
|
59
|
+
"typescript": "^5.2.2",
|
|
60
|
+
"vm-browserify": "^1.1.2",
|
|
61
|
+
"webpack": "^5.89.0",
|
|
62
|
+
"webpack-cli": "^5.1.4",
|
|
63
|
+
"webpack-dev-server": "^4.15.1",
|
|
64
|
+
"@babel/core": "^7.26.0",
|
|
65
|
+
"@babel/preset-env": "^7.26.0",
|
|
66
|
+
"@types/jest": "^29.5.14",
|
|
67
|
+
"babel-jest": "^29.7.0",
|
|
68
|
+
"jest": "^29.7.0",
|
|
69
|
+
"prettier": "^3.4.2",
|
|
70
|
+
"ts-jest": "^29.2.5"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
}
|
|
33
74
|
}
|
|
75
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export declare class BaseApi {
|
|
12
|
+
private _servicePtr;
|
|
13
|
+
constructor(ptr: number);
|
|
14
|
+
get servicePtr(): number;
|
|
15
|
+
destroyRefs(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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.BaseApi = void 0;
|
|
14
|
+
class BaseApi {
|
|
15
|
+
_servicePtr;
|
|
16
|
+
constructor(ptr) {
|
|
17
|
+
this._servicePtr = ptr;
|
|
18
|
+
}
|
|
19
|
+
get servicePtr() {
|
|
20
|
+
if (this._servicePtr < 0) {
|
|
21
|
+
throw new Error("This API instance is no longer valid because the connection associated with it has been closed.");
|
|
22
|
+
}
|
|
23
|
+
return this._servicePtr;
|
|
24
|
+
}
|
|
25
|
+
destroyRefs() {
|
|
26
|
+
this._servicePtr = -1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.BaseApi = BaseApi;
|
|
@@ -0,0 +1,45 @@
|
|
|
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 { ConnectionNative } from "../api/ConnectionNative";
|
|
13
|
+
import { PagingQuery, PagingList, Context } from "../Types";
|
|
14
|
+
import { BaseNative } from "../api/BaseNative";
|
|
15
|
+
export declare class Connection extends BaseApi {
|
|
16
|
+
private native;
|
|
17
|
+
apisRefs: {
|
|
18
|
+
[apiId: string]: {
|
|
19
|
+
_apiServicePtr: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
nativeApisDeps: {
|
|
23
|
+
[apiId: string]: BaseNative;
|
|
24
|
+
};
|
|
25
|
+
constructor(native: ConnectionNative, ptr: number);
|
|
26
|
+
/**
|
|
27
|
+
* Gets the ID of the current connection.
|
|
28
|
+
*
|
|
29
|
+
* @returns {number} ID of the connection
|
|
30
|
+
*/
|
|
31
|
+
getConnectionId(): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Gets a list of Contexts available for the user.
|
|
34
|
+
*
|
|
35
|
+
* @param pagingQuery struct with list query parameters
|
|
36
|
+
* @returns {PagingList<Context>} struct containing a list of Contexts
|
|
37
|
+
*/
|
|
38
|
+
listContexts(pagingQuery: PagingQuery): Promise<PagingList<Context>>;
|
|
39
|
+
/**
|
|
40
|
+
* Disconnects from the Platform backend.
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
disconnect(): Promise<void>;
|
|
44
|
+
private freeApis;
|
|
45
|
+
}
|