Skip to content

Commit bdf3d69

Browse files
feat(account): add v3 and the ProjectAPI (#769)
Co-authored-by: Vincent Germain <[email protected]>
1 parent 0345968 commit bdf3d69

File tree

6 files changed

+346
-0
lines changed

6 files changed

+346
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * as v2 from './v2/index.gen'
2+
export * as v3 from './v3/index.gen'
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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 as ParentAPI,
5+
enrichForPagination,
6+
urlParams,
7+
validatePathParam,
8+
} from '../../../bridge'
9+
import {
10+
marshalProjectApiCreateProjectRequest,
11+
marshalProjectApiUpdateProjectRequest,
12+
unmarshalListProjectsResponse,
13+
unmarshalProject,
14+
} from './marshalling.gen'
15+
import type {
16+
ListProjectsResponse,
17+
Project,
18+
ProjectApiCreateProjectRequest,
19+
ProjectApiDeleteProjectRequest,
20+
ProjectApiGetProjectRequest,
21+
ProjectApiListProjectsRequest,
22+
ProjectApiUpdateProjectRequest,
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 ProjectAPI extends ParentAPI {
35+
/**
36+
* Create a new Project for an Organization. Generate a new Project for an
37+
* Organization, specifying its configuration including name and description.
38+
*
39+
* @param request - The request {@link ProjectApiCreateProjectRequest}
40+
* @returns A Promise of Project
41+
*/
42+
createProject = (request: Readonly<ProjectApiCreateProjectRequest>) =>
43+
this.client.fetch<Project>(
44+
{
45+
body: JSON.stringify(
46+
marshalProjectApiCreateProjectRequest(request, this.client.settings),
47+
),
48+
headers: jsonContentHeaders,
49+
method: 'POST',
50+
path: `/account/v3/projects`,
51+
},
52+
unmarshalProject,
53+
)
54+
55+
protected pageOfListProjects = (
56+
request: Readonly<ProjectApiListProjectsRequest> = {},
57+
) =>
58+
this.client.fetch<ListProjectsResponse>(
59+
{
60+
method: 'GET',
61+
path: `/account/v3/projects`,
62+
urlParams: urlParams(
63+
['name', request.name],
64+
['order_by', request.orderBy ?? 'created_at_asc'],
65+
[
66+
'organization_id',
67+
request.organizationId ??
68+
this.client.settings.defaultOrganizationId,
69+
],
70+
['page', request.page],
71+
[
72+
'page_size',
73+
request.pageSize ?? this.client.settings.defaultPageSize,
74+
],
75+
['project_ids', request.projectIds],
76+
),
77+
},
78+
unmarshalListProjectsResponse,
79+
)
80+
81+
/**
82+
* List all Projects of an Organization. List all Projects of an Organization.
83+
* The response will include the total number of Projects as well as their
84+
* associated Organizations, names, and IDs. Other information includes the
85+
* creation and update date of the Project.
86+
*
87+
* @param request - The request {@link ProjectApiListProjectsRequest}
88+
* @returns A Promise of ListProjectsResponse
89+
*/
90+
listProjects = (request: Readonly<ProjectApiListProjectsRequest> = {}) =>
91+
enrichForPagination('projects', this.pageOfListProjects, request)
92+
93+
/**
94+
* Get an existing Project. Retrieve information about an existing Project,
95+
* specified by its Project ID. Its full details, including ID, name and
96+
* description, are returned in the response object.
97+
*
98+
* @param request - The request {@link ProjectApiGetProjectRequest}
99+
* @returns A Promise of Project
100+
*/
101+
getProject = (request: Readonly<ProjectApiGetProjectRequest> = {}) =>
102+
this.client.fetch<Project>(
103+
{
104+
method: 'GET',
105+
path: `/account/v3/projects/${validatePathParam(
106+
'projectId',
107+
request.projectId ?? this.client.settings.defaultProjectId,
108+
)}`,
109+
},
110+
unmarshalProject,
111+
)
112+
113+
/**
114+
* Delete an existing Project. Delete an existing Project, specified by its
115+
* Project ID. The Project needs to be empty (meaning there are no resources
116+
* left in it) to be deleted effectively. Note that deleting a Project is
117+
* permanent, and cannot be undone.
118+
*
119+
* @param request - The request {@link ProjectApiDeleteProjectRequest}
120+
*/
121+
deleteProject = (request: Readonly<ProjectApiDeleteProjectRequest> = {}) =>
122+
this.client.fetch<void>({
123+
method: 'DELETE',
124+
path: `/account/v3/projects/${validatePathParam(
125+
'projectId',
126+
request.projectId ?? this.client.settings.defaultProjectId,
127+
)}`,
128+
})
129+
130+
/**
131+
* Update Project. Update the parameters of an existing Project, specified by
132+
* its Project ID. These parameters include the name and description.
133+
*
134+
* @param request - The request {@link ProjectApiUpdateProjectRequest}
135+
* @returns A Promise of Project
136+
*/
137+
updateProject = (request: Readonly<ProjectApiUpdateProjectRequest> = {}) =>
138+
this.client.fetch<Project>(
139+
{
140+
body: JSON.stringify(
141+
marshalProjectApiUpdateProjectRequest(request, this.client.settings),
142+
),
143+
headers: jsonContentHeaders,
144+
method: 'PATCH',
145+
path: `/account/v3/projects/${validatePathParam(
146+
'projectId',
147+
request.projectId ?? this.client.settings.defaultProjectId,
148+
)}`,
149+
},
150+
unmarshalProject,
151+
)
152+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
export { ProjectAPI } from './api.gen'
4+
export type {
5+
ListProjectsRequestOrderBy,
6+
ListProjectsResponse,
7+
Project,
8+
ProjectApiCreateProjectRequest,
9+
ProjectApiDeleteProjectRequest,
10+
ProjectApiGetProjectRequest,
11+
ProjectApiListProjectsRequest,
12+
ProjectApiUpdateProjectRequest,
13+
} from './types.gen'
14+
export * as ValidationRules from './validation-rules.gen'
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 randomName from '@scaleway/random-name'
4+
import {
5+
isJSONObject,
6+
unmarshalArrayOfObject,
7+
unmarshalDate,
8+
} from '../../../bridge'
9+
import type { DefaultValues } from '../../../bridge'
10+
import type {
11+
ListProjectsResponse,
12+
Project,
13+
ProjectApiCreateProjectRequest,
14+
ProjectApiUpdateProjectRequest,
15+
} from './types.gen'
16+
17+
export const unmarshalProject = (data: unknown) => {
18+
if (!isJSONObject(data)) {
19+
throw new TypeError(
20+
`Unmarshalling the type 'Project' failed as data isn't a dictionary.`,
21+
)
22+
}
23+
24+
return {
25+
createdAt: unmarshalDate(data.created_at),
26+
description: data.description,
27+
id: data.id,
28+
name: data.name,
29+
organizationId: data.organization_id,
30+
updatedAt: unmarshalDate(data.updated_at),
31+
} as Project
32+
}
33+
34+
export const unmarshalListProjectsResponse = (data: unknown) => {
35+
if (!isJSONObject(data)) {
36+
throw new TypeError(
37+
`Unmarshalling the type 'ListProjectsResponse' failed as data isn't a dictionary.`,
38+
)
39+
}
40+
41+
return {
42+
projects: unmarshalArrayOfObject(data.projects, unmarshalProject),
43+
totalCount: data.total_count,
44+
} as ListProjectsResponse
45+
}
46+
47+
export const marshalProjectApiCreateProjectRequest = (
48+
request: ProjectApiCreateProjectRequest,
49+
defaults: DefaultValues,
50+
): Record<string, unknown> => ({
51+
description: request.description,
52+
name: request.name || randomName('proj'),
53+
organization_id: request.organizationId ?? defaults.defaultOrganizationId,
54+
})
55+
56+
export const marshalProjectApiUpdateProjectRequest = (
57+
request: ProjectApiUpdateProjectRequest,
58+
defaults: DefaultValues,
59+
): Record<string, unknown> => ({
60+
description: request.description,
61+
name: request.name,
62+
})
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
/** Total number of Projects. */
13+
totalCount: number
14+
/** Paginated returned Projects. */
15+
projects: Project[]
16+
}
17+
18+
/** Project. */
19+
export interface Project {
20+
/** ID of the Project. */
21+
id: string
22+
/** Name of the Project. */
23+
name: string
24+
/** Organization ID of the Project. */
25+
organizationId: string
26+
/** Creation date of the Project. */
27+
createdAt?: Date
28+
/** Update date of the Project. */
29+
updatedAt?: Date
30+
/** Description of the Project. */
31+
description: string
32+
}
33+
34+
export type ProjectApiCreateProjectRequest = {
35+
/** Name of the Project. */
36+
name?: string
37+
/** Organization ID of the Project. */
38+
organizationId?: string
39+
/** Description of the Project. */
40+
description: string
41+
}
42+
43+
export type ProjectApiListProjectsRequest = {
44+
/** Organization ID of the Project. */
45+
organizationId?: string
46+
/** Name of the Project. */
47+
name?: string
48+
/** Page number for the returned Projects. */
49+
page?: number
50+
/** Maximum number of Project per page. */
51+
pageSize?: number
52+
/** Sort order of the returned Projects. */
53+
orderBy?: ListProjectsRequestOrderBy
54+
/**
55+
* Project IDs to filter for. The results will be limited to any Projects with
56+
* an ID in this array.
57+
*/
58+
projectIds?: string[]
59+
}
60+
61+
export type ProjectApiGetProjectRequest = {
62+
/** Project ID of the Project. */
63+
projectId?: string
64+
}
65+
66+
export type ProjectApiDeleteProjectRequest = {
67+
/** Project ID of the Project. */
68+
projectId?: string
69+
}
70+
71+
export type ProjectApiUpdateProjectRequest = {
72+
/** Project ID of the Project. */
73+
projectId?: string
74+
/** Name of the Project. */
75+
name?: string
76+
/** Description of the Project. */
77+
description?: string
78+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 const ProjectApiCreateProjectRequest = {
5+
description: {
6+
maxLength: 200,
7+
},
8+
name: {
9+
maxLength: 64,
10+
minLength: 1,
11+
pattern: /^[a-zA-Z0-9\._\- ]+$/,
12+
},
13+
}
14+
15+
export const ProjectApiListProjectsRequest = {
16+
name: {
17+
maxLength: 64,
18+
minLength: 1,
19+
pattern: /^[a-zA-Z0-9\._\- ]+$/,
20+
},
21+
page: {
22+
greaterThan: 0,
23+
},
24+
pageSize: {
25+
greaterThanOrEqual: 1,
26+
lessThanOrEqual: 100,
27+
},
28+
}
29+
30+
export const ProjectApiUpdateProjectRequest = {
31+
description: {
32+
maxLength: 200,
33+
},
34+
name: {
35+
maxLength: 64,
36+
minLength: 1,
37+
pattern: /^[a-zA-Z0-9\._\- ]+$/,
38+
},
39+
}

0 commit comments

Comments
 (0)