Skip to content

ManagementExpressContextFactory

type ManagementExpressContextFactory<TContext> = (input) => TContext | Promise<TContext>;

Defined in: management-express/src/types.ts:44

Creates request-specific context for the Management Surface from Express state.

The returned value is passed through to @monque/management as managementContext. Management authorization hooks and payload serializers receive that same value as their context input. If omitted, the Management Surface receives no application context.

Type ParameterDefault typeDescription
TContextunknownApplication-specific context exposed to management hooks.
ParameterType
inputManagementExpressContextInput

TContext | Promise<TContext>

app.use(
	'/monque',
	createManagementExpressRouter<{ userId: string; role: string }>({
		monque,
		context: ({ req }) => ({
			userId: req.get('x-user-id') ?? 'anonymous',
			role: req.get('x-role') ?? 'viewer',
		}),
		authorize: ({ action, context }) => {
			return context.role === 'operator' || action === 'read';
		},
	}),
);