@matrix-widget-toolkit/api 4.0.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/api/extras/events.d.cts +26 -1
- package/build/cjs/api/extras/index.d.cts +1 -1
- package/build/cjs/api/index.d.cts +2 -1
- package/build/cjs/api/registration.d.cts +2 -2
- package/build/cjs/api/types.d.cts +24 -0
- package/build/cjs/index.cjs +136 -13
- package/build/esm/api/extras/events.d.ts +26 -1
- package/build/esm/api/extras/index.d.ts +1 -1
- package/build/esm/api/index.d.ts +2 -1
- package/build/esm/api/registration.d.ts +2 -2
- package/build/esm/api/types.d.ts +24 -0
- package/build/esm/index.js +130 -14
- package/build/index.d.ts +57 -8
- package/package.json +16 -12
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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,
|
|
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
|
|
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
|
|
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
|
*
|
package/build/cjs/index.cjs
CHANGED
|
@@ -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
|
|
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
|
|
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,
|
|
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
|
|
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',
|
|
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
|
*
|
|
@@ -1127,6 +1227,16 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1127
1227
|
this.matrixWidgetApi = matrixWidgetApi$1;
|
|
1128
1228
|
this.widgetId = widgetId;
|
|
1129
1229
|
this.widgetParameters = widgetParameters;
|
|
1230
|
+
// Disable the update_state API that is not implemented.
|
|
1231
|
+
this.matrixWidgetApi.on("action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.SupportedApiVersions), function (event) {
|
|
1232
|
+
event.preventDefault();
|
|
1233
|
+
var supportedVersions = matrixWidgetApi.CurrentApiVersions.filter(function (apiVersion) {
|
|
1234
|
+
return apiVersion !== matrixWidgetApi.UnstableApiVersion.MSC2762_UPDATE_STATE;
|
|
1235
|
+
});
|
|
1236
|
+
matrixWidgetApi$1.transport.reply(event.detail, {
|
|
1237
|
+
supported_versions: supportedVersions,
|
|
1238
|
+
});
|
|
1239
|
+
});
|
|
1130
1240
|
this.events$ = rxjs.fromEvent(this.matrixWidgetApi, "action:".concat(matrixWidgetApi.WidgetApiToWidgetAction.SendEvent), function (event) {
|
|
1131
1241
|
event.preventDefault();
|
|
1132
1242
|
try {
|
|
@@ -1146,7 +1256,9 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1146
1256
|
// Ignore errors while replying
|
|
1147
1257
|
}
|
|
1148
1258
|
return event;
|
|
1149
|
-
})
|
|
1259
|
+
})
|
|
1260
|
+
.pipe(rxjs.filter(function (event) { return isValidToDeviceMessageEvent(event.detail.data); }))
|
|
1261
|
+
.pipe(rxjs.share());
|
|
1150
1262
|
this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [matrixWidgetApi.MatrixCapabilities.RequiresClient]), true);
|
|
1151
1263
|
}
|
|
1152
1264
|
/**
|
|
@@ -1381,11 +1493,15 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1381
1493
|
/** {@inheritDoc WidgetApi.receiveStateEvents} */
|
|
1382
1494
|
WidgetApiImpl.prototype.receiveStateEvents = function (eventType_1) {
|
|
1383
1495
|
return __awaiter(this, arguments, void 0, function (eventType, _a) {
|
|
1496
|
+
var unvalidatedEvents, validatedEvents;
|
|
1384
1497
|
var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
|
|
1385
1498
|
return __generator(this, function (_c) {
|
|
1386
1499
|
switch (_c.label) {
|
|
1387
1500
|
case 0: return [4 /*yield*/, this.matrixWidgetApi.readStateEvents(eventType, Number.MAX_SAFE_INTEGER, stateKey, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
|
|
1388
|
-
case 1:
|
|
1501
|
+
case 1:
|
|
1502
|
+
unvalidatedEvents = (_c.sent());
|
|
1503
|
+
validatedEvents = unvalidatedEvents.filter(isValidStateEvent);
|
|
1504
|
+
return [2 /*return*/, validatedEvents];
|
|
1389
1505
|
}
|
|
1390
1506
|
});
|
|
1391
1507
|
});
|
|
@@ -1408,7 +1524,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1408
1524
|
}
|
|
1409
1525
|
return undefined;
|
|
1410
1526
|
}), rxjs.filter(isDefined));
|
|
1411
|
-
return rxjs.concat(historyEvent$, futureEvent$);
|
|
1527
|
+
return rxjs.concat(historyEvent$, futureEvent$).pipe(rxjs.filter(isValidStateEvent));
|
|
1412
1528
|
};
|
|
1413
1529
|
/** {@inheritDoc WidgetApi.sendStateEvent} */
|
|
1414
1530
|
WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
|
|
@@ -1418,11 +1534,15 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1418
1534
|
/** {@inheritDoc WidgetApi.receiveRoomEvents} */
|
|
1419
1535
|
WidgetApiImpl.prototype.receiveRoomEvents = function (eventType_1) {
|
|
1420
1536
|
return __awaiter(this, arguments, void 0, function (eventType, _a) {
|
|
1537
|
+
var unvalidatedEvents, validatedEvents;
|
|
1421
1538
|
var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
|
|
1422
1539
|
return __generator(this, function (_c) {
|
|
1423
1540
|
switch (_c.label) {
|
|
1424
1541
|
case 0: return [4 /*yield*/, this.matrixWidgetApi.readRoomEvents(eventType, Number.MAX_SAFE_INTEGER, messageType, typeof roomIds === 'string' ? [matrixWidgetApi.Symbols.AnyRoom] : roomIds)];
|
|
1425
|
-
case 1:
|
|
1542
|
+
case 1:
|
|
1543
|
+
unvalidatedEvents = (_c.sent());
|
|
1544
|
+
validatedEvents = unvalidatedEvents.filter(isValidRoomEvent);
|
|
1545
|
+
return [2 /*return*/, validatedEvents];
|
|
1426
1546
|
}
|
|
1427
1547
|
});
|
|
1428
1548
|
});
|
|
@@ -1445,7 +1565,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1445
1565
|
}
|
|
1446
1566
|
return undefined;
|
|
1447
1567
|
}), rxjs.filter(isDefined));
|
|
1448
|
-
return rxjs.concat(historyEvent$, futureEvent$);
|
|
1568
|
+
return rxjs.concat(historyEvent$, futureEvent$).pipe(rxjs.filter(isValidRoomEvent));
|
|
1449
1569
|
};
|
|
1450
1570
|
/** {@inheritDoc WidgetApi.sendRoomEvent} */
|
|
1451
1571
|
WidgetApiImpl.prototype.sendRoomEvent = function (eventType_1, content_1) {
|
|
@@ -1511,7 +1631,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1511
1631
|
};
|
|
1512
1632
|
/** {@inheritDoc WidgetApi.observeToDeviceMessages} */
|
|
1513
1633
|
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; }));
|
|
1634
|
+
return this.toDeviceMessages$.pipe(rxjs.map(function (e) { return e.detail.data; }), rxjs.filter(isValidToDeviceMessageEvent), rxjs.filter(function (e) { return e.type === eventType; }));
|
|
1515
1635
|
};
|
|
1516
1636
|
/** {@inheritDoc WidgetApi.openModal} */
|
|
1517
1637
|
WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
|
|
@@ -1762,15 +1882,18 @@ exports.getContent = getContent;
|
|
|
1762
1882
|
exports.getOriginalEventId = getOriginalEventId;
|
|
1763
1883
|
exports.getRoomMemberDisplayName = getRoomMemberDisplayName;
|
|
1764
1884
|
exports.hasActionPower = hasActionPower;
|
|
1765
|
-
exports.hasRequiredWidgetParameters = hasRequiredWidgetParameters;
|
|
1766
1885
|
exports.hasRoomEventPower = hasRoomEventPower;
|
|
1767
1886
|
exports.hasStateEventPower = hasStateEventPower;
|
|
1887
|
+
exports.hasWidgetParameters = hasWidgetParameters;
|
|
1768
1888
|
exports.isRoomEvent = isRoomEvent;
|
|
1769
1889
|
exports.isStateEvent = isStateEvent;
|
|
1770
1890
|
exports.isValidEventWithRelatesTo = isValidEventWithRelatesTo;
|
|
1771
1891
|
exports.isValidPowerLevelStateEvent = isValidPowerLevelStateEvent;
|
|
1772
1892
|
exports.isValidRedactionEvent = isValidRedactionEvent;
|
|
1893
|
+
exports.isValidRoomEvent = isValidRoomEvent;
|
|
1773
1894
|
exports.isValidRoomMemberStateEvent = isValidRoomMemberStateEvent;
|
|
1895
|
+
exports.isValidStateEVent = isValidStateEvent;
|
|
1896
|
+
exports.isValidToDeviceMessageEvent = isValidToDeviceMessageEvent;
|
|
1774
1897
|
exports.makeEventFromSendStateEventResult = makeEventFromSendStateEventResult;
|
|
1775
1898
|
exports.navigateToRoom = navigateToRoom;
|
|
1776
1899
|
exports.observeRedactionEvents = observeRedactionEvents;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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';
|
package/build/esm/api/index.d.ts
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
|
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).
|
package/build/esm/api/types.d.ts
CHANGED
|
@@ -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
|
*
|
package/build/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Symbols, WidgetEventCapability, EventDirection, WidgetApi, WidgetApiToWidgetAction, MatrixCapabilities } from 'matrix-widget-api';
|
|
1
|
+
import { Symbols, WidgetEventCapability, EventDirection, WidgetApi, WidgetApiToWidgetAction, CurrentApiVersions, UnstableApiVersion, 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
|
|
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
|
|
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,
|
|
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
|
|
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',
|
|
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
|
*
|
|
@@ -1125,6 +1221,16 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1125
1221
|
this.matrixWidgetApi = matrixWidgetApi;
|
|
1126
1222
|
this.widgetId = widgetId;
|
|
1127
1223
|
this.widgetParameters = widgetParameters;
|
|
1224
|
+
// Disable the update_state API that is not implemented.
|
|
1225
|
+
this.matrixWidgetApi.on("action:".concat(WidgetApiToWidgetAction.SupportedApiVersions), function (event) {
|
|
1226
|
+
event.preventDefault();
|
|
1227
|
+
var supportedVersions = CurrentApiVersions.filter(function (apiVersion) {
|
|
1228
|
+
return apiVersion !== UnstableApiVersion.MSC2762_UPDATE_STATE;
|
|
1229
|
+
});
|
|
1230
|
+
matrixWidgetApi.transport.reply(event.detail, {
|
|
1231
|
+
supported_versions: supportedVersions,
|
|
1232
|
+
});
|
|
1233
|
+
});
|
|
1128
1234
|
this.events$ = fromEvent(this.matrixWidgetApi, "action:".concat(WidgetApiToWidgetAction.SendEvent), function (event) {
|
|
1129
1235
|
event.preventDefault();
|
|
1130
1236
|
try {
|
|
@@ -1144,7 +1250,9 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1144
1250
|
// Ignore errors while replying
|
|
1145
1251
|
}
|
|
1146
1252
|
return event;
|
|
1147
|
-
})
|
|
1253
|
+
})
|
|
1254
|
+
.pipe(filter(function (event) { return isValidToDeviceMessageEvent(event.detail.data); }))
|
|
1255
|
+
.pipe(share());
|
|
1148
1256
|
this.initialCapabilities = __spreadArray(__spreadArray([], capabilities, true), (supportStandalone ? [] : [MatrixCapabilities.RequiresClient]), true);
|
|
1149
1257
|
}
|
|
1150
1258
|
/**
|
|
@@ -1379,11 +1487,15 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1379
1487
|
/** {@inheritDoc WidgetApi.receiveStateEvents} */
|
|
1380
1488
|
WidgetApiImpl.prototype.receiveStateEvents = function (eventType_1) {
|
|
1381
1489
|
return __awaiter(this, arguments, void 0, function (eventType, _a) {
|
|
1490
|
+
var unvalidatedEvents, validatedEvents;
|
|
1382
1491
|
var _b = _a === void 0 ? {} : _a, stateKey = _b.stateKey, roomIds = _b.roomIds;
|
|
1383
1492
|
return __generator(this, function (_c) {
|
|
1384
1493
|
switch (_c.label) {
|
|
1385
1494
|
case 0: return [4 /*yield*/, this.matrixWidgetApi.readStateEvents(eventType, Number.MAX_SAFE_INTEGER, stateKey, typeof roomIds === 'string' ? [Symbols.AnyRoom] : roomIds)];
|
|
1386
|
-
case 1:
|
|
1495
|
+
case 1:
|
|
1496
|
+
unvalidatedEvents = (_c.sent());
|
|
1497
|
+
validatedEvents = unvalidatedEvents.filter(isValidStateEvent);
|
|
1498
|
+
return [2 /*return*/, validatedEvents];
|
|
1387
1499
|
}
|
|
1388
1500
|
});
|
|
1389
1501
|
});
|
|
@@ -1406,7 +1518,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1406
1518
|
}
|
|
1407
1519
|
return undefined;
|
|
1408
1520
|
}), filter(isDefined));
|
|
1409
|
-
return concat(historyEvent$, futureEvent$);
|
|
1521
|
+
return concat(historyEvent$, futureEvent$).pipe(filter(isValidStateEvent));
|
|
1410
1522
|
};
|
|
1411
1523
|
/** {@inheritDoc WidgetApi.sendStateEvent} */
|
|
1412
1524
|
WidgetApiImpl.prototype.sendStateEvent = function (eventType, content, _a) {
|
|
@@ -1416,11 +1528,15 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1416
1528
|
/** {@inheritDoc WidgetApi.receiveRoomEvents} */
|
|
1417
1529
|
WidgetApiImpl.prototype.receiveRoomEvents = function (eventType_1) {
|
|
1418
1530
|
return __awaiter(this, arguments, void 0, function (eventType, _a) {
|
|
1531
|
+
var unvalidatedEvents, validatedEvents;
|
|
1419
1532
|
var _b = _a === void 0 ? {} : _a, messageType = _b.messageType, roomIds = _b.roomIds;
|
|
1420
1533
|
return __generator(this, function (_c) {
|
|
1421
1534
|
switch (_c.label) {
|
|
1422
1535
|
case 0: return [4 /*yield*/, this.matrixWidgetApi.readRoomEvents(eventType, Number.MAX_SAFE_INTEGER, messageType, typeof roomIds === 'string' ? [Symbols.AnyRoom] : roomIds)];
|
|
1423
|
-
case 1:
|
|
1536
|
+
case 1:
|
|
1537
|
+
unvalidatedEvents = (_c.sent());
|
|
1538
|
+
validatedEvents = unvalidatedEvents.filter(isValidRoomEvent);
|
|
1539
|
+
return [2 /*return*/, validatedEvents];
|
|
1424
1540
|
}
|
|
1425
1541
|
});
|
|
1426
1542
|
});
|
|
@@ -1443,7 +1559,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1443
1559
|
}
|
|
1444
1560
|
return undefined;
|
|
1445
1561
|
}), filter(isDefined));
|
|
1446
|
-
return concat(historyEvent$, futureEvent$);
|
|
1562
|
+
return concat(historyEvent$, futureEvent$).pipe(filter(isValidRoomEvent));
|
|
1447
1563
|
};
|
|
1448
1564
|
/** {@inheritDoc WidgetApi.sendRoomEvent} */
|
|
1449
1565
|
WidgetApiImpl.prototype.sendRoomEvent = function (eventType_1, content_1) {
|
|
@@ -1509,7 +1625,7 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1509
1625
|
};
|
|
1510
1626
|
/** {@inheritDoc WidgetApi.observeToDeviceMessages} */
|
|
1511
1627
|
WidgetApiImpl.prototype.observeToDeviceMessages = function (eventType) {
|
|
1512
|
-
return this.toDeviceMessages$.pipe(map(function (e) { return e.detail.data; }), filter(function (e) { return e.type === eventType; }));
|
|
1628
|
+
return this.toDeviceMessages$.pipe(map(function (e) { return e.detail.data; }), filter(isValidToDeviceMessageEvent), filter(function (e) { return e.type === eventType; }));
|
|
1513
1629
|
};
|
|
1514
1630
|
/** {@inheritDoc WidgetApi.openModal} */
|
|
1515
1631
|
WidgetApiImpl.prototype.openModal = function (pathName, name, options) {
|
|
@@ -1744,4 +1860,4 @@ var WidgetApiImpl = /** @class */ (function () {
|
|
|
1744
1860
|
return WidgetApiImpl;
|
|
1745
1861
|
}());
|
|
1746
1862
|
|
|
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,
|
|
1863
|
+
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.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "A simplified layer on top of matrix-widget-api to use build widgets.",
|
|
5
5
|
"author": "Nordeck IT + Consulting GmbH",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@rollup/plugin-commonjs": "28.0.
|
|
26
|
-
"@types/node": "22.
|
|
27
|
-
"@types/qs": "6.9.
|
|
28
|
-
"@vitest/coverage-v8": "
|
|
29
|
-
"typescript": "5.7.
|
|
30
|
-
"vite": "
|
|
31
|
-
"vitest": "
|
|
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
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
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",
|