/workspace

The Workspace API module exports the getKeyMethod() which returns a method from the keyMethods{} object.

  • layer
  • locale
  • locales
  • roles

The workspace typedef object has templates, locale, locales, dbs, and roles properties. The workspace will be cached in the process by the workspace/cache module.

Requires

Methods

(async, inner) getKeyMethod(req, res)

The cached workspace requested from the workspaceCache() will be assigned to the workspace variable declared in the module scope.

The method checks whether the req.params.key matches a keyMethods property and returns the matching method.

Parameters:
NameTypeDescription
reqreq

HTTP request.

resres

HTTP response.

Properties
NameTypeDescription
req.paramsObject

HTTP request params.

params.keystring

Workspace API method requested.

(async, inner) layer(req, res) → {res}

The method requests a JSON layer from the getLayer module.

Parameters:
NameTypeDescription
reqreq

HTTP request.

resres

HTTP response.

Properties
NameTypeAttributesDescription
req.paramsObject

HTTP request params.

params.localestring<optional>

Locale key.

params.layerboolean<optional>

Layer key.

params.userObject<optional>

User requesting the layer.

Returns:

The HTTP response with either an error.message or the JSON layer.

Type: 
res

(async, inner) locale(req, res) → {res}

The method requests a JSON locale from the getLocale module.

All locale layers are requested from the getLayer module with params.layers flag.

The locale.layers{} object is reduced to an array of layer keys without the params.layers flag.

Parameters:
NameTypeDescription
reqreq

HTTP request.

resres

HTTP response.

Properties
NameTypeAttributesDescription
req.paramsObject

HTTP request params.

params.localestring<optional>

Locale key.

params.layersboolean<optional>

Whether layer objects should be returned with the locale.

params.userObject<optional>

User requesting the locale.

Returns:

The HTTP response with either an error.message or the JSON locale.

Type: 
res

(inner) locales(req, res) → {res}

The locales method reduces the workspace.locales{} object to an array locales with only the key and name properties.

The locales are not merged with templates and only roles defined inside the workspace.locales{} locale object are considered for access.

Parameters:
NameTypeDescription
reqreq

HTTP request.

resres

HTTP response.

Properties
NameTypeAttributesDescription
req.paramsObject

HTTP request params.

params.userObject<optional>

User requesting the locales.

Returns:

The HTTP response with either an error.message or JSON array of locales in workspace.

Type: 
res

(inner) removeRoles(obj) → {object}

Recursively removes all 'roles' objects from the provided object [locale, layer]. This function is designed to sanitize locale configuration objects before sending to the client, ensuring that role-based permissions data is not exposed.

Parameters:
NameTypeDescription
objobject

A locale or layer JSON object.

Returns:
Type: 
object

(inner) roles(req, res) → {Array|Object}

The roles method returns an array of roles returned from the roles utility.

An object with detailed workspace.roles{} can be requested with the detail=true url parameter for the workspace/roles request.

Parameters:
NameTypeDescription
reqreq

HTTP request.

resreq

HTTP response.

Properties
NameTypeDescription
req.paramsObject

HTTP request parameter.

params.detailBoolean

Whether the roles should be returned as an object with details.

Returns:

Returns either an array of roles as string, or an object with roles as properties.

Type: 
Array | Object

(inner) templateUse(obj, test)

Iterates through all nested object properties. Test properties found in the test.properties Set. Removes template keys from test.unused_templates Set. Add template keys to test.used_templates Array.

Parameters:
NameTypeDescription
objObject

The object to test.

testObject

The test config object.

Properties
NameTypeDescription
test.propertiesSet

Set of properties to test ['template', 'templates', 'query']

test.workspace_templatesSet

Set of templates _type=workspace templates.

test.unused_templatesSet

Set of templates not (yet) used.

test.overwritten_templatesSet

Set of _type=workspace templates which have been overwritten.

test.used_templatesArray

Array of template keys for each usage.

(inner) test(req, res)

The workspace/test method which is only available to user with admin credentials requests all locales in workspace.

The cached workspace will be flushed for the test method.

Requesting all locales should add any additional templates to the workspace.

The test method will iterate over all workspace.templates and get from the getTemplate method to check whether any errors are logged on a template in regards to its src parameter.

A flat array of template.err will be returned from the workspace/test method.

Parameters:
NameTypeDescription
reqreq

HTTP request.

resreq

HTTP response.

Properties
NameTypeDescription
req.paramsObject

HTTP request parameter.

params.userObject

The user requesting the test method.

user.adminBoolean

The user is required to have admin priviliges.