@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.
@@ -124,6 +124,14 @@ var __assign$2 = (undefined && undefined.__assign) || function () {
124
124
  };
125
125
  return __assign$2.apply(this, arguments);
126
126
  };
127
+ /**
128
+ * The type of the power levels state event.
129
+ */
130
+ var STATE_EVENT_POWER_LEVELS = 'm.room.power_levels';
131
+ /**
132
+ * The types of type of the create event.
133
+ */
134
+ var STATE_EVENT_CREATE = 'm.room.create';
127
135
  /**
128
136
  * Check if the given event is a {@link StateEvent}.
129
137
  *
@@ -151,7 +159,12 @@ function isRoomEvent(event) {
151
159
  // Allow any here, so that the validation works for every event
152
160
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
161
  function isValidRoomEvent(event) {
154
- return roomEventSchema.validate(event).error === undefined;
162
+ var result = roomEventSchema.validate(event);
163
+ if (result.error) {
164
+ console.warn('Invalid room event:', result.error.details, { event: event });
165
+ return false;
166
+ }
167
+ return true;
155
168
  }
156
169
  /**
157
170
  * Check if the given value is a valid {@link StateEvent}.
@@ -162,7 +175,12 @@ function isValidRoomEvent(event) {
162
175
  // Allow any here, so that the validation works for every event
163
176
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
177
  function isValidStateEvent(event) {
165
- return stateEventSchema.validate(event).error === undefined;
178
+ var result = stateEventSchema.validate(event);
179
+ if (result.error) {
180
+ console.warn('Invalid state event:', result.error.details, { event: event });
181
+ return false;
182
+ }
183
+ return true;
166
184
  }
167
185
  /**
168
186
  * Check if the given value is a valid {@link ToDeviceMessageEvent}.
@@ -171,19 +189,26 @@ function isValidStateEvent(event) {
171
189
  * @returns true if value is a valid to device message, else false.
172
190
  */
173
191
  function isValidToDeviceMessageEvent(event) {
174
- return toDeviceMessageSchema.validate(event).error === undefined;
192
+ var result = toDeviceMessageSchema.validate(event);
193
+ if (result.error) {
194
+ console.warn('Invalid to device message event:', result.error.details, {
195
+ event: event,
196
+ });
197
+ return false;
198
+ }
199
+ return true;
175
200
  }
