@matrix-widget-toolkit/api 3.3.2 → 3.4.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.
@@ -152,8 +152,8 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
152
152
  });
153
153
  };
154
154
  var __generator$3 = (undefined && undefined.__generator) || function (thisArg, body) {
155
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
156
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
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
+ 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]); }; }
158
158
  function step(op) {
159
159
  if (f) throw new TypeError("Generator is already executing.");
@@ -449,8 +449,8 @@ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _argu
449
449
  });
450
450
  };
451
451
  var __generator$2 = (undefined && undefined.__generator) || function (thisArg, body) {
452
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
453
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
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
+ 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]); }; }
455
455
  function step(op) {
456
456
  if (f) throw new TypeError("Generator is already executing.");
@@ -775,8 +775,8 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
775
775
  });
776
776
  };
777
777
  var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
778
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
779
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
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
+ 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]); }; }
781
781
  function step(op) {
782
782
  if (f) throw new TypeError("Generator is already executing.");
@@ -842,6 +842,7 @@ function generateWidgetRegistrationUrl(options) {
842
842
  if (options === void 0) { options = {}; }
843
843
  var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
844
844
  // don't forward widgetId and parentUrl as they will be generated by the client
845
+ // eslint-disable-next-line
845
846
  var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
846
847
  var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
847
848
  .map(function (_a) {
@@ -989,8 +990,8 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
989
990
  });
990
991
  };
991
992
  var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
992
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
993
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
993
+ 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);
994
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
994
995
  function verb(n) { return function (v) { return step([n, v]); }; }
995
996
  function step(op) {
996
997
  if (f) throw new TypeError("Generator is already executing.");
@@ -1054,7 +1055,7 @@ var WidgetApiImpl = /** @class */ (function () {
1054
1055
  try {
1055
1056
  _this.matrixWidgetApi.transport.reply(event.detail, {});
1056
1057
  }
1057
- catch (_) {
1058
+ catch (_a) {
1058
1059
  // Ignore errors while replying
1059
1060
  }
1060
1061
  return event;
@@ -1064,7 +1065,7 @@ var WidgetApiImpl = /** @class */ (function () {
1064
1065
  try {
1065
1066
  matrixWidgetApi$1.transport.reply(event.detail, {});
1066
1067
  }
1067
- catch (_) {
1068
+ catch (_a) {
1068
1069
  // Ignore errors while replying
1069
1070
  }
1070
1071
  return event;
@@ -1244,6 +1245,7 @@ var WidgetApiImpl = /** @class */ (function () {
1244
1245
  throw new Error("Capabilities rejected: ".concat(Array.from(missingSet).join(', ')));
1245
1246
  }
1246
1247
  }), rxjs.first());
1248
+ // eslint-disable-next-line no-async-promise-executor
1247
1249
  return [4 /*yield*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1248
1250
  var subscription, err_1;
1249
1251
  return __generator(this, function (_a) {
@@ -1271,6 +1273,7 @@ var WidgetApiImpl = /** @class */ (function () {
1271
1273
  });
1272
1274
  }); })];
1273
1275
  case 1:
1276
+ // eslint-disable-next-line no-async-promise-executor
1274
1277
  _a.sent();
1275
1278
  return [2 /*return*/];
1276
1279
  }
@@ -1679,6 +1682,17 @@ var WidgetApiImpl = /** @class */ (function () {
1679
1682
  });
1680
1683
  });
1681
1684
  };
1685
+ /** {@inheritdoc WidgetApi.downloadFile} */
1686
+ WidgetApiImpl.prototype.downloadFile = function (contentUrl) {
1687
+ return __awaiter(this, void 0, void 0, function () {
1688
+ return __generator(this, function (_a) {
1689
+ switch (_a.label) {
1690
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.downloadFile(contentUrl)];
1691
+ case 1: return [2 /*return*/, _a.sent()];
1692
+ }
1693
+ });
1694
+ });
1695
+ };
1682
1696
  return WidgetApiImpl;
1683
1697
  }());
1684
1698
 
@@ -150,8 +150,8 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
150
150
  });
151
151
  };
152
152
  var __generator$3 = (undefined && undefined.__generator) || function (thisArg, body) {
153
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
154
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
153
+ 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);
154
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
155
155
  function verb(n) { return function (v) { return step([n, v]); }; }
156
156
  function step(op) {
157
157
  if (f) throw new TypeError("Generator is already executing.");
@@ -447,8 +447,8 @@ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _argu
447
447
  });
448
448
  };
449
449
  var __generator$2 = (undefined && undefined.__generator) || function (thisArg, body) {
450
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
451
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
450
+ 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);
451
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
452
452
  function verb(n) { return function (v) { return step([n, v]); }; }
