{"version":3,"sources":["stores/destinations.ts","stores/currentPageHeader.ts","stores/sources.ts","stores/entitiesStore.ts","stores/helpers.ts","stores/inAppNotifications.ts","stores/_initializeAllStores.ts","stores/apiKeys.ts"],"names":["DestinationsStore","idField","hideElements","dst","destinationsReferenceMap","_type","hidden","apiKeysStore","services","ApplicationServices","get","makeObservable","createFreeDatabase","flow","id","destination","backendApiClient","post","projectId","activeProject","credentials","freeDatabaseDestination","_comment","_id","_uid","randomId","_mappings","_onlyKeys","_connectionTestOk","_sources","_formData","pguser","pgpassword","pghost","pgport","pgdatabase","mode","flowResult","generateAddInitialApiKeyIfNeeded","linkedFreeDatabaseDestination","list","uid","add","EntitiesStore","destinationsStore","CurrentPageHeader","_breadcrumbs","makeAutoObservable","length","link","title","map","element","breadcrumbs","console","log","normalized","b","currentPageHeaderStore","sourcesStore","EntitiesStoreStatus","IDLE","GLOBAL_LOADING","BACKGROUND_LOADING","GLOBAL_ERROR","type","schema","_initialized","_state","observable","status","errorMessage","_entities","bind","computed","listHidden","listIncludeHidden","action","bound","pullAll","delete","replace","patch","message","entity","filter","find","getId","options","showGlobalLoader","resetError","setStatus","storageService","table","getAll","entities","setError","entityToAdd","addedEntity","Error","push","index","findIndex","item","getObjectDepth","Object","assign","ConnectionsHelper","stores","sources","destinations","apiKeyId","updateDestinationsConnectionsToApiKey","sourceId","updateDestinationsConnectionsToSource","destinationId","updateSourcesConnectionsToDestination","connectedSourcesIds","updateEntitiesConnections","store","connectedEntitiesIdsField","connectedDestinationsIds","some","isInitialized","apiKeys","nonExistentApiKeys","nonExistentSources","existingApiKeys","key","existingSources","src","forEach","includes","nonExistentDestinations","existingDestinations","source","Promise","all","nonExistentKey","unconnectDeletedApiKey","nonExistentSrc","unconnectDeletedSource","unconnectDeletedDestination","entityId","connectedEntitiesIds","connectedEntitiesSchema","patches","entityShouldBeConnected","entityIsConnected","entries","connectionsHelper","InAppNotificationsStore","_destinationsStore","_apiKeysStore","_connectorsStore","keyIsConnected","reduce","isConnected","keyUid","orphanDestinations","icon","ui","editEntityRoute","projectRoute","destinationPageRoutes","editExact","orphanApiKeys","apiKeysReferenceMap","js","apiKeysRoutes","orphanConnectors","sourceProtoType","allSourcesMap","pic","sourcesPageRoutes","notifications","inAppNotificationsStore","initializeAllStores","analyticsService","initalizeStoresData","healConnections","onGlobalError","allSettled","ApiKeysStore","override","newApiKey","generateApiKey","comment","addedApiKey","generateApiToken","serverAuth","jsAuth","origins","len","postfix","note"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA;AAEA;AAGA;AAEA;AAEA;AAGO,GAAMA,kBAAb,kfAIE,4BAAc,6OACZ,uBAAM,cAAN,CAAsB,CACpBC,OAAO,CAAE,MADW,CAEpBC,YAAY,CAAE,sBAAAC,GAAG,yDAAIC,wEAAwB,CAACD,GAAG,CAACE,KAAL,CAA5B,gDAAI,sBAAqCC,MAAzC,EAFG,CAAtB,EADY,MAHGC,YAGH,CAHgCA,8DAGhC,OAFKC,QAEL,QAKZ,MAAKA,QAAL,CAAgBC,gFAAmB,CAACC,GAApB,EAAhB,CACAC,mEAAc,CAAC,wNAAM,CACnBC,kBAAkB,CAAEC,iDADD,CAAP,CAAd,CANY,aASb,CAbH,mQAeE,qCAAmCC,EAAnC,CAAmE,CACjE,GAAMC,YAAmC,CAAG,KAAKL,GAAL,CAASI,EAAT,CAA5C,CACA,MAAOC,YAAW,CAAGX,wEAAwB,CAACW,WAAW,CAACV,KAAb,CAA3B,CAAiD,IAAnE,CACD,CAlBH,oQAoBE,2aAC6C,MAAM,MAAKG,QAAL,CAAcQ,gBAAd,CAA+BC,IAA/B,CAAoC,WAApC,CAAiD,CAChGC,SAAS,CAAE,KAAKV,QAAL,CAAcW,aAAd,CAA4BL,EADyD,CAAjD,CAAN,CAD7C,OACQM,WADR,eAIQC,uBAJR,CAImD,CAC/ChB,KAAK,CAAE,UADwC,CAE/CiB,QAAQ,CACN,0GACA,4HAJ6C,CAK/CC,GAAG,CAAE,eAL0C,CAM/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K,OAAO,CAAE,EALJ,CAAP,CAOD,CApCH,gCAsCE,0BAAwB/H,IAAxB,CAAsCgI,GAAtC,CAA4D,CAC1D,GAAMC,QAAO,WAAMzL,gFAAmB,CAACC,GAApB,GAA0BS,aAA1B,CAAwCL,EAA9C,aAAoDW,sEAAQ,CAACwK,GAAD,CAA5D,CAAb,CACA,MAAOhI,KAAI,CAACjB,MAAL,CAAc,CAAd,WAAqBiB,IAArB,aAA6BiI,OAA7B,EAAyCA,OAAhD,CACD,CAzCH,kRA2CE,0CAAyC1G,OAAzC,6UACO,CAAC,KAAKhD,IAAL,CAAUQ,MADlB,oFAEE,MAAMX,gEAAU,CAAC,KAAKK,GAAL,CAAS,CAAEiJ,OAAO,CAAEnG,OAAF,SAAEA,OAAF,iBAAEA,OAAO,CAAE2G,IAApB,CAAT,CAAD,CAAhB,CAFF,qFA3CF,2BAAkCxJ,qEAAlC,EAiDO,GAAMpC,aAAY,CAAG,GAAIgL,aAAJ,EAArB,C","file":"static/js/main~4fd8bb2a.bcfc5111.chunk.js","sourcesContent":["// @Libs\nimport { flow, flowResult, makeObservable } from \"mobx\"\n// @Services\nimport ApplicationServices from \"lib/services/ApplicationServices\"\n// @Stores\nimport { EntitiesStore } from \"./entitiesStore\"\nimport { apiKeysStore, ApiKeysStore } from \"./apiKeys\"\n// @Catalog\nimport { destinationsReferenceMap, Destination } from \"@jitsu/catalog\"\n// @Utils\nimport { randomId } from \"utils/numbers\"\n// @Types\nimport type { PgDatabaseCredentials } from \"lib/services/model\"\n\nexport class DestinationsStore extends EntitiesStore {\n private readonly apiKeysStore: ApiKeysStore = apiKeysStore\n protected readonly services: ApplicationServices\n\n constructor() {\n super(\"destinations\", {\n idField: \"_uid\",\n hideElements: dst => destinationsReferenceMap[dst._type]?.hidden,\n })\n this.services = ApplicationServices.get()\n makeObservable(this, {\n createFreeDatabase: flow,\n })\n }\n\n public getDestinationReferenceById(id: string): Destination | null {\n const destination: DestinationData | null = this.get(id)\n return destination ? destinationsReferenceMap[destination._type] : null\n }\n\n public *createFreeDatabase() {\n const credentials: PgDatabaseCredentials = yield this.services.backendApiClient.post(\"/database\", {\n projectId: this.services.activeProject.id,\n })\n const freeDatabaseDestination: DestinationData = {\n _type: \"postgres\",\n _comment:\n \"We set up a test postgres database for you. It's hosted by us and has a 10,000 rows limitation. It's ok\" +\n \" to try with service with it. However, don't use it in production setup. To reveal credentials, click on the 'Edit' button\",\n _id: \"demo_postgres\",\n _uid: randomId(),\n _mappings: null,\n _onlyKeys: [],\n _connectionTestOk: true,\n _sources: [],\n _formData: {\n pguser: credentials[\"User\"],\n pgpassword: credentials[\"Password\"],\n pghost: credentials[\"Host\"],\n pgport: credentials[\"Port\"],\n pgdatabase: credentials[\"Database\"],\n mode: \"stream\",\n },\n }\n yield flowResult(this.apiKeysStore.generateAddInitialApiKeyIfNeeded())\n const linkedFreeDatabaseDestination: DestinationData = {\n ...freeDatabaseDestination,\n _onlyKeys: [this.apiKeysStore.list[0].uid],\n }\n yield flowResult(this.add(linkedFreeDatabaseDestination))\n }\n}\n\nexport const destinationsStore = new DestinationsStore()\n","import { makeAutoObservable } from \"mobx\"\nimport { ReactNode } from \"react\"\nimport { cloneDeep } from \"lodash\"\n\n/**\n * Breadcrumb element\n */\nexport type BreadcrumbElement = {\n /**\n * Link. If not set, the element will not be highlighted\n */\n link?: string\n /**\n * If link is absolute. Otherwise, it's going to be relative to the project\n */\n absolute?: boolean\n /**\n * Link title\n */\n title: ReactNode\n}\n\ninterface ICurrentPageHeader {\n /** the list of breadcrumbs to render */\n breadcrumbs: BreadcrumbElement[]\n /**\n * Sets breadcrumbs. If first element doesn't point to project home, it will be added\n * automatically\n */\n setBreadcrumbs(...breadcrumbs: (BreadcrumbElement | string)[])\n}\n\n/**\n * This store allows components to modify page header.\n *\n * At the moment, it only stores the breadcrumbs at the top of the page\n */\nclass CurrentPageHeader implements ICurrentPageHeader {\n private _breadcrumbs: BreadcrumbElement[]\n\n constructor() {\n makeAutoObservable(this)\n }\n\n get breadcrumbs(): BreadcrumbElement[] {\n if (!this._breadcrumbs || this._breadcrumbs.length == 0) {\n return [{ link: \"/\", title: \"Home\" }]\n }\n /**\n * Deep copying `title` JSX Element object in order to prevent React from freezing it in\n * store on render. Otherwise, MobX _might_ occasionally throw `Dynamic observable objects\n * cannot be frozen`\n */\n return this._breadcrumbs.map(element => ({ ...element, title: cloneDeep(element.title) }))\n }\n\n setBreadcrumbs(...breadcrumbs: (BreadcrumbElement | string)[]) {\n console.log(\"Setting breadcrumbs\", breadcrumbs)\n let normalized: BreadcrumbElement[] = breadcrumbs.map(b => (typeof b === \"string\" ? { title: b } : b))\n this._breadcrumbs =\n normalized.length > 0 && normalized[0].link === \"/\" ? normalized : [{ link: \"/\", title: \"Home\" }, ...normalized]\n }\n}\n\nexport const currentPageHeaderStore: ICurrentPageHeader = new CurrentPageHeader()\n","import { EntitiesStore } from \"./entitiesStore\"\n\nexport type SourcesStore = EntitiesStore\n\nexport const sourcesStore = new EntitiesStore(\"sources\", { idField: \"sourceId\" })\n","import ApplicationServices from \"lib/services/ApplicationServices\"\nimport { remove } from \"lodash\"\nimport { makeObservable, observable, computed, action, flow } from \"mobx\"\nimport { getObjectDepth } from \"lib/commons/utils\"\n\nexport type EntityType = \"api_keys\" | \"sources\" | \"destinations\"\nexport type EntityData = ApiKey | SourceData | DestinationData\nexport enum EntitiesStoreStatus {\n \"IDLE\" = \"IDLE\",\n \"GLOBAL_LOADING\" = \"GLOBAL_LOADING\",\n \"BACKGROUND_LOADING\" = \"BACKGROUND_LOADING\",\n \"GLOBAL_ERROR\" = \"GLOBAL_ERROR\",\n}\n\ntype EntitySchema = {\n /** Unique id field of the entity */\n idField: string\n /** Tells which entities to exclude from the `store.list` list*/\n hideElements?: (entity: T) => boolean\n}\n\n// (!) TO DO: move type to this file\nconst { IDLE, GLOBAL_LOADING, BACKGROUND_LOADING, GLOBAL_ERROR } = EntitiesStoreStatus\n\n/**\n * Generic entities store class for manipulating objects.\n *\n * Methods of this class both make API calls and update the subscribed UI components.\n *\n * For creating a new store either instantiate this class or a class that extends this one:\n * @example\n * // Using EntitiesStore class\n * const apiKeysStore = new EntitiesStore(\"api_keys\", {idField: \"uid\"})\n *\n * // Using an extended class\n * const destinationsStore = new DestinationsStore()\n * class DestinationsStore extends EntitiesStore {\n * constructor() {\n * super(\"destinations\", {\n * idField: \"_uid\",\n * connectedEntitiesFields: { sources: \"_sources\", api_keys: \"_only_keys\" },\n * hideElements: dst => destinationsReferenceMap[dst._type]?.hidden,\n * })\n * }\n *\n * public someDestinationsSpecificMethod() {\n * // logic\n * }\n * }\n **/\nexport class EntitiesStore {\n protected _initialized: boolean = false\n protected _state: { status: EntitiesStoreStatus; errorMessage: string } = observable({\n status: IDLE,\n errorMessage: \"\",\n })\n protected readonly type: EntityType\n protected readonly schema: EntitySchema\n protected readonly services: ApplicationServices\n\n _entities: T[] = []\n\n constructor(type: EntityType, schema: EntitySchema) {\n this.type = type\n this.schema = schema\n this.services = ApplicationServices.get()\n this.get = this.get.bind(this)\n makeObservable(this, {\n _entities: observable,\n status: computed,\n errorMessage: computed,\n list: computed,\n listHidden: computed,\n listIncludeHidden: computed,\n get: action.bound,\n pullAll: flow.bound,\n add: flow.bound,\n delete: flow.bound,\n replace: flow.bound,\n patch: flow.bound,\n })\n }\n\n protected setStatus(status: EntitiesStoreStatus) {\n this._state.status = status\n }\n\n protected setError(message: string) {\n this._state.status = GLOBAL_ERROR\n this._state.errorMessage = message\n }\n\n protected resetError() {\n this._state.errorMessage = \"\"\n this._state.status = IDLE\n }\n\n protected getId(entity: T): string {\n return entity[this.schema.idField]\n }\n\n public get list() {\n return this.schema.hideElements\n ? this._entities.filter(element => !this.schema.hideElements(element))\n : this._entities\n }\n\n public get listHidden() {\n return this.schema.hideElements ? this._entities.filter(element => this.schema.hideElements(element)) : []\n }\n\n public get listIncludeHidden() {\n return this._entities\n }\n\n public get status() {\n return this._state.status\n }\n\n public get isInitialized(): boolean {\n return this._initialized\n }\n\n public get errorMessage() {\n return this._state.errorMessage\n }\n\n public get(id: string): T | null {\n return this.list.find(entity => this.getId(entity) === id)\n }\n\n public *pullAll(options?: { showGlobalLoader?: boolean }) {\n const { showGlobalLoader } = options ?? { showGlobalLoader: false }\n this.resetError()\n this.setStatus(showGlobalLoader ? GLOBAL_LOADING : BACKGROUND_LOADING)\n try {\n const entities = yield this.services.storageService.table(this.type).getAll()\n this._entities = entities ?? []\n this._initialized = true\n } catch (error) {\n this.setError(`Failed to fetch ${this.type}: ${error.message || error}`)\n } finally {\n this.setStatus(IDLE)\n }\n }\n\n public *add(entityToAdd: T): Generator {\n this.resetError()\n this.setStatus(BACKGROUND_LOADING)\n try {\n const addedEntity = yield this.services.storageService.table(this.type).add(entityToAdd)\n if (!addedEntity) {\n throw new Error(`Error: '${this.type}' store failed to add an entity ${entityToAdd}`)\n }\n this._entities.push(addedEntity)\n return addedEntity\n } finally {\n this.setStatus(IDLE)\n }\n }\n\n public *delete(id: string) {\n this.resetError()\n this.setStatus(BACKGROUND_LOADING)\n try {\n yield this.services.storageService.table(this.type).delete(id)\n remove(this._entities, entity => this.getId(entity) === id)\n } finally {\n this.setStatus(IDLE)\n }\n }\n\n public *replace(entity: T) {\n this.resetError()\n this.setStatus(BACKGROUND_LOADING)\n try {\n const index = this._entities.findIndex(item => this.getId(item) === this.getId(entity))\n if (index >= 0) {\n yield this.services.storageService.table(this.type).replace(this.getId(entity), entity)\n this._entities[index] = entity\n } else {\n throw new Error(`Error: ${this.type} store failed to replace entity in store. Entity: ${entity}`)\n }\n } finally {\n this.setStatus(IDLE)\n }\n }\n\n public *patch(id: string, patch: Partial) {\n this.resetError()\n this.setStatus(BACKGROUND_LOADING)\n try {\n if (getObjectDepth(patch) > 2) {\n throw new Error(`Entities recursive patch is not supported`)\n }\n yield this.services.storageService.table(this.type).patch(id, patch)\n Object.assign(this.get(id), patch)\n } finally {\n this.setStatus(IDLE)\n }\n }\n}\n","import { without } from \"lodash\"\nimport { EntitiesStore, EntityData } from \"stores/entitiesStore\"\nimport { ApiKeysStore, apiKeysStore } from \"stores/apiKeys\"\nimport { sourcesStore, SourcesStore } from \"stores/sources\"\nimport { destinationsStore, DestinationsStore } from \"stores/destinations\"\nimport { flowResult } from \"mobx\"\n\nclass ConnectionsHelper {\n private readonly sourcesStore: SourcesStore\n private readonly destinationsStore: DestinationsStore\n private readonly apiKeysStore: ApiKeysStore\n\n constructor(stores: { sources: SourcesStore; destinations: DestinationsStore; apiKeysStore: ApiKeysStore }) {\n this.sourcesStore = stores.sources\n this.destinationsStore = stores.destinations\n this.apiKeysStore = stores.apiKeysStore\n }\n\n public async unconnectDeletedApiKey(apiKeyId: string) {\n await this.updateDestinationsConnectionsToApiKey(apiKeyId, [])\n }\n\n public async unconnectDeletedSource(sourceId: string) {\n await this.updateDestinationsConnectionsToSource(sourceId, [])\n }\n\n public async unconnectDeletedDestination(destinationId: string) {\n await this.updateSourcesConnectionsToDestination(destinationId, [])\n }\n\n public async updateSourcesConnectionsToDestination(destinationId: string, connectedSourcesIds: string[]) {\n await this.updateEntitiesConnections(destinationId, connectedSourcesIds, {\n store: this.sourcesStore,\n idField: \"sourceId\",\n connectedEntitiesIdsField: \"destinations\",\n })\n }\n\n public async updateDestinationsConnectionsToSource(sourceId: string, connectedDestinationsIds: string[]) {\n await this.updateEntitiesConnections(sourceId, connectedDestinationsIds, {\n store: this.destinationsStore,\n idField: \"_uid\",\n connectedEntitiesIdsField: \"_sources\",\n })\n }\n\n public async updateDestinationsConnectionsToApiKey(apiKeyId: string, connectedDestinationsIds: string[]) {\n await this.updateEntitiesConnections(apiKeyId, connectedDestinationsIds, {\n store: this.destinationsStore,\n idField: \"_uid\",\n connectedEntitiesIdsField: \"_onlyKeys\",\n })\n }\n\n /**\n * Finds and unconnects non-existent entities that may exist due\n * to connections management errors in UI\n */\n public async healConnections() {\n if ([this.sourcesStore, this.destinationsStore, this.apiKeysStore].some(store => !store.isInitialized)) {\n return\n }\n\n const destinations = this.destinationsStore.listIncludeHidden\n const sources = this.sourcesStore.listIncludeHidden\n const apiKeys = this.apiKeysStore.listIncludeHidden\n\n const nonExistentApiKeys: string[] = []\n const nonExistentSources: string[] = []\n const existingApiKeys = apiKeys.map(key => key.uid)\n const existingSources = sources.map(src => src.sourceId)\n destinations.forEach(destination => {\n destination._onlyKeys?.forEach(key => {\n if (!existingApiKeys.includes(key)) nonExistentApiKeys.push(key)\n })\n destination._sources?.forEach(src => {\n if (!existingSources.includes(src)) nonExistentSources.push(src)\n })\n })\n\n const nonExistentDestinations: string[] = []\n const existingDestinations = destinations.map(key => key._uid)\n sources.forEach(source => {\n source.destinations.forEach(dst => {\n if (!existingDestinations.includes(dst)) nonExistentDestinations.push(dst)\n })\n })\n\n await Promise.all([\n ...nonExistentApiKeys.map(nonExistentKey => this.unconnectDeletedApiKey(nonExistentKey)),\n ...nonExistentSources.map(nonExistentSrc => this.unconnectDeletedSource(nonExistentSrc)),\n ...nonExistentDestinations.map(nonExistentKey => this.unconnectDeletedDestination(nonExistentKey)),\n ])\n }\n\n /**\n * Updates entities specified in `connectedEntitiesIds` by an entity to the other entities in the list (if not already connected) or disconnects\n * this entity from all entities that are not in the list (if there are ones that connected)\n * @param entityId - entity that will be connected to the every entity in the following list\n * @param connectedEntitiesIds - list of entities that will be connected to the entity specified as the first parameter\n * @param connectedEntitiesSchema - schema of the entities in the list\n *\n * @example\n *\n * // will disconnect all connected destinations from source with `sourceId`\n * await this.updateEntitiesConnections(sourceId, [], {\n * store: this.destinationsStore,\n * idField: \"_uid\",\n * connectedEntitiesIdsField: \"_sources\",\n * })\n *\n * // will connect source with id `sourceId` to all destination with `connectedDestinationsIds` and will de\n * // will disconnect all non-listed destinations in `connectedDestinationsIds` from source with `sourceId`\n * await this.updateEntitiesConnections(sourceId, connectedDestinationsIds, {\n * store: this.destinationsStore,\n * idField: \"_uid\",\n * connectedEntitiesIdsField: \"_sources\",\n * })\n */\n private async updateEntitiesConnections(\n entityId: string,\n connectedEntitiesIds: string[],\n connectedEntitiesSchema: { store: EntitiesStore; idField: string; connectedEntitiesIdsField: string }\n ): Promise {\n const patches: { [id: string]: Partial } = {}\n const { connectedEntitiesIdsField } = connectedEntitiesSchema\n connectedEntitiesSchema.store.list.forEach(entity => {\n const entityShouldBeConnected = connectedEntitiesIds.includes(entity[connectedEntitiesSchema.idField])\n const entityIsConnected = !!entity[connectedEntitiesIdsField]?.includes(entityId)\n if (entityIsConnected === entityShouldBeConnected) return\n\n if (entityShouldBeConnected) {\n patches[entity[connectedEntitiesSchema.idField]] = {\n [connectedEntitiesIdsField]: [...(entity[connectedEntitiesIdsField] ?? []), entityId],\n } as any\n } else {\n patches[entity[connectedEntitiesSchema.idField]] = {\n [connectedEntitiesIdsField]: without(entity[connectedEntitiesIdsField] ?? [], entityId),\n } as any\n }\n })\n\n await Promise.all(\n Object.entries(patches).map(([entityId, patch]) => {\n return flowResult(connectedEntitiesSchema.store.patch(entityId, patch))\n })\n )\n }\n}\n\nexport const connectionsHelper = new ConnectionsHelper({\n sources: sourcesStore,\n destinations: destinationsStore,\n apiKeysStore: apiKeysStore,\n})\n","// @Libs\nimport { makeAutoObservable } from \"mobx\"\nimport React from \"react\"\n// @Reference\nimport { destinationsReferenceMap } from \"@jitsu/catalog\"\nimport { allSourcesMap } from \"@jitsu/catalog\"\n// @Routes\nimport { destinationPageRoutes } from \"ui/pages/DestinationsPage/DestinationsPage.routes\"\nimport { sourcesPageRoutes } from \"ui/pages/SourcesPage/SourcesPage.routes\"\n// @Stores\nimport { destinationsStore } from \"./destinations\"\nimport { apiKeysStore } from \"./apiKeys\"\nimport { sourcesStore } from \"./sources\"\nimport { apiKeysReferenceMap } from \"@jitsu/catalog\"\nimport { projectRoute } from \"lib/components/ProjectLink/ProjectLink\"\nimport { apiKeysRoutes } from \"lib/components/ApiKeys/ApiKeysRouter\"\n\nexport type NotificationData = {\n id: string\n title?: string | React.ReactNode\n message: string\n type: \"danger\" | \"error\" | \"warning\" | \"info\"\n icon?: React.ReactNode\n editEntityRoute: string\n}\n\ninterface IInAppNotificationsStore {\n notifications: NotificationData[]\n hasNotifications: boolean\n}\n\nclass InAppNotificationsStore implements IInAppNotificationsStore {\n private _destinationsStore = destinationsStore\n private _apiKeysStore = apiKeysStore\n private _connectorsStore = sourcesStore\n\n constructor() {\n makeAutoObservable(this)\n }\n\n private get orphanApiKeys(): ApiKey[] {\n return this._apiKeysStore.list.filter(({ uid }) => {\n const keyIsConnected = this._destinationsStore.list.reduce(\n (isConnected, destination) => isConnected || destination._onlyKeys.some(keyUid => keyUid === uid),\n false\n )\n return !keyIsConnected\n })\n }\n\n private get orphanDestinations(): DestinationData[] {\n return this._destinationsStore.list.filter(({ _onlyKeys, _sources }) => !_onlyKeys?.length && !_sources?.length)\n }\n\n private get orphanConnectors(): SourceData[] {\n return this._connectorsStore.list.filter(({ destinations }) => !destinations?.length)\n }\n\n public get notifications(): NotificationData[] {\n return [\n ...this.orphanDestinations.map(({ _id, _type }) => ({\n id: _id,\n title: _id,\n message: `The destination does not have any linked Connectors or API keys and thus will not recieve data.`,\n type: \"danger\" as const,\n icon: destinationsReferenceMap[_type]?.ui.icon,\n editEntityRoute: projectRoute(`${destinationPageRoutes.editExact}`, { id: _id }),\n })),\n ...this.orphanApiKeys.map(({ uid }) => ({\n id: uid,\n title: `API Key ${uid}`,\n message: `The API key is not linked to any destination. Events from pixels using this key will be lost.`,\n type: \"danger\" as const,\n icon: apiKeysReferenceMap.js.icon,\n editEntityRoute: projectRoute(apiKeysRoutes.editExact, { id: uid }),\n })),\n ...this.orphanConnectors.map(({ sourceId, sourceProtoType }) => ({\n id: sourceId,\n title: sourceId,\n message: `The source does not have a linked destination to send events to. Data sync is stopped.`,\n type: \"danger\" as const,\n icon: allSourcesMap[sourceProtoType]?.pic,\n editEntityRoute: projectRoute(`${sourcesPageRoutes.editExact}`, { sourceId }),\n })),\n ]\n }\n\n public get hasNotifications(): boolean {\n return !!this.notifications.length\n }\n}\n\nexport const inAppNotificationsStore = new InAppNotificationsStore()\n","import AnalyticsService from \"lib/services/analytics\"\nimport { flowResult } from \"mobx\"\nimport { apiKeysStore } from \"./apiKeys\"\nimport { destinationsStore } from \"./destinations\"\nimport { connectionsHelper } from \"./helpers\"\nimport { sourcesStore } from \"./sources\"\n\nexport const initializeAllStores = async (analyticsService: AnalyticsService): Promise => {\n await initalizeStoresData()\n try {\n await connectionsHelper.healConnections()\n } catch (error) {\n analyticsService.onGlobalError(new Error(`Failed to heal connections after stores initialization: ${error}`))\n }\n}\n\nconst initalizeStoresData = (): Promise<\n [PromiseSettledResult, PromiseSettledResult, PromiseSettledResult]\n> =>\n Promise.allSettled([\n flowResult(apiKeysStore.pullAll({ showGlobalLoader: true })),\n flowResult(destinationsStore.pullAll({ showGlobalLoader: true })),\n flowResult(sourcesStore.pullAll({ showGlobalLoader: true })),\n ])\n","// @Libs\nimport { flowResult, makeObservable, flow, override } from \"mobx\"\n// @Services\nimport ApplicationServices from \"lib/services/ApplicationServices\"\n// @Utils\nimport { randomId } from \"utils/numbers\"\nimport { EntitiesStore, EntitiesStoreStatus } from \"./entitiesStore\"\n\n//const services = ApplicationServices.get()\nexport class ApiKeysStore extends EntitiesStore {\n protected readonly services: ApplicationServices\n\n constructor() {\n super(\"api_keys\", { idField: \"uid\" })\n this.services = ApplicationServices.get()\n makeObservable(this, {\n add: override,\n generateAddInitialApiKeyIfNeeded: flow,\n })\n }\n\n public *add(key?: Partial): Generator {\n this.resetError()\n this.setStatus(EntitiesStoreStatus.BACKGROUND_LOADING)\n const newApiKey: ApiKey = { ...this.generateApiKey(key.comment), ...(key ?? {}) }\n try {\n const addedApiKey = yield this.services.storageService.table(\"api_keys\").add(newApiKey)\n if (!addedApiKey) {\n throw new Error(`API keys store failed to add a new key: ${newApiKey}`)\n }\n this._entities.push(addedApiKey)\n return addedApiKey\n } finally {\n this.setStatus(EntitiesStoreStatus.IDLE)\n }\n }\n\n public generateApiKey(comment?: string): ApiKey {\n return {\n uid: this.generateApiToken(\"\", 6),\n serverAuth: this.generateApiToken(\"s2s\"),\n jsAuth: this.generateApiToken(\"js\"),\n comment,\n origins: [],\n }\n }\n\n public generateApiToken(type: string, len?: number): string {\n const postfix = `${ApplicationServices.get().activeProject.id}.${randomId(len)}`\n return type.length > 0 ? `${type}.${postfix}` : postfix\n }\n\n public *generateAddInitialApiKeyIfNeeded(options?: { note?: string }) {\n if (!!this.list.length) return\n yield flowResult(this.add({ comment: options?.note }))\n }\n}\n\nexport const apiKeysStore = new ApiKeysStore()\n"],"sourceRoot":""}