Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgef committed Jan 17, 2024
1 parent dd7e3aa commit 29102ab
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/components/Apiker/Apiker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -127,5 +131,8 @@ class Apiker {
}
}

/**
* Instance of the Apiker class
*/
const apiker = new Apiker();
export { apiker };
7 changes: 0 additions & 7 deletions src/components/Auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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){
Expand All @@ -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){
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -235,7 +229,6 @@ export const isCurrentUserAdmin = async (): Promise<boolean> => {
* 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();
Expand Down
29 changes: 26 additions & 3 deletions src/components/Bans/Bans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,51 @@ 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;
}
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;
Expand Down
3 changes: 2 additions & 1 deletion src/components/Email/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./Email";
export * from "./constants";
export * from "./constants";
export * from "./interfaces";
14 changes: 11 additions & 3 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -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";
export * from "./Validation";

0 comments on commit 29102ab

Please sign in to comment.