# Project plan — edge_functions

Evidence date: 2026-10-16.

Source repository: `git@bitbucket.org:overdrive/edge_functions.git` (`https://bitbucket.org/overdrive/edge_functions.git`).

Inspected revision: `main` at `7449104` (2024-05-02, Jaco Brits, "add new functions"). The scan-host path `~/projects/sonar_scan/repos/edge_functions` was not on this machine. The tree below was read from that git revision. Full history is four commits. There are no other branches and no tags.

There is no product requirements document in the source repository and no prior Silicon Ark set for this directory. `readme.txt` is a local setup note (Deno, Supabase CLI, serve, and one deploy command). It is not a product brief.

`package-lock.json` records the package name `datafy_edge_fuctions`. `supabase/config.toml` sets `project_id` to the same string, including the missing "n". Supabase CLI sets `project_id` from the working directory name at `supabase init`. **Inferred:** the project was initialised in a folder of that name. The Bitbucket repository slug is `edge_functions`. Why the two names differ is **Unknown / Requires Confirmation**.

Silicon Ark `terraform_scripts` describes a Datafy production Supabase host at `supabase.datafy.co.za`. This repository's readme points at Supabase project ref `natpyffafbqetnbeoctm` (`https://natpyffafbqetnbeoctm.supabase.co/functions/v1/hello`). The shared word "datafy" is the only link in evidence. Whether this repository deploys to that host is **Unknown / Requires Confirmation**.

This plan describes what the repository contains. It does not decide what the product should become.

## Product

**Documented** in `readme.txt`: a Windows-oriented recipe for installing Deno and the Supabase CLI, creating a function named `hello`, serving functions locally without JWT verification, and deploying `hello` to a named Supabase project.

**Implemented** on `main` at `7449104`: three Deno edge functions under `supabase/functions/`.

- `hello` reads one `name` from table `sites` and returns a JSON greeting.
- `callsheet` downloads one Excel object from Storage and logs the sheet names. The HTTP body it returns is an empty payload object.
- `upload_sj` attempts to download a different Excel object and upsert rows into `report_sj`. The success path assigns to a `const` and cannot return that response as written.

No written statement of product owner, audience, or business goal was found. The spreadsheet names (`CMR_CALL_CYCLE_2023.xlsx`, `FState Region ALL CHANNEL REPORTS 10 MARCH 2024.xlsx`) are the only domain clues. What CMR, Free State, and `sj` mean in this product is **Unknown / Requires Confirmation**.

## Branch reality

| Line | Tip | Date | What it is |
|---|---|---|---|
| `main` (default; `origin/HEAD`) | `7449104` | 2024-05-02 | Only branch. 4 commits from 2024-03-29 to 2024-05-02 |

Nothing in git is dated after 2024-05-02. Whether any function is still deployed is **Unknown / Requires Confirmation**. This inspection did not call the URL in `readme.txt`.

| Commit | Date | Author | Subject |
|---|---|---|---|
| `3ee659a` | 2024-03-29 | Jaco Brits | Initial commit (`.gitignore` only) |
| `323c389` | 2024-03-29 | Jaco Brits | `sonar-project.properties` created online with Bitbucket |
| `2f97818` | 2024-03-29 | Jaco Brits | `bitbucket-pipelines.yml` created online with Bitbucket |
| `7449104` | 2024-05-02 | Jaco Brits | add new functions (readme, CLI config, three functions, npm lockfile) |

## Objectives

No objectives document exists. The objectives that can be read from the repo are:

1. Run Supabase locally and serve edge functions (`readme.txt`).
2. Deploy function `hello` to project ref `natpyffafbqetnbeoctm` (`readme.txt`).
3. Read a site name from Postgres (`supabase/functions/hello/index.ts`).
4. Open a call-cycle workbook from Storage (`supabase/functions/callsheet/index.ts`). The parse-and-return steps are comments, not running code.
5. Load a regional channel-report workbook into `report_sj` (`supabase/functions/upload_sj/index.ts`). The handler does not complete that path as written.
6. Run SonarQube on `main` (`bitbucket-pipelines.yml`, `sonar-project.properties`).

## Scope

In scope for this repository:

- Supabase CLI project (`package.json`, `supabase/config.toml`, empty `supabase/seed.sql`).
- Three edge functions and their Deno imports.
- Editor settings for the Deno language server (`.vscode/`).
- A Bitbucket Pipelines SonarQube step on `main`.
- A generic ignore file and `supabase/.gitignore` (`.branches`, `.temp`, `.env`).

Out of scope, because they are not in this repository:

- SQL migrations, RLS policies, and the definitions of `sites` and `report_sj`.
- The Excel files themselves.
- A frontend, a caller application, or an API client other than these functions.
- Supabase project settings in the hosted dashboard (secrets, JWT enforcement as actually deployed, buckets).
- The Datafy AWS Terraform stack. Name overlap only. See the opening note.

The onboarding issue (OVER-100, created 2026-09-28) listed `sonarqube_scan.bat` in the top-level tree. That file is not in `main` at `7449104`. No commit adds or removes it. Whether it existed only as an untracked file on the scan host is **Unknown / Requires Confirmation**.

## System architecture

