Skip to content

Commit aeed476

Browse files
authored
feat(account): add MFA OTP (#224)
1 parent 3c6c143 commit aeed476

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

packages/clients/src/api/account/v2/api.gen.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,31 @@ import {
77
validatePathParam,
88
} from '../../../bridge'
99
import {
10+
marshalCreateMFAOTPRequest,
1011
marshalCreateProjectRequest,
1112
marshalUpdateProjectRequest,
13+
marshalValidateMFAOTPRequest,
14+
unmarshalListMFAOTPsResponse,
1215
unmarshalListProjectsResponse,
16+
unmarshalMFAOTP,
1317
unmarshalProject,
18+
unmarshalValidateMFAOTPResponse,
1419
} from './marshalling.gen'
1520
import type {
21+
CreateMFAOTPRequest,
1622
CreateProjectRequest,
23+
DeleteMFAOTPRequest,
1724
DeleteProjectRequest,
1825
GetProjectRequest,
26+
ListMFAOTPsRequest,
27+
ListMFAOTPsResponse,
1928
ListProjectsRequest,
2029
ListProjectsResponse,
30+
MFAOTP,
2131
Project,
2232
UpdateProjectRequest,
33+
ValidateMFAOTPRequest,
34+
ValidateMFAOTPResponse,
2335
} from './types.gen'
2436

2537
const jsonContentHeaders = {
@@ -139,4 +151,86 @@ export class AccountV2GenAPI extends API {
139151
},
140152
unmarshalProject,
141153
)
154+
155+
protected pageOfListMFAOTPs = (request: Readonly<ListMFAOTPsRequest>) =>
156+
this.client.fetch<ListMFAOTPsResponse>(
157+
{
158+
method: 'GET',
159+
path: `/account/v2/mfa/otps`,
160+
urlParams: urlParams(
161+
['account_root_user_id', request.accountRootUserId],
162+
['order_by', request.orderBy ?? 'created_at_asc'],
163+
['page', request.page],
164+
[
165+
'page_size',
166+
request.pageSize ?? this.client.settings.defaultPageSize,
167+
],
168+
),
169+
},
170+
unmarshalListMFAOTPsResponse,
171+
)
172+
173+
/**
174+
* List MFA OTPs
175+
*
176+
* @param request - The request {@link ListMFAOTPsRequest}
177+
* @returns A Promise of ListMFAOTPsResponse
178+
*/
179+
listMFAOTPs = (request: Readonly<ListMFAOTPsRequest>) =>
180+
enrichForPagination('mfaOtps', this.pageOfListMFAOTPs, request)
181+
182+
/**
183+
* Create MFA OTP
184+
*
185+
* @param request - The request {@link CreateMFAOTPRequest}
186+
* @returns A Promise of MFAOTP
187+
*/
188+
createMFAOTP = (request: Readonly<CreateMFAOTPRequest>) =>
189+
this.client.fetch<MFAOTP>(
190+
{
191+
body: JSON.stringify(
192+
marshalCreateMFAOTPRequest(request, this.client.settings),
193+
),
194+
headers: jsonContentHeaders,
195+
method: 'POST',
196+
path: `/account/v2/mfa/otps`,
197+
},
198+
unmarshalMFAOTP,
199+
)
200+
201+
/**
202+
* Validate MFA OTP
203+
*
204+
* @param request - The request {@link ValidateMFAOTPRequest}
205+
* @returns A Promise of ValidateMFAOTPResponse
206+
*/
207+
validateMFAOTP = (request: Readonly<ValidateMFAOTPRequest>) =>
208+
this.client.fetch<ValidateMFAOTPResponse>(
209+
{
210+
body: JSON.stringify(
211+
marshalValidateMFAOTPRequest(request, this.client.settings),
212+
),
213+
headers: jsonContentHeaders,
214+
method: 'POST',
215+
path: `/account/v2/mfa/otps/${validatePathParam(
216+
'mfaOtpId',
217+
request.mfaOtpId,
218+
)}/validate`,
219+
},
220+
unmarshalValidateMFAOTPResponse,
221+
)
222+
223+
/**
224+
* Delete MFA OTP
225+
*
226+
* @param request - The request {@link DeleteMFAOTPRequest}
227+
*/
228+
deleteMFAOTP = (request: Readonly<DeleteMFAOTPRequest>) =>
229+
this.client.fetch<void>({
230+
method: 'DELETE',
231+
path: `/account/v2/mfa/otps/${validatePathParam(
232+
'mfaOtpId',
233+
request.mfaOtpId,
234+
)}`,
235+
})
142236
}

packages/clients/src/api/account/v2/marshalling.gen.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,27 @@ import {
77
} from '../../../bridge'
88
import type { DefaultValues } from '../../../bridge'
99
import type {
10+
CreateMFAOTPRequest,
1011
CreateProjectRequest,
12+
ListMFAOTPsResponse,
1113
ListProjectsResponse,
14+
MFAOTP,
1215
Project,
1316
UpdateProjectRequest,
17+
ValidateMFAOTPRequest,
18+
ValidateMFAOTPResponse,
1419
} from './types.gen'
1520

