@matrix-widget-toolkit/api 1.0.2 → 3.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.
@@ -606,8 +606,8 @@ function isValidEventWithRelatesTo(event) {
606
606
  * The name of the room member state event.
607
607
  */
608
608
  var STATE_EVENT_ROOM_MEMBER = 'm.room.member';
609
- function isStringOrUndefined(value) {
610
- return value === undefined || typeof value === 'string';
609
+ function isStringUndefinedOrNull(value) {
610
+ return value === undefined || value === null || typeof value === 'string';
611
611
  }
612
612
  /**
613
613
  * Validates that `event` is has a valid structure for a
@@ -624,10 +624,12 @@ function isValidRoomMemberStateEvent(event) {
624
624
  if (typeof content.membership !== 'string') {
625
625
  return false;
626
626
  }
627
- if (!isStringOrUndefined(content.displayname)) {
627
+ if (!isStringUndefinedOrNull(content.displayname)) {
628
628
  return false;
629
629
  }
630
- if (!isStringOrUndefined(content.avatar_url)) {
630
+ // the avatar_url shouldn't be null, but some implementations
631
+ // set it as a valid value
632
+ if (!isStringUndefinedOrNull(content.avatar_url)) {
631
633
  return false;
632
634
  }
633
635
  return true;
@@ -1441,14 +1443,13 @@ var WidgetApiImpl = /** @class */ (function () {
1441
1443
  /** {@inheritDoc WidgetApi.readEventRelations} */
1442
1444
  WidgetApiImpl.prototype.readEventRelations = function (eventId, options) {
1443
1445
  return __awaiter(this, void 0, void 0, function () {
1444
- var _a, original_event, chunk, next_batch;
1446
+ var _a, chunk, next_batch;
1445
1447
  return __generator(this, function (_b) {
1446
1448
  switch (_b.label) {
1447
- case 0: return [4 /*yield*/, this.matrixWidgetApi.readEventRelations(eventId, options === null || options === void 0 ? void 0 : options.roomId, options === null || options === void 0 ? void 0 : options.relationType, options === null || options === void 0 ? void 0 : options.eventType, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.from)];
1449
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.readEventRelations(eventId, options === null || options === void 0 ? void 0 : options.roomId, options === null || options === void 0 ? void 0 : options.relationType, options === null || options === void 0 ? void 0 : options.eventType, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.from, undefined, options === null || options === void 0 ? void 0 : options.direction)];
1448
1450
  case 1:
1449
- _a = _b.sent(), original_event = _a.original_event, chunk = _a.chunk, next_batch = _a.next_batch;
1451
+ _a = _b.sent(), chunk = _a.chunk, next_batch = _a.next_batch;
1450
1452
  return [2 /*return*/, {
1451
- originalEvent: original_event,
1452
1453
  chunk: chunk,
1453
1454
  nextToken: next_batch !== null && next_batch !== void 0 ? next_batch : undefined,
1454
1455
  }];
@@ -604,8 +604,8 @@ function isValidEventWithRelatesTo(event) {
604
604
  * The name of the room member state event.
605
605
  */
606
606
  var STATE_EVENT_ROOM_MEMBER = 'm.room.member';
607
- function isStringOrUndefined(value) {
608
- return value === undefined || typeof value === 'string';
607
+ function isStringUndefinedOrNull(value) {
608
+ return value === undefined || value === null || typeof value === 'string';
609
609
  }
610
610
  /**
611
611
  * Validates that `event` is has a valid structure for a
@@ -622,10 +622,12 @@ function isValidRoomMemberStateEvent(event) {
622
622
  if (typeof content.membership !== 'string') {
623
623
  return false;
624
624
  }
625
- if (!isStringOrUndefined(content.displayname)) {
625
+ if (!isStringUndefinedOrNull(content.displayname)) {
626
626
  return false;
627
627
  }
628
- if (!isStringOrUndefined(content.avatar_url)) {
628
+ // the avatar_url shouldn't be null, but some implementations
629
+ // set it as a valid value
630
+ if (!isStringUndefinedOrNull(content.avatar_url)) {
629
631
  return false;
630
632
  }
631
633
  return true;
@@ -1439,14 +1441,13 @@ var WidgetApiImpl = /** @class */ (function () {
1439
1441
  /** {@inheritDoc WidgetApi.readEventRelations} */
1440
1442
  WidgetApiImpl.prototype.readEventRelations = function (eventId, options) {
1441
1443
  return __awaiter(this, void 0, void 0, function () {
1442
- var _a, original_event, chunk, next_batch;
1444
+ var _a, chunk, next_batch;
1443
1445
  return __generator(this, function (_b) {
1444
1446
  switch (_b.label) {
1445
- case 0: return [4 /*yield*/, this.matrixWidgetApi.readEventRelations(eventId, options === null || options === void 0 ? void 0 : options.roomId, options === null || options === void 0 ? void 0 : options.relationType, options === null || options === void 0 ? void 0 : options.eventType, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.from)];
1447
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.readEventRelations(eventId, options === null || options === void 0 ? void 0 : options.roomId, options === null || options === void 0 ? void 0 : options.relationType, options === null || options === void 0 ? void 0 : options.eventType, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.from, undefined, options === null || options === void 0 ? void 0 : options.direction)];
1446
1448
  case 1:
1447
- _a = _b.sent(), original_event = _a.original_event, chunk = _a.chunk, next_batch = _a.next_batch;
1449
+ _a = _b.sent(), chunk = _a.chunk, next_batch = _a.next_batch;
1448
1450
  return [2 /*return*/, {
1449
- originalEvent: original_event,
1450
1451
  chunk: chunk,
1451
1452
  nextToken: next_batch !== null && next_batch !== void 0 ? next_batch : undefined,
1452
1453
  }];
package/build/index.d.ts CHANGED
@@ -370,11 +370,11 @@ export declare type RoomMemberStateEventContent = {
370
370
  /**
371
371
  * The display name for this user, if any.
372
372
  */
373
- displayname?: string;
373
+ displayname?: string | null;
374
374
  /**
375
375
  * The avatar URL for this user, if any.
376
376
  */
377
- avatar_url?: string;
377
+ avatar_url?: string | null;
378
378
  };
379
379
 
380
380
  /**
@@ -571,15 +571,14 @@ export declare type WidgetApi = {
571
571
  roomId?: string;
572
572
  }): Promise<RoomEvent<T>>;
573
573
  /**
574
- * Receive an event with a given `eventId` and all events that relate to it by
575
- * means of MSC2674. Both `originalEvent` and `chunk` can include state events
576
- * or room events.
574
+ * Receive all events that relate to a given `eventId` by means of MSC2674.
575
+ * `chunk` can include state events or room events.
577
576
  *
578
577
  * @remarks You can only receive events where the capability to receive it was
579
- * approved. If `originalEvent` is not approved, an exception is thrown.
580
- * If an event in `chunk` is not approve, it is silently skipped. Note
581
- * that the call might return less than `limit` events due to various
582
- * reasons, including missing capabilities or encrypted events.
578
+ * approved. If an event in `chunk` is not approved, it is silently
579
+ * skipped. Note that the call might return less than `limit` events
580
+ * due to various reasons, including missing capabilities or encrypted
581
+ * events.
583
582
  *
584
583
  * @param eventId - The id of the event to receive
585
584
  * @param options - Options for receiving the related events.
@@ -590,6 +589,8 @@ export declare type WidgetApi = {
590
589
  * no further page exists.
591
590
  * Use `relationType` to only return events with that `rel_type`.
592
591
  * Use `eventType` to only return events with that `type`.
592
+ * Use `direction` to change time-order of the chunks
593
+ * (default: 'b').
593
594
  *
594
595
  * @throws if the capability to receive the type of event is missing.
595
596
  */
@@ -599,8 +600,8 @@ export declare type WidgetApi = {
599
600
  from?: string;
600
601
  relationType?: string;
601
602
  eventType?: string;
603
+ direction?: 'f' | 'b';
602
604
  }): Promise<{
603
- originalEvent?: RoomEvent | StateEvent;
604
605
  chunk: Array<RoomEvent | StateEvent>;
605
606
  nextToken?: string;
606
607
  }>;
@@ -791,8 +792,8 @@ export declare class WidgetApiImpl implements WidgetApi {
791
792
  from?: string;
792
793
  relationType?: string;
793
794
  eventType?: string;
795
+ direction?: 'f' | 'b';
794
796
  }): Promise<{
795
- originalEvent?: RoomEvent | StateEvent;
796
797
  chunk: Array<RoomEvent | StateEvent>;
797
798
  nextToken?: string;
798
799
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matrix-widget-toolkit/api",
3
- "version": "1.0.2",
3
+ "version": "3.0.0",
4
4
  "description": "A simplified layer on top of matrix-widget-api to use build widgets.",
5
5
  "author": "Nordeck IT + Consulting GmbH",
6
6
  "license": "Apache-2.0",
@@ -10,7 +10,7 @@
10
10
  "devDependencies": {
11
11
  "@craco/craco": "^6.4.5",
12
12
  "@types/jest": "^27.5.2",
13
- "@types/node": "^16.18.4",
13
+ "@types/node": "^16.18.11",
14
14
  "@types/qs": "^6.9.7",
15
15
  "typescript": "^4.8.4"
16
16
  },
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "matrix-widget-api": "^1.1.1",
31
31
  "qs": "^6.11.0",
32
- "rxjs": "^7.5.7"
32
+ "rxjs": "^7.8.0"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",