UNPKG

@planet-a/affinity-node

Version:
58 lines (57 loc) 1.92 kB
import { enumFromValue } from './enum_from_value.js'; import { defaultTransformers } from './axios_default_transformers.js'; import { whoAmIUrl } from './urls.js'; /** * TODO(@joscha): Enum is most likely incomplete */ export var GrantType; (function (GrantType) { GrantType["API_KEY"] = "api_key"; })(GrantType || (GrantType = {})); /** * TODO(@joscha): Enum is most likely incomplete */ export var Scope; (function (Scope) { Scope["EXTERNAL_API"] = "external_api"; })(Scope || (Scope = {})); /** * @module */ export class Auth { /** @hidden */ constructor(axios) { Object.defineProperty(this, "axios", { enumerable: true, configurable: true, writable: true, value: axios }); } /** * 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) */ async whoAmI() { const response = await this.axios.get(whoAmIUrl(), { transformResponse: [ ...defaultTransformers(), (json) => { return { ...json, grant: { createdAt: new Date(json.grant.createdAt), // TODO(@joscha): when the API is complete, throw here on undefined values type: enumFromValue(json.grant.type, GrantType), // TODO(@joscha): when the API is complete, throw here on undefined values scope: enumFromValue(json.grant.scope, Scope), }, }; }, ], }); return response.data; } }