UNPKG

@inweb/client

Version:

JavaScript REST API client for the Open Cloud Server

698 lines (697 loc) 30.9 kB
import { EventEmitter2 } from "@inweb/eventemitter2"; import { IHttpClient } from "./IHttpClient"; import { ClientEventMap } from "./ClientEvents"; import { Assembly } from "./Assembly"; import { File } from "./File"; import { Job } from "./Job"; import { Project } from "./Project"; import { User } from "./User"; import { OAuthClient } from "./OAuthClient"; import { ISharedLinkPermissions } from "./ISharedLink"; import { SharedLink } from "./SharedLink"; import { Plugin } from "./Plugin"; /** * Provides methods for managing Open Cloud Server resources such as users, files, assemblies, jobs, * projects, etc. */ export declare class Client extends EventEmitter2<ClientEventMap> { private _serverUrl; private _httpClient; private _user; eventEmitter: EventEmitter2; /** * @param params - An object containing client configuration parameters. * @param params.serverUrl - Open Cloud REST API server URL. */ constructor(params?: { serverUrl?: string; }); /** * Open Cloud REST API server URL. Use {@link configure | configure()} to change server URL. * * @readonly */ get serverUrl(): string; /** * HTTP client instance used to send requests to the REST API server. * * @readonly */ get httpClient(): IHttpClient; /** * Changes the client parameters. * * After changing the parameters, you must re-login. * * @param params - An object containing new parameters. * @param params.serverUrl - Open Cloud REST API server URL. */ configure(params: { serverUrl?: string; }): this; /** * Returns client and server versions. * * No authorization is required to obtain the version. */ version(): Promise<{ server: string; client: string; hash: string; }>; /** * Registers a new user on the server. * * No authorization is required to register a new user. * * @param email - User email. Cannot be empty. Must be unique within the server. * @param password - User password. Cannot be empty. Password can only contain letters (a-z, A-Z), * numbers (0-9), and special characters (~!@#$%^&*()_-+={}[]<>|/'":;.,?). * @param userName - User name. Cannot be empty or blank if defined. Specify `undefined` to use * `username` from email. */ registerUser(email: string, password: string, userName?: string): Promise<any>; /** * Resends a Confirmation Email to the new user. If the user's email is already confirmed, an exception * will be thrown. * * No authorization is required to register a new user. * * A user must provide their email and password to resend their own confirmation email. An authorized * administrator can resend the email for any user by providing the user's email only; a password is * not required. * * @param email - User email. * @param password - User password. */ resendConfirmationEmail(email: string, password: string): Promise<any>; /** * Marks the user's email address as confirmed. If the user's email is already confirmed, an exception * will be thrown. * * @param emailConfirmationId - Confirmation code from the Confirmation Email. */ confirmUserEmail(emailConfirmationId: string): Promise<any>; /** * Log in an existing user using email or user name. * * @param email - An email or user name for authentication request. * @param password - Password for authentication request. */ signInWithEmail(email: string, password: string): Promise<User>; /** * Log in an existing user using access token (API Key). * * @param token - An access token for authentication request. See {@link User.token} for more details. */ signInWithToken(token: string): Promise<User>; /** * Log out. * * You must log in again using {@link signInWithEmail} or {@link signInWithToken} to continue making * requests to the server */ signOut(): void; private setCurrentUser; private clearCurrentUser; /** * Returns the current logged in user. Returns `null` if the user is not logged in or the logged in * user has deleted themselves. */ getCurrentUser(): User | null; /** * Returns the list of server enabled identity providers. * * No authorization is required to obtain a list of providers. */ getIdentityProviders(): Promise<{ name: string; url: string; }[]>; /** * Returns the current server settings. * * Only administrators can get server settings. If the current logged in user is not an administrator, * an exception will be thrown. * * @returns Returns an object with server settings. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#Settings | Open Cloud Settings API}. */ getServerSettings(): Promise<any>; /** * Changes the server settings. * * Only administrators can change server settings. If the current logged in user is not an * administrator, an exception will be thrown. * * @param settings - An object with the new server settings or part of the settings. For more * information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#Settings | Open Cloud Settings API}. * @returns Returns an object with updated server settings. */ updateServerSettings(settings: any): Promise<any>; /** * Result for OAuth client list. * * @typedef {any} OAuthClientsResult * @property {OAuthClient[]} result - Result client list. * @property {number} start - The starting index in the client list in the request. * @property {number} limit - The maximum number of requested clients. * @property {number} allSize - Total number of OAuth clients on the server. * @property {number} size - The number of clients in the result list. */ /** * Returns a list of OAuth clients of the server. * * Only administrators can get a list of OAuth clients. If the current logged in user is not an * administrator, an exception will be thrown. * * @param start - The starting index in the client list. Used for paging. * @param limit - The maximum number of clients that should be returned per request. Used for paging. */ getOAuthClients(start?: number, limit?: number): Promise<{ result: OAuthClient[]; start: number; limit: number; allSize: number; size: number; }>; /** * Returns information about the specified OAuth client. * * Only administrators can get OAuth clients. If the current logged in user is not an administrator, an * exception will be thrown. * * @param clientId - Client ID. */ getOAuthClient(clientId: string): Promise<OAuthClient>; /** * Creates a new OAuth client on the server. * * Only administrators can create OAuth clients. If the current logged in user is not an administrator, * an exception will be thrown. * * @param name - Client name. * @param redirectUrl - Endpoint to which the OAuth 2.0 server sends the response. * @param description - Client description. */ createOAuthClient(name: string, redirectUrl: string, description?: string): Promise<OAuthClient>; /** * Deletes the specified OAuth client from the server. * * Only administrators can delete OAuth clients. If the current logged in user is not an administrator, * an exception will be thrown. * * @param clientId - Client ID. * @returns Returns the raw data of a deleted client. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#OAuthClient | Open Cloud OAuth Clients API}. */ deleteOAuthClient(clientId: string): Promise<any>; /** * Returns the list of server users. * * Only administrators can get a list of users. If the current logged in user is not an administrator, * an exception will be thrown. */ getUsers(): Promise<User[]>; /** * Returns information about the specified user. * * Only administrators can get other users. If the current logged in user is not an administrator, they * can only get themselves, otherwise an exception will be thrown. * * @param userId - User ID. */ getUser(userId: string): Promise<User>; /** * Creates a new user on the server. * * Only administrators can create users. If the current logged in user is not an administrator, an * exception will be thrown. * * @param email - User email. Cannot be empty. Must be unique within the server. * @param password - User password. Cannot be empty. Password can only contain Latin letters (a-z, * A-Z), numbers (0-9), and special characters (~!@#$%^&*()_-+={}[]<>|/'":;.,?). * @param params - Additional user data. * @param params.isAdmin - `true` if user is an administrator. * @param params.userName - User name. Cannot be empty or blank if defined. Specify `undefined` to use * `username` from email. * @param params.firstName - First name. * @param params.lastName - Last name. * @param params.canCreateProject - `true` if user is allowed to create a project. * @param params.projectsLimit - The maximum number of projects that the user can create. * @param params.storageLimit - The size of the file storage available to the user in bytes. */ createUser(email: string, password: string, params?: { isAdmin?: boolean; userName?: string; firstName?: string; lastName?: string; canCreateProject?: boolean; projectsLimit?: number; storageLimit?: number; }): Promise<User>; /** * Deletes the specified user from the server. * * Only administrators can delete users. If the current logged in user is not an administrator, an * exception will be thrown. * * Administrators can delete themselves or other administrators. An administrator can only delete * themselves if they are not the last administrator. * * You need to re-login after deleting the current logged in user. * * @param userId - User ID. * @returns Returns the raw data of a deleted user. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#Users | Open Cloud Users API}. */ deleteUser(userId: string): Promise<any>; /** * Result for file list. * * @typedef {any} FilesResult * @property {File[]} result - Result file list. * @property {number} start - The starting index in the file list in the request. * @property {number} limit - The maximum number of requested files. * @property {number} allSize - Total number of files the user has access to. * @property {number} size - The number of files in the result list. */ /** * Returns a list of files from the server. * * You cannot list other users' files unless they have explicitly granted you `read` access or you are * an administrator. To list these files, you must use the file ID filter. * * You cannot list files shared with you via shared links. * * @param start - The starting index in the file list. Used for paging. * @param limit - The maximum number of files that should be returned per request. Used for paging. * @param name - Filter the files by part of the name. Case sensitive. * @param ext - Filter the files by extension. Extension can be `dgn`, `dwf`, `dwg`, `dxf`, `ifc`, * `ifczip`, `nwc`, `nwd`, `obj`, `rcs`, `rfa`, `rvt`, `step`, `stl`, `stp`, `vsf`, or any other file * type extension. * @param ids - List of file IDs to return. * @param sortByDesc - Allows to specify the descending order of the result. By default, files are * sorted by name in ascending order. * @param sortField - Allows to specify sort field. Can be `name`, `size`, `created`, or `updatedAt`. * @param shared - Returns shared files only. */ getFiles(start?: number, limit?: number, name?: string, ext?: string | string[], ids?: string | string[], sortByDesc?: boolean, sortField?: string, shared?: boolean): Promise<{ result: File[]; start: number; limit: number; allSize: number; size: number; }>; /** * Returns information about the specified file. * * You cannot retrieve other users' files unless they have explicitly granted you `read` access or you * are an administrator. * * @param fileId - File ID. */ getFile(fileId: string): Promise<File>; /** * Upload a drawing or reference file to the server. * * Fires: * * - {@link UploadProgressEvent | uploadprogress} * * @param file - {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object are * generally retrieved from a {@link https://developer.mozilla.org/docs/Web/API/FileList | FileList} * object returned as a result of a user selecting files using the HTML `<input>` element. * @param params - An object containing upload parameters. * @param params.geometry - Create the File Converter job to convert geometry data after uploading the * file. Can be one of: * * - `true` - Convert file geometry data to `VSFX` format for opening in `VisualizeJS` 3D viewer. * - `vsfx` - Convert file geometry data to `VSFX` format for opening in `VisualizeJS` 3D viewer. * - `gltf` - Convert file geometry data to `glTF` format for opening in `Three.js` 3D viewer. * * @param params.properties - Create the File Converter job to extract properties after uploading the * file. * @param params.jobParameters - Parameters for the File Converter jobs. Use this to specify additional * parameters for retrieving the geometry and properties of uploaded file. Can be given as command * line arguments in form `--arg=value`. * @param params.waitForDone - Wait for geometry and properties jobs to complete. * @param params.timeout - The time, in milliseconds that the function should wait jobs. If no one jobs * are done during this time, the `TimeoutError` exception will be thrown. * @param params.interval - The time, in milliseconds, the function should delay in between checking * jobs status. * @param params.signal - An * {@link https://developer.mozilla.org/docs/Web/API/AbortController | AbortController} signal, which * can be used to abort waiting as desired. * @param params.onCheckout - Waiting progress callback. Return `true` to cancel waiting. * @param params.onProgress - Upload progress callback. */ uploadFile(file: globalThis.File, params?: { geometry?: boolean | string; properties?: boolean; jobParameters?: { geometry?: string | object; properties?: string | object; }; waitForDone?: boolean; timeout?: number; interval?: number; signal?: AbortSignal; onCheckout?: (file: File, ready: boolean) => boolean; onProgress?: (progress: number, file: globalThis.File) => void; }): Promise<File>; /** * Deletes the specified file and all its versions from the server. * * You cannot delete other users' files unless you are an administrator. * * You cannot delete a version file, only the original file. To delete a version file use * {@link File.deleteVersion | File.deleteVersion()}. * * @param fileId - File ID. * @returns Returns the raw data of a deleted file. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#Files | Open Cloud Files API}. */ deleteFile(fileId: string): Promise<any>; /** * Downloads the specified file from the server. * * You cannot download other users' files unless they have explicitly granted you `readSourceFile` * access or you are an administrator. * * @param fileId - File ID. * @param onProgress - Download progress callback. * @param signal - An * {@link https://developer.mozilla.org/docs/Web/API/AbortController | AbortController} signal. Allows * to communicate with a fetch request and abort it if desired. */ downloadFile(fileId: string, onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>; /** * Result for job list. * * @typedef {any} JobsResult * @property {Job[]} result - Result job list. * @property {number} start - The starting index in the job list in the request. * @property {number} limit - The maximum number of requested jobs. * @property {number} allSize - Total number of jobs created by the user. * @property {number} size - The number of jobs in the result list. */ /** * Returns a list of jobs from the server. * * You cannot list other users' jobs unless you are an administrator. * * @param status - Filter the jobs by status. Status can be `waiting`, `inprogress`, `done`, or * `failed`. * @param limit - The maximum number of jobs that should be returned per request. Used for paging. * @param start - The starting index in the job list. Used for paging. * @param sortByDesc - Allows to specify the descending order of the result. By default, jobs are * sorted by creation time in ascending order. * @param sortField - Allows to specify sort field. Can be `createdAt`, `startedAt`, or `lastUpdate`. */ getJobs(status?: string | string[], limit?: number, start?: number, sortByDesc?: boolean, sortField?: string): Promise<{ result: Job[]; start: number; limit: number; allSize: number; size: number; }>; /** * Returns information about the specified job. * * You cannot retrieve other users' jobs unless you are an administrator. * * @param jobId - Job ID. */ getJob(jobId: string): Promise<Job>; /** * Creates a new job on the server for the specified file. * * You cannot create jobs for other users' files unless they have explicitly granted you `createJob` * access or you are an administrator. * * @param fileId - File ID. * @param outputFormat - The job type. Can be one of: * * - `geometry` - Convert file geometry data to `VSFX` format for opening in `VisualizeJS` 3D viewer. * - `geometryGltf` - Convert file geometry data to `glTF` format for opening in `Three.js` 3D viewer. * - `properties` - Extract file properties. * - `validation` - Validate the IFC file. * - `dwg`, `obj`, `gltf`, `glb`, `vsf`, `pdf`, `3dpdf` - Export file to the specified format. * - Other custom job name. Custom job must be registered in the job templates. * * @param parameters - Parameters for the File Converter jobs or custom job. Can be given as JSON * object or command line arguments in form `--arg=value`. */ createJob(fileId: string, outputFormat: string, parameters?: string | object): Promise<Job>; /** * Deletes the specified job from the server. * * You cannot delete other users' jobs unless you are an administrator. * * You can only delete jobs that are in the `waiting` status (jobs that have been created but not yet * started). Jobs that are currently running (`inprogress`) or have already completed (`done` or * `failed`) cannot be deleted. * * @param jobId - Job ID. * @returns Returns the raw data of a deleted job. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#Jobs | Open Cloud Jobs API}. */ deleteJob(jobId: string): Promise<any>; /** * Result for assembly list. * * @typedef {any} AssembliesResult * @property {Assembly[]} result - Result assembly list. * @property {number} start - The starting index in the assembly list in the request. * @property {number} limit - The maximum number of requested assemblies. * @property {number} allSize - Total number of assemblies the user has access to. * @property {number} size - The number of assemblies in the result list. */ /** * Returns a list of assemblies created by the current logged in user. * * @param start - The starting index in the assembly list. Used for paging. * @param limit - The maximum number of assemblies that should be returned per request. Used for * paging. * @param name - Filter the assemblies by part of the name. Case sensitive. * @param ids - List of assembly IDs to return. * @param sortByDesc - Allows to specify the descending order of the result. By default assemblies are * sorted by name in ascending order. * @param sortField - Allows to specify sort field. Can be `name` or `created`. */ getAssemblies(start?: number, limit?: number, name?: string, ids?: string | string[], sortByDesc?: boolean, sortField?: string): Promise<{ result: Assembly[]; start: number; limit: number; allSize: number; size: number; }>; /** * Returns information about the specified assembly. * * @param assemblyId - Assembly ID. */ getAssembly(assemblyId: string): Promise<Assembly>; /** * Creates a new assembly on the server. * * @param files - List of file IDs. * @param name - Assembly name. * @param params - Additional assembly creating parameters. * @param params.jobParameters - Parameters for the File Converter jobs. Use this to specify additional * parameters for generating the geometry and properties of the new assembly. Can be given as JSON * object or command line arguments in form `--arg=value`. * @param params.waitForDone - Wait for assembly to be created. * @param params.timeout - The time, in milliseconds, that the function should wait for the assembly to * be created. If the assembly is not created within this time, a TimeoutError exception will be * thrown. * @param params.interval - The time, in milliseconds, the function should delay in between checking * assembly status. * @param params.signal - An * {@link https://developer.mozilla.org/docs/Web/API/AbortController | AbortController} signal, which * can be used to abort waiting as desired. * @param params.onCheckout - Waiting progress callback. Return `true` to cancel waiting. */ createAssembly(files: string[], name: string, params?: { jobParameters?: { geometry?: string | object; properties?: string | object; }; waitForDone?: boolean; timeout?: number; interval?: number; signal?: AbortSignal; onCheckout?: (assembly: Assembly, ready: boolean) => boolean; }): Promise<Assembly>; /** * Deletes the specified assembly from the server. * * @param assemblyId - Assembly ID. * @returns Returns the raw data of a deleted assembly. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#Assemblies | Open Cloud API}. */ deleteAssembly(assemblyId: string): Promise<any>; /** * Result for project list. * * @typedef {any} ProjectsResult * @property {Project[]} result - Result project list. * @property {number} start - The starting index in the project list in the request. * @property {number} limit - The maximum number of requested projects. * @property {number} allSize - Total number of projects the user has access to. * @property {number} size - The number of projects in the result list. */ /** * Returns a list of projects that the currently logged in user has created or has access to. * * @param start - The starting index in the project list. Used for paging. * @param limit - The maximum number of projects that should be returned per request. Used for paging. * @param name - Filter the projects by part of the name. Case sensitive. * @param ids - List of project IDs to return. * @param sortByDesc - Allows to specify the descending order of the result. By default projects are * sorted by name in ascending order. * @param sortField - Allows to specify sort field. Can be `name`, `createdAt`, `updatedAt`, * `startDate`, or `endDate`. */ getProjects(start?: number, limit?: number, name?: string, ids?: string | string[], sortByDesc?: boolean, sortField?: string): Promise<{ result: Project[]; start: number; limit: number; allSize: number; size: number; }>; /** * Returns information about the specified project. * * @param projectId - Project ID. */ getProject(projectId: string): Promise<Project>; /** * Creates a new project on the server. * * @param name - Project name. * @param description - Project description. * @param startDate - Project start date. * @param endDate - Project end date. */ createProject(name: string, description?: string, startDate?: Date | string, endDate?: Date | string): Promise<Project>; /** * Deletes the specified project from the server. * * @param projectId - Project ID. * @returns Returns the raw data of a deleted project. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#Project | Open Cloud Projects API}. */ deleteProject(projectId: string): Promise<any>; /** * Returns information about the specified file shared link. * * @param token - Shared link token. */ getSharedLink(token: string): Promise<SharedLink>; /** * Creates a file shared link. * * Only file owner can create shared link. If the current logged in user is not a file owner, an * exception will be thrown. * * @param fileId - File ID. * @param permissions - Share permissions. */ createSharedLink(fileId: string, permissions?: ISharedLinkPermissions): Promise<SharedLink>; /** * Deletes the specified file shared link. * * Only file owner can delete shared link. If the current logged in user is not a file owner, an * exception will be thrown. * * @param token - Shared link token. * @returns Returns the raw data of a deleted shared link. For more information, see * {@link https://cloud.opendesign.com/docs//pages/server/api.html#ShareLinks | Open Cloud SharedLinks API}. */ deleteSharedLink(token: string): Promise<any>; /** * Returns information about a file for specified shared link token. * * Some file features are not available via shared link: * * - Updating file properties, preview, and viewpoints * - Creating file jobs * - Managing file permissions * - Managing file versions * - Deleting file * * @param token - Shared link token. * @param password - Password to get access to the file. */ getSharedFile(token: string, password?: string): Promise<File>; /** * Returns the list of installed plugins. * * Only administrators can get a list of plugins. If the current logged in user is not an * administrator, an exception will be thrown. */ getPlugins(): Promise<Plugin[]>; /** * Returns information about the specified plugin. * * Only administrators can list plugins. If the current logged in user is not an administrator, an * exception will be thrown. * * @param name - Plugin name. * @param version - Plugin version. */ getPlugin(name: string, version: string): Promise<Plugin>; /** * Uploads and install a plugin package to the server. The package must be a ZIP file and undergoes * verification, scanning, and health checks during installation. * * Only administrators can upload plugins. If the current logged in user is not an administrator, an * exception will be thrown. * * @param file - {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object are * generally retrieved from a {@link https://developer.mozilla.org/docs/Web/API/FileList | FileList} * object returned as a result of a user selecting files using the HTML `<input>` element. * @param onProgress - Upload progress callback. */ uploadPlugin(file: globalThis.File, onProgress?: (progress: number, file: globalThis.File) => void): Promise<Plugin>; /** * Uninstalls and deletes the specified plugin from the server. * * Only administrators can delete plugins. If the current logged in user is not an administrator, an * exception will be thrown. * * @param name - Plugin name. * @param version - Plugin version. */ deletePlugin(name: string, version: string): Promise<Plugin>; /** * Downloads the specified plugin package from the server. * * Only administrators can download plugin packages. If the current logged in user is not an * administrator, an exception will be thrown. * * @param name - Plugin name. * @param version - Plugin version. * @param onProgress - Download progress callback. * @param signal - An * {@link https://developer.mozilla.org/docs/Web/API/AbortController | AbortController} signal. Allows * to communicate with a fetch request and abort it if desired. */ downloadPlugin(name: string, version: string, onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer>; /** * Executes a plugin command. * * If you have multiple versions of a plugin installed and want to run the command for the latest * version of the plugin, specify `undefined` or empty string for the `version` parameter. * * @param name - Plugin name. * @param version - Plugin version. Specify `undefined` or empty string to run the command for the * latest version of the plugin. * @param command - Command to execute. * @param parameters - Command parameters. Command-dependent. */ executePluginCommand(name: string, version: string, command: string, parameters?: BodyInit | object): Promise<any>; }