diff --git a/docs/analytics.enumorstring.md b/docs/analytics.enumorstring.md index 62cb3dd7..ceae0335 100644 --- a/docs/analytics.enumorstring.md +++ b/docs/analytics.enumorstring.md @@ -16,3 +16,4 @@ export type EnumOrString = T | `${T}`; Allows interfaces to support both enums and strings. + diff --git a/docs/analytics.environment.md b/docs/analytics.environment.md index f6c94adc..05ec14fa 100644 --- a/docs/analytics.environment.md +++ b/docs/analytics.environment.md @@ -9,9 +9,8 @@ The Yext Environments **Signature:** ```typescript -export type Environment = EnumOrString; +export type Environment = 'PRODUCTION' | 'SANDBOX'; ``` -**References:** [EnumOrString](./analytics.enumorstring.md), [EnvironmentEnum](./analytics.environmentenum.md) ## Remarks diff --git a/docs/analytics.environmentenum.md b/docs/analytics.environmentenum.md deleted file mode 100644 index f7e70792..00000000 --- a/docs/analytics.environmentenum.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [@yext/analytics](./analytics.md) > [EnvironmentEnum](./analytics.environmentenum.md) - -## EnvironmentEnum enum - -An enum for the Yext Environments - -**Signature:** - -```typescript -export declare enum EnvironmentEnum -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| Production | "PRODUCTION" | | -| Sandbox | "SANDBOX" | unsupported in the EU region | - -## Remarks - -Affects the domain the requests are sent to. - diff --git a/docs/analytics.md b/docs/analytics.md index a5a290ea..9865c365 100644 --- a/docs/analytics.md +++ b/docs/analytics.md @@ -4,14 +4,6 @@ ## analytics package -## Enumerations - -| Enumeration | Description | -| --- | --- | -| [EnvironmentEnum](./analytics.environmentenum.md) | An enum for the Yext Environments | -| [RegionEnum](./analytics.regionenum.md) | An enum of the physical region the Yext account | -| [VersionLabelEnum](./analytics.versionlabelenum.md) | An enum for the Search Version Labels | - ## Functions | Function | Description | @@ -32,8 +24,7 @@ | Type Alias | Description | | --- | --- | | [Action](./analytics.action.md) | The action types accepted by the Analytics Events API. | -| [EnumOrString](./analytics.enumorstring.md) | A TypeScript utility type which creates a union of an enum member and its string representation. | | [Environment](./analytics.environment.md) | The Yext Environments | | [Region](./analytics.region.md) | The physical region of the Yext account | -| [VersionLabel](./analytics.versionlabel.md) | The Search Version Label | +| [VersionLabel](./analytics.versionlabel.md) | An enum for the Search Version Labels | diff --git a/docs/analytics.partialpayload.md b/docs/analytics.partialpayload.md new file mode 100644 index 00000000..9f359c4c --- /dev/null +++ b/docs/analytics.partialpayload.md @@ -0,0 +1,16 @@ + + +[Home](./index.md) > [@yext/analytics](./analytics.md) > [PartialPayload](./analytics.partialpayload.md) + +## PartialPayload type + +A Payload that is a subset of the EventPayload + +**Signature:** + +```typescript +export type PartialPayload = Partial>; +``` +**References:** [EventPayload](./analytics.eventpayload.md) + + diff --git a/docs/analytics.region.md b/docs/analytics.region.md index 99d6f086..f643d969 100644 --- a/docs/analytics.region.md +++ b/docs/analytics.region.md @@ -9,9 +9,8 @@ The physical region of the Yext account **Signature:** ```typescript -export type Region = EnumOrString; +export type Region = 'us' | 'eu'; ``` -**References:** [EnumOrString](./analytics.enumorstring.md), [RegionEnum](./analytics.regionenum.md) ## Remarks diff --git a/docs/analytics.regionenum.md b/docs/analytics.regionenum.md deleted file mode 100644 index 2476066b..00000000 --- a/docs/analytics.regionenum.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [@yext/analytics](./analytics.md) > [RegionEnum](./analytics.regionenum.md) - -## RegionEnum enum - -An enum of the physical region the Yext account - -**Signature:** - -```typescript -export declare enum RegionEnum -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| EU | "eu" | | -| US | "us" | | - -## Remarks - -Affects the domain the requests are sent to. - diff --git a/docs/analytics.versionlabel.md b/docs/analytics.versionlabel.md index f4eb2945..6d8bfa36 100644 --- a/docs/analytics.versionlabel.md +++ b/docs/analytics.versionlabel.md @@ -4,14 +4,13 @@ ## VersionLabel type -The Search Version Label +An enum for the Search Version Labels **Signature:** ```typescript -export type VersionLabel = EnumOrString; +export type VersionLabel = 'PRODUCTION' | 'STAGING'; ``` -**References:** [EnumOrString](./analytics.enumorstring.md), [VersionLabelEnum](./analytics.versionlabelenum.md) ## Remarks diff --git a/docs/analytics.versionlabelenum.md b/docs/analytics.versionlabelenum.md deleted file mode 100644 index 0b4a3911..00000000 --- a/docs/analytics.versionlabelenum.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [@yext/analytics](./analytics.md) > [VersionLabelEnum](./analytics.versionlabelenum.md) - -## VersionLabelEnum enum - -An enum for the Search Version Labels - -**Signature:** - -```typescript -export declare enum VersionLabelEnum -``` - -## Enumeration Members - -| Member | Value | Description | -| --- | --- | --- | -| Production | "PRODUCTION" | | -| Staging | "STAGING" | | - -## Remarks - -Affects the contents of the versionLabel field in the search object field in the event payload. - diff --git a/etc/analytics.api.md b/etc/analytics.api.md index 95dd4d58..e302b181 100644 --- a/etc/analytics.api.md +++ b/etc/analytics.api.md @@ -27,17 +27,7 @@ export interface AnalyticsEventService { } // @public -export type EnumOrString = T | `${T}`; - -// @public -export type Environment = EnumOrString; - -// @public -export enum EnvironmentEnum { - // (undocumented) - Production = "PRODUCTION", - Sandbox = "SANDBOX" -} +export type Environment = 'PRODUCTION' | 'SANDBOX'; // @public export interface EventPayload { @@ -100,29 +90,13 @@ export interface EventPayload { } // @public -export type Region = EnumOrString; - -// @public -export enum RegionEnum { - // (undocumented) - EU = "eu", - // (undocumented) - US = "us" -} +export type Region = 'us' | 'eu'; // @public export function reportBrowserAnalytics(): Promise; // @public -export type VersionLabel = EnumOrString; - -// @public -export enum VersionLabelEnum { - // (undocumented) - Production = "PRODUCTION", - // (undocumented) - Staging = "STAGING" -} +export type VersionLabel = 'PRODUCTION' | 'STAGING'; // (No @packageDocumentation comment for this package) diff --git a/src/EnumOrString.ts b/src/EnumOrString.ts deleted file mode 100644 index 43a038e3..00000000 --- a/src/EnumOrString.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * A TypeScript utility type which creates a union of an enum member and its string representation. - * - * @remarks - * Allows interfaces to support both enums and strings. - * - * @public - */ -export type EnumOrString = T | `${T}`; diff --git a/src/Environment.ts b/src/Environment.ts index f34e58fc..ce4be59e 100644 --- a/src/Environment.ts +++ b/src/Environment.ts @@ -1,18 +1,3 @@ -import { EnumOrString } from './EnumOrString'; -/** - * An enum for the Yext Environments - * - * @remarks - * Affects the domain the requests are sent to. - * - * @public - */ -export enum EnvironmentEnum { - Production = 'PRODUCTION', - /** unsupported in the EU region */ - Sandbox = 'SANDBOX' -} - /** * The Yext Environments * @@ -21,4 +6,4 @@ export enum EnvironmentEnum { * * @public */ -export type Environment = EnumOrString; +export type Environment = 'PRODUCTION' | 'SANDBOX'; diff --git a/src/Region.ts b/src/Region.ts index 5cfde3f8..9a66e857 100644 --- a/src/Region.ts +++ b/src/Region.ts @@ -1,17 +1,3 @@ -import { EnumOrString } from './EnumOrString'; -/** - * An enum of the physical region the Yext account - * - * @remarks - * Affects the domain the requests are sent to. - * - * @public - */ -export enum RegionEnum { - US = 'us', - EU = 'eu' -} - /** * The physical region of the Yext account * @@ -20,4 +6,5 @@ export enum RegionEnum { * * @public */ -export type Region = EnumOrString; + +export type Region = 'us' | 'eu'; diff --git a/src/VersionLabel.ts b/src/VersionLabel.ts index 4cddfd2f..eca5ddac 100644 --- a/src/VersionLabel.ts +++ b/src/VersionLabel.ts @@ -1,5 +1,3 @@ -import { EnumOrString } from './EnumOrString'; - /** * An enum for the Search Version Labels * @@ -8,17 +6,4 @@ import { EnumOrString } from './EnumOrString'; * * @public */ -export enum VersionLabelEnum { - Production = 'PRODUCTION', - Staging = 'STAGING' -} - -/** - * The Search Version Label - * - * @remarks - * Affects the contents of the versionLabel field in the search object field in the event payload. - * - * @public - */ -export type VersionLabel = EnumOrString; +export type VersionLabel = 'PRODUCTION' | 'STAGING'; diff --git a/src/index.ts b/src/index.ts index b2fa8fd2..0edd6cb8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,6 @@ export * from './AnalyticsEventService'; export * from './Environment'; export * from './Region'; export * from './EventPayload'; -export * from './EnumOrString'; export * from './Action'; export * from './VersionLabel'; diff --git a/src/setupRequestUrl.ts b/src/setupRequestUrl.ts index 8495f80d..1e57b09d 100644 --- a/src/setupRequestUrl.ts +++ b/src/setupRequestUrl.ts @@ -1,17 +1,14 @@ -import { Environment, EnvironmentEnum } from './Environment'; -import { Region, RegionEnum } from './Region'; +import { Environment } from './Environment'; +import { Region } from './Region'; const urlBase = 'yextevents.com/accounts/me/events'; export function setupRequestUrl(env?: Environment, region?: Region): string { - if (env === EnvironmentEnum.Sandbox && region === RegionEnum.EU) { + const isSandbox = env === 'SANDBOX'; + if (isSandbox && region === 'eu') { throw new Error('Sandbox environment is not available in the EU region.'); } return ( - 'https://' + - (env === EnvironmentEnum.Sandbox ? 'sbx.' : '') + - (region ?? 'us') + - '.' + - urlBase + 'https://' + (isSandbox ? 'sbx.' : '') + (region ?? 'us') + '.' + urlBase ); } diff --git a/tests/AnalyticsEventReporter.test.ts b/tests/AnalyticsEventReporter.test.ts index 1f88fba6..a5012732 100644 --- a/tests/AnalyticsEventReporter.test.ts +++ b/tests/AnalyticsEventReporter.test.ts @@ -1,8 +1,6 @@ import { AnalyticsConfig } from '../src/AnalyticsConfig'; import { AnalyticsEventReporter } from '../src/AnalyticsEventReporter'; -import { RegionEnum } from '../src/Region'; import { postWithBeacon, postWithFetch, useBeacon } from '../src/post'; -import { EnvironmentEnum } from '../src/Environment'; import { getOrSetupSessionId } from '../src/setupSessionId'; import { AnalyticsEventService } from '../src/AnalyticsEventService'; @@ -96,7 +94,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'apiKey', authorization: 'validKey', - region: RegionEnum.EU, + region: 'eu', forceFetch: false }; const reporter = new AnalyticsEventReporter(config).with({ @@ -139,7 +137,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'bearer', authorization: 'bearerToken', - env: EnvironmentEnum.Sandbox + env: 'SANDBOX' }; const reporter = new AnalyticsEventReporter(config).with({ action: 'c_lowercase_custom_action', @@ -354,7 +352,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'apiKey', authorization: 'validKey', - region: RegionEnum.EU, + region: 'eu', forceFetch: false }; const reporter = new AnalyticsEventReporter(config).with({ @@ -400,7 +398,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'apiKey', authorization: 'validKey', - region: RegionEnum.EU, + region: 'eu', forceFetch: false }; @@ -448,7 +446,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'apiKey', authorization: 'validKey', - region: RegionEnum.EU, + region: 'eu', forceFetch: true }; @@ -486,7 +484,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'apiKey', authorization: 'validKey', - region: RegionEnum.EU, + region: 'eu', forceFetch: false }; @@ -525,7 +523,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'apiKey', authorization: 'validKey', - region: RegionEnum.EU, + region: 'eu', forceFetch: false }; @@ -601,7 +599,7 @@ describe('Test report function', () => { const config: AnalyticsConfig = { authorizationType: 'apiKey', authorization: 'validKey', - region: RegionEnum.EU, + region: 'eu', forceFetch: false, sessionTrackingEnabled: true }; @@ -657,7 +655,7 @@ describe('Test report function', () => { }, searchTerm: 'searchTerm', sessionId: 'sessionId', - sites: { + pages: { siteUid: 321, template: 'template' }, @@ -736,7 +734,7 @@ describe('Test report function', () => { }, searchTerm: 'searchTerm', sessionId: 'sessionId', - sites: { + pages: { siteUid: 321, template: 'template' }, diff --git a/tests/setupRequestUrl.test.ts b/tests/setupRequestUrl.test.ts index 9534f25c..d0cf805b 100644 --- a/tests/setupRequestUrl.test.ts +++ b/tests/setupRequestUrl.test.ts @@ -1,69 +1,28 @@ -import { EnvironmentEnum } from '../src/Environment'; -import { RegionEnum } from '../src/Region'; import { setupRequestUrl } from '../src/setupRequestUrl'; describe('setUpRequestUrl Test', () => { - it('should set url correctly for env: prod, region: us using their Enums', () => { - const resultUrl = setupRequestUrl( - EnvironmentEnum.Production, - RegionEnum.US - ); - const expectedUrl = 'https://us.yextevents.com/accounts/me/events'; - - expect(resultUrl).toEqual(expectedUrl); - }); - - it('should set url correctly for env: prod, region: us using their string literals', () => { + it('should set url correctly for env: prod, region: us', () => { const resultUrl = setupRequestUrl('PRODUCTION', 'us'); const expectedUrl = 'https://us.yextevents.com/accounts/me/events'; expect(resultUrl).toEqual(expectedUrl); }); - it('should set url correctly for env: prod, region: eu using their Enums', () => { - const resultUrl = setupRequestUrl( - EnvironmentEnum.Production, - RegionEnum.EU - ); - const expectedUrl = 'https://eu.yextevents.com/accounts/me/events'; - - expect(resultUrl).toEqual(expectedUrl); - }); - - it('should set url correctly for env: prod, region: eu using their string literals', () => { + it('should set url correctly for env: prod, region: eu', () => { const resultUrl = setupRequestUrl('PRODUCTION', 'eu'); const expectedUrl = 'https://eu.yextevents.com/accounts/me/events'; expect(resultUrl).toEqual(expectedUrl); }); - it('should set url correctly for env: sbx, region: us using their Enums', () => { - const resultUrl = setupRequestUrl(EnvironmentEnum.Sandbox, RegionEnum.US); - const expectedUrl = 'https://sbx.us.yextevents.com/accounts/me/events'; - - expect(resultUrl).toEqual(expectedUrl); - }); - - it('should set url correctly for env: sbx, region: us using their string literals', () => { + it('should set url correctly for env: sbx, region: us', () => { const resultUrl = setupRequestUrl('SANDBOX', 'us'); const expectedUrl = 'https://sbx.us.yextevents.com/accounts/me/events'; expect(resultUrl).toEqual(expectedUrl); }); - it('should throw error for env: sbx, region: eu using their Enums', () => { - try { - setupRequestUrl(EnvironmentEnum.Sandbox, RegionEnum.EU); - // Fail test if above expression doesn't throw anything. - expect(true).toBe(false); - } catch (e) { - expect(e.message).toBe( - 'Sandbox environment is not available in the EU region.' - ); - } - }); - - it('should throw error for env: sbx, region: eu using their string literals', () => { + it('should throw error for env: sbx, region: eu', () => { try { setupRequestUrl('SANDBOX', 'eu'); // Fail test if above expression doesn't throw anything. @@ -82,28 +41,14 @@ describe('setUpRequestUrl Test', () => { expect(resultUrl).toEqual(expectedUrl); }); - it('should set url correctly with no env argument passed in using its Enum', () => { - const resultUrl = setupRequestUrl(undefined, RegionEnum.EU); - const expectedUrl = 'https://eu.yextevents.com/accounts/me/events'; - - expect(resultUrl).toEqual(expectedUrl); - }); - - it('should set url correctly with no env argument passed in using their string literals', () => { + it('should set url correctly with no env argument passed in', () => { const resultUrl = setupRequestUrl(undefined, 'eu'); const expectedUrl = 'https://eu.yextevents.com/accounts/me/events'; expect(resultUrl).toEqual(expectedUrl); }); - it('should set url correctly with no region argument passed in using its Enum', () => { - const resultUrl = setupRequestUrl(EnvironmentEnum.Sandbox, undefined); - const expectedUrl = 'https://sbx.us.yextevents.com/accounts/me/events'; - - expect(resultUrl).toEqual(expectedUrl); - }); - - it('should set url correctly with no region argument passed in using their string literals', () => { + it('should set url correctly with no region argument passed in', () => { const resultUrl = setupRequestUrl('SANDBOX', undefined); const expectedUrl = 'https://sbx.us.yextevents.com/accounts/me/events';