Skip to content

Commit

Permalink
Make app-runtime modules configurable and simplfy the app-runtime sta…
Browse files Browse the repository at this point in the history
…rtup (#407)

* feat: make app-runtime modules configurable

* chore: update tests

* refactor: simplify config access
  • Loading branch information
jkoenig134 authored Jan 29, 2025
1 parent 4eb70ec commit d258266
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 38 deletions.
5 changes: 3 additions & 2 deletions packages/app-runtime/src/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export interface AppConfig extends RuntimeConfig {
export interface AppConfigOverwrite {
transportLibrary?: Omit<IConfigOverwrite, "supportedIdentityVersion">;
accountsDbName?: string;
applicationId: string;
applicationId?: string;
applePushEnvironment?: "Development" | "Production";
allowMultipleAccountsWithSameAddress?: boolean;
databaseFolder?: string;
modules?: Record<string, { enabled?: boolean; [x: string | number | symbol]: unknown }>;
}

export function createAppConfig(...configs: AppConfigOverwrite[]): AppConfig {
export function createAppConfig(...configs: (AppConfigOverwrite | AppConfig)[]): AppConfig {
const appConfig: Omit<AppConfig, "transportLibrary" | "applicationId"> & {
transportLibrary: Omit<IConfigOverwrite, "supportedIdentityVersion" | "platformClientId" | "platformClientSecret" | "baseUrl">;
} = {
Expand Down
25 changes: 2 additions & 23 deletions packages/app-runtime/src/AppRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class AppRuntime extends Runtime<AppConfig> {
this._accountServices = new AccountServices(this._multiAccountController);
}

public static async create(nativeBootstrapper: INativeBootstrapper, appConfig?: AppConfigOverwrite, eventBus?: EventBus): Promise<AppRuntime> {
public static async create(nativeBootstrapper: INativeBootstrapper, appConfig: AppConfigOverwrite | AppConfig = {}, eventBus?: EventBus): Promise<AppRuntime> {
// TODO: JSSNMSHDD-2524 (validate app config)

if (!nativeBootstrapper.isInitialized) {
Expand All @@ -213,28 +213,7 @@ export class AppRuntime extends Runtime<AppConfig> {
}
}

const applePushEnvironmentResult = nativeBootstrapper.nativeEnvironment.configAccess.get("applePushEnvironment");
const applePushEnvironment = applePushEnvironmentResult.isError ? undefined : applePushEnvironmentResult.value;

const applicationId = nativeBootstrapper.nativeEnvironment.configAccess.get("applicationId").value;
const transportConfig = nativeBootstrapper.nativeEnvironment.configAccess.get("transport").value;
const databaseFolder = nativeBootstrapper.nativeEnvironment.configAccess.get("databaseFolder").value;

const mergedConfig = appConfig
? createAppConfig(
{
transportLibrary: transportConfig,
applicationId: applicationId,
applePushEnvironment: applePushEnvironment
},
appConfig
)
: createAppConfig({
transportLibrary: transportConfig,
applicationId: applicationId,
applePushEnvironment: applePushEnvironment,
databaseFolder: databaseFolder
});
const mergedConfig = createAppConfig(appConfig);

const runtime = new AppRuntime(nativeBootstrapper.nativeEnvironment, mergedConfig, eventBus);
await runtime.init();
Expand Down
2 changes: 0 additions & 2 deletions packages/app-runtime/src/natives/INativeConfigAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ export interface INativeConfigAccess {
set(key: string, value: any): Result<void>;
remove(key: string): Result<void>;
save(): Promise<Result<void>>;
initDefaultConfig(path: string): Promise<Result<void>>;
initRuntimeConfig(path: string): Promise<Result<void>>;
}
6 changes: 3 additions & 3 deletions packages/app-runtime/test/lib/TestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import { defaultsDeep } from "lodash";
import path from "path";
import { GenericContainer, Wait } from "testcontainers";
import { LogLevel } from "typescript-logging";
import { AppConfig, AppRuntime, IUIBridge, LocalAccountDTO, LocalAccountSession, createAppConfig as runtime_createAppConfig } from "../../src";
import { AppConfig, AppConfigOverwrite, AppRuntime, IUIBridge, LocalAccountDTO, LocalAccountSession, createAppConfig as runtime_createAppConfig } from "../../src";
import { FakeUIBridge } from "./FakeUIBridge";
import { FakeNativeBootstrapper } from "./natives/FakeNativeBootstrapper";

export class TestUtil {
public static async createRuntime(configOverride?: any, uiBridge: IUIBridge = new FakeUIBridge(), eventBus?: EventBus): Promise<AppRuntime> {
public static async createRuntime(configOverride?: AppConfigOverwrite, uiBridge: IUIBridge = new FakeUIBridge(), eventBus?: EventBus): Promise<AppRuntime> {
configOverride = defaultsDeep(configOverride, {
modules: {
pushNotification: { enabled: false }
Expand All @@ -42,7 +42,7 @@ export class TestUtil {
return runtime;
}

public static async createRuntimeWithoutInit(configOverride?: any): Promise<AppRuntime> {
public static async createRuntimeWithoutInit(configOverride?: AppConfigOverwrite): Promise<AppRuntime> {
const config = this.createAppConfig(configOverride);

const nativeBootstrapper = new FakeNativeBootstrapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,4 @@ export class FakeNativeConfigAccess implements INativeConfigAccess {
public save(): Promise<Result<void>> {
return Promise.resolve(Result.ok(undefined));
}

public initRuntimeConfig(/* logger: ILogger, fileAccess: INativeFileAccess*/): Promise<Result<void>> {
return Promise.resolve(Result.ok(undefined));
}

public initDefaultConfig(): Promise<Result<void>> {
return Promise.resolve(Result.ok(undefined));
}
}

0 comments on commit d258266

Please sign in to comment.