@matrix-widget-toolkit/api 4.0.0 → 4.1.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.
@@ -1,4 +1,5 @@
1
- import { RoomEvent, StateEvent } from '../types';
1
+ import Joi from 'joi';
2
+ import { RoomEvent, StateEvent, ToDeviceMessageEvent } from '../types';
2
3
  /**
3
4
  * Check if the given event is a {@link StateEvent}.
4
5
  *
@@ -13,3 +14,27 @@ export declare function isStateEvent(event: RoomEvent | StateEvent): event is St
13
14
  * @returns True, if the event is a {@link RoomEvent}.
14
15
  */
15
16
  export declare function isRoomEvent(event: RoomEvent | StateEvent): event is RoomEvent;
17
+ /**
18
+ * Check if the given value is a valid {@link RoomEvent}.
19
+ *
20
+ * @param event - The value to check
21
+ * @returns true if value is a valid room event, else false.
22
+ */
23
+ export declare function isValidRoomEvent(event: unknown): event is RoomEvent<any>;
24
+ /**
25
+ * Check if the given value is a valid {@link StateEvent}.
26
+ *
27
+ * @param event - The value to check
28
+ * @returns true if value is a valid state event, else false.
29
+ */
30
+ export declare function isValidStateEvent(event: unknown): event is StateEvent<any>;
31
+ /**
32
+ * Check if the given value is a valid {@link ToDeviceMessageEvent}.
33
+ *
34
+ * @param event - The value to check
35
+ * @returns true if value is a valid to device message, else false.
36
+ */
37
+ export declare function isValidToDeviceMessageEvent(event: unknown): event is ToDeviceMessageEvent<any>;
38
+ export declare const roomEventSchema: Joi.ObjectSchema<RoomEvent>;
39
+ export declare const stateEventSchema: Joi.ObjectSchema<StateEvent>;
40
+ export declare const toDeviceMessageSchema: Joi.ObjectSchema<ToDeviceMessageEvent>;
@@ -1,6 +1,6 @@
1
1
  export { generateRoomTimelineCapabilities } from './capabilities';
2
2
  export { getRoomMemberDisplayName } from './displayName';
3
- export { isRoomEvent, isStateEvent } from './events';
3
+ export { isRoomEvent, isStateEvent, isValidRoomEvent, isValidStateEvent as isValidStateEVent, isValidToDeviceMessageEvent, } from './events';
4
4
  export { WIDGET_CAPABILITY_NAVIGATE, navigateToRoom } from './navigateTo';
5
5
  export type { NavigateToRoomOptions } from './navigateTo';
6
6
  export { compareOriginServerTS } from './originServerTs';
@@ -1,7 +1,8 @@
1
1
  export * from './extras';
2
2
  export { extractRawWidgetParameters, extractWidgetApiParameters, extractWidgetParameters, parseWidgetId, } from './parameters';
3
3
  export type { WidgetApiParameters, WidgetId } from './parameters';
4
- export { generateWidgetRegistrationUrl, hasRequiredWidgetParameters, repairWidgetRegistration, } from './registration';
4
+ export { generateWidgetRegistrationUrl, hasWidgetParameters, repairWidgetRegistration, } from './registration';
5
+ export { WidgetParameter } from './types';
5
6
  export type { RoomEvent, StateEvent, ToDeviceMessageEvent, TurnServer, WidgetApi, WidgetConfig, WidgetParameters, WidgetRegistration, } from './types';
6
7
  export { makeEventFromSendStateEventResult, sendStateEventWithEventResult, } from './utils';
7
8
  export { WidgetApiImpl } from './WidgetApiImpl';
@@ -1,11 +1,11 @@
1
1
  import { WidgetApi, WidgetParameters, WidgetRegistration } from './types';
2
2
  /**
3
- * Checks whether all widget parameters were provided to the widget.
3
+ * Checks whether the necessary widget parameters were provided to the widget.
4
4
  *
5
5
  * @param widgetApi - The widget api to read the parameters from
6
6
  * @returns True, if all parameters were provided.
7
7
  */
8
- export declare function hasRequiredWidgetParameters(widgetApi: WidgetApi): boolean;
8
+ export declare function hasWidgetParameters(widgetApi: WidgetApi): boolean;
9
9
  /**
10
10
  * Generate a registration URL for the widget based on the current URL and
11
11
  * include all widget parameters (and their placeholders).
@@ -1,5 +1,19 @@
1
1
  import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, IRoomEvent, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidget, IWidgetApiRequest, IWidgetApiRequestData, ModalButtonID, Symbols, WidgetEventCapability } from 'matrix-widget-api';
2
2
  import { Observable } from 'rxjs';
3
+ /**
4
+ * Enumeration of widget parameters that can be checked if they are available upon registration.
5
+ */
6
+ export declare enum WidgetParameter {
7
+ UserId = "userId",
8
+ DisplayName = "displayName",
9
+ AvatarUrl = "avatarUrl",
10
+ RoomId = "roomId",
11
+ Theme = "theme",
12
+ ClientId = "clientId",
13
+ ClientLanguage = "clientLanguage",
14
+ DeviceId = "deviceId",
15
+ BaseUrl = "baseUrl"
16
+ }
3
17
  /**
4
18
  * Parameters passed from the client to the widget during initialization.
5
19
  */
