// Generated from the LeavePulse contract. Do not edit. import { Resource, extractId } from "../runtime/resource"; import { TopicSubscription } from "../runtime/realtime"; import { fetchCachedOrThrow } from "../runtime/etag-store"; import { Page, type PageData, pageDataFrom } from "../runtime/page"; import type { components } from "../types"; import type * as models from "../models"; import type { LeavePulseFile } from "../runtime/transport"; import type { ClientContext } from "../client"; import type { Snowflake } from "../runtime/snowflake"; import type { Application } from "./Application"; import type { Build } from "./Build"; import type { Server } from "./Server"; import type { Session } from "./Session"; type Data = components["schemas"]["MeResponse"]; export class Me extends Resource { constructor( data: Data, private readonly ctx: ClientContext, ) { super(data); } /** Re-fetch this Me and hydrate in place. */ async refresh(): Promise { const data = await fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me` }, ); let hydrated = data as Record; const id = extractId(hydrated); return this.ctx.cache.upsertAlias( "Me", this.id, id, hydrated, () => this, ) as this; } /** Load this Me's data (alias of refresh). */ fetch(): Promise { return this.refresh(); } /** me.issue_ws_token */ async issueWsToken( body: models.WsTokenRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/auth/ws-token`, body, }); } /** me.billing.snapshot */ async billingSnapshot(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/billing/snapshot` }, ); } /** builds.list */ async buildsList(): Promise { const data = await fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/builds` }, ); const items = Array.isArray(data) ? data : ((data as Record)["items"] ?? []); return this.ctx.hydrateMany("Build", items) as Build[]; } /** me.engagement */ async engagement(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/community/projects/me/engagement` }, ); } /** me.account.change_email */ async accountChangeEmail( body: models.EmailChangeRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/account/actions/change-email`, body, }); } /** me.account.delete */ async accountDelete(): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/account/actions/delete`, }); } /** me.account.export */ async accountExport(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/account/export` }, ); } /** me.avatar.remove */ async avatarRemove(): Promise { return this.ctx.transport.request({ method: "DELETE", path: `/v1/me/avatar`, }); } /** me.avatar.upload */ async avatarUpload(file: LeavePulseFile): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/avatar`, multipart: { fileField: "file", file, fields: {} }, }); } /** me.avatar.set */ async avatarSet(body: models.AvatarUrlRequest): Promise { return this.ctx.transport.request({ method: "PUT", path: `/v1/me/avatar`, body, }); } /** me.minecraft.unlink */ async minecraftUnlink( accountId: Snowflake, ): Promise { return this.ctx.transport.request({ method: "DELETE", path: `/v1/me/minecraft/accounts/${accountId}`, }); } /** me.minecraft.link_code */ async minecraftLinkCode( body: models.MinecraftLinkCodeRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/minecraft/link-code`, body, }); } /** me.minecraft.complete_link */ async minecraftCompleteLink( body: models.LinkCompletionRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/minecraft/link/complete`, body, }); } /** me.minecraft.official_link_start */ async minecraftOfficialLinkStart(): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/minecraft/official/start`, }); } /** me.minecraft.resolve */ async minecraftResolve( body: models.MinecraftResolveRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/minecraft/resolve`, body, }); } /** me.minecraft.state */ async minecraftState(params?: { projectId?: Snowflake; }): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/minecraft/state`, query: { project_id: params?.projectId }, }, ); } /** me.notifications.get */ async notificationsGet(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/notifications` }, ); } /** me.notifications.update */ async notificationsUpdate( body: models.NotificationPreferencesUpdate, ): Promise { return this.ctx.transport.request({ method: "PATCH", path: `/v1/me/notifications`, body, }); } /** me.notifications.delivery.get */ async notificationsDeliveryGet(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/notifications/delivery` }, ); } /** me.notifications.delivery.update */ async notificationsDeliveryUpdate( body: models.DeliveryPreferencesUpdate, ): Promise { return this.ctx.transport.request({ method: "PATCH", path: `/v1/me/notifications/delivery`, body, }); } /** me.notifications.delivery.email.confirm */ async notificationsDeliveryEmailConfirm( body: models.EmailConfirmRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/notifications/delivery/email/confirm`, body, }); } /** me.notifications.delivery.email.confirm_request */ async notificationsDeliveryEmailConfirmRequest( body: models.EmailConfirmRequestPayload, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/notifications/delivery/email/confirm-request`, body, }); } /** me.notifications.delivery.send_test */ async notificationsDeliverySendTest( body: models.SendTestRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/notifications/delivery/test`, body, }); } /** me.notifications.feed.list */ async notificationsFeedList(params?: { page?: number; perPage?: number; unreadOnly?: boolean; }): Promise> { const fetchPage = async ( page: number, perPage: number, ): Promise> => { const data = await fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/notifications/feed`, query: { page: page, per_page: perPage, unread_only: params?.unreadOnly, }, }, ); return pageDataFrom( data, (raw) => raw as models.Notification[], page, perPage, ); }; return new Page( await fetchPage(params?.page ?? 1, params?.perPage ?? 20), fetchPage, ); } /** me.notifications.feed.mark_all_read */ async notificationsFeedMarkAllRead(): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/notifications/feed/read-all`, }); } /** me.notifications.feed.unread_count */ async notificationsFeedUnreadCount(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/notifications/feed/unread-count` }, ); } /** me.notifications.feed.dismiss */ async notificationsFeedDismiss( notificationId: string, ): Promise { return this.ctx.transport.request({ method: "DELETE", path: `/v1/me/notifications/feed/${notificationId}`, }); } /** me.notifications.feed.mark_read */ async notificationsFeedMarkRead( notificationId: string, ): Promise { const data = await this.ctx.transport.request({ method: "POST", path: `/v1/me/notifications/feed/${notificationId}/read`, }); return data as models.Notification; } /** me.notifications.feed.mark_unread */ async notificationsFeedMarkUnread( notificationId: string, ): Promise { const data = await this.ctx.transport.request({ method: "POST", path: `/v1/me/notifications/feed/${notificationId}/unread`, }); return data as models.Notification; } /** me.oauth.list */ async oauthList(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/oauth/providers` }, ); } /** me.oauth.unlink */ async oauthUnlink(provider: string): Promise { return this.ctx.transport.request({ method: "DELETE", path: `/v1/me/oauth/${provider}`, }); } /** me.oauth.link_start */ async oauthLinkStart( provider: string, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/oauth/${provider}/link/start`, }); } /** me.password.status */ async passwordStatus(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/password` }, ); } /** me.password.set */ async passwordSet( body: models.PasswordSetRequest, ): Promise { return this.ctx.transport.request({ method: "PUT", path: `/v1/me/password`, body, }); } /** me.password.change */ async passwordChange( body: models.PasswordChangeRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/password/actions/change`, body, }); } /** me.pat_tokens.list */ async patTokensList(): Promise { const data = await fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/pat-tokens` }, ); const items = Array.isArray(data) ? data : ((data as Record)["items"] ?? []); return items as models.PatToken[]; } /** me.pat_tokens.create */ async patTokensCreate( body: models.CreatePatTokenRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/pat-tokens`, body, }); } /** me.pat_tokens.revoke */ async patTokensRevoke(tokenId: string): Promise { return this.ctx.transport.request({ method: "DELETE", path: `/v1/me/pat-tokens/${tokenId}`, }); } /** me.profile.update */ async profileUpdate( body: models.ProfileUpdateRequest, ): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/profile`, body, }); } /** me.sessions.list */ async sessionsList(): Promise { const data = await fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/sessions` }, ); const items = Array.isArray(data) ? data : ((data as Record)["sessions"] ?? []); return this.ctx.hydrateMany("Session", items) as Session[]; } /** me.sessions.revoke_others */ async sessionsRevokeOthers(): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/sessions/actions/revoke-others`, }); } /** me.stats */ async stats(params?: { estimated?: boolean }): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/stats`, query: { estimated: params?.estimated }, }, ); } /** me.stats_unverified */ async statsUnverified(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/stats/unverified` }, ); } /** me.totp.status */ async totpStatus(): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/totp` }, ); } /** me.totp.begin */ async totpBegin(): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/totp/actions/begin`, }); } /** me.totp.confirm */ async totpConfirm(body: models.TotpCodeRequest): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/totp/actions/confirm`, body, }); } /** me.totp.disable */ async totpDisable(body: models.TotpCodeRequest): Promise { return this.ctx.transport.request({ method: "POST", path: `/v1/me/totp/actions/disable`, body, }); } /** me.whitelist.applications */ async whitelistApplications(params?: { status?: string; page?: number; perPage?: number; }): Promise> { const fetchPage = async ( page: number, perPage: number, ): Promise> => { const data = await fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/me/whitelist/applications`, query: { status: params?.status, page: page, per_page: perPage }, }, ); return pageDataFrom( data, (raw) => this.ctx.hydrateMany("Application", raw) as Application[], page, perPage, ); }; return new Page( await fetchPage(params?.page ?? 1, params?.perPage ?? 20), fetchPage, ); } /** me.servers.list */ async serversList(params?: { page?: number; perPage?: number; }): Promise> { const fetchPage = async ( page: number, perPage: number, ): Promise> => { const data = await fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/servers/mine`, query: { page: page, per_page: perPage }, }, ); return pageDataFrom( data, (raw) => this.ctx.hydrateMany("Server", raw) as Server[], page, perPage, ); }; return new Page( await fetchPage(params?.page ?? 1, params?.perPage ?? 20), fetchPage, ); } /** me.servers.issues */ async serversIssues(params?: { page?: number; perPage?: number; includeOk?: boolean; }): Promise { return fetchCachedOrThrow( this.ctx.transport, this.ctx.etagStore, { method: "GET", path: `/v1/servers/mine/issues`, query: { page: params?.page, per_page: params?.perPage, include_ok: params?.includeOk, }, }, ); } /** Subscribe to `user.server_issues` (private realtime). */ onServerIssues(): TopicSubscription { return new TopicSubscription(this.ctx.realtime, "user.server_issues"); } /** Subscribe to `user.tickets` (private realtime). */ onTickets(): TopicSubscription { return new TopicSubscription(this.ctx.realtime, "user.tickets"); } /** Subscribe to `user.billing` (private realtime). */ onBilling(): TopicSubscription { return new TopicSubscription(this.ctx.realtime, "user.billing"); } /** Subscribe to `user.whitelist` (private realtime). */ onWhitelist(): TopicSubscription { return new TopicSubscription(this.ctx.realtime, "user.whitelist"); } /** Subscribe to `user.notifications` (private realtime). */ onNotifications(): TopicSubscription { return new TopicSubscription(this.ctx.realtime, "user.notifications"); } }