453
453
  function step(op) {
454
454
  if (f) throw new TypeError("Generator is already executing.");
@@ -773,8 +773,8 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
773
773
  });
774
774
  };
775
775
  var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
776
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
777
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
776
+ 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);
777
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
778
778
  function verb(n) { return function (v) { return step([n, v]); }; }
779
779
  function step(op) {
780
780
  if (f) throw new TypeError("Generator is already executing.");
@@ -840,6 +840,7 @@ function generateWidgetRegistrationUrl(options) {
840
840
  if (options === void 0) { options = {}; }
841
841
  var pathName = options.pathName, _j = options.includeParameters, includeParameters = _j === void 0 ? true : _j, widgetParameters = options.widgetParameters;
842
842
  // don't forward widgetId and parentUrl as they will be generated by the client
843
+ // eslint-disable-next-line
843
844
  var _k = extractRawWidgetParameters(); _k.widgetId; _k.parentUrl; var rawWidgetParameters = __rest(_k, ["widgetId", "parentUrl"]);
844
845
  var parameters = Object.entries(__assign(__assign({}, rawWidgetParameters), { theme: (_a = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.theme) !== null && _a !== void 0 ? _a : '$org.matrix.msc2873.client_theme', matrix_user_id: (_b = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.userId) !== null && _b !== void 0 ? _b : '$matrix_user_id', matrix_display_name: (_c = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.displayName) !== null && _c !== void 0 ? _c : '$matrix_display_name', matrix_avatar_url: (_d = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.avatarUrl) !== null && _d !== void 0 ? _d : '$matrix_avatar_url', matrix_room_id: (_e = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.roomId) !== null && _e !== void 0 ? _e : '$matrix_room_id', matrix_client_id: (_f = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientId) !== null && _f !== void 0 ? _f : '$org.matrix.msc2873.client_id', matrix_client_language: (_g = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.clientLanguage) !== null && _g !== void 0 ? _g : '$org.matrix.msc2873.client_language', matrix_base_url: (_h = widgetParameters === null || widgetParameters === void 0 ? void 0 : widgetParameters.baseUrl) !== null && _h !== void 0 ? _h : '$org.matrix.msc4039.matrix_base_url' }))
845
846
  .map(function (_a) {
@@ -987,8 +988,8 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
987
988
  });
988
989
  };
989
990
  var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
990
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
991
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
991
+ 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);
992
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
992
993
  function verb(n) { return function (v) { return step([n, v]); }; }
993
994
  function step(op) {
994
995
  if (f) throw new TypeError("Generator is already executing.");
@@ -1052,7 +1053,7 @@ var WidgetApiImpl = /** @class */ (function () {
1052
1053
  try {
1053
1054
  _this.matrixWidgetApi.transport.reply(event.detail, {});
1054
1055
  }
1055
- catch (_) {
1056
+ catch (_a) {
1056
1057
  // Ignore errors while replying
1057
1058
  }
1058
1059
  return event;
@@ -1062,7 +1063,7 @@ var WidgetApiImpl = /** @class */ (function () {
1062
1063
  try {
1063
1064
  matrixWidgetApi.transport.reply(event.detail, {});
1064
1065
  }
1065
- catch (_) {
1066
+ catch (_a) {
1066
1067
  // Ignore errors while replying
1067
1068
  }
1068
1069
  return event;
@@ -1242,6 +1243,7 @@ var WidgetApiImpl = /** @class */ (function () {
1242
1243
  throw new Error("Capabilities rejected: ".concat(Array.from(missingSet).join(', ')));
1243
1244
  }
1244
1245
  }), first());
1246
+ // eslint-disable-next-line no-async-promise-executor
1245
1247
  return [4 /*yield*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1246
1248
  var subscription, err_1;
1247
1249
  return __generator(this, function (_a) {
@@ -1269,6 +1271,7 @@ var WidgetApiImpl = /** @class */ (function () {
1269
1271
  });
1270
1272
  }); })];
1271
1273
  case 1:
1274
+ // eslint-disable-next-line no-async-promise-executor
1272
1275
  _a.sent();
1273
1276
  return [2 /*return*/];
1274
1277
  }
@@ -1677,6 +1680,17 @@ var WidgetApiImpl = /** @class */ (function () {
1677
1680
  });
1678
1681
  });
1679
1682
  };
1683
+ /** {@inheritdoc WidgetApi.downloadFile} */
1684
+ WidgetApiImpl.prototype.downloadFile = function (contentUrl) {
1685
+ return __awaiter(this, void 0, void 0, function () {
1686
+ return __generator(this, function (_a) {
1687
+ switch (_a.label) {
1688
+ case 0: return [4 /*yield*/, this.matrixWidgetApi.downloadFile(contentUrl)];
1689
+ case 1: return [2 /*return*/, _a.sent()];
1690
+ }
1691
+ });
1692
+ });
1693
+ };
1680
1694
  return WidgetApiImpl;
