UNPKG

@snap/camera-kit

Version:
123 lines 6.95 kB
import { __awaiter } from "tslib"; import { Container, Injectable, PartialContainer } from "@snap/ts-inject"; import { remoteMediaAssetLoaderFactory } from "./lens/assets/remoteMediaAssetLoaderFactory"; import { deviceDependentAssetLoaderFactory } from "./lens/assets/deviceDependentAssetLoader"; import { staticAssetLoaderFactory } from "./lens/assets/staticAssetLoader"; import { defaultFetchHandlerFactory } from "./handlers/defaultFetchHandler"; import { cameraKitServiceFetchHandlerFactory } from "./handlers/cameraKitServiceFetchHandlerFactory"; import { createCameraKitConfigurationFactory } from "./configuration"; import { lensCoreFactory } from "./lens-core-module/loader/lensCoreFactory"; import { cameraKitFactory } from "./CameraKit"; import { lensRepositoryFactory } from "./lens/LensRepository"; import lensCoreWasm from "./lensCoreWasmVersions"; import environment from "./environment"; import { uriHandlersFactory } from "./uri-handlers/UriHandlers"; import { assert } from "./common/assertions"; import { isSafeString } from "./common/typeguards"; import { metricsEventTargetFactory } from "./metrics/metricsEventTarget"; import { reportGloballyScopedMetrics } from "./metrics/reporters/reporters"; import { getLogger } from "./logger/logger"; import { logEntriesFactory } from "./logger/logEntries"; import { assertPlatformSupported } from "./platform/assertPlatformSupported"; import { lensPersistenceStoreFactory } from "./lens/LensPersistenceStore"; import { remoteConfigurationFactory } from "./remote-configuration/remoteConfiguration"; import { lensAssetRepositoryFactory } from "./lens/assets/LensAssetRepository"; import { legalStateFactory } from "./legal/legalState"; import { legalPromptFactory } from "./legal/legalPrompt"; import { bootstrapError, configurationError } from "./namedErrors"; import { businessEventsReporterFactory } from "./metrics/businessEventsReporter"; import { reportGlobalException } from "./metrics/reporters/reportGlobalException"; import { registerLogEntriesSubscriber } from "./logger/registerLogEntriesSubscriber"; import { requestStateEventTargetFactory } from "./handlers/requestStateEmittingHandler"; import { pageVisibilityFactory } from "./common/pageVisibility"; import { cofHandlerFactory } from "./remote-configuration/cofHandler"; import { remoteApiServicesFactory } from "./uri-handlers/internal-handlers/remoteApiUriHandler"; import { lensesClientFactory } from "./clients/lensesClient"; import { grpcHandlerFactory } from "./clients/grpcHandler"; import { lensSourcesFactory } from "./lens/LensSource"; import { cameraKitLensSourceFactory } from "./lens/cameraKitLensSource"; import { externalMetricsSubjectFactory, metricsClientFactory } from "./clients/metricsClient"; import { Timer } from "./metrics/operational/Timer"; import { fetchWatermarkLens } from "./lens/fetchWatermarkLens"; import { filePickerFactory } from "./lens-client-interface/filePicker"; import { userDataAccessResolverFactory } from "./lens/userDataAccessResolver"; import { remoteApiSpecsClientFactory } from "./clients/remoteApiSpecsClient"; import { geoDataProviderFactory } from "./geo/geoDataProvider"; const logger = getLogger("bootstrapCameraKit"); const nonWrappableErrors = [ "ConfigurationError", "PlatformNotSupportedError", ]; function shouldWrapError(error) { if (error instanceof Error) { return !nonWrappableErrors.some((name) => error.name === name); } return true; } export function bootstrapCameraKit(configuration, provide) { return __awaiter(this, void 0, void 0, function* () { console.info(`Camera Kit SDK: ${environment.PACKAGE_VERSION} (${lensCoreWasm.version}/${lensCoreWasm.buildNumber})`); try { const bootstrapLatency = new Timer("bootstrap_time"); assert(isSafeString(configuration.apiToken), configurationError("Invalid or unsafe apiToken provided.")); const configurationFactory = createCameraKitConfigurationFactory(configuration); const defaultPublicContainer = Container.provides(configurationFactory) .provides(userDataAccessResolverFactory) .provides(filePickerFactory) .provides(defaultFetchHandlerFactory) .provides(remoteMediaAssetLoaderFactory) .provides(lensSourcesFactory) .provides(remoteApiServicesFactory) .provides(uriHandlersFactory) .provides(geoDataProviderFactory) .provides(externalMetricsSubjectFactory); const publicContainer = provide ? provide(defaultPublicContainer) : defaultPublicContainer; const telemetryContainer = Container.provides(publicContainer) .provides(pageVisibilityFactory) .provides(cameraKitServiceFetchHandlerFactory) .provides(requestStateEventTargetFactory) .provides(grpcHandlerFactory) .provides(metricsClientFactory) .provides(logEntriesFactory) .run(registerLogEntriesSubscriber) .provides(metricsEventTargetFactory) .provides(reportGlobalException) .provides(cofHandlerFactory) .provides(remoteConfigurationFactory) .provides(legalPromptFactory) .provides(legalStateFactory) .run(reportGloballyScopedMetrics) .run(businessEventsReporterFactory); telemetryContainer.get(reportGlobalException.token); yield assertPlatformSupported(); const lensCore = yield telemetryContainer.provides(lensCoreFactory).get(lensCoreFactory.token); const container = telemetryContainer .provides(Injectable(lensCoreFactory.token, () => lensCore)) .provides(lensesClientFactory) .provides(remoteApiSpecsClientFactory) .provides(cameraKitLensSourceFactory) .provides(lensPersistenceStoreFactory) .provides(deviceDependentAssetLoaderFactory) .provides(staticAssetLoaderFactory) .provides(lensAssetRepositoryFactory) .provides(lensRepositoryFactory) .provides(cameraKitFactory) .run(fetchWatermarkLens); const cameraKit = container.get(cameraKitFactory.token); bootstrapLatency.measure(); container.get(metricsClientFactory.token).setOperationalMetrics(bootstrapLatency); return cameraKit; } catch (error) { if (shouldWrapError(error)) { error = bootstrapError("Error occurred during Camera Kit bootstrapping.", error); } logger.error(error); throw error; } }); } export function createExtension() { return new PartialContainer({}); } //# sourceMappingURL=bootstrapCameraKit.js.map