@simplito/privmx-webendpoint
Version:
PrivMX Web Endpoint library
103 lines (102 loc) • 3.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MOCK_CUSTOM_EVENT = exports.MOCK_LIB_CONNECTED_EVENT = exports.MOCK_CONNECTION_USER_STATUS_EVENT = exports.MOCK_CONNECTION_USER_ADDED_EVENT = exports.MOCK_THREAD_MESSAGE_DELETED_EVENT = exports.MOCK_THREAD_CREATED_EVENT = exports.MOCK_STORE_FILE_DELETED_EVENT = exports.MOCK_STORE_CREATED_EVENT = exports.MOCK_INBOX_ENTRY_DELETED_EVENT = exports.MOCK_INBOX_CREATED_EVENT = void 0;
exports.createBaseEvent = createBaseEvent;
function createBaseEvent(subsId) {
return {
type: "inboxCreated",
data: {},
channel: `inbox`,
connectionId: 1,
subscriptions: [subsId],
version: 0,
timestamp: Date.now(),
};
}
const MOCK_INBOX_CREATED_EVENT = (subsId) => ({
...createBaseEvent(subsId),
type: "inboxCreated",
channel: `inbox`,
});
exports.MOCK_INBOX_CREATED_EVENT = MOCK_INBOX_CREATED_EVENT;
const MOCK_INBOX_ENTRY_DELETED_EVENT = (inboxID, subsId) => ({
...createBaseEvent(subsId),
type: "inboxEntryDeleted",
channel: `inbox/${inboxID}/entries`,
});
exports.MOCK_INBOX_ENTRY_DELETED_EVENT = MOCK_INBOX_ENTRY_DELETED_EVENT;
const MOCK_STORE_CREATED_EVENT = (subsId) => ({
...createBaseEvent(subsId),
type: "storeUpdated",
channel: `store`,
});
exports.MOCK_STORE_CREATED_EVENT = MOCK_STORE_CREATED_EVENT;
const MOCK_STORE_FILE_DELETED_EVENT = (storeID, subsId) => ({
...createBaseEvent(subsId),
type: "storeFileCreated",
channel: `store/${storeID}/files`,
});
exports.MOCK_STORE_FILE_DELETED_EVENT = MOCK_STORE_FILE_DELETED_EVENT;
const MOCK_THREAD_CREATED_EVENT = (subsId) => ({
...createBaseEvent(subsId),
type: "threadUpdated",
channel: `thread`,
});
exports.MOCK_THREAD_CREATED_EVENT = MOCK_THREAD_CREATED_EVENT;
const MOCK_THREAD_MESSAGE_DELETED_EVENT = (threadID, subsId) => ({
...createBaseEvent(subsId),
type: "threadNewMessage",
channel: `thread/${threadID}/messages`,
});
exports.MOCK_THREAD_MESSAGE_DELETED_EVENT = MOCK_THREAD_MESSAGE_DELETED_EVENT;
const MOCK_CONNECTION_USER_ADDED_EVENT = (subsId) => ({
...createBaseEvent(subsId),
type: "contextUserAdded",
channel: "context/userAdded",
data: {
contextId: "ctx-1",
user: {
userId: "user-1",
pubKey: "pub-1",
},
},
});
exports.MOCK_CONNECTION_USER_ADDED_EVENT = MOCK_CONNECTION_USER_ADDED_EVENT;
const MOCK_CONNECTION_USER_STATUS_EVENT = (subsId) => ({
...createBaseEvent(subsId),
type: "contextUserStatusChanged",
channel: "context/userStatus",
data: {
contextId: "ctx-1",
users: [
{
user: {
userId: "user-1",
pubKey: "pub-1",
},
action: "login",
},
],
},
});
exports.MOCK_CONNECTION_USER_STATUS_EVENT = MOCK_CONNECTION_USER_STATUS_EVENT;
const MOCK_LIB_CONNECTED_EVENT = (connectionId) => ({
...createBaseEvent("ignored"),
type: "libConnected",
channel: "channel/lib_connected",
connectionId,
});
exports.MOCK_LIB_CONNECTED_EVENT = MOCK_LIB_CONNECTED_EVENT;
const MOCK_CUSTOM_EVENT = (subsId, contextId = "ctx-1", channelName = "custom-channel") => ({
...createBaseEvent(subsId),
type: "contextCustom",
channel: `context/${contextId}/${channelName}`,
data: {
contextId,
userId: "user-1",
payload: new Uint8Array([1, 2, 3]),
statusCode: 0,
schemaVersion: 5,
},
});
exports.MOCK_CUSTOM_EVENT = MOCK_CUSTOM_EVENT;