From 21b9e396a5d0473cbbd00ac92ba12931bb2ae2d1 Mon Sep 17 00:00:00 2001 From: MGJamJam Date: Mon, 6 May 2024 07:39:06 -0300 Subject: [PATCH] add AnalyticsLicenseType --- .../src/utils/licenses.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/bitmovin-analytics-datasource/src/utils/licenses.ts b/bitmovin-analytics-datasource/src/utils/licenses.ts index a9c8d15..c4b4107 100644 --- a/bitmovin-analytics-datasource/src/utils/licenses.ts +++ b/bitmovin-analytics-datasource/src/utils/licenses.ts @@ -2,31 +2,41 @@ import { lastValueFrom } from 'rxjs'; import { getBackendSrv } from '@grafana/runtime'; import { SelectableValue } from '@grafana/data'; +type AnalyticsLicense = { + readonly name: string; + readonly id: string; + readonly licenseKey?: string; +}; + const licenseEndpoints = [ { endpoint: '/analytics/licenses', - mapperFunc: (license: any): SelectableValue => ({ + mapperFunc: (license: AnalyticsLicense): SelectableValue => ({ value: license.licenseKey, label: license.name ? license.name : license.licenseKey, }), }, { endpoint: '/analytics/virtual-licenses', - mapperFunc: (license: any): SelectableValue => ({ + mapperFunc: (license: AnalyticsLicense): SelectableValue => ({ value: license.id, label: license.name ? license.name : license.id, }), }, { endpoint: '/analytics/demo-licenses', - mapperFunc: (license: any): SelectableValue => ({ + mapperFunc: (license: AnalyticsLicense): SelectableValue => ({ value: license.id, label: license.name ? license.name : license.id, }), }, ]; -async function fetchLicensesForEndpoint(url: string, apiKey: string, mapperFunc: (license: any) => SelectableValue) { +async function fetchLicensesForEndpoint( + url: string, + apiKey: string, + mapperFunc: (license: AnalyticsLicense) => SelectableValue +) { const options = { url: url, headers: { 'X-Api-Key': apiKey }, @@ -48,11 +58,11 @@ async function fetchLicensesForEndpoint(url: string, apiKey: string, mapperFunc: export async function fetchLicenses(apiKey: string, baseUrl: string): Promise { const allLicenses: SelectableValue[] = []; - for (const licenseEndpoints1 of licenseEndpoints) { + for (const licenseEndpoint of licenseEndpoints) { const licenses = await fetchLicensesForEndpoint( - baseUrl + licenseEndpoints1.endpoint, + baseUrl + licenseEndpoint.endpoint, apiKey, - licenseEndpoints1.mapperFunc + licenseEndpoint.mapperFunc ); allLicenses.push(...licenses); }