Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

3.7 KB
Raw Blame
export const analyticsKeys = {
  // logs/reports endpoints
  functionsCombinedStats: (
    projectRef: string | undefined,
    {
      interval,
      functionId,
    }: {
      functionId: string | undefined
      interval: string | undefined
    }
  ) =>
    [
      'projects',
      projectRef,
      'functions-combined-stats',
      {
        interval,
        functionId,
      },
    ] as const,
  functionsInvStats: (
    projectRef: string | undefined,
    {
      interval,
      functionId,
    }: {
      functionId: string | undefined
      interval: string | undefined
    }
  ) =>
    [
      'projects',
      projectRef,
      'functions-inv-stats',
      {
        interval,
        functionId,
      },
    ] as const,
  functionsReqStats: (
    projectRef: string | undefined,
    {
      interval,
      functionId,
    }: {
      functionId: string | undefined
      interval: string | undefined
    }
  ) =>
    [
      'projects',
      projectRef,
      'functions-req-stats',
      {
        interval,
        functionId,
      },
    ] as const,
  functionsResourceUsage: (
    projectRef: string | undefined,
    {
      interval,
      functionId,
    }: {
      functionId: string | undefined
      interval: string | undefined
    }
  ) =>
    [
      'projects',
      projectRef,
      'functions-resource-usage',
      {
        interval,
        functionId,
      },
    ] as const,

  orgDailyStats: (
    orgSlug: string | undefined,
    {
      startDate,
      endDate,
      projectRef,
    }: {
      startDate?: string
      endDate?: string
      projectRef?: string
    }
  ) =>
    [
      'organizations',
      orgSlug,
      'daily-stats',
      {
        startDate: isoDateStringToDate(startDate),
        endDate: isoDateStringToDate(endDate),
        projectRef,
      },
    ] as const,
  infraMonitoring: (
    projectRef: string | undefined,
    {
      attribute,
      startDate,
      endDate,
      interval,
      databaseIdentifier,
    }: {
      attribute?: string
      startDate?: string
      endDate?: string
      interval?: string
      databaseIdentifier?: string
    }
  ) =>
    [
      'projects',
      projectRef,
      'infra-monitoring',
      { attribute, startDate, endDate, interval, databaseIdentifier },
    ] as const,
  infraMonitoringGroup: (
    projectRef: string | undefined,
    {
      attributes,
      startDate,
      endDate,
      interval,
      databaseIdentifier,
    }: {
      attributes?: string[]
      startDate?: string
      endDate?: string
      interval?: string
      databaseIdentifier?: string
    }
  ) =>
    [
      'projects',
      projectRef,
      'infra-monitoring',
      'group',
      {
        attributes: attributes ? [...attributes].sort() : undefined,
        startDate,
        endDate,
        interval,
        databaseIdentifier,
      },
    ] as const,
  apiKeysLastUsed: (
    projectRef: string | undefined,
    {
      isoTimestampStart,
      isoTimestampEnd,
    }: {
      isoTimestampStart?: string
      isoTimestampEnd?: string
    }
  ) =>
    ['projects', projectRef, 'api-keys-last-used', { isoTimestampStart, isoTimestampEnd }] as const,
  usageApiCounts: (projectRef: string | undefined, interval: string | undefined) =>
    ['projects', projectRef, 'usage.api-counts', interval] as const,

  serviceHealth: (
    projectRef: string | undefined,
    {
      startDate,
      endDate,
      granularity,
    }: {
      startDate?: string
      endDate?: string
      granularity?: string
    }
  ) => ['projects', projectRef, 'service-health', { startDate, endDate, granularity }] as const,
}

function isoDateStringToDate(isoDateString: string | undefined): string | undefined {
  if (!isoDateString) return isoDateString

  return isoDateString.split('T')[0]
}