@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
65 lines (64 loc) • 3.48 kB
JavaScript
// TODO: better import syntax?
import { BaseAPIRequestFactory } from './baseapi.js';
import { HttpMethod, HttpInfo } from '../http/http.js';
import { ObjectSerializer } from '../models/ObjectSerializer.js';
import { ApiException } from './exception.js';
import { isCodeInRange } from '../util.js';
/**
* no description
*/
export class AuthApiRequestFactory extends BaseAPIRequestFactory {
/**
* Returns information about the authenticated user, their current organization, and API key permissions. Use this endpoint to verify your authentication and understand your available API access levels.
* Get current user
*/
async v2AuthWhoamiGET(_options) {
let _config = _options || this.configuration;
// Path Params
const localVarPath = '/v2/auth/whoami';
// Make Request Context
const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8");
let authMethod;
// Apply auth methods
authMethod = _config.authMethods["bearerAuth"];
if (authMethod?.applySecurityAuthentication) {
await authMethod?.applySecurityAuthentication(requestContext);
}
const defaultAuth = _config?.authMethods?.default;
if (defaultAuth?.applySecurityAuthentication) {
await defaultAuth?.applySecurityAuthentication(requestContext);
}
return requestContext;
}
}
export class AuthApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to v2AuthWhoamiGET
* @throws ApiException if the response code was not in [200, 299]
*/
async v2AuthWhoamiGETWithHttpInfo(response) {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "WhoAmI", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
if (isCodeInRange("404", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "NotFoundErrors", "");
throw new ApiException(response.httpStatusCode, "Not Found", body, response.headers);
}
if (isCodeInRange("0", response.httpStatusCode)) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "Errors", "");
throw new ApiException(response.httpStatusCode, "Errors", body, response.headers);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer.deserialize(ObjectSerializer.parse(await response.body.text(), contentType), "WhoAmI", "");
return new HttpInfo(response.httpStatusCode, response.headers, response.body, body);
}
throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers);
}
}