smartsocket/ts/smartsocket.helpers.ts

41 lines
1.7 KiB
TypeScript
Raw Normal View History

2016-08-07 12:58:20 +00:00
import * as plugins from "./smartsocket.plugins";
2016-08-08 16:20:00 +00:00
// classes
import { Smartsocket } from "./smartsocket.classes.smartsocket";
2016-08-12 01:22:36 +00:00
import { SocketFunction, allSocketFunctions } from "./smartsocket.classes.socketfunction";
import { SocketConnection, ISocketConnectionAuthenticationObject } from "./smartsocket.classes.socketconnection";
2016-08-12 03:17:13 +00:00
import { SocketRequest, allSocketRequests, TSocketRequestSide } from "./smartsocket.classes.socketrequest";
2016-09-04 22:34:09 +00:00
import { SocketRole } from "./smartsocket.classes.socketrole";
2016-08-07 12:58:20 +00:00
// SocketConnection helpers
2016-09-04 22:34:09 +00:00
export let checkPasswordForRole = (dataArg: ISocketConnectionAuthenticationObject, referenceSmartsocket:Smartsocket): boolean => {
let targetPasswordHash = getSocketRoleByName(dataArg.role,referenceSmartsocket).passwordHash;
let computedCompareHash = plugins.nodehash.sha256FromStringSync(dataArg.password);
return targetPasswordHash === computedCompareHash;
}
2016-08-12 01:22:36 +00:00
// SocketFunction helpers
export let getSocketFunctionByName = (functionNameArg: string): SocketFunction => {
2016-08-12 03:17:13 +00:00
return allSocketFunctions.find((socketFunctionArg) => { return socketFunctionArg.name === functionNameArg });
2016-08-12 01:22:36 +00:00
}
2016-08-12 03:17:13 +00:00
// SocketRequest helpers
/**
* get corresponding Socketrequest instance by shortId
*/
export let getSocketRequestById = (shortIdArg: string, requestSide?: TSocketRequestSide): SocketRequest => {
return allSocketRequests.find((socketRequestArg) => { return socketRequestArg.shortid === shortIdArg })
2016-08-12 03:17:13 +00:00
}
2016-08-07 12:58:20 +00:00
2016-08-08 16:20:00 +00:00
// SocketRole helpers
2016-08-12 01:22:36 +00:00
/**
2016-08-12 03:17:13 +00:00
* get corresponding SocketRole instance by name
2016-08-12 01:22:36 +00:00
*/
2016-09-04 22:34:09 +00:00
export let getSocketRoleByName = (socketRoleNameArg: string,referenceSmartsocket:Smartsocket): SocketRole => {
return referenceSmartsocket.socketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg })
2016-08-08 16:20:00 +00:00
};
2016-08-07 12:58:20 +00:00