mirror of
https://github.com/LukeHagar/idn-admin-console.git
synced 2025-12-06 04:20:02 +00:00
Add server-side code to load identity data and events
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { createConfiguration } from '$lib/sailpoint/sdk';
|
||||
import { getSession, getToken } from '$lib/utils/oauth';
|
||||
import {
|
||||
IdentitiesBetaApi,
|
||||
SearchApi,
|
||||
type EventDocument,
|
||||
type IdentityBeta,
|
||||
type Search
|
||||
} from 'sailpoint-api-client';
|
||||
|
||||
export const load = async ({ cookies, params }) => {
|
||||
const session = await getSession(cookies);
|
||||
const idnSession = await getToken(cookies);
|
||||
|
||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
||||
const identityApi = new IdentitiesBetaApi(config);
|
||||
const searchApi = new SearchApi(config);
|
||||
|
||||
const identityResp = identityApi.getIdentity({ id: params.identityID });
|
||||
|
||||
const identityData = new Promise<IdentityBeta>((resolve) => {
|
||||
identityResp
|
||||
.then((response) => {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
const identityEvents = new Promise<EventDocument[]>((resolve) => {
|
||||
identityResp.then((response) => {
|
||||
const identity = response.data;
|
||||
const search: Search = {
|
||||
indices: ['events'],
|
||||
query: {
|
||||
query: `target.name: "${identity.name}"`
|
||||
},
|
||||
sort: ['created']
|
||||
};
|
||||
|
||||
searchApi
|
||||
.searchPost({
|
||||
search
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return { identityData, identityEvents };
|
||||
};
|
||||
Reference in New Issue
Block a user