diff --git a/packages/clients/src/api/account/v2/api.gen.ts b/packages/clients/src/api/account/v2/api.gen.ts index fc70fdb50..2f11a7641 100644 --- a/packages/clients/src/api/account/v2/api.gen.ts +++ b/packages/clients/src/api/account/v2/api.gen.ts @@ -7,19 +7,31 @@ import { validatePathParam, } from '../../../bridge' import { + marshalCreateMFAOTPRequest, marshalCreateProjectRequest, marshalUpdateProjectRequest, + marshalValidateMFAOTPRequest, + unmarshalListMFAOTPsResponse, unmarshalListProjectsResponse, + unmarshalMFAOTP, unmarshalProject, + unmarshalValidateMFAOTPResponse, } from './marshalling.gen' import type { + CreateMFAOTPRequest, CreateProjectRequest, + DeleteMFAOTPRequest, DeleteProjectRequest, GetProjectRequest, + ListMFAOTPsRequest, + ListMFAOTPsResponse, ListProjectsRequest, ListProjectsResponse, + MFAOTP, Project, UpdateProjectRequest, + ValidateMFAOTPRequest, + ValidateMFAOTPResponse, } from './types.gen' const jsonContentHeaders = { @@ -139,4 +151,86 @@ export class AccountV2GenAPI extends API { }, unmarshalProject, ) + + protected pageOfListMFAOTPs = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/account/v2/mfa/otps`, + urlParams: urlParams( + ['account_root_user_id', request.accountRootUserId], + ['order_by', request.orderBy ?? 'created_at_asc'], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListMFAOTPsResponse, + ) + + /** + * List MFA OTPs + * + * @param request - The request {@link ListMFAOTPsRequest} + * @returns A Promise of ListMFAOTPsResponse + */ + listMFAOTPs = (request: Readonly) => + enrichForPagination('mfaOtps', this.pageOfListMFAOTPs, request) + + /** + * Create MFA OTP + * + * @param request - The request {@link CreateMFAOTPRequest} + * @returns A Promise of MFAOTP + */ + createMFAOTP = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateMFAOTPRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/account/v2/mfa/otps`, + }, + unmarshalMFAOTP, + ) + + /** + * Validate MFA OTP + * + * @param request - The request {@link ValidateMFAOTPRequest} + * @returns A Promise of ValidateMFAOTPResponse + */ + validateMFAOTP = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalValidateMFAOTPRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/account/v2/mfa/otps/${validatePathParam( + 'mfaOtpId', + request.mfaOtpId, + )}/validate`, + }, + unmarshalValidateMFAOTPResponse, + ) + + /** + * Delete MFA OTP + * + * @param request - The request {@link DeleteMFAOTPRequest} + */ + deleteMFAOTP = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/account/v2/mfa/otps/${validatePathParam( + 'mfaOtpId', + request.mfaOtpId, + )}`, + }) } diff --git a/packages/clients/src/api/account/v2/marshalling.gen.ts b/packages/clients/src/api/account/v2/marshalling.gen.ts index d62873b86..770b142b8 100644 --- a/packages/clients/src/api/account/v2/marshalling.gen.ts +++ b/packages/clients/src/api/account/v2/marshalling.gen.ts @@ -7,12 +7,27 @@ import { } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { + CreateMFAOTPRequest, CreateProjectRequest, + ListMFAOTPsResponse, ListProjectsResponse, + MFAOTP, Project, UpdateProjectRequest, + ValidateMFAOTPRequest, + ValidateMFAOTPResponse, } from './types.gen' +export const unmarshalMFAOTP = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'MFAOTP' failed as data isn't a dictionary.`, + ) + } + + return { id: data.id } as MFAOTP +} + export const unmarshalProject = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -30,6 +45,19 @@ export const unmarshalProject = (data: unknown) => { } as Project } +export const unmarshalListMFAOTPsResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListMFAOTPsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + mfaOtps: unmarshalArrayOfObject(data.mfa_otps, unmarshalMFAOTP), + totalCount: data.total_count, + } as ListMFAOTPsResponse +} + export const unmarshalListProjectsResponse = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -43,6 +71,23 @@ export const unmarshalListProjectsResponse = (data: unknown) => { } as ListProjectsResponse } +export const unmarshalValidateMFAOTPResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ValidateMFAOTPResponse' failed as data isn't a dictionary.`, + ) + } + + return { backupCodes: data.backup_codes } as ValidateMFAOTPResponse +} + +export const marshalCreateMFAOTPRequest = ( + request: CreateMFAOTPRequest, + defaults: DefaultValues, +): Record => ({ + account_root_user_id: request.accountRootUserId, +}) + export const marshalCreateProjectRequest = ( request: CreateProjectRequest, defaults: DefaultValues, @@ -59,3 +104,10 @@ export const marshalUpdateProjectRequest = ( description: request.description, name: request.name, }) + +export const marshalValidateMFAOTPRequest = ( + request: ValidateMFAOTPRequest, + defaults: DefaultValues, +): Record => ({ + otp: request.otp, +}) diff --git a/packages/clients/src/api/account/v2/types.gen.ts b/packages/clients/src/api/account/v2/types.gen.ts index af61fb1d8..728be576d 100644 --- a/packages/clients/src/api/account/v2/types.gen.ts +++ b/packages/clients/src/api/account/v2/types.gen.ts @@ -1,12 +1,22 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. +export type ListMFAOTPsRequestOrderBy = 'created_at_asc' | 'created_at_desc' + export type ListProjectsRequestOrderBy = | 'created_at_asc' | 'created_at_desc' | 'name_asc' | 'name_desc' +/** List mfaot ps response */ +export interface ListMFAOTPsResponse { + /** The total number of MFA OTPs */ + totalCount: number + /** The paginated returned MFA OTPs */ + mfaOtps: Array +} + /** List projects response */ export interface ListProjectsResponse { /** The total number of projects */ @@ -15,6 +25,12 @@ export interface ListProjectsResponse { projects: Array } +/** Mfaotp */ +export interface MFAOTP { + /** The ID of the MFA OTP */ + id: string +} + /** Project */ export interface Project { /** The ID of the project */ @@ -31,6 +47,12 @@ export interface Project { description: string } +/** Validate mfaotp response */ +export interface ValidateMFAOTPResponse { + /** The backup codes of the MFA OTP */ + backupCodes: Array +} + export type CreateProjectRequest = { /** The name of the project */ name: string @@ -73,3 +95,31 @@ export type UpdateProjectRequest = { /** The description of the project */ description?: string } + +export type ListMFAOTPsRequest = { + /** The page number for the returned MFA OTPs */ + page?: number + /** The maximum number of MFA OTP per page */ + pageSize?: number + /** The sort order of the returned MFA OTPs */ + orderBy?: ListMFAOTPsRequestOrderBy + /** Filter out by a account root user ID */ + accountRootUserId: string +} + +export type CreateMFAOTPRequest = { + /** The account root user ID of the MFA OTP */ + accountRootUserId: string +} + +export type ValidateMFAOTPRequest = { + /** The MFA OTP ID */ + mfaOtpId: string + /** The code of the MFA OTP */ + otp: string +} + +export type DeleteMFAOTPRequest = { + /** The MFA OTP ID */ + mfaOtpId: string +}