matrix-widget-api
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -6,2 +6,9 @@ import { Capability, IOpenIDCredentials, OpenIDRequestState, SimpleObservable, IRoomEvent, IRoomAccountData, ITurnServer } from ".."; | ||
} | ||
export interface ISendFutureDetails { | ||
roomId: string; | ||
futureGroupId: string; | ||
sendToken: string; | ||
cancelToken: string; | ||
refreshToken?: string; | ||
} | ||
export interface IOpenIDUpdate { | ||
@@ -67,2 +74,22 @@ state: OpenIDRequestState; | ||
/** | ||
* @experimental Part of MSC4140 & MSC4157 | ||
* Sends a future into a room. If `roomId` is falsy, the client should send the future | ||
* into the room the user is currently looking at. The widget API will have already | ||
* verified that the widget is capable of sending the future's event to that room. | ||
* @param {number|null} futureTimeout The future's timeout, or null for an action future. | ||
* May not be null if {@link futureGroupId} is null. | ||
* @param {string|null} futureGroupId The ID of the group the future belongs to, | ||
* or null if it will be put in a new group. May not be null if {@link futureTimeout} is null. | ||
* @param {string} eventType The event type of the event to be sent by the future. | ||
* @param {*} content The content for the event to be sent by the future. | ||
* @param {string|null} stateKey The state key if the event to be sent by the future is | ||
* a state event, otherwise null. May be an empty string. | ||
* @param {string|null} roomId The room ID to send the future to. If falsy, the room the | ||
* user is currently looking at. | ||
* @returns {Promise<ISendFutureDetails>} Resolves when the future has been sent with | ||
* details of that future. | ||
* @throws Rejected when the future could not be sent. | ||
*/ | ||
sendFuture(futureTimeout: number | null, futureGroupId: string | null, eventType: string, content: unknown, stateKey?: string | null, roomId?: string | null): Promise<ISendFutureDetails>; | ||
/** | ||
* Sends a to-device event. The widget API will have already verified that the widget | ||
@@ -69,0 +96,0 @@ * is capable of sending the event. |
@@ -14,3 +14,3 @@ "use strict"; | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* | ||
* Copyright 2020 - 2021 The Matrix.org Foundation C.I.C. | ||
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C. | ||
* | ||
@@ -84,2 +84,29 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
/** | ||
* @experimental Part of MSC4140 & MSC4157 | ||
* Sends a future into a room. If `roomId` is falsy, the client should send the future | ||
* into the room the user is currently looking at. The widget API will have already | ||
* verified that the widget is capable of sending the future's event to that room. | ||
* @param {number|null} futureTimeout The future's timeout, or null for an action future. | ||
* May not be null if {@link futureGroupId} is null. | ||
* @param {string|null} futureGroupId The ID of the group the future belongs to, | ||
* or null if it will be put in a new group. May not be null if {@link futureTimeout} is null. | ||
* @param {string} eventType The event type of the event to be sent by the future. | ||
* @param {*} content The content for the event to be sent by the future. | ||
* @param {string|null} stateKey The state key if the event to be sent by the future is | ||
* a state event, otherwise null. May be an empty string. | ||
* @param {string|null} roomId The room ID to send the future to. If falsy, the room the | ||
* user is currently looking at. | ||
* @returns {Promise<ISendFutureDetails>} Resolves when the future has been sent with | ||
* details of that future. | ||
* @throws Rejected when the future could not be sent. | ||
*/ | ||
}, { | ||
key: "sendFuture", | ||
value: function sendFuture(futureTimeout, futureGroupId, eventType, content) { | ||
var stateKey = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; | ||
var roomId = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null; | ||
return Promise.reject(new Error("Failed to override function")); | ||
} | ||
/** | ||
* Sends a to-device event. The widget API will have already verified that the widget | ||
@@ -86,0 +113,0 @@ * is capable of sending the event. |
@@ -10,2 +10,4 @@ import { IWidgetApiRequest, IWidgetApiRequestData } from "./IWidgetApiRequest"; | ||
room_id?: string; | ||
future_timeout?: number; | ||
future_group_id?: string; | ||
} | ||
@@ -18,3 +20,7 @@ export interface ISendEventFromWidgetActionRequest extends IWidgetApiRequest { | ||
room_id: string; | ||
event_id: string; | ||
event_id?: string; | ||
future_group_id?: string; | ||
send_token?: string; | ||
cancel_token?: string; | ||
refresh_token?: string; | ||
} | ||
@@ -21,0 +27,0 @@ export interface ISendEventFromWidgetActionResponse extends ISendEventFromWidgetActionRequest { |
@@ -200,4 +200,5 @@ /// <reference types="node" /> | ||
closeModalWidget(data?: IModalWidgetReturnData): Promise<void>; | ||
sendRoomEvent(eventType: string, content: unknown, roomId?: string): Promise<ISendEventFromWidgetResponseData>; | ||
sendStateEvent(eventType: string, stateKey: string, content: unknown, roomId?: string): Promise<ISendEventFromWidgetResponseData>; | ||
sendRoomEvent(eventType: string, content: unknown, roomId?: string, futureTimeout?: number, futureGroupId?: string): Promise<ISendEventFromWidgetResponseData>; | ||
sendStateEvent(eventType: string, stateKey: string, content: unknown, roomId?: string, futureTimeout?: number, futureGroupId?: string): Promise<ISendEventFromWidgetResponseData>; | ||
private sendEvent; | ||
/** | ||
@@ -204,0 +205,0 @@ * Sends a to-device event. |
@@ -21,2 +21,4 @@ "use strict"; | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -40,3 +42,3 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } | ||
function _OverloadYield(value, kind) { this.v = value, this.k = kind; } /* | ||
* Copyright 2020 - 2021 The Matrix.org Foundation C.I.C. | ||
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C. | ||
* | ||
@@ -411,18 +413,25 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
key: "sendRoomEvent", | ||
value: function sendRoomEvent(eventType, content, roomId) { | ||
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SendEvent, { | ||
type: eventType, | ||
content: content, | ||
room_id: roomId | ||
}); | ||
value: function sendRoomEvent(eventType, content, roomId, futureTimeout, futureGroupId) { | ||
return this.sendEvent(eventType, undefined, content, roomId, futureTimeout, futureGroupId); | ||
} | ||
}, { | ||
key: "sendStateEvent", | ||
value: function sendStateEvent(eventType, stateKey, content, roomId) { | ||
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SendEvent, { | ||
value: function sendStateEvent(eventType, stateKey, content, roomId, futureTimeout, futureGroupId) { | ||
return this.sendEvent(eventType, stateKey, content, roomId, futureTimeout, futureGroupId); | ||
} | ||
}, { | ||
key: "sendEvent", | ||
value: function sendEvent(eventType, stateKey, content, roomId, futureTimeout, futureGroupId) { | ||
return this.transport.send(_WidgetApiAction.WidgetApiFromWidgetAction.SendEvent, _objectSpread(_objectSpread(_objectSpread(_objectSpread({ | ||
type: eventType, | ||
content: content, | ||
state_key: stateKey, | ||
content: content | ||
}, stateKey !== undefined && { | ||
state_key: stateKey | ||
}), roomId !== undefined && { | ||
room_id: roomId | ||
}); | ||
}), futureTimeout !== undefined && { | ||
future_timeout: futureTimeout | ||
}), futureGroupId !== undefined && { | ||
future_group_id: futureGroupId | ||
})); | ||
} | ||
@@ -429,0 +438,0 @@ |
{ | ||
"name": "matrix-widget-api", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Matrix Widget API SDK", | ||
@@ -20,6 +20,7 @@ "main": "./lib/index.js", | ||
"build:browser:prod": "browserify lib/index.js --s mxwidgets -p tinyify -o dist/api.min.js", | ||
"lint": "yarn lint:types && yarn lint:ts", | ||
"lint": "yarn lint:types && yarn lint:ts && yarn lint:workflows", | ||
"lint:ts": "eslint src test", | ||
"lint:types": "tsc --noEmit", | ||
"lint:fix": "eslint src test --fix", | ||
"lint:workflows": "find .github/workflows -type f \\( -iname '*.yaml' -o -iname '*.yml' \\) | xargs -I {} sh -c 'echo \"Linting {}\"; action-validator \"{}\"'", | ||
"test": "jest" | ||
@@ -37,2 +38,4 @@ }, | ||
"devDependencies": { | ||
"@action-validator/cli": "^0.5.3", | ||
"@action-validator/core": "^0.5.3", | ||
"@babel/cli": "^7.11.6", | ||
@@ -39,0 +42,0 @@ "@babel/core": "^7.11.6", |
/* | ||
* Copyright 2020 - 2021 The Matrix.org Foundation C.I.C. | ||
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C. | ||
* | ||
@@ -27,3 +27,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
import { Capability, MatrixCapabilities } from "./interfaces/Capabilities"; | ||
import { IOpenIDUpdate, ISendEventDetails, WidgetDriver } from "./driver/WidgetDriver"; | ||
import { IOpenIDUpdate, ISendEventDetails, ISendFutureDetails, WidgetDriver } from "./driver/WidgetDriver"; | ||
import { | ||
@@ -481,6 +481,5 @@ ICapabilitiesActionResponseData, | ||
const isState = request.data.state_key !== null && request.data.state_key !== undefined; | ||
let sendEventPromise: Promise<ISendEventDetails>; | ||
if (isState) { | ||
if (!this.canSendStateEvent(request.data.type, request.data.state_key!)) { | ||
let sendEventPromise: Promise<ISendEventDetails|ISendFutureDetails>; | ||
if (request.data.state_key !== undefined) { | ||
if (!this.canSendStateEvent(request.data.type, request.data.state_key)) { | ||
return this.transport.reply<IWidgetApiErrorResponseData>(request, { | ||
@@ -491,8 +490,19 @@ error: {message: "Cannot send state events of this type"}, | ||
sendEventPromise = this.driver.sendEvent( | ||
request.data.type, | ||
request.data.content || {}, | ||
request.data.state_key, | ||
request.data.room_id, | ||
); | ||
if (request.data.future_timeout === undefined && request.data.future_group_id === undefined) { | ||
sendEventPromise = this.driver.sendEvent( | ||
request.data.type, | ||
request.data.content || {}, | ||
request.data.state_key, | ||
request.data.room_id, | ||
); | ||
} else { | ||
sendEventPromise = this.driver.sendFuture( | ||
request.data.future_timeout ?? null, | ||
request.data.future_group_id ?? null, | ||
request.data.type, | ||
request.data.content || {}, | ||
request.data.state_key, | ||
request.data.room_id, | ||
); | ||
} | ||
} else { | ||
@@ -507,8 +517,19 @@ const content = request.data.content as { msgtype?: string } || {}; | ||
sendEventPromise = this.driver.sendEvent( | ||
request.data.type, | ||
content, | ||
null, // not sending a state event | ||
request.data.room_id, | ||
); | ||
if (request.data.future_timeout === undefined && request.data.future_group_id === undefined) { | ||
sendEventPromise = this.driver.sendEvent( | ||
request.data.type, | ||
content, | ||
null, // not sending a state event | ||
request.data.room_id, | ||
); | ||
} else { | ||
sendEventPromise = this.driver.sendFuture( | ||
request.data.future_timeout ?? null, | ||
request.data.future_group_id ?? null, | ||
request.data.type, | ||
content, | ||
null, // not sending a state event | ||
request.data.room_id, | ||
); | ||
} | ||
} | ||
@@ -519,3 +540,10 @@ | ||
room_id: sentEvent.roomId, | ||
event_id: sentEvent.eventId, | ||
...("eventId" in sentEvent ? { | ||
event_id: sentEvent.eventId, | ||
} : { | ||
future_group_id: sentEvent.futureGroupId, | ||
send_token: sentEvent.sendToken, | ||
cancel_token: sentEvent.cancelToken, | ||
...("refreshToken" in sentEvent && { refresh_token: sentEvent.refreshToken }), | ||
}), | ||
}); | ||
@@ -522,0 +550,0 @@ }).catch(e => { |
/* | ||
* Copyright 2020 - 2021 The Matrix.org Foundation C.I.C. | ||
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C. | ||
* | ||
@@ -32,2 +32,10 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
export interface ISendFutureDetails { | ||
roomId: string; | ||
futureGroupId: string; | ||
sendToken: string; | ||
cancelToken: string; | ||
refreshToken?: string; | ||
} | ||
export interface IOpenIDUpdate { | ||
@@ -108,2 +116,32 @@ state: OpenIDRequestState; | ||
/** | ||
* @experimental Part of MSC4140 & MSC4157 | ||
* Sends a future into a room. If `roomId` is falsy, the client should send the future | ||
* into the room the user is currently looking at. The widget API will have already | ||
* verified that the widget is capable of sending the future's event to that room. | ||
* @param {number|null} futureTimeout The future's timeout, or null for an action future. | ||
* May not be null if {@link futureGroupId} is null. | ||
* @param {string|null} futureGroupId The ID of the group the future belongs to, | ||
* or null if it will be put in a new group. May not be null if {@link futureTimeout} is null. | ||
* @param {string} eventType The event type of the event to be sent by the future. | ||
* @param {*} content The content for the event to be sent by the future. | ||
* @param {string|null} stateKey The state key if the event to be sent by the future is | ||
* a state event, otherwise null. May be an empty string. | ||
* @param {string|null} roomId The room ID to send the future to. If falsy, the room the | ||
* user is currently looking at. | ||
* @returns {Promise<ISendFutureDetails>} Resolves when the future has been sent with | ||
* details of that future. | ||
* @throws Rejected when the future could not be sent. | ||
*/ | ||
public sendFuture( | ||
futureTimeout: number | null, | ||
futureGroupId: string | null, | ||
eventType: string, | ||
content: unknown, | ||
stateKey: string | null = null, | ||
roomId: string | null = null, | ||
): Promise<ISendFutureDetails> { | ||
return Promise.reject(new Error("Failed to override function")); | ||
} | ||
/** | ||
* Sends a to-device event. The widget API will have already verified that the widget | ||
@@ -110,0 +148,0 @@ * is capable of sending the event. |
/* | ||
* Copyright 2020 - 2021 The Matrix.org Foundation C.I.C. | ||
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C. | ||
* | ||
@@ -27,2 +27,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
room_id?: string; // eslint-disable-line camelcase | ||
// MSC4157: Futures | ||
future_timeout?: number; // eslint-disable-line camelcase | ||
future_group_id?: string; // eslint-disable-line camelcase | ||
} | ||
@@ -37,3 +41,9 @@ | ||
room_id: string; // eslint-disable-line camelcase | ||
event_id: string; // eslint-disable-line camelcase | ||
event_id?: string; // eslint-disable-line camelcase | ||
// MSC4157: Futures | ||
future_group_id?: string; // eslint-disable-line camelcase | ||
send_token?: string; // eslint-disable-line camelcase | ||
cancel_token?: string; // eslint-disable-line camelcase | ||
refresh_token?: string; // eslint-disable-line camelcase | ||
} | ||
@@ -40,0 +50,0 @@ |
/* | ||
* Copyright 2020 - 2021 The Matrix.org Foundation C.I.C. | ||
* Copyright 2020 - 2024 The Matrix.org Foundation C.I.C. | ||
* | ||
@@ -403,7 +403,6 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
roomId?: string, | ||
futureTimeout?: number, | ||
futureGroupId?: string, | ||
): Promise<ISendEventFromWidgetResponseData> { | ||
return this.transport.send<ISendEventFromWidgetRequestData, ISendEventFromWidgetResponseData>( | ||
WidgetApiFromWidgetAction.SendEvent, | ||
{type: eventType, content, room_id: roomId}, | ||
); | ||
return this.sendEvent(eventType, undefined, content, roomId, futureTimeout, futureGroupId); | ||
} | ||
@@ -416,6 +415,26 @@ | ||
roomId?: string, | ||
futureTimeout?: number, | ||
futureGroupId?: string, | ||
): Promise<ISendEventFromWidgetResponseData> { | ||
return this.sendEvent(eventType, stateKey, content, roomId, futureTimeout, futureGroupId); | ||
} | ||
private sendEvent( | ||
eventType: string, | ||
stateKey: string | undefined, | ||
content: unknown, | ||
roomId?: string, | ||
futureTimeout?: number, | ||
futureGroupId?: string, | ||
): Promise<ISendEventFromWidgetResponseData> { | ||
return this.transport.send<ISendEventFromWidgetRequestData, ISendEventFromWidgetResponseData>( | ||
WidgetApiFromWidgetAction.SendEvent, | ||
{type: eventType, content, state_key: stateKey, room_id: roomId}, | ||
{ | ||
type: eventType, | ||
content, | ||
...(stateKey !== undefined && { state_key: stateKey }), | ||
...(roomId !== undefined && { room_id: roomId }), | ||
...(futureTimeout !== undefined && { future_timeout: futureTimeout }), | ||
...(futureGroupId !== undefined && { future_group_id: futureGroupId }), | ||
}, | ||
); | ||
@@ -422,0 +441,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1739083
17244
21