@may-db/core 0.1.0 → 0.1.1
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/README.md +98 -0
- package/dist/MayDb.d.ts +26 -9
- package/dist/MayDb.d.ts.map +1 -1
- package/dist/MayDb.js +114 -74
- package/dist/MayDb.js.map +1 -1
- package/dist/Room.d.ts +40 -57
- package/dist/Room.d.ts.map +1 -1
- package/dist/Room.js +212 -232
- package/dist/Room.js.map +1 -1
- package/dist/authStorage.d.ts +7 -7
- package/dist/authStorage.d.ts.map +1 -1
- package/dist/authStorage.js +8 -8
- package/dist/authStorage.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/loginFlow.d.ts +10 -3
- package/dist/loginFlow.d.ts.map +1 -1
- package/dist/loginFlow.js +19 -14
- package/dist/loginFlow.js.map +1 -1
- package/dist/matrix-crdt-shim.d.ts +43 -0
- package/dist/matrix-crdt-shim.d.ts.map +1 -0
- package/dist/matrix-crdt-shim.js +2 -0
- package/dist/matrix-crdt-shim.js.map +1 -0
- package/dist/singletonRoom.d.ts.map +1 -1
- package/dist/singletonRoom.js +5 -36
- package/dist/singletonRoom.js.map +1 -1
- package/dist/types.d.ts +7 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { MayDb } from "./MayDb";
|
|
2
|
-
export { Room } from "./Room";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { getOrCreateSingletonRoomId } from "./singletonRoom";
|
|
2
|
+
export { Room, type RoomDelegate } from "./Room";
|
|
3
|
+
export { Auth, startSsoLogin, completeSsoLogin, } from "./loginFlow";
|
|
4
|
+
export { getStoredSession, saveStoredSession, clearStoredSession, getStoredHomeserver, saveStoredHomeserver, clearStoredHomeserver, } from "./authStorage";
|
|
6
5
|
export { isValidMatrixId, extractLocalpart } from "./matrixId";
|
|
7
6
|
export { PRESENCE_EVENT, PRESENCE_TIMEOUT_MS, applyPresenceUpdates, filterRelevantPresenceEvents, isPresenceContent, type PresenceContent, type PresenceUpdate, type RemotePresence, type ToDeviceEvent, } from "./presence";
|
|
8
7
|
export { getUserColor, PRESENCE_COLORS } from "./utils/presenceColors";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,IAAI,EACJ,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { MayDb } from "./MayDb";
|
|
2
2
|
export { Room } from "./Room";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { getOrCreateSingletonRoomId } from "./singletonRoom";
|
|
3
|
+
export { Auth, startSsoLogin, completeSsoLogin, } from "./loginFlow";
|
|
4
|
+
export { getStoredSession, saveStoredSession, clearStoredSession, getStoredHomeserver, saveStoredHomeserver, clearStoredHomeserver, } from "./authStorage";
|
|
6
5
|
export { isValidMatrixId, extractLocalpart } from "./matrixId";
|
|
7
6
|
export { PRESENCE_EVENT, PRESENCE_TIMEOUT_MS, applyPresenceUpdates, filterRelevantPresenceEvents, isPresenceContent, } from "./presence";
|
|
8
7
|
export { getUserColor, PRESENCE_COLORS } from "./utils/presenceColors";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAqB,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,IAAI,EACJ,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,GAKlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,SAAS,CAAC"}
|
package/dist/loginFlow.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { getStoredSession, clearStoredSession } from "./authStorage";
|
|
2
|
+
import type { Session } from "./types";
|
|
3
|
+
export declare function startSsoLogin(): void;
|
|
4
|
+
export declare function completeSsoLogin(): Promise<Session | null>;
|
|
5
|
+
export declare const Auth: {
|
|
6
|
+
startSsoLogin: typeof startSsoLogin;
|
|
7
|
+
completeSsoLogin: typeof completeSsoLogin;
|
|
8
|
+
getStoredSession: typeof getStoredSession;
|
|
9
|
+
clearStoredSession: typeof clearStoredSession;
|
|
10
|
+
};
|
|
4
11
|
//# sourceMappingURL=loginFlow.d.ts.map
|
package/dist/loginFlow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loginFlow.d.ts","sourceRoot":"","sources":["../src/loginFlow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loginFlow.d.ts","sourceRoot":"","sources":["../src/loginFlow.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAiCvC,wBAAgB,aAAa,IAAI,IAAI,CAQpC;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAoBhE;AAED,eAAO,MAAM,IAAI;;;;;CAKhB,CAAC"}
|
package/dist/loginFlow.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function startLogin() {
|
|
3
|
-
// For now, just login with matrix.org all the time. Later, findhomeserver.com will make this good.
|
|
4
|
-
const homeserver = "https://matrix.org";
|
|
5
|
-
saveHomeserver(homeserver);
|
|
6
|
-
const redirectUrl = encodeURIComponent(window.location.origin + window.location.pathname);
|
|
7
|
-
window.location.href = `${homeserver}/_matrix/client/v3/login/sso/redirect?redirectUrl=${redirectUrl}`;
|
|
8
|
-
}
|
|
1
|
+
import { saveStoredSession, saveStoredHomeserver, getStoredHomeserver, clearStoredHomeserver, getStoredSession, clearStoredSession, } from "./authStorage";
|
|
9
2
|
async function exchangeLoginToken(homeserver, loginToken) {
|
|
10
3
|
const response = await fetch(`${homeserver}/_matrix/client/v3/login`, {
|
|
11
4
|
method: "POST",
|
|
@@ -29,20 +22,32 @@ async function exchangeLoginToken(homeserver, loginToken) {
|
|
|
29
22
|
deviceId: data.device_id,
|
|
30
23
|
};
|
|
31
24
|
}
|
|
32
|
-
export
|
|
25
|
+
export function startSsoLogin() {
|
|
26
|
+
const homeserver = "https://matrix.org";
|
|
27
|
+
saveStoredHomeserver(homeserver);
|
|
28
|
+
const redirectUrl = encodeURIComponent(window.location.origin + window.location.pathname);
|
|
29
|
+
window.location.href = `${homeserver}/_matrix/client/v3/login/sso/redirect?redirectUrl=${redirectUrl}`;
|
|
30
|
+
}
|
|
31
|
+
export async function completeSsoLogin() {
|
|
33
32
|
const params = new URLSearchParams(window.location.search);
|
|
34
33
|
const loginToken = params.get("loginToken");
|
|
35
34
|
if (!loginToken) {
|
|
36
35
|
return null;
|
|
37
36
|
}
|
|
38
37
|
window.history.replaceState({}, document.title, window.location.pathname);
|
|
39
|
-
const homeserver =
|
|
38
|
+
const homeserver = getStoredHomeserver();
|
|
40
39
|
if (!homeserver) {
|
|
41
40
|
throw new Error("No homeserver stored for SSO callback");
|
|
42
41
|
}
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return
|
|
42
|
+
const session = await exchangeLoginToken(homeserver, loginToken);
|
|
43
|
+
saveStoredSession(session);
|
|
44
|
+
clearStoredHomeserver();
|
|
45
|
+
return session;
|
|
47
46
|
}
|
|
47
|
+
export const Auth = {
|
|
48
|
+
startSsoLogin,
|
|
49
|
+
completeSsoLogin,
|
|
50
|
+
getStoredSession,
|
|
51
|
+
clearStoredSession,
|
|
52
|
+
};
|
|
48
53
|
//# sourceMappingURL=loginFlow.js.map
|
package/dist/loginFlow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loginFlow.js","sourceRoot":"","sources":["../src/loginFlow.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"loginFlow.js","sourceRoot":"","sources":["../src/loginFlow.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAGvB,KAAK,UAAU,kBAAkB,CAC/B,UAAkB,EAClB,UAAkB;IAElB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,UAAU,0BAA0B,EAAE;QACpE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,UAAU;SAClB,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,IAAI,GACR,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAExB,OAAO;QACL,UAAU;QACV,WAAW,EAAE,IAAI,CAAC,YAAY;QAC9B,MAAM,EAAE,IAAI,CAAC,OAAO;QACpB,QAAQ,EAAE,IAAI,CAAC,SAAS;KACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,MAAM,UAAU,GAAG,oBAAoB,CAAC;IACxC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAEjC,MAAM,WAAW,GAAG,kBAAkB,CACpC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAClD,CAAC;IACF,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,UAAU,qDAAqD,WAAW,EAAE,CAAC;AACzG,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAE5C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE1E,MAAM,UAAU,GAAG,mBAAmB,EAAE,CAAC;IACzC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACjE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC3B,qBAAqB,EAAE,CAAC;IAExB,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,aAAa;IACb,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;CACnB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { MatrixClient } from "matrix-js-sdk";
|
|
2
|
+
import type { Awareness } from "y-protocols/awareness";
|
|
3
|
+
import type { Doc } from "yjs";
|
|
4
|
+
declare module "matrix-crdt" {
|
|
5
|
+
interface MatrixProviderOptions {
|
|
6
|
+
writer?: {
|
|
7
|
+
flushInterval?: number;
|
|
8
|
+
retryIfForbiddenInterval?: number;
|
|
9
|
+
};
|
|
10
|
+
translator?: {
|
|
11
|
+
updatesAsRegularMessages?: boolean;
|
|
12
|
+
updateEventType?: string;
|
|
13
|
+
snapshotEventType?: string;
|
|
14
|
+
};
|
|
15
|
+
reader?: {
|
|
16
|
+
snapshotInterval?: number;
|
|
17
|
+
};
|
|
18
|
+
enableExperimentalWebrtcSync?: boolean;
|
|
19
|
+
}
|
|
20
|
+
type RoomConfig = {
|
|
21
|
+
type: "id";
|
|
22
|
+
id: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "alias";
|
|
25
|
+
alias: string;
|
|
26
|
+
};
|
|
27
|
+
type Event<T> = (listener: (e: T) => void) => {
|
|
28
|
+
dispose(): void;
|
|
29
|
+
};
|
|
30
|
+
class MatrixProvider {
|
|
31
|
+
constructor(doc: Doc, matrixClient: MatrixClient, room: RoomConfig, awareness?: Awareness, opts?: MatrixProviderOptions);
|
|
32
|
+
initialize(): void;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
readonly canWrite: boolean;
|
|
35
|
+
readonly roomId: string | undefined;
|
|
36
|
+
onDocumentAvailable: Event<void>;
|
|
37
|
+
onDocumentUnavailable: Event<void>;
|
|
38
|
+
onReceivedEvents: Event<void>;
|
|
39
|
+
onCanWriteChanged: Event<void>;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=matrix-crdt-shim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix-crdt-shim.d.ts","sourceRoot":"","sources":["../src/matrix-crdt-shim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK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AAC,IAAI,CAAC,CAAC;KAChC;CACF;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix-crdt-shim.js","sourceRoot":"","sources":["../src/matrix-crdt-shim.ts"],"names":[],"mappings":"AAiDA,OAAO,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singletonRoom.d.ts","sourceRoot":"","sources":["../src/singletonRoom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,KAAK,EACT,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"singletonRoom.d.ts","sourceRoot":"","sources":["../src/singletonRoom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,KAAK,EACT,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAMjB"}
|
package/dist/singletonRoom.js
CHANGED
|
@@ -1,39 +1,8 @@
|
|
|
1
1
|
export async function getOrCreateSingletonRoomId(db, accountDataKey, roomName) {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
const accountData = (await matrixClient.getAccountDataFromServer(namespace));
|
|
9
|
-
roomId = accountData?.[accountDataKey] ?? null;
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
// No account data yet
|
|
13
|
-
}
|
|
14
|
-
if (roomId) {
|
|
15
|
-
try {
|
|
16
|
-
if (!matrixClient.getRoom(roomId)) {
|
|
17
|
-
await matrixClient.joinRoom(roomId);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// Room not accessible, create a new one
|
|
22
|
-
roomId = null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (!roomId) {
|
|
26
|
-
roomId = await db.createMatrixRoom(roomName);
|
|
27
|
-
let existingData = {};
|
|
28
|
-
try {
|
|
29
|
-
existingData =
|
|
30
|
-
(await matrixClient.getAccountDataFromServer(namespace)) || {};
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
// No existing data
|
|
34
|
-
}
|
|
35
|
-
await matrixClient.setAccountData(namespace, { ...existingData, [accountDataKey]: roomId });
|
|
36
|
-
}
|
|
37
|
-
return roomId;
|
|
2
|
+
const room = await db.rooms.getOrCreateSingleton({
|
|
3
|
+
key: accountDataKey,
|
|
4
|
+
name: roomName,
|
|
5
|
+
});
|
|
6
|
+
return room.id;
|
|
38
7
|
}
|
|
39
8
|
//# sourceMappingURL=singletonRoom.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singletonRoom.js","sourceRoot":"","sources":["../src/singletonRoom.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,EAAS,EACT,cAAsB,EACtB,QAAgB;IAEhB,MAAM,
|
|
1
|
+
{"version":3,"file":"singletonRoom.js","sourceRoot":"","sources":["../src/singletonRoom.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,EAAS,EACT,cAAsB,EACtB,QAAgB;IAEhB,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,oBAAoB,CAAC;QAC/C,GAAG,EAAE,cAAc;QACnB,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,EAAE,CAAC;AACjB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type * as sdk from "matrix-js-sdk";
|
|
2
|
-
export interface
|
|
2
|
+
export interface Session {
|
|
3
3
|
homeserver: string;
|
|
4
4
|
accessToken: string;
|
|
5
5
|
userId: string;
|
|
6
6
|
deviceId: string;
|
|
7
7
|
}
|
|
8
|
-
export type AccessLevel = "
|
|
8
|
+
export type AccessLevel = "viewer" | "editor" | "owner";
|
|
9
9
|
export interface RoomMember {
|
|
10
10
|
userId: string;
|
|
11
11
|
displayName: string;
|
|
@@ -23,13 +23,14 @@ export interface InviteMonitorOptions {
|
|
|
23
23
|
pollIntervalMs?: number;
|
|
24
24
|
}
|
|
25
25
|
export type RoomStatus = "disconnected" | "connecting" | "connected" | "error";
|
|
26
|
-
export interface
|
|
27
|
-
|
|
26
|
+
export interface RoomState {
|
|
27
|
+
status: RoomStatus;
|
|
28
|
+
canEdit: boolean;
|
|
29
|
+
name: string | null;
|
|
28
30
|
}
|
|
29
31
|
export type MatrixClient = sdk.MatrixClient;
|
|
30
32
|
/**
|
|
31
|
-
* Interface for what a
|
|
32
|
-
* This allows Room to work with different client implementations.
|
|
33
|
+
* Interface for what a room instance needs from its host client.
|
|
33
34
|
*/
|
|
34
35
|
export interface RoomServices {
|
|
35
36
|
matrixClient: MatrixClient;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,eAAe,CAAC;AAE1C,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,eAAe,CAAC;AAE1C,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,OA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