UNPKG

@yext/search-core

Version:

Typescript Networking Library for the Yext Search API

54 lines 2.91 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.QuestionSubmissionServiceImpl = void 0; const provideEndpoints_1 = require("../provideEndpoints"); const getClientSdk_1 = require("../utils/getClientSdk"); /** * An implementation of QuestionSubmissionService which hits LiveAPI. * * @internal */ class QuestionSubmissionServiceImpl { constructor(config, httpService, apiResponseValidator) { this.config = config; this.httpService = httpService; this.apiResponseValidator = apiResponseValidator; this.endpoint = this.config.endpoints.questionSubmission; } submitQuestion(request) { var _a; return __awaiter(this, void 0, void 0, function* () { const queryParams = Object.assign(Object.assign(Object.assign({ v: provideEndpoints_1.defaultApiVersion }, ('apiKey' in this.config && { api_key: this.config.apiKey })), { sessionTrackingEnabled: request.sessionTrackingEnabled }), (_a = this.config) === null || _a === void 0 ? void 0 : _a.additionalQueryParams); const body = { email: request.email, entityId: request.entityId, name: request.name, questionDescription: request.questionDescription, questionLanguage: this.config.locale, questionText: request.questionText, site: 'FIRSTPARTY' }; const response = 'token' in this.config ? yield this.httpService.post(this.endpoint, queryParams, body, (0, getClientSdk_1.getClientSdk)(request.additionalHttpHeaders), this.config.token) : yield this.httpService.post(this.endpoint, queryParams, body, (0, getClientSdk_1.getClientSdk)(request.additionalHttpHeaders)); const validationResult = this.apiResponseValidator.validate(response); if (validationResult instanceof Error) { return Promise.reject(validationResult); } return { uuid: response.meta.uuid }; }); } } exports.QuestionSubmissionServiceImpl = QuestionSubmissionServiceImpl; //# sourceMappingURL=QuestionSubmissionServiceImpl.js.map