Catalyst / admin/Synapse-Cortex 14.8 GB / 57.8 GB 40.0 GB free
Help Sign in

admin / Synapse-Cortex

public

Self Hosted ITSM Tool with RBAC/Tenanting and MFA

Code Issues Pull requests Pipelines Packages Security Insights Wiki Settings
Synapse-Cortex / Synapse-Cortexv2 / frontend / src / api / playbooks.ts 2315 B · main
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { api } from './client'
import type { ApprovalLevel, PlaybookGraph, PlaybookImportResult, PlaybookOut } from './types'

export interface PlaybookCreatePayload {
  name: string
  enabled?: boolean
  graph_json: PlaybookGraph
  allowed_target_os: string[]
  required_approval_level?: ApprovalLevel
  forbidden_commands: string[]
  acknowledged_dangerous_commands?: string[]
}

/** The portable, importable/exportable shape of a playbook - exactly the
 * fields the backend's create/import accepts, with none of the
 * instance-specific ones (id, tenant_id, timestamps). A file may hold one
 * of these or an array of them. */
export interface PlaybookExport {
  name: string
  enabled: boolean
  graph_json: PlaybookGraph
  allowed_target_os: string[]
  required_approval_level: ApprovalLevel
  forbidden_commands: string[]
  acknowledged_dangerous_commands?: string[]
}

export interface PlaybookUpdatePayload {
  name?: string
  enabled?: boolean
  graph_json?: PlaybookGraph
  allowed_target_os?: string[]
  required_approval_level?: ApprovalLevel
  forbidden_commands?: string[]
  acknowledged_dangerous_commands?: string[]
}

export const playbooksApi = {
  list: () => api.get<PlaybookOut[]>('/api/v1/playbooks'),
  get: (id: string) => api.get<PlaybookOut>(`/api/v1/playbooks/${id}`),
  create: (payload: PlaybookCreatePayload) => api.post<PlaybookOut>('/api/v1/playbooks', payload),
  update: (id: string, payload: PlaybookUpdatePayload) => api.patch<PlaybookOut>(`/api/v1/playbooks/${id}`, payload),
  toggle: (id: string) => api.patch<PlaybookOut>(`/api/v1/playbooks/${id}/toggle`),
  delete: (id: string) => api.delete<void>(`/api/v1/playbooks/${id}`),
  import: (playbooks: PlaybookExport[]) =>
    api.post<PlaybookImportResult>('/api/v1/playbooks/import', { playbooks }),
}

/** Reduces a full PlaybookOut to its portable export shape (drops id,
 * tenant_id, timestamps) so the downloaded file is re-importable as-is. */
export function toPlaybookExport(p: PlaybookOut): PlaybookExport {
  return {
    name: p.name,
    enabled: p.enabled,
    graph_json: p.graph_json,
    allowed_target_os: p.allowed_target_os,
    required_approval_level: p.required_approval_level,
    forbidden_commands: p.forbidden_commands,
    acknowledged_dangerous_commands: p.acknowledged_dangerous_commands,
  }
}