UNPKG

@pagamio/frontend-commons-lib

Version:

Pagamio library for Frontend reusable components like the form engine and table container

33 lines (32 loc) 1.38 kB
import { DefaultAuthenticatorProcessor } from './processors/DefaultAuthenticatorProcessor'; import { StrapiAuthenticatorProcessor } from './processors/StrapiAuthenticatorProcessor'; import { AuthenticatorType } from './types'; /** * Factory class for creating authenticator processors * Maintains a registry of processor implementations and creates instances on demand */ export class AuthenticatorFactory { // Registry of authenticator processor constructors static processors = { [AuthenticatorType.DEFAULT]: DefaultAuthenticatorProcessor, [AuthenticatorType.STRAPI]: StrapiAuthenticatorProcessor, }; /** * Gets an authenticator processor by type * @param type - The type of authenticator to get * @returns An authenticator processor instance */ static getProcessor(type) { // If no type specified or type not found, return the default processor const ProcessorClass = type && this.processors[type] ? this.processors[type] : this.processors[AuthenticatorType.DEFAULT]; return new ProcessorClass(); } /** * Registers a new authenticator processor * @param type - The type identifier for this processor * @param processorClass - The processor class constructor */ static registerProcessor(type, processorClass) { this.processors[type] = processorClass; } }