diff --git a/runtime/analytics/index.ts b/runtime/analytics/index.ts index 36613629..ffa65611 100644 --- a/runtime/analytics/index.ts +++ b/runtime/analytics/index.ts @@ -10,3 +10,4 @@ export { } from './interface'; export { default as MockAnalyticsService } from './MockAnalyticsService'; export { default as SegmentAnalyticsService } from './SegmentAnalyticsService'; +export type * from './types'; diff --git a/runtime/analytics/types.ts b/runtime/analytics/types.ts new file mode 100644 index 00000000..1ed9797d --- /dev/null +++ b/runtime/analytics/types.ts @@ -0,0 +1,7 @@ +export interface AnalyticsService { + sendTrackingLogEvent(eventName: string, properties: object): Promise, + identifyAuthenticatedUser(userId: string | number, traits?: Record): void, + identifyAnonymousUser(traits?: Record): void, + sendTrackEvent(eventName?: string, properties?: Record): void, + sendPageEvent(category: string, name: string, properties?: Record): void, +} diff --git a/runtime/auth/index.ts b/runtime/auth/index.ts index eaf890bb..49b74a4e 100644 --- a/runtime/auth/index.ts +++ b/runtime/auth/index.ts @@ -17,3 +17,4 @@ export { setAuthenticatedUser } from './interface'; export { default as MockAuthService } from './MockAuthService'; +export type * from './types'; diff --git a/runtime/auth/types.ts b/runtime/auth/types.ts new file mode 100644 index 00000000..f8d38e43 --- /dev/null +++ b/runtime/auth/types.ts @@ -0,0 +1,15 @@ +import { User } from '../../types'; + +export interface AuthService { + getAuthenticatedHttpClient(options?: Record): unknown, + getHttpClient(options?: Record): unknown, + getLoginRedirectUrl(redirectUrl?: string): string, + redirectToLogin(redirectUrl?: string): void, + getLogoutRedirectUrl(redirectUrl?: string): string, + redirectToLogout(redirectUrl?: string): void, + getAuthenticatedUser(): User | null, + setAuthenticatedUser(authUser: User): void, + fetchAuthenticatedUser(options?: Record): Promise, + ensureAuthenticatedUser(redirectUrl?: string): Promise, + hydrateAuthenticatedUser(): Promise, +} diff --git a/runtime/logging/index.ts b/runtime/logging/index.ts index c7ec935d..95d5d500 100644 --- a/runtime/logging/index.ts +++ b/runtime/logging/index.ts @@ -7,3 +7,4 @@ export { } from './interface'; export { default as MockLoggingService } from './MockLoggingService'; export { default as NewRelicLoggingService } from './NewRelicLoggingService'; +export type * from './types'; diff --git a/types.ts b/types.ts index 4e81a595..cdb39d14 100644 --- a/types.ts +++ b/types.ts @@ -2,6 +2,9 @@ import { FC, ReactElement, ReactNode } from 'react'; import { MessageDescriptor } from 'react-intl'; import { RouteObject } from 'react-router'; import { SlotOperation } from './runtime/slots/types'; +import { LoggingService } from './runtime/logging'; +import { AnalyticsService } from './runtime/analytics'; +import { AuthService } from './runtime/auth'; // Apps @@ -60,6 +63,22 @@ export interface RequiredSiteConfig { export type LocalizedMessages = Record>; export type SiteMessages = LocalizedMessages[]; +export type LoggingServiceClass = new (options: { + config: SiteConfig, +}) => LoggingService; + +export type AnalyticsServiceClass = new (options: { + config: SiteConfig, + loggingService: LoggingService, + httpClient: unknown, +}) => AnalyticsService; + +export type AuthServiceClass = new (options: { + config: SiteConfig, + loggingService: LoggingService, + middleware: unknown[], +}) => AuthService; + export interface OptionalSiteConfig { // Site environment environment: EnvironmentTypes; @@ -96,7 +115,12 @@ export interface OptionalSiteConfig { ignoredErrorRegex: RegExp | null; // Analytics - segmentKey: string | null; + segmentKey: string | null, + + // Services + loggingService: LoggingServiceClass, + analyticsService: AnalyticsServiceClass, + authService: AuthServiceClass, } export type SiteConfig = RequiredSiteConfig & Partial; @@ -125,7 +149,7 @@ export interface User { roles: string[]; userId: number; username: string; - avatar: string; + avatar?: string; } export enum EnvironmentTypes {