@matrix-widget-toolkit/api 3.2.2 → 3.3.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.
@@ -81,6 +81,7 @@ function extractWidgetParameters() {
81
81
  theme: params['theme'],
82
82
  clientId: params['matrix_client_id'],
83
83
  clientLanguage: params['matrix_client_language'],
84
+ baseUrl: params['matrix_base_url'],
84
85
  isOpenedByClient: isOpenedByClient,
85
86
  };
86
87
  }
@@ -193,7 +194,8 @@ function hasRequiredWidgetParameters(widgetApi) {
193
194
  typeof widgetApi.widgetParameters.roomId === 'string' &&
194
195
  typeof widgetApi.widgetParameters.theme === 'string' &&
195
196
  typeof widgetApi.widgetParameters.clientId === 'string' &&
196
- typeof widgetApi.widgetParameters.clientLanguage === 'string');
197
+ typeof widgetApi.widgetParameters.clientLanguage === 'string' &&
198
+ typeof widgetApi.widgetParameters.baseUrl === 'string');
197
199
  }
198
200
  /**
199
201
  * Generate a registration URL for the widget based on the current URL and
@@ -205,12 +207,12 @@ function hasRequiredWidgetParameters(widgetApi) {
205
207
  * @returns The generated URL.
206
208
  */
207
209
  function generateWidgetRegistrationUrl(options) {
208
- var _a, _b, _c, _d, _e, _f, _g;
210
+ var _a, _b, _c, _d, _e, _f, _g, _h;
209
211
  if (options === void 0) { options = {}; }
210
- var pathName = options.pathName, _h = options.includeParameters, includeParameters = _h === void 0 ? true : _h, widgetParameters = options.widgetParameters;
212
+ var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
211
213
  // don't forward widgetId and parentUrl as they will be generated by the client
212
- var _j = extractRawWidgetParameters(); _j.widgetId; _j.parentUrl; var rawWidgetParameters = __rest(_j, ["widgetId", "parentUrl"]);
213
- 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' }))
214
+ var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
215
+ var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
214
216
  .map(function (_a) {
215
217
  var k = _a[0], v = _a[1];
216
218
  return "".concat(k, "=").concat(v);
@@ -1024,6 +1026,28 @@ var WidgetApiImpl = /** @class */ (function () {
1024
1026
  });
1025
1027
  });
1026
1028
  };
1029
+ /** {@inheritdoc WidgetApi.getMediaConfig} */
1030
+ WidgetApiImpl.prototype.getMediaConfig = function () {
1031
+ return __awaiter$2(this, void 0, void 0, function () {
1032
+ return __generator$2(this, function (_a) {
1033
+ switch (_a.label) {
1034
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.getMediaConfig()];
1035
+ case 1: return [2 /*return*/, _a.sent()];
1036
+ }
1037
+ });
1038
+ });
1039
+ };
1040
+ /** {@inheritdoc WidgetApi.uploadFile} */
1041
+ WidgetApiImpl.prototype.uploadFile = function (file) {
1042
+ return __awaiter$2(this, void 0, void 0, function () {
1043
+ return __generator$2(this, function (_a) {
1044
+ switch (_a.label) {
1045
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.uploadFile(file)];
1046
+ case 1: return [2 /*return*/, _a.sent()];
1047
+ }
1048
+ });
1049
+ });
1050
+ };
1027
1051
  return WidgetApiImpl;
1028
1052
  }());
1029
1053
 
@@ -79,6 +79,7 @@ function extractWidgetParameters() {
79
79
  theme: params['theme'],
80
80
  clientId: params['matrix_client_id'],
81
81
  clientLanguage: params['matrix_client_language'],
82
+ baseUrl: params['matrix_base_url'],
82
83
  isOpenedByClient: isOpenedByClient,
83
84
  };
84
85
  }
@@ -191,7 +192,8 @@ function hasRequiredWidgetParameters(widgetApi) {
191
192
  typeof widgetApi.widgetParameters.roomId === 'string' &&
192
193
  typeof widgetApi.widgetParameters.theme === 'string' &&
193
194
  typeof widgetApi.widgetParameters.clientId === 'string' &&
194
- typeof widgetApi.widgetParameters.clientLanguage === 'string');
195
+ typeof widgetApi.widgetParameters.clientLanguage === 'string' &&
196
+ typeof widgetApi.widgetParameters.baseUrl === 'string');
195
197
  }
196
198
  /**
197
199
  * Generate a registration URL for the widget based on the current URL and
@@ -203,12 +205,12 @@ function hasRequiredWidgetParameters(widgetApi) {
203
205
  * @returns The generated URL.
204
206
  */
