@matrix-widget-toolkit/api 3.4.2 → 4.0.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 (64) hide show
  1. package/build/cjs/api/WidgetApiImpl.d.cts +179 -0
  2. package/build/cjs/api/WidgetApiImpl.test.d.cts +1 -0
  3. package/build/cjs/api/extras/capabilities.d.cts +12 -0
  4. package/build/cjs/api/extras/capabilities.test.d.cts +1 -0
  5. package/build/cjs/api/extras/displayName.d.cts +12 -0
  6. package/build/cjs/api/extras/displayName.test.d.cts +1 -0
  7. package/build/cjs/api/extras/events.d.cts +15 -0
  8. package/build/cjs/api/extras/events.test.d.cts +1 -0
  9. package/build/cjs/api/extras/index.d.cts +14 -0
  10. package/build/cjs/api/extras/navigateTo.d.cts +24 -0
  11. package/build/cjs/api/extras/navigateTo.test.d.cts +1 -0
  12. package/build/cjs/api/extras/originServerTs.d.cts +10 -0
  13. package/build/cjs/api/extras/originServerTs.test.d.cts +1 -0
  14. package/build/cjs/api/extras/powerLevel.d.cts +105 -0
  15. package/build/cjs/api/extras/powerLevel.test.d.cts +1 -0
  16. package/build/cjs/api/extras/redactions.d.cts +42 -0
  17. package/build/cjs/api/extras/redactions.test.d.cts +1 -0
  18. package/build/cjs/api/extras/relatesTo.d.cts +60 -0
  19. package/build/cjs/api/extras/relatesTo.test.d.cts +1 -0
  20. package/build/cjs/api/extras/roomMember.d.cts +35 -0
  21. package/build/cjs/api/extras/roomMember.test.d.cts +1 -0
  22. package/build/cjs/api/index.d.cts +8 -0
  23. package/build/cjs/api/parameters.d.cts +58 -0
  24. package/build/cjs/api/parameters.test.d.cts +1 -0
  25. package/build/cjs/api/registration.d.cts +33 -0
  26. package/build/cjs/api/registration.test.d.cts +1 -0
  27. package/build/cjs/api/types.d.cts +466 -0
  28. package/build/cjs/api/utils.d.cts +20 -0
  29. package/build/cjs/api/utils.test.d.cts +1 -0
  30. package/build/cjs/{index.js → index.cjs} +100 -48
  31. package/build/cjs/index.d.cts +5 -0
  32. package/build/esm/api/WidgetApiImpl.d.ts +179 -0
  33. package/build/esm/api/WidgetApiImpl.test.d.ts +1 -0
  34. package/build/esm/api/extras/capabilities.d.ts +12 -0
  35. package/build/esm/api/extras/capabilities.test.d.ts +1 -0
  36. package/build/esm/api/extras/displayName.d.ts +12 -0
  37. package/build/esm/api/extras/displayName.test.d.ts +1 -0
  38. package/build/esm/api/extras/events.d.ts +15 -0
  39. package/build/esm/api/extras/events.test.d.ts +1 -0
  40. package/build/esm/api/extras/index.d.ts +14 -0
  41. package/build/esm/api/extras/navigateTo.d.ts +24 -0
  42. package/build/esm/api/extras/navigateTo.test.d.ts +1 -0
  43. package/build/esm/api/extras/originServerTs.d.ts +10 -0
  44. package/build/esm/api/extras/originServerTs.test.d.ts +1 -0
  45. package/build/esm/api/extras/powerLevel.d.ts +105 -0
  46. package/build/esm/api/extras/powerLevel.test.d.ts +1 -0
  47. package/build/esm/api/extras/redactions.d.ts +42 -0
  48. package/build/esm/api/extras/redactions.test.d.ts +1 -0
  49. package/build/esm/api/extras/relatesTo.d.ts +60 -0
  50. package/build/esm/api/extras/relatesTo.test.d.ts +1 -0
  51. package/build/esm/api/extras/roomMember.d.ts +35 -0
  52. package/build/esm/api/extras/roomMember.test.d.ts +1 -0
  53. package/build/esm/api/index.d.ts +8 -0
  54. package/build/esm/api/parameters.d.ts +58 -0
  55. package/build/esm/api/parameters.test.d.ts +1 -0
  56. package/build/esm/api/registration.d.ts +33 -0
  57. package/build/esm/api/registration.test.d.ts +1 -0
  58. package/build/esm/api/types.d.ts +466 -0
  59. package/build/esm/api/utils.d.ts +20 -0
  60. package/build/esm/api/utils.test.d.ts +1 -0
  61. package/build/esm/index.d.ts +5 -0
  62. package/build/esm/index.js +99 -49
  63. package/build/index.d.ts +17 -2
  64. package/package.json +25 -16
