@matrix-widget-toolkit/api 4.2.0 → 5.0.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/build/index.d.ts CHANGED
@@ -26,11 +26,16 @@ import { WidgetEventCapability } from 'matrix-widget-api';
26
26
  /**
27
27
  * Calculate the power level of the user based on a `m.room.power_levels` event.
28
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
+ *
29
33
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event.
34
+ * @param createRoomStateEvent - the `m.room.create` event for the room.
30
35
  * @param userId - the ID of the user.
31
36
  * @returns the power level of the user.
32
37
  */
33
- export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent, userId?: string): number;
38
+ export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string): UserPowerLevelType;
34
39
 
35
40
  /**
36
41
  * Compares two room events by their origin server timestamp.
@@ -42,6 +47,14 @@ export declare function calculateUserPowerLevel(powerLevelStateEvent: PowerLevel
42
47
  */
43
48
  export declare function compareOriginServerTS<T>(a: RoomEvent<T>, b: RoomEvent<T>): number;
44
49
 
50
+ /**
51
+ * Compare a user's power level to a normal power level.
52
+ * @param userPowerLevel - The user's power level
53
+ * @param normalPowerLevel - The normal power level
54
+ * @returns True if the user's power level is greater than or equal to the normal power level, false otherwise
55
+ */
56
+ export declare function compareUserPowerLevelToNormalPowerLevel(userPowerLevel: UserPowerLevelType, normalPowerLevel: number): boolean;
57
+
45
58
  /**
46
59
  * Content of a room event that relates to another event.
47
60
  */
@@ -135,31 +148,34 @@ export declare function getRoomMemberDisplayName(member: StateEvent<RoomMemberSt
135
148
  * * redact: Redact a message from another user
136
149
  *
137
150
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
151
+ * @param createRoomStateEvent - the `m.room.create` event for the room
138
152
  * @param userId - the id of the user
139
153
  * @param action - the action
140
154
  * @returns if true, the user has the power
141
155
  */
142
- export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
156
+ export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
143
157
 
144
158
  /**
145
159
  * Check if a user has the power to send a specific room event.
146
160
  *
147
161
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
162
+ * @param createRoomStateEvent - the `m.room.create` event for the room
148
163
  * @param userId - the id of the user
149
164
  * @param eventType - the type of room event
150
165
  * @returns if true, the user has the power
151
166
  */
152
- export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
167
+ export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, eventType: string): boolean;
153
168
 
154
169
  /**
155
170
  * Check if a user has the power to send a specific state event.
156
171
  *
157
172
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
173
+ * @param createRoomStateEvent - the `m.room.create` event for the room
158
174
  * @param userId - the id of the user
159
175
  * @param eventType - the type of state event
160
176
  * @returns if true, the user has the power
161
177
  */
162
- export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
178
+ export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, createRoomStateEvent: StateEvent<StateEventCreateContent> | undefined, userId: string | undefined, eventType: string): boolean;
163
179
 
164
180
  /**
165
181
  * Checks whether the necessary widget parameters were provided to the widget.
@@ -185,6 +201,14 @@ export declare function isRoomEvent(event: RoomEvent | StateEvent): event is Roo
185
201
  */
186
202
  export declare function isStateEvent(event: RoomEvent | StateEvent): event is StateEvent;
187
203
 
204
+ /**
205
+ * Validates that `event` is has a valid structure for a
206
+ * {@link StateEventCreateContent}.
207
+ * @param event - The event to validate.
208
+ * @returns True, if the event is valid.
209
+ */
210
+ export declare function isValidCreateEventSchema(event: StateEvent<unknown> | undefined): event is StateEvent<StateEventCreateContent>;
211
+
188
212
  /**
189
213
  * Validates that `event` has a valid structure for a
190
214
  * {@link EventWithRelatesTo}.
@@ -380,6 +404,12 @@ export declare function repairWidgetRegistration(widgetApi: WidgetApi, registrat
380
404
  */
381
405
  export declare const ROOM_EVENT_REDACTION = "m.room.redaction";
382
406
 
407
+ /**
408
+ * Room version 12 requires us to have something larger than Max integer for room creators.
409
+ * This is a workaround to allow the room creator to always have the highest power level.
410
+ */
411
+ export declare const ROOM_VERSION_12_CREATOR = "ROOM_VERSION_12_CREATOR";
412
+
383
413
  /**
384
414
  * Generic type for room events.
385
415
  */
@@ -421,7 +451,12 @@ export declare type RoomMemberStateEventContent = {
421
451
  export declare function sendStateEventWithEventResult<T>(widgetApi: WidgetApi, type: string, stateKey: string, content: T): Promise<StateEvent<T>>;
422
452
 
423
453
  /**
424
- * The name of the power levels state event.
454
+ * The types of type of the create event.
455
+ */
456
+ export declare const STATE_EVENT_CREATE = "m.room.create";
457
+
458
+ /**
459
+ * The type of the power levels state event.
425
460
  */
426
461
  export declare const STATE_EVENT_POWER_LEVELS = "m.room.power_levels";
427
462
 
@@ -438,6 +473,12 @@ export declare type StateEvent<T = unknown> = Omit<IRoomEvent, 'content' | 'unsi
438
473
  content: T;
439
474
  };
440
475
 
476
+ export declare type StateEventCreateContent = {
477
+ room_version?: string;
478
+ creator?: string;
479
+ additional_creators?: string[];
480
+ };
481
+
441
482
  /**
442
483
  * Generic type for to device message events.
443
484
  */
@@ -461,6 +502,8 @@ export declare type TurnServer = {
461
502
  credential: string;
462
503
  };
463
504
 
505
+ export declare type UserPowerLevelType = number | typeof ROOM_VERSION_12_CREATOR;
506
+
464
507
  /**
465
508
  * The capability that needs to be requested in order to navigate to another room.
466
509
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matrix-widget-toolkit/api",
3
- "version": "4.2.0",
3
+ "version": "5.0.1",
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.3",
26
- "@types/node": "22.15.30",
25
+ "@rollup/plugin-commonjs": "28.0.6",
26
+ "@types/node": "22.15.35",
27
27
  "@types/qs": "6.14.0",
28
- "@vitest/coverage-v8": "3.2.2",
28
+ "@vitest/coverage-v8": "3.2.4",
29
29
  "typescript": "5.8.3",
30
30
  "vite": "6.3.5",
31
- "vitest": "3.2.2"
31
+ "vitest": "3.2.4"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsc && rollup --config ../../rollup.config.mjs",