```text
HTTP caller
  -> Supabase Edge Functions gateway  /functions/v1/<function-name>
       hello       Postgres table sites via SUPABASE_URL + SUPABASE_ANON_KEY
       callsheet   Storage bucket uploads, object callsheet/CMR_CALL_CYCLE_2023.xlsx
                   (same URL and anon key)
       upload_sj   second client: SUPABASE_STORAGE_URL + SUPABASE_ANON_STORAGE_KEY
                   then table report_sj via the first client

Local developer
  npx supabase start
  npx supabase functions serve --no-verify-jwt
  http://127.0.0.1:54321/functions/v1/<name>

Bitbucket Pipelines (branch main only)
  image maven:3.3.9
  sonarsource/sonarqube-scan:2.0.1
  SONAR_HOST_URL, SONAR_TOKEN from repository or workspace variables
```

`readme.txt` is the only place that names a hosted base URL. It names `hello` only. Deploy commands for `callsheet` and `upload_sj` are not written down.

`supabase/config.toml` is the local stack from `supabase init` (API, DB, Studio, Auth, Storage, Realtime, Inbucket, Analytics, and experimental S3 placeholders). The three functions do not call Auth, Realtime, Inbucket, or Analytics. Those sections are local CLI template, not function behaviour.

## Major components

| Component | Where | Role |
|---|---|---|
| `hello` | `supabase/functions/hello/index.ts` | Greeting from the first `sites.name` |
| `callsheet` | `supabase/functions/callsheet/index.ts` | Download a call-cycle workbook and log sheet names |
| `upload_sj` | `supabase/functions/upload_sj/index.ts` | Attempt to load a channel-report workbook into `report_sj` |
| Supabase CLI | `package.json` devDependency `supabase` `^1.151.1`, locked at `1.151.1` | Local stack and deploy |
| Local stack config | `supabase/config.toml` | Ports, Postgres 15, storage limit, auth template |
| SonarQube | `bitbucket-pipelines.yml`, `sonar-project.properties` | Analysis on `main` |
| Setup note | `readme.txt` | Install, serve, deploy `hello`, example secret |

There is no `deno.json`, import map, or `[functions.*]` block. Each function's entrypoint is the conventional `index.ts`. The directory name is the endpoint name. `readme.txt` says that explicitly for `hello`.

## Milestones

The repository does not list future milestones. The only sequence on record is the git history above: ignore file, then Sonar wiring created in the Bitbucket UI, then one commit that added the functions about five weeks later.

Current project status: **source present, work stopped in git on 2024-05-02**. `callsheet` returns an empty payload. `upload_sj` does not reach its JSON response on either branch, because both branches assign to `data` after `const { data, error }`. No tests are in the tree. No pipeline step deploys functions.

## Implementation plan

There is no written implementation plan. What the tree shows was actually done:

1. `3ee659a` added a generic ignore template (Node, Java, Python, Maven, JetBrains, media). It is not specific to Deno or Supabase, apart from `node_modules/` and `dist/`.
2. `323c389` and `2f97818` added Sonar project key and a Pipelines step. Both commit subjects say the files were created online with Bitbucket.
3. `7449104` added the CLI, the readme, editor settings, and all three functions in one commit. `supabase/seed.sql` was added empty.

Nothing in the repository describes a next step. Commented blocks inside `callsheet` show an earlier attempt to turn each sheet into CSV and to download `FState Region ALL CHANNEL REPORTS 10 MARCH 2024.xlsx`. That filename is the one `upload_sj` uses. Those comments are not a committed plan.

## Known dependencies

| Dependency | Declared in | Version in the lock or import |
|---|---|---|
| `supabase` CLI | `package.json` `devDependencies` | `^1.151.1`, resolved `1.151.1`. `engines.npm` `>=8` |
| Deno | `readme.txt` install step; `.vscode` Deno extension | Version not pinned |
| `@supabase/supabase-js` | `npm:@supabase/supabase-js` in all three functions | No version specifier |
| `flat` (`xlsx`, `readXLSX`) | `https://deno.land/x/flat/mod.ts` in `callsheet` | No tag or commit pin. `readXLSX` is imported and not used |
| `@supabase/storage-js` | `npm:@supabase/storage-js` in `upload_sj` | No version specifier |
| `std/encoding/base64` `decode` | `npm:std/encoding/base64` in `upload_sj` | Imported and not used. The specifier is `npm:std`, not a `deno.land/std` URL |
| SheetJS `read` | `npm:xlsx/mod` in `upload_sj` | No version specifier |

Postgres tables `sites` and `report_sj`, and Storage bucket `uploads`, are used and not created here. `supabase/seed.sql` is empty. There is no `supabase/migrations` directory.

Runtime environment names the functions read:

- `SUPABASE_URL`, `SUPABASE_ANON_KEY` — all three functions.
- `SUPABASE_STORAGE_URL`, `SUPABASE_ANON_STORAGE_KEY` — `upload_sj` only.

`readme.txt` shows `supabase secrets set MY_NAME=Chewbacca` as a general example. No function reads `MY_NAME`.

## Current status

| Area | State | Evidence |
|---|---|---|
| Repository | Single branch `main`, last commit 2024-05-02 | `git log`, `git branch -a` |
| Functions | Three handlers committed; two do not deliver the behaviour their comments describe | `supabase/functions/*/index.ts` |
| Database schema | Not in this repo | No migrations; empty seed |
| Hosted deploy | Documented for `hello` only | `readme.txt` |
| Tests | None | No test files, no test script, pipeline step is Sonar only |
| CI | SonarQube on `main`, Maven image | `bitbucket-pipelines.yml` |
| Silicon Ark | This set is the first | No earlier `edge_functions/` directory |
