diff --git a/src/internal/apis/AuthApi.ts b/src/internal/apis/AuthApi.ts index 93d51ab..9cbac31 100644 --- a/src/internal/apis/AuthApi.ts +++ b/src/internal/apis/AuthApi.ts @@ -14,6 +14,7 @@ import * as runtime from '../runtime'; import type { + AcceptAccountRequestResponseModel, GetAllApiKeysResponse, IssueApiKeyRequest, IssueApiKeyResponse, @@ -23,6 +24,8 @@ import type { RequestNewAccountModel, } from '../models/index'; import { + AcceptAccountRequestResponseModelFromJSON, + AcceptAccountRequestResponseModelToJSON, GetAllApiKeysResponseFromJSON, GetAllApiKeysResponseToJSON, IssueApiKeyRequestFromJSON, @@ -39,6 +42,12 @@ import { RequestNewAccountModelToJSON, } from '../models/index'; +export interface AuthControllerAcceptAccountRequestRequest { + id: string; + xUserPassword?: string; + xUserEmail?: string; +} + export interface AuthControllerCreateAccountRequestRequest { requestNewAccountModel: RequestNewAccountModel; } @@ -51,8 +60,8 @@ export interface AuthControllerCreateApiKeyRequest { export interface AuthControllerDeleteAccountRequestRequest { id: string; - xUserPassword: string; - xUserEmail: string; + xUserPassword?: string; + xUserEmail?: string; } export interface AuthControllerDeleteApiKeyByIdRequest { @@ -63,8 +72,15 @@ export interface AuthControllerDeleteApiKeyByIdRequest { } export interface AuthControllerGetAllAccountRequestsRequest { - xUserPassword: string; - xUserEmail: string; + xUserPassword?: string; + xUserEmail?: string; +} + +export interface AuthControllerGetAllApiKeysRequest { + offset?: number; + limit?: number; + xUserPassword?: string; + xUserEmail?: string; } export interface AuthControllerGetAllApiKeysRequest { @@ -91,6 +107,78 @@ export interface AuthControllerTestAuthRequest { * */ export class AuthApi extends runtime.BaseAPI { + /** + * Accepts a pending account request: creates the user, optionally creates/links a project (for ADMIN requests with a projectName), and deletes the pending request. Requires admin or superadmin credentials. + * Accept an account request + */ + async authControllerAcceptAccountRequestRaw( + requestParameters: AuthControllerAcceptAccountRequestRequest, + initOverrides?: RequestInit | runtime.InitOverrideFunction + ): Promise> { + if (requestParameters['id'] == null) { + throw new runtime.RequiredError( + 'id', + 'Required parameter "id" was null or undefined when calling authControllerAcceptAccountRequest().' + ); + } + + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + if (requestParameters['xUserPassword'] != null) { + headerParameters['X-User-Password'] = String( + requestParameters['xUserPassword'] + ); + } + + if (requestParameters['xUserEmail'] != null) { + headerParameters['X-User-Email'] = String( + requestParameters['xUserEmail'] + ); + } + + if (this.configuration && this.configuration.accessToken) { + const token = this.configuration.accessToken; + const tokenString = await token('API_Key', []); + + if (tokenString) { + headerParameters['Authorization'] = `Bearer ${tokenString}`; + } + } + const response = await this.request( + { + path: `/auth/account-request/{id}/accept`.replace( + `{${'id'}}`, + encodeURIComponent(String(requestParameters['id'])) + ), + method: 'POST', + headers: headerParameters, + query: queryParameters, + }, + initOverrides + ); + + return new runtime.JSONApiResponse(response, (jsonValue) => + AcceptAccountRequestResponseModelFromJSON(jsonValue) + ); + } + + /** + * Accepts a pending account request: creates the user, optionally creates/links a project (for ADMIN requests with a projectName), and deletes the pending request. Requires admin or superadmin credentials. + * Accept an account request + */ + async authControllerAcceptAccountRequest( + requestParameters: AuthControllerAcceptAccountRequestRequest, + initOverrides?: RequestInit | runtime.InitOverrideFunction + ): Promise { + const response = await this.authControllerAcceptAccountRequestRaw( + requestParameters, + initOverrides + ); + return await response.value(); + } + /** * Allows a prospective user to submit a request for a new account. The request is stored and can be reviewed by an admin. * Submit a new account request @@ -222,20 +310,6 @@ export class AuthApi extends runtime.BaseAPI { ); } - if (requestParameters['xUserPassword'] == null) { - throw new runtime.RequiredError( - 'xUserPassword', - 'Required parameter "xUserPassword" was null or undefined when calling authControllerDeleteAccountRequest().' - ); - } - - if (requestParameters['xUserEmail'] == null) { - throw new runtime.RequiredError( - 'xUserEmail', - 'Required parameter "xUserEmail" was null or undefined when calling authControllerDeleteAccountRequest().' - ); - } - const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; @@ -372,20 +446,6 @@ export class AuthApi extends runtime.BaseAPI { requestParameters: AuthControllerGetAllAccountRequestsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction ): Promise> { - if (requestParameters['xUserPassword'] == null) { - throw new runtime.RequiredError( - 'xUserPassword', - 'Required parameter "xUserPassword" was null or undefined when calling authControllerGetAllAccountRequests().' - ); - } - - if (requestParameters['xUserEmail'] == null) { - throw new runtime.RequiredError( - 'xUserEmail', - 'Required parameter "xUserEmail" was null or undefined when calling authControllerGetAllAccountRequests().' - ); - } - const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; @@ -430,7 +490,7 @@ export class AuthApi extends runtime.BaseAPI { * Retrieve all account requests */ async authControllerGetAllAccountRequests( - requestParameters: AuthControllerGetAllAccountRequestsRequest, + requestParameters: AuthControllerGetAllAccountRequestsRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction ): Promise { const response = await this.authControllerGetAllAccountRequestsRaw( diff --git a/src/internal/models/AcceptAccountRequestResponseModel.ts b/src/internal/models/AcceptAccountRequestResponseModel.ts new file mode 100644 index 0000000..7693d0e --- /dev/null +++ b/src/internal/models/AcceptAccountRequestResponseModel.ts @@ -0,0 +1,91 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Juno + * Juno Public API Docs + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +import type { AcceptAccountRequestResponseProject } from './AcceptAccountRequestResponseProject'; +import { + AcceptAccountRequestResponseProjectFromJSON, + AcceptAccountRequestResponseProjectFromJSONTyped, + AcceptAccountRequestResponseProjectToJSON, +} from './AcceptAccountRequestResponseProject'; +import type { AcceptAccountRequestResponseUser } from './AcceptAccountRequestResponseUser'; +import { + AcceptAccountRequestResponseUserFromJSON, + AcceptAccountRequestResponseUserFromJSONTyped, + AcceptAccountRequestResponseUserToJSON, +} from './AcceptAccountRequestResponseUser'; + +/** + * + * @export + * @interface AcceptAccountRequestResponseModel + */ +export interface AcceptAccountRequestResponseModel { + /** + * The created user + * @type {AcceptAccountRequestResponseUser} + * @memberof AcceptAccountRequestResponseModel + */ + user: AcceptAccountRequestResponseUser; + /** + * The created or linked project (if applicable) + * @type {AcceptAccountRequestResponseProject} + * @memberof AcceptAccountRequestResponseModel + */ + project?: AcceptAccountRequestResponseProject; +} + +/** + * Check if a given object implements the AcceptAccountRequestResponseModel interface. + */ +export function instanceOfAcceptAccountRequestResponseModel( + value: object +): value is AcceptAccountRequestResponseModel { + if (!('user' in value) || value['user'] === undefined) return false; + return true; +} + +export function AcceptAccountRequestResponseModelFromJSON( + json: any +): AcceptAccountRequestResponseModel { + return AcceptAccountRequestResponseModelFromJSONTyped(json, false); +} + +export function AcceptAccountRequestResponseModelFromJSONTyped( + json: any, + ignoreDiscriminator: boolean +): AcceptAccountRequestResponseModel { + if (json == null) { + return json; + } + return { + user: AcceptAccountRequestResponseUserFromJSON(json['user']), + project: + json['project'] == null + ? undefined + : AcceptAccountRequestResponseProjectFromJSON(json['project']), + }; +} + +export function AcceptAccountRequestResponseModelToJSON( + value?: AcceptAccountRequestResponseModel | null +): any { + if (value == null) { + return value; + } + return { + user: AcceptAccountRequestResponseUserToJSON(value['user']), + project: AcceptAccountRequestResponseProjectToJSON(value['project']), + }; +} diff --git a/src/internal/models/AcceptAccountRequestResponseProject.ts b/src/internal/models/AcceptAccountRequestResponseProject.ts new file mode 100644 index 0000000..bc06d50 --- /dev/null +++ b/src/internal/models/AcceptAccountRequestResponseProject.ts @@ -0,0 +1,76 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Juno + * Juno Public API Docs + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * + * @export + * @interface AcceptAccountRequestResponseProject + */ +export interface AcceptAccountRequestResponseProject { + /** + * Project ID + * @type {number} + * @memberof AcceptAccountRequestResponseProject + */ + id: number; + /** + * Project name + * @type {string} + * @memberof AcceptAccountRequestResponseProject + */ + name: string; +} + +/** + * Check if a given object implements the AcceptAccountRequestResponseProject interface. + */ +export function instanceOfAcceptAccountRequestResponseProject( + value: object +): value is AcceptAccountRequestResponseProject { + if (!('id' in value) || value['id'] === undefined) return false; + if (!('name' in value) || value['name'] === undefined) return false; + return true; +} + +export function AcceptAccountRequestResponseProjectFromJSON( + json: any +): AcceptAccountRequestResponseProject { + return AcceptAccountRequestResponseProjectFromJSONTyped(json, false); +} + +export function AcceptAccountRequestResponseProjectFromJSONTyped( + json: any, + ignoreDiscriminator: boolean +): AcceptAccountRequestResponseProject { + if (json == null) { + return json; + } + return { + id: json['id'], + name: json['name'], + }; +} + +export function AcceptAccountRequestResponseProjectToJSON( + value?: AcceptAccountRequestResponseProject | null +): any { + if (value == null) { + return value; + } + return { + id: value['id'], + name: value['name'], + }; +} diff --git a/src/internal/models/AcceptAccountRequestResponseUser.ts b/src/internal/models/AcceptAccountRequestResponseUser.ts new file mode 100644 index 0000000..b8343e8 --- /dev/null +++ b/src/internal/models/AcceptAccountRequestResponseUser.ts @@ -0,0 +1,113 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Juno + * Juno Public API Docs + * + * The version of the OpenAPI document: 1.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * + * @export + * @interface AcceptAccountRequestResponseUser + */ +export interface AcceptAccountRequestResponseUser { + /** + * User ID + * @type {number} + * @memberof AcceptAccountRequestResponseUser + */ + id: number; + /** + * Email + * @type {string} + * @memberof AcceptAccountRequestResponseUser + */ + email: string; + /** + * Name + * @type {string} + * @memberof AcceptAccountRequestResponseUser + */ + name: string; + /** + * User type + * @type {string} + * @memberof AcceptAccountRequestResponseUser + */ + type: AcceptAccountRequestResponseUserTypeEnum; + /** + * Project IDs the user is linked to + * @type {Array} + * @memberof AcceptAccountRequestResponseUser + */ + projectIds?: Array; +} + +/** + * @export + */ +export const AcceptAccountRequestResponseUserTypeEnum = { + Superadmin: 'SUPERADMIN', + Admin: 'ADMIN', + User: 'USER', +} as const; +export type AcceptAccountRequestResponseUserTypeEnum = + (typeof AcceptAccountRequestResponseUserTypeEnum)[keyof typeof AcceptAccountRequestResponseUserTypeEnum]; + +/** + * Check if a given object implements the AcceptAccountRequestResponseUser interface. + */ +export function instanceOfAcceptAccountRequestResponseUser( + value: object +): value is AcceptAccountRequestResponseUser { + if (!('id' in value) || value['id'] === undefined) return false; + if (!('email' in value) || value['email'] === undefined) return false; + if (!('name' in value) || value['name'] === undefined) return false; + if (!('type' in value) || value['type'] === undefined) return false; + return true; +} + +export function AcceptAccountRequestResponseUserFromJSON( + json: any +): AcceptAccountRequestResponseUser { + return AcceptAccountRequestResponseUserFromJSONTyped(json, false); +} + +export function AcceptAccountRequestResponseUserFromJSONTyped( + json: any, + ignoreDiscriminator: boolean +): AcceptAccountRequestResponseUser { + if (json == null) { + return json; + } + return { + id: json['id'], + email: json['email'], + name: json['name'], + type: json['type'], + projectIds: json['projectIds'] == null ? undefined : json['projectIds'], + }; +} + +export function AcceptAccountRequestResponseUserToJSON( + value?: AcceptAccountRequestResponseUser | null +): any { + if (value == null) { + return value; + } + return { + id: value['id'], + email: value['email'], + name: value['name'], + type: value['type'], + projectIds: value['projectIds'], + }; +} diff --git a/src/internal/models/index.ts b/src/internal/models/index.ts index a55f965..3efaa89 100644 --- a/src/internal/models/index.ts +++ b/src/internal/models/index.ts @@ -1,5 +1,8 @@ /* tslint:disable */ /* eslint-disable */ +export * from './AcceptAccountRequestResponseModel'; +export * from './AcceptAccountRequestResponseProject'; +export * from './AcceptAccountRequestResponseUser'; export * from './AccessKey'; export * from './AggregateInterval'; export * from './AnalyticsConfigResponse'; diff --git a/src/lib/auth.ts b/src/lib/auth.ts index e7bcdaa..062f84e 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -9,6 +9,7 @@ import { RequestNewAccountModel, RequestNewAccountModelUserTypeEnum, GetAllApiKeysResponse, + AcceptAccountRequestResponseModel, } from '../internal/index'; import { validatePaginationParam, @@ -19,6 +20,8 @@ import { export type UserCredentials = string | { email: string; password: string }; +export type UserType = 'SUPERADMIN' | 'ADMIN' | 'USER'; + export class AuthAPI { private internalApi: AuthApi; private apiKey?: string; @@ -140,18 +143,62 @@ export class AuthAPI { } async getAllAccountRequests(options: { - email: string; - password: string; + credentials: UserCredentials; }): Promise { - const { email, password } = options; + const { credentials } = options; - validateString(email, 'The email must be nonempty'); - validateString(password, 'The password must be nonempty'); + validateUserCredentials(credentials); - return await this.internalApi.authControllerGetAllAccountRequests({ - xUserEmail: email.trim(), - xUserPassword: password.trim(), - }); + if (typeof credentials == 'string') { + return await this.internalApi.authControllerGetAllAccountRequests( + { xUserEmail: '', xUserPassword: '' }, + async ({ init }) => ({ + headers: { + ...(init.headers as Record), + Authorization: `Bearer ${credentials}`, + }, + }) + ); + } else { + return await this.internalApi.authControllerGetAllAccountRequests({ + xUserEmail: credentials.email, + xUserPassword: credentials.password, + }); + } + } + + async acceptAccountRequest(options: { + id: string; + credentials: UserCredentials; + }): Promise { + let { id, credentials } = options; + + validateString(id, 'The request ID must be nonempty'); + validateUserCredentials(credentials); + + id = id.trim(); + + try { + if (typeof credentials == 'string') { + return await this.internalApi.authControllerAcceptAccountRequest( + { id }, + async ({ init }) => ({ + headers: { + ...(init.headers as Record), + Authorization: `Bearer ${credentials}`, + }, + }) + ); + } else { + return await this.internalApi.authControllerAcceptAccountRequest({ + id, + xUserPassword: credentials.password, + xUserEmail: credentials.email, + }); + } + } catch (e) { + throw e; + } } async getAllApiKeys(options: { @@ -223,19 +270,29 @@ export class AuthAPI { async deleteAccountRequest(options: { id: string; - email: string; - password: string; + credentials: UserCredentials; }): Promise { - const { id, email, password } = options; + const { id, credentials } = options; validateString(id, 'The id must be nonempty'); - validateString(email, 'The email must be nonempty'); - validateString(password, 'The password must be nonempty'); + validateUserCredentials(credentials); - return await this.internalApi.authControllerDeleteAccountRequest({ - id: id.trim(), - xUserEmail: email.trim(), - xUserPassword: password.trim(), - }); + if (typeof credentials == 'string') { + return await this.internalApi.authControllerDeleteAccountRequest( + { id: id.trim(), xUserEmail: '', xUserPassword: '' }, + async ({ init }) => ({ + headers: { + ...(init.headers as Record), + Authorization: `Bearer ${credentials}`, + }, + }) + ); + } else { + return await this.internalApi.authControllerDeleteAccountRequest({ + id: id.trim(), + xUserEmail: credentials.email, + xUserPassword: credentials.password, + }); + } } }