UNPKG

@yext/search-core

Version:

Typescript Networking Library for the Yext Search API

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