Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: public api start #674

Merged
merged 50 commits into from Feb 26, 2024
Merged

feat: public api start #674

merged 50 commits into from Feb 26, 2024

Conversation

catalinpit
Copy link
Contributor

@catalinpit catalinpit commented Nov 22, 2023

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.

Copy link
Contributor

coderabbitai bot commented Nov 22, 2023

Important

Auto Review Skipped

Auto reviews are limited to the following labels: coderabbit. Please add one of these labels to enable auto reviews.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

This update introduces a comprehensive suite for document management through an API, including functionalities for managing documents, recipients, fields, and API tokens. It encompasses creating, updating, deleting, and retrieving documents, along with recipient and field management. Additionally, it enhances user experience by providing a dashboard for API token management, enabling users to generate, view, and delete tokens with ease. The implementation is supported by schema validations, server-side logic, and user interface components, ensuring a seamless integration into the existing system.

Changes

File Path Change Summary
packages/api/v1/contract.ts, implementation.ts, schema.ts Introduced API contracts, implementations, and TypeScript schemas for document, recipient, and field management.
packages/api/v1/examples/... (01 to 09) Added examples demonstrating API usage for document, field, and recipient operations.
packages/lib/server-only/field/... (create-field.ts, delete-field.ts, get-field-by-id.ts, update-field.ts) Functions for creating, deleting, fetching, and updating fields in documents.
packages/lib/server-only/recipient/... (delete-recipient.ts, get-recipient-by-email.ts, get-recipient-by-id.ts, update-recipient.ts) Functions for managing recipients, including deletion, fetching by email or ID, and updates.
apps/web/src/components/(dashboard)/... (profile-dropdown.tsx, settings/layout/desktop-nav.tsx, settings/layout/mobile-nav.tsx) UI updates for the dashboard, including a new API Tokens menu item and navigation buttons.
apps/web/src/app/(dashboard)/settings/tokens/page.tsx, apps/web/src/components/forms/token.tsx Introduced functionality and forms for managing API tokens in the dashboard.
packages/lib/constants/time.ts, server-only/public-api/create-api-token.ts Added time constants and a function for creating API tokens.
packages/prisma/migrations/.../migration.sql, schema.prisma Database schema updates for optional expiry dates in API tokens and added ApiToken model.
packages/trpc/server/api-token-router/router.ts, schema.ts TRPC router and schema for API token management operations.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2024 1:24am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2024 1:24am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Visit Preview Feb 26, 2024 1:24am
prd-marketing ⬜️ Ignored (Inspect) Visit Preview Feb 26, 2024 1:24am

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b9e5905 and 22e3a79.
Files ignored due to path filters (1)
  • package-lock.json is excluded by: !**/*.json
Files selected for processing (1)
  • packages/prisma/schema.prisma (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/prisma/schema.prisma

@Mythie Mythie merged commit f7c6b53 into main Feb 26, 2024
13 checks passed
@Mythie Mythie deleted the feat/public-api branch February 26, 2024 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[DOC-287] REST API
6 participants