The following are hooks are already available in STLSe and will be executed with priority 10 and return you the desired value. You can obviously override them if needed.
interface frontend_filters { /** * This filter is triggered when the configuration of the instance are updated * * if it returns true, an alert will show up after which the page will be reloaded * if it returns false, nothing will happen * * @default true * @priority 10 * @returns boolean */ stlse_on_instance_refresh: (shouldReload: boolean) => boolean, /** * Allows you to hook into the final return object from the request call * @priority 10 * @returns the response object */ stlse_request_return_response: (object: FetchResponse<any>, response: Response, request: Request, options: FetchOptions) => Promise<FetchResponse<any>>, }
interface frontend_actions { /** * Allows you to list all modules that are loaded for this isntance * @priority 10 * @returns the full list of the loaded modules */ stlse_modules_get_list: () => Array<{slug: string, version: string}>, /** * Allows you to get the name of the module that triggers this hook * @priority 10 * @returns the full name `scope__slug` of the module that triggers this call */ stlse_module_name: () => string | void | Promise<string | void>, /** * Allows you to change the endpoint of STLSe * @param endpoint sets the main endpoint of STLSe * @priority 10 * @returns the endpoint that was set */ stlse_context_set_endpoint: (endpoint: string) => string, /** * Allows you to retrieve the information of STLSe * @priority 10 * @returns the endpoint of STLSe that was set */ stlse_context_get_endpoint: () => string, /** * Checks whether the WebSocket Socket.io connection with the backend is active * @priority 10 * @returns boolean */ stlse_socket_is_active: () => boolean, /** * Returns the id of the WebSocket Socket.io client * @priority 10 * @returns string */ stlse_socket_get_id: () => string, /** * Adds a callback that is triggered when a WebSocket Socket.io event is emitted * @param socketCode the code to listen to for the WebSocket Socket.io event * @param listener The callback function that takes the arguments passed when the WebSocket Socket.io event was emitted * @priority 10 * @returns void */ stlse_socket_on: (socketCode: string, listener: (...args: any[]) => void) => void, /** * Removes a callback that is triggered when a WebSocket Socket.io event is emitted * @param socketCode the code to listen to for the WebSocket Socket.io event * @param listener The same callback function passed as reference on the "stlse_socket_on" listener to remove * @priority 10 * @returns void */ stlse_socket_off: (socketCode: string, listener: (...args: any[]) => void) => void, /** * Emits a websocket event sending this data to the backend * @param socketCode the code to emit * @param args Arguments to pass to the backend * @priority 10 * @returns void */ stlse_socket_emit: (socketCode: string, ...args: any[]) => void, /** * Allows you to send an object containing custom fields to describe the current websocket client * @param description description object which may include any arbitrary data * @priority 10 * @returns void */ stlse_socket_add_description: (description: object) => void, /** * @priority 10 * @returns The authorization token data if it was set */ stlse_auth_get_token_data: () => DecodedAuthzTokenData | undefined, /** * Checks if the current authorization token is expired or not * @priority 10 * @returns true if token is valid, false if token is not set or invalid */ stlse_auth_is_token_valid: () => boolean, /** * Checks if the current token is valid, if so will fetch * @priority 10 * @returns a valid fresh token */ stlse_auth_get_valid_token: () => Promise<string>, /** * Saves the current authentication information in the specified cache key * @param changeCacheKey the key to use for the auth information * @priority 10 * @returns void */ stlse_auth_save_cache: (changeCacheKey: string) => void, /** * Restores a login session from the given cache key * @param cacheKey cache key where to get the authentication information from * @priority 10 * @returns true if successfully loaded and refreshed, false if not valid */ stlse_auth_load_cache: (cacheKey?: string) => Promise<boolean>, /** * Deletes the authentication information ONLY from the cache. * It will keep them in memory * @priority 10 * @returns void */ stlse_auth_clear_cache: () => void, /** * Deletes the authnetication information both from the cache and also from memory. * After calling this function all subsequent requests will return authentication error, so please remember to logout * @priority 10 * @returns void */ stlse_auth_clear_all: () => void, /** * This will be triggered when a secondary browser window overrides the authentication/cookie information and they are not compatibile with the current window * e.g. modules changed or SUB ID changed * @priority 10 * @returns boolean "true" to continue with default behaviour of clearing and reloading, "false" to not do any action */ stlse_auth_overridden_by_secondary_window: (errorMessage: string) => boolean, /** * A simple wrapper around fetch() to send requests to specified module * @param moduleName Module to send the request to * @param method HTTP Method to use * @param path the url path * @param options { module?: string, data?: any, headers?: {[string: string]: string}, params?: {[string: string]: any} } * @priority 10 * @returns response object { request: Request, response: Response, headers: {[string: string]: string}, status: number, ok: boolean, data: T, config: {method: Method, endpoint: string, options: FetchOptions} } */ stlse_request: <T = any>(method: Method, path: string, options?: FetchOptions) => Promise<FetchResponse<T>>, /** * This action triggers directly the native fetch() function but with extra authorization headers automatically insterted * @priority 10 * @returns the fetch() call result */ stlse_request_fetch: typeof fetch; /** * checks the connection status of the client, and returns the result * @priority 10 * @returns a ConnectionStatus enum, which can be one of the following values: 'OK' | 'SERVER-DOWN' | 'CLIENT-DOWN' */ stlse_request_check_connection: () => Promise<ConnectionStatus>, }
/** * If a hook accepts no props, then don't set any, but set empty object {} instead, * instead of: `hook_name: (p: any) => any`, do: `hook_name: (p: {}) => any` */ interface frontend_react_hooks { /** * This is the react root mount point, where you mount the start entry point react component of you module. * Used mostly by themes */ stlse_root_mount_point: (p: {instanceId: string}) => any, }
interface backend_filters { /** * Allows you to add additional data to the jwt token generated for the user * @param dataObj The data object to return * @param subId The subid for the client * @param instanceId The instance id of the application * @priority 10 * @returns the data object to add to the jwt token */ stlse_auth_token_data: (dataObj: object, subId: string, instanceId: string) => object, }
interface backend_actions { /** * listens to any socket event that is emitted from the frontend * @param namespace The namespace of the websocket client that emitted the event * @param originSocketId The websocket client id that emitted the event * @param eventCode The code of the websocket event that was emitted * @param args Any additional arguments that was passed when the client emitted the event * @priority 10 * @returns void */ stlse_socket_on_any: (namespace: string, originSocketId: string, eventCode: string, ...args: any) => void, /** * allows you to listen to a specific socket event by adding a suffix to this key * e.g. `stlse_socket_on__triggerevent` will listen to the 'triggerevent' event * e.g. `stlse_socket_on__anotheEvent` will listen to the 'anotheEvent' event * * this helps reduce how many different modules are executed as they are selected based on this key * * @param namespace The namespace of the websocket client that emitted the event * @param originSocketId The websocket client id that emitted the event * @param eventCode The code of the websocket event that was emitted * @param args Any additional arguments that was passed when the client emitted the event * @priority 10 * @returns void */ [key: `stlse_socket_on__${string}`]: (namespace: string, originSocketId: string, eventCode: string, ...args: any) => void, stlse_socket_on__: (namespace: string, originSocketId: string, eventCode: string, ...args: any) => void, /** * Allows you to send a socket event to the target websocket client * @param namespace The namespace of the websocket client where to emit the event * @param targetSocketId The target websocket client id to emit to. You can also use the instanceId of the application to emit to all the websocket clients of that instance * @param eventCode The code to emit to the client/s * @param args Any additional arguments that are going to be sent to the client * @priority 10 * @returns undefined if no module have modified the payload to send to the client * @returns an object containing the data that was sent to the client if they were modified by some module */ stlse_socket_emit: (namespace: string, targetSocketId: string, eventCode: string, ...args: any) => undefined | {namespace: string, targetSocketId: string, eventCode: string, args: any[]}, /** * Lists the websocket client connected in a given namespace * @param namespace the namespace of the websocket connections * @priority 10 * @returns an object containing the id of the websocket client connected, and the description object emitted by that client */ stlse_socket_list: (namespace: string) => Array<{id: string, description?: {[key: string]: any}}>; /** * Executes the specified operation on the db() object of mongo * @param operation The operation of the MongoDB database to execute. It corresponds to the functions available on the Database object of mongodb. e.g listCollections() * @param args Arguments to the operation * @priority 10 * @returns Result of operation */ stlse_db: (operation: keyof Db, ...args: any[]) => any, // stlse_db: <T extends keyof Db>(operation: T, ...args: Db[T] extends (...args: any[]) => any ? Parameters<Db[T]> : any[]) => Promise<Db[T]>, /** * sends an operation to the db().collection() object of mongo * @param collection Collection to operate on * @param operation The operation of the MongoDB collection to execute. It corresponds to the functions available on the Collection object of mongodb. e.g find(), findOne(), insertOne(), insertMany, ...etc. * @param args Arguments to the operation * @priority 10 * @returns Result of operation */ stlse_db_collection: (collection: string, operation: keyof Collection, ...args: any[]) => any, /** * A simple wrapper around fetch() to send requests to specified module * @param method HTTP Method to use * @param path the url path * @param options { data?: any, headers?: {[string: string]: string}, params?: {[string: string]: any} } * @priority 10 * @returns response object { headers: {[string: string]: string}, status: number, ok: boolean, data: T, config: {method: Method, endpoint: string, options: FetchOptions} } */ stlse_request: <T = any>(method: Method, path: string, options: FetchOptions) => Promise<FetchResponse<T>>, }