@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.
- package/build/cjs/api/WidgetApiImpl.d.cts +179 -0
- package/build/cjs/api/WidgetApiImpl.test.d.cts +1 -0
- package/build/cjs/api/extras/capabilities.d.cts +12 -0
- package/build/cjs/api/extras/capabilities.test.d.cts +1 -0
- package/build/cjs/api/extras/displayName.d.cts +12 -0
- package/build/cjs/api/extras/displayName.test.d.cts +1 -0
- package/build/cjs/api/extras/events.d.cts +15 -0
- package/build/cjs/api/extras/events.test.d.cts +1 -0
- package/build/cjs/api/extras/index.d.cts +14 -0
- package/build/cjs/api/extras/navigateTo.d.cts +24 -0
- package/build/cjs/api/extras/navigateTo.test.d.cts +1 -0
- package/build/cjs/api/extras/originServerTs.d.cts +10 -0
- package/build/cjs/api/extras/originServerTs.test.d.cts +1 -0
- package/build/cjs/api/extras/powerLevel.d.cts +105 -0
- package/build/cjs/api/extras/powerLevel.test.d.cts +1 -0
- package/build/cjs/api/extras/redactions.d.cts +42 -0
- package/build/cjs/api/extras/redactions.test.d.cts +1 -0
- package/build/cjs/api/extras/relatesTo.d.cts +60 -0
- package/build/cjs/api/extras/relatesTo.test.d.cts +1 -0
- package/build/cjs/api/extras/roomMember.d.cts +35 -0
- package/build/cjs/api/extras/roomMember.test.d.cts +1 -0
- package/build/cjs/api/index.d.cts +8 -0
- package/build/cjs/api/parameters.d.cts +58 -0
- package/build/cjs/api/parameters.test.d.cts +1 -0
- package/build/cjs/api/registration.d.cts +33 -0
- package/build/cjs/api/registration.test.d.cts +1 -0
- package/build/cjs/api/types.d.cts +466 -0
- package/build/cjs/api/utils.d.cts +20 -0
- package/build/cjs/api/utils.test.d.cts +1 -0
- package/build/cjs/{index.js → index.cjs} +100 -48
- package/build/cjs/index.d.cts +5 -0
- package/build/esm/api/WidgetApiImpl.d.ts +179 -0
- package/build/esm/api/WidgetApiImpl.test.d.ts +1 -0
- package/build/esm/api/extras/capabilities.d.ts +12 -0
- package/build/esm/api/extras/capabilities.test.d.ts +1 -0
- package/build/esm/api/extras/displayName.d.ts +12 -0
- package/build/esm/api/extras/displayName.test.d.ts +1 -0
- package/build/esm/api/extras/events.d.ts +15 -0
- package/build/esm/api/extras/events.test.d.ts +1 -0
- package/build/esm/api/extras/index.d.ts +14 -0
- package/build/esm/api/extras/navigateTo.d.ts +24 -0
- package/build/esm/api/extras/navigateTo.test.d.ts +1 -0
- package/build/esm/api/extras/originServerTs.d.ts +10 -0
- package/build/esm/api/extras/originServerTs.test.d.ts +1 -0
- package/build/esm/api/extras/powerLevel.d.ts +105 -0
- package/build/esm/api/extras/powerLevel.test.d.ts +1 -0
- package/build/esm/api/extras/redactions.d.ts +42 -0
- package/build/esm/api/extras/redactions.test.d.ts +1 -0
- package/build/esm/api/extras/relatesTo.d.ts +60 -0
- package/build/esm/api/extras/relatesTo.test.d.ts +1 -0
- package/build/esm/api/extras/roomMember.d.ts +35 -0
- package/build/esm/api/extras/roomMember.test.d.ts +1 -0
- package/build/esm/api/index.d.ts +8 -0
- package/build/esm/api/parameters.d.ts +58 -0
- package/build/esm/api/parameters.test.d.ts +1 -0
- package/build/esm/api/registration.d.ts +33 -0
- package/build/esm/api/registration.test.d.ts +1 -0
- package/build/esm/api/types.d.ts +466 -0
- package/build/esm/api/utils.d.ts +20 -0
- package/build/esm/api/utils.test.d.ts +1 -0
- package/build/esm/index.d.ts +5 -0
- package/build/esm/index.js +99 -49
- package/build/index.d.ts +17 -2
- package/package.json +25 -16
|
@@ -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 {};
|