mirror of
https://github.com/LukeHagar/idn-admin-console.git
synced 2025-12-07 12:37:46 +00:00
Remove unused code and update promise types in report pages
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { createConfiguration } from '$lib/sailpoint/sdk.js';
|
import { createConfiguration } from '$lib/sailpoint/sdk.js';
|
||||||
import { getToken } from '$lib/utils/oauth.js';
|
import { getToken } from '$lib/utils/oauth.js';
|
||||||
import { SearchApi, type Search, Paginator } from 'sailpoint-api-client';
|
import { SearchApi, type Search, Paginator, type IdentityDocument } from 'sailpoint-api-client';
|
||||||
|
|
||||||
export const load = async ({ cookies }) => {
|
export const load = async ({ cookies }) => {
|
||||||
const search: Search = {
|
const search: Search = {
|
||||||
@@ -16,7 +16,13 @@ export const load = async ({ cookies }) => {
|
|||||||
|
|
||||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
||||||
const api = new SearchApi(config);
|
const api = new SearchApi(config);
|
||||||
const reportData = (await Paginator.paginateSearchApi(api, search, 100, 20000)).data;
|
const reportResp = Paginator.paginateSearchApi(api, search, 100, 20000);
|
||||||
|
|
||||||
|
const reportData = new Promise<IdentityDocument[]>((resolve) => {
|
||||||
|
reportResp.then((response) => {
|
||||||
|
resolve(response.data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return { reportData };
|
return { reportData };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createConfiguration } from '$lib/sailpoint/sdk.js';
|
import { createConfiguration } from '$lib/sailpoint/sdk.js';
|
||||||
import { getToken } from '$lib/utils/oauth.js';
|
import { getToken } from '$lib/utils/oauth.js';
|
||||||
import { SearchApi, type Search, Paginator } from 'sailpoint-api-client';
|
import { Paginator, SearchApi, type IdentityDocument, type Search } from 'sailpoint-api-client';
|
||||||
|
|
||||||
export const load = async ({ cookies }) => {
|
export const load = async ({ cookies }) => {
|
||||||
const search: Search = {
|
const search: Search = {
|
||||||
@@ -16,7 +16,13 @@ export const load = async ({ cookies }) => {
|
|||||||
|
|
||||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
||||||
const api = new SearchApi(config);
|
const api = new SearchApi(config);
|
||||||
const reportData = (await Paginator.paginateSearchApi(api, search, 100, 20000)).data;
|
const searchResp = Paginator.paginateSearchApi(api, search, 100, 20000);
|
||||||
|
|
||||||
|
const reportData = new Promise<IdentityDocument[]>((resolve) => {
|
||||||
|
searchResp.then((response) => {
|
||||||
|
resolve(response.data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return { reportData };
|
return { reportData };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { createConfiguration } from '$lib/sailpoint/sdk';
|
||||||
|
import { getSession, getToken } from '$lib/utils/oauth';
|
||||||
|
import { Paginator, SearchApi, type Search, type EventDocument } from 'sailpoint-api-client';
|
||||||
|
|
||||||
|
export const load = async ({ cookies }) => {
|
||||||
|
const session = await getSession(cookies);
|
||||||
|
const idnSession = await getToken(cookies);
|
||||||
|
|
||||||
|
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
||||||
|
const api = new SearchApi(config);
|
||||||
|
const search: Search = {
|
||||||
|
indices: ['events'],
|
||||||
|
query: {
|
||||||
|
query: `name: "Create Account Failed" AND created: [now-90d TO now]`
|
||||||
|
},
|
||||||
|
sort: ['created']
|
||||||
|
};
|
||||||
|
|
||||||
|
const searchResp = Paginator.paginateSearchApi(api, search, 100, 20000);
|
||||||
|
|
||||||
|
const errorEvents = new Promise<EventDocument[]>((resolve) => {
|
||||||
|
searchResp.then((response) => {
|
||||||
|
resolve(response.data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return { errorEvents };
|
||||||
|
};
|
||||||
@@ -1,10 +1,150 @@
|
|||||||
import type { SourceEvents } from '$lib/Types.js';
|
import { getFilters, getLimit, getPage, getSorters } from '$lib/Utils.js';
|
||||||
import type { Source } from 'sailpoint-api-client';
|
import { createConfiguration } from '$lib/sailpoint/sdk.js';
|
||||||
|
import { getToken } from '$lib/utils/oauth.js';
|
||||||
|
import {
|
||||||
|
SearchApi,
|
||||||
|
SourcesApi,
|
||||||
|
type EventDocument,
|
||||||
|
type Search,
|
||||||
|
type SourcesApiListSourcesRequest,
|
||||||
|
type Source
|
||||||
|
} from 'sailpoint-api-client';
|
||||||
|
|
||||||
export const load = async ({ fetch }) => {
|
export const load = async ({ cookies, url }) => {
|
||||||
const aggData: { sources: Source[]; events: SourceEvents[] } = (
|
const session = JSON.parse(cookies.get('session')!);
|
||||||
await fetch('/api/sailpoint/sourceAggEvents')
|
const idnSession = await getToken(cookies);
|
||||||
).json();
|
|
||||||
|
|
||||||
return { aggData };
|
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
||||||
|
const sourceApi = new SourcesApi(config);
|
||||||
|
const searchApi = new SearchApi(config);
|
||||||
|
|
||||||
|
const page = getPage(url);
|
||||||
|
const filters = getFilters(url);
|
||||||
|
const limit = getLimit(url);
|
||||||
|
const sorters = getSorters(url);
|
||||||
|
|
||||||
|
const requestParams: SourcesApiListSourcesRequest = {
|
||||||
|
filters,
|
||||||
|
offset: Number(page) * Number(limit),
|
||||||
|
limit: Number(limit),
|
||||||
|
sorters,
|
||||||
|
count: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = sourceApi.listSources(requestParams);
|
||||||
|
|
||||||
|
const sources = new Promise<Source[]>((resolve) => {
|
||||||
|
apiResponse
|
||||||
|
.then((response) => {
|
||||||
|
resolve(response.data);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const totalCount = new Promise<number>((resolve) => {
|
||||||
|
apiResponse
|
||||||
|
.then((response) => {
|
||||||
|
resolve(response.headers['x-total-count']);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
type SourceEvents = {
|
||||||
|
accounts: { started: EventDocument | undefined; passed: EventDocument | undefined };
|
||||||
|
entitlements: { started: EventDocument | undefined; passed: EventDocument | undefined };
|
||||||
|
};
|
||||||
|
|
||||||
|
const eventNames: string[] = [
|
||||||
|
'Aggregate Source Account Passed',
|
||||||
|
'Aggregate Source Account Started',
|
||||||
|
'Aggregate Source Entitlement Passed',
|
||||||
|
'Aggregate Source Entitlement Started'
|
||||||
|
];
|
||||||
|
|
||||||
|
const eventsMap = new Promise<Map<string, SourceEvents>>((resolve) => {
|
||||||
|
sources.then(async (sources) => {
|
||||||
|
const sourceEventsMap = new Map<string, SourceEvents>();
|
||||||
|
|
||||||
|
for (const source of sources) {
|
||||||
|
const allEvents: EventDocument[] = [];
|
||||||
|
const promises: Promise<EventDocument[]>[] = [];
|
||||||
|
|
||||||
|
for (const event of eventNames) {
|
||||||
|
const search: Search = {
|
||||||
|
indices: ['events'],
|
||||||
|
query: {
|
||||||
|
query: `target.name: "${source.name}" AND name:"${event}"`
|
||||||
|
},
|
||||||
|
sort: ['created']
|
||||||
|
};
|
||||||
|
|
||||||
|
promises.push(
|
||||||
|
searchApi
|
||||||
|
.searchPost({
|
||||||
|
search
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
return response.data;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw err;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.allSettled(promises).then((results) => {
|
||||||
|
for (const event of results) {
|
||||||
|
if (event.status == 'fulfilled' && event.value.length > 0) {
|
||||||
|
allEvents.push(event.value[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceEvents: SourceEvents = {
|
||||||
|
accounts: { started: undefined, passed: undefined },
|
||||||
|
entitlements: { started: undefined, passed: undefined }
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const event of allEvents) {
|
||||||
|
if (event.attributes!.sourceName === source.name) {
|
||||||
|
switch (event.technicalName) {
|
||||||
|
case 'SOURCE_ACCOUNT_AGGREGATE_STARTED':
|
||||||
|
if (!sourceEvents.accounts.started) {
|
||||||
|
sourceEvents.accounts.started = event || undefined;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'SOURCE_ACCOUNT_AGGREGATE_PASSED':
|
||||||
|
if (!sourceEvents.accounts.passed) {
|
||||||
|
sourceEvents.accounts.passed = event || undefined;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'SOURCE_ENTITLEMENT_AGGREGATE_STARTED':
|
||||||
|
if (!sourceEvents.entitlements.started) {
|
||||||
|
sourceEvents.entitlements.started = event || undefined;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'SOURCE_ENTITLEMENT_AGGREGATE_PASSED':
|
||||||
|
if (!sourceEvents.entitlements.passed) {
|
||||||
|
sourceEvents.entitlements.passed = event || undefined;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceEventsMap.set(source.name, sourceEvents);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(sourceEventsMap);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return { sources, eventsMap, totalCount, params: { page, limit, filters, sorters } };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
export const load = async ({ fetch }) => {
|
|
||||||
const response = fetch('/api/sailpoint/sources', {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'content-type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return { response };
|
|
||||||
};
|
|
||||||
@@ -25,10 +25,10 @@ export const load = async ({ cookies, url }) => {
|
|||||||
|
|
||||||
const apiResponse = api.listSources(requestParams);
|
const apiResponse = api.listSources(requestParams);
|
||||||
|
|
||||||
const sources = new Promise((resolve) => {
|
const sources = new Promise<Source[]>((resolve) => {
|
||||||
apiResponse
|
apiResponse
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
resolve(response.data as Source[]);
|
resolve(response.data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
Reference in New Issue
Block a user