Methods
(async) adminMenu(locals, req) → {array}
Build admin menu based on locals and request.
- If multi-site is enabled, it will include the cross-site menu with options to manage all sites and site settings.
- If caching is enabled, it will include the cache storage menu in the appropriate section.
- Session management menu is also included in the appropriate section.
| Name | Type | Description |
|---|---|---|
locals | object | The locals object. |
req | object | The request object. |
- The admin menu items.
- Type:
- array
(async) applyActionHook(optsopt)
Apply action hook to the provided model.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts | object | <optional> | {} | The options object. Properties
|
(async) applyQueryHook(model, id, options) → {object}
Apply query hook to the provided model.
| Name | Type | Description |
|---|---|---|
model | object | The model object. |
id | string | | The ID of the model. |
options | object | Additional options. |
The result of the model hook.
- Type:
- object
(async) checkIconset(req, reply) → {Promise.<void>}
Check and set the iconset for a request.
| Name | Type | Description |
|---|---|---|
req | Object | The request object. |
reply | Object | The reply object. |
- A promise that resolves when the iconset is checked and set.
- Type:
- Promise.<void>
(async) checkRoute(req) → {Promise.<void>}
Check the route for a request.
| Name | Type | Description |
|---|---|---|
req | Object | The request object. |
- A promise that resolves when the route is checked.
- Type:
- Promise.<void>
checkRouteGuard(guards, paths) → {string|undefined}
Check route guard
| Name | Type | Description |
|---|---|---|
guards | Array | The array of guard objects. |
paths | Array | The array of paths to check. |
- The matched path or undefined if no match is found.
- Type:
- string |
undefined
(async) checkTeam(req, reply) → {Promise.<void>}
Check and set the team for a request.
| Name | Type | Description |
|---|---|---|
req | Object | The request object. |
reply | Object | The reply object. |
- A promise that resolves when the team is checked and set.
- Type:
- Promise.<void>
(async) checkTheme(req, reply) → {Promise.<void>}
Check and set the theme for a request.
| Name | Type | Description |
|---|---|---|
req | Object | The request object. |
reply | Object | The reply object. |
- A promise that resolves when the theme is checked and set.
- Type:
- Promise.<void>
(async) checkUser(req, reply, source) → {Promise.<(boolean|void)>}
Check and set the user for a request.
| Name | Type | Description |
|---|---|---|
req | Object | The request object. |
reply | Object | The reply object. |
source | Object | The source object. |
- A promise that resolves to a boolean indicating the result of the check or void.
- Type:
- Promise.<(boolean|void)>
(async) checkXSite(req, reply) → {Promise.<void>}
Check and set the Cross-site settings for a request.
| Name | Type | Description |
|---|---|---|
req | Object | The request object. |
reply | Object | The reply object. |
- A promise that resolves when the XSite is checked and set.
- Type:
- Promise.<void>
(async) clearCacheSite(id, result)
Clear the cache for a specific site.
| Name | Type | Description |
|---|---|---|
id | string | | The ID of the site. |
result | object | The result object containing site data. |
(async) clearCacheUser(id, result)
Clear the cache for a specific user.
| Name | Type | Description |
|---|---|---|
id | string | | The ID of the user. |
result | object | The result object containing user data. |
(async) createJwtFromUserRecord(rec) → {Promise.<object>}
Create JWT from user record
| Name | Type | Description |
|---|---|---|
rec | object | The user record object. |
- The JWT token and its expiration date.
- Type:
- Promise.<object>
(async) createNewSite(alias, hostnameopt, verboseopt)
Create a new site with the specified alias and optional hostname, using fixtures for initial data.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
alias | string | The alias for the new site. | ||
hostname | string | <optional> | The hostname for the new site. | |
verbose | boolean | <optional> | false | Whether to log verbose output. |
(async) createRefs(site, data, options, verbose)
Create references for the specified site using the provided data, options, and verbosity settings.
| Name | Type | Description |
|---|---|---|
site | object | The site object for which to create references. |
data | object | The data object containing fixtures for the site. |
options | object | Options to pass to the createRecord method. |
verbose | boolean | Whether to log verbose output. |
filterModelFromSetting(opts) → {object}
Filter model data based on settings.
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts | object | The options object. Properties
|
The filtered results and operation values.
- Type:
- object
generatePassword(req) → {string}
Generate a random password based on the configuration settings
| Name | Type | Description |
|---|---|---|
req | object | The request object. |
- The generated password.
- Type:
- string
(async) getActionGuards(rereadopt) → {Promise.<Array>}
Get action guards, optionally reloading them from the database.
| Name | Type | Attributes | Description |
|---|---|---|---|
reread | boolean | <optional> | Whether to reload the guards from the database. |
- A promise that resolves to an array of action guards.
- Type:
- Promise.<Array>
(async) getAllFixtures(aliasopt) → {Promise.<object>}
Get all fixtures for the specified alias, replacing any occurrences of '{alias}' in the fixture data with the provided alias.
| Name | Type | Attributes | Description |
|---|---|---|---|
alias | string | <optional> | The alias for the fixtures. |
- A promise that resolves to the fixtures data.
- Type:
- Promise.<object>
(async) getAnonymousGuards(rereadopt) → {Promise.<Array>}
Get anonymous guards, optionally reloading them from the database.
| Name | Type | Attributes | Description |
|---|---|---|---|
reread | boolean | <optional> | Whether to reload the guards from the database. |
- A promise that resolves to an array of anonymous guards.
- Type:
- Promise.<Array>
(async) getApiKeyFromUserId(id) → {Promise.<string>}
Get API key from user ID by hashing the user's salt
| Name | Type | Description |
|---|---|---|
id | string | | The user ID. |
- A promise that resolves to the API key.
- Type:
- Promise.<string>
(async) getAttribGuards(rereadopt) → {Promise.<Array>}
Get attribute guards, optionally reloading them from the database.
| Name | Type | Attributes | Description |
|---|---|---|---|
reread | boolean | <optional> | Whether to reload the guards from the database. |
- A promise that resolves to an array of attribute guards.
- Type:
- Promise.<Array>
(async) getCountriesValues() → {Promise.<Array.<{value: (string|number), text: string}>>}
Get a list of countries with their values and names
- A promise that resolves to an array of country values and names.
- Type:
- Promise.<Array.<{value: (string|number), text: string}>>
getModelNames(asValueopt) → {Array}
Get all loaded model names, optionally returning them as value-text pairs.
| Name | Type | Attributes | Description |
|---|---|---|---|
asValue | boolean | <optional> | Whether to return the model names as value-text pairs. |
- An array of model names or value-text pairs.
- Type:
- Array
(async) getQueryGuards(rereadopt) → {Promise.<Array>}
Get query guards, optionally reloading them from the database.
| Name | Type | Attributes | Description |
|---|---|---|---|
reread | boolean | <optional> | Whether to reload the guards from the database. |
- A promise that resolves to an array of query guards.
- Type:
- Promise.<Array>
(async) getSecureGuards(rereadopt) → {Promise.<Array>}
Get secure guards, optionally reloading them from the database.
| Name | Type | Attributes | Description |
|---|---|---|---|
reread | boolean | <optional> | Whether to reload the guards from the database. |
- A promise that resolves to an array of secure guards.
- Type:
- Promise.<Array>
(async) getSite(input, byIdopt) → {object}
Get site information based on the provided input, which can be either a hostname or an ID. If multi-site is enabled, it will fetch the site based on the hostname or ID; otherwise, it will return the default site.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input | string | | The input value, which can be either a hostname or an ID. | ||
byId | boolean | <optional> | false | Whether to fetch the site by ID. |
The site information.
- Type:
- object
getTeamIdsAndAliases(req) → {object}
Get the team IDs and aliases for the user in the request.
| Name | Type | Description |
|---|---|---|
req | object | The request object. |
An object containing the team IDs and aliases.
- Type:
- object
(async) getUserById(id, req) → {object|null}
Get a user by their ID.
| Name | Type | Description |
|---|---|---|
id | string | | The ID of the user to retrieve. |
req | object | The request object. |
The user object if found, otherwise null.
- Type:
- object |
null
(async) getUserByToken(token, req) → {object|null}
Get a user by their token.
| Name | Type | Description |
|---|---|---|
token | string | The token of the user to retrieve. |
req | object | The request object. |
The user object if found, otherwise null.
- Type:
- object |
null
(async) hash(item) → {Promise.<string>}
Hash the given item using the specified algorithm from the configuration.
| Name | Type | Description |
|---|---|---|
item | * | The item to be hashed. |
- A promise that resolves to the hashed value.
- Type:
- Promise.<string>
(async) init()
Plugin initialization method. This method is called by the Bajo framework during plugin initialization.
(async) isActionAllowed(action, model, req) → {Promise.<boolean>}
Check if the specified action is allowed for the given model and request. It retrieves the action guards, filters them based on the site ID, model name, and team IDs, and checks if the action is included in the allowed values. If any guard denies the action, it returns false; otherwise, it returns true.
| Name | Type | Description |
|---|---|---|
action | string | The action to check. Available actions are: 'READ', 'CREATE', 'UPDATE', 'REMOVE' and 'EXPORT'. |
model | object | The model object. |
req | object | The request object. |
- Returns true if the action is allowed, otherwise false.
- Type:
- Promise.<boolean>
(async) mergeTeam(user, req)
Merge team information into the user object.
| Name | Type | Description |
|---|---|---|
user | object | The user object to merge team information into. |
req | object | The request object. |
parseNsSettings(ns, setting, items)
Parse namespace settings for a request.
| Name | Type | Description |
|---|---|---|
ns | string | The namespace. |
setting | Object | The setting object. |
items | Array | The items to parse. |
(async) passwordRule(req) → {object}
Generate a password validation rule based on the configuration settings.
| Name | Type | Description |
|---|---|---|
req | object | The request object. |
- The Joi password validation rule.
- Type:
- object
pathsToCheck(req) → {Array}
Gather all paths to check for a request.
| Name | Type | Description |
|---|---|---|
req | Object | The request object. |
- An array of paths to check.
- Type:
- Array
(async) populateRouteGuards(sitesopt)
Populate route guards at start
| Name | Type | Attributes | Description |
|---|---|---|---|
sites | array | <optional> | List of sites to populate route guards for. If not provided, it will fetch all active sites. |
(async) rebuildFilter(model, filteropt, optionsopt) → {Promise.<object>}
Rebuild the filter for the provided model.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
model | object | The model object. | ||
filter | object | <optional> | {} | The filter object. |
options | object | <optional> | {} | Additional options. |
The rebuilt filter.
- Type:
- Promise.<object>
(async) removeRefs(site, options, verbose)
Remove references for the specified site using the provided options and verbosity settings.
| Name | Type | Description |
|---|---|---|
site | object | The site object for which to remove references. |
options | object | Options to pass to the removeRecord method. |
verbose | boolean | Whether to log verbose output. |
(async) removeSite(alias, verboseopt)
Remove a site with the specified alias, along with its references, using the provided verbosity settings.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
alias | string | The alias of the site to remove. | ||
verbose | boolean | <optional> | false | Whether to log verbose output. |
(async) resetToken(textopt) → {Promise.<{salt: string, token: string}>}
Reset token by generating a new salt and hashing it twice to create a new token.
| Name | Type | Attributes | Description |
|---|---|---|---|
text | string | <optional> | Optional text to use as the salt. If not provided, a new salt will be generated. |
- A promise that resolves to an object containing the salt and token.
- Type:
- Promise.<{salt: string, token: string}>
(async) runAttribGuard(optsopt)
Apply attribute guards to the provided model.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts | object | <optional> | {} | The options object. Properties
|
(async) runQueryGuard(optsopt)
Apply query guards to the provided query.
| Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts | object | <optional> | {} | The options object. Properties
|
(async) sendMail(tpl, paramsopt)
Method to send mail through Masohi Messaging System. It is a thin wrapper for masohi-mail send method.
If both masohiMail and waibu are not loaded, nothing is delivered.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
tpl | string | | Mail's template to use. If a string is given, the same template will be used for html & plaintext versions. Otherwise, the first template will be used for html mail, and the second one is for it's plaintext version | ||
params | Object | <optional> | {} | masohi-mail's params object. |
(async) signin(options)
Sign in user and redirect to the specified URL
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | object | The options object. Properties
|
(async) signout(options)
Sign out user and redirect to the specified URL
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | object | The options object. Properties
|
(async) start()
Plugin start method. This method is called by the Bajo framework during plugin start.
(async) verifyApiKey(req, reply, source, payload) → {boolean}
Verify API key
| Name | Type | Description |
|---|---|---|
req | object | The request object. |
reply | object | The reply object. |
source | string | The source of the authentication setting. |
payload | object | The payload object. |
- True if the API key is valid, otherwise false.
- Type:
- boolean
(async) verifyBasic(req, reply, source, payload) → {boolean|string}
Verify basic authentication
| Name | Type | Description |
|---|---|---|
req | object | The request object. |
reply | object | The reply object. |
source | string | The source of the authentication setting. |
payload | object | The payload object. |
- True if the basic authentication is valid, otherwise false or an error message.
- Type:
- boolean |
string
(async) verifyJwt(req, reply, source, payload) → {boolean}
Verify JWT authentication
| Name | Type | Description |
|---|---|---|
req | object | The request object. |
reply | object | The reply object. |
source | string | The source of the authentication setting. |
payload | object | The payload object. |
- True if the JWT authentication is valid, otherwise false.
- Type:
- boolean
(async) verifySession(req, reply, source, payload) → {boolean}
Verify user session
| Name | Type | Description |
|---|---|---|
req | object | The request object. |
reply | object | The reply object. |
source | string | The source of the authentication setting. |
payload | object | The payload object. |
- True if the session is valid, otherwise false.
- Type:
- boolean