matrix-bot-sdk
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -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[]; | ||
} |
@@ -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. |
{ | ||
"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/*" | ||
] | ||
} |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
104375
0
37
2200
5
3
1
+ Added@types/node@^8.10.34
+ Addedtslint@^5.11.0
+ Addedtypescript@^3.1.1
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@types/node@8.10.66(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuiltin-modules@1.1.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddiff@4.0.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtslib@1.14.1(transitive)
+ Addedtslint@5.20.1(transitive)
+ Addedtsutils@2.29.0(transitive)
+ Addedtypescript@3.9.10(transitive)
+ Addedwrappy@1.0.2(transitive)