205
207
  function generateWidgetRegistrationUrl(options) {
206
- var _a, _b, _c, _d, _e, _f, _g;
208
+ var _a, _b, _c, _d, _e, _f, _g, _h;
207
209
  if (options === void 0) { options = {}; }
208
- var pathName = options.pathName, _h = options.includeParameters, includeParameters = _h === void 0 ? true : _h, widgetParameters = options.widgetParameters;
210
+ var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
209
211
  // don't forward widgetId and parentUrl as they will be generated by the client
210
- var _j = extractRawWidgetParameters(); _j.widgetId; _j.parentUrl; var rawWidgetParameters = __rest(_j, ["widgetId", "parentUrl"]);
211
- 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' }))
212
+ var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
213
+ var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
212
214
  .map(function (_a) {
213
215
  var k = _a[0], v = _a[1];
214
216
  return "".concat(k, "=").concat(v);
@@ -1022,6 +1024,28 @@ var WidgetApiImpl = /** @class */ (function () {
1022
1024
  });
1023
1025
  });
1024
1026
  };
1027
+ /** {@inheritdoc WidgetApi.getMediaConfig} */
1028
+ WidgetApiImpl.prototype.getMediaConfig = function () {
1029
+ return __awaiter$2(this, void 0, void 0, function () {
1030
+ return __generator$2(this, function (_a) {
1031
+ switch (_a.label) {
1032
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.getMediaConfig()];
1033
+ case 1: return [2 /*return*/, _a.sent()];
1034
+ }
1035
+ });
1036
+ });
1037
+ };
1038
+ /** {@inheritdoc WidgetApi.uploadFile} */
1039
+ WidgetApiImpl.prototype.uploadFile = function (file) {
1040
+ return __awaiter$2(this, void 0, void 0, function () {
1041
+ return __generator$2(this, function (_a) {
1042
+ switch (_a.label) {
1043
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.uploadFile(file)];
1044
+ case 1: return [2 /*return*/, _a.sent()];
1045
+ }
1046
+ });
1047
+ });
1048
+ };
1025
1049
  return WidgetApiImpl;
1026
1050
  }());
1027
1051
 
package/build/index.d.ts CHANGED
@@ -4,11 +4,13 @@
4
4
  */
5
5
 
6
6
  import { Capability } from 'matrix-widget-api';
7
+ import { IGetMediaConfigActionFromWidgetResponseData } from 'matrix-widget-api';
7
8
  import { IModalWidgetCreateData } from 'matrix-widget-api';
8
9
  import { IModalWidgetOpenRequestDataButton } from 'matrix-widget-api';
9
10
  import { IModalWidgetReturnData } from 'matrix-widget-api';
10
11
  import { IOpenIDCredentials } from 'matrix-widget-api';
11
12
  import { IRoomEvent } from 'matrix-widget-api';
13
+ import { IUploadFileActionFromWidgetResponseData } from 'matrix-widget-api';
12
14
  import { IWidget } from 'matrix-widget-api';
13
15
  import { IWidgetApiRequest } from 'matrix-widget-api';
14
16
  import { IWidgetApiRequestData } from 'matrix-widget-api';
@@ -744,6 +746,18 @@ export declare type WidgetApi = {
744
746
  avatarUrl?: string;
745
747
  }>;
746
748
  }>;
749
+ /**
750
+ * Get the config for the media repository.
751
+ * @returns Promise which resolves with an object containing the config.
752
+ */
753
+ getMediaConfig(): Promise<IGetMediaConfigActionFromWidgetResponseData>;
754
+ /**
755
+ * Upload a file to the media repository on the homeserver.
756
+ * @param file - The object to upload. Something that can be sent to
757
+ * XMLHttpRequest.send (typically a File).
758
+ * @returns Resolves to the location of the uploaded file.
759
+ */
760
+ uploadFile(file: XMLHttpRequestBodyInit): Promise<IUploadFileActionFromWidgetResponseData>;
747
761
  };
748
762
 
749
763
  /**
@@ -900,6 +914,10 @@ export declare class WidgetApiImpl implements WidgetApi {
900
914
  avatarUrl?: string;
901
915
  }>;
902
916
  }>;
917
+ /** {@inheritdoc WidgetApi.getMediaConfig} */
918
+ getMediaConfig(): Promise<IGetMediaConfigActionFromWidgetResponseData>;
919
+ /** {@inheritdoc WidgetApi.uploadFile} */
920
+ uploadFile(file: XMLHttpRequestBodyInit): Promise<IUploadFileActionFromWidgetResponseData>;
903
921
  }
904
922
 
905
923
  /**
@@ -1001,6 +1019,10 @@ export declare type WidgetParameters = {
1001
1019
  * The current selected language in the client.
1002
1020
  */
1003
1021
  clientLanguage?: string;
1022
+ /**
1023
+ * The homeserver base URL.
1024
+ */
1025
+ baseUrl?: string;
1004
1026
  /**
1005
1027
  * Whether the widget was opened by a client or not.
1006
1028
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matrix-widget-toolkit/api",
3
- "version": "3.2.2",
3
+ "version": "3.3.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",