UNPKG

rhombus-node-mcp

Version:
46 lines (45 loc) 1.66 kB
import { postApi } from "../network/network.js"; export async function resolveUserUuid(email, requestModifiers, sessionId) { const res = await postApi({ route: "/user/findUserByEmail", body: { email }, modifiers: requestModifiers, sessionId, }); if (res.error) { throw new Error(res.errorMsg ?? "Failed to find user by email"); } const user = res.user; if (!user?.uuid) { throw new Error(`No user found with email: ${email}`); } const name = [user.firstName, user.lastName].filter(Boolean).join(" ") || undefined; return { uuid: user.uuid, name }; } export async function getAccessEventsByUser(userUuid, startTimeMs, endTimeMs, limit, requestModifiers, sessionId) { const body = { userUuid, limit: limit ?? 100, }; if (startTimeMs) body.createdAfterMs = startTimeMs; if (endTimeMs) body.createdBeforeMs = endTimeMs; const res = await postApi({ route: "/component/findComponentEventsByUser", body, modifiers: requestModifiers, sessionId, }); const events = res.componentEvents ?? []; return events.map((evt) => ({ eventUuid: evt.uuid ?? undefined, eventType: evt.type ?? undefined, timestampMs: evt.timestampMs ?? evt.createdAtMs ?? undefined, locationUuid: evt.locationUuid ?? undefined, componentUuid: evt.componentUuid ?? undefined, ownerDeviceUuid: evt.ownerDeviceUuid ?? undefined, authorizationResult: evt.authorizationResult ?? undefined, authenticationResult: evt.authenticationResult ?? undefined, })); }