From c8c107405f539c3d2316e30de21252b8d3920efc Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Nov 2024 11:39:17 -0500 Subject: [PATCH] Let widget driver send error details (#28357) * Let widget driver send error details * Match new widget API types * Don't @link across packages in case web documentation generation disallows it. * Update matrix-widget-api * Update matrix-js-sdk Include matrix-org/matrix-js-sdk#4507 to fix playwright CI --- package.json | 2 +- src/stores/widgets/StopGapWidgetDriver.ts | 13 +++++++++++++ yarn.lock | 12 ++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index cbb8a33480..e40dea659e 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ "matrix-encrypt-attachment": "^1.0.3", "matrix-events-sdk": "0.0.1", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", - "matrix-widget-api": "^1.9.0", + "matrix-widget-api": "^1.10.0", "memoize-one": "^6.0.0", "oidc-client-ts": "^3.0.1", "opus-recorder": "^8.0.3", diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 09553b40ce..5bc2ac7fc0 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -24,6 +24,7 @@ import { WidgetDriver, WidgetEventCapability, WidgetKind, + IWidgetApiErrorResponseDataDetails, ISearchUserDirectoryResult, IGetMediaConfigResult, UpdateDelayedEventAction, @@ -33,6 +34,7 @@ import { ITurnServer as IClientTurnServer, EventType, IContent, + MatrixError, MatrixEvent, Room, Direction, @@ -689,4 +691,15 @@ export class StopGapWidgetDriver extends WidgetDriver { const blob = await response.blob(); return { file: blob }; } + + /** + * Expresses a {@link MatrixError} as a JSON payload + * for use by Widget API error responses. + * @param error The error to handle. + * @returns The error expressed as a JSON payload, + * or undefined if it is not a {@link MatrixError}. + */ + public processError(error: unknown): IWidgetApiErrorResponseDataDetails | undefined { + return error instanceof MatrixError ? { matrix_api_error: error.asWidgetApiErrorData() } : undefined; + } } diff --git a/yarn.lock b/yarn.lock index 343a0f3ef4..c5ef6a55e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8309,7 +8309,7 @@ matrix-events-sdk@0.0.1: "matrix-js-sdk@github:matrix-org/matrix-js-sdk#develop": version "34.10.0" - resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/5a1488ebd5552817b1e95265afe7b3baac1231a2" + resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/6855ace6422082d173438cb23368d2fabc6a1086" dependencies: "@babel/runtime" "^7.12.5" "@matrix-org/matrix-sdk-crypto-wasm" "^9.0.0" @@ -8320,7 +8320,7 @@ matrix-events-sdk@0.0.1: jwt-decode "^4.0.0" loglevel "^1.7.1" matrix-events-sdk "0.0.1" - matrix-widget-api "^1.8.2" + matrix-widget-api "^1.10.0" oidc-client-ts "^3.0.1" p-retry "4" sdp-transform "^2.14.1" @@ -8345,10 +8345,10 @@ matrix-web-i18n@^3.2.1: minimist "^1.2.8" walk "^2.3.15" -matrix-widget-api@^1.8.2, matrix-widget-api@^1.9.0: - version "1.9.0" - resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.9.0.tgz#884136b405bd3c56e4ea285095c9e01ec52b6b1f" - integrity sha512-au8mqralNDqrEvaVAkU37bXOb8I9SCe+ACdPk11QWw58FKstVq31q2wRz+qWA6J+42KJ6s1DggWbG/S3fEs3jw== +matrix-widget-api@^1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.10.0.tgz#d31ea073a5871a1fb1a511ef900b0c125a37bf55" + integrity sha512-rkAJ29briYV7TJnfBVLVSKtpeBrBju15JZFSDP6wj8YdbCu1bdmlplJayQ+vYaw1x4fzI49Q+Nz3E85s46sRDw== dependencies: "@types/events" "^3.0.0" events "^3.2.0"