176
- /**
177
- * Base properties to validate for all events.
178
- */
179
- var eventSchemaProps = {
180
- type: Joi__default.default.string().required(),
201
+ var eventSchemaBasicProps = {
181
202
  // Do roughly check against the format
182
203
  // https://spec.matrix.org/v1.13/appendices/#common-identifier-format
183
204
  sender: Joi__default.default.string().pattern(new RegExp('^@[^\\s:]*:\\S*$')).required(),
184
- room_id: Joi__default.default.string().pattern(new RegExp('^![^:]*:\\S*')).required(),
185
- content: Joi__default.default.object().required(),
205
+ // Prior versions of the code had checked for a server_name. However in room version 12+ this got dropped. There is no way for us to check this here.
206
+ room_id: Joi__default.default.string().pattern(new RegExp('^!')).required(),
186
207
  };
208
+ /**
209
+ * Base properties to validate for all events.
210
+ */
211
+ var eventSchemaProps = __assign$2({ type: Joi__default.default.string().required(), content: Joi__default.default.object().required() }, eventSchemaBasicProps);
187
212
  var roomEventSchema = Joi__default.default.object(__assign$2(__assign$2({}, eventSchemaProps), { event_id: Joi__default.default.string().pattern(new RegExp('^\\$.*')).required(), origin_server_ts: Joi__default.default.date().timestamp('javascript').required() })).unknown();
188
213
  var stateEventSchema = Joi__default.default.object(__assign$2(__assign$2({}, eventSchemaProps), { event_id: Joi__default.default.string().pattern(new RegExp('^\\$.*')), origin_server_ts: Joi__default.default.date().timestamp('javascript'), state_key: Joi__default.default.string().allow('').required() })).unknown();
189
214
  var toDeviceMessageSchema = Joi__default.default.object({
@@ -192,6 +217,71 @@ var toDeviceMessageSchema = Joi__default.default.object({
192
217
  encrypted: Joi__default.default.boolean().required(),
193
218
  content: Joi__default.default.object().required(),
194
219
  }).unknown();
220
+ var createEventSchema = Joi__default.default.object(__assign$2(__assign$2({}, eventSchemaBasicProps), { type: Joi__default.default.string().equal(STATE_EVENT_CREATE).required(), content: Joi__default.default.object({
221
+ // Room version 1 does not have a room version, so we allow it to be undefined.
222
+ room_version: Joi__default.default.string().optional(),
223
+ // The user ID of the creator of the room. (only from 1-10. after that we must use the sender field)
224
+ creator: Joi__default.default.string().optional(),
225
+ // Room version 12 introduces the additional_creators field.
226
+ additional_creators: Joi__default.default.array().items(Joi__default.default.string()).optional(),
227
+ })
228
+ .unknown()
229
+ .required() })).unknown();
230
+ /**
231
+ * Validates that `event` is has a valid structure for a
232
+ * {@link StateEventCreateContent}.
233
+ * @param event - The event to validate.
234
+ * @returns True, if the event is valid.
235
+ */
236
+ function isValidCreateEventSchema(event) {
237
+ if (!event) {
238
+ return true;
239
+ }
240
+ var result = createEventSchema.validate(event);
241
+ if (result.error) {
242
+ console.warn('Invalid room create message event:', result.error.details, {
243
+ event: event,
244
+ });
245
+ return false;
246
+ }
247
+ return true;
248
+ }
249
+ var powerLevelsEventSchema = Joi__default.default.object(__assign$2(__assign$2({}, eventSchemaBasicProps), {
250
+ // Strictly require to match the power levels event type
251
+ type: Joi__default.default.string().equal(STATE_EVENT_POWER_LEVELS).required(), content: Joi__default.default.object({
252
+ ban: Joi__default.default.number().optional().default(50),
253
+ events: Joi__default.default.object().pattern(Joi__default.default.string(), Joi__default.default.number()).optional(),
254
+ events_default: Joi__default.default.number().optional().default(0),
255
+ invite: Joi__default.default.number().optional().default(0),
256
+ kick: Joi__default.default.number().optional().default(50),
257
+ notifications: Joi__default.default.object({
258
+ room: Joi__default.default.number().optional().default(50),
259
+ })
260
+ .unknown()
261
+ .optional(),
262
+ redact: Joi__default.default.number().optional().default(50),
263
+ state_default: Joi__default.default.number().optional().default(50),
264
+ users: Joi__default.default.object().pattern(Joi__default.default.string(), Joi__default.default.number()).optional(),
265
+ users_default: Joi__default.default.number().optional().default(0),
266
+ })
267
+ .unknown()
268
+ .required() })).unknown();
269
+ /**
270
+ * Validates that `event` is has a valid structure for a
271
+ * {@link PowerLevelsStateEvent}.
272
+ * @param event - The event to validate.
273
+ * @returns True, if the event is valid.
274
+ */
275
+ function isValidPowerLevelStateEvent(event) {
276
+ var result = powerLevelsEventSchema.validate(event);
277
+ if (result.error) {
278
+ console.warn('Invalid powerlevel event:', result.error.details, {
279
+ event: event,
280
+ });
281
+ return false;
282
+ }
283
+ return true;
284
+ }
195
285
 
196
286
  /*
197
287
  * Copyright 2022 Nordeck IT + Consulting GmbH
@@ -319,95 +409,57 @@ function compareOriginServerTS(a, b) {
319
409
  * limitations under the License.
320
410
  */
321
411
  /**
322
- * The name of the power levels state event.
323
- */
324
- var STATE_EVENT_POWER_LEVELS = 'm.room.power_levels';
325
- function isNumberOrUndefined(value) {
326
- return value === undefined || typeof value === 'number';
327
- }
328
- function isStringToNumberMapOrUndefined(value) {
329
- return (value === undefined ||
330
- (value !== null &&
331
- typeof value === 'object' &&
332
- Object.entries(value).every(function (_a) {
333
- var k = _a[0], v = _a[1];
334
- return typeof k === 'string' && typeof v === 'number';
335
- })));
336
- }
337
- /**
338
- * Validates that `event` is has a valid structure for a
339
- * {@link PowerLevelsStateEvent}.
340
- * @param event - The event to validate.
341
- * @returns True, if the event is valid.
412
+ * Room version 12 requires us to have something larger than Max integer for room creators.
413
+ * This is a workaround to allow the room creator to always have the highest power level.
342
414
  */
343
- function isValidPowerLevelStateEvent(event) {
344
- if (event.type !== STATE_EVENT_POWER_LEVELS ||
345
- typeof event.content !== 'object') {
346
- return false;
347
- }
348
- var content = event.content;
349
- if (!isStringToNumberMapOrUndefined(content.events)) {
350
- return false;
351
- }
352
- if (!isNumberOrUndefined(content.state_default)) {
353
- return false;
354
- }
355
- if (!isNumberOrUndefined(content.events_default)) {
356
- return false;
357
- }
358
- if (!isStringToNumberMapOrUndefined(content.users)) {
359
- return false;
360
- }
361
- if (!isNumberOrUndefined(content.users_default)) {
362
- return false;
363
- }
364
- if (!isNumberOrUndefined(content.ban)) {
365
- return false;
366
- }
367
- if (!isNumberOrUndefined(content.invite)) {
368
- return false;
369
- }
370
- if (!isNumberOrUndefined(content.kick)) {
371
- return false;
415
+ var ROOM_VERSION_12_CREATOR = 'ROOM_VERSION_12_CREATOR';
416
+ function compareUserPowerLevelToNormalPowerLevel(userPowerLevel, normalPowerLevel) {
417
+ if (userPowerLevel === ROOM_VERSION_12_CREATOR) {
418
+ // Room version 12 creator has the highest power level.
419
+ return true;
372
420
  }
373
- if (!isNumberOrUndefined(content.redact)) {
421
+ if (typeof userPowerLevel !== 'number') {
422
+ // If the user power level is not a number, we cannot compare it to a normal power level.
374
423
  return false;
375
424
  }
376
- return true;
425
+ // Compare the user power level to the normal power level.
426
+ return userPowerLevel >= normalPowerLevel;
377
427
  }
378
428
  /**
379
429
  * Check if a user has the power to send a specific room event.
380
430
  *
381
431
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
432
+ * @param createRoomStateEvent - the `m.room.create` event for the room
382
433
  * @param userId - the id of the user
383
434
  * @param eventType - the type of room event
384
435
  * @returns if true, the user has the power
385
436
  */
386
- function hasRoomEventPower(powerLevelStateEvent, userId, eventType) {
387
- if (!powerLevelStateEvent) {
388
- // See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
389
- return true;
437
+ function hasRoomEventPower(powerLevelStateEvent, createRoomStateEvent, userId, eventType) {
438
+ if (!userId) {
439
+ // This is invalid but required to be checked due to widget API which may not know it
440
+ throw new Error('Cannot check action power without a user ID. Please provide a user ID.');
390
441
  }
391
- var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
442
+ var userLevel = calculateUserPowerLevel(powerLevelStateEvent, createRoomStateEvent, userId);
392
443
  var eventLevel = calculateRoomEventPowerLevel(powerLevelStateEvent, eventType);
393
- return userLevel >= eventLevel;
444
+ return compareUserPowerLevelToNormalPowerLevel(userLevel, eventLevel);
394
445
  }
395
446
  /**
396
447
  * Check if a user has the power to send a specific state event.
397
448
  *
398
449
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
450
+ * @param createRoomStateEvent - the `m.room.create` event for the room
399
451
  * @param userId - the id of the user
400
452
  * @param eventType - the type of state event
401
453
  * @returns if true, the user has the power
402
454
  */
403
- function hasStateEventPower(powerLevelStateEvent, userId, eventType) {
404
- if (!powerLevelStateEvent) {
405
- // See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
406
- return true;
455
+ function hasStateEventPower(powerLevelStateEvent, createRoomStateEvent, userId, eventType) {
456
+ if (!userId) {
457
+ // This is invalid but required to be checked due to widget API which may not know it
458
+ throw new Error('Cannot check action power without a user ID. Please provide a user ID.');
407
459
  }
408
- var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
409
- var eventLevel = calculateStateEventPowerLevel(powerLevelStateEvent, eventType);
410
- return userLevel >= eventLevel;
460
+ var userLevel = calculateUserPowerLevel(powerLevelStateEvent, createRoomStateEvent, userId);
461
+ var eventLevel = calculateStateEventPowerLevel(powerLevelStateEvent, createRoomStateEvent, eventType);
462
+ return compareUserPowerLevelToNormalPowerLevel(userLevel, eventLevel);
411
463
  }
412
464
  /**
413
465
  * Check if a user has the power to perform a specific action.
@@ -419,30 +471,74 @@ function hasStateEventPower(powerLevelStateEvent, userId, eventType) {
419
471
  * * redact: Redact a message from another user
420
472
  *
421
473
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
474
+ * @param createRoomStateEvent - the `m.room.create` event for the room
422
475
  * @param userId - the id of the user
423
476
  * @param action - the action
424
477
  * @returns if true, the user has the power
425
478
  */
426
- function hasActionPower(powerLevelStateEvent, userId, action) {
427
- if (!powerLevelStateEvent) {
428
- // See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L36-L43
429
- return true;
479
+ function hasActionPower(powerLevelStateEvent, createRoomStateEvent, userId, action) {
480
+ if (!userId) {
481
+ // This is invalid but required to be checked due to widget API which may not know it
482
+ throw new Error('Cannot check action power without a user ID. Please provide a user ID.');
430
483
  }
431
- var userLevel = calculateUserPowerLevel(powerLevelStateEvent, userId);
484
+ var userLevel = calculateUserPowerLevel(powerLevelStateEvent, createRoomStateEvent, userId);
432
485
  var eventLevel = calculateActionPowerLevel(powerLevelStateEvent, action);
433
- return userLevel >= eventLevel;
486
+ return compareUserPowerLevelToNormalPowerLevel(userLevel, eventLevel);
434
487
  }
435
488
  /**
436
489
  * Calculate the power level of the user based on a `m.room.power_levels` event.
437
490
  *
491
+ * Note that we return the @see UserPowerLevelType type instead of a number as Room Version 12
492
+ * gives a Room creator (and additionalCreators) always the highest power level regardless
493
+ * of the highest next Powerlevel number.
494
+ *
438
495
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event.
496
+ * @param createRoomStateEvent - the `m.room.create` event for the room.
439
497
  * @param userId - the ID of the user.
440
498
  * @returns the power level of the user.
441
499
  */
442
- function calculateUserPowerLevel(powerLevelStateEvent, userId) {
443
- var _a, _b, _c;
444
- // See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L8-L12
445
- return ((_c = (_b = (userId ? (_a = powerLevelStateEvent.users) === null || _a === void 0 ? void 0 : _a[userId] : undefined)) !== null && _b !== void 0 ? _b : powerLevelStateEvent.users_default) !== null && _c !== void 0 ? _c : 0);
500
+ function calculateUserPowerLevel(powerLevelStateEvent, createRoomStateEvent, userId) {
501
+ var _a, _b, _c, _d, _e, _f;
502
+ // This is practically not allowed and therefor not covered by the spec. However a js consumer could still pass an undefined userId so we handle it gracefully.
503
+ if (!userId) {
504
+ // If no user ID is provided, we return the default user power level or 0 if not set.
505
+ return 0;
506
+ }
507
+ // If we have room version 12 we must check if the user is the creator of the room and needs to have the highest power level.
508
+ if (((_a = createRoomStateEvent === null || createRoomStateEvent === void 0 ? void 0 : createRoomStateEvent.content) === null || _a === void 0 ? void 0 : _a.room_version) === '12' ||
509
+ ((_b = createRoomStateEvent === null || createRoomStateEvent === void 0 ? void 0 : createRoomStateEvent.content) === null || _b === void 0 ? void 0 : _b.room_version) === 'org.matrix.hydra.11') {
510
+ // If the user is the creator of the room, we return the special ROOM_VERSION_12_CREATOR value.
511
+ if (createRoomStateEvent.sender === userId) {
512
+ return ROOM_VERSION_12_CREATOR;
513
+ }
514
+ if ((_c = createRoomStateEvent.content.additional_creators) === null || _c === void 0 ? void 0 : _c.includes(userId)) {
515
+ // If the user is an additional creator of the room, we return the special ROOM_VERSION_12_CREATOR value.
516
+ return ROOM_VERSION_12_CREATOR;
517
+ }
518
+ }
519
+ // If there is no power level state event, we assume the user has no power unless they are the room creator in which case they get PL 100.
520
+ if (!powerLevelStateEvent) {
521
+ if (['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'].includes((_e = (_d = createRoomStateEvent === null || createRoomStateEvent === void 0 ? void 0 : createRoomStateEvent.content) === null || _d === void 0 ? void 0 : _d.room_version) !== null && _e !== void 0 ? _e : '1')) {
522
+ // Room version 1-10 does not have a room version, so we assume the creator has power level 100.
523
+ return ((_f = createRoomStateEvent === null || createRoomStateEvent === void 0 ? void 0 : createRoomStateEvent.content) === null || _f === void 0 ? void 0 : _f.creator) === userId ? 100 : 0;
524
+ }
525
+ else {
526
+ // For room versions 11 and above, we assume the sender has power level 100.
527
+ return (createRoomStateEvent === null || createRoomStateEvent === void 0 ? void 0 : createRoomStateEvent.sender) === userId ? 100 : 0;
528
+ }
529
+ }
530
+ if (powerLevelStateEvent.users && userId in powerLevelStateEvent.users) {
531
+ // If the user is explicitly listed in the users map, return their power level.
532
+ return powerLevelStateEvent.users[userId];
533
+ }
534
+ else if (powerLevelStateEvent.users_default !== undefined) {
535
+ // If the user is not explicitly listed, return the default user power level.
536
+ return powerLevelStateEvent.users_default;
537
+ }
538
+ else {
539
+ // If no users or default is set, return 0.
540
+ return 0;
541
+ }
446
542
  }
447
543
  /**
448
544
  * Calculate the power level that a user needs send a specific room event.
@@ -454,19 +550,26 @@ function calculateUserPowerLevel(powerLevelStateEvent, userId) {
454
550
  function calculateRoomEventPowerLevel(powerLevelStateEvent, eventType) {
455
551
  var _a, _b, _c;
456
552
  // See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L14-L19
457
- return ((_c = (_b = (_a = powerLevelStateEvent.events) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : powerLevelStateEvent.events_default) !== null && _c !== void 0 ? _c : 0);
553
+ return ((_c = (_b = (_a = powerLevelStateEvent === null || powerLevelStateEvent === void 0 ? void 0 : powerLevelStateEvent.events) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : powerLevelStateEvent === null || powerLevelStateEvent === void 0 ? void 0 : powerLevelStateEvent.events_default) !== null && _c !== void 0 ? _c : 0);
458
554
  }
459
555
  /**
460
556
  * Calculate the power level that a user needs send a specific state event.
461
557
  *
462
558
  * @param powerLevelStateEvent - the content of the `m.room.power_levels` event
559
+ * @param createRoomStateEvent - the `m.room.create` event
463
560
  * @param eventType - the type of state event
464
561
  * @returns the power level that is needed
465
562
  */
466
- function calculateStateEventPowerLevel(powerLevelStateEvent, eventType) {
467
- var _a, _b, _c;
563
+ function calculateStateEventPowerLevel(powerLevelStateEvent, createRoomStateEvent, eventType) {
564
+ var _a, _b, _c, _d, _e;
565
+ // In room version 12 (and the beta org.matrix.hydra.11 version) we need 150 for m.room.tombstone events and it cant be changed by the user.
566
+ if ((((_a = createRoomStateEvent === null || createRoomStateEvent === void 0 ? void 0 : createRoomStateEvent.content) === null || _a === void 0 ? void 0 : _a.room_version) === '12' ||
567
+ ((_b = createRoomStateEvent === null || createRoomStateEvent === void 0 ? void 0 : createRoomStateEvent.content) === null || _b === void 0 ? void 0 : _b.room_version) === 'org.matrix.hydra.11') &&
568
+ eventType === 'm.room.tombstone') {
569
+ return 150;
570
+ }
468
571
  // See https://github.com/matrix-org/matrix-spec/blob/203b9756f52adfc2a3b63d664f18cdbf9f8bf126/data/event-schemas/schema/m.room.power_levels.yaml#L14-L19
469
- return ((_c = (_b = (_a = powerLevelStateEvent.events) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : powerLevelStateEvent.state_default) !== null && _c !== void 0 ? _c : 50);
572
+ return ((_e = (_d = (_c = powerLevelStateEvent === null || powerLevelStateEvent === void 0 ? void 0 : powerLevelStateEvent.events) === null || _c === void 0 ? void 0 : _c[eventType]) !== null && _d !== void 0 ? _d : powerLevelStateEvent === null || powerLevelStateEvent === void 0 ? void 0 : powerLevelStateEvent.state_default) !== null && _e !== void 0 ? _e : 50);
470
573
  }
471
574
  /**
472
575
  * Calculate the power level that a user needs to perform an action.
@@ -1529,6 +1632,24 @@ var WidgetApiImpl = /** @class */ (function () {
1529
1632
  var _b = _a === void 0 ? {} : _a, roomId = _b.roomId, _c = _b.stateKey, stateKey = _c === void 0 ? '' : _c;
1530
1633
  return this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId);
1531
1634
  };
1635
+ /** {@inheritDoc WidgetApi.sendDelayedStateEvent} */
1636
+ WidgetApiImpl.prototype.sendDelayedStateEvent = function (eventType_1, content_1, delay_1) {
1637
+ return __awaiter(this, arguments, void 0, function (eventType, content, delay, _a) {
1638
+ var delay_id;
1639
+ var _b = _a === void 0 ? {} : _a, roomId = _b.roomId, _c = _b.stateKey, stateKey = _c === void 0 ? '' : _c;
1640
+ return __generator(this, function (_d) {
1641
+ switch (_d.label) {
1642
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId, delay)];
1643
+ case 1:
1644
+ delay_id = (_d.sent()).delay_id;
1645
+ if (!delay_id) {
1646
+ throw new Error('Delayed event must have a delay_id');
1647
+ }
1648
+ return [2 /*return*/, { delay_id: delay_id }];
1649
+ }
1650
+ });
1651
+ });
1652
+ };
1532
1653
  /** {@inheritDoc WidgetApi.receiveRoomEvents} */
1533
1654
  WidgetApiImpl.prototype.receiveRoomEvents = function (eventType_1) {
1534
1655
  return __awaiter(this, arguments, void 0, function (eventType, _a) {
@@ -1597,6 +1718,37 @@ var WidgetApiImpl = /** @class */ (function () {
1597
1718
  });
1598
1719
  });
1599
1720
  };
1721
+ /** {@inheritDoc WidgetApi.sendDelayedRoomEvent} */
1722
+ WidgetApiImpl.prototype.sendDelayedRoomEvent = function (eventType_1, content_1, delay_1) {
1723
+ return __awaiter(this, arguments, void 0, function (eventType, content, delay, _a) {
1724
+ var delay_id;
1725
+ var _b = _a === void 0 ? {} : _a, roomId = _b.roomId;
1726
+ return __generator(this, function (_c) {
1727
+ switch (_c.label) {
1728
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId, delay)];
1729
+ case 1:
1730
+ delay_id = (_c.sent()).delay_id;
1731
+ if (!delay_id) {
1732
+ throw new Error('Delayed event must have a delay_id');
1733
+ }
1734
+ return [2 /*return*/, { delay_id: delay_id }];
1735
+ }
1736
+ });
1737
+ });
1738
+ };
1739
+ /** {@inheritDoc WidgetApi.updateDelayedEvent} */
1740
+ WidgetApiImpl.prototype.updateDelayedEvent = function (delayId, action) {
1741
+ return __awaiter(this, void 0, void 0, function () {
1742
+ return __generator(this, function (_a) {
1743
+ switch (_a.label) {
1744
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.updateDelayedEvent(delayId, action)];
1745
+ case 1:
1746
+ _a.sent();
1747
+ return [2 /*return*/];
1748
+ }
1749
+ });
1750
+ });
1751
+ };
1600
1752
  /** {@inheritDoc WidgetApi.readEventRelations} */
1601
1753
  WidgetApiImpl.prototype.readEventRelations = function (eventId, options) {
1602
1754
  return __awaiter(this, void 0, void 0, function () {
@@ -1865,6 +2017,7 @@ var WidgetApiImpl = /** @class */ (function () {
1865
2017
  }());
1866
2018
 
1867
2019
  exports.ROOM_EVENT_REDACTION = ROOM_EVENT_REDACTION;
2020
+ exports.STATE_EVENT_CREATE = STATE_EVENT_CREATE;
1868
2021
  exports.STATE_EVENT_POWER_LEVELS = STATE_EVENT_POWER_LEVELS;
1869
2022
  exports.STATE_EVENT_ROOM_MEMBER = STATE_EVENT_ROOM_MEMBER;
1870
2023
  exports.WIDGET_CAPABILITY_NAVIGATE = WIDGET_CAPABILITY_NAVIGATE;
@@ -1885,6 +2038,7 @@ exports.hasStateEventPower = hasStateEventPower;
1885
2038
  exports.hasWidgetParameters = hasWidgetParameters;
1886
2039
  exports.isRoomEvent = isRoomEvent;
1887
2040
  exports.isStateEvent = isStateEvent;
2041
+ exports.isValidCreateEventSchema = isValidCreateEventSchema;
1888
2042
  exports.isValidEventWithRelatesTo = isValidEventWithRelatesTo;
1889
2043
  exports.isValidPowerLevelStateEvent = isValidPowerLevelStateEvent;
1890
2044
  exports.isValidRedactionEvent = isValidRedactionEvent;
@@ -1,4 +1,4 @@
1
- import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidgetApiRequestData, WidgetApi as MatrixWidgetApi, ModalButtonID, Symbols, WidgetEventCapability } from 'matrix-widget-api';
1
+ import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidgetApiRequestData, WidgetApi as MatrixWidgetApi, ModalButtonID, Symbols, UpdateDelayedEventAction, WidgetEventCapability } from 'matrix-widget-api';
2
2
  import { Observable } from 'rxjs';
3
3
  import { RoomEvent, StateEvent, ToDeviceMessageEvent, TurnServer, WidgetApi, WidgetConfig, WidgetParameters } from './types';
4
4
  /**
@@ -108,6 +108,13 @@ export declare class WidgetApiImpl implements WidgetApi {
108
108
  roomId?: string;
109
109
  stateKey?: string;
110
110
  }): Promise<ISendEventFromWidgetResponseData>;
111
+ /** {@inheritDoc WidgetApi.sendDelayedStateEvent} */
112
+ sendDelayedStateEvent<T>(eventType: string, content: T, delay: number, { roomId, stateKey }?: {
113
+ roomId?: string;
114
+ stateKey?: string;
115
+ }): Promise<{
116
+ delay_id: string;
117
+ }>;
111
118
  /** {@inheritDoc WidgetApi.receiveRoomEvents} */
112
119
  receiveRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
113
120
  messageType?: string;
@@ -122,6 +129,14 @@ export declare class WidgetApiImpl implements WidgetApi {
122
129
  sendRoomEvent<T>(eventType: string, content: T, { roomId }?: {
123
130
  roomId?: string;
124
131
  }): Promise<RoomEvent<T>>;
132
+ /** {@inheritDoc WidgetApi.sendDelayedRoomEvent} */
133
+ sendDelayedRoomEvent<T>(eventType: string, content: T, delay: number, { roomId }?: {
134
+ roomId?: string;
135
+ }): Promise<{
136
+ delay_id: string;
137
+ }>;
138
+ /** {@inheritDoc WidgetApi.updateDelayedEvent} */
139
+ updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<void>;
125
140
  /** {@inheritDoc WidgetApi.readEventRelations} */
126
141
  readEventRelations(eventId: string, options?: {
127
142
  roomId?: string;
@@ -1,5 +1,13 @@
1
1
  import Joi from 'joi';
2
2
  import { RoomEvent, StateEvent, ToDeviceMessageEvent } from '../types';
3
+ /**
4
+ * The type of the power levels state event.
5
+ */
6
+ export declare const STATE_EVENT_POWER_LEVELS = "m.room.power_levels";
7
+ /**
8
+ * The types of type of the create event.
9
+ */
10
+ export declare const STATE_EVENT_CREATE = "m.room.create";
3
11
  /**
4
12
  * Check if the given event is a {@link StateEvent}.
5
13
  *
@@ -38,3 +46,46 @@ export declare function isValidToDeviceMessageEvent(event: unknown): event is To
38
46
  export declare const roomEventSchema: Joi.ObjectSchema<RoomEvent>;
39
47
  export declare const stateEventSchema: Joi.ObjectSchema<StateEvent>;
40
48
  export declare const toDeviceMessageSchema: Joi.ObjectSchema<ToDeviceMessageEvent>;
49
+ export type StateEventCreateContent = {
50
+ room_version?: string;
51
+ creator?: string;
52
+ additional_creators?: string[];
53
+ };
54
+ export declare const createEventSchema: Joi.ObjectSchema<StateEvent<StateEventCreateContent>>;
55
+ /**
56
+ * Validates that `event` is has a valid structure for a
57
+ * {@link StateEventCreateContent}.
58
+ * @param event - The event to validate.
59
+ * @returns True, if the event is valid.
60
+ */
61
+ export declare function isValidCreateEventSchema(event: StateEvent<unknown> | undefined): event is StateEvent<StateEventCreateContent>;
62
+ /**
63
+ * The types of actions.
64
+ */
65
+ export type PowerLevelsActions = 'invite' | 'kick' | 'ban' | 'redact';
66
+ /**
67
+ * The content of an `m.room.power_levels` event.
68
+ */
69
+ export type PowerLevelsStateEvent = {
70
+ events?: {
71
+ [key: string]: number;
72
+ };
73
+ state_default?: number;
74
+ events_default?: number;
75
+ users?: {
76
+ [key: string]: number;
77
+ };
78
+ users_default?: number;
79
+ ban?: number;
80
+ invite?: number;
81
+ kick?: number;
82
+ redact?: number;
83
+ };
84
+ export declare const powerLevelsEventSchema: Joi.ObjectSchema<StateEvent<PowerLevelsStateEvent>>;
85
+ /**
86
+ * Validates that `event` is has a valid structure for a
87
+ * {@link PowerLevelsStateEvent}.
88
+ * @param event - The event to validate.
89
+ * @returns True, if the event is valid.
90
+ */
91
+ export declare function isValidPowerLevelStateEvent(event: StateEvent<unknown>): event is StateEvent<PowerLevelsStateEvent>;
@@ -1,11 +1,12 @@
1
1
  export { generateRoomTimelineCapabilities } from './capabilities';
2
2
  export { getRoomMemberDisplayName } from './displayName';
3
- export { isRoomEvent, isStateEvent, isValidRoomEvent, isValidStateEvent as isValidStateEVent, isValidToDeviceMessageEvent, } from './events';
3
+ export { STATE_EVENT_CREATE, isRoomEvent, isStateEvent, isValidCreateEventSchema, isValidRoomEvent, isValidStateEvent as isValidStateEVent, isValidToDeviceMessageEvent, } from './events';
4
+ export type { PowerLevelsActions, PowerLevelsStateEvent, StateEventCreateContent, } from './events';
4
5
  export { WIDGET_CAPABILITY_NAVIGATE, navigateToRoom } from './navigateTo';
5
6
  export type { NavigateToRoomOptions } from './navigateTo';
6
7
  export { compareOriginServerTS } from './originServerTs';
7
8
  export { STATE_EVENT_POWER_LEVELS, calculateUserPowerLevel, hasActionPower, hasRoomEventPower, hasStateEventPower, isValidPowerLevelStateEvent, } from './powerLevel';
8
- export type { PowerLevelsActions, PowerLevelsStateEvent } from './powerLevel';
9
+ export type { ROOM_VERSION_12_CREATOR, UserPowerLevelType } from './powerLevel';
9
10
  export { ROOM_EVENT_REDACTION, isValidRedactionEvent, observeRedactionEvents, redactEvent, } from './redactions';
10
11
  export type { Redaction, RedactionRoomEvent } from './redactions';
11
12
  export { getContent, getOriginalEventId, isValidEventWithRelatesTo, } from './relatesTo';