Skip to content

feat(account): add v3 and the ProjectAPI #769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/clients/src/api/account/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * as v2 from './v2/index.gen'
export * as v3 from './v3/index.gen'
152 changes: 152 additions & 0 deletions packages/clients/src/api/account/v3/api.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.
import {
API as ParentAPI,
enrichForPagination,
urlParams,
validatePathParam,
} from '../../../bridge'
import {
marshalProjectApiCreateProjectRequest,
marshalProjectApiUpdateProjectRequest,
unmarshalListProjectsResponse,
unmarshalProject,
} from './marshalling.gen'
import type {
ListProjectsResponse,
Project,
ProjectApiCreateProjectRequest,
ProjectApiDeleteProjectRequest,
ProjectApiGetProjectRequest,
ProjectApiListProjectsRequest,
ProjectApiUpdateProjectRequest,
} from './types.gen'

const jsonContentHeaders = {
'Content-Type': 'application/json; charset=utf-8',
}

/**
* Account API.
*
* This API allows you to manage projects.
*/
export class ProjectAPI extends ParentAPI {
/**
* Create a new Project for an Organization. Generate a new Project for an
* Organization, specifying its configuration including name and description.
*
* @param request - The request {@link ProjectApiCreateProjectRequest}
* @returns A Promise of Project
*/
createProject = (request: Readonly<ProjectApiCreateProjectRequest>) =>
this.client.fetch<Project>(
{
body: JSON.stringify(
marshalProjectApiCreateProjectRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/account/v3/projects`,
},
unmarshalProject,
)

protected pageOfListProjects = (
request: Readonly<ProjectApiListProjectsRequest> = {},
) =>
this.client.fetch<ListProjectsResponse>(
{
method: 'GET',
path: `/account/v3/projects`,
urlParams: urlParams(
['name', request.name],
['order_by', request.orderBy ?? 'created_at_asc'],
[
'organization_id',
request.organizationId ??
this.client.settings.defaultOrganizationId,
],
['page', request.page],
[
'page_size',
request.pageSize ?? this.client.settings.defaultPageSize,
],
['project_ids', request.projectIds],
),
},
unmarshalListProjectsResponse,
)

/**
* List all Projects of an Organization. List all Projects of an Organization.
* The response will include the total number of Projects as well as their
* associated Organizations, names, and IDs. Other information includes the
* creation and update date of the Project.
*
* @param request - The request {@link ProjectApiListProjectsRequest}
* @returns A Promise of ListProjectsResponse
*/
listProjects = (request: Readonly<ProjectApiListProjectsRequest> = {}) =>
enrichForPagination('projects', this.pageOfListProjects, request)

/**
* Get an existing Project. Retrieve information about an existing Project,
* specified by its Project ID. Its full details, including ID, name and
* description, are returned in the response object.
*
* @param request - The request {@link ProjectApiGetProjectRequest}
* @returns A Promise of Project
*/
getProject = (request: Readonly<ProjectApiGetProjectRequest> = {}) =>
this.client.fetch<Project>(
{
method: 'GET',
path: `/account/v3/projects/${validatePathParam(
'projectId',
request.projectId ?? this.client.settings.defaultProjectId,
)}`,
},
unmarshalProject,
)

/**
* Delete an existing Project. Delete an existing Project, specified by its
* Project ID. The Project needs to be empty (meaning there are no resources
* left in it) to be deleted effectively. Note that deleting a Project is
* permanent, and cannot be undone.
*
* @param request - The request {@link ProjectApiDeleteProjectRequest}
*/
deleteProject = (request: Readonly<ProjectApiDeleteProjectRequest> = {}) =>
this.client.fetch<void>({
method: 'DELETE',
path: `/account/v3/projects/${validatePathParam(
'projectId',
request.projectId ?? this.client.settings.defaultProjectId,
)}`,
})

/**
* Update Project. Update the parameters of an existing Project, specified by
* its Project ID. These parameters include the name and description.
*
* @param request - The request {@link ProjectApiUpdateProjectRequest}
* @returns A Promise of Project
*/
updateProject = (request: Readonly<ProjectApiUpdateProjectRequest> = {}) =>
this.client.fetch<Project>(
{
body: JSON.stringify(
marshalProjectApiUpdateProjectRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'PATCH',
path: `/account/v3/projects/${validatePathParam(
'projectId',
request.projectId ?? this.client.settings.defaultProjectId,
)}`,
},
unmarshalProject,
)
}
14 changes: 14 additions & 0 deletions packages/clients/src/api/account/v3/index.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.
export { ProjectAPI } from './api.gen'
export type {
ListProjectsRequestOrderBy,
ListProjectsResponse,
Project,
ProjectApiCreateProjectRequest,
ProjectApiDeleteProjectRequest,
ProjectApiGetProjectRequest,
ProjectApiListProjectsRequest,
ProjectApiUpdateProjectRequest,
} from './types.gen'
export * as ValidationRules from './validation-rules.gen'
62 changes: 62 additions & 0 deletions packages/clients/src/api/account/v3/marshalling.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.
import randomName from '@scaleway/random-name'
import {
isJSONObject,
unmarshalArrayOfObject,
unmarshalDate,
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
ListProjectsResponse,
Project,
ProjectApiCreateProjectRequest,
ProjectApiUpdateProjectRequest,
} from './types.gen'

export const unmarshalProject = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'Project' failed as data isn't a dictionary.`,
)
}

return {
createdAt: unmarshalDate(data.created_at),
description: data.description,
id: data.id,
name: data.name,
organizationId: data.organization_id,
updatedAt: unmarshalDate(data.updated_at),
} as Project
}

export const unmarshalListProjectsResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ListProjectsResponse' failed as data isn't a dictionary.`,
)
}

return {
projects: unmarshalArrayOfObject(data.projects, unmarshalProject),
totalCount: data.total_count,
} as ListProjectsResponse
}

export const marshalProjectApiCreateProjectRequest = (
request: ProjectApiCreateProjectRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
description: request.description,
name: request.name || randomName('proj'),
organization_id: request.organizationId ?? defaults.defaultOrganizationId,
})

export const marshalProjectApiUpdateProjectRequest = (
request: ProjectApiUpdateProjectRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
description: request.description,
name: request.name,
})
78 changes: 78 additions & 0 deletions packages/clients/src/api/account/v3/types.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.

export type ListProjectsRequestOrderBy =
| 'created_at_asc'
| 'created_at_desc'
| 'name_asc'
| 'name_desc'

/** List projects response. */
export interface ListProjectsResponse {
/** Total number of Projects. */
totalCount: number
/** Paginated returned Projects. */
projects: Project[]
}

/** Project. */
export interface Project {
/** ID of the Project. */
id: string
/** Name of the Project. */
name: string
/** Organization ID of the Project. */
organizationId: string
/** Creation date of the Project. */
createdAt?: Date
/** Update date of the Project. */
updatedAt?: Date
/** Description of the Project. */
description: string
}

export type ProjectApiCreateProjectRequest = {
/** Name of the Project. */
name?: string
/** Organization ID of the Project. */
organizationId?: string
/** Description of the Project. */
description: string
}

export type ProjectApiListProjectsRequest = {
/** Organization ID of the Project. */
organizationId?: string
/** Name of the Project. */
name?: string
/** Page number for the returned Projects. */
page?: number
/** Maximum number of Project per page. */
pageSize?: number
/** Sort order of the returned Projects. */
orderBy?: ListProjectsRequestOrderBy
/**
* Project IDs to filter for. The results will be limited to any Projects with
* an ID in this array.
*/
projectIds?: string[]
}

export type ProjectApiGetProjectRequest = {
/** Project ID of the Project. */
projectId?: string
}

export type ProjectApiDeleteProjectRequest = {
/** Project ID of the Project. */
projectId?: string
}

export type ProjectApiUpdateProjectRequest = {
/** Project ID of the Project. */
projectId?: string
/** Name of the Project. */
name?: string
/** Description of the Project. */
description?: string
}
39 changes: 39 additions & 0 deletions packages/clients/src/api/account/v3/validation-rules.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.

export const ProjectApiCreateProjectRequest = {
description: {
maxLength: 200,
},
name: {
maxLength: 64,
minLength: 1,
pattern: /^[a-zA-Z0-9\._\- ]+$/,
},
}

export const ProjectApiListProjectsRequest = {
name: {
maxLength: 64,
minLength: 1,
pattern: /^[a-zA-Z0-9\._\- ]+$/,
},
page: {
greaterThan: 0,
},
pageSize: {
greaterThanOrEqual: 1,
lessThanOrEqual: 100,
},
}

export const ProjectApiUpdateProjectRequest = {
description: {
maxLength: 200,
},
name: {
maxLength: 64,
minLength: 1,
pattern: /^[a-zA-Z0-9\._\- ]+$/,
},
}