diff --git a/packages/clients/src/api/account/index.ts b/packages/clients/src/api/account/index.ts index c399bf084..6235f13ce 100644 --- a/packages/clients/src/api/account/index.ts +++ b/packages/clients/src/api/account/index.ts @@ -1 +1,2 @@ export * as v2 from './v2/index.gen' +export * as v3 from './v3/index.gen' diff --git a/packages/clients/src/api/account/v3/api.gen.ts b/packages/clients/src/api/account/v3/api.gen.ts new file mode 100644 index 000000000..05fb498e6 --- /dev/null +++ b/packages/clients/src/api/account/v3/api.gen.ts @@ -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) => + this.client.fetch( + { + body: JSON.stringify( + marshalProjectApiCreateProjectRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/account/v3/projects`, + }, + unmarshalProject, + ) + + protected pageOfListProjects = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + 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 = {}) => + 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 = {}) => + this.client.fetch( + { + 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 = {}) => + this.client.fetch({ + 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 = {}) => + this.client.fetch( + { + 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, + ) +} diff --git a/packages/clients/src/api/account/v3/index.gen.ts b/packages/clients/src/api/account/v3/index.gen.ts new file mode 100644 index 000000000..2760d6891 --- /dev/null +++ b/packages/clients/src/api/account/v3/index.gen.ts @@ -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' diff --git a/packages/clients/src/api/account/v3/marshalling.gen.ts b/packages/clients/src/api/account/v3/marshalling.gen.ts new file mode 100644 index 000000000..151eb0a5c --- /dev/null +++ b/packages/clients/src/api/account/v3/marshalling.gen.ts @@ -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 => ({ + description: request.description, + name: request.name || randomName('proj'), + organization_id: request.organizationId ?? defaults.defaultOrganizationId, +}) + +export const marshalProjectApiUpdateProjectRequest = ( + request: ProjectApiUpdateProjectRequest, + defaults: DefaultValues, +): Record => ({ + description: request.description, + name: request.name, +}) diff --git a/packages/clients/src/api/account/v3/types.gen.ts b/packages/clients/src/api/account/v3/types.gen.ts new file mode 100644 index 000000000..d35012ac5 --- /dev/null +++ b/packages/clients/src/api/account/v3/types.gen.ts @@ -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 +} diff --git a/packages/clients/src/api/account/v3/validation-rules.gen.ts b/packages/clients/src/api/account/v3/validation-rules.gen.ts new file mode 100644 index 000000000..f8adbd9da --- /dev/null +++ b/packages/clients/src/api/account/v3/validation-rules.gen.ts @@ -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\._\- ]+$/, + }, +}