21+
export const unmarshalMFAOTP = (data: unknown) => {
22+
if (!isJSONObject(data)) {
23+
throw new TypeError(
24+
`Unmarshalling the type 'MFAOTP' failed as data isn't a dictionary.`,
25+
)
26+
}
27+
28+
return { id: data.id } as MFAOTP
29+
}
30+
1631
export const unmarshalProject = (data: unknown) => {
1732
if (!isJSONObject(data)) {
1833
throw new TypeError(
@@ -30,6 +45,19 @@ export const unmarshalProject = (data: unknown) => {
3045
} as Project
3146
}
3247

48+
export const unmarshalListMFAOTPsResponse = (data: unknown) => {
49+
if (!isJSONObject(data)) {
50+
throw new TypeError(
51+
`Unmarshalling the type 'ListMFAOTPsResponse' failed as data isn't a dictionary.`,
52+
)
53+
}
54+
55+
return {
56+
mfaOtps: unmarshalArrayOfObject(data.mfa_otps, unmarshalMFAOTP),
57+
totalCount: data.total_count,
58+
} as ListMFAOTPsResponse
59+
}
60+
3361
export const unmarshalListProjectsResponse = (data: unknown) => {
3462
if (!isJSONObject(data)) {
3563
throw new TypeError(
@@ -43,6 +71,23 @@ export const unmarshalListProjectsResponse = (data: unknown) => {
4371
} as ListProjectsResponse
4472
}
4573

74+
export const unmarshalValidateMFAOTPResponse = (data: unknown) => {
75+
if (!isJSONObject(data)) {
76+
throw new TypeError(
77+
`Unmarshalling the type 'ValidateMFAOTPResponse' failed as data isn't a dictionary.`,
78+
)
79+
}
80+
81+
return { backupCodes: data.backup_codes } as ValidateMFAOTPResponse
82+
}
83+
84+
export const marshalCreateMFAOTPRequest = (
85+
request: CreateMFAOTPRequest,
86+
defaults: DefaultValues,
87+
): Record<string, unknown> => ({
88+
account_root_user_id: request.accountRootUserId,
89+
})
90+
4691
export const marshalCreateProjectRequest = (
4792
request: CreateProjectRequest,
4893
defaults: DefaultValues,
@@ -59,3 +104,10 @@ export const marshalUpdateProjectRequest = (
59104
description: request.description,
60105
name: request.name,
61106
})
107+
108+
export const marshalValidateMFAOTPRequest = (
109+
request: ValidateMFAOTPRequest,
110+
defaults: DefaultValues,
111+
): Record<string, unknown> => ({
112+
otp: request.otp,
113+
})

packages/clients/src/api/account/v2/types.gen.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
33

4+
export type ListMFAOTPsRequestOrderBy = 'created_at_asc' | 'created_at_desc'
5+
46
export type ListProjectsRequestOrderBy =
57
| 'created_at_asc'
68
| 'created_at_desc'
79
| 'name_asc'
810
| 'name_desc'
911

12+
/** List mfaot ps response */
13+
export interface ListMFAOTPsResponse {
14+
/** The total number of MFA OTPs */
15+
totalCount: number
16+
/** The paginated returned MFA OTPs */
17+
mfaOtps: Array<MFAOTP>
18+
}
19+
1020
/** List projects response */
1121
export interface ListProjectsResponse {
1222
/** The total number of projects */
@@ -15,6 +25,12 @@ export interface ListProjectsResponse {
1525
projects: Array<Project>
1626
}
1727

28+
/** Mfaotp */
29+
export interface MFAOTP {
30+
/** The ID of the MFA OTP */
31+
id: string
32+
}
33+
1834
/** Project */
1935
export interface Project {
2036
/** The ID of the project */
@@ -31,6 +47,12 @@ export interface Project {
3147
description: string
3248
}
3349

50+
/** Validate mfaotp response */
51+
export interface ValidateMFAOTPResponse {
52+
/** The backup codes of the MFA OTP */
53+
backupCodes: Array<string>
54+
}
55+
3456
export type CreateProjectRequest = {
3557
/** The name of the project */
3658
name: string
@@ -73,3 +95,31 @@ export type UpdateProjectRequest = {
7395
/** The description of the project */
7496
description?: string
7597
}
98+
99+
export type ListMFAOTPsRequest = {
100+
/** The page number for the returned MFA OTPs */
101+
page?: number
102+
/** The maximum number of MFA OTP per page */
103+
pageSize?: number
104+
/** The sort order of the returned MFA OTPs */
105+
orderBy?: ListMFAOTPsRequestOrderBy
106+
/** Filter out by a account root user ID */
107+
accountRootUserId: string
108+
}
109+
110+
export type CreateMFAOTPRequest = {
111+
/** The account root user ID of the MFA OTP */
112+
accountRootUserId: string
113+
}
114+
115+
export type ValidateMFAOTPRequest = {
116+
/** The MFA OTP ID */
117+
mfaOtpId: string
118+
/** The code of the MFA OTP */
119+
otp: string
120+
}
121+
122+
export type DeleteMFAOTPRequest = {
123+
/** The MFA OTP ID */
124+
mfaOtpId: string
125+
}

0 commit comments

Comments
 (0)