UNPKG

@yext/search-core

Version:

Typescript Networking Library for the Yext Search API

74 lines 3.72 kB
import { Environment } from './models/core/Environment'; import { CloudRegion } from './models/core/CloudRegion'; import { CloudChoice } from './models/core/CloudChoice'; export var defaultApiVersion = 20220511; /** * Provides methods for getting various endpoints. * * @internal */ var EndpointsFactory = /** @class */ (function () { function EndpointsFactory(config) { this.environment = (config === null || config === void 0 ? void 0 : config.environment) || Environment.PROD; this.cloudRegion = (config === null || config === void 0 ? void 0 : config.cloudRegion) || CloudRegion.US; this.cloudChoice = (config === null || config === void 0 ? void 0 : config.cloudChoice) || CloudChoice.GLOBAL_MULTI; } /** Provides the domain based on environment and cloud region. */ EndpointsFactory.prototype.getDomain = function () { if (this.isInternalTestEnvironment() && this.cloudRegion === CloudRegion.US) { return "https://liveapi-".concat(this.environment, ".yext.com"); } switch (this.cloudChoice) { case CloudChoice.GLOBAL_GCP: return "https://".concat(this.environment, "-cdn-gcp.").concat(this.cloudRegion, ".yextapis.com"); case CloudChoice.GLOBAL_MULTI: default: return "https://".concat(this.environment, "-cdn.").concat(this.cloudRegion, ".yextapis.com"); } }; /** Provides the cached domain based on environment and cloud region. */ EndpointsFactory.prototype.getCachedDomain = function () { if (this.isInternalTestEnvironment() && this.cloudRegion === CloudRegion.US) { return "https://liveapi-".concat(this.environment, ".yext.com"); } switch (this.cloudChoice) { case CloudChoice.GLOBAL_GCP: return "https://".concat(this.environment, "-cdn-cached-gcp.").concat(this.cloudRegion, ".yextapis.com"); case CloudChoice.GLOBAL_MULTI: default: return "https://".concat(this.environment, "-cdn-cached.").concat(this.cloudRegion, ".yextapis.com"); } }; /** Provides all endpoints based on environment and cloud region. */ EndpointsFactory.prototype.getEndpoints = function () { return { universalSearch: "".concat(this.getDomain(), "/v2/accounts/me/search/query"), verticalSearch: "".concat(this.getDomain(), "/v2/accounts/me/search/vertical/query"), questionSubmission: "".concat(this.getDomain(), "/v2/accounts/me/createQuestion"), status: 'https://answersstatus.pagescdn.com', universalAutocomplete: "".concat(this.getCachedDomain(), "/v2/accounts/me/search/autocomplete"), verticalAutocomplete: "".concat(this.getCachedDomain(), "/v2/accounts/me/search/vertical/autocomplete"), filterSearch: "".concat(this.getDomain(), "/v2/accounts/me/search/filtersearch"), generativeDirectAnswer: "".concat(this.getDomain(), "/v2/accounts/me/search/generateAnswer"), }; }; EndpointsFactory.prototype.isInternalTestEnvironment = function () { return this.environment === Environment.DEV || this.environment === Environment.QA; }; return EndpointsFactory; }()); export { EndpointsFactory }; /** * The endpoints to use for sandbox experiences. * * @deprecated Set the appropriate environment and cloud region in {@link ServingConfig} instead. * * @public */ export var SandboxEndpoints = new EndpointsFactory({ environment: Environment.SANDBOX, cloudRegion: CloudRegion.US, cloudChoice: CloudChoice.GLOBAL_MULTI }) .getEndpoints(); //# sourceMappingURL=provideEndpoints.js.map