d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import { getErrorMessage } from '@sim/utils/errors'
|
|
import type { Workflow } from '@/tools/incidentio/types'
|
|
|
|
function toStringValue(value: unknown): string {
|
|
return typeof value === 'string' ? value : String(value ?? '')
|
|
}
|
|
|
|
function toOptionalStringValue(value: unknown): string | undefined {
|
|
return typeof value === 'string' && value ? value : undefined
|
|
}
|
|
|
|
function toNumberValue(value: unknown): number {
|
|
return typeof value === 'number' ? value : Number(value ?? 0)
|
|
}
|
|
|
|
function toBooleanValue(value: unknown): boolean {
|
|
return value === true
|
|
}
|
|
|
|
function toArrayValue<T = unknown>(value: unknown): T[] {
|
|
return Array.isArray(value) ? (value as T[]) : []
|
|
}
|
|
|
|
export function parseIncidentioJsonParam(
|
|
jsonString: string | undefined,
|
|
paramName: string,
|
|
defaultValue: unknown
|
|
): unknown {
|
|
if (jsonString === undefined || jsonString === '') return defaultValue
|
|
|
|
try {
|
|
return JSON.parse(jsonString)
|
|
} catch (error) {
|
|
throw new Error(`Invalid JSON for ${paramName}: ${getErrorMessage(error)}`)
|
|
}
|
|
}
|
|
|
|
export function parseRequiredIncidentioJsonParam(
|
|
jsonString: string | undefined,
|
|
paramName: string
|
|
): unknown {
|
|
if (jsonString === undefined || jsonString === '') {
|
|
throw new Error(`Missing required JSON for ${paramName}`)
|
|
}
|
|
|
|
return parseIncidentioJsonParam(jsonString, paramName, undefined)
|
|
}
|
|
|
|
export function mapIncidentioWorkflow(workflow: Record<string, unknown>): Workflow {
|
|
return {
|
|
id: toStringValue(workflow.id),
|
|
name: toStringValue(workflow.name),
|
|
trigger: toStringValue(workflow.trigger),
|
|
once_for: toArrayValue(workflow.once_for),
|
|
version: toNumberValue(workflow.version),
|
|
expressions: toArrayValue(workflow.expressions),
|
|
condition_groups: toArrayValue(workflow.condition_groups),
|
|
steps: toArrayValue(workflow.steps),
|
|
include_private_incidents: toBooleanValue(workflow.include_private_incidents),
|
|
include_private_escalations: toBooleanValue(workflow.include_private_escalations),
|
|
runs_on_incident_modes: toArrayValue<string>(workflow.runs_on_incident_modes),
|
|
continue_on_step_error: toBooleanValue(workflow.continue_on_step_error),
|
|
runs_on_incidents: toStringValue(workflow.runs_on_incidents) as Workflow['runs_on_incidents'],
|
|
state: toStringValue(workflow.state) as Workflow['state'],
|
|
delay: workflow.delay,
|
|
folder: toOptionalStringValue(workflow.folder),
|
|
runs_from: toOptionalStringValue(workflow.runs_from),
|
|
shortform: toOptionalStringValue(workflow.shortform),
|
|
}
|
|
}
|