[PR #674] [MERGED] feat: public api start #1115

Closed
opened 2026-02-26 19:31:54 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/documenso/documenso/pull/674
Author: @catalinpit
Created: 11/22/2023
Status: Merged
Merged: 2/26/2024
Merged by: @Mythie

Base: mainHead: feat/public-api


📝 Commits (10+)

  • 24d9906 feat: public api start
  • 4a6b3ed feat: get documents api route with pagination
  • 6d6c935 feat: update contract
  • b3008fb feat: add route for retrieving a single document by id
  • 5c8a77e chore: merged main
  • 309b561 feat: create the model for the api token
  • 2ccede7 chore: update the contract to add deleteDocument route
  • 80fe7cc feat: api token page in the settings
  • fbee6ee feat: api token functions
  • 2deaad5 feat: token page

📊 Changes

83 files changed (+5645 additions, -269 deletions)

View changed files

📝 apps/web/package.json (+1 -0)
📝 apps/web/src/app/(dashboard)/documents/[id]/document-page-view.tsx (+1 -0)
📝 apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx (+6 -0)
📝 apps/web/src/app/(dashboard)/documents/[id]/edit/document-edit-page-view.tsx (+1 -0)
📝 apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-page-view.tsx (+1 -0)
📝 apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx (+1 -0)
📝 apps/web/src/app/(dashboard)/documents/delete-document-dialog.tsx (+5 -3)
apps/web/src/app/(dashboard)/settings/tokens/page.tsx (+74 -0)
📝 apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx (+5 -0)
📝 apps/web/src/app/(teams)/t/[teamUrl]/layout.tsx (+4 -1)
apps/web/src/app/(teams)/t/[teamUrl]/settings/tokens/page.tsx (+85 -0)
apps/web/src/app/api/v1/openapi/page.tsx (+3 -0)
📝 apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx (+8 -0)
📝 apps/web/src/components/(dashboard)/settings/layout/desktop-nav.tsx (+14 -1)
📝 apps/web/src/components/(dashboard)/settings/layout/mobile-nav.tsx (+14 -1)
apps/web/src/components/(dashboard)/settings/token/contants.ts (+7 -0)
apps/web/src/components/(dashboard)/settings/token/delete-token-dialog.tsx (+185 -0)
📝 apps/web/src/components/(teams)/settings/layout/desktop-nav.tsx (+12 -1)
📝 apps/web/src/components/(teams)/settings/layout/mobile-nav.tsx (+12 -1)
apps/web/src/components/forms/token.tsx (+257 -0)

...and 63 more files

📄 Description

This PR adds the public-facing API.

API high-level workings

The public API will allow users to interact with Documenso programmatically. At the moment, there are 5 available endpoints:

  1. GET /documents
    • get all documents of the user making the API call
    • it accepts 2 URL query parameters - page and perPage, but they are not mandatory
  2. GET /documents/:id
    • get a specific document of the user making the API call
    • it requires 1 URL parameter, which represents the ID of the document that needs to be retrieved
  3. DELETE /documents/:id
    • delete a specific document of the user making the API call
    • it requires 1 URL parameter, which represents the ID of the document that needs to be deleted
  4. POST /documents
    • making a POST request to this endpoint will return an S3 pre-signed URL where you can upload the document
    • it requires you to pass the file name and the file content type
  5. PATCH /documents/:id/send-for-signing
    • send a document for signing
    • it allows you to pass the following:
      • signer email (required)
      • signer name (optional)
      • field type (signature, email, name, etc.) (required)
      • page number where to insert the field (required)
      • page X (required)
      • page Y (required)
      • page width (required)
      • page height (required)
      • email subject (optional)
      • email body (optional)

The users are authenticated through API tokens. The users can create one or more tokens in their account settings, and each token will be available for 1 year (duration open to suggestions/changes).

Each time the user makes a request, the app checks if the token exists and if it's valid. The app will return 401 (unauthorized) and the appropriate error message if either is false. If both are true AND the user uses the correct HTTP verb and passes the required URL parameters and body, the API call will be successful.

Code overview:

  • @documenso/packages/lib/trpc/api-contract - this folder contains the contract and schema files. The contract.ts file describes the structure of the API, the format of the requests and responses, and how to authenticate your API calls, among others. The schema.ts file contains the Zod schemas used in the API contract.
  • @documenso/packages/trpc/server/api-token-router - this folder contains the router.rs and schema.ts files. Here are the tRPC procedures used on the frontend. That is, the user's settings page, where the user can list/create/delete API tokens.
  • @documenso/packages/trpc/tsconfig.json - I added "strict": true because that's what's suggested in the ts-rest documentation. (source)
  • [...ts-rest].tsx - This file contains the implementation of the API. You can see the logic behind each route.
  • the rest of the code represents the code for the API tokens page in the user's settings.

Summary by CodeRabbit

  • New Features
    • Introduced document management API with functionalities for managing documents, recipients, and fields including creation, updating, deletion, and retrieval.
    • Added API endpoints for managing API tokens, allowing users to create, view, and delete API tokens with optional expiration dates.
    • Implemented user interface enhancements for API token management in the dashboard, including forms for token creation and settings for managing tokens.
  • Documentation
    • Added example files demonstrating the usage of document and field management functionalities through the API.
  • Refactor
    • Integrated authentication middleware for secure access to document management functionalities.
  • Chore
    • Updated database schema to make the expiration date optional for API tokens.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/documenso/documenso/pull/674 **Author:** [@catalinpit](https://github.com/catalinpit) **Created:** 11/22/2023 **Status:** ✅ Merged **Merged:** 2/26/2024 **Merged by:** [@Mythie](https://github.com/Mythie) **Base:** `main` ← **Head:** `feat/public-api` --- ### 📝 Commits (10+) - [`24d9906`](https://github.com/documenso/documenso/commit/24d9906557ed7ed5644f4069da591c1b143a24a7) feat: public api start - [`4a6b3ed`](https://github.com/documenso/documenso/commit/4a6b3edc05bf66b809395fc085de215c0364eefc) feat: get documents api route with pagination - [`6d6c935`](https://github.com/documenso/documenso/commit/6d6c93539f05f05d463f5ced57e7b234b78822d5) feat: update contract - [`b3008fb`](https://github.com/documenso/documenso/commit/b3008fb272349a4a40ccd56427d69f315c3dd9df) feat: add route for retrieving a single document by id - [`5c8a77e`](https://github.com/documenso/documenso/commit/5c8a77ee8fa52aba552e271d98d0e91e5897298c) chore: merged main - [`309b561`](https://github.com/documenso/documenso/commit/309b56168a2da1f8c4304c7b4de7345257a04c20) feat: create the model for the api token - [`2ccede7`](https://github.com/documenso/documenso/commit/2ccede72eaea0f70caa998404bffe36683e5fdc9) chore: update the contract to add deleteDocument route - [`80fe7cc`](https://github.com/documenso/documenso/commit/80fe7ccdf5f0e66764671ec7f2d3bb22e10f506d) feat: api token page in the settings - [`fbee6ee`](https://github.com/documenso/documenso/commit/fbee6eedc10a4d7cc53a8afb323443198d022319) feat: api token functions - [`2deaad5`](https://github.com/documenso/documenso/commit/2deaad5c345265494b0dbfbc2d8c8d6277a6bcc8) feat: token page ### 📊 Changes **83 files changed** (+5645 additions, -269 deletions) <details> <summary>View changed files</summary> 📝 `apps/web/package.json` (+1 -0) 📝 `apps/web/src/app/(dashboard)/documents/[id]/document-page-view.tsx` (+1 -0) 📝 `apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx` (+6 -0) 📝 `apps/web/src/app/(dashboard)/documents/[id]/edit/document-edit-page-view.tsx` (+1 -0) 📝 `apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-page-view.tsx` (+1 -0) 📝 `apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx` (+1 -0) 📝 `apps/web/src/app/(dashboard)/documents/delete-document-dialog.tsx` (+5 -3) ➕ `apps/web/src/app/(dashboard)/settings/tokens/page.tsx` (+74 -0) 📝 `apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx` (+5 -0) 📝 `apps/web/src/app/(teams)/t/[teamUrl]/layout.tsx` (+4 -1) ➕ `apps/web/src/app/(teams)/t/[teamUrl]/settings/tokens/page.tsx` (+85 -0) ➕ `apps/web/src/app/api/v1/openapi/page.tsx` (+3 -0) 📝 `apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx` (+8 -0) 📝 `apps/web/src/components/(dashboard)/settings/layout/desktop-nav.tsx` (+14 -1) 📝 `apps/web/src/components/(dashboard)/settings/layout/mobile-nav.tsx` (+14 -1) ➕ `apps/web/src/components/(dashboard)/settings/token/contants.ts` (+7 -0) ➕ `apps/web/src/components/(dashboard)/settings/token/delete-token-dialog.tsx` (+185 -0) 📝 `apps/web/src/components/(teams)/settings/layout/desktop-nav.tsx` (+12 -1) 📝 `apps/web/src/components/(teams)/settings/layout/mobile-nav.tsx` (+12 -1) ➕ `apps/web/src/components/forms/token.tsx` (+257 -0) _...and 63 more files_ </details> ### 📄 Description This PR adds the public-facing API. ![API high-level workings](https://github.com/documenso/documenso/assets/25515812/9f866889-164f-401f-bf4e-d3e69b6382f1) The public API will allow users to interact with Documenso programmatically. At the moment, there are 5 available endpoints: 1. `GET /documents` - get all documents of the user making the API call - it accepts 2 URL query parameters - `page` and `perPage`, but they are not mandatory 2. `GET /documents/:id` - get a specific document of the user making the API call - it requires 1 URL parameter, which represents the ID of the document that needs to be retrieved 3. `DELETE /documents/:id` - delete a specific document of the user making the API call - it requires 1 URL parameter, which represents the ID of the document that needs to be deleted 4. `POST /documents` - making a POST request to this endpoint will return an S3 pre-signed URL where you can upload the document - it requires you to pass the file name and the file content type 5. `PATCH /documents/:id/send-for-signing` - send a document for signing - it allows you to pass the following: - signer email *(required)* - signer name *(optional)* - field type (signature, email, name, etc.) *(required)* - page number where to insert the field *(required)* - page X *(required)* - page Y *(required)* - page width *(required)* - page height *(required)* - email subject *(optional)* - email body *(optional)* The users are authenticated through API tokens. The users can create one or more tokens in their account settings, and each token will be available for 1 year _(duration open to suggestions/changes)_. Each time the user makes a request, the app checks if the token exists and if it's valid. The app will return `401` *(unauthorized)* and the appropriate error message if either is false. If both are true AND the user uses the correct HTTP verb and passes the required URL parameters and body, the API call will be successful. Code overview: - `@documenso/packages/lib/trpc/api-contract` - this folder contains the `contract` and `schema` files. The `contract.ts` file describes the structure of the API, the format of the requests and responses, and how to authenticate your API calls, among others. The `schema.ts` file contains the Zod schemas used in the API contract. - `@documenso/packages/trpc/server/api-token-router` - this folder contains the `router.rs` and `schema.ts` files. Here are the tRPC procedures used on the frontend. That is, the user's settings page, where the user can list/create/delete API tokens. - `@documenso/packages/trpc/tsconfig.json` - I added `"strict": true` because that's what's suggested in the `ts-rest` documentation. *([source](https://ts-rest.com/docs/quickstart#create-a-contract))* - `[...ts-rest].tsx` - This file contains the implementation of the API. You can see the logic behind each route. - the rest of the code represents the code for the API tokens page in the user's settings. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced document management API with functionalities for managing documents, recipients, and fields including creation, updating, deletion, and retrieval. - Added API endpoints for managing API tokens, allowing users to create, view, and delete API tokens with optional expiration dates. - Implemented user interface enhancements for API token management in the dashboard, including forms for token creation and settings for managing tokens. - **Documentation** - Added example files demonstrating the usage of document and field management functionalities through the API. - **Refactor** - Integrated authentication middleware for secure access to document management functionalities. - **Chore** - Updated database schema to make the expiration date optional for API tokens. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 19:31:54 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/documenso#1115
No description provided.