matrix-appservice
Advanced tools
Comparing version 0.2.1 to 0.2.2-b
@@ -24,2 +24,3 @@ "use strict"; | ||
}; | ||
this._cachedRegex = {}; | ||
} | ||
@@ -137,3 +138,85 @@ | ||
/** | ||
* Check if a user_id meets this registration regex. | ||
* @param {string} userId The user ID | ||
* @param {boolean} onlyExclusive True to restrict matching to only exclusive | ||
* regexes. False to allow exclusive or non-exlusive regexes to match. | ||
* @return {boolean} True if there is a match. | ||
*/ | ||
AppServiceRegistration.prototype.isUserMatch = function(userId, onlyExclusive) { | ||
return this._isMatch(this.namespaces.users, userId, onlyExclusive); | ||
}; | ||
/** | ||
* Check if a room alias meets this registration regex. | ||
* @param {string} alias The room alias | ||
* @param {boolean} onlyExclusive True to restrict matching to only exclusive | ||
* regexes. False to allow exclusive or non-exlusive regexes to match. | ||
* @return {boolean} True if there is a match. | ||
*/ | ||
AppServiceRegistration.prototype.isAliasMatch = function(alias, onlyExclusive) { | ||
return this._isMatch(this.namespaces.aliases, alias, onlyExclusive); | ||
}; | ||
/** | ||
* Check if a room ID meets this registration regex. | ||
* @param {string} roomId The room ID | ||
* @param {boolean} onlyExclusive True to restrict matching to only exclusive | ||
* regexes. False to allow exclusive or non-exlusive regexes to match. | ||
* @return {boolean} True if there is a match. | ||
*/ | ||
AppServiceRegistration.prototype.isRoomMatch = function(roomId, onlyExclusive) { | ||
return this._isMatch(this.namespaces.rooms, roomId, onlyExclusive); | ||
}; | ||
/** | ||
* Convert a JSON object to an AppServiceRegistration object. | ||
* @static | ||
* @param {Object} obj The registration object | ||
* @return {?AppServiceRegistration} The registration or null if the object | ||
* cannot be coerced into a registration. | ||
*/ | ||
AppServiceRegistration.fromObject = function(obj) { | ||
if (!obj.url) { | ||
return null; | ||
} | ||
var reg = new AppServiceRegistration(obj.url); | ||
reg.setHomeserverToken(obj.hs_token); | ||
reg.setAppServiceToken(obj.as_token); | ||
reg.setSenderLocalpart(obj.sender_localpart); | ||
if (obj.namespaces) { | ||
var kinds = ["users", "aliases", "rooms"]; | ||
kinds.forEach(function(kind) { | ||
if (!obj.namespaces[kind]) { | ||
return; | ||
} | ||
obj.namespaces[kind].forEach(function(regexObj) { | ||
reg.addRegexPattern( | ||
kind, regexObj.regex, regexObj.exclusive | ||
); | ||
}); | ||
}); | ||
} | ||
return reg; | ||
}; | ||
AppServiceRegistration.prototype._isMatch = function(regexList, sample, onlyExclusive) { | ||
onlyExclusive = Boolean(onlyExclusive); | ||
for (var i = 0; i < regexList.length; i++) { | ||
var regex = this._cachedRegex[regexList[i].regex]; | ||
if (!regex) { | ||
regex = new RegExp(regexList[i].regex); | ||
this._cachedRegex[regexList[i].regex] = regex; | ||
} | ||
if (regex.test(sample)) { | ||
if (onlyExclusive && !regexList[i].exclusive) { | ||
continue; | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** The application service registration class. */ | ||
module.exports = AppServiceRegistration; |
@@ -63,4 +63,9 @@ "use strict"; | ||
if (possiblePromise) { | ||
possiblePromise.then(function() { | ||
possiblePromise.done(function() { | ||
res.send({}); | ||
}, function(e) { | ||
res.send({ | ||
errcode: "M_UNKNOWN", | ||
error: e ? e.message : "" | ||
}); | ||
}); | ||
@@ -78,4 +83,9 @@ } | ||
if (possiblePromise) { | ||
possiblePromise.then(function() { | ||
possiblePromise.done(function() { | ||
res.send({}); | ||
}, function(e) { | ||
res.send({ | ||
errcode: "M_UNKNOWN", | ||
error: e ? e.message : "" | ||
}); | ||
}); | ||
@@ -82,0 +92,0 @@ } |
{ | ||
"name": "matrix-appservice", | ||
"version": "0.2.1", | ||
"version": "0.2.2b", | ||
"description": "Matrix Application Service Framework", | ||
@@ -10,4 +10,5 @@ "main": "./index", | ||
"scripts": { | ||
"gendoc": "jsdoc -r lib -R README.md -P package.json -d .jsdoc", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"lint": "jshint -c .jshint lib && gjslint --unix_mode --disable 0131,0211,0200,0222 --max_line_length 90 -r lib/" | ||
"lint": "eslint lib/" | ||
}, | ||
@@ -30,4 +31,5 @@ "repository": { | ||
"devDependencies": { | ||
"jsdoc": "^3.3.2" | ||
"jsdoc": "^3.3.2", | ||
"eslint": "^1.3.1" | ||
} | ||
} |
@@ -44,3 +44,3 @@ This is a Matrix Application Service framework written in Node.js. | ||
A hosted API reference can be found on [GitHub Pages](http://matrix-org.github.io/matrix-appservice-node/matrix-appservice/0.2.0/). | ||
A hosted API reference can be found on [GitHub Pages](http://matrix-org.github.io/matrix-appservice-node/index.html). | ||
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
28952
10
374
2
1