@matrix-widget-toolkit/api 3.4.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/build/cjs/api/WidgetApiImpl.d.cts +179 -0
  2. package/build/cjs/api/WidgetApiImpl.test.d.cts +1 -0
  3. package/build/cjs/api/extras/capabilities.d.cts +12 -0
  4. package/build/cjs/api/extras/capabilities.test.d.cts +1 -0
  5. package/build/cjs/api/extras/displayName.d.cts +12 -0
  6. package/build/cjs/api/extras/displayName.test.d.cts +1 -0
  7. package/build/cjs/api/extras/events.d.cts +15 -0
  8. package/build/cjs/api/extras/events.test.d.cts +1 -0
  9. package/build/cjs/api/extras/index.d.cts +14 -0
  10. package/build/cjs/api/extras/navigateTo.d.cts +24 -0
  11. package/build/cjs/api/extras/navigateTo.test.d.cts +1 -0
  12. package/build/cjs/api/extras/originServerTs.d.cts +10 -0
  13. package/build/cjs/api/extras/originServerTs.test.d.cts +1 -0
  14. package/build/cjs/api/extras/powerLevel.d.cts +105 -0
  15. package/build/cjs/api/extras/powerLevel.test.d.cts +1 -0
  16. package/build/cjs/api/extras/redactions.d.cts +42 -0
  17. package/build/cjs/api/extras/redactions.test.d.cts +1 -0
  18. package/build/cjs/api/extras/relatesTo.d.cts +60 -0
  19. package/build/cjs/api/extras/relatesTo.test.d.cts +1 -0
  20. package/build/cjs/api/extras/roomMember.d.cts +35 -0
  21. package/build/cjs/api/extras/roomMember.test.d.cts +1 -0
  22. package/build/cjs/api/index.d.cts +8 -0
  23. package/build/cjs/api/parameters.d.cts +58 -0
  24. package/build/cjs/api/parameters.test.d.cts +1 -0
  25. package/build/cjs/api/registration.d.cts +33 -0
  26. package/build/cjs/api/registration.test.d.cts +1 -0
  27. package/build/cjs/api/types.d.cts +466 -0
  28. package/build/cjs/api/utils.d.cts +20 -0
  29. package/build/cjs/api/utils.test.d.cts +1 -0
  30. package/build/cjs/{index.js → index.cjs} +100 -48
  31. package/build/cjs/index.d.cts +5 -0
  32. package/build/esm/api/WidgetApiImpl.d.ts +179 -0
  33. package/build/esm/api/WidgetApiImpl.test.d.ts +1 -0
  34. package/build/esm/api/extras/capabilities.d.ts +12 -0
  35. package/build/esm/api/extras/capabilities.test.d.ts +1 -0
  36. package/build/esm/api/extras/displayName.d.ts +12 -0
  37. package/build/esm/api/extras/displayName.test.d.ts +1 -0
  38. package/build/esm/api/extras/events.d.ts +15 -0
  39. package/build/esm/api/extras/events.test.d.ts +1 -0
  40. package/build/esm/api/extras/index.d.ts +14 -0
  41. package/build/esm/api/extras/navigateTo.d.ts +24 -0
  42. package/build/esm/api/extras/navigateTo.test.d.ts +1 -0
  43. package/build/esm/api/extras/originServerTs.d.ts +10 -0
  44. package/build/esm/api/extras/originServerTs.test.d.ts +1 -0
  45. package/build/esm/api/extras/powerLevel.d.ts +105 -0
  46. package/build/esm/api/extras/powerLevel.test.d.ts +1 -0
  47. package/build/esm/api/extras/redactions.d.ts +42 -0
  48. package/build/esm/api/extras/redactions.test.d.ts +1 -0
  49. package/build/esm/api/extras/relatesTo.d.ts +60 -0
  50. package/build/esm/api/extras/relatesTo.test.d.ts +1 -0
  51. package/build/esm/api/extras/roomMember.d.ts +35 -0
  52. package/build/esm/api/extras/roomMember.test.d.ts +1 -0
  53. package/build/esm/api/index.d.ts +8 -0
  54. package/build/esm/api/parameters.d.ts +58 -0
  55. package/build/esm/api/parameters.test.d.ts +1 -0
  56. package/build/esm/api/registration.d.ts +33 -0
  57. package/build/esm/api/registration.test.d.ts +1 -0
  58. package/build/esm/api/types.d.ts +466 -0
  59. package/build/esm/api/utils.d.ts +20 -0
  60. package/build/esm/api/utils.test.d.ts +1 -0
  61. package/build/esm/index.d.ts +5 -0
  62. package/build/esm/index.js +99 -49
  63. package/build/index.d.ts +17 -2
  64. package/package.json +27 -15
