UNPKG

@atomist/automation-client

Version:
73 lines 2.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const globals_1 = require("../../../globals"); const ApolloGraphClientFactory_1 = require("../../../graph/ApolloGraphClientFactory"); const AbstractRequestProcessor_1 = require("../AbstractRequestProcessor"); const RequestProcessor_1 = require("../RequestProcessor"); const WebSocketMessageClient_1 = require("../websocket/WebSocketMessageClient"); /** * RequestProcessor implementation used by the Express infrastructure to process * inbound events via HTTP REST apis. */ class ExpressRequestProcessor extends AbstractRequestProcessor_1.AbstractRequestProcessor { constructor(automations, configuration, listeners = []) { super(automations, listeners); this.automations = automations; this.configuration = configuration; this.listeners = listeners; this.graphClientFactory = new ApolloGraphClientFactory_1.ApolloGraphClientFactory(this.configuration, () => { if (this.configuration.apiKey) { return `Bearer ${this.configuration.apiKey}`; } else { return `token ${this.configuration.token}`; } }); } sendStatusMessage(payload, ctx) { return Promise.resolve(); } createGraphClient(event, context) { return !!this.configuration.http.graphClientFactory ? this.configuration.http.graphClientFactory(context) : this.graphClientFactory.createGraphClient(event); } createMessageClient(event, context) { return !!this.configuration.http.messageClientFactory ? this.configuration.http.messageClientFactory(context) : new ExpressMessageClient(event); } } exports.ExpressRequestProcessor = ExpressRequestProcessor; class ExpressMessageClient { constructor(event) { this.event = event; if (globals_1.automationClientInstance().webSocketHandler && globals_1.automationClientInstance().webSocketHandler.webSocket) { const ws = globals_1.automationClientInstance().webSocketHandler.webSocket; if (RequestProcessor_1.isCommandIncoming(this.event)) { this.delegate = new WebSocketMessageClient_1.WebSocketCommandMessageClient(this.event, ws); } else if (RequestProcessor_1.isEventIncoming(this.event)) { this.delegate = new WebSocketMessageClient_1.WebSocketEventMessageClient(this.event, ws); } } } respond(msg, options) { if (this.delegate) { return this.delegate.respond(msg, options); } else { return Promise.resolve(); } } send(msg, destinations, options) { if (this.delegate) { return this.delegate.send(msg, destinations, options); } else { return Promise.resolve(); } } } //# sourceMappingURL=ExpressRequestProcessor.js.map