Commit Graph

19 Commits

Author SHA1 Message Date
Will Chen
91cf1e97c3 Support shared modules for supabase edge functions (#1964)
Credit: thanks @SlayTheDragons whose PR
https://github.com/dyad-sh/dyad/pull/1665 paved the way for this
implementation.

<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Adds _shared module support for Supabase edge functions with
import-map packaging and automatic redeploys; updates deployment to
include full function directories plus shared files, and adds path
utilities and tests.
> 
> - **Supabase Edge Functions**
> - **Shared Modules Support**: Detect `_shared` changes and redeploy
all functions; regular function changes deploy only that function.
> - **Deployment Overhaul**: `deploySupabaseFunctions` now uploads full
function directories plus `_shared` files via multipart form-data, sets
`entrypoint_path`, and writes `import_map.json` (`_shared/` →
`../_shared/`).
> - **Function Discovery & Packaging**: Add file collection helpers
(`listFilesWithStats`, `loadZipEntries`) and path utilities
(`toPosixPath`, `findFunctionDirectory`, `stripSupabaseFunctionsPrefix`)
with signature-based caching for `_shared`.
> - **APIs & Utils**: Introduce `isSharedServerModule`, refine
`isServerFunction` (excludes `_shared`), add
`extractFunctionNameFromPath`, and `buildSignature`.
> - **IPC Changes**
> - Update file edit/rename/delete flows to track shared module edits
and trigger full redeploys; otherwise deploy per-function using
extracted name and `appPath`.
> - **Prompts**
>   - Document `_shared` usage and import pattern in Supabase prompt.
> - **Tests**
> - Add tests for function/shared detection, name extraction, path
handling, and signature building.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
f35599ec0e708e2ef6b7e78ae7901b29953a6dff. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->









<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds support for shared modules for Supabase edge functions. Shared code
in supabase/functions/_shared is now bundled via an import map and
triggers redeploys across all functions when changed.

- **New Features**
- Detects shared modules in supabase/functions/_shared and redeploys all
functions when they change.
- Deploys full function directories plus shared files, and writes an
import_map.json that resolves "_shared/" imports.
- Auto-deploys only the affected function on file changes; switches to
redeploy-all when a shared module is touched.

- **Refactors**
- deploySupabaseFunction now uploads multiple files (function + shared)
using multipart form-data and sets entrypoint/import map.
- Added file collection, path utilities, and shared-file caching via
content signatures to reduce redundant reads.
- Updated deployAllSupabaseFunctions to skip non-function dirs (e.g.,
_shared) and use functionPath.
- Added tests for function/shared detection, path handling, and
signature building.

<sup>Written for commit 302d84625d9e61477db9ada052a027b29ff18cef.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-12-15 18:07:57 -08:00
Will Chen
8ce87dd61f Re-deploy all supabase edge function when revert version (#1787)
#1784 

<!-- CURSOR_SUMMARY -->
> [!NOTE]
> After reverting to a previous version, automatically deploy all
Supabase edge functions; failures are logged as warnings without
blocking the revert.
> 
> - **Version Revert Flow (`src/ipc/handlers/version_handlers.ts`)**:
> - After revert, re-deploy all Supabase edge functions when
`app.supabaseProjectId` is present via `deployAllSupabaseFunctions`.
> - Aggregate deployment errors into `warningMessage` (non-blocking);
logs successes/failures.
>   - Initialize `warningMessage` to an empty string.
> - **Supabase Utilities (`src/supabase_admin/supabase_utils.ts`)**:
> - Add `deployAllSupabaseFunctions`: scans `supabase/functions/*`,
ensures `index.ts`, reads content, calls `deploySupabaseFunctions`,
logs, collects errors; skips if directory missing.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c29333c0f951b60b4e80da0b46cf0287d03bdae1. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->





<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Automatically re-deploys Supabase edge functions after restoring a
previous app version to keep functions in sync with reverted code.
Deployment failures surface as warnings and do not block the revert.

- **New Features**
- Re-deploy all Supabase edge functions on version revert when an app
has a Supabase project ID.
- Added deployAllSupabaseFunctions: scans supabase/functions, deploys
each index.ts sequentially, skips missing files, collects errors, and
logs warnings.

<sup>Written for commit c29333c0f951b60b4e80da0b46cf0287d03bdae1.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-15 01:40:52 -08:00
Will Chen
c50527b4c0 Security Panel MVP (#1660)
TODOs:

- [x] Add documentation
- [x] e2e tests: run security review, update knowledge, and fix issue
- [x] more stringent risk rating


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Introduces a new Security mode with a Security Review panel that runs
reviews, edits rules, parses findings via IPC, and supports fixing
issues, with tests and prompt/runtime support.
> 
> - **UI/Preview Panel**:
> - Add `security` preview mode to `previewModeAtom` and ActionHeader
(Shield button).
> - New `SecurityPanel` showing findings table (sorted by severity), run
review, fix issue flow, and edit `SECURITY_RULES.md` dialog.
>   - Wire into `PreviewPanel` content switch.
> - **Hooks**:
>   - `useSecurityReview(appId)`: fetch latest review via IPC.
> - `useStreamChat`: add `onSettled` callback to invoke refreshes after
streams.
> - **IPC/Main**:
> - `security_handlers`: `get-latest-security-review` parses
`<dyad-security-finding>` from latest assistant message.
>   - Register handler in `ipc_host`; expose channel in `preload`.
>   - `ipc_client`: add `getLatestSecurityReview(appId)`.
> - `chat_stream_handlers`: detect `/security-review`, use dedicated
system prompt, optionally append `SECURITY_RULES.md`, suppress
Supabase-not-available note in this mode.
> - **Prompts**:
> - Add `SECURITY_REVIEW_SYSTEM_PROMPT` with structured finding output.
> - **Supabase**:
> - Enhance schema query to include `rls_enabled`, split policy
`using_clause`/`with_check_clause`.
> - **E2E Tests**:
> - New `security_review.spec.ts` plus snapshots and fixture findings;
update test helper for `security` mode and findings table snapshot.
> - Fake LLM server streams security findings for `/security-review` and
increases batch size.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
5022d01e22a2dd929a968eeba0da592e0aeece01. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-29 17:32:52 -07:00
Will Chen
133ca57628 Support Supabase branches (#1394)
<!-- This is an auto-generated description by cubic. -->

## Summary by cubic
Adds Supabase database branch selection per app, with a new schema field
and UI to choose a branch after connecting a project. Resets branch when
changing or disconnecting the project to keep state consistent.

- **New Features**
  - Added apps.supabase_branch_id column.
- Branch dropdown in SupabaseConnector shown after a project is
connected; selection persists and triggers app refresh.
- New state and hooks: supabaseBranchesAtom, loadBranches(projectId),
setAppBranch(branchId).
- IPC endpoints: supabase:list-branches and supabase:set-app-branch;
setting/unsetting project also clears the branch.

- **Migration**
- Apply drizzle migration 0013_supabase_branch.sql to add the
supabase_branch_id column (defaults to null).

<!-- End of auto-generated description by cubic. -->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds Supabase database branch selection per app, including parent
project tracking, new IPC endpoints, UI dropdown, and an accompanying DB
migration with e2e tests.
> 
> - **Database**:
> - Add `apps.supabase_parent_project_id` via migration
`drizzle/0015_complete_old_lace.sql`; snapshot and journal updated.
> - **IPC/Main**:
> - New `supabase:list-branches` handler and management client
`listSupabaseBranches` (real API + test stubs).
> - Update `supabase:set-app-project` to accept `{ projectId,
parentProjectId?, appId }`; unset clears both IDs.
> - `get-app` resolves `supabaseProjectName` using
`supabase_parent_project_id` when present.
> - **Types & Client**:
> - Add `SupabaseBranch`, `SetSupabaseAppProjectParams`, and
`App.supabaseParentProjectId`; expose `listSupabaseBranches` and updated
`setSupabaseAppProject` in `ipc_client` and preload whitelist.
> - **UI/Hooks**:
> - Supabase UI: branch dropdown in `SupabaseConnector` with
`loadBranches`, selection persists via updated `setAppProject`.
> - State: add `supabaseBranchesAtom`; `useSupabase` gets `branches`,
`loadBranches`, new param shape for `setAppProject`.
>   - TokenBar/ChatInput: add `data-testid` for token bar and toggle.
> - **Supabase Context (tests)**:
> - Test build returns large context for `test-branch-project-id` to
validate branch selection.
> - **E2E Tests**:
> - Add `supabase_branch.spec.ts` and snapshot verifying branch
selection affects token usage.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
33054278db8396b4371ed6e8224105cb5684b7ac. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-10-14 15:34:42 -07:00
Will Chen
72be54e6c5 verify jwt to false (#1085)
fixes #1010 
    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Disable automatic JWT verification for Supabase Edge Functions and
update prompts/templates to require and demonstrate manual auth
handling. Fixes #1010.

- **Bug Fixes**
  - Set verify_jwt: false in function deployment.
- Updated Supabase prompt with an Authentication section and guidance to
manually verify tokens.
- Adjusted the hello function template to check the Authorization header
and return 401 when missing.

<!-- End of auto-generated description by cubic. -->
2025-08-25 21:10:22 -07:00
Will Chen
ade5271e22 Better supabase error message (#682) 2025-07-21 16:32:39 -07:00
Will Chen
382fe9bab5 support setting for writing supabase migration files (#427) 2025-06-17 15:14:02 -07:00
Will Chen
f9eb14d25f Better supabase error message (#415) 2025-06-16 14:25:05 -07:00
Will Chen
16bf0828f5 Fix stale app UI (supabase) & overall E2E test infra improvements (#337)
Fixes #269
2025-06-04 23:07:59 -07:00
Will Chen
7f410ce830 Better supabase error message (#336)
Fixes #287
2025-06-04 22:22:00 -07:00
Will Chen
648724b4e9 Fix #186 by only fetching normal functions for supabase context (#194)
Fixes #186, #168.
2025-05-19 11:48:33 -07:00
Will Chen
2537fbb342 lint using oxlint (#106) 2025-05-08 17:21:35 -07:00
Will Chen
0d56651220 Run prettier on everything (#104) 2025-05-06 23:02:28 -07:00
Will Chen
4fb4e49c5d Supabase publishable key (#73) 2025-05-02 12:39:17 -07:00
Will Chen
deb3c2d362 Handle PR comments from mrge 2025-04-23 12:59:09 -07:00
Will Chen
55c0190f26 Support rename/delete edge function & standardize output 2025-04-23 12:59:09 -07:00
Will Chen
6e1935bbba Support supabase function deployment 2025-04-23 12:59:09 -07:00
Will Chen
922ee7d90a Handle token refresh for supabase 2025-04-23 12:59:09 -07:00
Will Chen
4294ce5767 Supabase support: client, auth & SQL 2025-04-23 12:59:09 -07:00