diff --git a/src/components/Apiker/Apiker.ts b/src/components/Apiker/Apiker.ts index 77bddf1..c72199a 100644 --- a/src/components/Apiker/Apiker.ts +++ b/src/components/Apiker/Apiker.ts @@ -6,7 +6,11 @@ import { handleEntryRequest, RequestParams } from "../Request"; import type { Controllers, EmailOptions, Firewall, ObjectStateMapping, Options, Routes, Timings } from "./interfaces"; import { ResponseParams } from "./utils"; -class Apiker { +/** + * Apiker class definition. + * ⚠️ Please do not instantiate this class and use the "apiker" exported instance instead. + */ +export class Apiker { name = "Apiker"; routes: Routes = {}; controllers: Controllers = {}; @@ -127,5 +131,8 @@ class Apiker { } } +/** + * Instance of the Apiker class + */ const apiker = new Apiker(); export { apiker }; diff --git a/src/components/Auth/utils.ts b/src/components/Auth/utils.ts index 7ccd0de..047ce4f 100644 --- a/src/components/Auth/utils.ts +++ b/src/components/Auth/utils.ts @@ -12,7 +12,6 @@ const Bcrypt = bcrypt(); /** * Encodes an input into Base64 * @param inputStr Base64 input to decode - * @returns */ export const encodeString = (inputStr: any) => { const wordArr = CryptoJS.enc.Utf8.parse(inputStr); @@ -23,7 +22,6 @@ export const encodeString = (inputStr: any) => { /** * Decodes a Base64 input * @param inputStr Base64 input to decode - * @returns */ export const decodeString = (inputStr: any) => { const keyb64 = inputStr.toString(CryptoJS.enc.Base64); @@ -35,7 +33,6 @@ export const decodeString = (inputStr: any) => { * Generates a JWT token * @param data Payload to include in the token * @param expirationInMinutes Expiration of the token (in minutes) - * @returns */ export const createJWT = (data: any, expirationInMinutes = 0) => { if(expirationInMinutes > 0){ @@ -53,7 +50,6 @@ export const createJWT = (data: any, expirationInMinutes = 0) => { /** * Parses a JWT token * @param token JWT token - * @returns */ export const parseJWT = (token: string, disableClientIdCheck?: boolean) => { if(!token){ @@ -88,7 +84,6 @@ export const parseJWT = (token: string, disableClientIdCheck?: boolean) => { /** * Generates a bcrypt hash of a given message * @param message Message to hash - * @returns */ export const hash_bcrypt = (message: string): string => { const salt = Bcrypt.genSaltSync(7); @@ -100,7 +95,6 @@ export const hash_bcrypt = (message: string): string => { * Compares a raw value with a bcrypt hash * @param message Raw input to compare * @param hash Hash to compare against - * @returns */ export const compare_bcrypt = (message: string, hash: string): boolean => { return Bcrypt.compareSync(message, hash); @@ -235,7 +229,6 @@ export const isCurrentUserAdmin = async (): Promise => { * Generates auth tokens for a given user * @param userId The user's ID * @param expirationInMinutes The expiration time for the action token. The refresh token does not expire. - * @returns */ export const getTokens = (userId: string, expirationInMinutes = AUTH_TOKEN_DURATION_MINS_DEFAULT) => { const clientId = getClientId(); diff --git a/src/components/Bans/Bans.ts b/src/components/Bans/Bans.ts index b6af363..ca6c199 100644 --- a/src/components/Bans/Bans.ts +++ b/src/components/Bans/Bans.ts @@ -3,11 +3,20 @@ import { addLogEntry, deleteAllLogsInObject, getAllLogEntries, getUserLogEntries import { OBN } from "../ObjectBase"; import { BANS_PREFIX } from "./constants"; +/** + * Bans an entity + * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) + * @param clientId The user's clientId (defaulting to getClientId()) + */ export const banEntity = async (entity: string, clientId = getClientId()) => { const user = await getCurrentUser(); return await addLogEntry(BANS_PREFIX, { issuedBy: user?.id, objectId: entity }, OBN.BANS, entity, clientId); }; +/** + * Unbans an entity + * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) + */ export const unbanEntity = async (entity: string) => { if(!entity){ return; @@ -15,16 +24,30 @@ export const unbanEntity = async (entity: string) => { return await deleteAllLogsInObject(OBN.BANS, entity) }; +/** + * Checks whether an entity is banned + * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) + */ export const isEntityBanned = async (entity: string) => { const entries = await getAllLogEntries(OBN.BANS, 1, entity); - return entries && entries.length; + return entries && !!entries.length; }; -export const getBannedEntries = async (entity: string) => { - const entries = await getAllLogEntries(OBN.BANS, 10, entity); +/** + * Get a list of banned entries for a given entity + * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) + * @param limit The number of results to return + */ +export const getBannedEntries = async (entity: string, limit = 10) => { + const entries = await getAllLogEntries(OBN.BANS, limit, entity); return entries; }; +/** + * Get a list of banned entries (without filtering by entity) + * @param entity The user's ID (can be any string, but preferable a signedIp acquired through getSignedIp()) + * @param limit The number of results to return + */ export const getBannedEntities = async (limit = 10) => { const entries = await getAllLogEntries(OBN.BANS, limit); return entries; diff --git a/src/components/Email/index.ts b/src/components/Email/index.ts index 984fcd4..0e08e62 100644 --- a/src/components/Email/index.ts +++ b/src/components/Email/index.ts @@ -1,2 +1,3 @@ export * from "./Email"; -export * from "./constants"; \ No newline at end of file +export * from "./constants"; +export * from "./interfaces"; \ No newline at end of file diff --git a/src/components/index.ts b/src/components/index.ts index 30493ab..5e6515a 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,9 +1,17 @@ export * from "./Apiker"; export * from "./Auth"; +export * from "./Bans"; +export * from "./Email"; +export * from "./EmailTemplates"; +export * from "./Firewall"; +export * from "./Geolocation"; +export * from "./Logging"; +export * from "./Middleware"; export * from "./ObjectBase"; +export * from "./Page"; +export * from "./RateLimit"; export * from "./Request"; export * from "./Response"; -export * from "./RateLimit"; -export * from "./Logging"; +export * from "./State"; export * from "./Timings"; -export * from "./Email"; \ No newline at end of file +export * from "./Validation"; \ No newline at end of file