import * as U from '../api/userTypes'; import {canvas, Match} from '../request/requestBuidler'; import * as ResponseType from '../api/responseTypes'; export async function getSelf() { return canvas({ uri: "/api/v1/users/:id", uriParams: {id: "self"}, method: "GET", param: {include: ["uudi", "last_login"]} }) } export async function getUser( userId: Match["id"], ) { return canvas({ uri: "/api/v1/users/:id", uriParams: {id: userId}, method: "GET", param: {include: ["uudi", "last_login"]} }) } export async function getUserProfile( user: ResponseType.User ): Promise>; export async function getUserProfile( userId: Match["user_id"] ): Promise>; export async function getUserProfile( user: | Match["user_id"] | ResponseType.User ) { const userId = (user as ResponseType.User)?.id ?? (user as Match["user_id"]); return canvas({ uri: "/api/v1/users/:user_id/profile", uriParams: {user_id: userId}, method: "GET", param: {} }) } export async function getUserActivityStream( config: Match, ) { return canvas({ uri: "/api/v1/users/self/activity_stream", uriParams: {}, method: "GET", param: config }); }; export async function getUserPageViews( userId: Match["user_id"], period?: [Date, Date], ): Promise>; export async function getUserPageViews( user: ResponseType.User, period?: [Date, Date], ): Promise>; export async function getUserPageViews( user: | Match["user_id"] | ResponseType.User, period?: [Date, Date], ) { const userId = (user as ResponseType.User)?.id ?? (user as Match["user_id"]) ?? "self"; return canvas({ uri: "/api/v1/users/:user_id/page_views", uriParams: {user_id: userId}, method: "GET", param: (() => { if (period !== undefined) { const [start_time, end_time] = period.map(e => e.toISOString()); return {start_time, end_time} } else return {} })() }) } export async function getUsersInAccount( accountId: Match["account_id"], config: Match ) { return canvas({ uri: "/api/v1/accounts/:account_id/users", uriParams: {account_id: accountId}, method: "GET", param: config, }); }