-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support env, region, and endpoints (#16)
updated config to expose env, region and endpoints field to customize/override the default URLs to make requests to. J=CLIP-288 TEST=manual&auto see that chat endpoint works with clippy EU prod and US dev account using test-site. see that jest tests passed
- Loading branch information
Showing
29 changed files
with
440 additions
and
96 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [ChatConfig](./chat-core.chatconfig.md) > [endpoints](./chat-core.chatconfig.endpoints.md) | ||
|
||
## ChatConfig.endpoints property | ||
|
||
Overrides for the URLs which are used when making requests to the Chat API. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
endpoints?: Endpoints; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [ChatConfig](./chat-core.chatconfig.md) > [env](./chat-core.chatconfig.env.md) | ||
|
||
## ChatConfig.env property | ||
|
||
Defines the environment of the API domains. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
env?: EnumOrLiteral<Environment>; | ||
``` | ||
|
||
## Remarks | ||
|
||
Default to PROD. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [ChatConfig](./chat-core.chatconfig.md) > [region](./chat-core.chatconfig.region.md) | ||
|
||
## ChatConfig.region property | ||
|
||
The region to send the requests to. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
region?: EnumOrLiteral<Region>; | ||
``` | ||
|
||
## Remarks | ||
|
||
Defaults to 'US'. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [Endpoints](./chat-core.endpoints.md) > [chat](./chat-core.endpoints.chat.md) | ||
|
||
## Endpoints.chat property | ||
|
||
Chat API endpoint. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
chat: string; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [Endpoints](./chat-core.endpoints.md) > [chatStream](./chat-core.endpoints.chatstream.md) | ||
|
||
## Endpoints.chatStream property | ||
|
||
Chat streaming API endpoint. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
chatStream: string; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [Endpoints](./chat-core.endpoints.md) | ||
|
||
## Endpoints interface | ||
|
||
The URLs which are used when making requests to the Chat API. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
export interface Endpoints | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [chat](./chat-core.endpoints.chat.md) | | string | Chat API endpoint. | | ||
| [chatStream](./chat-core.endpoints.chatstream.md) | | string | Chat streaming API endpoint. | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [Environment](./chat-core.environment.md) | ||
|
||
## Environment enum | ||
|
||
Defines the environment of the API domains. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
export declare enum Environment | ||
``` | ||
|
||
## Enumeration Members | ||
|
||
| Member | Value | Description | | ||
| --- | --- | --- | | ||
| PROD | <code>"prod"</code> | | | ||
| SANDBOX | <code>"sbx"</code> | | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@yext/chat-core](./chat-core.md) > [Region](./chat-core.region.md) | ||
|
||
## Region enum | ||
|
||
The region to send the requests to. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
export declare enum Region | ||
``` | ||
|
||
## Enumeration Members | ||
|
||
| Member | Value | Description | | ||
| --- | --- | --- | | ||
| EU | <code>"eu"</code> | | | ||
| US | <code>"us"</code> | | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export const defaultApiVersion = 20230101; | ||
export const defaultApiDomain = "liveapi.yext.com"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Region } from "../models/endpoints/Region"; | ||
import { EndpointConfig } from "../models/endpoints/EndpointConfig"; | ||
import { Endpoints } from "../models/endpoints/Endpoints"; | ||
import { Environment } from "../models/endpoints/Environment"; | ||
|
||
/** | ||
* Provides methods for getting various endpoints. | ||
* | ||
* @internal | ||
*/ | ||
export class EndpointsFactory { | ||
private static getDomain(endpointConfig: EndpointConfig): string { | ||
const { region = Region.US, env = Environment.PROD } = endpointConfig; | ||
switch (region) { | ||
case Region.US: | ||
return env === Environment.PROD | ||
? "liveapi.yext.com" | ||
: `liveapi-${env}.yext.com`; | ||
case Region.EU: | ||
if (env === Environment.PROD) { | ||
return "cdn.eu.yextapis.com"; | ||
} | ||
throw new Error( | ||
`Unsupported domain: invalid environment "${env}" for region EU` | ||
); | ||
default: | ||
throw new Error(`Unsupported domain: unknown region "${region}"`); | ||
} | ||
} | ||
|
||
public static getEndpoints(endpointConfig: EndpointConfig): Endpoints { | ||
const { businessId, botId } = endpointConfig; | ||
const domain = this.getDomain(endpointConfig); | ||
return { | ||
chat: `https://${domain}/v2/accounts/${ | ||
businessId || "me" | ||
}/chat/${botId}/message`, | ||
chatStream: `https://${domain}/v2/accounts/${ | ||
businessId || "me" | ||
}/chat/${botId}/message/streaming`, | ||
}; | ||
} | ||
} |
Oops, something went wrong.