Middlewares that you want to compose
hasOneOfPermissions is a middleware generator. It allows you to check on permissions attached in customClaims.
import { isAuth, hasOneOfPermissions, composeMiddlewares } from '@rainbow-cloud-functions/callables';
const callableFunctionFoo = (data, context) => {
// callable function code here.
};
exports.callableFunctionFoo = composeMiddlewares(
isAuth(),
hasOneOfPermissions(['read:book', 'write:book'])
)(callableFunctionFoo);
hasOneOfRoles is a middleware generator. It allows you to check on roles attached in customClaims.
import { isAuth, hasOneOfRoles, composeMiddlewares } from '@rainbow-cloud-functions/callables';
const callableFunctionFoo = (data, context) => {
// callable function code here.
};
exports.callableFunctionFoo = composeMiddlewares(
isAuth(),
hasOneOfRoles(['admin', 'reseller'])
)(callableFunctionFoo);
import { isAuth } from '@rainbow-cloud-functions/callables';
const callableFunctionFoo = (data, context) => {
// callable function code here.
};
exports.callableFunctionFoo = isAuth()(callableFunctionFoo);
import { isAuth } from '@rainbow-cloud-functions/callables';
const callableFunctionFoo = (data, context) => {
// callable function code here.
};
const customError = () => throw new HttpsError('unauthenticated', 'foo');
exports.callableFunctionFoo = isAuth(customError)(callableFunctionFoo);
Allows the customization of the Error thrown.
isValidData is a middleware generator. It allows you to validate the data object param of a callable function using JSON Schema Validator(Ajv).
import { isValidData } from '@rainbow-cloud-functions/callables';
const callableFunctionFoo = (data, context) => {
// callable function code here.
};
const schema = {
type: 'object',
properties: {
name: { type: 'string' },
},
required: ['name'],
};
exports.callableFunctionFoo = isValidData({ schema })(callableFunctionFoo);
import { isValidData } from '@rainbow-cloud-functions/callables';
const callableFunctionFoo = (data, context) => {
// callable function code here.
};
const keywords = [
{
keyword: "isUppercase",
validate: (schema, data) => data.toUpperCase() === data,
}
]
const schema = {
type: 'object',
properties: {
name: {
type: 'string',
isUppercase: true,
},
},
required: ['name'],
};
Generated using TypeDoc
Description
The
compose
function is a middleware generator. This allows you to compose several simple callable middleware to make up a heavier one. Usecompose
to integrate various functionalities into a more complex one.Usage