@matrix-widget-toolkit/api 4.1.2 → 5.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/README.md +9 -0
- package/build/cjs/api/WidgetApiImpl.d.cts +16 -1
- package/build/cjs/api/extras/events.d.cts +51 -0
- package/build/cjs/api/extras/index.d.cts +3 -2
- package/build/cjs/api/extras/powerLevel.d.cts +22 -38
- package/build/cjs/api/types.d.cts +40 -1
- package/build/cjs/index.cjs +242 -88
- package/build/esm/api/WidgetApiImpl.d.ts +16 -1
- package/build/esm/api/extras/events.d.ts +51 -0
- package/build/esm/api/extras/index.d.ts +3 -2
- package/build/esm/api/extras/powerLevel.d.ts +22 -38
- package/build/esm/api/types.d.ts +40 -1
- package/build/esm/index.js +241 -89
- package/build/index.d.ts +95 -5
- package/package.json +8 -8
package/build/index.d.ts
CHANGED
|
@@ -19,17 +19,23 @@ import { IWidgetApiRequestData } from 'matrix-widget-api';
|
|
|
19
19
|
import { ModalButtonID } from 'matrix-widget-api';
|
|
20
20
|
import { Observable } from 'rxjs';
|
|
21
21
|
import { Symbols } from 'matrix-widget-api';
|
|
22
|
+
import { UpdateDelayedEventAction } from 'matrix-widget-api';
|
|
22
23
|
import { WidgetApi as WidgetApi_2 } from 'matrix-widget-api';
|
|
23
24
|
import { WidgetEventCapability } from 'matrix-widget-api';
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Calculate the power level of the user based on a `m.room.power_levels` event.
|
|
27
28
|
*
|
|
29
|
+
* Note that we return the @see UserPowerLevelType type instead of a number as Room Version 12
|
|
30
|
+
* gives a Room creator (and additionalCreators) always the highest power level regardless
|
|
31
|
+
* of the highest next Powerlevel number.
|
|
32
|
+
*
|
|
28
33
|
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event.
|
|
34
|
+
* @param createRoomStateEvent - the `m.room.create` event for the room.
|
|
29
35
|
* @param userId - the ID of the user.
|
|
30
36
|
* @returns the power level of the user.
|
|
31
37
|
*/
|
|
32
|
-
export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, userId
|
|
38
|
+
export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string): UserPowerLevelType;
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
41
|
* Compares two room events by their origin server timestamp.
|
|
@@ -134,31 +140,34 @@ export declare function getRoomMemberDisplayName(member: StateEvent<RoomMemberSt
|
|
|
134
140
|
* * redact: Redact a message from another user
|
|
135
141
|
*
|
|
136
142
|
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
143
|
+
* @param createRoomStateEvent - the `m.room.create` event for the room
|
|
137
144
|
* @param userId - the id of the user
|
|
138
145
|
* @param action - the action
|
|
139
146
|
* @returns if true, the user has the power
|
|
140
147
|
*/
|
|
141
|
-
export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
|
|
148
|
+
export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
|
|
142
149
|
|
|
143
150
|
/**
|
|
144
151
|
* Check if a user has the power to send a specific room event.
|
|
145
152
|
*
|
|
146
153
|
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
154
|
+
* @param createRoomStateEvent - the `m.room.create` event for the room
|
|
147
155
|
* @param userId - the id of the user
|
|
148
156
|
* @param eventType - the type of room event
|
|
149
157
|
* @returns if true, the user has the power
|
|
150
158
|
*/
|
|
151
|
-
export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
|
|
159
|
+
export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, eventType: string): boolean;
|
|
152
160
|
|
|
153
161
|
/**
|
|
154
162
|
* Check if a user has the power to send a specific state event.
|
|
155
163
|
*
|
|
156
164
|
* @param powerLevelStateEvent - the content of the `m.room.power_levels` event
|
|
165
|
+
* @param createRoomStateEvent - the `m.room.create` event for the room
|
|
157
166
|
* @param userId - the id of the user
|
|
158
167
|
* @param eventType - the type of state event
|
|
159
168
|
* @returns if true, the user has the power
|
|
160
169
|
*/
|
|
161
|
-
export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
|
|
170
|
+
export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, eventType: string): boolean;
|
|
162
171
|
|
|
163
172
|
/**
|
|
164
173
|
* Checks whether the necessary widget parameters were provided to the widget.
|
|
@@ -184,6 +193,14 @@ export declare function isRoomEvent(event: RoomEvent | StateEvent): event is Roo
|
|
|
184
193
|
*/
|
|
185
194
|
export declare function isStateEvent(event: RoomEvent | StateEvent): event is StateEvent;
|
|
186
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Validates that `event` is has a valid structure for a
|
|
198
|
+
* {@link StateEventCreateContent}.
|
|
199
|
+
* @param event - The event to validate.
|
|
200
|
+
* @returns True, if the event is valid.
|
|
201
|
+
*/
|
|
202
|
+
export declare function isValidCreateEventSchema(event: StateEvent<unknown> | undefined): event is StateEvent<StateEventCreateContent>;
|
|
203
|
+
|
|
187
204
|
/**
|
|
188
205
|
* Validates that `event` has a valid structure for a
|
|
189
206
|
* {@link EventWithRelatesTo}.
|
|
@@ -379,6 +396,12 @@ export declare function repairWidgetRegistration(widgetApi: WidgetApi, registrat
|
|
|
379
396
|
*/
|
|
380
397
|
export declare const ROOM_EVENT_REDACTION = "m.room.redaction";
|
|
381
398
|
|
|
399
|
+
/**
|
|
400
|
+
* Room version 12 requires us to have something larger than Max integer for room creators.
|
|
401
|
+
* This is a workaround to allow the room creator to always have the highest power level.
|
|
402
|
+
*/
|
|
403
|
+
export declare const ROOM_VERSION_12_CREATOR = "ROOM_VERSION_12_CREATOR";
|
|
404
|
+
|
|
382
405
|
/**
|
|
383
406
|
* Generic type for room events.
|
|
384
407
|
*/
|
|
@@ -420,7 +443,12 @@ export declare type RoomMemberStateEventContent = {
|
|
|
420
443
|
export declare function sendStateEventWithEventResult<T>(widgetApi: WidgetApi, type: string, stateKey: string, content: T): Promise<StateEvent<T>>;
|
|
421
444
|
|
|
422
445
|
/**
|
|
423
|
-
* The
|
|
446
|
+
* The types of type of the create event.
|
|
447
|
+
*/
|
|
448
|
+
export declare const STATE_EVENT_CREATE = "m.room.create";
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* The type of the power levels state event.
|
|
424
452
|
*/
|
|
425
453
|
export declare const STATE_EVENT_POWER_LEVELS = "m.room.power_levels";
|
|
426
454
|
|
|
@@ -437,6 +465,12 @@ export declare type StateEvent<T = unknown> = Omit<IRoomEvent, 'content' | 'unsi
|
|
|
437
465
|
content: T;
|
|
438
466
|
};
|
|
439
467
|
|
|
468
|
+
export declare type StateEventCreateContent = {
|
|
469
|
+
room_version?: string;
|
|
470
|
+
creator?: string;
|
|
471
|
+
additional_creators?: string[];
|
|
472
|
+
};
|
|
473
|
+
|
|
440
474
|
/**
|
|
441
475
|
* Generic type for to device message events.
|
|
442
476
|
*/
|
|
@@ -460,6 +494,8 @@ export declare type TurnServer = {
|
|
|
460
494
|
credential: string;
|
|
461
495
|
};
|
|
462
496
|
|
|
497
|
+
export declare type UserPowerLevelType = number | typeof ROOM_VERSION_12_CREATOR;
|
|
498
|
+
|
|
463
499
|
/**
|
|
464
500
|
* The capability that needs to be requested in order to navigate to another room.
|
|
465
501
|
*/
|
|
@@ -582,6 +618,23 @@ export declare type WidgetApi = {
|
|
|
582
618
|
roomId?: string;
|
|
583
619
|
stateKey?: string;
|
|
584
620
|
}): Promise<ISendEventFromWidgetResponseData>;
|
|
621
|
+
/**
|
|
622
|
+
* Send a delayed state event with a given type to the current room.
|
|
623
|
+
* @param eventType - The type of the event to send.
|
|
624
|
+
* @param content - The content of the event.
|
|
625
|
+
* @param delay - The delay of the event in milliseconds.
|
|
626
|
+
* @param options - Options for sending the state event.
|
|
627
|
+
* Use `roomId` to send the state event to another room.
|
|
628
|
+
* Use `stateKey` to send a state event with a custom state
|
|
629
|
+
* key.
|
|
630
|
+
* @returns The result data of delayed event with delay_id.
|
|
631
|
+
*/
|
|
632
|
+
sendDelayedStateEvent<T>(eventType: string, content: T, delay: number, options?: {
|
|
633
|
+
roomId?: string;
|
|
634
|
+
stateKey?: string;
|
|
635
|
+
}): Promise<{
|
|
636
|
+
delay_id: string;
|
|
637
|
+
}>;
|
|
585
638
|
/**
|
|
586
639
|
* Receive all room events of a given type from the current room.
|
|
587
640
|
*
|
|
@@ -635,6 +688,28 @@ export declare type WidgetApi = {
|
|
|
635
688
|
sendRoomEvent<T>(eventType: string, content: T, options?: {
|
|
636
689
|
roomId?: string;
|
|
637
690
|
}): Promise<RoomEvent<T>>;
|
|
691
|
+
/**
|
|
692
|
+
* Send a delayed room event with a given type to the current room.
|
|
693
|
+
* @param eventType - The type of the event to send.
|
|
694
|
+
* @param content - The content of the event.
|
|
695
|
+
* @param delay - The delay of the event in milliseconds.
|
|
696
|
+
* @param options - Options for sending the state event.
|
|
697
|
+
* Use `roomId` to send the state event to another room.
|
|
698
|
+
* Use `stateKey` to send a state event with a custom state
|
|
699
|
+
* key.
|
|
700
|
+
* @returns The result data of delayed event with delay_id.
|
|
701
|
+
*/
|
|
702
|
+
sendDelayedRoomEvent<T>(eventType: string, content: T, delay: number, options?: {
|
|
703
|
+
roomId?: string;
|
|
704
|
+
}): Promise<{
|
|
705
|
+
delay_id: string;
|
|
706
|
+
}>;
|
|
707
|
+
/**
|
|
708
|
+
* Update a delayed event by delay id
|
|
709
|
+
* @param delayId - The delay id of the event
|
|
710
|
+
* @param action - The action to update
|
|
711
|
+
*/
|
|
712
|
+
updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<void>;
|
|
638
713
|
/**
|
|
639
714
|
* Receive all events that relate to a given `eventId` by means of MSC2674.
|
|
640
715
|
* `chunk` can include state events or room events.
|
|
@@ -898,6 +973,13 @@ export declare class WidgetApiImpl implements WidgetApi {
|
|
|
898
973
|
roomId?: string;
|
|
899
974
|
stateKey?: string;
|
|
900
975
|
}): Promise<ISendEventFromWidgetResponseData>;
|
|
976
|
+
/** {@inheritDoc WidgetApi.sendDelayedStateEvent} */
|
|
977
|
+
sendDelayedStateEvent<T>(eventType: string, content: T, delay: number, { roomId, stateKey }?: {
|
|
978
|
+
roomId?: string;
|
|
979
|
+
stateKey?: string;
|
|
980
|
+
}): Promise<{
|
|
981
|
+
delay_id: string;
|
|
982
|
+
}>;
|
|
901
983
|
/** {@inheritDoc WidgetApi.receiveRoomEvents} */
|
|
902
984
|
receiveRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
|
|
903
985
|
messageType?: string;
|
|
@@ -912,6 +994,14 @@ export declare class WidgetApiImpl implements WidgetApi {
|
|
|
912
994
|
sendRoomEvent<T>(eventType: string, content: T, { roomId }?: {
|
|
913
995
|
roomId?: string;
|
|
914
996
|
}): Promise<RoomEvent<T>>;
|
|
997
|
+
/** {@inheritDoc WidgetApi.sendDelayedRoomEvent} */
|
|
998
|
+
sendDelayedRoomEvent<T>(eventType: string, content: T, delay: number, { roomId }?: {
|
|
999
|
+
roomId?: string;
|
|
1000
|
+
}): Promise<{
|
|
1001
|
+
delay_id: string;
|
|
1002
|
+
}>;
|
|
1003
|
+
/** {@inheritDoc WidgetApi.updateDelayedEvent} */
|
|
1004
|
+
updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<void>;
|
|
915
1005
|
/** {@inheritDoc WidgetApi.readEventRelations} */
|
|
916
1006
|
readEventRelations(eventId: string, options?: {
|
|
917
1007
|
roomId?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matrix-widget-toolkit/api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A simplified layer on top of matrix-widget-api to use build widgets.",
|
|
5
5
|
"author": "Nordeck IT + Consulting GmbH",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@rollup/plugin-commonjs": "28.0.
|
|
26
|
-
"@types/node": "22.
|
|
27
|
-
"@types/qs": "6.
|
|
28
|
-
"@vitest/coverage-v8": "3.
|
|
29
|
-
"typescript": "5.
|
|
30
|
-
"vite": "6.
|
|
31
|
-
"vitest": "3.
|
|
25
|
+
"@rollup/plugin-commonjs": "28.0.6",
|
|
26
|
+
"@types/node": "22.15.35",
|
|
27
|
+
"@types/qs": "6.14.0",
|
|
28
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
29
|
+
"typescript": "5.8.3",
|
|
30
|
+
"vite": "6.3.5",
|
|
31
|
+
"vitest": "3.2.4"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsc && rollup --config ../../rollup.config.mjs",
|