Skip to content

feat(integrations): native TinyFish Fetch and Gmail draft creation - #115

Merged
hugoalves-dev merged 2 commits into
mainfrom
hugo/lucid-allen-thoyxd
Nov 24, 2026
Merged

hugoalves-dev merged 2 commits into
mainfrom
hugo/lucid-allen-thoyxd

Conversation

@hugoalves-dev

Copy link
Copy Markdown
Owner

Closes #113

Summary

TinyFish Fetch and Gmail draft creation now run inside the backend, and the AI client reaches them through Applywell's own MCP server. The client still writes the resume content and the email body. There is no n8n, webhook or external MCP.

New MCP tools. The names follow the repo's existing Kebab-Case convention, not the fetch_url / create_email_draft names suggested in the issue:

  • Fetch-Url: reads a URL through the user's TinyFish key and returns Markdown, title, final URL and metadata, plus an untrusted-content notice and a manualInputRequired fallback.
  • List-Email-Accounts: lists the connected Gmail mailboxes and their profiles (e.g. Java, CSharp).
  • Create-Email-Draft: creates an HTML draft and can attach the application's generated resume PDF.

REST endpoints are under /api/v1/integrations/{tinyfetch,gmail}/**. The full contract is in docs/integrations.md.

Design notes

  • Secrets at rest: API keys and OAuth tokens are encrypted with AES-256-GCM using the new APP_INTEGRATIONS_ENCRYPTION_KEY. Responses only include a masked hint such as ••••1234.
  • TinyFetch:
    • SSRF guard: only http(s) on default ports, no credentials in the URL, and every resolved address must be public.
    • Per-user cache, plus de-duplication of identical requests that are in flight at the same time.
    • Per-minute and daily quotas. Users can only set values at or below the server ceilings (default 150/min and 1000/day).
    • Bounded retry with backoff on 429/5xx, honouring Retry-After.
    • Content is truncated past a configurable size. Blocked or thin pages come back as BLOCKED or PARTIAL so the AI asks the user to paste the content.
  • Gmail:
    • OAuth 2.0 with PKCE and a single-use state. The only scope requested is gmail.compose. Signing in with Google does not grant Gmail access.
    • Multiple accounts per user, each with a profile name.
    • Tokens are refreshed when needed. Disconnecting revokes the grant, and an invalid_grant on refresh flags the account for reconnection.
    • The message is MIME multipart. The resume PDF is read internally through the user's Drive connection, which also checks application ownership.
  • Idempotency: a ledger row is committed before Gmail is called.
    • Repeating a request returns the existing draft.
    • A timeout or Gmail 5xx returns 409 EMAIL_DRAFT_OUTCOME_UNKNOWN. It is never retried automatically, so no duplicate drafts.
    • Definitive failures can be retried.
  • Safety:
    • Drafts are never sent, and creating one never changes an application's status.
    • A failed draft never touches the application or its resume.
    • Changing credentials and connecting or disconnecting mailboxes are restricted to first-party sessions (@UserSessionOnly), so an AI client can use the integrations but cannot rewire them.
  • Observability: Micrometer counters and timers for fetches and drafts. Logs include the host only, never the full URL, recipients, bodies or tokens.

Deploy checklist

  • Set APP_INTEGRATIONS_ENCRYPTION_KEY (openssl rand -base64 32).
  • Enable the Gmail API in the Google Cloud project and add ${APP_API_BASE_URL}/api/v1/integrations/gmail/oauth/callback to the OAuth client's redirect URIs.
  • Set GMAIL_OAUTH_COMPLETE_URL=https://applywell.hugojava.dev/account.
  • gmail.compose is a restricted scope. While the consent screen is in Testing, only listed test users can connect and refresh tokens expire after 7 days. Public use requires Google verification (see the docs).
  • Flyway V39 creates 5 new tables. It is additive only.

Testing

  • 391 unit tests pass (mvn test -Dtest='com.jobtracker.unit.**.*Test'), including the new suites for the cipher, the SSRF validator, the TinyFetch client, service and quotas, the Gmail client, credentials, accounts, MIME, ledger and drafts, and the MCP tool contract.
  • Not run: the Testcontainers ITs, because there is no Docker in this environment.
  • Manual verification against a local PostgreSQL 16:
    • Applied V1–V37 plus V39. V38 was skipped because pgvector is not installed locally.
    • Booted the jar with ddl-auto: validate: startup succeeded and 31 MCP tools were registered.
    • Smoke-tested the REST flow: settings CRUD, key stored as ciphertext, limit bounds, SSRF rejection, Gmail consent URL (PKCE + gmail.compose), a forged OAuth state redirecting with an error, and the draft endpoint with no connected account.
  • Not verified against the real APIs, since there were no credentials or network access to them here:
    • Live TinyFish calls. The endpoint and fields come from the public Fetch API reference, and the parser accepts text, markdown or content.
    • Live Gmail calls.

Frontend: hugoalves-dev/React-JobApplyTracker (branch hugo/lucid-allen-thoyxd).


Generated by Claude Code

Adds per-user TinyFish Fetch (URL to Markdown) and Gmail draft creation
directly in the backend, exposed through Applywell's own MCP server
(Fetch-Url, List-Email-Accounts, Create-Email-Draft) and REST API under
/api/v1/integrations/**. The AI client still generates resume content
and email bodies; no n8n, webhook or external MCP is involved.

- AES-256-GCM encryption at rest for API keys and OAuth tokens
- TinyFetch: SSRF guard, per-user cache, in-flight dedup, per-minute and
  daily quotas, bounded retry with backoff and Retry-After, manual-input
  fallback for blocked/partial pages, content flagged as untrusted
- Gmail: OAuth 2.0 + PKCE with gmail.compose only, multiple accounts with
  profiles, refresh/revoke, MIME HTML + resume PDF read internally from
  Drive, idempotency ledger that never auto-retries ambiguous outcomes
- Drafts are never sent and never change application status
- Credential mutations restricted to first-party user sessions

Closes #113

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GfjfbPHrV3NGdTB4ssht2P
@github-actions github-actions Bot added documentation Improvements or additions to documentation backend tests database configuration labels Nov 24, 2026
@github-actions

Copy link
Copy Markdown

Qodana for JVM

8 new problems were found

Inspection name Severity Problems
Constant values 🔶 Warning 3
Nullability and data flow problems 🔶 Warning 3
Non-atomic operation on 'volatile' field 🔶 Warning 2
View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/[email protected]
        with:
          upload-result: true
Contact Qodana team

Contact us at [email protected]

@hugoalves-dev
hugoalves-dev merged commit ebb128a into main Nov 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend configuration database documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: integrar TinyFish Fetch e criação de rascunhos Gmail nativamente ao Applywell

2 participants