Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

matrix-bot-sdk

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matrix-bot-sdk - npm Package Compare versions

Comparing version 0.1.14 to 0.1.15

scripts/try_build.js

37

lib/MatrixClient.d.ts

@@ -96,2 +96,17 @@ /// <reference types="node" />

/**
* Resolves a room ID or alias to a room ID. If the given ID or alias looks like a room ID
* already, it will be returned as-is. If the room ID or alias looks like a room alias, it
* will be resolved to a room ID if possible. If the room ID or alias is neither, an error
* will be raised.
* @param {string} roomIdOrAlias the room ID or alias to resolve to a room ID
* @returns {Promise<string>} resolves to the room ID
*/
resolveRoom(roomIdOrAlias: string): Promise<string>;
/**
* Does a room directory lookup for a given room alias
* @param {string} roomAlias the room alias to look up in the room directory
* @returns {Promise<RoomDirectoryLookupResponse>} resolves to the room's information
*/
lookupRoomAlias(roomAlias: string): Promise<RoomDirectoryLookupResponse>;
/**
* Gets the current user ID for this client

@@ -182,2 +197,20 @@ * @returns {Promise<string>} The user ID of this client

/**
* Sends a state event to the given room
* @param {string} roomId the room ID to send the event to
* @param {string} type the event type to send
* @param {string} stateKey the state key to send, should not be null
* @param {string} content the event body to send
* @returns {Promise<string>} resolves to the event ID that represents the message
*/
sendStateEvent(roomId: string, type: string, stateKey: string, content: any): Promise<string>;
/**
* Checks if a given user has a required power level
* @param {string} userId the user ID to check the power level of
* @param {string} roomId the room ID to check the power level in
* @param {string} eventType the event type to look for in the `events` property of the power levels
* @param {boolean} isState true to indicate the event is intended to be a state event
* @returns {Promise<boolean>} resolves to true if the user has the required power level, resolves to false otherwise
*/
userHasPowerLevelFor(userId: string, roomId: string, eventType: string, isState: boolean): Promise<boolean>;
/**
* Performs a web request to the homeserver, applying appropriate authorization headers for

@@ -195,1 +228,5 @@ * this client.

}
export interface RoomDirectoryLookupResponse {
roomId: string;
residentServers: string[];
}

72

lib/MatrixClient.js

@@ -153,2 +153,32 @@ "use strict";

/**
* Resolves a room ID or alias to a room ID. If the given ID or alias looks like a room ID
* already, it will be returned as-is. If the room ID or alias looks like a room alias, it
* will be resolved to a room ID if possible. If the room ID or alias is neither, an error
* will be raised.
* @param {string} roomIdOrAlias the room ID or alias to resolve to a room ID
* @returns {Promise<string>} resolves to the room ID
*/
resolveRoom(roomIdOrAlias) {
return __awaiter(this, void 0, void 0, function* () {
if (roomIdOrAlias.startsWith("!"))
return roomIdOrAlias; // probably
if (roomIdOrAlias.startsWith("#"))
return this.lookupRoomAlias(roomIdOrAlias).then(r => r.roomId);
throw new Error("Invalid room ID or alias");
});
}
/**
* Does a room directory lookup for a given room alias
* @param {string} roomAlias the room alias to look up in the room directory
* @returns {Promise<RoomDirectoryLookupResponse>} resolves to the room's information
*/
lookupRoomAlias(roomAlias) {
return this.doRequest("GET", "/_matrix/client/r0/directory/room/" + encodeURIComponent(roomAlias)).then(response => {
return {
roomId: response["room_id"],
residentServers: response["servers"],
};
});
}
/**
* Gets the current user ID for this client

@@ -310,3 +340,3 @@ * @returns {Promise<string>} The user ID of this client

else
console.debug("MatrixClientLite", "Not handling event " + event['type']);
this.emit("room.event", roomId, event);
}

@@ -433,2 +463,42 @@ }

/**
* Sends a state event to the given room
* @param {string} roomId the room ID to send the event to
* @param {string} type the event type to send
* @param {string} stateKey the state key to send, should not be null
* @param {string} content the event body to send
* @returns {Promise<string>} resolves to the event ID that represents the message
*/
sendStateEvent(roomId, type, stateKey, content) {
return this.doRequest("PUT", "/_matrix/client/r0/rooms/" + roomId + "/state/" + type + "/" + stateKey, null, content).then(response => {
return response['event_id'];
});
}
/**
* Checks if a given user has a required power level
* @param {string} userId the user ID to check the power level of
* @param {string} roomId the room ID to check the power level in
* @param {string} eventType the event type to look for in the `events` property of the power levels
* @param {boolean} isState true to indicate the event is intended to be a state event
* @returns {Promise<boolean>} resolves to true if the user has the required power level, resolves to false otherwise
*/
userHasPowerLevelFor(userId, roomId, eventType, isState) {
return __awaiter(this, void 0, void 0, function* () {
const powerLevelsEvent = yield this.getRoomStateEvents(roomId, "m.room.power_levels", "");
if (!powerLevelsEvent || typeof (powerLevelsEvent) !== "object") {
throw new Error("Unexpected power level event: none in room or multiple returned");
}
let requiredPower = isState ? 50 : 0;
if (isState && powerLevelsEvent["state_default"])
requiredPower = powerLevelsEvent["state_default"];
if (!isState && powerLevelsEvent["users_default"])
requiredPower = powerLevelsEvent["users_default"];
if (powerLevelsEvent["events"] && powerLevelsEvent["events"][eventType])
requiredPower = powerLevelsEvent["events"][eventType];
let userPower = 0;
if (powerLevelsEvent["users"] && powerLevelsEvent["users"][userId])
userPower = powerLevelsEvent["users"][userId];
return userPower >= requiredPower;
});
}
/**
* Performs a web request to the homeserver, applying appropriate authorization headers for

@@ -435,0 +505,0 @@ * this client.

20

package.json
{
"name": "matrix-bot-sdk",
"version": "0.1.14",
"version": "0.1.15",
"description": "A lightweight version of the matrix-js-sdk intended for bots",

@@ -15,9 +15,5 @@ "repository": {

"homepage": "https://github.com/turt2live/matrix-js-bot-sdk#readme",
"devDependencies": {
"@types/node": "^10.11.4",
"tslint": "^5.11.0",
"typescript": "^3.1.1"
},
"scripts": {
"prepublish": "npm run build",
"prepare": "node scripts/try_build.js",
"prepublishOnly": "npm run build",
"build": "tsc",

@@ -33,4 +29,7 @@ "lint": "tslint --project ./tsconfig.json -t stylish"

"dependencies": {
"@types/node": "^8.10.34",
"bluebird": "^3.5.2",
"request": "^2.88.0"
"request": "^2.88.0",
"tslint": "^5.11.0",
"typescript": "^3.1.1"
},

@@ -47,3 +46,8 @@ "keywords": [

"modules"
],
"files": [
"src/*",
"lib/*",
"scripts/*"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc