diff --git a/components/prisma_management_api/README.md b/components/prisma_management_api/README.md new file mode 100644 index 0000000000000..b6d9a3740daea --- /dev/null +++ b/components/prisma_management_api/README.md @@ -0,0 +1,131 @@ +# Prisma Management API + +The Prisma Management API interacts seamlessly with Pipedream, empowering you to craft customized automations and workflows for your Prisma Postgres databases. Create projects, manage databases, and handle connection strings with ease. + +## Overview + +The Prisma Management API provides programmatic access to manage Prisma Postgres database projects. This integration allows you to automate database lifecycle management, connection string generation, and resource provisioning within your Pipedream workflows. + +With this integration, you can: + +- **Automate Database Provisioning**: Automatically create new Postgres database projects with proper regional distribution +- **Manage Connection Strings**: Generate and manage secure connection strings for your applications +- **Monitor Resources**: List and inspect databases, projects, and connection details across your workspace +- **Streamline Cleanup**: Systematically remove databases and connection strings when no longer needed + +## Getting Started + +To use the Prisma Management API with Pipedream, you'll need to connect your Prisma account and obtain an API integration token. + +## Actions + +### Project Management + +#### Create Database +Creates a new Postgres database project via Prisma Management API. This action creates a complete project with database and provides connection string details in the response for immediate use. + +**Parameters:** +- `name` (string, required): The name of the Postgres database project to create +- `region` (string, optional): The region where the database should be created (default: us-east-1) + +**Available regions:** us-east-1, us-west-1, eu-west-3, eu-central-1, ap-northeast-1, ap-southeast-1 + +#### List Projects in Prisma Workspace +Retrieves all projects within your Prisma workspace. + +#### Get Project Details +Retrieves detailed information about a specific project including associated databases and configuration. + +**Parameters:** +- `projectId` (string, required): The ID of the project to retrieve + +#### Delete Database +Removes an entire Postgres database project and all associated resources. + +**Parameters:** +- `projectId` (string, required): The ID of the project to delete + +### Database Management + +#### Create New Database in Existing Project +Adds a new database to an existing Prisma project. + +**Parameters:** +- `projectId` (string, required): The ID of the project where the database should be created +- `region` (string, optional): The region for the database +- `isDefault` (boolean, optional): Whether to set this as the default database for the project + +#### List Databases from Project +Retrieves all databases within a specific project. + +**Parameters:** +- `projectId` (string, required): The ID of the project + +#### Get Database Details +Retrieves detailed information about a specific Prisma Postgres database. + +**Parameters:** +- `databaseId` (string, required): The ID of the database + +#### Delete Database by Database ID +Removes a specific database by its ID. + +**Parameters:** +- `databaseId` (string, required): The ID of the database to delete + +### Connection String Management + +#### Create Database Connection String +Generates a new connection string for database access. + +**Parameters:** +- `databaseId` (string, required): The ID of the database +- `name` (string, required): A descriptive name for the connection + +#### List Database Connection Strings +Retrieves all connection strings for a specific database. + +**Parameters:** +- `databaseId` (string, required): The ID of the database + +#### Delete Database Connection String +Removes a specific connection string. + +**Parameters:** +- `connectionId` (string, required): The ID of the connection to delete + +### Utilities + +#### Get Prisma Postgres Regions +Retrieves the list of available regions for Prisma Postgres deployment. + +## Authentication + +This integration uses API Token authentication. You'll need to provide your Prisma Management API Service token when configuring the connection in Pipedream. + +To obtain your API token: +1. Log in to your Prisma account +2. Navigate to your workspace settings +3. Generate a new Service Token +4. Copy the token for use in Pipedream + +## API Documentation + +For complete API documentation and additional details, visit the [Prisma Management API Documentation](https://www.prisma.io/docs/postgres/introduction/management-api). + +## Example Workflows + +### Automated Database Setup for New Projects +Trigger a workflow when a new project is created in your system, automatically provision a Prisma Postgres database, and store the connection details in your configuration management system. + +### Database Cleanup Automation +Schedule periodic cleanup of unused databases and connection strings to maintain security and reduce costs. + +### Multi-Region Database Deployment +Create databases across multiple regions for improved performance and redundancy based on your application's geographic distribution. + +## Support + +For issues specific to the Prisma Management API, refer to the [official documentation](https://www.prisma.io/docs/postgres/introduction/management-api). + +For Pipedream-related questions, visit the [Pipedream documentation](https://pipedream.com/docs) or community forums. \ No newline at end of file diff --git a/components/prisma_management_api/actions/create-database-connection-string/create-database-connection-string.mjs b/components/prisma_management_api/actions/create-database-connection-string/create-database-connection-string.mjs new file mode 100644 index 0000000000000..b3a01073e0f48 --- /dev/null +++ b/components/prisma_management_api/actions/create-database-connection-string/create-database-connection-string.mjs @@ -0,0 +1,37 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Create Database Connection String", + version: "1.0.0", + key: "prisma_management_api-create-database-connection-string", + description: "Creates a new connection string for an existing database via Prisma Management API. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + databaseId: { + type: "string", + label: "Database ID", + description: "The ID of the database to create a connection string for", + }, + name: { + type: "string", + label: "Connection Name", + description: "A descriptive name for the connection string", + }, + }, + async run({ $ }) { + const response = await this.app.createConnectionString({ + $, + databaseId: this.databaseId, + data: { + name: this.name, + }, + }); + + if (response) { + $.export("$summary", `Successfully created connection string for database ${this.databaseId}${response.id ? ` with connection ID ${response.id}` : ""}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/create-database/create-database.mjs b/components/prisma_management_api/actions/create-database/create-database.mjs new file mode 100644 index 0000000000000..ba861e95e8d0e --- /dev/null +++ b/components/prisma_management_api/actions/create-database/create-database.mjs @@ -0,0 +1,50 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Create Database", + version: "1.0.0", + key: "prisma_management_api-create-database", + description: "Creates a new Postgres database project via Prisma Management API. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + name: { + type: "string", + label: "Project Name", + description: "The name of the Postgres database project to create", + }, + region: { + propDefinition: [ + app, + "region", + ], + default: "us-east-1", + }, + }, + async run({ $ }) { + const response = await this.app.createProject({ + $, + data: { + name: this.name, + region: this.region, + }, + }); + + if (response) { + const projectId = response.data?.id; + const databaseId = response.data?.database?.id; + + let summary = `Successfully created Postgres database project "${this.name}"`; + if (projectId) { + summary += ` with Project ID ${projectId}`; + } + if (databaseId) { + summary += ` and Database ID ${databaseId}`; + } + + $.export("$summary", summary); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/create-new-database-in-existing-project/create-new-database-in-existing-project.mjs b/components/prisma_management_api/actions/create-new-database-in-existing-project/create-new-database-in-existing-project.mjs new file mode 100644 index 0000000000000..73b9e19530654 --- /dev/null +++ b/components/prisma_management_api/actions/create-new-database-in-existing-project/create-new-database-in-existing-project.mjs @@ -0,0 +1,52 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Create New Database in Existing Project", + version: "1.0.0", + key: "prisma_management_api-create-new-database-in-existing-project", + description: "Create a new database in an existing Prisma project. Requires Project ID. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + projectId: { + type: "string", + label: "Project ID", + description: "The ID of the project where the database should be created", + }, + region: { + propDefinition: [ + app, + "region", + ], + }, + isDefault: { + type: "boolean", + label: "Set as Default Database", + description: "Whether to set this database as the default for the project", + optional: true, + default: false, + }, + }, + async run({ $ }) { + if (!this.region) { + throw new Error("Region is required for creating a database"); + } + + const data = { + region: this.region, + }; + if (this.isDefault !== undefined) data.default = this.isDefault; + + const response = await this.app.createDatabase({ + $, + projectId: this.projectId, + data, + }); + + if (response) { + $.export("$summary", `Successfully created database in project ${this.projectId}${response.id ? ` with ID ${response.id}` : ""}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/delete-database-by-database-id/delete-database-by-database-id.mjs b/components/prisma_management_api/actions/delete-database-by-database-id/delete-database-by-database-id.mjs new file mode 100644 index 0000000000000..6abf13e5d175d --- /dev/null +++ b/components/prisma_management_api/actions/delete-database-by-database-id/delete-database-by-database-id.mjs @@ -0,0 +1,33 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Delete Database by Database ID", + version: "1.0.0", + key: "prisma_management_api-delete-database-by-database-id", + description: "Delete a specific database by Database ID via Prisma Management API. This action is irreversible. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + databaseId: { + type: "string", + label: "Database ID", + description: "The ID of the database to delete", + }, + }, + async run({ $ }) { + const response = await this.app.deleteDatabase({ + $, + databaseId: this.databaseId, + }); + + if (response || response === null) { + $.export("$summary", `Successfully deleted database with ID ${this.databaseId}`); + } + + return { + success: true, + databaseId: this.databaseId, + message: "Database deleted successfully", + }; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/delete-database-connection-string/delete-database-connection-string.mjs b/components/prisma_management_api/actions/delete-database-connection-string/delete-database-connection-string.mjs new file mode 100644 index 0000000000000..eed0b5a4417a7 --- /dev/null +++ b/components/prisma_management_api/actions/delete-database-connection-string/delete-database-connection-string.mjs @@ -0,0 +1,33 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Delete Database Connection String", + version: "1.0.0", + key: "prisma_management_api-delete-database-connection-string", + description: "Deletes a specific database connection string via Prisma Management API. This action is irreversible. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + connectionId: { + type: "string", + label: "Connection ID", + description: "The ID of the database connection to delete", + }, + }, + async run({ $ }) { + const response = await this.app.deleteConnectionString({ + $, + connectionId: this.connectionId, + }); + + if (response || response === null) { + $.export("$summary", `Successfully deleted database connection with ID ${this.connectionId}`); + } + + return { + success: true, + connectionId: this.connectionId, + message: "Database connection deleted successfully", + }; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/delete-database/delete-database.mjs b/components/prisma_management_api/actions/delete-database/delete-database.mjs new file mode 100644 index 0000000000000..8391c34143907 --- /dev/null +++ b/components/prisma_management_api/actions/delete-database/delete-database.mjs @@ -0,0 +1,33 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Delete Database", + version: "1.0.0", + key: "prisma_management_api-delete-database", + description: "Deletes a Postgres database project via Prisma Management API. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + projectId: { + type: "string", + label: "Project ID", + description: "The ID of the Postgres database project to delete", + }, + }, + async run({ $ }) { + const response = await this.app.deleteProject({ + $, + projectId: this.projectId, + }); + + if (response || response === null) { + $.export("$summary", `Successfully deleted Postgres database project with ID ${this.projectId}`); + } + + return { + success: true, + projectId: this.projectId, + message: "Database project deleted successfully", + }; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/get-database-details/get-database-details.mjs b/components/prisma_management_api/actions/get-database-details/get-database-details.mjs new file mode 100644 index 0000000000000..996383f339c1e --- /dev/null +++ b/components/prisma_management_api/actions/get-database-details/get-database-details.mjs @@ -0,0 +1,29 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Get Database details", + version: "1.0.0", + key: "prisma_management_api-get-database-details", + description: "Get database details of a particular Prisma Postgres database via Prisma Management API. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + databaseId: { + type: "string", + label: "Database ID", + description: "The ID of the database to retrieve information for", + }, + }, + async run({ $ }) { + const response = await this.app.getDatabase({ + $, + databaseId: this.databaseId, + }); + + if (response) { + $.export("$summary", `Successfully retrieved database information for ID ${this.databaseId}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/get-postgres-regions/get-postgres-regions.mjs b/components/prisma_management_api/actions/get-postgres-regions/get-postgres-regions.mjs new file mode 100644 index 0000000000000..1ac6db5c5bf27 --- /dev/null +++ b/components/prisma_management_api/actions/get-postgres-regions/get-postgres-regions.mjs @@ -0,0 +1,24 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Get Prisma Postgres Regions", + version: "1.0.0", + key: "prisma_management_api-get-postgres-regions", + description: "Retrieves a list of all available regions where Prisma Postgres databases can be deployed. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.listRegions({ + $, + }); + + if (response) { + const count = response.data?.length || 0; + $.export("$summary", `Successfully retrieved ${count} available Postgres region${count !== 1 ? "s" : ""}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/get-project-details/get-project-details.mjs b/components/prisma_management_api/actions/get-project-details/get-project-details.mjs new file mode 100644 index 0000000000000..2b760b9fd3380 --- /dev/null +++ b/components/prisma_management_api/actions/get-project-details/get-project-details.mjs @@ -0,0 +1,29 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "Get Project details", + version: "1.0.0", + key: "prisma_management_api-get-project-details", + description: "Get project details of a particular project in Prisma Workspace via Prisma Management API. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + projectId: { + type: "string", + label: "Project ID", + description: "The ID of the project to retrieve information for", + }, + }, + async run({ $ }) { + const response = await this.app.getProject({ + $, + projectId: this.projectId, + }); + + if (response) { + $.export("$summary", `Successfully retrieved project information for ID ${this.projectId}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/list-database-connection-strings/list-database-connection-strings.mjs b/components/prisma_management_api/actions/list-database-connection-strings/list-database-connection-strings.mjs new file mode 100644 index 0000000000000..3b64745a1fc91 --- /dev/null +++ b/components/prisma_management_api/actions/list-database-connection-strings/list-database-connection-strings.mjs @@ -0,0 +1,30 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "List Database Connection Strings", + version: "1.0.0", + key: "prisma_management_api-list-database-connection-strings", + description: "Retrieves a list of all connection strings for a specific database via Prisma Management API. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + databaseId: { + type: "string", + label: "Database ID", + description: "The ID of the database to list connections for", + }, + }, + async run({ $ }) { + const response = await this.app.listConnectionStrings({ + $, + databaseId: this.databaseId, + }); + + if (response) { + const count = response.data?.length || 0; + $.export("$summary", `Successfully retrieved ${count} connection${count !== 1 ? "s" : ""} for database ${this.databaseId}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/list-databases-from-project/list-databases-from-project.mjs b/components/prisma_management_api/actions/list-databases-from-project/list-databases-from-project.mjs new file mode 100644 index 0000000000000..55b65cfa68cbc --- /dev/null +++ b/components/prisma_management_api/actions/list-databases-from-project/list-databases-from-project.mjs @@ -0,0 +1,30 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "List Databases from Project", + version: "1.0.0", + key: "prisma_management_api-list-databases-from-project", + description: "Retrieves a list of all databases within a specific Prisma project. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + projectId: { + type: "string", + label: "Project ID", + description: "The ID of the project to list databases from", + }, + }, + async run({ $ }) { + const response = await this.app.listDatabases({ + $, + projectId: this.projectId, + }); + + if (response) { + const count = response.data?.length || 0; + $.export("$summary", `Successfully retrieved ${count} database${count !== 1 ? "s" : ""} from project ${this.projectId}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/actions/list-projects-in-prisma-workspace/list-projects-in-prisma-workspace.mjs b/components/prisma_management_api/actions/list-projects-in-prisma-workspace/list-projects-in-prisma-workspace.mjs new file mode 100644 index 0000000000000..0e0da4dc52d6a --- /dev/null +++ b/components/prisma_management_api/actions/list-projects-in-prisma-workspace/list-projects-in-prisma-workspace.mjs @@ -0,0 +1,29 @@ +import app from "../../prisma_management_api.app.mjs"; + +export default { + name: "List Projects in Prisma Workspace", + version: "1.0.0", + key: "prisma_management_api-list-projects-in-prisma-workspace", + description: "List Projects in a Prisma Workspace via Prisma Management API. [See docs here](https://www.prisma.io/docs/postgres/introduction/management-api)", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.listProjects({ + $, + }); + + if (response) { + const items = Array.isArray(response) + ? response + : Array.isArray(response?.data) + ? response.data + : []; + const count = items.length; + $.export("$summary", `Successfully retrieved ${count} project${count !== 1 ? "s" : ""}`); + } + + return response; + }, +}; \ No newline at end of file diff --git a/components/prisma_management_api/package.json b/components/prisma_management_api/package.json index 3b543d7c7a9e1..fe03d28844e80 100644 --- a/components/prisma_management_api/package.json +++ b/components/prisma_management_api/package.json @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^1.5.1" } } \ No newline at end of file diff --git a/components/prisma_management_api/prisma_management_api.app.mjs b/components/prisma_management_api/prisma_management_api.app.mjs index 39fcb4d5527d5..28dd9a2a71887 100644 --- a/components/prisma_management_api/prisma_management_api.app.mjs +++ b/components/prisma_management_api/prisma_management_api.app.mjs @@ -1,11 +1,143 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "prisma_management_api", - propDefinitions: {}, + propDefinitions: { + region: { + type: "string", + label: "Region", + description: "The region where the database should be created", + async options() { + const response = await this.listRegions(); + const regions = response?.data || []; + return regions + .filter((region) => !region.status || region.status === "available") + .map((region) => ({ + label: region.name || region.id, + value: region.id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.prisma.io/v1"; + }, + _makeRequest({ + $ = this, path, ...args + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.api_token}`, + "Content-Type": "application/json", + }, + ...args, + }); + }, + async createProject(args = {}) { + return this._makeRequest({ + path: "/projects", + method: "post", + ...args, + }); + }, + async deleteProject({ + projectId, ...args + }) { + return this._makeRequest({ + path: `/projects/${projectId}`, + method: "delete", + ...args, + }); + }, + async listProjects(args = {}) { + return this._makeRequest({ + path: "/projects", + method: "get", + ...args, + }); + }, + async getProject({ + projectId, ...args + }) { + return this._makeRequest({ + path: `/projects/${projectId}`, + method: "get", + ...args, + }); + }, + async createDatabase({ + projectId, ...args + }) { + return this._makeRequest({ + path: `/projects/${projectId}/databases`, + method: "post", + ...args, + }); + }, + async listDatabases({ + projectId, ...args + }) { + return this._makeRequest({ + path: `/projects/${projectId}/databases`, + method: "get", + ...args, + }); + }, + async getDatabase({ + databaseId, ...args + }) { + return this._makeRequest({ + path: `/databases/${databaseId}`, + method: "get", + ...args, + }); + }, + async deleteDatabase({ + databaseId, ...args + }) { + return this._makeRequest({ + path: `/databases/${databaseId}`, + method: "delete", + ...args, + }); + }, + async listConnectionStrings({ + databaseId, ...args + }) { + return this._makeRequest({ + path: `/databases/${databaseId}/connections`, + method: "get", + ...args, + }); + }, + async createConnectionString({ + databaseId, data, ...args + }) { + return this._makeRequest({ + path: `/databases/${databaseId}/connections`, + method: "post", + data: data || {}, + ...args, + }); + }, + async deleteConnectionString({ + connectionId, ...args + }) { + return this._makeRequest({ + path: `/connections/${connectionId}`, + method: "delete", + ...args, + }); + }, + async listRegions(args = {}) { + return this._makeRequest({ + path: "/regions/postgres", + method: "get", + ...args, + }); }, }, }; \ No newline at end of file