2023-03-24 21:08:36 +00:00
|
|
|
import { InputMessage, OutputMessage, Policy } from './types.ts';
|
2023-03-24 19:36:11 +00:00
|
|
|
|
2023-03-24 21:08:36 +00:00
|
|
|
/** Processes messages through multiple policies, bailing early on rejection. */
|
|
|
|
async function pipeline(msg: InputMessage, policies: Policy[]): Promise<OutputMessage> {
|
|
|
|
for (const policy of policies) {
|
|
|
|
const result = await policy(msg);
|
|
|
|
if (result.action !== 'accept') {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: msg.event.id,
|
|
|
|
action: 'accept',
|
|
|
|
msg: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default pipeline;
|