diff --git a/packages/analytics-browser/src/config.ts b/packages/analytics-browser/src/config.ts index 7440f5c31..c47bc289a 100644 --- a/packages/analytics-browser/src/config.ts +++ b/packages/analytics-browser/src/config.ts @@ -3,7 +3,7 @@ import { BrowserOptions, BrowserConfig as IBrowserConfig, DefaultTrackingOptions, - Diagnostic as IDiagnostic, + Diagnostic, Storage, TrackingOptions, TransportType, @@ -27,7 +27,7 @@ import { parseLegacyCookies } from './cookie-migration'; import { CookieOptions } from '@amplitude/analytics-types/lib/esm/config/browser'; import { DEFAULT_IDENTITY_STORAGE, DEFAULT_SERVER_ZONE } from './constants'; import { AmplitudeBrowser } from './browser-client'; -import { Diagnostic } from './diagnostics/diagnostic'; +import { BrowserDiagnostic } from './diagnostics/diagnostic'; // Exported for testing purposes only. Do not expose to public interface. export class BrowserConfig extends Config implements IBrowserConfig { @@ -78,7 +78,7 @@ export class BrowserConfig extends Config implements IBrowserConfig { }, public transport: 'fetch' | 'xhr' | 'beacon' = 'fetch', public useBatch: boolean = false, - public diagnosticProvider: IDiagnostic | DiagnosticOptions = new Diagnostic(), + public diagnosticProvider: Diagnostic | DiagnosticOptions = new BrowserDiagnostic(), userId?: string, ) { super({ apiKey, storageProvider, transportProvider: createTransport(transport) }); diff --git a/packages/analytics-browser/src/diagnostics/diagnostic.ts b/packages/analytics-browser/src/diagnostics/diagnostic.ts index 315799c93..223044313 100644 --- a/packages/analytics-browser/src/diagnostics/diagnostic.ts +++ b/packages/analytics-browser/src/diagnostics/diagnostic.ts @@ -1,6 +1,6 @@ -import { Diagnostic as CoreDiagnostic } from '@amplitude/analytics-core'; +import { BaseDiagnostic } from '@amplitude/analytics-core'; -export class Diagnostic extends CoreDiagnostic { +export class BrowserDiagnostic extends BaseDiagnostic { async flush(): Promise { await fetch(this.serverUrl, this.requestPayloadBuilder(this.queue)); await super.flush(); diff --git a/packages/analytics-core/src/config.ts b/packages/analytics-core/src/config.ts index e6737aa83..565f64556 100644 --- a/packages/analytics-core/src/config.ts +++ b/packages/analytics-core/src/config.ts @@ -1,7 +1,7 @@ import { Event, Config as IConfig, - Diagnostic as IDiagnostic, + Diagnostic, DiagnosticOptions, Logger as ILogger, LogLevel, @@ -20,7 +20,7 @@ import { } from './constants'; import { Logger } from './logger'; -import { Diagnostic } from './diagnostics/diagnostic'; +import { BaseDiagnostic } from './diagnostics/diagnostic'; export const getDefaultConfig = () => ({ flushMaxRetries: 12, @@ -33,7 +33,7 @@ export const getDefaultConfig = () => ({ serverUrl: AMPLITUDE_SERVER_URL, serverZone: 'US' as ServerZoneType, useBatch: false, - diagnosticProvider: new Diagnostic(), + diagnosticProvider: new BaseDiagnostic(), }); export class Config implements IConfig { @@ -52,7 +52,7 @@ export class Config implements IConfig { transportProvider: Transport; storageProvider?: Storage; useBatch: boolean; - diagnosticProvider: IDiagnostic | DiagnosticOptions; + diagnosticProvider: Diagnostic | DiagnosticOptions; protected _optOut = false; get optOut() { @@ -83,10 +83,10 @@ export class Config implements IConfig { if (options.diagnosticProvider == undefined) { this.diagnosticProvider = defaultConfig.diagnosticProvider; - } else if (options.diagnosticProvider instanceof Diagnostic) { + } else if (options.diagnosticProvider instanceof BaseDiagnostic) { this.diagnosticProvider = options.diagnosticProvider; } else { - this.diagnosticProvider = new Diagnostic(options.diagnosticProvider as DiagnosticOptions); + this.diagnosticProvider = new BaseDiagnostic(options.diagnosticProvider as DiagnosticOptions); } this.diagnosticProvider.apiKey = this.apiKey; diff --git a/packages/analytics-core/src/diagnostics/diagnostic.ts b/packages/analytics-core/src/diagnostics/diagnostic.ts index acc488ec2..76a5c1a2d 100644 --- a/packages/analytics-core/src/diagnostics/diagnostic.ts +++ b/packages/analytics-core/src/diagnostics/diagnostic.ts @@ -1,9 +1,9 @@ -import { Diagnostic as IDiagnostic, DiagnosticOptions } from '@amplitude/analytics-types'; +import { Diagnostic, DiagnosticOptions } from '@amplitude/analytics-types'; import { DIAGNOSTIC_ENDPOINT } from '../constants'; import { DiagnosticEvent } from './typings'; import { DIAGNOSTIC_METADATA_TYPE } from './constants'; -export class Diagnostic implements IDiagnostic { +export class BaseDiagnostic implements Diagnostic { isDisabled = false; serverUrl: string = DIAGNOSTIC_ENDPOINT; apiKey?: string = ''; diff --git a/packages/analytics-core/src/index.ts b/packages/analytics-core/src/index.ts index 052283a19..ce714d81c 100644 --- a/packages/analytics-core/src/index.ts +++ b/packages/analytics-core/src/index.ts @@ -2,7 +2,7 @@ export { AmplitudeCore } from './core-client'; export { Identify } from './identify'; export { Revenue } from './revenue'; export { Destination } from './plugins/destination'; -export { Diagnostic } from './diagnostics/diagnostic'; +export { BaseDiagnostic } from './diagnostics/diagnostic'; export { EXCEEDED_MAX_RETRY_DIAGNOSTIC_MESSAGE, MISSING_API_KEY_DIAGNOSTIC_MESSAGE, diff --git a/packages/analytics-core/test/config.test.ts b/packages/analytics-core/test/config.test.ts index 2e4d50c26..9f00a4acc 100644 --- a/packages/analytics-core/test/config.test.ts +++ b/packages/analytics-core/test/config.test.ts @@ -8,7 +8,7 @@ import { import { Config, createServerConfig, getServerUrl } from '../src/config'; import { Logger } from '../src/logger'; import { API_KEY, useDefaultConfig } from './helpers/default'; -import { Diagnostic } from '../src/diagnostics/diagnostic'; +import { BaseDiagnostic } from '../src/diagnostics/diagnostic'; describe('config', () => { test('should create default config', () => { @@ -79,13 +79,13 @@ describe('config', () => { storageProvider: defaultConfig.storageProvider, transportProvider: defaultConfig.transportProvider, useBatch: true, - diagnosticProvider: new Diagnostic({ isDisabled: true, apiKey: API_KEY }), + diagnosticProvider: new BaseDiagnostic({ isDisabled: true, apiKey: API_KEY }), }); }); test('should overwirte diagnostic provider', () => { const defaultConfig = useDefaultConfig(); - const diagnosticProvider = new Diagnostic({ isDisabled: true }); + const diagnosticProvider = new BaseDiagnostic({ isDisabled: true }); const config = new Config({ apiKey: API_KEY, storageProvider: defaultConfig.storageProvider, diff --git a/packages/analytics-core/test/diagnostic.test.ts b/packages/analytics-core/test/diagnostic.test.ts index b71463f5a..517eda347 100644 --- a/packages/analytics-core/test/diagnostic.test.ts +++ b/packages/analytics-core/test/diagnostic.test.ts @@ -1,16 +1,16 @@ import { DIAGNOSTIC_ENDPOINT } from '../src/constants'; -import { Diagnostic } from '../src/diagnostics/diagnostic'; +import { BaseDiagnostic } from '../src/diagnostics/diagnostic'; jest.useFakeTimers(); describe('Diagnostic', () => { - let diagnostic: Diagnostic; + let diagnostic: BaseDiagnostic; const eventCount = 5; const code = 200; const delay = 60000; beforeEach(() => { - diagnostic = new Diagnostic(); + diagnostic = new BaseDiagnostic(); }); afterEach(() => { @@ -25,14 +25,14 @@ describe('Diagnostic', () => { test('should set isDisabled to provided value', () => { const isDisabled = true; - diagnostic = new Diagnostic({ isDisabled }); + diagnostic = new BaseDiagnostic({ isDisabled }); expect(diagnostic.serverUrl).toBe(DIAGNOSTIC_ENDPOINT); expect(diagnostic.isDisabled).toBe(isDisabled); }); test('should set serverUrl to provided value', () => { const serverUrl = 'https://test.com'; - diagnostic = new Diagnostic({ serverUrl }); + diagnostic = new BaseDiagnostic({ serverUrl }); expect(diagnostic.serverUrl).toBe(serverUrl); expect(diagnostic.isDisabled).toBe(false); }); diff --git a/packages/analytics-core/test/index.test.ts b/packages/analytics-core/test/index.test.ts index 4cfceafa7..e61d64e03 100644 --- a/packages/analytics-core/test/index.test.ts +++ b/packages/analytics-core/test/index.test.ts @@ -14,7 +14,7 @@ import { UUID, MemoryStorage, createIdentifyEvent, - Diagnostic, + BaseDiagnostic, buildResult, EXCEEDED_MAX_RETRY_DIAGNOSTIC_MESSAGE, MISSING_API_KEY_DIAGNOSTIC_MESSAGE, @@ -40,7 +40,7 @@ describe('index', () => { expect(typeof client.remove).toBe('function'); expect(typeof BaseTransport).toBe('function'); expect(typeof Destination).toBe('function'); - expect(typeof Diagnostic).toBe('function'); + expect(typeof BaseDiagnostic).toBe('function'); expect(typeof Config).toBe('function'); expect(typeof Logger).toBe('function'); expect(typeof returnWrapper).toBe('function'); diff --git a/packages/analytics-core/test/plugins/destination.test.ts b/packages/analytics-core/test/plugins/destination.test.ts index 3494542a1..70daa54b7 100644 --- a/packages/analytics-core/test/plugins/destination.test.ts +++ b/packages/analytics-core/test/plugins/destination.test.ts @@ -1,13 +1,5 @@ import { Destination, getResponseBodyString } from '../../src/plugins/destination'; -import { - Config, - DestinationContext, - Logger, - Payload, - Result, - Status, - Diagnostic as IDiagnostic, -} from '@amplitude/analytics-types'; +import { Config, DestinationContext, Logger, Payload, Result, Status, Diagnostic } from '@amplitude/analytics-types'; import { API_KEY, useDefaultConfig } from '../helpers/default'; import { INVALID_API_KEY, @@ -24,12 +16,12 @@ import { } from '../../src/diagnostics/constants'; const jsons = (obj: any) => JSON.stringify(obj, null, 2); -class Diagnostic implements IDiagnostic { +class TestDiagnostic implements Diagnostic { track = jest.fn(); isDisabled = false; serverUrl = 'test'; } -const diagnosticProvider = new Diagnostic(); +const diagnosticProvider = new TestDiagnostic(); describe('destination', () => { afterEach(() => { diff --git a/packages/analytics-node/test/config.test.ts b/packages/analytics-node/test/config.test.ts index d3231ab6a..0a9852bd8 100644 --- a/packages/analytics-node/test/config.test.ts +++ b/packages/analytics-node/test/config.test.ts @@ -27,7 +27,7 @@ describe('config', () => { storageProvider: undefined, transportProvider: new Http(), useBatch: false, - diagnosticProvider: new core.Diagnostic({ apiKey: API_KEY }), + diagnosticProvider: new core.BaseDiagnostic({ apiKey: API_KEY }), }); }); }); @@ -57,7 +57,7 @@ describe('config', () => { transportProvider: new Http(), userId: undefined, useBatch: false, - diagnosticProvider: new core.Diagnostic({ apiKey: API_KEY }), + diagnosticProvider: new core.BaseDiagnostic({ apiKey: API_KEY }), }); }); }); diff --git a/packages/analytics-react-native/test/config.test.ts b/packages/analytics-react-native/test/config.test.ts index 20e6cecf5..c2f8768b8 100644 --- a/packages/analytics-react-native/test/config.test.ts +++ b/packages/analytics-react-native/test/config.test.ts @@ -60,7 +60,7 @@ describe('config', () => { }, transportProvider: new FetchTransport(), useBatch: false, - diagnosticProvider: new core.Diagnostic({ apiKey: '' }), + diagnosticProvider: new core.BaseDiagnostic({ apiKey: '' }), trackingSessionEvents: false, }); }); @@ -114,7 +114,7 @@ describe('config', () => { }, transportProvider: new FetchTransport(), useBatch: false, - diagnosticProvider: new core.Diagnostic({ apiKey: API_KEY }), + diagnosticProvider: new core.BaseDiagnostic({ apiKey: API_KEY }), trackingSessionEvents: false, }); }); @@ -196,7 +196,7 @@ describe('config', () => { }, transportProvider: new FetchTransport(), useBatch: false, - diagnosticProvider: new core.Diagnostic({ apiKey: API_KEY }), + diagnosticProvider: new core.BaseDiagnostic({ apiKey: API_KEY }), _userId: 'userIdFromCookies', }); }); diff --git a/packages/plugin-page-view-tracking-browser/test/page-view-tracking.test.ts b/packages/plugin-page-view-tracking-browser/test/page-view-tracking.test.ts index 336da4dfb..9c5e3e157 100644 --- a/packages/plugin-page-view-tracking-browser/test/page-view-tracking.test.ts +++ b/packages/plugin-page-view-tracking-browser/test/page-view-tracking.test.ts @@ -1,5 +1,5 @@ import { createInstance } from '@amplitude/analytics-browser'; -import { Diagnostic, Logger, UUID } from '@amplitude/analytics-core'; +import { BaseDiagnostic, Logger, UUID } from '@amplitude/analytics-core'; import { BrowserConfig, LogLevel } from '@amplitude/analytics-types'; import { pageViewTrackingPlugin, shouldTrackHistoryPageView } from '../src/page-view-tracking'; import { CookieStorage, FetchTransport } from '@amplitude/analytics-client-common'; @@ -31,7 +31,7 @@ describe('pageViewTrackingPlugin', () => { language: true, platform: true, }, - diagnosticProvider: new Diagnostic(), + diagnosticProvider: new BaseDiagnostic(), }; beforeAll(() => { diff --git a/packages/plugin-web-attribution-browser/test/web-attribution.test.ts b/packages/plugin-web-attribution-browser/test/web-attribution.test.ts index ce81a4d9d..781428595 100644 --- a/packages/plugin-web-attribution-browser/test/web-attribution.test.ts +++ b/packages/plugin-web-attribution-browser/test/web-attribution.test.ts @@ -3,7 +3,7 @@ import { BASE_CAMPAIGN, CampaignParser, CookieStorage, FetchTransport } from '@a import { webAttributionPlugin } from '../src/web-attribution'; import * as helpers from '../src/helpers'; import { BrowserConfig, LogLevel } from '@amplitude/analytics-types'; -import { Diagnostic, Logger, UUID } from '@amplitude/analytics-core'; +import { BaseDiagnostic, Logger, UUID } from '@amplitude/analytics-core'; describe('webAttributionPlugin', () => { const mockConfig: BrowserConfig = { @@ -32,7 +32,7 @@ describe('webAttributionPlugin', () => { language: true, platform: true, }, - diagnosticProvider: new Diagnostic(), + diagnosticProvider: new BaseDiagnostic(), }; describe('setup', () => {