balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

index.js (1245B)


      1 import { hasRequiredPlugins } from './hasRequiredPlugins'
      2 import { hasPluginsActivated } from './hasPluginsActivated'
      3 import { check as checkNeedsRegistrationModal } from './NeedsRegistrationModal'
      4 
      5 export const Middleware = (middleware = []) => {
      6     return {
      7         hasRequiredPlugins: hasRequiredPlugins,
      8         hasPluginsActivated: hasPluginsActivated,
      9         NeedsRegistrationModal: checkNeedsRegistrationModal,
     10         stack: [],
     11         async check(template) {
     12             for (const m of middleware) {
     13                 const cb = await this[`${m}`](template)
     14                 setTimeout(() => {
     15                     this.stack.push(cb.pass
     16                         ? cb.allow
     17                         : cb.deny)
     18                 }, 0)
     19             }
     20         },
     21         reset() {
     22             this.stack = []
     23         },
     24     }
     25 }
     26 
     27 export async function AuthorizationCheck(pipes) {
     28     const middleware = MiddlewareGenerator(pipes)
     29     while (true) {
     30         const result = await middleware.next()
     31 
     32         // TODO: Could probably have a check for errors here
     33         if (result.done) {
     34             break
     35         }
     36     }
     37 }
     38 export async function* MiddlewareGenerator(middleware) {
     39     for (const m of middleware) {
     40         yield await m()
     41     }
     42 }