@@ -142,7 +142,7 @@ function isRoomEvent(event) {
142
142
  * See the License for the specific language governing permissions and
143
143
  * limitations under the License.
144
144
  */
145
- var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
145
+ var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
146
146
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
147
147
  return new (P || (P = Promise))(function (resolve, reject) {
148
148
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -151,7 +151,7 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
151
151
  step((generator = generator.apply(thisArg, _arguments || [])).next());
152
152
  });
153
153
  };
154
- var __generator$3 = (undefined && undefined.__generator) || function (thisArg, body) {
154
+ var __generator$4 = (undefined && undefined.__generator) || function (thisArg, body) {
155
155
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
156
156
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
157
157
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -192,10 +192,10 @@ var WIDGET_CAPABILITY_NAVIGATE = 'org.matrix.msc2931.navigate';
192
192
  * @param opts - {@link NavigateToRoomOptions}
193
193
  */
194
194
  function navigateToRoom(widgetApi_1, roomId_1) {
195
- return __awaiter$3(this, arguments, void 0, function (widgetApi, roomId, opts) {
195
+ return __awaiter$4(this, arguments, void 0, function (widgetApi, roomId, opts) {
196
196
  var _a, via, params, url;
197
197
  if (opts === void 0) { opts = {}; }
198
- return __generator$3(this, function (_b) {
198
+ return __generator$4(this, function (_b) {
199
199
  switch (_b.label) {
200
200
  case 0:
201
201
  _a = opts.via, via = _a === void 0 ? [] : _a;
@@ -439,7 +439,7 @@ function calculateActionPowerLevel(powerLevelStateEvent, action) {
439
439
  * See the License for the specific language governing permissions and
440
440
  * limitations under the License.
441
441
  */
442
- var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
442
+ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
443
443
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
444
444
  return new (P || (P = Promise))(function (resolve, reject) {
445
445
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -448,7 +448,7 @@ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _argu
448
448
  step((generator = generator.apply(thisArg, _arguments || [])).next());
449
449
  });
450
450
  };
451
- var __generator$2 = (undefined && undefined.__generator) || function (thisArg, body) {
451
+ var __generator$3 = (undefined && undefined.__generator) || function (thisArg, body) {
452
452
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
453
453
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
454
454
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -498,9 +498,9 @@ function isValidRedactionEvent(event) {
498
498
  * @returns The redaction event that was send to the room.
499
499
  */
500
500
  function redactEvent(widgetApi, eventId) {
501
- return __awaiter$2(this, void 0, void 0, function () {
501
+ return __awaiter$3(this, void 0, void 0, function () {
502
502
  var result;
503
- return __generator$2(this, function (_a) {
503
+ return __generator$3(this, function (_a) {
504
504
  switch (_a.label) {
505
505
  case 0: return [4 /*yield*/, widgetApi.sendRoomEvent(ROOM_EVENT_REDACTION, { redacts: eventId })];
506
506
  case 1:
@@ -765,7 +765,7 @@ var __assign = (undefined && undefined.__assign) || function () {
765
765
  };
766
766
  return __assign.apply(this, arguments);
767
767
  };
768
- var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
768
+ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
769
769
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
770
770
  return new (P || (P = Promise))(function (resolve, reject) {
771
771
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -774,7 +774,7 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
774
774
  step((generator = generator.apply(thisArg, _arguments || [])).next());
775
775
  });
776
776
  };
777
- var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
777
+ var __generator$2 = (undefined && undefined.__generator) || function (thisArg, body) {
778
778
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
779
779
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
780
780
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -873,10 +873,10 @@ var STATE_EVENT_WIDGETS = 'im.vector.modular.widgets';
873
873
  * registration, like the display name of the widget.
874
874
  */
875
875
  function repairWidgetRegistration(widgetApi_1) {
876
- return __awaiter$1(this, arguments, void 0, function (widgetApi, registration) {
876
+ return __awaiter$2(this, arguments, void 0, function (widgetApi, registration) {
877
877
  var readResult, url, name, type, data;
878
878
  if (registration === void 0) { registration = {}; }
879
- return __generator$1(this, function (_a) {
879
+ return __generator$2(this, function (_a) {
880
880
  switch (_a.label) {
881
881
  case 0: return [4 /*yield*/, widgetApi.requestCapabilities([
882
882
  matrixWidgetApi.WidgetEventCapability.forStateEvent(matrixWidgetApi.EventDirection.Send, STATE_EVENT_WIDGETS, widgetApi.widgetId),
@@ -938,6 +938,42 @@ function repairWidgetRegistration(widgetApi_1) {
938
938
  * See the License for the specific language governing permissions and
939
939
  * limitations under the License.
940
940
  */
941
+ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
942
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
943
+ return new (P || (P = Promise))(function (resolve, reject) {
944
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
945
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
946
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
947
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
948
+ });
949
+ };
950
+ var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
951
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
952
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
953
+ function verb(n) { return function (v) { return step([n, v]); }; }
954
+ function step(op) {
955
+ if (f) throw new TypeError("Generator is already executing.");
956
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
957
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
958
+ if (y = 0, t) op = [op[0] & 2, t.value];
959
+ switch (op[0]) {
960
+ case 0: case 1: t = op; break;
961
+ case 4: _.label++; return { value: op[1], done: false };
962
+ case 5: _.label++; y = op[1]; op = [0]; continue;
963
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
964
+ default:
965
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
966
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
967
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
968
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
969
+ if (t[2]) _.ops.pop();
970
+ _.trys.pop(); continue;
971
+ }
972
+ op = body.call(thisArg, _);
973
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
974
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
975
+ }
976
+ };
941
977
  function convertToRawCapabilities(rawCapabilities) {
942
978
  return rawCapabilities.map(function (c) { return (typeof c === 'string' ? c : c.raw); });
943
979
  }
@@ -964,6 +1000,47 @@ function isInRoom(matrixEvent, currentRoomId, roomIds) {
964
1000
  }
965
1001
  return roomIds.includes(matrixEvent.room_id);
966
1002
  }
1003
+ /**
1004
+ * Create a state event from the arguments.
1005
+ *
1006
+ * @returns A state event with current timestamp origin_server_ts.
1007
+ */
1008
+ function makeEventFromSendStateEventResult(type, stateKey, content, sender, sendResult) {
1009
+ if (sendResult.event_id === undefined) {
1010
+ throw new Error('Send state event did not return an event ID');
1011
+ }
1012
+ return {
1013
+ content: content,
1014
+ event_id: sendResult.event_id,
1015
+ origin_server_ts: Date.now(),
1016
+ room_id: sendResult.room_id,
1017
+ sender: sender,
1018
+ state_key: stateKey,
1019
+ type: type,
1020
+ };
1021
+ }
1022
+ /**
1023
+ * Send a state event and resolve to a "virtual" state event.
1024
+ *
1025
+ * @returns Promise, that resolves to a state event with current timestamp origin_server_ts.
1026
+ */
1027
+ function sendStateEventWithEventResult(widgetApi, type, stateKey, content) {
1028
+ return __awaiter$1(this, void 0, void 0, function () {
1029
+ var response;
1030
+ return __generator$1(this, function (_a) {
1031
+ switch (_a.label) {
1032
+ case 0:
1033
+ if (widgetApi.widgetParameters.userId === undefined) {
1034
+ throw new Error('Own user ID is undefined');
1035
+ }
1036
+ return [4 /*yield*/, widgetApi.sendStateEvent(type, content, { stateKey: stateKey })];
1037
+ case 1:
1038
+ response = _a.sent();
1039
+ return [2 /*return*/, makeEventFromSendStateEventResult(type, stateKey, content, widgetApi.widgetParameters.userId, response)];
1040
+ }
1041
+ });
1042
+ });
1043
+ }
967
1044
 
968
1045
  /*
969
1046
  * Copyright 2022 Nordeck IT + Consulting GmbH
@@ -1334,36 +1411,9 @@ var WidgetApiImpl = /** @class */ (function () {
1334
1411
  return rxjs.concat(historyEvent$, futureEvent$);
1335
1412
  };
1336
1413
  /** {@inheritDoc WidgetApi.sendStateEvent} */
1337
- WidgetApiImpl.prototype.sendStateEvent = function (eventType_1, content_1) {
1338
- return __awaiter(this, arguments, void 0, function (eventType, content, _a) {
1339
- var subject, subscription, _b, event_id_1, room_id_1, event_1;
1340
- var _c = _a === void 0 ? {} : _a, roomId = _c.roomId, _d = _c.stateKey, stateKey = _d === void 0 ? '' : _d;
1341
- return __generator(this, function (_e) {
1342
- switch (_e.label) {
1343
- case 0:
1344
- subject = new rxjs.ReplaySubject();
1345
- subscription = this.events$.subscribe(function (e) { return subject.next(e); });
1346
- _e.label = 1;
1347
- case 1:
1348
- _e.trys.push([1, , 4, 5]);
1349
- return [4 /*yield*/, this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId)];
1350
- case 2:
1351
- _b = _e.sent(), event_id_1 = _b.event_id, room_id_1 = _b.room_id;
1352
- return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
1353
- var matrixEvent = event.detail.data;
1354
- return (matrixEvent.event_id === event_id_1 &&
1355
- matrixEvent.room_id === room_id_1);
1356
- }), rxjs.map(function (event) { return event.detail.data; })))];
1357
- case 3:
1358
- event_1 = _e.sent();
1359
- return [2 /*return*/, event_1];
1360
- case 4:
1361
- subscription.unsubscribe();
1362
- return [7 /*endfinally*/];
1363
- case 5: return [2 /*return*/];
1364
- }
1365
- });
1366
- });
1414
+ WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
1415
+ var _b = _a === void 0 ? {} : _a, roomId = _b.roomId, _c = _b.stateKey, stateKey = _c === void 0 ? '' : _c;
1416
+ return this.matrixWidgetApi.sendStateEvent(eventType, stateKey, content, roomId);
1367
1417
  };
1368
1418
  /** {@inheritDoc WidgetApi.receiveRoomEvents} */
1369
1419
  WidgetApiImpl.prototype.receiveRoomEvents = function (eventType_1) {
@@ -1400,7 +1450,7 @@ var WidgetApiImpl = /** @class */ (function () {
1400
1450
  /** {@inheritDoc WidgetApi.sendRoomEvent} */
1401
1451
  WidgetApiImpl.prototype.sendRoomEvent = function (eventType_1, content_1) {
1402
1452
  return __awaiter(this, arguments, void 0, function (eventType, content, _a) {
1403
- var subject, subscription, _b, event_id_2, room_id_2, event_2;
1453
+ var subject, subscription, _b, event_id_1, room_id_1, event_1;
1404
1454
  var _c = _a === void 0 ? {} : _a, roomId = _c.roomId;
1405
1455
  return __generator(this, function (_d) {
1406
1456
  switch (_d.label) {
@@ -1412,15 +1462,15 @@ var WidgetApiImpl = /** @class */ (function () {
1412
1462
  _d.trys.push([1, , 4, 5]);
1413
1463
  return [4 /*yield*/, this.matrixWidgetApi.sendRoomEvent(eventType, content, roomId)];
1414
1464
  case 2:
1415
- _b = _d.sent(), event_id_2 = _b.event_id, room_id_2 = _b.room_id;
1465
+ _b = _d.sent(), event_id_1 = _b.event_id, room_id_1 = _b.room_id;
1416
1466
  return [4 /*yield*/, rxjs.firstValueFrom(subject.pipe(rxjs.filter(function (event) {
1417
1467
  var matrixEvent = event.detail.data;
1418
- return (matrixEvent.event_id === event_id_2 &&
1419
- matrixEvent.room_id === room_id_2);
1468
+ return (matrixEvent.event_id === event_id_1 &&
1469
+ matrixEvent.room_id === room_id_1);
1420
1470
  }), rxjs.map(function (event) { return event.detail.data; })))];
1421
1471
  case 3:
1422
- event_2 = _d.sent();
1423
- return [2 /*return*/, event_2];
1472
+ event_1 = _d.sent();
1473
+ return [2 /*return*/, event_1];
1424
1474
  case 4:
1425
1475
  subscription.unsubscribe();
1426
1476
  return [7 /*endfinally*/];
@@ -1721,8 +1771,10 @@ exports.isValidEventWithRelatesTo = isValidEventWithRelatesTo;
1721
1771
  exports.isValidPowerLevelStateEvent = isValidPowerLevelStateEvent;
1722
1772
  exports.isValidRedactionEvent = isValidRedactionEvent;
1723
1773
  exports.isValidRoomMemberStateEvent = isValidRoomMemberStateEvent;
1774
+ exports.makeEventFromSendStateEventResult = makeEventFromSendStateEventResult;
1724
1775
  exports.navigateToRoom = navigateToRoom;
1725
1776
  exports.observeRedactionEvents = observeRedactionEvents;
1726
1777
  exports.parseWidgetId = parseWidgetId;
1727
1778
  exports.redactEvent = redactEvent;
1728
1779
  exports.repairWidgetRegistration = repairWidgetRegistration;
1780
+ exports.sendStateEventWithEventResult = sendStateEventWithEventResult;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @packageDocumentation This is package that wraps `matrix-widget-api` to
3
+ * provide a more convenient API.
4
+ */
5
+ export * from './api';
@@ -0,0 +1,179 @@
1
+ import { Capability, IDownloadFileActionFromWidgetResponseData, IGetMediaConfigActionFromWidgetResponseData, IModalWidgetCreateData, IModalWidgetOpenRequestDataButton, IModalWidgetReturnData, IOpenIDCredentials, ISendEventFromWidgetResponseData, IUploadFileActionFromWidgetResponseData, IWidgetApiRequestData, WidgetApi as MatrixWidgetApi, ModalButtonID, Symbols, WidgetEventCapability } from 'matrix-widget-api';
2
+ import { Observable } from 'rxjs';
3
+ import { RoomEvent, StateEvent, ToDeviceMessageEvent, TurnServer, WidgetApi, WidgetConfig, WidgetParameters } from './types';
4
+ /**
5
+ * Options for the {@link WidgetApiImpl.create} function.
6
+ */
7
+ export type WidgetApiOptions = {
8
+ /**
9
+ * Optional initial capabilities that should be requested from the user on
10
+ * load.
11
+ */
12
+ capabilities?: Array<WidgetEventCapability | Capability>;
13
+ /**
14
+ * Enable the the pop-out button for pinned widgets that support running
15
+ * without the Widget API.
16
+ */
17
+ supportStandalone?: boolean;
18
+ };
19
+ /**
20
+ * Implementation of the API from the widget to the client.
21
+ *
22
+ * @remarks Widget API is specified here:
23
+ * https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit#heading=h.9rn9lt6ctkgi
24
+ */
25
+ export declare class WidgetApiImpl implements WidgetApi {
26
+ /**
27
+ * Provide access to the underlying widget API from `matrix-widget-sdk`.
28
+ *
29
+ * @remarks Normally there is no need to use it, however if features are
30
+ * missing from `WidgetApi` it can be handy to work with the
31
+ * original API.
32
+ */
33
+ readonly matrixWidgetApi: MatrixWidgetApi;
34
+ /** {@inheritDoc WidgetApi.widgetId} */
35
+ readonly widgetId: string;
36
+ /** {@inheritDoc WidgetApi.widgetParameters} */
37
+ readonly widgetParameters: WidgetParameters;
38
+ /**
39
+ * Initialize a new widget API instance and wait till it is ready.
40
+ * There should only be one instance of the widget API. The widget API should
41
+ * be created as early as possible when starting the application. This is
42
+ * required to match the timing of the API connection establishment with the
43
+ * client, especially in Safari. Therefore it is recommended to create it
44
+ * inside the entrypoint, before initializing rendering engines like react.
45
+ *
46
+ * @param param0 - {@link WidgetApiOptions}
47
+ *
48
+ * @returns A widget API instance ready to use.
49
+ */
50
+ static create({ capabilities, supportStandalone, }?: WidgetApiOptions): Promise<WidgetApi>;
51
+ private widgetConfig;
52
+ private outstandingCapabilitiesRequest;
53
+ private outstandingOpenIDConnectTokenRequest;
54
+ private cachedOpenIdToken;
55
+ private readonly events$;
56
+ private readonly toDeviceMessages$;
57
+ private readonly initialCapabilities;
58
+ constructor(
59
+ /**
60
+ * Provide access to the underlying widget API from `matrix-widget-sdk`.
61
+ *
62
+ * @remarks Normally there is no need to use it, however if features are
63
+ * missing from `WidgetApi` it can be handy to work with the
64
+ * original API.
65
+ */
66
+ matrixWidgetApi: MatrixWidgetApi,
67
+ /** {@inheritDoc WidgetApi.widgetId} */
68
+ widgetId: string,
69
+ /** {@inheritDoc WidgetApi.widgetParameters} */
70
+ widgetParameters: WidgetParameters, { capabilities, supportStandalone }?: WidgetApiOptions);
71
+ /**
72
+ * Initialize the widget API and wait till a connection with the client is
73
+ * fully established.
74
+ *
75
+ * Waits till the user has approved the initial set of capabilities. The
76
+ * method doesn't fail if the user doesn't approve all of them. It is
77
+ * required to check manually afterwards.
78
+ * In case of modal widgets it waits till the `widgetConfig` is received.
79
+ *
80
+ * @remarks Should only be called once during startup.
81
+ */
82
+ initialize(): Promise<void>;
83
+ /** {@inheritDoc WidgetApi.getWidgetConfig} */
84
+ getWidgetConfig<T extends IWidgetApiRequestData>(): Readonly<WidgetConfig<T> | undefined>;
85
+ /** {@inheritDoc WidgetApi.rerequestInitialCapabilities} */
86
+ rerequestInitialCapabilities(): Promise<void>;
87
+ /** {@inheritDoc WidgetApi.hasInitialCapabilities} */
88
+ hasInitialCapabilities(): boolean;
89
+ /** {@inheritDoc WidgetApi.requestCapabilities} */
90
+ requestCapabilities(capabilities: Array<WidgetEventCapability | Capability>): Promise<void>;
91
+ private requestCapabilitiesInternal;
92
+ /** {@inheritDoc WidgetApi.hasCapabilities} */
93
+ hasCapabilities(capabilities: Array<WidgetEventCapability | Capability>): boolean;
94
+ /** {@inheritDoc WidgetApi.receiveSingleStateEvent} */
95
+ receiveSingleStateEvent<T>(eventType: string, stateKey?: string): Promise<StateEvent<T> | undefined>;
96
+ /** {@inheritDoc WidgetApi.receiveStateEvents} */
97
+ receiveStateEvents<T>(eventType: string, { stateKey, roomIds, }?: {
98
+ stateKey?: string;
99
+ roomIds?: string[] | Symbols.AnyRoom;
100
+ }): Promise<StateEvent<T>[]>;
101
+ /** {@inheritDoc WidgetApi.observeStateEvents} */
102
+ observeStateEvents<T>(eventType: string, { stateKey, roomIds, }?: {
103
+ stateKey?: string;
104
+ roomIds?: string[] | Symbols.AnyRoom;
105
+ }): Observable<StateEvent<T>>;
106
+ /** {@inheritDoc WidgetApi.sendStateEvent} */
107
+ sendStateEvent<T>(eventType: string, content: T, { roomId, stateKey }?: {
108
+ roomId?: string;
109
+ stateKey?: string;
110
+ }): Promise<ISendEventFromWidgetResponseData>;
111
+ /** {@inheritDoc WidgetApi.receiveRoomEvents} */
112
+ receiveRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
113
+ messageType?: string;
114
+ roomIds?: string[] | Symbols.AnyRoom;
115
+ }): Promise<Array<RoomEvent<T>>>;
116
+ /** {@inheritDoc WidgetApi.observeRoomEvents} */
117
+ observeRoomEvents<T>(eventType: string, { messageType, roomIds, }?: {
118
+ messageType?: string;
119
+ roomIds?: string[] | Symbols.AnyRoom;
120
+ }): Observable<RoomEvent<T>>;
121
+ /** {@inheritDoc WidgetApi.sendRoomEvent} */
122
+ sendRoomEvent<T>(eventType: string, content: T, { roomId }?: {
123
+ roomId?: string;
124
+ }): Promise<RoomEvent<T>>;
125
+ /** {@inheritDoc WidgetApi.readEventRelations} */
126
+ readEventRelations(eventId: string, options?: {
127
+ roomId?: string;
128
+ limit?: number;
129
+ from?: string;
130
+ relationType?: string;
131
+ eventType?: string;
132
+ direction?: 'f' | 'b';
133
+ }): Promise<{
134
+ chunk: Array<RoomEvent | StateEvent>;
135
+ nextToken?: string;
136
+ }>;
137
+ /** {@inheritDoc WidgetApi.sendToDeviceMessage} */
138
+ sendToDeviceMessage<T>(eventType: string, encrypted: boolean, content: {
139
+ [userId: string]: {
140
+ [deviceId: string | '*']: T;
141
+ };
142
+ }): Promise<void>;
143
+ /** {@inheritDoc WidgetApi.observeToDeviceMessages} */
144
+ observeToDeviceMessages<T>(eventType: string): Observable<ToDeviceMessageEvent<T>>;
145
+ /** {@inheritDoc WidgetApi.openModal} */
146
+ openModal<T extends Record<string, unknown> = Record<string, unknown>, U extends IModalWidgetCreateData = IModalWidgetCreateData>(pathName: string, name: string, options?: {
147
+ buttons?: IModalWidgetOpenRequestDataButton[];
148
+ data?: U;
149
+ }): Promise<T | undefined>;
150
+ /** {@inheritDoc WidgetApi.setModalButtonEnabled} */
151
+ setModalButtonEnabled(buttonId: ModalButtonID, isEnabled: boolean): Promise<void>;
152
+ /** {@inheritDoc WidgetApi.observeModalButtons} */
153
+ observeModalButtons(): Observable<ModalButtonID>;
154
+ /** {@inheritDoc WidgetApi.closeModal} */
155
+ closeModal<T extends IModalWidgetReturnData>(data?: T): Promise<void>;
156
+ /** {@inheritdoc WidgetApi.navigateTo} */
157
+ navigateTo(uri: string): Promise<void>;
158
+ /** {@inheritdoc WidgetApi.requestOpenIDConnectToken} */
159
+ requestOpenIDConnectToken(): Promise<IOpenIDCredentials>;
160
+ private requestOpenIDConnectTokenInternal;
161
+ /** {@inheritdoc WidgetApi.observeTurnServers} */
162
+ observeTurnServers(): Observable<TurnServer>;
163
+ /** {@inheritdoc WidgetApi.searchUserDirectory} */
164
+ searchUserDirectory(searchTerm: string, options?: {
165
+ limit?: number | undefined;
166
+ } | undefined): Promise<{
167
+ results: Array<{
168
+ userId: string;
169
+ displayName?: string;
170
+ avatarUrl?: string;
171
+ }>;
172
+ }>;
173
+ /** {@inheritdoc WidgetApi.getMediaConfig} */
174
+ getMediaConfig(): Promise<IGetMediaConfigActionFromWidgetResponseData>;
175
+ /** {@inheritdoc WidgetApi.uploadFile} */
176
+ uploadFile(file: XMLHttpRequestBodyInit): Promise<IUploadFileActionFromWidgetResponseData>;
177
+ /** {@inheritdoc WidgetApi.downloadFile} */
178
+ downloadFile(contentUrl: string): Promise<IDownloadFileActionFromWidgetResponseData>;
179
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Symbols } from 'matrix-widget-api';
2
+ /**
3
+ * Generate a list of capabilities to access the timeline of other rooms.
4
+ * If enabled, all previously or future capabilities will apply to _all_
5
+ * selected rooms.
6
+ * If `Symbols.AnyRoom` is passed, this is expanded to all joined
7
+ * or invited rooms the client is able to see, current and future.
8
+ *
9
+ * @param roomIds - a list of room ids or `@link Symbols.AnyRoom`.
10
+ * @returns the generated capabilities.
11
+ */
12
+ export declare function generateRoomTimelineCapabilities(roomIds: string[] | Symbols.AnyRoom): string[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { StateEvent } from '../types';
2
+ import { RoomMemberStateEventContent } from './roomMember';
3
+ /**
4
+ * Generate a unique displayname of a user that is consistent across Matrix clients.
5
+ *
6
+ * @remarks The algorithm is based on https://spec.matrix.org/v1.1/client-server-api/#calculating-the-display-name-for-a-user
7
+ *
8
+ * @param member - the member to generate a name for.
9
+ * @param allRoomMembers - a list of all members of the same room.
10
+ * @returns the displayname that is unique in given the set of all room members.
11
+ */
12
+ export declare function getRoomMemberDisplayName(member: StateEvent<RoomMemberStateEventContent>, allRoomMembers?: StateEvent<RoomMemberStateEventContent>[]): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { RoomEvent, StateEvent } from '../types';
2
+ /**
3
+ * Check if the given event is a {@link StateEvent}.
4
+ *
5
+ * @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
6
+ * @returns True, if the event is a {@link StateEvent}.
7
+ */
8
+ export declare function isStateEvent(event: RoomEvent | StateEvent): event is StateEvent;
9
+ /**
10
+ * Check if the given event is a {@link RoomEvent}.
11
+ *
12
+ * @param event - An event that is either a {@link RoomEvent} or a {@link StateEvent}.
13
+ * @returns True, if the event is a {@link RoomEvent}.
14
+ */
15
+ export declare function isRoomEvent(event: RoomEvent | StateEvent): event is RoomEvent;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ export { generateRoomTimelineCapabilities } from './capabilities';
2
+ export { getRoomMemberDisplayName } from './displayName';
3
+ export { isRoomEvent, isStateEvent } from './events';
4
+ export { WIDGET_CAPABILITY_NAVIGATE, navigateToRoom } from './navigateTo';
5
+ export type { NavigateToRoomOptions } from './navigateTo';
6
+ export { compareOriginServerTS } from './originServerTs';
7
+ export { STATE_EVENT_POWER_LEVELS, calculateUserPowerLevel, hasActionPower, hasRoomEventPower, hasStateEventPower, isValidPowerLevelStateEvent, } from './powerLevel';
8
+ export type { PowerLevelsActions, PowerLevelsStateEvent } from './powerLevel';
9
+ export { ROOM_EVENT_REDACTION, isValidRedactionEvent, observeRedactionEvents, redactEvent, } from './redactions';
10
+ export type { Redaction, RedactionRoomEvent } from './redactions';
11
+ export { getContent, getOriginalEventId, isValidEventWithRelatesTo, } from './relatesTo';
12
+ export type { EventWithRelatesTo, NewContentRelatesTo, RelatesTo, RoomEventOrNewContent, } from './relatesTo';
13
+ export { STATE_EVENT_ROOM_MEMBER, isValidRoomMemberStateEvent, } from './roomMember';
14
+ export type { MembershipState, RoomMemberStateEventContent, } from './roomMember';
@@ -0,0 +1,24 @@
1
+ import { WidgetApi } from '../types';
2
+ /**
3
+ * The capability that needs to be requested in order to navigate to another room.
4
+ */
5
+ export declare const WIDGET_CAPABILITY_NAVIGATE = "org.matrix.msc2931.navigate";
6
+ /**
7
+ * Options for the {@link navigateToRoom} function.
8
+ */
9
+ export type NavigateToRoomOptions = {
10
+ /**
11
+ * Optional, array of one or more homeserver domains to discover the room.
12
+ */
13
+ via?: string[];
14
+ };
15
+ /**
16
+ * Navigate the client to another matrix room.
17
+ *
18
+ * @remarks This requires the {@link WIDGET_CAPABILITY_NAVIGATE} capability.
19
+ *
20
+ * @param widgetApi - the {@link WidgetApi} instance.
21
+ * @param roomId - the room ID.
22
+ * @param opts - {@link NavigateToRoomOptions}
23
+ */
24
+ export declare function navigateToRoom(widgetApi: WidgetApi, roomId: string, opts?: NavigateToRoomOptions): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { RoomEvent } from '../types';
2
+ /**
3
+ * Compares two room events by their origin server timestamp.
4
+ *
5
+ * @param a - A room event
6
+ * @param b - A room event
7
+ * @returns Either zero if the timestamp is equal, \>0 if a is newer, or \<0 if
8
+ * b is newer.
9
+ */
10
+ export declare function compareOriginServerTS<T>(a: RoomEvent<T>, b: RoomEvent<T>): number;
@@ -0,0 +1 @@
1
+ export {};