UNPKG

neon-sdk

Version:

TypeScript SDK for managing your Neon Serverless PostgreSQL projects

1,376 lines (1,367 loc) 86.6 kB
// generated/core/BaseHttpRequest.ts var BaseHttpRequest = class { constructor(config) { this.config = config; } }; // generated/core/ApiError.ts var ApiError = class extends Error { url; status; statusText; body; request; constructor(request2, response, message) { super(message); this.name = "ApiError"; this.url = response.url; this.status = response.status; this.statusText = response.statusText; this.body = response.body; this.request = request2; } }; // generated/core/CancelablePromise.ts var CancelError = class extends Error { constructor(message) { super(message); this.name = "CancelError"; } get isCancelled() { return true; } }; var CancelablePromise = class { #isResolved; #isRejected; #isCancelled; #cancelHandlers; #promise; #resolve; #reject; constructor(executor) { this.#isResolved = false; this.#isRejected = false; this.#isCancelled = false; this.#cancelHandlers = []; this.#promise = new Promise((resolve2, reject) => { this.#resolve = resolve2; this.#reject = reject; const onResolve = (value) => { if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } this.#isResolved = true; if (this.#resolve) this.#resolve(value); }; const onReject = (reason) => { if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } this.#isRejected = true; if (this.#reject) this.#reject(reason); }; const onCancel = (cancelHandler) => { if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } this.#cancelHandlers.push(cancelHandler); }; Object.defineProperty(onCancel, "isResolved", { get: () => this.#isResolved }); Object.defineProperty(onCancel, "isRejected", { get: () => this.#isRejected }); Object.defineProperty(onCancel, "isCancelled", { get: () => this.#isCancelled }); return executor(onResolve, onReject, onCancel); }); } get [Symbol.toStringTag]() { return "Cancellable Promise"; } then(onFulfilled, onRejected) { return this.#promise.then(onFulfilled, onRejected); } catch(onRejected) { return this.#promise.catch(onRejected); } finally(onFinally) { return this.#promise.finally(onFinally); } cancel() { if (this.#isResolved || this.#isRejected || this.#isCancelled) { return; } this.#isCancelled = true; if (this.#cancelHandlers.length) { try { for (const cancelHandler of this.#cancelHandlers) { cancelHandler(); } } catch (error) { console.warn("Cancellation threw an error", error); return; } } this.#cancelHandlers.length = 0; if (this.#reject) this.#reject(new CancelError("Request aborted")); } get isCancelled() { return this.#isCancelled; } }; // generated/core/request.ts var isDefined = (value) => { return value !== void 0 && value !== null; }; var isString = (value) => { return typeof value === "string"; }; var isStringWithValue = (value) => { return isString(value) && value !== ""; }; var isBlob = (value) => { return typeof value === "object" && typeof value.type === "string" && typeof value.stream === "function" && typeof value.arrayBuffer === "function" && typeof value.constructor === "function" && typeof value.constructor.name === "string" && /^(Blob|File)$/.test(value.constructor.name) && /^(Blob|File)$/.test(value[Symbol.toStringTag]); }; var isFormData = (value) => { return value instanceof FormData; }; var base64 = (str) => { try { return btoa(str); } catch (err) { return Buffer.from(str).toString("base64"); } }; var getQueryString = (params) => { const qs = []; const append = (key, value) => { qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); }; const process = (key, value) => { if (isDefined(value)) { if (Array.isArray(value)) { value.forEach((v) => { process(key, v); }); } else if (typeof value === "object") { Object.entries(value).forEach(([k, v]) => { process(`${key}[${k}]`, v); }); } else { append(key, value); } } }; Object.entries(params).forEach(([key, value]) => { process(key, value); }); if (qs.length > 0) { return `?${qs.join("&")}`; } return ""; }; var getUrl = (config, options) => { const encoder = config.ENCODE_PATH || encodeURI; const path = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => { if (options.path?.hasOwnProperty(group)) { return encoder(String(options.path[group])); } return substring; }); const url = `${config.BASE}${path}`; if (options.query) { return `${url}${getQueryString(options.query)}`; } return url; }; var getFormData = (options) => { if (options.formData) { const formData = new FormData(); const process = (key, value) => { if (isString(value) || isBlob(value)) { formData.append(key, value); } else { formData.append(key, JSON.stringify(value)); } }; Object.entries(options.formData).filter(([_, value]) => isDefined(value)).forEach(([key, value]) => { if (Array.isArray(value)) { value.forEach((v) => process(key, v)); } else { process(key, value); } }); return formData; } return void 0; }; var resolve = async (options, resolver) => { if (typeof resolver === "function") { return resolver(options); } return resolver; }; var getHeaders = async (config, options) => { const [token, username, password, additionalHeaders] = await Promise.all([ resolve(options, config.TOKEN), resolve(options, config.USERNAME), resolve(options, config.PASSWORD), resolve(options, config.HEADERS) ]); const headers = Object.entries({ Accept: "application/json", ...additionalHeaders, ...options.headers }).filter(([_, value]) => isDefined(value)).reduce((headers2, [key, value]) => ({ ...headers2, [key]: String(value) }), {}); if (isStringWithValue(token)) { headers["Authorization"] = `Bearer ${token}`; } if (isStringWithValue(username) && isStringWithValue(password)) { const credentials = base64(`${username}:${password}`); headers["Authorization"] = `Basic ${credentials}`; } if (options.body !== void 0) { if (options.mediaType) { headers["Content-Type"] = options.mediaType; } else if (isBlob(options.body)) { headers["Content-Type"] = options.body.type || "application/octet-stream"; } else if (isString(options.body)) { headers["Content-Type"] = "text/plain"; } else if (!isFormData(options.body)) { headers["Content-Type"] = "application/json"; } } return new Headers(headers); }; var getRequestBody = (options) => { if (options.body !== void 0) { if (options.mediaType?.includes("/json")) { return JSON.stringify(options.body); } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) { return options.body; } else { return JSON.stringify(options.body); } } return void 0; }; var sendRequest = async (config, options, url, body, formData, headers, onCancel) => { const controller = new AbortController(); const request2 = { headers, body: body ?? formData, method: options.method, signal: controller.signal }; if (config.WITH_CREDENTIALS) { request2.credentials = config.CREDENTIALS; } onCancel(() => controller.abort()); return await fetch(url, request2); }; var getResponseHeader = (response, responseHeader) => { if (responseHeader) { const content = response.headers.get(responseHeader); if (isString(content)) { return content; } } return void 0; }; var getResponseBody = async (response) => { if (response.status !== 204) { try { const contentType = response.headers.get("Content-Type"); if (contentType) { const jsonTypes = ["application/json", "application/problem+json"]; const isJSON = jsonTypes.some((type) => contentType.toLowerCase().startsWith(type)); if (isJSON) { return await response.json(); } else { return await response.text(); } } } catch (error) { console.error(error); } } return void 0; }; var catchErrorCodes = (options, result) => { const errors = { 400: "Bad Request", 401: "Unauthorized", 403: "Forbidden", 404: "Not Found", 500: "Internal Server Error", 502: "Bad Gateway", 503: "Service Unavailable", ...options.errors }; const error = errors[result.status]; if (error) { throw new ApiError(options, result, error); } if (!result.ok) { const errorStatus = result.status ?? "unknown"; const errorStatusText = result.statusText ?? "unknown"; const errorBody = (() => { try { return JSON.stringify(result.body, null, 2); } catch (e) { return void 0; } })(); throw new ApiError( options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}` ); } }; var request = (config, options) => { return new CancelablePromise(async (resolve2, reject, onCancel) => { try { const url = getUrl(config, options); const formData = getFormData(options); const body = getRequestBody(options); const headers = await getHeaders(config, options); if (!onCancel.isCancelled) { const response = await sendRequest(config, options, url, body, formData, headers, onCancel); const responseBody = await getResponseBody(response); const responseHeader = getResponseHeader(response, options.responseHeader); const result = { url, ok: response.ok, status: response.status, statusText: response.statusText, body: responseHeader ?? responseBody }; catchErrorCodes(options, result); resolve2(result.body); } } catch (error) { reject(error); } }); }; // generated/core/FetchHttpRequest.ts var FetchHttpRequest = class extends BaseHttpRequest { constructor(config) { super(config); } /** * Request method * @param options The request options from the service * @returns CancelablePromise<T> * @throws ApiError */ request(options) { return request(this.config, options); } }; // generated/services/ApiKeyService.ts var ApiKeyService = class { constructor(httpRequest) { this.httpRequest = httpRequest; } /** * List API keys * Retrieves the API keys for your Neon account. * The response does not include API key tokens. A token is only provided when creating an API key. * API keys can also be managed in the Neon Console. * For more information, see [Manage API keys](https://neon.tech/docs/manage/api-keys/). * * @returns ApiKeysListResponseItem Returned the API keys for the Neon account * @returns GeneralError General Error * @throws ApiError */ listApiKeys() { return this.httpRequest.request({ method: "GET", url: "/api_keys" }); } /** * Create API key * Creates an API key. * The `key_name` is a user-specified name for the key. * This method returns an `id` and `key`. The `key` is a randomly generated, 64-bit token required to access the Neon API. * API keys can also be managed in the Neon Console. * See [Manage API keys](https://neon.tech/docs/manage/api-keys/). * * @param requestBody * @returns ApiKeyCreateResponse Created an API key * @returns GeneralError General Error * @throws ApiError */ createApiKey(requestBody) { return this.httpRequest.request({ method: "POST", url: "/api_keys", body: requestBody, mediaType: "application/json" }); } /** * Revoke API key * Revokes the specified API key. * An API key that is no longer needed can be revoked. * This action cannot be reversed. * You can obtain `key_id` values by listing the API keys for your Neon account. * API keys can also be managed in the Neon Console. * See [Manage API keys](https://neon.tech/docs/manage/api-keys/). * * @param keyId The API key ID * @returns ApiKeyRevokeResponse Revoked the specified API key * @returns GeneralError General Error * @throws ApiError */ revokeApiKey(keyId) { return this.httpRequest.request({ method: "DELETE", url: "/api_keys/{key_id}", path: { "key_id": keyId } }); } }; // generated/services/AuthService.ts var AuthService = class { constructor(httpRequest) { this.httpRequest = httpRequest; } /** * Create Neon Auth integration * Creates a project on a third-party authentication provider's platform for use with Neon Auth. * Use this endpoint if the frontend integration flow can't be used. * * @param requestBody * @returns GeneralError General Error * @returns IdentityCreateIntegrationResponse Creates Neon Auth integration * @throws ApiError */ createProjectIdentityIntegration(requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/auth/create", body: requestBody, mediaType: "application/json" }); } /** * Create Auth Provider SDK keys * Generates SDK or API Keys for the auth provider. These might be called different things depending * on the auth provider you're using, but are generally used for setting up the frontend and backend SDKs. * * @param requestBody * @returns GeneralError General Error * @returns IdentityCreateIntegrationResponse Creates Auth Provider SDK keys * @throws ApiError */ createProjectIdentityAuthProviderSdkKeys(requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/auth/keys", body: requestBody, mediaType: "application/json" }); } /** * Transfer Neon-managed auth project to your own account * Transfer ownership of your Neon-managed auth project to your own auth provider account. * * @param requestBody * @returns IdentityTransferAuthProviderProjectResponse Transfer initiated. Follow the URL to complete the process in your auth provider's UI. * @returns GeneralError General Error * @throws ApiError */ transferProjectIdentityAuthProviderProject(requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/auth/transfer_ownership", body: requestBody, mediaType: "application/json" }); } /** * Lists active integrations with auth providers * @param projectId The Neon project ID * @returns ListProjectIdentityIntegrationsResponse Return management API keys metadata * @returns GeneralError General Error * @throws ApiError */ listProjectIdentityIntegrations(projectId) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/auth/integrations", path: { "project_id": projectId } }); } /** * Delete integration with auth provider * @param projectId The Neon project ID * @param authProvider The authentication provider name * @returns any Delete the integration with the authentication provider * @returns GeneralError General Error * @throws ApiError */ deleteProjectIdentityIntegration(projectId, authProvider) { return this.httpRequest.request({ method: "DELETE", url: "/projects/{project_id}/auth/integration/{auth_provider}", path: { "project_id": projectId, "auth_provider": authProvider } }); } }; // generated/services/BranchService.ts var BranchService = class { constructor(httpRequest) { this.httpRequest = httpRequest; } /** * Create branch * Creates a branch in the specified project. * You can obtain a `project_id` by listing the projects for your Neon account. * * This method does not require a request body, but you can specify one to create a compute endpoint for the branch or to select a non-default parent branch. * The default behavior is to create a branch from the project's default branch with no compute endpoint, and the branch name is auto-generated. * There is a maximum of one read-write endpoint per branch. * A branch can have multiple read-only endpoints. * For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). * * @param projectId The Neon project ID * @param requestBody * @returns GeneralError General Error * @returns any Created a branch. An endpoint is only created if it was specified in the request. * @throws ApiError */ createProjectBranch(projectId, requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/{project_id}/branches", path: { "project_id": projectId }, body: requestBody, mediaType: "application/json" }); } /** * List branches * Retrieves a list of branches for the specified project. * You can obtain a `project_id` by listing the projects for your Neon account. * * Each Neon project has a root branch named `main`. * A `branch_id` value has a `br-` prefix. * A project may contain child branches that were branched from `main` or from another branch. * A parent branch is identified by the `parent_id` value, which is the `id` of the parent branch. * For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). * * @param projectId The Neon project ID * @param search Search by branch `name` or `id`. You can specify partial `name` or `id` values to filter results. * @param sortBy Sort the branches by sort_field. If not provided, branches will be sorted by updated_at descending order * @param cursor A cursor to use in pagination. A cursor defines your place in the data list. Include `response.pagination.next` in subsequent API calls to fetch next page of the list. * @param sortOrder Defines the sorting order of entities. * @param limit The maximum number of records to be returned in the response * @returns any Returned a list of branches for the specified project * @returns GeneralError General Error * @throws ApiError */ listProjectBranches(projectId, search, sortBy = "updated_at", cursor, sortOrder = "desc", limit) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches", path: { "project_id": projectId }, query: { "search": search, "sort_by": sortBy, "cursor": cursor, "sort_order": sortOrder, "limit": limit } }); } /** * Retrieve number of branches * Retrieves the total number of branches in the specified project. * You can obtain a `project_id` by listing the projects for your Neon account. * * @param projectId The Neon project ID * @param search Count branches matching the `name` in search query * @returns any Returned a count of branches for the specified project * @returns GeneralError General Error * @throws ApiError */ countProjectBranches(projectId, search) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/count", path: { "project_id": projectId }, query: { "search": search } }); } /** * Retrieve branch details * Retrieves information about the specified branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain a `branch_id` by listing the project's branches. * A `branch_id` value has a `br-` prefix. * * Each Neon project is initially created with a root and default branch named `main`. * A project can contain one or more branches. * A parent branch is identified by a `parent_id` value, which is the `id` of the parent branch. * For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). * * @param projectId The Neon project ID * @param branchId The branch ID * @returns any Returned information about the specified branch * @returns GeneralError General Error * @throws ApiError */ getProjectBranch(projectId, branchId) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}", path: { "project_id": projectId, "branch_id": branchId } }); } /** * Delete branch * Deletes the specified branch from a project, and places * all compute endpoints into an idle state, breaking existing client connections. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain a `branch_id` by listing the project's branches. * For related information, see [Manage branches](https://neon.tech/docs/manage/branches/). * * When a successful response status is received, the compute endpoints are still active, * and the branch is not yet deleted from storage. * The deletion occurs after all operations finish. * You cannot delete a project's root or default branch, and you cannot delete a branch that has a child branch. * A project must have at least one branch. * * @param projectId The Neon project ID * @param branchId The branch ID * @returns BranchOperations Deleted the specified branch * @returns GeneralError General Error * @throws ApiError */ deleteProjectBranch(projectId, branchId) { return this.httpRequest.request({ method: "DELETE", url: "/projects/{project_id}/branches/{branch_id}", path: { "project_id": projectId, "branch_id": branchId } }); } /** * Update branch * Updates the specified branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param requestBody * @returns BranchOperations Updated the specified branch * @returns GeneralError General Error * @throws ApiError */ updateProjectBranch(projectId, branchId, requestBody) { return this.httpRequest.request({ method: "PATCH", url: "/projects/{project_id}/branches/{branch_id}", path: { "project_id": projectId, "branch_id": branchId }, body: requestBody, mediaType: "application/json" }); } /** * Restore branch * Restores a branch to an earlier state in its own or another branch's history * @param projectId The Neon project ID * @param branchId The branch ID * @param requestBody * @returns BranchOperations Updated the specified branch * @returns GeneralError General Error * @throws ApiError */ restoreProjectBranch(projectId, branchId, requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/{project_id}/branches/{branch_id}/restore", path: { "project_id": projectId, "branch_id": branchId }, body: requestBody, mediaType: "application/json" }); } /** * Retrieve database schema * Retrieves the schema from the specified database. The `lsn` and `timestamp` values cannot be specified at the same time. If both are omitted, the database schema is retrieved from database's head. * @param projectId The Neon project ID * @param branchId The branch ID * @param dbName Name of the database for which the schema is retrieved * @param lsn The Log Sequence Number (LSN) for which the schema is retrieved * * @param timestamp The point in time for which the schema is retrieved * * @returns BranchSchemaResponse Schema definition * @returns GeneralError General Error * @throws ApiError */ getProjectBranchSchema(projectId, branchId, dbName, lsn, timestamp) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/schema", path: { "project_id": projectId, "branch_id": branchId }, query: { "db_name": dbName, "lsn": lsn, "timestamp": timestamp } }); } /** * Compare database schema * Compares the schema from the specified database with another branch's schema. * @param projectId The Neon project ID * @param branchId The branch ID * @param dbName Name of the database for which the schema is retrieved * @param baseBranchId The branch ID to compare the schema with * @param lsn The Log Sequence Number (LSN) for which the schema is retrieved * * @param timestamp The point in time for which the schema is retrieved * * @param baseLsn The Log Sequence Number (LSN) for the base branch schema * * @param baseTimestamp The point in time for the base branch schema * * @returns BranchSchemaCompareResponse Difference between the schemas * @returns GeneralError General Error * @throws ApiError */ getProjectBranchSchemaComparison(projectId, branchId, dbName, baseBranchId, lsn, timestamp, baseLsn, baseTimestamp) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/compare_schema", path: { "project_id": projectId, "branch_id": branchId }, query: { "base_branch_id": baseBranchId, "db_name": dbName, "lsn": lsn, "timestamp": timestamp, "base_lsn": baseLsn, "base_timestamp": baseTimestamp } }); } /** * Set branch as default * Sets the specified branch as the project's default branch. * The default designation is automatically removed from the previous default branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * For more information, see [Manage branches](https://neon.tech/docs/manage/branches/). * * @param projectId The Neon project ID * @param branchId The branch ID * @returns BranchOperations Updated the specified branch * @returns GeneralError General Error * @throws ApiError */ setDefaultProjectBranch(projectId, branchId) { return this.httpRequest.request({ method: "POST", url: "/projects/{project_id}/branches/{branch_id}/set_as_default", path: { "project_id": projectId, "branch_id": branchId } }); } /** * List branch endpoints * Retrieves a list of compute endpoints for the specified branch. * Neon permits only one read-write compute endpoint per branch. * A branch can have multiple read-only compute endpoints. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * * @param projectId The Neon project ID * @param branchId The branch ID * @returns EndpointsResponse Returned a list of endpoints for the specified branch * @returns GeneralError General Error * @throws ApiError */ listProjectBranchEndpoints(projectId, branchId) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/endpoints", path: { "project_id": projectId, "branch_id": branchId } }); } /** * List databases * Retrieves a list of databases for the specified branch. * A branch can have multiple databases. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). * * @param projectId The Neon project ID * @param branchId The branch ID * @returns DatabasesResponse Returned a list of databases of the specified branch * @returns GeneralError General Error * @throws ApiError */ listProjectBranchDatabases(projectId, branchId) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/databases", path: { "project_id": projectId, "branch_id": branchId } }); } /** * Create database * Creates a database in the specified branch. * A branch can have multiple databases. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param requestBody * @returns GeneralError General Error * @returns DatabaseOperations Created a database in the specified branch * @throws ApiError */ createProjectBranchDatabase(projectId, branchId, requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/{project_id}/branches/{branch_id}/databases", path: { "project_id": projectId, "branch_id": branchId }, body: requestBody, mediaType: "application/json" }); } /** * Retrieve database details * Retrieves information about the specified database. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` and `database_name` by listing the branch's databases. * For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param databaseName The database name * @returns DatabaseResponse Returned the database details * @returns GeneralError General Error * @throws ApiError */ getProjectBranchDatabase(projectId, branchId, databaseName) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/databases/{database_name}", path: { "project_id": projectId, "branch_id": branchId, "database_name": databaseName } }); } /** * Update database * Updates the specified database in the branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` and `database_name` by listing the branch's databases. * For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param databaseName The database name * @param requestBody * @returns DatabaseOperations Updated the database * @returns GeneralError General Error * @throws ApiError */ updateProjectBranchDatabase(projectId, branchId, databaseName, requestBody) { return this.httpRequest.request({ method: "PATCH", url: "/projects/{project_id}/branches/{branch_id}/databases/{database_name}", path: { "project_id": projectId, "branch_id": branchId, "database_name": databaseName }, body: requestBody, mediaType: "application/json" }); } /** * Delete database * Deletes the specified database from the branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` and `database_name` by listing the branch's databases. * For related information, see [Manage databases](https://neon.tech/docs/manage/databases/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param databaseName The database name * @returns DatabaseOperations Deleted the specified database * @returns GeneralError General Error * @throws ApiError */ deleteProjectBranchDatabase(projectId, branchId, databaseName) { return this.httpRequest.request({ method: "DELETE", url: "/projects/{project_id}/branches/{branch_id}/databases/{database_name}", path: { "project_id": projectId, "branch_id": branchId, "database_name": databaseName } }); } /** * List roles * Retrieves a list of Postgres roles from the specified branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). * * @param projectId The Neon project ID * @param branchId The branch ID * @returns RolesResponse Returned a list of roles from the specified branch. * @returns GeneralError General Error * @throws ApiError */ listProjectBranchRoles(projectId, branchId) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/roles", path: { "project_id": projectId, "branch_id": branchId } }); } /** * Create role * Creates a Postgres role in the specified branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). * * Connections established to the active compute endpoint will be dropped. * If the compute endpoint is idle, the endpoint becomes active for a short period of time and is suspended afterward. * * @param projectId The Neon project ID * @param branchId The branch ID * @param requestBody * @returns GeneralError General Error * @returns RoleOperations Created a role in the specified branch * @throws ApiError */ createProjectBranchRole(projectId, branchId, requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/{project_id}/branches/{branch_id}/roles", path: { "project_id": projectId, "branch_id": branchId }, body: requestBody, mediaType: "application/json" }); } /** * Retrieve role details * Retrieves details about the specified role. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * You can obtain the `role_name` by listing the roles for a branch. * In Neon, the terms "role" and "user" are synonymous. * For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param roleName The role name * @returns RoleResponse Returned details for the specified role * @returns GeneralError General Error * @throws ApiError */ getProjectBranchRole(projectId, branchId, roleName) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/roles/{role_name}", path: { "project_id": projectId, "branch_id": branchId, "role_name": roleName } }); } /** * Delete role * Deletes the specified Postgres role from the branch. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * You can obtain the `role_name` by listing the roles for a branch. * For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param roleName The role name * @returns RoleOperations Deleted the specified role from the branch * @returns GeneralError General Error * @throws ApiError */ deleteProjectBranchRole(projectId, branchId, roleName) { return this.httpRequest.request({ method: "DELETE", url: "/projects/{project_id}/branches/{branch_id}/roles/{role_name}", path: { "project_id": projectId, "branch_id": branchId, "role_name": roleName } }); } /** * Retrieve role password * Retrieves the password for the specified Postgres role, if possible. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * You can obtain the `role_name` by listing the roles for a branch. * For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param roleName The role name * @returns RolePasswordResponse Returned password for the specified role * @returns GeneralError General Error * @throws ApiError */ getProjectBranchRolePassword(projectId, branchId, roleName) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reveal_password", path: { "project_id": projectId, "branch_id": branchId, "role_name": roleName }, errors: { 404: `Role not found`, 412: `Storing passwords is disabled` } }); } /** * Reset role password * Resets the password for the specified Postgres role. * Returns a new password and operations. The new password is ready to use when the last operation finishes. * The old password remains valid until last operation finishes. * Connections to the compute endpoint are dropped. If idle, * the compute endpoint becomes active for a short period of time. * * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain the `branch_id` by listing the project's branches. * You can obtain the `role_name` by listing the roles for a branch. * For related information, see [Manage roles](https://neon.tech/docs/manage/roles/). * * @param projectId The Neon project ID * @param branchId The branch ID * @param roleName The role nam * @returns RoleOperations Reset the password for the specified role * @returns GeneralError General Error * @throws ApiError */ resetProjectBranchRolePassword(projectId, branchId, roleName) { return this.httpRequest.request({ method: "POST", url: "/projects/{project_id}/branches/{branch_id}/roles/{role_name}/reset_password", path: { "project_id": projectId, "branch_id": branchId, "role_name": roleName } }); } }; // generated/services/ConsumptionService.ts var ConsumptionService = class { constructor(httpRequest) { this.httpRequest = httpRequest; } /** * Retrieve account consumption metrics * Retrieves consumption metrics for Scale, Business, and Enterprise plan accounts. History begins at the time of upgrade. * * @param from Specify the start `date-time` for the consumption period. * The `date-time` value is rounded according to the specified `granularity`. * For example, `2024-03-15T15:30:00Z` for `daily` granularity will be rounded to `2024-03-15T00:00:00Z`. * The specified `date-time` value must respect the specified granularity: * - For `hourly`, consumption metrics are limited to the last 168 hours. * - For `daily`, consumption metrics are limited to the last 60 days. * - For `monthly`, consumption metrics are limited to the past year. * * The consumption history is available starting from `March 1, 2024, at 00:00:00 UTC`. * * @param to Specify the end `date-time` for the consumption period. * The `date-time` value is rounded according to the specified granularity. * For example, `2024-03-15T15:30:00Z` for `daily` granularity will be rounded to `2024-03-15T00:00:00Z`. * The specified `date-time` value must respect the specified granularity: * - For `hourly`, consumption metrics are limited to the last 168 hours. * - For `daily`, consumption metrics are limited to the last 60 days. * - For `monthly`, consumption metrics are limited to the past year. * * @param granularity Specify the granularity of consumption metrics. * Hourly, daily, and monthly metrics are available for the last 168 hours, 60 days, * and 1 year, respectively. * * @param orgId Specify the organization for which the consumption metrics should be returned. * If this parameter is not provided, the endpoint will return the metrics for the * authenticated user's account. * * @param includeV1Metrics Include metrics utilized in previous pricing models. * - **data_storage_bytes_hour**: The sum of the maximum observed storage values for each hour * for each project, which never decreases. * * @returns ConsumptionHistoryPerAccountResponse Returned consumption metrics for the Neon account * @returns GeneralError General Error * @throws ApiError */ getConsumptionHistoryPerAccount(from, to, granularity, orgId, includeV1Metrics) { return this.httpRequest.request({ method: "GET", url: "/consumption_history/account", query: { "from": from, "to": to, "granularity": granularity, "org_id": orgId, "include_v1_metrics": includeV1Metrics }, errors: { 403: `This endpoint is not available. It is only supported for Scale, Business, and Enterprise plan accounts.`, 404: `Account is not a member of the organization specified by \`org_id\`.`, 406: `The specified \`date-time\` range is outside the boundaries of the specified \`granularity\`. Adjust your \`from\` and \`to\` values or select a different \`granularity\`. `, 429: `Too many requests` } }); } /** * Retrieve project consumption metrics * Retrieves consumption metrics for Scale, Business, and Enterprise plan projects. History begins at the time of upgrade. * Issuing a call to this API does not wake a project's compute endpoint. * * @param from Specify the start `date-time` for the consumption period. * The `date-time` value is rounded according to the specified `granularity`. * For example, `2024-03-15T15:30:00Z` for `daily` granularity will be rounded to `2024-03-15T00:00:00Z`. * The specified `date-time` value must respect the specified `granularity`: * - For `hourly`, consumption metrics are limited to the last 168 hours. * - For `daily`, consumption metrics are limited to the last 60 days. * - For `monthly`, consumption metrics are limited to the last year. * * The consumption history is available starting from `March 1, 2024, at 00:00:00 UTC`. * * @param to Specify the end `date-time` for the consumption period. * The `date-time` value is rounded according to the specified granularity. * For example, `2024-03-15T15:30:00Z` for `daily` granularity will be rounded to `2024-03-15T00:00:00Z`. * The specified `date-time` value must respect the specified `granularity`: * - For `hourly`, consumption metrics are limited to the last 168 hours. * - For `daily`, consumption metrics are limited to the last 60 days. * - For `monthly`, consumption metrics are limited to the last year. * * @param granularity Specify the granularity of consumption metrics. * Hourly, daily, and monthly metrics are available for the last 168 hours, 60 days, * and 1 year, respectively. * * @param cursor Specify the cursor value from the previous response to get the next batch of projects. * @param limit Specify a value from 1 to 100 to limit number of projects in the response. * @param projectIds Specify a list of project IDs to filter the response. * If omitted, the response will contain all projects. * A list of project IDs can be specified as an array of parameter values or as a comma-separated list in a single parameter value. * - As an array of parameter values: `project_ids=cold-poetry-09157238%20&project_ids=quiet-snow-71788278` * - As a comma-separated list in a single parameter value: `project_ids=cold-poetry-09157238,quiet-snow-71788278` * * @param orgId Specify the organization for which the project consumption metrics should be returned. * If this parameter is not provided, the endpoint will return the metrics for the * authenticated user's projects. * * @param includeV1Metrics Include metrics utilized in previous pricing models. * - **data_storage_bytes_hour**: The sum of the maximum observed storage values for each hour, * which never decreases. * * @returns any Returned project consumption metrics for the Neon account * @returns GeneralError General Error * @throws ApiError */ getConsumptionHistoryPerProject(from, to, granularity, cursor, limit = 10, projectIds, orgId, includeV1Metrics) { return this.httpRequest.request({ method: "GET", url: "/consumption_history/projects", query: { "cursor": cursor, "limit": limit, "project_ids": projectIds, "from": from, "to": to, "granularity": granularity, "org_id": orgId, "include_v1_metrics": includeV1Metrics }, errors: { 403: `This endpoint is not available. It is only supported with Scale, Business, and Enterprise plan accounts.`, 404: `Account is not a member of the organization specified by \`org_id\`.`, 406: `The specified \`date-time\` range is outside the boundaries of the specified \`granularity\`. Adjust your \`from\` and \`to\` values or select a different \`granularity\`. `, 429: `Too many requests` } }); } }; // generated/services/EndpointService.ts var EndpointService = class { constructor(httpRequest) { this.httpRequest = httpRequest; } /** * Create compute endpoint * Creates a compute endpoint for the specified branch. * An endpoint is a Neon compute instance. * There is a maximum of one read-write compute endpoint per branch. * If the specified branch already has a read-write compute endpoint, the operation fails. * A branch can have multiple read-only compute endpoints. * * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain `branch_id` by listing the project's branches. * A `branch_id` has a `br-` prefix. * For supported regions and `region_id` values, see [Regions](https://neon.tech/docs/introduction/regions/). * For more information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). * * @param projectId The Neon project ID * @param requestBody * @returns GeneralError General Error * @returns EndpointOperations Created a compute endpoint * @throws ApiError */ createProjectEndpoint(projectId, requestBody) { return this.httpRequest.request({ method: "POST", url: "/projects/{project_id}/endpoints", path: { "project_id": projectId }, body: requestBody, mediaType: "application/json" }); } /** * List compute endpoints * Retrieves a list of compute endpoints for the specified project. * A compute endpoint is a Neon compute instance. * You can obtain a `project_id` by listing the projects for your Neon account. * For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). * * @param projectId The Neon project ID * @returns EndpointsResponse Returned a list of endpoints for the specified project * @returns GeneralError General Error * @throws ApiError */ listProjectEndpoints(projectId) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/endpoints", path: { "project_id": projectId } }); } /** * Retrieve compute endpoint details * Retrieves information about the specified compute endpoint. * A compute endpoint is a Neon compute instance. * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain an `endpoint_id` by listing your project's compute endpoints. * An `endpoint_id` has an `ep-` prefix. * For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/). * * @param projectId The Neon project ID * @param endpointId The endpoint ID * @returns EndpointResponse Returned information about the specified endpoint * @returns GeneralError General Error * @throws ApiError */ getProjectEndpoint(projectId, endpointId) { return this.httpRequest.request({ method: "GET", url: "/projects/{project_id}/endpoints/{endpoint_id}", path: { "project_id": projectId, "endpoint_id": endpointId } }); } /** * Delete compute endpoint * Delete the specified compute endpoint. * A compute endpoint is a Neon compute instance. * Deleting a compute endpoint drops existing network connections to the compute endpoint. * The deletion is completed when last operation in the chain finishes successfully. * * You can obtain a `project_id` by listing the projects for your Neon account. * You can obtain an `endpoint_id` by listing your project's compute endpoints. * An `endpoint_id` has an `ep-` prefix. * For information about compute endpoints, see [Manag