import { merchantAuthService } from './controller/MerchantAuthController'; // import { glueSchemaController } from './controller/GlueSchemaController'; import { sendEventController, } from './controller/RudderStackController'; import { EventInputType } from './models'; import { Environment, EventsTrackerInit } from './models/schemas/types'; export default class EventsManager { // Properties merchant = ''; sessionLocal = false; env = 'staging' as Environment; userIdLocal = ''; sourceLocal = ''; /** * Method that allow 'instance' and object and makes an merchant id validation, validate and * retrieve their info like, id, country, name * @param apiKey * @param userId * @param source * @param environment */ constructor({ apiKey, userId, source, environment = 'staging' }: EventsTrackerInit) { this.merchant = apiKey; this.sessionLocal = false; this.env = environment as Environment; this.userIdLocal = userId; this.sourceLocal = source; merchantAuthService(apiKey, environment as Environment).then(auth => { if (auth?.id !== undefined) { this.sessionLocal = true; } }); } /** * Method that allow to a user 'authenticated' send events to rudderstack * @param eventName Event name that identified to the event * @param event Object that keeps all the transaction data */ sendEvent(event: EventInputType) { if (this.sessionLocal) { const nameObject = Object.keys(event).slice(0); sendEventController( 'track', this.userIdLocal, nameObject[0], event, this.sourceLocal, this.env ); } } // Getter methods isDeUnaIntegration() { return (this.sessionLocal = true); } hasSession() { return this.sessionLocal; } getApiKey() { return this.merchant; } // buildEvents() { // glueSchemaController() // } }