1681
1695
  }());
1682
1696
 
package/build/index.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { Capability } from 'matrix-widget-api';
7
+ import { IDownloadFileActionFromWidgetResponseData } from 'matrix-widget-api';
7
8
  import { IGetMediaConfigActionFromWidgetResponseData } from 'matrix-widget-api';
8
9
  import { IModalWidgetCreateData } from 'matrix-widget-api';
9
10
  import { IModalWidgetOpenRequestDataButton } from 'matrix-widget-api';
@@ -758,6 +759,12 @@ export declare type WidgetApi = {
758
759
  * @returns Resolves to the location of the uploaded file.
759
760
  */
760
761
  uploadFile(file: XMLHttpRequestBodyInit): Promise<IUploadFileActionFromWidgetResponseData>;
762
+ /**
763
+ * Download a file to the media repository on the homeserver.
764
+ * @param contentUrl - MXC URI of the file to download
765
+ * @returns resolves to an object with: file - the file contents
766
+ */
767
+ downloadFile(contentUrl: string): Promise<IDownloadFileActionFromWidgetResponseData>;
761
768
  };
762
769
 
763
770
  /**
@@ -918,6 +925,8 @@ export declare class WidgetApiImpl implements WidgetApi {
918
925
  getMediaConfig(): Promise<IGetMediaConfigActionFromWidgetResponseData>;
919
926
  /** {@inheritdoc WidgetApi.uploadFile} */
920
927
  uploadFile(file: XMLHttpRequestBodyInit): Promise<IUploadFileActionFromWidgetResponseData>;
928
+ /** {@inheritdoc WidgetApi.downloadFile} */
929
+ downloadFile(contentUrl: string): Promise<IDownloadFileActionFromWidgetResponseData>;
921
930
  }
922
931
 
923
932
  /**
package/package.json CHANGED
@@ -1,26 +1,31 @@
1
1
  {
2
2
  "name": "@matrix-widget-toolkit/api",
3
- "version": "3.3.2",
3
+ "version": "3.4.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",
7
7
  "source": "./src/index.ts",
8
- "module": "./build/esm/index.js",
9
8
  "types": "./build/index.d.ts",
9
+ "exports": {
10
+ "import": "./build/esm/index.js",
11
+ "require": "./build/cjs/index.js"
12
+ },
13
+ "type": "module",
10
14
  "devDependencies": {
11
- "@craco/craco": "^7.1.0",
12
- "@rollup/plugin-commonjs": "^26.0.1",
13
- "@types/jest": "^27.5.2",
14
- "@types/node": "^20.8.6",
15
- "@types/qs": "^6.9.15",
16
- "typescript": "^5.5.3"
15
+ "@rollup/plugin-commonjs": "^28.0.0",
16
+ "@types/node": "^22.7.5",
17
+ "@types/qs": "^6.9.16",
18
+ "@vitest/coverage-v8": "^2.1.3",
19
+ "typescript": "5.6.3",
20
+ "vite": "^5.4.8",
21
+ "vitest": "^2.1.3"
17
22
  },
18
23
  "scripts": {
19
24
  "build": "tsc && rollup --config ../../rollup.config.mjs",
20
25
  "tsc": "tsc",
21
26
  "lint": "eslint .",
22
- "test": "jest --watch",
23
- "depcheck": "depcheck --ignores=@types/jest,@types/node,@rollup/plugin-commonjs --ignore-dirs=lib",
27
+ "test": "echo \"Tests have to run from root project\"",
28
+ "depcheck": "depcheck --ignores=@types/node,@rollup/plugin-commonjs,@vitest/coverage-v8 --ignore-dirs=lib",
24
29
  "prepack": "node ../../scripts/prepack.js",
25
30
  "postpack": "node ../../scripts/postpack.js",
26
31
  "translate": "echo \"Nothing to translate\"",
@@ -28,8 +33,8 @@
28
33
  "generate-api-report": "tsc && api-extractor run --verbose --local"
29
34
  },
30
35
  "dependencies": {
31
- "matrix-widget-api": "^1.6.0",
32
- "qs": "^6.12.3",
36
+ "matrix-widget-api": "^1.9.0",
37
+ "qs": "^6.13.0",
33
38
  "rxjs": "^7.8.1"
34
39
  },
35
40
  "repository": {
@@ -44,6 +49,5 @@
44
49
  "matrix",
45
50
  "widget",
46
51
  "matrix-widget-api"
47
- ],
48
- "main": "./build/cjs/index.js"
52
+ ]
49
53
  }