Skip to content

Commit

Permalink
refactor: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Oct 11, 2023
1 parent a7ccd78 commit c7bf5fa
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 44 deletions.
6 changes: 3 additions & 3 deletions packages/analytics-browser/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BrowserOptions,
BrowserConfig as IBrowserConfig,
DefaultTrackingOptions,
Diagnostic as IDiagnostic,
Diagnostic,
Storage,
TrackingOptions,
TransportType,
Expand All @@ -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 {
Expand Down Expand Up @@ -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) });
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-browser/src/diagnostics/diagnostic.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await fetch(this.serverUrl, this.requestPayloadBuilder(this.queue));
await super.flush();
Expand Down
12 changes: 6 additions & 6 deletions packages/analytics-core/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Event,
Config as IConfig,
Diagnostic as IDiagnostic,
Diagnostic,
DiagnosticOptions,
Logger as ILogger,
LogLevel,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -52,7 +52,7 @@ export class Config implements IConfig {
transportProvider: Transport;
storageProvider?: Storage<Event[]>;
useBatch: boolean;
diagnosticProvider: IDiagnostic | DiagnosticOptions;
diagnosticProvider: Diagnostic | DiagnosticOptions;

protected _optOut = false;
get optOut() {
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-core/src/diagnostics/diagnostic.ts
Original file line number Diff line number Diff line change
@@ -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 = '';
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/analytics-core/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions packages/analytics-core/test/diagnostic.test.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand All @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-core/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
UUID,
MemoryStorage,
createIdentifyEvent,
Diagnostic,
BaseDiagnostic,
buildResult,
EXCEEDED_MAX_RETRY_DIAGNOSTIC_MESSAGE,
MISSING_API_KEY_DIAGNOSTIC_MESSAGE,
Expand All @@ -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');
Expand Down
14 changes: 3 additions & 11 deletions packages/analytics-core/test/plugins/destination.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-node/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
});
});
});
Expand Down Expand Up @@ -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 }),
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/analytics-react-native/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('config', () => {
},
transportProvider: new FetchTransport(),
useBatch: false,
diagnosticProvider: new core.Diagnostic({ apiKey: '' }),
diagnosticProvider: new core.BaseDiagnostic({ apiKey: '' }),
trackingSessionEvents: false,
});
});
Expand Down Expand Up @@ -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,
});
});
Expand Down Expand Up @@ -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',
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('pageViewTrackingPlugin', () => {
language: true,
platform: true,
},
diagnosticProvider: new Diagnostic(),
diagnosticProvider: new BaseDiagnostic(),
};

beforeAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('webAttributionPlugin', () => {
language: true,
platform: true,
},
diagnosticProvider: new Diagnostic(),
diagnosticProvider: new BaseDiagnostic(),
};

describe('setup', () => {
Expand Down

0 comments on commit c7bf5fa

Please sign in to comment.