UNPKG

@planet-a/affinity-node

Version:
73 lines (72 loc) 1.95 kB
import { AxiosInstance } from 'axios'; import type { DateTime, Replace } from './types.js'; /** * TODO(@joscha): Enum is most likely incomplete */ export declare enum GrantType { API_KEY = "api_key" } /** * TODO(@joscha): Enum is most likely incomplete */ export declare enum Scope { EXTERNAL_API = "external_api" } export type Tenant = { /** Tenant ID; unrelated to any entity the current Affinity instance */ id: number; name: string; /** `https://<subdomain>.affinity.co` */ subdomain: string; }; export type User = { /** User ID; This is also the ID of the person in the current Affinity instance. * E.g. you can use it to get the person via `https://<subdomain>.affinity.co/persons/<id>` */ id: number; firstName: string; lastName: string; /** The primary email of the user */ email: string; }; export type GrantRaw = { type: string; scope: string; createdAt: DateTime; }; export type WhoAmIResponseRaw = { /** * Information about the Affinity instance the user belongs to. */ tenant: Tenant; /** * Data about the user whose API key was used for the endpoint. */ user: User; /** * Data about the type of authentication and metadata about the API key. */ grant: GrantRaw; }; export type WhoAmIResponse = Replace<WhoAmIResponseRaw, { grant: { type: GrantType; scope: Scope; createdAt: Date; }; }>; /** * @module */ export declare class Auth { private readonly axios; /** @hidden */ constructor(axios: AxiosInstance); /** * Gets information about the user sending the request, and their affiliate company. * There are no query or path parameters for this method. The information needed is contained within the API key. * * [More information](https://api-docs.affinity.co/#the-whoami-resource) */ whoAmI(): Promise<WhoAmIResponse>; }