Skip to content

Commit

Permalink
Add device identifier to config request
Browse files Browse the repository at this point in the history
  • Loading branch information
trmartin4 committed Jan 31, 2025
1 parent 1d71212 commit 593bfd1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export abstract class ConfigApiServiceAbstraction {
/**
* Fetches the server configuration for the given user. If no user is provided, the configuration will not contain user-specific context.
*/
abstract get(userId: UserId | undefined): Promise<ServerConfigResponse>;
abstract get(userId: UserId | undefined, appId: string): Promise<ServerConfigResponse>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export class ConfigApiService implements ConfigApiServiceAbstraction {
private tokenService: TokenService,
) {}

async get(userId: UserId | undefined): Promise<ServerConfigResponse> {
async get(userId: UserId | undefined, appId: string): Promise<ServerConfigResponse> {
// Authentication adds extra context to config responses, if the user has an access token, we want to use it
// We don't particularly care about ensuring the token is valid and not expired, just that it exists
const authed: boolean =
userId == null ? false : (await this.tokenService.getAccessToken(userId)) != null;

const r = await this.apiService.send("GET", "/config", null, authed, true);
const r = await this.apiService.send("GET", "/config", null, authed, true, null, (headers) => {
headers.set("Device-Identifier", appId);
});
return new ServerConfigResponse(r);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AuthService } from "../../../auth/abstractions/auth.service";
import { AuthenticationStatus } from "../../../auth/enums/authentication-status";
import { FeatureFlag } from "../../../enums/feature-flag.enum";
import { UserId } from "../../../types/guid";
import { AppIdService } from "../../abstractions/app-id.service";
import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction";
import { ServerConfig } from "../../abstractions/config/server-config";
import { Environment, EnvironmentService } from "../../abstractions/environment.service";
Expand Down Expand Up @@ -46,6 +47,7 @@ describe("ConfigService", () => {
const authService = mock<AuthService>({
authStatusFor$: (userId) => of(AuthenticationStatus.Unlocked),
});
const appIdService = mock<AppIdService>();
let stateProvider: FakeStateProvider;
let globalState: FakeGlobalState<Record<ApiUrl, ServerConfig>>;
let userState: FakeSingleUserState<ServerConfig>;
Expand Down Expand Up @@ -81,6 +83,7 @@ describe("ConfigService", () => {
logService,
stateProvider,
authService,
appIdService,
);
});

Expand Down Expand Up @@ -218,6 +221,7 @@ describe("ConfigService", () => {
mock<AuthService>({
authStatusFor$: () => of(AuthenticationStatus.Locked),
}),
appIdService,
);

const config = await firstValueFrom(sut.serverConfig$);
Expand All @@ -243,6 +247,7 @@ describe("ConfigService", () => {
logService,
stateProvider,
authService,
appIdService,
);
});

Expand Down Expand Up @@ -296,6 +301,7 @@ describe("ConfigService", () => {
logService,
stateProvider,
authService,
appIdService,
);

userState.nextState(null);
Expand Down Expand Up @@ -349,6 +355,7 @@ describe("ConfigService", () => {
logService,
stateProvider,
authService,
appIdService,
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
FeatureFlagValueType,
} from "../../../enums/feature-flag.enum";
import { UserId } from "../../../types/guid";
import { AppIdService } from "../../abstractions/app-id.service";
import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction";
import { ConfigService } from "../../abstractions/config/config.service";
import { ServerConfig } from "../../abstractions/config/server-config";
Expand Down Expand Up @@ -70,6 +71,7 @@ export class DefaultConfigService implements ConfigService {
private logService: LogService,
private stateProvider: StateProvider,
private authService: AuthService,
private appIdService: AppIdService,
) {
const userId$ = this.stateProvider.activeUserId$;
const authStatus$ = userId$.pipe(
Expand Down Expand Up @@ -186,7 +188,8 @@ export class DefaultConfigService implements ConfigService {
);
this.failedFetchFallbackSubject.next(existingConfig);
}, SLOW_EMISSION_GUARD);
const response = await this.configApiService.get(userId);
const appId = await this.appIdService.getAppId();
const response = await this.configApiService.get(userId, appId);
clearTimeout(handle);
const newConfig = new ServerConfig(new ServerConfigData(response));

Expand Down

0 comments on commit 593bfd1

Please sign in to comment.