{ "version": 3, "sources": ["libs/crm/integrations/automation/src/row-actions/automation-actions.service.ts", "libs/crm/integrations/automation/src/crm-automation-integrations.module.ts", "libs/crm/integrations/automation/src/row-actions/automation-actions.ts", "libs/crm/integrations/automation/src/index.ts", "libs/crm/integrations/automation/public_api.ts", "libs/crm/integrations/automation/index.ts"], "sourcesContent": ["import { Inject, Injectable, Optional } from '@angular/core';\nimport { MatDialog } from '@angular/material/dialog';\nimport { Row } from '@vendasta/galaxy/table';\nimport { StartManualAutomationDialogComponent, StartManualAutomationDialogData } from '@galaxy/automata/shared';\nimport { Automation, Context, EntityType } from '@vendasta/automata';\nimport { AccessService, convertGalaxyFilters, CRM_ACCESS_SERVICE_TOKEN, CRMSelectAllOptions } from '@galaxy/crm/static';\nimport { combineLatest, firstValueFrom, of, take } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { SnackbarService } from '@vendasta/galaxy/snackbar-service';\nimport { StartManualAutomationsRequestInterface } from '@vendasta/crm-integrations/lib/_internal/interfaces';\nimport { CrmAutomationApiService } from '@vendasta/crm-integrations';\n\nconst PERMISSION_DENIED = 7;\n\nfunction contextForAutomation(namespace: string): Context {\n if (namespace.startsWith('AG-')) {\n return Context.AUTOMATION_CONTEXT_SMB;\n }\n return Context.AUTOMATION_CONTEXT_PARTNER;\n}\n\nfunction onlySalesRunnable(context: Context) {\n if (context === Context.AUTOMATION_CONTEXT_SMB) {\n return false;\n }\n return true;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class AutomationActionsService {\n constructor(\n private readonly dialog: MatDialog,\n private readonly crmAutomationService: CrmAutomationApiService,\n private readonly snackbarService: SnackbarService,\n @Optional() @Inject(CRM_ACCESS_SERVICE_TOKEN) private readonly accessService: AccessService,\n ) {}\n\n async openStartManualAutomationDialog(\n namespace: string,\n objectType: string,\n rows: Row[],\n dontStartAutomation: boolean,\n isListOfEntities?: boolean,\n ): Promise {\n const canModifyAutomations$ = this.accessService?.canModifyAutomations$\n ? this.accessService.canModifyAutomations$\n : of(false);\n const hasAdminAccess$ = this.accessService?.hasPartnerPermissions$\n ? this.accessService.hasPartnerPermissions$\n : of(false);\n const options = await firstValueFrom(\n combineLatest([canModifyAutomations$, hasAdminAccess$]).pipe(\n map(([editPermission, adminPermission]) => {\n return {\n hideSettingsLink: !editPermission,\n onlySalespersonAutomations: !adminPermission && onlySalesRunnable(contextForAutomation(namespace)),\n onlySelectDontStart: dontStartAutomation,\n isListOfEntities: isListOfEntities,\n };\n }),\n ),\n );\n\n let entityType = EntityType.ENTITY_TYPE_COMPANY;\n if (objectType === 'Contact') {\n entityType = EntityType.ENTITY_TYPE_CONTACT;\n }\n const entityMap: Map = new Map();\n entityMap.set(\n entityType,\n rows.map((row) => row.id),\n );\n const data = {\n namespace: namespace,\n entities: entityMap,\n context: contextForAutomation(namespace),\n options: options,\n } as StartManualAutomationDialogData;\n const dialog = this.dialog.open(StartManualAutomationDialogComponent, {\n data: data,\n width: '500px',\n });\n return firstValueFrom(dialog.afterClosed());\n }\n\n async openSelectAllStartManualAutomationDialog(\n namespace: string,\n objectType: string,\n options?: CRMSelectAllOptions,\n ): Promise {\n const automation = await this.openStartManualAutomationDialog(namespace, objectType, [], true);\n if (!automation) {\n return;\n }\n const request = {\n automationId: automation.id,\n criteria: {\n namespace: namespace,\n objectType: objectType,\n filters: convertGalaxyFilters(options?.filters || []),\n searchTerm: options?.search,\n },\n } as StartManualAutomationsRequestInterface;\n this.crmAutomationService\n .startManualAutomations(request)\n .pipe(take(1))\n .subscribe({\n next: () => {\n this.snackbarService.openSuccessSnack('AUTOMATIONS.MANUAL_AUTOMATIONS.AUTOMATION_STARTED', {\n interpolateTranslateParams: {\n name: automation.name,\n },\n });\n },\n error: (err) => {\n console.error(err);\n if (err.error.code === PERMISSION_DENIED) {\n this.snackbarService.openErrorSnack('AUTOMATIONS.EDITOR.ERRORS.PERMISSION_DENIED_STARTING_AUTOMATION');\n } else {\n this.snackbarService.openErrorSnack('AUTOMATIONS.EDITOR.ERRORS.ERROR_STARTING_AUTOMATION');\n }\n },\n });\n }\n}\n", "import { NgModule } from '@angular/core';\nimport { RouterModule, Routes } from '@angular/router';\nimport { TranslationModule } from '@galaxy/crm/static';\n\nimport { AutomationActionsService } from './row-actions/automation-actions.service';\nexport { AutomationActionsService };\n\nconst CRM_ROUTES: Routes = [];\n\n@NgModule({\n imports: [RouterModule.forChild(CRM_ROUTES), TranslationModule],\n exports: [RouterModule],\n providers: [AutomationActionsService],\n})\nexport class CrmAutomationIntegrationsModule {}\n", "import { SingleRowAction } from '@galaxy/crm/static';\nimport { AutomationActionsService } from './automation-actions.service';\nimport { CRMSelectAllOptions, MultiRowAction, SelectAllAction } from '@galaxy/crm/static';\nimport { Row } from '@vendasta/galaxy/table';\n\nexport function AutomationSingleRowAction(\n namespace: string,\n service: AutomationActionsService,\n objectType: string,\n label: string,\n): SingleRowAction {\n return {\n label: label,\n callback: (row) => {\n service.openStartManualAutomationDialog(namespace, objectType, [row], false);\n },\n };\n}\n\nexport function AutomationMultiRowAction(\n namespace: string,\n service: AutomationActionsService,\n objectType: string,\n label: string,\n): MultiRowAction {\n return {\n label: label,\n callback: (rows) => {\n service.openStartManualAutomationDialog(namespace, objectType, rows, false);\n },\n };\n}\n\nexport function AutomationSelectAllRowAction(\n namespace: string,\n service: AutomationActionsService,\n objectType: string,\n label: string,\n): SelectAllAction {\n return {\n label: label,\n callback: (rows: Row[], options?: CRMSelectAllOptions) => {\n service.openSelectAllStartManualAutomationDialog(namespace, objectType, options);\n },\n };\n}\n", "export * from './crm-automation-integrations.module';\nexport * from './row-actions/automation-actions';\nexport * from './row-actions/automation-actions.service';\n", "export * from './src';\n", "export * from './public_api';\n"], "mappings": "wYAcA,SAASA,EAAqBC,EAAiB,CAC7C,OAAIA,EAAUC,WAAW,KAAK,EACrBC,EAAQC,uBAEVD,EAAQE,0BACjB,CAEA,SAASC,EAAkBC,EAAgB,CACzC,OAAIA,IAAYJ,EAAQC,sBAI1B,CA1BA,IAYMI,EAiBOC,EA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,EAEJ,CAxCA,IAAAE,EAAAC,EAAA,QCLA,IAAAC,EAAAC,EAAA,KAAAC,IACAC,IACAC,MCFA,IAAAC,EAAAC,EAAA,KAAAC,MCAA,IAAAC,EAAAC,EAAA,KAAAC", "names": ["contextForAutomation", "namespace", "startsWith", "Context", "AUTOMATION_CONTEXT_SMB", "AUTOMATION_CONTEXT_PARTNER", "onlySalesRunnable", "context", "PERMISSION_DENIED", "AutomationActionsService", "init_automation_actions_service", "__esmMin", "init_src", "init_vendasta_automata", "init_esm", "init_operators", "constructor", "dialog", "crmAutomationService", "snackbarService", "accessService", "openStartManualAutomationDialog", "objectType", "rows", "dontStartAutomation", "isListOfEntities", "__async", "canModifyAutomations$", "of", "hasAdminAccess$", "hasPartnerPermissions$", "options", "firstValueFrom", "combineLatest", "pipe", "map", "editPermission", "adminPermission", "hideSettingsLink", "onlySalespersonAutomations", "onlySelectDontStart", "entityType", "EntityType", "ENTITY_TYPE_COMPANY", "ENTITY_TYPE_CONTACT", "entityMap", "Map", "set", "row", "id", "data", "entities", "open", "StartManualAutomationDialogComponent", "width", "afterClosed", "openSelectAllStartManualAutomationDialog", "automation", "request", "automationId", "criteria", "filters", "convertGalaxyFilters", "searchTerm", "search", "startManualAutomations", "take", "subscribe", "next", "openSuccessSnack", "interpolateTranslateParams", "name", "error", "err", "console", "code", "openErrorSnack", "\u0275\u0275inject", "MatDialog", "CrmAutomationApiService", "SnackbarService", "CRM_ACCESS_SERVICE_TOKEN", "factory", "\u0275fac", "providedIn", "init_crm_automation_integrations_module", "__esmMin", "init_automation_actions_service", "AutomationSingleRowAction", "namespace", "service", "objectType", "label", "callback", "row", "openStartManualAutomationDialog", "AutomationMultiRowAction", "rows", "AutomationSelectAllRowAction", "options", "openSelectAllStartManualAutomationDialog", "init_automation_actions", "__esmMin", "init_src", "__esmMin", "init_crm_automation_integrations_module", "init_automation_actions", "init_automation_actions_service", "init_public_api", "__esmMin", "init_src", "init_automation", "__esmMin", "init_public_api"] }