-
Notifications
You must be signed in to change notification settings - Fork 11
fix: add missing SiteConfig service override typings and definitions #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,31 @@ export interface RequiredSiteConfig { | |
| export type LocalizedMessages = Record<string, Record<string, string>>; | ||
| export type SiteMessages = LocalizedMessages[]; | ||
|
|
||
| // Generic logger contract | ||
| export interface LoggingService { | ||
| debug?(message: string, meta?: Record<string, unknown>): void, | ||
| info?(message: string, meta?: Record<string, unknown>): void, | ||
| warn?(message: string, meta?: Record<string, unknown>): void, | ||
| error?(message: string | Error, meta?: Record<string, unknown>): void, | ||
| } | ||
|
|
||
| // Generic analytics contract | ||
| export interface AnalyticsService { | ||
| identify?(userId: string | number, traits?: Record<string, unknown>): void, | ||
| track(event: string, properties?: Record<string, unknown>): void, | ||
| page?(name?: string, properties?: Record<string, unknown>): void, | ||
| reset?(): void, | ||
| } | ||
|
|
||
| // Generic auth contract | ||
| export interface AuthService { | ||
| isAuthenticated(): boolean | Promise<boolean>, | ||
| getAccessToken?(): string | null | Promise<string | null>, | ||
| login?(redirectUrl?: string): void | Promise<void>, | ||
| logout?(redirectUrl?: string): void | Promise<void>, | ||
| getCurrentUser?(): User | null | Promise<User | null>, | ||
| } | ||
|
|
||
| export interface OptionalSiteConfig { | ||
| // Site environment | ||
| environment: EnvironmentTypes, | ||
|
|
@@ -92,6 +117,11 @@ export interface OptionalSiteConfig { | |
|
|
||
| // Analytics | ||
| segmentKey: string | null, | ||
|
|
||
| // Services | ||
| loggingService: LoggingService, | ||
| analyticsService: AnalyticsService, | ||
| authService: AuthService, | ||
|
Comment on lines
+122
to
+124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These keys hold service classes, not instances. Each Typing them as instances means a consumer who satisfies the type with an object literal gets a types.ts:42 already has the correct pattern for this: export type ExternalScriptLoaderClass = new (data: { config: AppConfig }) => ExternalScriptLoader;Constructor options differ per service: logging gets |
||
| } | ||
|
|
||
| export type SiteConfig = RequiredSiteConfig & Partial<OptionalSiteConfig>; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the three interfaces match the contracts the runtime validates against.
For logging, runtime/logging/types.ts:1-4 already defines
LoggingService, with the correct shape (logInfo,logError). This is a second, contradictory definition of the same name, though unfortunately it is the one that becomes public API.configureLoggingvalidates the instance against{ logInfo, logError }(runtime/logging/interface.js:34-37), which is what NewRelicLoggingService:132-152 and MockLoggingService:14-21 implement. No logging service in the repo hasdebug,info,warn, orerror.For analytics,
configureAnalyticsrequiressendTrackingLogEvent,identifyAuthenticatedUser,identifyAnonymousUser,sendTrackEvent, andsendPageEvent(runtime/analytics/interface.js:42-48), which is what SegmentAnalyticsService:133-234 implements. There's notrack,page,identify, orreset.trackbeing non-optional also makes this a hard error rather than a weak-type warning:analyticsService: SegmentAnalyticsServicefails withTS2741: Property 'track' is missing.For auth,
configureAuthrequires eleven methods (runtime/auth/interface.js:73-85). AxiosJwtAuthService:111-310 has neitherisAuthenticatednorgetCurrentUser, soauthService: AxiosJwtAuthServicefails withTS2741: Property 'isAuthenticated' is missing. That class is a perfectly good service at runtime; it's the declared type that rejects it.