@@ -39,6 +53,10 @@ export type WidgetParameters = {
39
53
  * The current selected language in the client.
40
54
  */
41
55
  clientLanguage?: string;
56
+ /**
57
+ * The device id of the current client session..
58
+ */
59
+ deviceId?: string;
42
60
  /**
43
61
  * The homeserver base URL.
44
62
  */
@@ -107,6 +125,12 @@ export type WidgetRegistration = {
107
125
  * The display name of the widget.
108
126
  */
109
127
  name?: string;
128
+ /**
129
+ * Checks for custom widget-specific registration parameters that might be required.
130
+ *
131
+ * Added for backwards compatibility with old widget registrations.
132
+ */
133
+ requiredParameters?: WidgetParameter[];
110
134
  /**
111
135
  * The avatar URL used to display an icon on the widget.
112
136
  *
@@ -1,9 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var matrixWidgetApi = require('matrix-widget-api');
4
+ var Joi = require('joi');
4
5
  var qs = require('qs');
5
6
  var rxjs = require('rxjs');
6
7
 
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var Joi__default = /*#__PURE__*/_interopDefault(Joi);
11
+
7
12
  /*
8
13
  * Copyright 2022 Nordeck IT + Consulting GmbH
9
14
  *
@@ -108,6 +113,17 @@ function getRoomMemberDisplayName(member, allRoomMembers) {
108
113
  * See the License for the specific language governing permissions and
109
114
  * limitations under the License.
110
115
  */
116
+ var __assign$2 = (undefined && undefined.__assign) || function () {
117
+ __assign$2 = Object.assign || function(t) {
118
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
119
+ s = arguments[i];
120
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
121
+ t[p] = s[p];
122
+ }
123
+ return t;
124
+ };
125
+ return __assign$2.apply(this, arguments);
126
+ };
111
127
  /**
112
128
  * Check if the given event is a {@link StateEvent}.
113
129
  *
@@ -126,6 +142,58 @@ function isStateEvent(event) {
126
142
  function isRoomEvent(event) {
127
143
  return !('state_key' in event);
128
144
  }
145
+ /**
146
+ * Check if the given value is a valid {@link RoomEvent}.
147
+ *
148
+ * @param event - The value to check
149
+ * @returns true if value is a valid room event, else false.
150
+ */
151
+ // Allow any here, so that the validation works for every event
152
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
+ function isValidRoomEvent(event) {
154
+ return roomEventSchema.validate(event).error === undefined;
155
+ }
156
+ /**
157
+ * Check if the given value is a valid {@link StateEvent}.
158
+ *
159
+ * @param event - The value to check
160
+ * @returns true if value is a valid state event, else false.
161
+ */
162
+ // Allow any here, so that the validation works for every event
163
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
164
+ function isValidStateEvent(event) {
165
+ return stateEventSchema.validate(event).error === undefined;
166
+ }
167
+ /**
168
+ * Check if the given value is a valid {@link ToDeviceMessageEvent}.
169
+ *
170
+ * @param event - The value to check
171
+ * @returns true if value is a valid to device message, else false.
172
+ */
173
+ function isValidToDeviceMessageEvent(event) {
174
+ return toDeviceMessageSchema.validate(event).error === undefined;
175
+ }
176
+ /**
177
+ * Base properties to validate for all events.
178
+ */
179
+ var eventSchemaProps = {
180
+ type: Joi__default.default.string().required(),
181
+ // Do roughly check against the format
182
+ // https://spec.matrix.org/v1.13/appendices/#common-identifier-format
183
+ sender: Joi__default.default.string().pattern(new RegExp('^@[^\\s:]*:\\S*$')).required(),
184
+ event_id: Joi__default.default.string().pattern(new RegExp('^\\$.*')).required(),
185
+ room_id: Joi__default.default.string().pattern(new RegExp('^![^:]*:\\S*')).required(),
186
+ origin_server_ts: Joi__default.default.date().timestamp('javascript').required(),
187
+ content: Joi__default.default.object().required(),
188
+ };
189
+ var roomEventSchema = Joi__default.default.object(__assign$2({}, eventSchemaProps)).unknown();
190
+ var stateEventSchema = Joi__default.default.object(__assign$2(__assign$2({}, eventSchemaProps), { state_key: Joi__default.default.string().allow('').required() })).unknown();
191
+ var toDeviceMessageSchema = Joi__default.default.object({
192
+ type: Joi__default.default.string().required(),
193
+ sender: Joi__default.default.string().required(),
194
+ encrypted: Joi__default.default.boolean().required(),
195
+ content: Joi__default.default.object().required(),
196
+ }).unknown();
129
197
 
130
198
  /*
131
199
  * Copyright 2022 Nordeck IT + Consulting GmbH
@@ -713,6 +781,7 @@ function extractWidgetParameters() {
713
781
  clientId: params['matrix_client_id'],
714
782
  clientLanguage: params['matrix_client_language'],
715
783
  baseUrl: params['matrix_base_url'],
784
+ deviceId: params['matrix_device_id'],
716
785
  isOpenedByClient: isOpenedByClient,
717
786
  };
718
787
  }
@@ -813,12 +882,12 @@ var __rest = (undefined && undefined.__rest) || function (s, e) {
813
882
  return t;
814
883
  };
815
884
  /**
816
- * Checks whether all widget parameters were provided to the widget.
885
+ * Checks whether the necessary widget parameters were provided to the widget.
817
886
  *
818
887
  * @param widgetApi - The widget api to read the parameters from
819
888
  * @returns True, if all parameters were provided.
820
889
  */
821
- function hasRequiredWidgetParameters(widgetApi) {
890
+ function hasWidgetParameters(widgetApi) {
822
891
  return (typeof widgetApi.widgetParameters.userId === 'string' &&
823
892
  typeof widgetApi.widgetParameters.displayName === 'string' &&
824
893
  typeof widgetApi.widgetParameters.avatarUrl === 'string' &&
@@ -838,13 +907,13 @@ function hasRequiredWidgetParameters(widgetApi) {
838
907
  * @returns The generated URL.
839
908
  */
840
909
  function generateWidgetRegistrationUrl(options) {
841
- var _a, _b, _c, _d, _e, _f, _g, _h;
910
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
842
911
  if (options === void 0) { options = {}; }
843
- var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
912
+ var pathName = options.pathName, _k = options.includeParameters, includeParameters = _k === void 0 ? true : _k, widgetParameters = options.widgetParameters;
844
913
  // don't forward widgetId and parentUrl as they will be generated by the client
845
914
  // eslint-disable-next-line
846
- var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
847
- var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
915
+ var _l = extractRawWidgetParameters(); _l.widgetId; _l.parentUrl; var rawWidgetParameters = __rest(_l, ["widgetId", "parentUrl"]);
916
+ var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_device_id: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.deviceId) !== null && _h !== void 0 ? _h : '$org.matrix.msc3819.matrix_device_id', matrix_base_url: (_j = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _j !== void 0 ? _j : '$org.matrix.msc4039.matrix_base_url' }))
848
917
  .map(function (_a) {
849
918
  var k = _a[0], v = _a[1];
850
919
  return "".concat(k, "=").concat(v);
@@ -923,6 +992,37 @@ function repairWidgetRegistration(widgetApi_1) {
923
992
  });
924
993
  }
925
994
 
995
+ /*
996
+ * Copyright 2022 Nordeck IT + Consulting GmbH
997
+ *
998
+ * Licensed under the Apache License, Version 2.0 (the "License");
999
+ * you may not use this file except in compliance with the License.
1000
+ * You may obtain a copy of the License at
1001
+ *
1002
+ * http://www.apache.org/licenses/LICENSE-2.0
1003
+ *
1004
+ * Unless required by applicable law or agreed to in writing, software
1005
+ * distributed under the License is distributed on an "AS IS" BASIS,
1006
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1007
+ * See the License for the specific language governing permissions and
1008
+ * limitations under the License.
1009
+ */
1010
+ /**
1011
+ * Enumeration of widget parameters that can be checked if they are available upon registration.
1012
+ */
1013
+ exports.WidgetParameter = void 0;
1014
+ (function (WidgetParameter) {
1015
+ WidgetParameter["UserId"] = "userId";
1016
+ WidgetParameter["DisplayName"] = "displayName";
1017
+ WidgetParameter["AvatarUrl"] = "avatarUrl";
1018
+ WidgetParameter["RoomId"] = "roomId";
1019
+ WidgetParameter["Theme"] = "theme";
1020
+ WidgetParameter["ClientId"] = "clientId";
1021
+ WidgetParameter["ClientLanguage"] = "clientLanguage";
1022
+ WidgetParameter["DeviceId"] = "deviceId";
1023
+ WidgetParameter["BaseUrl"] = "baseUrl";
1024
+ })(exports.WidgetParameter || (exports.WidgetParameter = {}));
1025
+
926
1026
  /*
927
1027
  * Copyright 2022 Nordeck IT + Consulting GmbH
928
1028
  *
@@ -1146,7 +1246,9 @@ var WidgetApiImpl = /** @class */ (function () {
1146
1246
  // Ignore errors while replying
1147
1247
  }
1148
1248
  return event;
1149
- }).pipe(rxjs.share());
1249
+ })
1250
+ .pipe(rxjs.filter(function (event) { return isValidToDeviceMessageEvent(event.detail.data); }))
1251
+ .pipe(rxjs.share());
1150
1252
  this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [matrixWidgetApi.MatrixCapabilities.RequiresClient]), true);
