MCPcopy Create free account
hub / github.com/ProtonDriveApps/sdk / init

Function init

cli/src/init.ts:19–92  ·  view source on GitHub ↗
(configOptions: InitConfig)

Source from the content-addressed store, hash-verified

17import { disableSentry, initTelemetry } from './telemetry';
18
19export async function init(configOptions: InitConfig) {
20 const config = getConfig(configOptions);
21 await Promise.all([
22 mkdir(config.cacheDir, { recursive: true }),
23 mkdir(config.appDir, { recursive: true }),
24 mkdir(config.logDir, { recursive: true }),
25 ]);
26
27 const { telemetry, metrics, enableMetrics, flush: flushTelemetry } = initTelemetry(config);
28 const logger = telemetry.getLogger('cli');
29
30 logger.info(`Version: CLI=${configOptions.appVersion}, SDK=${configOptions.sdkVersion ?? 'unknown'}`);
31
32 const openPGPCryptoModule = initOpenPGPCryptoModule();
33 const credentials = initCredentials(config, logger);
34 const { auth, addresses, srp, httpClient, apiClient } = await initApi(config, credentials, logger, CryptoProxy);
35
36 // Sentry is enabled from the start to collect crashes before any user
37 // operation is performed to avoid going blind in case of a hard crash.
38 // Once the core application is running and the telemetry preference is
39 // known, the metrics are enabled or disabled accordingly.
40 logger.debug(`Telemetry enabled: build=${configOptions.enableMetrics}, user=${credentials.isTelemetryEnabled()}`);
41 if (credentials.isTelemetryEnabled()) {
42 // TODO: Once we have Account SDK, get the user plan from the auth object.
43 enableMetrics(apiClient, 'unknown');
44 } else {
45 disableSentry();
46 }
47
48 const clientUid = await getOrGenerateClientUid(config, logger);
49 const caches = createCaches(config, credentials, logger);
50 const eventsProvider = config.enablePersistedEvents
51 ? await PersistedEventsProvider.open(logger, config.appDir)
52 : new NoEventsProvider();
53
54 const sdkDependencies = {
55 config: {
56 baseUrl: config.baseUrl,
57 clientUid,
58 },
59 httpClient,
60 entitiesCache: caches.entitiesCache,
61 cryptoCache: caches.cryptoCache,
62 telemetry,
63 openPGPCryptoModule,
64 account: addresses,
65 srpModule: srp,
66 latestEventIdProvider: eventsProvider,
67 featureFlagProvider: configOptions.flags
68 ? new FeatureFlagProvider(configOptions.flags)
69 : await FeatureFlagProvider.fromJsonFile(path.join(config.appDir, 'config.json')),
70 };
71 const sdk = new ProtonDriveClient(sdkDependencies);
72 const photosSdk = new ProtonDrivePhotosClient(sdkDependencies);
73 const sdkDiagnostic = initDiagnostic(sdkDependencies);
74
75 const eventsManager = await Manager.create(logger, sdk, photosSdk, eventsProvider, auth.isLoggedIn());
76

Callers 2

runCommandFunction · 0.90
startReplFunction · 0.90

Calls 15

getConfigFunction · 0.90
initTelemetryFunction · 0.90
initCredentialsFunction · 0.90
initApiFunction · 0.90
getOrGenerateClientUidFunction · 0.90
createCachesFunction · 0.90
initDiagnosticFunction · 0.90
initOpenPGPCryptoModuleFunction · 0.85
openMethod · 0.80
fromJsonFileMethod · 0.80
getLoggerMethod · 0.65
isLoggedInMethod · 0.65

Tested by

no test coverage detected