@@ -0,0 +1,179 @@
1
+ import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidgetApiRequestData, WidgetApi as MatrixWidgetApi, ModalButtonID, Symbols, WidgetEventCapability } from 'matrix-widget-api';
2
+ import { Observable } from 'rxjs';
3
+ import { RoomEvent, StateEvent, ToDeviceMessageEvent, TurnServer, WidgetApi, WidgetConfig, WidgetParameters } from './types';
4
+ /**
5
+ * Options for the {@link WidgetApiImpl.create} function.
6
+ */
7
+ export type WidgetApiOptions = {
8
+ /**
9
+ * Optional initial capabilities that should be requested from the user on
10
+ * load.
11
+ */
12
+ capabilities?: Array<WidgetEventCapability | Capability>;
13
+ /**
14
+ * Enable the the pop-out button for pinned widgets that support running
15
+ * without the Widget API.
16
+ */
17
+ supportStandalone?: boolean;
18
+ };
19
+ /**
20
+ * Implementation of the API from the widget to the client.
21
+ *
22
+ * @remarks Widget API is specified here:
23
+ * https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit#heading=h.9rn9lt6ctkgi
24
+ */
25
+ export declare class WidgetApiImpl implements WidgetApi {
26
+ /**
27
+ * Provide access to the underlying widget API from `matrix-widget-sdk`.
28
+ *
29
+ * @remarks Normally there is no need to use it, however if features are
30
+ * missing from `WidgetApi` it can be handy to work with the
31
+ * original API.
32
+ */
33
+ readonly matrixWidgetApi: MatrixWidgetApi;
34
+ /** {@inheritDoc WidgetApi.widgetId} */
35
+ readonly widgetId: string;
36
+ /** {@inheritDoc WidgetApi.widgetParameters} */
37
+ readonly widgetParameters: WidgetParameters;
38
+ /**
39
+ * Initialize a new widget API instance and wait till it is ready.
40
+ * There should only be one instance of the widget API. The widget API should
41
+ * be created as early as possible when starting the application. This is
42
+ * required to match the timing of the API connection establishment with the
43
+ * client, especially in Safari. Therefore it is recommended to create it
44
+ * inside the entrypoint, before initializing rendering engines like react.
45
+ *
46
+ * @param param0 - {@link WidgetApiOptions}
47
+ *
48
+ * @returns A widget API instance ready to use.
49
+ */
50
+ static create({ capabilities, supportStandalone, }?: WidgetApiOptions): Promise<WidgetApi>;
51
+ private widgetConfig;
52
+ private outstandingCapabilitiesRequest;
53
+ private outstandingOpenIDConnectTokenRequest;
54
+ private cachedOpenIdToken;
55
+ private readonly events$;
56
+ private readonly toDeviceMessages$;
57
+ private readonly initialCapabilities;
58
+ constructor(
59
+ /**
60
+ * Provide access to the underlying widget API from `matrix-widget-sdk`.
61
+ *
62
+ * @remarks Normally there is no need to use it, however if features are
63
+ * missing from `WidgetApi` it can be handy to work with the
64
+ * original API.
65
+ */
66
+ matrixWidgetApi: MatrixWidgetApi,
67
+ /** {@inheritDoc WidgetApi.widgetId} */
68
+ widgetId: string,
69
+ /** {@inheritDoc WidgetApi.widgetParameters} */
70
+ widgetParameters: WidgetParameters, { capabilities, supportStandalone }?: WidgetApiOptions);
71
+ /**
72
+ * Initialize the widget API and wait till a connection with the client is
73
+ * fully established.
74
+ *
75
+ * Waits till the user has approved the initial set of capabilities. The
76
+ * method doesn't fail if the user doesn't approve all of them. It is
77
+ * required to check manually afterwards.
78
+ * In case of modal widgets it waits till the `widgetConfig` is received.
79
+ *
80
+ * @remarks Should only be called once during startup.
81
+ */
82
+ initialize(): Promise<void>;
83
+ /** {@inheritDoc WidgetApi.getWidgetConfig} */
84
+ getWidgetConfig<T extends IWidgetApiRequestData>(): Readonly<WidgetConfig<T> | undefined>;
85
+ /** {@inheritDoc WidgetApi.rerequestInitialCapabilities} */
86
+ rerequestInitialCapabilities(): Promise<void>;
87
+ /** {@inheritDoc WidgetApi.hasInitialCapabilities} */
88
+ hasInitialCapabilities(): boolean;
89
+ /** {@inheritDoc WidgetApi.requestCapabilities} */
90
+ requestCapabilities(capabilities: Array<WidgetEventCapability | Capability>): Promise<void>;
91
+ private requestCapabilitiesInternal;
92
+ /** {@inheritDoc WidgetApi.hasCapabilities} */
93
+ hasCapabilities(capabilities: Array<WidgetEventCapability | Capability>): boolean;
94
+ /** {@inheritDoc WidgetApi.receiveSingleStateEvent} */
95
+ receiveSingleStateEvent<T>(eventType: string, stateKey?: string): Promise<StateEvent<T> | undefined>;
96
+ /** {@inheritDoc WidgetApi.receiveStateEvents} */
97
+ receiveStateEvents<T>(eventType: string, { stateKey, roomIds, }?: {
98
+ stateKey?: string;
99
+ roomIds?: string[] | Symbols.AnyRoom;
100
+ }): Promise<StateEvent<T>[]>;
101
+ /** {@inheritDoc WidgetApi.observeStateEvents} */
102
+ observeStateEvents<T>(eventType: string, { stateKey, roomIds, }?: {
103
+ stateKey?: string;
104
+ roomIds?: string[] | Symbols.AnyRoom;
105
+ }): Observable<StateEvent<T>>;
106
+ /** {@inheritDoc WidgetApi.sendStateEvent} */
107
+ sendStateEvent<T>(eventType: string, content: T, { roomId, stateKey }?: {
108
+ roomId?: string;
109
+ stateKey?: string;
110
+ }): Promise<ISendEventFromWidgetResponseData>;
111
+ /** {@inheritDoc WidgetApi.receiveRoomEvents} */
112
+ receiveRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
113
+ messageType?: string;
114
+ roomIds?: string[] | Symbols.AnyRoom;
115
+ }): Promise<Array<RoomEvent<T>>>;
116
+ /** {@inheritDoc WidgetApi.observeRoomEvents} */
117
+ observeRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
118
+ messageType?: string;
119
+ roomIds?: string[] | Symbols.AnyRoom;
120
+ }): Observable<RoomEvent<T>>;
121
+ /** {@inheritDoc WidgetApi.sendRoomEvent} */
122
+ sendRoomEvent<T>(eventType: string, content: T, { roomId }?: {
123
+ roomId?: string;
124
+ }): Promise<RoomEvent<T>>;
125
+ /** {@inheritDoc WidgetApi.readEventRelations} */
126
+ readEventRelations(eventId: string, options?: {
127
+ roomId?: string;
128
+ limit?: number;
129
+ from?: string;
130
+ relationType?: string;
131
+ eventType?: string;
132
+ direction?: 'f' | 'b';
133
+ }): Promise<{
134
+ chunk: Array<RoomEvent | StateEvent>;
135
+ nextToken?: string;
136
+ }>;
137
+ /** {@inheritDoc WidgetApi.sendToDeviceMessage} */
138
+ sendToDeviceMessage<T>(eventType: string, encrypted: boolean, content: {
139
+ [userId: string]: {
140
+ [deviceId: string | '*']: T;
141
+ };
142
+ }): Promise<void>;
143
+ /** {@inheritDoc WidgetApi.observeToDeviceMessages} */
144
+ observeToDeviceMessages<T>(eventType: string): Observable<ToDeviceMessageEvent<T>>;
145
+ /** {@inheritDoc WidgetApi.openModal} */
146
+ openModal<T extends Record<string, unknown> = Record<string, unknown>, U extends IModalWidgetCreateData = IModalWidgetCreateData>(pathName: string, name: string, options?: {
147
+ buttons?: IModalWidgetOpenRequestDataButton[];
148
+ data?: U;
149
+ }): Promise<T | undefined>;
150
+ /** {@inheritDoc WidgetApi.setModalButtonEnabled} */
151
+ setModalButtonEnabled(buttonId: ModalButtonID, isEnabled: boolean): Promise<void>;
152
+ /** {@inheritDoc WidgetApi.observeModalButtons} */
153
+ observeModalButtons(): Observable<ModalButtonID>;
154
+ /** {@inheritDoc WidgetApi.closeModal} */
155
+ closeModal<T extends IModalWidgetReturnData>(data?: T): Promise<void>;
156
+ /** {@inheritdoc WidgetApi.navigateTo} */
157
+ navigateTo(uri: string): Promise<void>;
158
+ /** {@inheritdoc WidgetApi.requestOpenIDConnectToken} */
159
+ requestOpenIDConnectToken(): Promise<IOpenIDCredentials>;
160
+ private requestOpenIDConnectTokenInternal;
161
+ /** {@inheritdoc WidgetApi.observeTurnServers} */
162
+ observeTurnServers(): Observable<TurnServer>;
163
+ /** {@inheritdoc WidgetApi.searchUserDirectory} */
164
+ searchUserDirectory(searchTerm: string, options?: {
165
+ limit?: number | undefined;
166
+ } | undefined): Promise<{
167
+ results: Array<{
168
+ userId: string;
169
+ displayName?: string;
170
+ avatarUrl?: string;
171
+ }>;
172
+ }>;
173
+ /** {@inheritdoc WidgetApi.getMediaConfig} */
174
+ getMediaConfig(): Promise<IGetMediaConfigActionFromWidgetResponseData>;
175
+ /** {@inheritdoc WidgetApi.uploadFile} */
176
+ uploadFile(file: XMLHttpRequestBodyInit): Promise<IUploadFileActionFromWidgetResponseData>;
177
+ /** {@inheritdoc WidgetApi.downloadFile} */
178
+ downloadFile(contentUrl: string): Promise<IDownloadFileActionFromWidgetResponseData>;
179
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Symbols } from 'matrix-widget-api';
2
+ /**
3
+ * Generate a list of capabilities to access the timeline of other rooms.
4
+ * If enabled, all previously or future capabilities will apply to _all_
5
+ * selected rooms.
6
+ * If `Symbols.AnyRoom` is passed, this is expanded to all joined
7
+ * or invited rooms the client is able to see, current and future.
8
+ *
9
+ * @param roomIds - a list of room ids or `@link Symbols.AnyRoom`.
10
+ * @returns the generated capabilities.
11
+ */
12
+ export declare function generateRoomTimelineCapabilities(roomIds: string[] | Symbols.AnyRoom): string[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { StateEvent } from '../types';
2
+ import { RoomMemberStateEventContent } from './roomMember';
3
+ /**
4
+ * Generate a unique displayname of a user that is consistent across Matrix clients.
5
+ *
6
+ * @remarks The algorithm is based on https://spec.matrix.org/v1.1/client-server-api/#calculating-the-display-name-for-a-user
7
+ *
8
+ * @param member - the member to generate a name for.
9
+ * @param allRoomMembers - a list of all members of the same room.
10
+ * @returns the displayname that is unique in given the set of all room members.
11
+ */
12
+ export declare function getRoomMemberDisplayName(member: StateEvent<RoomMemberStateEventContent>, allRoomMembers?: StateEvent<RoomMemberStateEventContent>[]): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { RoomEvent, StateEvent } from '../types';
2
+ /**
3
+ * Check if the given event is a {@link StateEvent}.
4
+ *
5
+ * @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
6
+ * @returns True, if the event is a {@link StateEvent}.
7
+ */
8
+ export declare function isStateEvent(event: RoomEvent | StateEvent): event is StateEvent;
9
+ /**
10
+ * Check if the given event is a {@link RoomEvent}.
11
+ *
12
+ * @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
13
+ * @returns True, if the event is a {@link RoomEvent}.
14
+ */
15
+ export declare function isRoomEvent(event: RoomEvent | StateEvent): event is RoomEvent;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ export { generateRoomTimelineCapabilities } from './capabilities';
2
+ export { getRoomMemberDisplayName } from './displayName';
3
+ export { isRoomEvent, isStateEvent } from './events';
4
+ export { WIDGET_CAPABILITY_NAVIGATE, navigateToRoom } from './navigateTo';
5
+ export type { NavigateToRoomOptions } from './navigateTo';
6
+ export { compareOriginServerTS } from './originServerTs';
7
+ export { STATE_EVENT_POWER_LEVELS, calculateUserPowerLevel, hasActionPower, hasRoomEventPower, hasStateEventPower, isValidPowerLevelStateEvent, } from './powerLevel';
8
+ export type { PowerLevelsActions, PowerLevelsStateEvent } from './powerLevel';
9
+ export { ROOM_EVENT_REDACTION, isValidRedactionEvent, observeRedactionEvents, redactEvent, } from './redactions';
10
+ export type { Redaction, RedactionRoomEvent } from './redactions';
11
+ export { getContent, getOriginalEventId, isValidEventWithRelatesTo, } from './relatesTo';
12
+ export type { EventWithRelatesTo, NewContentRelatesTo, RelatesTo, RoomEventOrNewContent, } from './relatesTo';
13
+ export { STATE_EVENT_ROOM_MEMBER, isValidRoomMemberStateEvent, } from './roomMember';
14
+ export type { MembershipState, RoomMemberStateEventContent, } from './roomMember';
@@ -0,0 +1,24 @@
1
+ import { WidgetApi } from '../types';
2
+ /**
3
+ * The capability that needs to be requested in order to navigate to another room.
4
+ */
5
+ export declare const WIDGET_CAPABILITY_NAVIGATE = "org.matrix.msc2931.navigate";
6
+ /**
7
+ * Options for the {@link navigateToRoom} function.
8
+ */
9
+ export type NavigateToRoomOptions = {
10
+ /**
11
+ * Optional, array of one or more homeserver domains to discover the room.
12
+ */
13
+ via?: string[];
14
+ };
15
+ /**
16
+ * Navigate the client to another matrix room.
17
+ *
18
+ * @remarks This requires the {@link WIDGET_CAPABILITY_NAVIGATE} capability.
19
+ *
20
+ * @param widgetApi - the {@link WidgetApi} instance.
21
+ * @param roomId - the room ID.
22
+ * @param opts - {@link NavigateToRoomOptions}
23
+ */
24
+ export declare function navigateToRoom(widgetApi: WidgetApi, roomId: string, opts?: NavigateToRoomOptions): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { RoomEvent } from '../types';
2
+ /**
3
+ * Compares two room events by their origin server timestamp.
4
+ *
5
+ * @param a - A room event
6
+ * @param b - A room event
7
+ * @returns Either zero if the timestamp is equal, \>0 if a is newer, or \<0 if
8
+ * b is newer.
9
+ */
10
+ export declare function compareOriginServerTS<T>(a: RoomEvent<T>, b: RoomEvent<T>): number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,105 @@
1
+ import { StateEvent } from '../types';
2
+ /**
3
+ * The name of the power levels state event.
4
+ */
5
+ export declare const STATE_EVENT_POWER_LEVELS = "m.room.power_levels";
6
+ /**
7
+ * The types of actions.
8
+ */
9
+ export type PowerLevelsActions = 'invite' | 'kick' | 'ban' | 'redact';
10
+ /**
11
+ * The content of an `m.room.power_levels` event.
12
+ */
13
+ export type PowerLevelsStateEvent = {
14
+ events?: {
15
+ [key: string]: number;
16
+ };
17
+ state_default?: number;
18
+ events_default?: number;
19
+ users?: {
20
+ [key: string]: number;
21
+ };
22
+ users_default?: number;
23
+ ban?: number;
24
+ invite?: number;
25
+ kick?: number;
26
+ redact?: number;
27
+ };
28
+ /**
29
+ * Validates that `event` is has a valid structure for a
30
+ * {@link PowerLevelsStateEvent}.
31
+ * @param event - The event to validate.
32
+ * @returns True, if the event is valid.
33
+ */
34
+ export declare function isValidPowerLevelStateEvent(event: StateEvent<unknown>): event is StateEvent<PowerLevelsStateEvent>;
35
+ /**
36
+ * Check if a user has the power to send a specific room event.
37
+ *
38
+ * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
39
+ * @param userId - the id of the user
40
+ * @param eventType - the type of room event
41
+ * @returns if true, the user has the power
42
+ */
43
+ export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
44
+ /**
45
+ * Check if a user has the power to send a specific state event.
46
+ *
47
+ * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
48
+ * @param userId - the id of the user
49
+ * @param eventType - the type of state event
50
+ * @returns if true, the user has the power
51
+ */
52
+ export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
53
+ /**
54
+ * Check if a user has the power to perform a specific action.
55
+ *
56
+ * Supported actions:
57
+ * * invite: Invite a new user into the room
58
+ * * kick: Kick a user from the room
59
+ * * ban: Ban a user from the room
60
+ * * redact: Redact a message from another user
61
+ *
62
+ * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
63
+ * @param userId - the id of the user
64
+ * @param action - the action
65
+ * @returns if true, the user has the power
66
+ */
67
+ export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
68
+ /**
69
+ * Calculate the power level of the user based on a `m.room.power_levels` event.
70
+ *
71
+ * @param powerLevelStateEvent - the content of the `m.room.power_levels` event.
72
+ * @param userId - the ID of the user.
73
+ * @returns the power level of the user.
74
+ */
75
+ export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, userId?: string): number;
76
+ /**
77
+ * Calculate the power level that a user needs send a specific room event.
78
+ *
79
+ * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
80
+ * @param eventType - the type of room event
81
+ * @returns the power level that is needed
82
+ */
83
+ export declare function calculateRoomEventPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, eventType: string): number;
84
+ /**
85
+ * Calculate the power level that a user needs send a specific state event.
86
+ *
87
+ * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
88
+ * @param eventType - the type of state event
89
+ * @returns the power level that is needed
90
+ */
91
+ export declare function calculateStateEventPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, eventType: string): number;
92
+ /**
93
+ * Calculate the power level that a user needs to perform an action.
94
+ *
95
+ * Supported actions:
96
+ * * invite: Invite a new user into the room
97
+ * * kick: Kick a user from the room
98
+ * * ban: Ban a user from the room
99
+ * * redact: Redact a message from another user
100
+ *
101
+ * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
102
+ * @param action - the action
103
+ * @returns the power level that is needed
104
+ */
105
+ export declare function calculateActionPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, action: PowerLevelsActions): number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import { Observable } from 'rxjs';
2
+ import { RoomEvent, WidgetApi } from '../types';
3
+ /**
4
+ * The name of the redaction room event.
5
+ */
6
+ export declare const ROOM_EVENT_REDACTION = "m.room.redaction";
7
+ /**
8
+ * The content of an `m.room.redaction` event.
9
+ */
10
+ export type Redaction = {
11
+ /**
12
+ * The id of the event that is redacted.
13
+ */
14
+ redacts: string;
15
+ };
16
+ /**
17
+ * Types a {@link RoomEvent} to include the properties of a redaction.
18
+ *
19
+ * @remarks The redaction event is a special snowflake. The actual data is
20
+ * outside the content to make it readable without having to decrypt
21
+ * it.
22
+ */
23
+ export type RedactionRoomEvent = RoomEvent<Record<string, never>> & Redaction;
24
+ /**
25
+ * Check whether the format of a redaction event is valid.
26
+ * @param event - The event to check.
27
+ * @returns True if the event format is valid, otherwise false.
28
+ */
29
+ export declare function isValidRedactionEvent(event: RoomEvent<unknown>): event is RedactionRoomEvent;
30
+ /**
31
+ * Redacts an event in the current room.
32
+ * @param widgetApi - An instance of the widget API.
33
+ * @param eventId - The id of the event to redact.
34
+ * @returns The redaction event that was send to the room.
35
+ */
36
+ export declare function redactEvent(widgetApi: WidgetApi, eventId: string): Promise<RedactionRoomEvent>;
37
+ /**
38
+ * Observes redaction events in the current room.
39
+ * @param widgetApi - An instance of the widget API.
40
+ * @returns An observable of validated redaction events.
41
+ */
42
+ export declare function observeRedactionEvents(widgetApi: WidgetApi): Observable<RedactionRoomEvent>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,60 @@
1
+ import { RoomEvent } from '../types';
2
+ /**
3
+ * Defines a relation to another event.
4
+ */
5
+ export type RelatesTo<RelationType extends string> = {
6
+ /**
7
+ * The event id of the other event.
8
+ */
9
+ event_id: string;
10
+ /**
11
+ * The relation to the other event.
12
+ */
13
+ rel_type: RelationType;
14
+ };
15
+ /**
16
+ * Content of a room event that relates to another event.
17
+ */
18
+ export type EventWithRelatesTo<RelationType extends string> = RoomEvent<{
19
+ /**
20
+ * A reference to the event that it relates to.
21
+ */
22
+ 'm.relates_to': RelatesTo<RelationType>;
23
+ }>;
24
+ /**
25
+ * Content of a room event that replaces an existing event with
26
+ * the "m.replace" relation, which means that the content of the
27
+ * previous event is fully replaced.
28
+ */
29
+ export type NewContentRelatesTo<T> = EventWithRelatesTo<'m.replace'>['content'] & {
30
+ /**
31
+ * The new content of the event.
32
+ */
33
+ 'm.new_content': T;
34
+ };
35
+ /**
36
+ * A room event that either contains the content directly or contains an
37
+ * "m.new_content" object.
38
+ */
39
+ export type RoomEventOrNewContent<T = unknown> = RoomEvent<T | NewContentRelatesTo<T>>;
40
+ /**
41
+ * Get the original event id, or the event id of the current event if it
42
+ * doesn't relates to another event.
43
+ * @param event - The room event.
44
+ * @returns The event id of the original event, or the current event id.
45
+ */
46
+ export declare function getOriginalEventId<T>(event: RoomEventOrNewContent<T>): string;
47
+ /**
48
+ * Get the content of the event, independent from whether it contains the
49
+ * content directly or contains a "m.new_content" key.
50
+ * @param event - The room event.
51
+ * @returns Only the content of the room event.
52
+ */
53
+ export declare function getContent<T>(event: RoomEventOrNewContent<T>): T;
54
+ /**
55
+ * Validates that `event` has a valid structure for a
56
+ * {@link EventWithRelatesTo}.
57
+ * @param event - The event to validate.
58
+ * @returns True, if the event is valid.
59
+ */
60
+ export declare function isValidEventWithRelatesTo(event: RoomEvent): event is EventWithRelatesTo<string>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import { StateEvent } from '../types';
2
+ /**
3
+ * The name of the room member state event.
4
+ */
5
+ export declare const STATE_EVENT_ROOM_MEMBER = "m.room.member";
6
+ /**
7
+ * The membership state of a user.
8
+ */
9
+ export type MembershipState = 'join' | 'invite' | 'leave' | 'ban' | 'knock';
10
+ /**
11
+ * The content of an `m.room.member` event.
12
+ *
13
+ * @remarks based on https://github.com/matrix-org/matrix-spec/blob/main/data/event-schemas/schema/m.room.member.yaml
14
+ */
15
+ export type RoomMemberStateEventContent = {
16
+ /**
17
+ * The membership state of the user.
18
+ */
19
+ membership: MembershipState;
20
+ /**
21
+ * The display name for this user, if any.
22
+ */
23
+ displayname?: string | null;
24
+ /**
25
+ * The avatar URL for this user, if any.
26
+ */
27
+ avatar_url?: string | null;
28
+ };
29
+ /**
30
+ * Validates that `event` is has a valid structure for a
31
+ * {@link RoomMemberStateEventContent}.
32
+ * @param event - The event to validate.
33
+ * @returns True, if the event is valid.
34
+ */
35
+ export declare function isValidRoomMemberStateEvent(event: StateEvent<unknown>): event is StateEvent<RoomMemberStateEventContent>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from './extras';
2
+ export { extractRawWidgetParameters, extractWidgetApiParameters, extractWidgetParameters, parseWidgetId, } from './parameters';
3
+ export type { WidgetApiParameters, WidgetId } from './parameters';
4
+ export { generateWidgetRegistrationUrl, hasRequiredWidgetParameters, repairWidgetRegistration, } from './registration';
5
+ export type { RoomEvent, StateEvent, ToDeviceMessageEvent, TurnServer, WidgetApi, WidgetConfig, WidgetParameters, WidgetRegistration, } from './types';
6
+ export { makeEventFromSendStateEventResult, sendStateEventWithEventResult, } from './utils';
7
+ export { WidgetApiImpl } from './WidgetApiImpl';
8
+ export type { WidgetApiOptions } from './WidgetApiImpl';
@@ -0,0 +1,58 @@
1
+ import { WidgetParameters } from './types';
2
+ /**
3
+ * Parameters used to initialize the widget API inside the widget.
4
+ */
5
+ export type WidgetApiParameters = {
6
+ /**
7
+ * The id of the widget.
8
+ */
9
+ widgetId: string;
10
+ /**
11
+ * The origin of the client.
12
+ */
13
+ clientOrigin: string;
14
+ };
15
+ /**
16
+ * Extract the parameters used to initialize the widget API from the current
17
+ * `window.location`.
18
+ * @returns The parameters required for initializing the widget API.
19
+ */
20
+ export declare function extractWidgetApiParameters(): WidgetApiParameters;
21
+ /**
22
+ * Extract the widget parameters from the current `window.location`.
23
+ * @returns The all unprocessed raw widget parameters.
24
+ */
25
+ export declare function extractRawWidgetParameters(): Record<string, string>;
26
+ /**
27
+ * Extract the widget parameters from the current `window.location`.
28
+ * @returns The widget parameters.
29
+ */
30
+ export declare function extractWidgetParameters(): WidgetParameters;
31
+ /**
32
+ * Individual fields that are decoded inside a widget id.
33
+ */
34
+ export type WidgetId = {
35
+ /**
36
+ * The widget id of the main widget if working with modals, or the widget id
37
+ * of the current widget if not.
38
+ */
39
+ mainWidgetId: string;
40
+ /**
41
+ * The room id the widget is registered in.
42
+ */
43
+ roomId?: string;
44
+ /**
45
+ * The user id of the user that registered the widget.
46
+ */
47
+ creator?: string;
48
+ /**
49
+ * True, if this widget is a modal widget.
50
+ */
51
+ isModal: boolean;
52
+ };
53
+ /**
54
+ * Parse a widget id into the individual fields.
55
+ * @param widgetId - The widget id to parse.
56
+ * @returns The individual fields encoded inside a widget id.
57
+ */
58
+ export declare function parseWidgetId(widgetId: string): WidgetId;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { WidgetApi, WidgetParameters, WidgetRegistration } from './types';
2
+ /**
3
+ * Checks whether all widget parameters were provided to the widget.
4
+ *
5
+ * @param widgetApi - The widget api to read the parameters from
6
+ * @returns True, if all parameters were provided.
7
+ */
8
+ export declare function hasRequiredWidgetParameters(widgetApi: WidgetApi): boolean;
9
+ /**
10
+ * Generate a registration URL for the widget based on the current URL and
11
+ * include all widget parameters (and their placeholders).
12
+ * @param options - Options for generating the URL.
13
+ * Use `pathName` to include an optional sub path in the URL.
14
+ * Use `includeParameters` to append the widget parameters to
15
+ * the URL, defaults to `true`.
16
+ * @returns The generated URL.
17
+ */
18
+ export declare function generateWidgetRegistrationUrl(options?: {
19
+ pathName?: string;
20
+ includeParameters?: boolean;
21
+ widgetParameters?: Partial<WidgetParameters>;
22
+ }): string;
23
+ export declare const STATE_EVENT_WIDGETS = "im.vector.modular.widgets";
24
+ /**
25
+ * Repair/configure the registration of the current widget.
26
+ * This steps make sure to include all the required widget parameters in the
27
+ * URL. Support setting a widget name and additional parameters.
28
+ *
29
+ * @param widgetApi - The widget api of the current widget.
30
+ * @param registration - Optional configuration options for the widget
31
+ * registration, like the display name of the widget.
32
+ */
33
+ export declare function repairWidgetRegistration(widgetApi: WidgetApi, registration?: WidgetRegistration): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};