1151
1253
  }
1152
1254
  /**
@@ -1381,11 +1483,15 @@ var WidgetApiImpl = /** @class */ (function () {
1381
1483
  /** {@inheritDoc WidgetApi.receiveStateEvents} */
1382
1484
  WidgetApiImpl.prototype.receiveStateEvents = function (eventType_1) {
1383
1485
  return __awaiter(this, arguments, void 0, function (eventType, _a) {
1486
+ var unvalidatedEvents, validatedEvents;
1384
1487
  var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
1385
1488
  return __generator(this, function (_c) {
1386
1489
  switch (_c.label) {
1387
1490
  case 0: return [4 /*yield*/, this.matrixWidgetApi.readStateEvents(eventType, Number.MAX_SAFE_INTEGER, stateKey, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
1388
- case 1: return [2 /*return*/, (_c.sent())];
1491
+ case 1:
1492
+ unvalidatedEvents = (_c.sent());
1493
+ validatedEvents = unvalidatedEvents.filter(isValidStateEvent);
1494
+ return [2 /*return*/, validatedEvents];
1389
1495
  }
1390
1496
  });
1391
1497
  });
@@ -1408,7 +1514,7 @@ var WidgetApiImpl = /** @class */ (function () {
1408
1514
  }
1409
1515
  return undefined;
1410
1516
  }), rxjs.filter(isDefined));
1411
- return rxjs.concat(historyEvent$, futureEvent$);
1517
+ return rxjs.concat(historyEvent$, futureEvent$).pipe(rxjs.filter(isValidStateEvent));
1412
1518
  };
1413
1519
  /** {@inheritDoc WidgetApi.sendStateEvent} */
1414
1520
  WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
@@ -1418,11 +1524,15 @@ var WidgetApiImpl = /** @class */ (function () {
1418
1524
  /** {@inheritDoc WidgetApi.receiveRoomEvents} */
1419
1525
  WidgetApiImpl.prototype.receiveRoomEvents = function (eventType_1) {
1420
1526
  return __awaiter(this, arguments, void 0, function (eventType, _a) {
1527
+ var unvalidatedEvents, validatedEvents;
1421
1528
  var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
1422
1529
  return __generator(this, function (_c) {
1423
1530
  switch (_c.label) {
1424
1531
  case 0: return [4 /*yield*/, this.matrixWidgetApi.readRoomEvents(eventType, Number.MAX_SAFE_INTEGER, messageType, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
1425
- case 1: return [2 /*return*/, (_c.sent())];
1532
+ case 1:
1533
+ unvalidatedEvents = (_c.sent());
1534
+ validatedEvents = unvalidatedEvents.filter(isValidRoomEvent);
1535
+ return [2 /*return*/, validatedEvents];
1426
1536
  }
1427
1537
  });
1428
1538
  });
@@ -1445,7 +1555,7 @@ var WidgetApiImpl = /** @class */ (function () {
1445
1555
  }
1446
1556
  return undefined;
1447
1557
  }), rxjs.filter(isDefined));
1448
- return rxjs.concat(historyEvent$, futureEvent$);
1558
+ return rxjs.concat(historyEvent$, futureEvent$).pipe(rxjs.filter(isValidRoomEvent));
1449
1559
  };
1450
1560
  /** {@inheritDoc WidgetApi.sendRoomEvent} */
1451
1561
  WidgetApiImpl.prototype.sendRoomEvent = function (eventType_1, content_1) {
@@ -1511,7 +1621,7 @@ var WidgetApiImpl = /** @class */ (function () {
1511
1621
  };
1512
1622
  /** {@inheritDoc WidgetApi.observeToDeviceMessages} */
1513
1623
  WidgetApiImpl.prototype.observeToDeviceMessages = function (eventType) {
1514
- return this.toDeviceMessages$.pipe(rxjs.map(function (e) { return e.detail.data; }), rxjs.filter(function (e) { return e.type === eventType; }));
1624
+ return this.toDeviceMessages$.pipe(rxjs.map(function (e) { return e.detail.data; }), rxjs.filter(isValidToDeviceMessageEvent), rxjs.filter(function (e) { return e.type === eventType; }));
1515
1625
  };
1516
1626
  /** {@inheritDoc WidgetApi.openModal} */
1517
1627
  WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
@@ -1762,15 +1872,18 @@ exports.getContent = getContent;
1762
1872
  exports.getOriginalEventId = getOriginalEventId;
1763
1873
  exports.getRoomMemberDisplayName = getRoomMemberDisplayName;
1764
1874
  exports.hasActionPower = hasActionPower;
1765
- exports.hasRequiredWidgetParameters = hasRequiredWidgetParameters;
1766
1875
  exports.hasRoomEventPower = hasRoomEventPower;
1767
1876
  exports.hasStateEventPower = hasStateEventPower;
1877
+ exports.hasWidgetParameters = hasWidgetParameters;
1768
1878
  exports.isRoomEvent = isRoomEvent;
1769
1879
  exports.isStateEvent = isStateEvent;
1770
1880
  exports.isValidEventWithRelatesTo = isValidEventWithRelatesTo;
1771
1881
  exports.isValidPowerLevelStateEvent = isValidPowerLevelStateEvent;
1772
1882
  exports.isValidRedactionEvent = isValidRedactionEvent;
1883
+ exports.isValidRoomEvent = isValidRoomEvent;
1773
1884
  exports.isValidRoomMemberStateEvent = isValidRoomMemberStateEvent;
1885
+ exports.isValidStateEVent = isValidStateEvent;
1886
+ exports.isValidToDeviceMessageEvent = isValidToDeviceMessageEvent;
1774
1887
  exports.makeEventFromSendStateEventResult = makeEventFromSendStateEventResult;
1775
1888
  exports.navigateToRoom = navigateToRoom;
1776
1889
  exports.observeRedactionEvents = observeRedactionEvents;
@@ -1,4 +1,5 @@
1
- import { RoomEvent, StateEvent } from '../types';
1
+ import Joi from 'joi';
2
+ import { RoomEvent, StateEvent, ToDeviceMessageEvent } from '../types';
2
3
  /**
3
4
  * Check if the given event is a {@link StateEvent}.
4
5
  *
@@ -13,3 +14,27 @@ export declare function isStateEvent(event: RoomEvent | StateEvent): event is St
13
14
  * @returns True, if the event is a {@link RoomEvent}.
14
15
  */
15
16
  export declare function isRoomEvent(event: RoomEvent | StateEvent): event is RoomEvent;
17
+ /**
18
+ * Check if the given value is a valid {@link RoomEvent}.
19
+ *
20
+ * @param event - The value to check
21
+ * @returns true if value is a valid room event, else false.
22
+ */
23
+ export declare function isValidRoomEvent(event: unknown): event is RoomEvent<any>;
24
+ /**
25
+ * Check if the given value is a valid {@link StateEvent}.
26
+ *
27
+ * @param event - The value to check
28
+ * @returns true if value is a valid state event, else false.
29
+ */
30
+ export declare function isValidStateEvent(event: unknown): event is StateEvent<any>;
31
+ /**
32
+ * Check if the given value is a valid {@link ToDeviceMessageEvent}.
33
+ *
34
+ * @param event - The value to check
35
+ * @returns true if value is a valid to device message, else false.
36
+ */
37
+ export declare function isValidToDeviceMessageEvent(event: unknown): event is ToDeviceMessageEvent<any>;
38
+ export declare const roomEventSchema: Joi.ObjectSchema<RoomEvent>;
39
+ export declare const stateEventSchema: Joi.ObjectSchema<StateEvent>;
40
+ export declare const toDeviceMessageSchema: Joi.ObjectSchema<ToDeviceMessageEvent>;
@@ -1,6 +1,6 @@
1
1
  export { generateRoomTimelineCapabilities } from './capabilities';
2
2
  export { getRoomMemberDisplayName } from './displayName';
3
- export { isRoomEvent, isStateEvent } from './events';
3
+ export { isRoomEvent, isStateEvent, isValidRoomEvent, isValidStateEvent as isValidStateEVent, isValidToDeviceMessageEvent, } from './events';
4
4
  export { WIDGET_CAPABILITY_NAVIGATE, navigateToRoom } from './navigateTo';
5
5
  export type { NavigateToRoomOptions } from './navigateTo';
6
6
  export { compareOriginServerTS } from './originServerTs';
@@ -1,7 +1,8 @@
1
1
  export * from './extras';
2
2
  export { extractRawWidgetParameters, extractWidgetApiParameters, extractWidgetParameters, parseWidgetId, } from './parameters';
3
3
  export type { WidgetApiParameters, WidgetId } from './parameters';
4
- export { generateWidgetRegistrationUrl, hasRequiredWidgetParameters, repairWidgetRegistration, } from './registration';
4
+ export { generateWidgetRegistrationUrl, hasWidgetParameters, repairWidgetRegistration, } from './registration';
5
+ export { WidgetParameter } from './types';
5
6
  export type { RoomEvent, StateEvent, ToDeviceMessageEvent, TurnServer, WidgetApi, WidgetConfig, WidgetParameters, WidgetRegistration, } from './types';
6
7
  export { makeEventFromSendStateEventResult, sendStateEventWithEventResult, } from './utils';
7
8
  export { WidgetApiImpl } from './WidgetApiImpl';
@@ -1,11 +1,11 @@
1
1
  import { WidgetApi, WidgetParameters, WidgetRegistration } from './types';
2
2
  /**
3
- * Checks whether all widget parameters were provided to the widget.
3
+ * Checks whether the necessary widget parameters were provided to the widget.
4
4
  *
5
5
  * @param widgetApi - The widget api to read the parameters from
6
6
  * @returns True, if all parameters were provided.
7
7
  */
8
- export declare function hasRequiredWidgetParameters(widgetApi: WidgetApi): boolean;
8
+ export declare function hasWidgetParameters(widgetApi: WidgetApi): boolean;
9
9
  /**
10
10
  * Generate a registration URL for the widget based on the current URL and
11
11
  * include all widget parameters (and their placeholders).
@@ -1,5 +1,19 @@
1
1
  import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, IRoomEvent, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidget, IWidgetApiRequest, IWidgetApiRequestData, ModalButtonID, Symbols, WidgetEventCapability } from 'matrix-widget-api';
2
2
  import { Observable } from 'rxjs';
3
+ /**
4
+ * Enumeration of widget parameters that can be checked if they are available upon registration.
5
+ */
6
+ export declare enum WidgetParameter {
7
+ UserId = "userId",
8
+ DisplayName = "displayName",
9
+ AvatarUrl = "avatarUrl",
10
+ RoomId = "roomId",
11
+ Theme = "theme",
12
+ ClientId = "clientId",
13
+ ClientLanguage = "clientLanguage",
14
+ DeviceId = "deviceId",
15
+ BaseUrl = "baseUrl"
16
+ }
3
17
  /**
4
18
  * Parameters passed from the client to the widget during initialization.
5
19
  */
@@ -39,6 +53,10 @@ export type WidgetParameters = {
39
53
  * The current selected language in the client.
40
54
  */
41
55
  clientLanguage?: string;
56
+ /**
57
+ * The device id of the current client session..
58
+ */
59
+ deviceId?: string;
42
60
  /**
43
61
  * The homeserver base URL.
44
62
  */
@@ -107,6 +125,12 @@ export type WidgetRegistration = {
107
125
  * The display name of the widget.
108
126
  */
109
127
  name?: string;
128
+ /**
129
+ * Checks for custom widget-specific registration parameters that might be required.
130
+ *
131
+ * Added for backwards compatibility with old widget registrations.
132
+ */
133
+ requiredParameters?: WidgetParameter[];
110
134
  /**
111
135
  * The avatar URL used to display an icon on the widget.
112
136
  *
@@ -1,4 +1,5 @@
1
1
  import { Symbols, WidgetEventCapability, EventDirection, WidgetApi, WidgetApiToWidgetAction, MatrixCapabilities } from 'matrix-widget-api';
2
+ import Joi from 'joi';
2
3
  import { stringify, parse } from 'qs';
3
4
  import { filter, fromEvent, firstValueFrom, map, first, throwError, from, mergeAll, concat, ReplaySubject, share } from 'rxjs';
4
5
 
@@ -106,6 +107,17 @@ function getRoomMemberDisplayName(member, allRoomMembers) {
106
107
  * See the License for the specific language governing permissions and
107
108
  * limitations under the License.
108
109
  */
110
+ var __assign$2 = (undefined && undefined.__assign) || function () {
111
+ __assign$2 = Object.assign || function(t) {
112
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
113
+ s = arguments[i];
114
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
115
+ t[p] = s[p];
116
+ }
117
+ return t;
118
+ };
119
+ return __assign$2.apply(this, arguments);
120
+ };
109
121
  /**
110
122
  * Check if the given event is a {@link StateEvent}.
111
123
  *
@@ -124,6 +136,58 @@ function isStateEvent(event) {
124
136
  function isRoomEvent(event) {
125
137
  return !('state_key' in event);
126
138
  }
139
+ /**
140
+ * Check if the given value is a valid {@link RoomEvent}.
141
+ *
142
+ * @param event - The value to check
143
+ * @returns true if value is a valid room event, else false.
144
+ */
145
+ // Allow any here, so that the validation works for every event
146
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
+ function isValidRoomEvent(event) {
148
+ return roomEventSchema.validate(event).error === undefined;
149
+ }
150
+ /**
151
+ * Check if the given value is a valid {@link StateEvent}.
152
+ *
153
+ * @param event - The value to check
154
+ * @returns true if value is a valid state event, else false.
155
+ */
156
+ // Allow any here, so that the validation works for every event
157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
+ function isValidStateEvent(event) {
159
+ return stateEventSchema.validate(event).error === undefined;
160
+ }
161
+ /**
162
+ * Check if the given value is a valid {@link ToDeviceMessageEvent}.
163
+ *
164
+ * @param event - The value to check
165
+ * @returns true if value is a valid to device message, else false.
166
+ */
167
+ function isValidToDeviceMessageEvent(event) {
168
+ return toDeviceMessageSchema.validate(event).error === undefined;
169
+ }
170
+ /**
171
+ * Base properties to validate for all events.
172
+ */
173
+ var eventSchemaProps = {
174
+ type: Joi.string().required(),
175
+ // Do roughly check against the format
176
+ // https://spec.matrix.org/v1.13/appendices/#common-identifier-format
177
+ sender: Joi.string().pattern(new RegExp('^@[^\\s:]*:\\S*$')).required(),
178
+ event_id: Joi.string().pattern(new RegExp('^\\$.*')).required(),
179
+ room_id: Joi.string().pattern(new RegExp('^![^:]*:\\S*')).required(),
180
+ origin_server_ts: Joi.date().timestamp('javascript').required(),
181
+ content: Joi.object().required(),
182
+ };
183
+ var roomEventSchema = Joi.object(__assign$2({}, eventSchemaProps)).unknown();
184
+ var stateEventSchema = Joi.object(__assign$2(__assign$2({}, eventSchemaProps), { state_key: Joi.string().allow('').required() })).unknown();
185
+ var toDeviceMessageSchema = Joi.object({
186
+ type: Joi.string().required(),
187
+ sender: Joi.string().required(),
188
+ encrypted: Joi.boolean().required(),
189
+ content: Joi.object().required(),
190
+ }).unknown();
127
191
 
128
192
  /*
129
193
  * Copyright 2022 Nordeck IT + Consulting GmbH
@@ -711,6 +775,7 @@ function extractWidgetParameters() {
711
775
  clientId: params['matrix_client_id'],
712
776
  clientLanguage: params['matrix_client_language'],
713
777
  baseUrl: params['matrix_base_url'],
778
+ deviceId: params['matrix_device_id'],
714
779
  isOpenedByClient: isOpenedByClient,
715
780
  };
716
781
  }
@@ -811,12 +876,12 @@ var __rest = (undefined && undefined.__rest) || function (s, e) {
811
876
  return t;
812
877
  };
813
878
  /**
814
- * Checks whether all widget parameters were provided to the widget.
879
+ * Checks whether the necessary widget parameters were provided to the widget.
815
880
  *
816
881
  * @param widgetApi - The widget api to read the parameters from
817
882
  * @returns True, if all parameters were provided.
818
883
  */
819
- function hasRequiredWidgetParameters(widgetApi) {
884
+ function hasWidgetParameters(widgetApi) {
820
885
  return (typeof widgetApi.widgetParameters.userId === 'string' &&
821
886
  typeof widgetApi.widgetParameters.displayName === 'string' &&
822
887
  typeof widgetApi.widgetParameters.avatarUrl === 'string' &&
@@ -836,13 +901,13 @@ function hasRequiredWidgetParameters(widgetApi) {
836
901
  * @returns The generated URL.
837
902
  */
838
903
  function generateWidgetRegistrationUrl(options) {
839
- var _a, _b, _c, _d, _e, _f, _g, _h;
904
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
840
905
  if (options === void 0) { options = {}; }
841
- var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
906
+ var pathName = options.pathName, _k = options.includeParameters, includeParameters = _k === void 0 ? true : _k, widgetParameters = options.widgetParameters;
842
907
  // don't forward widgetId and parentUrl as they will be generated by the client
843
908
  // eslint-disable-next-line
844
- var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
845
- var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
909
+ var _l = extractRawWidgetParameters(); _l.widgetId; _l.parentUrl; var rawWidgetParameters = __rest(_l, ["widgetId", "parentUrl"]);
910
+ var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_device_id: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.deviceId) !== null && _h !== void 0 ? _h : '$org.matrix.msc3819.matrix_device_id', matrix_base_url: (_j = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _j !== void 0 ? _j : '$org.matrix.msc4039.matrix_base_url' }))
846
911
  .map(function (_a) {
847
912
  var k = _a[0], v = _a[1];
848
913
  return "".concat(k, "=").concat(v);
@@ -921,6 +986,37 @@ function repairWidgetRegistration(widgetApi_1) {
921
986
  });
922
987
  }
923
988
 
989
+ /*
990
+ * Copyright 2022 Nordeck IT + Consulting GmbH
991
+ *
992
+ * Licensed under the Apache License, Version 2.0 (the "License");
993
+ * you may not use this file except in compliance with the License.
994
+ * You may obtain a copy of the License at
995
+ *
996
+ * http://www.apache.org/licenses/LICENSE-2.0
997
+ *
998
+ * Unless required by applicable law or agreed to in writing, software
999
+ * distributed under the License is distributed on an "AS IS" BASIS,
1000
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1001
+ * See the License for the specific language governing permissions and
1002
+ * limitations under the License.
1003
+ */
1004
+ /**
1005
+ * Enumeration of widget parameters that can be checked if they are available upon registration.
1006
+ */
1007
+ var WidgetParameter;
1008
+ (function (WidgetParameter) {
1009
+ WidgetParameter["UserId"] = "userId";
1010
+ WidgetParameter["DisplayName"] = "displayName";
1011
+ WidgetParameter["AvatarUrl"] = "avatarUrl";
1012
+ WidgetParameter["RoomId"] = "roomId";
1013
+ WidgetParameter["Theme"] = "theme";
1014
+ WidgetParameter["ClientId"] = "clientId";
1015
+ WidgetParameter["ClientLanguage"] = "clientLanguage";
1016
+ WidgetParameter["DeviceId"] = "deviceId";
1017
+ WidgetParameter["BaseUrl"] = "baseUrl";
1018
+ })(WidgetParameter || (WidgetParameter = {}));
1019
+
924
1020
  /*
925
1021
  * Copyright 2022 Nordeck IT + Consulting GmbH
926
1022
  *
@@ -1144,7 +1240,9 @@ var WidgetApiImpl = /** @class */ (function () {
1144
1240
  // Ignore errors while replying
1145
1241
  }
1146
1242
  return event;
1147
- }).pipe(share());
1243
+ })
1244
+ .pipe(filter(function (event) { return isValidToDeviceMessageEvent(event.detail.data); }))
1245
+ .pipe(share());
1148
1246
  this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [MatrixCapabilities.RequiresClient]), true);
1149
1247
  }
1150
1248
  /**
@@ -1379,11 +1477,15 @@ var WidgetApiImpl = /** @class */ (function () {
1379
1477
  /** {@inheritDoc WidgetApi.receiveStateEvents} */
1380
1478
  WidgetApiImpl.prototype.receiveStateEvents = function (eventType_1) {
1381
1479
  return __awaiter(this, arguments, void 0, function (eventType, _a) {
1480
+ var unvalidatedEvents, validatedEvents;
1382
1481
  var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
1383
1482
  return __generator(this, function (_c) {
1384
1483
  switch (_c.label) {
1385
1484
  case 0: return [4 /*yield*/, this.matrixWidgetApi.readStateEvents(eventType, Number.MAX_SAFE_INTEGER, stateKey, typeof roomIds === 'string' ? [Symbols.AnyRoom] : roomIds)];
1386
- case 1: return [2 /*return*/, (_c.sent())];
1485
+ case 1:
1486
+ unvalidatedEvents = (_c.sent());
1487
+ validatedEvents = unvalidatedEvents.filter(isValidStateEvent);
1488
+ return [2 /*return*/, validatedEvents];
1387
1489
  }
1388
1490
  });
1389
1491
  });
@@ -1406,7 +1508,7 @@ var WidgetApiImpl = /** @class */ (function () {
1406
1508
  }
1407
1509
  return undefined;
1408
1510
  }), filter(isDefined));
1409
- return concat(historyEvent$, futureEvent$);
1511
+ return concat(historyEvent$, futureEvent$).pipe(filter(isValidStateEvent));
1410
1512
  };
1411
1513
  /** {@inheritDoc WidgetApi.sendStateEvent} */
1412
1514
  WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
@@ -1416,11 +1518,15 @@ var WidgetApiImpl = /** @class */ (function () {
1416
1518
  /** {@inheritDoc WidgetApi.receiveRoomEvents} */
1417
1519
  WidgetApiImpl.prototype.receiveRoomEvents = function (eventType_1) {
1418
1520
  return __awaiter(this, arguments, void 0, function (eventType, _a) {
1521
+ var unvalidatedEvents, validatedEvents;
1419
1522
  var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
1420
1523
  return __generator(this, function (_c) {
1421
1524
  switch (_c.label) {
1422
1525
  case 0: return [4 /*yield*/, this.matrixWidgetApi.readRoomEvents(eventType, Number.MAX_SAFE_INTEGER, messageType, typeof roomIds === 'string' ? [Symbols.AnyRoom] : roomIds)];
1423
- case 1: return [2 /*return*/, (_c.sent())];
1526
+ case 1:
1527
+ unvalidatedEvents = (_c.sent());
1528
+ validatedEvents = unvalidatedEvents.filter(isValidRoomEvent);
1529
+ return [2 /*return*/, validatedEvents];
1424
1530
  }
1425
1531
  });
1426
1532
  });
@@ -1443,7 +1549,7 @@ var WidgetApiImpl = /** @class */ (function () {
1443
1549
  }
1444
1550
  return undefined;
1445
1551
  }), filter(isDefined));
1446
- return concat(historyEvent$, futureEvent$);
1552
+ return concat(historyEvent$, futureEvent$).pipe(filter(isValidRoomEvent));
1447
1553
  };
1448
1554
  /** {@inheritDoc WidgetApi.sendRoomEvent} */
1449
1555
  WidgetApiImpl.prototype.sendRoomEvent = function (eventType_1, content_1) {
@@ -1509,7 +1615,7 @@ var WidgetApiImpl = /** @class */ (function () {
1509
1615
  };
1510
1616
  /** {@inheritDoc WidgetApi.observeToDeviceMessages} */
1511
1617
  WidgetApiImpl.prototype.observeToDeviceMessages = function (eventType) {
1512
- return this.toDeviceMessages$.pipe(map(function (e) { return e.detail.data; }), filter(function (e) { return e.type === eventType; }));
1618
+ return this.toDeviceMessages$.pipe(map(function (e) { return e.detail.data; }), filter(isValidToDeviceMessageEvent), filter(function (e) { return e.type === eventType; }));
1513
1619
  };
1514
1620
  /** {@inheritDoc WidgetApi.openModal} */
1515
1621
  WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
@@ -1744,4 +1850,4 @@ var WidgetApiImpl = /** @class */ (function () {
1744
1850
  return WidgetApiImpl;
1745
1851
  }());
1746
1852
 
1747
- export { ROOM_EVENT_REDACTION, STATE_EVENT_POWER_LEVELS, STATE_EVENT_ROOM_MEMBER, WIDGET_CAPABILITY_NAVIGATE, WidgetApiImpl, calculateUserPowerLevel, compareOriginServerTS, extractRawWidgetParameters, extractWidgetApiParameters, extractWidgetParameters, generateRoomTimelineCapabilities, generateWidgetRegistrationUrl, getContent, getOriginalEventId, getRoomMemberDisplayName, hasActionPower, hasRequiredWidgetParameters, hasRoomEventPower, hasStateEventPower, isRoomEvent, isStateEvent, isValidEventWithRelatesTo, isValidPowerLevelStateEvent, isValidRedactionEvent, isValidRoomMemberStateEvent, makeEventFromSendStateEventResult, navigateToRoom, observeRedactionEvents, parseWidgetId, redactEvent, repairWidgetRegistration, sendStateEventWithEventResult };
1853
+ export { ROOM_EVENT_REDACTION, STATE_EVENT_POWER_LEVELS, STATE_EVENT_ROOM_MEMBER, WIDGET_CAPABILITY_NAVIGATE, WidgetApiImpl, WidgetParameter, calculateUserPowerLevel, compareOriginServerTS, extractRawWidgetParameters, extractWidgetApiParameters, extractWidgetParameters, generateRoomTimelineCapabilities, generateWidgetRegistrationUrl, getContent, getOriginalEventId, getRoomMemberDisplayName, hasActionPower, hasRoomEventPower, hasStateEventPower, hasWidgetParameters, isRoomEvent, isStateEvent, isValidEventWithRelatesTo, isValidPowerLevelStateEvent, isValidRedactionEvent, isValidRoomEvent, isValidRoomMemberStateEvent, isValidStateEvent as isValidStateEVent, isValidToDeviceMessageEvent, makeEventFromSendStateEventResult, navigateToRoom, observeRedactionEvents, parseWidgetId, redactEvent, repairWidgetRegistration, sendStateEventWithEventResult };
package/build/index.d.ts CHANGED
@@ -140,14 +140,6 @@ export declare function getRoomMemberDisplayName(member: StateEvent<RoomMemberSt
140
140
  */
141
141
  export declare function hasActionPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, action: PowerLevelsActions): boolean;
142
142
 
143
- /**
144
- * Checks whether all widget parameters were provided to the widget.
145
- *
146
- * @param widgetApi - The widget api to read the parameters from
147
- * @returns True, if all parameters were provided.
148
- */
149
- export declare function hasRequiredWidgetParameters(widgetApi: WidgetApi): boolean;
150
-
151
143
  /**
152
144
  * Check if a user has the power to send a specific room event.
153
145
  *
@@ -168,6 +160,14 @@ export declare function hasRoomEventPower(powerLevelStateEvent: PowerLevelsState
168
160
  */
169
161
  export declare function hasStateEventPower(powerLevelStateEvent: PowerLevelsStateEvent | undefined, userId: string | undefined, eventType: string): boolean;
170
162
 
163
+ /**
164
+ * Checks whether the necessary widget parameters were provided to the widget.
165
+ *
166
+ * @param widgetApi - The widget api to read the parameters from
167
+ * @returns True, if all parameters were provided.
168
+ */
169
+ export declare function hasWidgetParameters(widgetApi: WidgetApi): boolean;
170
+
171
171
  /**
172
172
  * Check if the given event is a {@link RoomEvent}.
173
173
  *
@@ -207,6 +207,14 @@ export declare function isValidPowerLevelStateEvent(event: StateEvent<unknown>):
207
207
  */
208
208
  export declare function isValidRedactionEvent(event: RoomEvent<unknown>): event is RedactionRoomEvent;
209
209
 
210
+ /**
211
+ * Check if the given value is a valid {@link RoomEvent}.
212
+ *
213
+ * @param event - The value to check
214
+ * @returns true if value is a valid room event, else false.
215
+ */
216
+ export declare function isValidRoomEvent(event: unknown): event is RoomEvent<any>;
217
+
210
218
  /**
211
219
  * Validates that `event` is has a valid structure for a
212
220
  * {@link RoomMemberStateEventContent}.
@@ -215,6 +223,22 @@ export declare function isValidRedactionEvent(event: RoomEvent<unknown>): event
215
223
  */
216
224
  export declare function isValidRoomMemberStateEvent(event: StateEvent<unknown>): event is StateEvent<RoomMemberStateEventContent>;
217
225
 
226
+ /**
227
+ * Check if the given value is a valid {@link StateEvent}.
228
+ *
229
+ * @param event - The value to check
230
+ * @returns true if value is a valid state event, else false.
231
+ */
232
+ export declare function isValidStateEVent(event: unknown): event is StateEvent<any>;
233
+
234
+ /**
235
+ * Check if the given value is a valid {@link ToDeviceMessageEvent}.
236
+ *
237
+ * @param event - The value to check
238
+ * @returns true if value is a valid to device message, else false.
239
+ */
240
+ export declare function isValidToDeviceMessageEvent(event: unknown): event is ToDeviceMessageEvent<any>;
241
+
218
242
  /**
219
243
  * Create a state event from the arguments.
220
244
  *
@@ -1004,6 +1028,21 @@ export declare type WidgetId = {
1004
1028
  isModal: boolean;
1005
1029
  };
1006
1030
 
1031
+ /**
1032
+ * Enumeration of widget parameters that can be checked if they are available upon registration.
1033
+ */
1034
+ export declare enum WidgetParameter {
1035
+ UserId = "userId",
1036
+ DisplayName = "displayName",
1037
+ AvatarUrl = "avatarUrl",
1038
+ RoomId = "roomId",
1039
+ Theme = "theme",
1040
+ ClientId = "clientId",
1041
+ ClientLanguage = "clientLanguage",
1042
+ DeviceId = "deviceId",
1043
+ BaseUrl = "baseUrl"
1044
+ }
1045
+
1007
1046
  /**
1008
1047
  * Parameters passed from the client to the widget during initialization.
1009
1048
  */
@@ -1043,6 +1082,10 @@ export declare type WidgetParameters = {
1043
1082
  * The current selected language in the client.
1044
1083
  */
1045
1084
  clientLanguage?: string;
1085
+ /**
1086
+ * The device id of the current client session..
1087
+ */
1088
+ deviceId?: string;
1046
1089
  /**
1047
1090
  * The homeserver base URL.
1048
1091
  */
@@ -1072,6 +1115,12 @@ export declare type WidgetRegistration = {
1072
1115
  * The display name of the widget.
1073
1116
  */
1074
1117
  name?: string;
1118
+ /**
1119
+ * Checks for custom widget-specific registration parameters that might be required.
1120
+ *
1121
+ * Added for backwards compatibility with old widget registrations.
1122
+ */
1123
+ requiredParameters?: WidgetParameter[];
1075
1124
  /**
1076
1125
  * The avatar URL used to display an icon on the widget.
1077
1126
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matrix-widget-toolkit/api",
3
- "version": "4.0.0",
3
+ "version": "4.1.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.1",
26
- "@types/node": "22.10.1",
27
- "@types/qs": "6.9.17",
28
- "@vitest/coverage-v8": "2.1.8",
29
- "typescript": "5.7.2",
30
- "vite": "5.4.11",
31
- "vitest": "2.1.8"
25
+ "@rollup/plugin-commonjs": "28.0.2",
26
+ "@types/node": "22.13.5",
27
+ "@types/qs": "6.9.18",
28
+ "@vitest/coverage-v8": "3.0.7",
29
+ "typescript": "5.7.3",
30
+ "vite": "6.2.0",
31
+ "vitest": "3.0.7"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsc && rollup --config ../../rollup.config.mjs",
@@ -40,12 +40,16 @@
40
40
  "postpack": "node ../../scripts/postpack.js",
41
41
  "translate": "echo \"Nothing to translate\"",
42
42
  "check-api-report": "api-extractor run --verbose",
43
- "generate-api-report": "tsc && api-extractor run --verbose --local"
43
+ "generate-api-report": "tsc && api-extractor run --verbose --local",
44
+ "clean": "yarn run clean:build",
45
+ "clean:build": "rm -rf lib",
46
+ "clean:cache": "echo 'script not implemented package'"
44
47
  },
45
48
  "dependencies": {
46
- "matrix-widget-api": "1.10.0",
47
- "qs": "6.13.1",
48
- "rxjs": "7.8.1"
49
+ "joi": "17.13.3",
50
+ "matrix-widget-api": "1.13.1",
51
+ "qs": "6.14.0",
52
+ "rxjs": "7.8.2"
49
53
  },
50
54
  "repository": {
51
55
  "type": "git",