Skip to content

Commit f8d7ab3

Browse files
authored
feat(account): add v2 (#15)
1 parent 3f57eca commit f8d7ab3

File tree

5 files changed

+278
-0
lines changed

5 files changed

+278
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * as v2alpha1 from './v2alpha1'
2+
export * as v2 from './v2'
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
API,
5+
enrichForPagination,
6+
urlParams,
7+
validatePathParam,
8+
} from '../../../bridge'
9+
import {
10+
marshalCreateProjectRequest,
11+
marshalUpdateProjectRequest,
12+
unmarshalListProjectsResponse,
13+
unmarshalProject,
14+
} from './marshalling.gen'
15+
import type {
16+
CreateProjectRequest,
17+
DeleteProjectRequest,
18+
GetProjectRequest,
19+
ListProjectsRequest,
20+
ListProjectsResponse,
21+
Project,
22+
UpdateProjectRequest,
23+
} from './types.gen'
24+
25+
const jsonContentHeaders = {
26+
'Content-Type': 'application/json; charset=utf-8',
27+
}
28+
29+
/**
30+
* Account API.
31+
*
32+
* This API allows you to manage projects.
33+
*/
34+
export class AccountV2GenAPI extends API {
35+
/**
36+
* Create project
37+
*
38+
* @param request - The request {@link CreateProjectRequest}
39+
* @returns A Promise of Project
40+
*/
41+
createProject = (request: Readonly<CreateProjectRequest>) =>
42+
this.client.fetch<Project>(
43+
{
44+
body: JSON.stringify(
45+
marshalCreateProjectRequest(request, this.client.settings),
46+
),
47+
headers: jsonContentHeaders,
48+
method: 'POST',
49+
path: `/account/v2/projects`,
50+
},
51+
unmarshalProject,
52+
)
53+
54+
protected pageOfListProjects = (
55+
request: Readonly<ListProjectsRequest> = {},
56+
) =>
57+
this.client.fetch<ListProjectsResponse>(
58+
{
59+
method: 'GET',
60+
path: `/account/v2/projects`,
61+
urlParams: urlParams(
62+
['name', request.name],
63+
['order_by', request.orderBy ?? 'created_at_asc'],
64+
[
65+
'organization_id',
66+
request.organizationId ??
67+
this.client.settings.defaultOrganizationId,
68+
],
69+
['page', request.page],
70+
[
71+
'page_size',
72+
request.pageSize ?? this.client.settings.defaultPageSize,
73+
],
74+
),
75+
},
76+
unmarshalListProjectsResponse,
77+
)
78+
79+
/**
80+
* List projects
81+
*
82+
* @param request - The request {@link ListProjectsRequest}
83+
* @returns A Promise of ListProjectsResponse
84+
*/
85+
listProjects = (request: Readonly<ListProjectsRequest> = {}) =>
86+
enrichForPagination('projects', this.pageOfListProjects, request)
87+
88+
/**
89+
* Get project
90+
*
91+
* @param request - The request {@link GetProjectRequest}
92+
* @returns A Promise of Project
93+
*/
94+
getProject = (request: Readonly<GetProjectRequest> = {}) =>
95+
this.client.fetch<Project>(
96+
{
97+
method: 'GET',
98+
path: `/account/v2/projects/${validatePathParam(
99+
'projectId',
100+
request.projectId ?? this.client.settings.defaultProjectId,
101+
)}`,
102+
},
103+
unmarshalProject,
104+
)
105+
106+
/**
107+
* Delete project
108+
*
109+
* @param request - The request {@link DeleteProjectRequest}
110+
*/
111+
deleteProject = (request: Readonly<DeleteProjectRequest> = {}) =>
112+
this.client.fetch<void>({
113+
method: 'DELETE',
114+
path: `/account/v2/projects/${validatePathParam(
115+
'projectId',
116+
request.projectId ?? this.client.settings.defaultProjectId,
117+
)}`,
118+
})
119+
120+
/**
121+
* Update project
122+
*
123+
* @param request - The request {@link UpdateProjectRequest}
124+
* @returns A Promise of Project
125+
*/
126+
updateProject = (request: Readonly<UpdateProjectRequest> = {}) =>
127+
this.client.fetch<Project>(
128+
{
129+
body: JSON.stringify(
130+
marshalUpdateProjectRequest(request, this.client.settings),
131+
),
132+
headers: jsonContentHeaders,
133+
method: 'PATCH',
134+
path: `/account/v2/projects/${validatePathParam(
135+
'projectId',
136+
request.projectId ?? this.client.settings.defaultProjectId,
137+
)}`,
138+
},
139+
unmarshalProject,
140+
)
141+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { AccountV2GenAPI as API } from './api.gen'
2+
export * from './types.gen'
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
isJSONObject,
5+
unmarshalArrayOfObject,
6+
unmarshalDate,
7+
} from '../../../bridge'
8+
import type { DefaultValues } from '../../../bridge'
9+
import type {
10+
CreateProjectRequest,
11+
ListProjectsResponse,
12+
Project,
13+
UpdateProjectRequest,
14+
} from './types.gen'
15+
16+
export const unmarshalProject = (data: unknown) => {
17+
if (!isJSONObject(data)) {
18+
throw new TypeError(
19+
`Unmarshalling the type 'Project' failed as data isn't a dictionary.`,
20+
)
21+
}
22+
23+
return {
24+
createdAt: unmarshalDate(data.created_at),
25+
description: data.description,
26+
id: data.id,
27+
name: data.name,
28+
organizationId: data.organization_id,
29+
updatedAt: unmarshalDate(data.updated_at),
30+
} as Project
31+
}
32+
33+
export const unmarshalListProjectsResponse = (data: unknown) => {
34+
if (!isJSONObject(data)) {
35+
throw new TypeError(
36+
`Unmarshalling the type 'ListProjectsResponse' failed as data isn't a dictionary.`,
37+
)
38+
}
39+
40+
return {
41+
projects: unmarshalArrayOfObject(data.projects, unmarshalProject),
42+
totalCount: data.total_count,
43+
} as ListProjectsResponse
44+
}
45+
46+
export const marshalCreateProjectRequest = (
47+
request: CreateProjectRequest,
48+
defaults: DefaultValues,
49+
): Record<string, unknown> => ({
50+
description: request.description,
51+
name: request.name,
52+
organization_id: request.organizationId ?? defaults.defaultOrganizationId,
53+
})
54+
55+
export const marshalUpdateProjectRequest = (
56+
request: UpdateProjectRequest,
57+
defaults: DefaultValues,
58+
): Record<string, unknown> => ({
59+
description: request.description,
60+
name: request.name,
61+
})
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
4+
export type ListProjectsRequestOrderBy =
5+
| 'created_at_asc'
6+
| 'created_at_desc'
7+
| 'name_asc'
8+
| 'name_desc'
9+
10+
/** List projects response */
11+
export interface ListProjectsResponse {
12+
/** The total number of projects */
13+
totalCount: number
14+
/** The paginated returned projects */
15+
projects: Array<Project>
16+
}
17+
18+
/** Project */
19+
export interface Project {
20+
/** The ID of the project */
21+
id: string
22+
/** The name of the project */
23+
name: string
24+
/** The organization ID of the project */
25+
organizationId: string
26+
/** The creation date of the project */
27+
createdAt?: Date
28+
/** The update date of the project */
29+
updatedAt?: Date
30+
/** The description of the project */
31+
description: string
32+
}
33+
34+
export type CreateProjectRequest = {
35+
/** The name of the project */
36+
name: string
37+
/** The organization ID of the project */
38+
organizationId?: string
39+
/** The description of the project */
40+
description?: string
41+
}
42+
43+
export type ListProjectsRequest = {
44+
/** The organization ID of the project */
45+
organizationId?: string
46+
/** The name of the project */
47+
name?: string
48+
/** The page number for the returned projects */
49+
page?: number
50+
/** The maximum number of project per page */
51+
pageSize?: number
52+
/** The sort order of the returned projects */
53+
orderBy?: ListProjectsRequestOrderBy
54+
}
55+
56+
export type GetProjectRequest = {
57+
/** The project ID of the project */
58+
projectId?: string
59+
}
60+
61+
export type DeleteProjectRequest = {
62+
/** The project ID of the project */
63+
projectId?: string
64+
}
65+
66+
export type UpdateProjectRequest = {
67+
/** The project ID of the project */
68+
projectId?: string
69+
/** The name of the project */
70+
name?: string
71+
/** The description of the project */
72+
description?: string
73+
}

0 commit comments

Comments
 (0)