Files
simstudioai--sim/apps/sim/tools/new_relic/utils.ts
T
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

67 lines
1.9 KiB
TypeScript

import type { NewRelicEntity, NewRelicRegion } from '@/tools/new_relic/types'
interface GraphQLError {
message?: string
}
export interface NewRelicRawEntity {
guid?: string | null
name?: string | null
entityType?: string | null
domain?: string | null
reporting?: boolean | null
alertSeverity?: string | null
tags?: ({ key?: string | null; values?: string[] | null } | null)[] | null
}
interface GraphQLResponse<TData> {
data?: TData
errors?: GraphQLError[]
}
export const getNerdGraphEndpoint = (region?: NewRelicRegion): string =>
region === 'eu' ? 'https://api.eu.newrelic.com/graphql' : 'https://api.newrelic.com/graphql'
export const newRelicHeaders = (apiKey: string): Record<string, string> => ({
'API-Key': apiKey,
'Content-Type': 'application/json',
})
export const gqlString = (value: string): string => JSON.stringify(value)
export async function parseNerdGraphResponse<TData>(
response: Response
): Promise<GraphQLResponse<TData>> {
const payload = (await response.json().catch(() => ({}))) as GraphQLResponse<TData>
if (!response.ok || payload.errors?.length) {
const message =
payload.errors
?.map((error) => error.message)
.filter((errorMessage): errorMessage is string => Boolean(errorMessage))
.join('; ') || `HTTP ${response.status}: ${response.statusText}`
throw new Error(message)
}
return payload
}
export const cleanOptionalString = (value?: string): string | undefined => {
const trimmed = value?.trim()
return trimmed ? trimmed : undefined
}
export const normalizeNewRelicEntity = (entity: NewRelicRawEntity): NewRelicEntity => ({
guid: entity.guid ?? null,
name: entity.name ?? null,
entityType: entity.entityType ?? null,
domain: entity.domain ?? null,
reporting: entity.reporting ?? null,
alertSeverity: entity.alertSeverity ?? null,
tags:
entity.tags?.map((tag) => ({
key: tag?.key ?? null,
values: tag?.values ?? [],
})) ?? [],
})