smartsocket/ts/smartsocket.helpers.ts

61 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-03-15 01:29:40 +00:00
import * as plugins from './smartsocket.plugins';
2016-08-07 12:58:20 +00:00
2016-08-08 16:20:00 +00:00
// classes
2018-03-15 01:29:40 +00:00
import { Smartsocket } from './smartsocket.classes.smartsocket';
import { SocketFunction, allSocketFunctions } from './smartsocket.classes.socketfunction';
import {
SocketConnection,
ISocketConnectionAuthenticationObject
} from './smartsocket.classes.socketconnection';
import {
SocketRequest,
allSocketRequests,
TSocketRequestSide
} from './smartsocket.classes.socketrequest';
import { SocketRole } from './smartsocket.classes.socketrole';
2016-08-07 12:58:20 +00:00
// SocketConnection helpers
2018-03-15 01:29:40 +00:00
export let checkPasswordForRole = (
dataArg: ISocketConnectionAuthenticationObject,
referenceSmartsocket: Smartsocket
): boolean => {
let targetPasswordHash = getSocketRoleByName(dataArg.role, referenceSmartsocket).passwordHash;
let computedCompareHash = plugins.smarthash.sha256FromStringSync(dataArg.password);
2018-03-15 01:29:40 +00:00
return targetPasswordHash === computedCompareHash;
};
2016-08-12 01:22:36 +00:00
// SocketFunction helpers
export let getSocketFunctionByName = (functionNameArg: string): SocketFunction => {
2018-03-15 01:29:40 +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
*/
2018-03-15 01:29:40 +00:00
export let getSocketRequestById = (
shortIdArg: string,
requestSide?: TSocketRequestSide
): SocketRequest => {
return allSocketRequests.find(socketRequestArg => {
return socketRequestArg.shortid === shortIdArg;
});
};
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
*/
2018-03-15 01:29:40 +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
};