forked from cartsnitch/cartsnitch
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2b0e7cbd3 | |||
| 6d7d54729c | |||
| 895ad77850 | |||
| 5f1570e6d2 | |||
| 96c0f89a03 | |||
| 0f8aa2fe47 | |||
| 6903c7dde3 | |||
| 2946ac8dc5 | |||
| 6717e105f4 | |||
| 01ea36c5aa | |||
| 0bb4b7d183 | |||
| 7b9194a152 | |||
| ca8cf2a80a | |||
| 5bb0a5817b | |||
| 2444219f75 | |||
| c707caea41 | |||
| 30d670a257 | |||
| cfa4d8fa91 | |||
| 39e8d5c9f9 | |||
| 44c475265e | |||
| 8e1f61214c | |||
| fb1c5fb929 | |||
| 75be08ccf3 |
@@ -46,6 +46,31 @@ jobs:
|
|||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: npx vitest run
|
run: npx vitest run
|
||||||
|
|
||||||
|
lighthouse:
|
||||||
|
runs-on: runners-cartsnitch
|
||||||
|
needs: [test]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "20"
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run build
|
||||||
|
- name: Install Chromium for Lighthouse
|
||||||
|
run: |
|
||||||
|
npm install -g playwright
|
||||||
|
npx playwright install --with-deps chromium
|
||||||
|
- name: Start preview server
|
||||||
|
run: |
|
||||||
|
npm run preview &
|
||||||
|
npx wait-on http://localhost:4173/ --timeout 30000
|
||||||
|
- name: Run Lighthouse CI
|
||||||
|
run: |
|
||||||
|
CHROME_PATH=$(find /home/runner/.cache/ms-playwright -name chrome -type f 2>/dev/null | head -1)
|
||||||
|
npm install -g @lhci/cli
|
||||||
|
LHCI_CHROME_PATH="$CHROME_PATH" lhci autorun
|
||||||
|
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: runners-cartsnitch
|
runs-on: runners-cartsnitch
|
||||||
needs: [lint, test]
|
needs: [lint, test]
|
||||||
@@ -111,6 +136,8 @@ jobs:
|
|||||||
build-and-push-auth:
|
build-and-push-auth:
|
||||||
runs-on: runners-cartsnitch
|
runs-on: runners-cartsnitch
|
||||||
needs: [lint, test]
|
needs: [lint, test]
|
||||||
|
outputs:
|
||||||
|
calver_tag: ${{ steps.calver.outputs.version }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
@@ -161,7 +188,7 @@ jobs:
|
|||||||
|
|
||||||
deploy-dev:
|
deploy-dev:
|
||||||
runs-on: runners-cartsnitch
|
runs-on: runners-cartsnitch
|
||||||
needs: [build-and-push]
|
needs: [build-and-push, build-and-push-auth]
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- name: Generate GitHub App token
|
- name: Generate GitHub App token
|
||||||
@@ -179,20 +206,25 @@ jobs:
|
|||||||
repository: cartsnitch/infra
|
repository: cartsnitch/infra
|
||||||
token: ${{ steps.app-token.outputs.token }}
|
token: ${{ steps.app-token.outputs.token }}
|
||||||
ref: main
|
ref: main
|
||||||
|
path: infra
|
||||||
|
|
||||||
- name: Install kubectl
|
- name: Install kubectl
|
||||||
uses: azure/setup-kubectl@v4
|
uses: azure/setup-kubectl@v4
|
||||||
|
|
||||||
|
- name: Install kustomize
|
||||||
|
uses: imranismail/setup-kustomize@v2
|
||||||
|
|
||||||
- name: Update dev overlay image tag
|
- name: Update dev overlay image tag
|
||||||
working-directory: apps/overlays/dev
|
|
||||||
run: |
|
run: |
|
||||||
|
cd infra/apps/overlays/dev
|
||||||
kustomize edit set image ghcr.io/cartsnitch/cartsnitch:${{ needs.build-and-push.outputs.calver_tag }}
|
kustomize edit set image ghcr.io/cartsnitch/cartsnitch:${{ needs.build-and-push.outputs.calver_tag }}
|
||||||
|
kustomize edit set image ghcr.io/cartsnitch/auth:${{ needs.build-and-push-auth.outputs.calver_tag }}
|
||||||
|
|
||||||
- name: Commit and push to infra
|
- name: Commit and push to infra
|
||||||
run: |
|
run: |
|
||||||
cd apps/overlays/dev
|
cd infra
|
||||||
git config user.name "cartsnitch-ci[bot]"
|
git config user.name "cartsnitch-ci[bot]"
|
||||||
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
git config user.email "cartsnitch-ci[bot]@users.noreply.github.com"
|
||||||
git add kustomization.yaml
|
git add apps/overlays/dev/kustomization.yaml
|
||||||
git commit -m "ci(dev): update cartsnitch image to ${{ needs.build-and-push.outputs.calver_tag }}"
|
git commit -m "ci(dev): update cartsnitch and auth images to ${{ needs.build-and-push.outputs.calver_tag }}"
|
||||||
git push origin main
|
git push origin main
|
||||||
|
|||||||
@@ -1,45 +1 @@
|
|||||||
# CartSnitch Monorepo
|
# CartSnitch
|
||||||
|
|
||||||
CartSnitch is a self-hosted grocery price intelligence platform. This repo consolidates the core services and the flagship frontend PWA.
|
|
||||||
|
|
||||||
## Services
|
|
||||||
|
|
||||||
| Directory | Service | Purpose |
|
|
||||||
|-----------|---------|---------|
|
|
||||||
| `/` (root) | **Frontend** | React 18 PWA — mobile-first price intelligence UI |
|
|
||||||
| `api/` | **API Gateway** | FastAPI — frontend-facing REST API |
|
|
||||||
| `common/` | **Common** | Shared Python models, schemas, Alembic migrations |
|
|
||||||
| `receiptwitness/` | **ReceiptWitness** | Purchase ingestion via retailer scrapers |
|
|
||||||
|
|
||||||
## Quick Start
|
|
||||||
|
|
||||||
### Frontend (root)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install
|
|
||||||
npm run dev # http://localhost:5173
|
|
||||||
npm run build # production build
|
|
||||||
npm run test # unit tests (Vitest)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Python Services
|
|
||||||
|
|
||||||
Each Python service uses [uv](https://github.com/astral-sh/uv) and has its own `pyproject.toml`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd api # or common / receiptwitness
|
|
||||||
uv sync
|
|
||||||
uv run pytest
|
|
||||||
```
|
|
||||||
|
|
||||||
## Development Workflow
|
|
||||||
|
|
||||||
- **Never push directly to main.** Always open a PR from a feature branch.
|
|
||||||
- Branch naming: `feature/<description>` or `fix/<description>`
|
|
||||||
- Conventional commits: `feat:`, `fix:`, `refactor:`, `docs:`, `chore:`
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
For full details see [CLAUDE.md](./CLAUDE.md) or the per-service `CLAUDE.md` in each subdirectory.
|
|
||||||
|
|
||||||
CartSnitch is a polyrepo-style monorepo: each service can be built and deployed independently, but sharing code between `common/` and the other Python services is done via local path dependencies in `pyproject.toml`.
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
"""Change users.id and FK columns from uuid to text.
|
||||||
|
|
||||||
|
Better-Auth generates nanoid-style text IDs (e.g. pGud2ln2WAFHC0KYjBVKR4Rc7mM8OcTI),
|
||||||
|
but the users table was using PostgreSQL uuid type, causing INSERT failures.
|
||||||
|
|
||||||
|
Revision ID: 003_fix_user_id_text
|
||||||
|
Revises: 002_better_auth_tables
|
||||||
|
Create Date: 2026-03-31
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision = "003_fix_user_id_text"
|
||||||
|
down_revision = "002_better_auth_tables"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# Step 1: Drop FK constraints that reference users.id
|
||||||
|
op.execute(text("ALTER TABLE user_store_accounts DROP CONSTRAINT IF EXISTS user_store_accounts_user_id_fkey"))
|
||||||
|
op.execute(text("ALTER TABLE purchases DROP CONSTRAINT IF EXISTS purchases_user_id_fkey"))
|
||||||
|
|
||||||
|
# Step 2: Alter users.id from uuid to text
|
||||||
|
op.alter_column("users", "id", existing_type=sa.UUID(), type_=sa.Text(), existing_nullable=False, postgresql_using="id::text")
|
||||||
|
|
||||||
|
# Step 3: Alter user_store_accounts.user_id from uuid to text
|
||||||
|
op.alter_column("user_store_accounts", "user_id", existing_type=sa.UUID(), type_=sa.Text(), existing_nullable=False, postgresql_using="user_id::text")
|
||||||
|
|
||||||
|
# Step 4: Alter purchases.user_id from uuid to text
|
||||||
|
op.alter_column("purchases", "user_id", existing_type=sa.UUID(), type_=sa.Text(), existing_nullable=False, postgresql_using="user_id::text")
|
||||||
|
|
||||||
|
# Step 5: Re-add FK constraints
|
||||||
|
op.execute(text("ALTER TABLE user_store_accounts ADD CONSTRAINT user_store_accounts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id)"))
|
||||||
|
op.execute(text("ALTER TABLE purchases ADD CONSTRAINT purchases_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id)"))
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# Drop FK constraints
|
||||||
|
op.execute(text("ALTER TABLE purchases DROP CONSTRAINT IF EXISTS purchases_user_id_fkey"))
|
||||||
|
op.execute(text("ALTER TABLE user_store_accounts DROP CONSTRAINT IF EXISTS user_store_accounts_user_id_fkey"))
|
||||||
|
|
||||||
|
# Alter back to UUID
|
||||||
|
op.alter_column("purchases", "user_id", existing_type=sa.Text(), type_=sa.UUID(), existing_nullable=False, postgresql_using="user_id::uuid")
|
||||||
|
op.alter_column("user_store_accounts", "user_id", existing_type=sa.Text(), type_=sa.UUID(), existing_nullable=False, postgresql_using="user_id::uuid")
|
||||||
|
op.alter_column("users", "id", existing_type=sa.Text(), type_=sa.UUID(), existing_nullable=False, postgresql_using="id::uuid")
|
||||||
|
|
||||||
|
# Re-add FK constraints
|
||||||
|
op.execute(text("ALTER TABLE user_store_accounts ADD CONSTRAINT user_store_accounts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id)"))
|
||||||
|
op.execute(text("ALTER TABLE purchases ADD CONSTRAINT purchases_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id)"))
|
||||||
@@ -36,6 +36,15 @@ export const auth = betterAuth({
|
|||||||
},
|
},
|
||||||
|
|
||||||
session: {
|
session: {
|
||||||
|
modelName: "sessions",
|
||||||
|
fields: {
|
||||||
|
userId: "user_id",
|
||||||
|
expiresAt: "expires_at",
|
||||||
|
ipAddress: "ip_address",
|
||||||
|
userAgent: "user_agent",
|
||||||
|
createdAt: "created_at",
|
||||||
|
updatedAt: "updated_at",
|
||||||
|
},
|
||||||
expiresIn: 60 * 60 * 24 * 7, // 7 days
|
expiresIn: 60 * 60 * 24 * 7, // 7 days
|
||||||
updateAge: 60 * 60 * 24, // refresh after 1 day
|
updateAge: 60 * 60 * 24, // refresh after 1 day
|
||||||
cookieCache: {
|
cookieCache: {
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# CartSnitch Common
|
||||||
|
|
||||||
|
Shared models, schemas, and utilities for CartSnitch services.
|
||||||
|
|
||||||
|
## Test Users
|
||||||
|
|
||||||
|
The following users are seeded by `cartsnitch-seed` and can be used for local development and UAT.
|
||||||
|
|
||||||
|
| Email | Password | Display Name | Notes |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `uat@cartsnitch.com` | `CartSnitch-UAT-2026!` | UAT Tester | Primary UAT account. Use for regression testing in the CartSnitch frontend. Created by the seed runner via Better-Auth's bcrypt path — credentials work against the live auth service. Idempotent; re-running the seed skips this user if it already exists. |
|
||||||
|
|
||||||
|
### Running the Seed
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install with seed dependencies
|
||||||
|
pip install -e "cartsnitch-common[seed]"
|
||||||
|
|
||||||
|
# Run (requires CARTSNITCH_DATABASE_URL_SYNC)
|
||||||
|
CARTSNITCH_DATABASE_URL_SYNC=postgresql://user:pass@localhost:5432/cartsnitch \
|
||||||
|
cartsnitch-seed
|
||||||
|
```
|
||||||
|
|
||||||
|
### Architecture
|
||||||
|
|
||||||
|
- **Models** live in `src/cartsnitch_common/models/`
|
||||||
|
- **Alembic migrations** run via the `api` service (`api/alembic/`)
|
||||||
|
- **Seed runner** runs via `cartsnitch-seed` (installed as a package entry point)
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
"""Change users.id and user_id FKs from uuid to text.
|
||||||
|
|
||||||
|
Revision ID: 003_fix_user_id_text
|
||||||
|
Revises:
|
||||||
|
Create Date: 2026-03-31
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
revision: str = "003_fix_user_id_text"
|
||||||
|
down_revision: Union[str, None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# Drop FK constraints first
|
||||||
|
op.execute("ALTER TABLE user_store_accounts DROP CONSTRAINT IF EXISTS user_store_accounts_user_id_fkey")
|
||||||
|
op.execute("ALTER TABLE purchases DROP CONSTRAINT IF EXISTS purchases_user_id_fkey")
|
||||||
|
|
||||||
|
# Alter users.id from uuid to text
|
||||||
|
op.execute("ALTER TABLE users ALTER COLUMN id TYPE text USING id::text")
|
||||||
|
|
||||||
|
# Alter user_id columns from uuid to text
|
||||||
|
op.execute("ALTER TABLE user_store_accounts ALTER COLUMN user_id TYPE text USING user_id::text")
|
||||||
|
op.execute("ALTER TABLE purchases ALTER COLUMN user_id TYPE text USING user_id::text")
|
||||||
|
|
||||||
|
# Re-add FK constraints
|
||||||
|
op.execute(
|
||||||
|
"ALTER TABLE user_store_accounts ADD CONSTRAINT user_store_accounts_user_id_fkey "
|
||||||
|
"FOREIGN KEY (user_id) REFERENCES users(id)"
|
||||||
|
)
|
||||||
|
op.execute(
|
||||||
|
"ALTER TABLE purchases ADD CONSTRAINT purchases_user_id_fkey "
|
||||||
|
"FOREIGN KEY (user_id) REFERENCES users(id)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# Drop FK constraints
|
||||||
|
op.execute("ALTER TABLE user_store_accounts DROP CONSTRAINT IF EXISTS user_store_accounts_user_id_fkey")
|
||||||
|
op.execute("ALTER TABLE purchases DROP CONSTRAINT IF EXISTS purchases_user_id_fkey")
|
||||||
|
|
||||||
|
# Alter back to uuid
|
||||||
|
op.execute("ALTER TABLE users ALTER COLUMN id TYPE uuid USING id::uuid")
|
||||||
|
op.execute("ALTER TABLE user_store_accounts ALTER COLUMN user_id TYPE uuid USING user_id::uuid")
|
||||||
|
op.execute("ALTER TABLE purchases ALTER COLUMN user_id TYPE uuid USING user_id::uuid")
|
||||||
|
|
||||||
|
# Re-add FK constraints
|
||||||
|
op.execute(
|
||||||
|
"ALTER TABLE user_store_accounts ADD CONSTRAINT user_store_accounts_user_id_fkey "
|
||||||
|
"FOREIGN KEY (user_id) REFERENCES users(id)"
|
||||||
|
)
|
||||||
|
op.execute(
|
||||||
|
"ALTER TABLE purchases ADD CONSTRAINT purchases_user_id_fkey "
|
||||||
|
"FOREIGN KEY (user_id) REFERENCES users(id)"
|
||||||
|
)
|
||||||
@@ -27,6 +27,7 @@ dev = [
|
|||||||
]
|
]
|
||||||
seed = [
|
seed = [
|
||||||
"faker>=33.0,<34.0",
|
"faker>=33.0,<34.0",
|
||||||
|
"bcrypt>=4.0,<6.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Purchase(UUIDPrimaryKeyMixin, TimestampMixin, Base):
|
|||||||
|
|
||||||
__tablename__ = "purchases"
|
__tablename__ = "purchases"
|
||||||
|
|
||||||
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("users.id"), nullable=False)
|
user_id: Mapped[str] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||||
store_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("stores.id"), nullable=False)
|
store_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("stores.id"), nullable=False)
|
||||||
store_location_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("store_locations.id"))
|
store_location_id: Mapped[uuid.UUID | None] = mapped_column(ForeignKey("store_locations.id"))
|
||||||
receipt_id: Mapped[str] = mapped_column(String(200), nullable=False)
|
receipt_id: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||||
|
|||||||
@@ -15,11 +15,12 @@ if TYPE_CHECKING:
|
|||||||
from cartsnitch_common.models.store import Store
|
from cartsnitch_common.models.store import Store
|
||||||
|
|
||||||
|
|
||||||
class User(UUIDPrimaryKeyMixin, TimestampMixin, Base):
|
class User(TimestampMixin, Base):
|
||||||
"""Application user."""
|
"""Application user."""
|
||||||
|
|
||||||
__tablename__ = "users"
|
__tablename__ = "users"
|
||||||
|
|
||||||
|
id: Mapped[str] = mapped_column(Text, primary_key=True)
|
||||||
email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
|
email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
|
||||||
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||||
display_name: Mapped[str | None] = mapped_column(String(100))
|
display_name: Mapped[str | None] = mapped_column(String(100))
|
||||||
@@ -37,7 +38,7 @@ class UserStoreAccount(UUIDPrimaryKeyMixin, TimestampMixin, Base):
|
|||||||
__tablename__ = "user_store_accounts"
|
__tablename__ = "user_store_accounts"
|
||||||
__table_args__ = (UniqueConstraint("user_id", "store_id", name="uq_user_store_account"),)
|
__table_args__ = (UniqueConstraint("user_id", "store_id", name="uq_user_store_account"),)
|
||||||
|
|
||||||
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("users.id"), nullable=False)
|
user_id: Mapped[str] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||||
store_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("stores.id"), nullable=False)
|
store_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("stores.id"), nullable=False)
|
||||||
# WARNING: Contains retailer session cookies/tokens. Encryption-at-rest
|
# WARNING: Contains retailer session cookies/tokens. Encryption-at-rest
|
||||||
# required before production deployment (e.g., pgcrypto or app-level encryption).
|
# required before production deployment (e.g., pgcrypto or app-level encryption).
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class PurchaseItemRead(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class PurchaseCreate(BaseModel):
|
class PurchaseCreate(BaseModel):
|
||||||
user_id: uuid.UUID
|
user_id: str
|
||||||
store_id: uuid.UUID
|
store_id: uuid.UUID
|
||||||
store_location_id: uuid.UUID | None = None
|
store_location_id: uuid.UUID | None = None
|
||||||
receipt_id: str
|
receipt_id: str
|
||||||
@@ -58,7 +58,7 @@ class PurchaseRead(BaseModel):
|
|||||||
model_config = {"from_attributes": True}
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
id: uuid.UUID
|
id: uuid.UUID
|
||||||
user_id: uuid.UUID
|
user_id: str
|
||||||
store_id: uuid.UUID
|
store_id: uuid.UUID
|
||||||
store_location_id: uuid.UUID | None
|
store_location_id: uuid.UUID | None
|
||||||
receipt_id: str
|
receipt_id: str
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class UserCreate(BaseModel):
|
|||||||
class UserRead(BaseModel):
|
class UserRead(BaseModel):
|
||||||
model_config = {"from_attributes": True}
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
id: uuid.UUID
|
id: str
|
||||||
email: str
|
email: str
|
||||||
display_name: str | None
|
display_name: str | None
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
@@ -25,7 +25,7 @@ class UserRead(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class UserStoreAccountCreate(BaseModel):
|
class UserStoreAccountCreate(BaseModel):
|
||||||
user_id: uuid.UUID
|
user_id: str
|
||||||
store_id: uuid.UUID
|
store_id: uuid.UUID
|
||||||
session_data: dict | None = None
|
session_data: dict | None = None
|
||||||
status: AccountStatus = AccountStatus.ACTIVE
|
status: AccountStatus = AccountStatus.ACTIVE
|
||||||
@@ -35,7 +35,7 @@ class UserStoreAccountRead(BaseModel):
|
|||||||
model_config = {"from_attributes": True}
|
model_config = {"from_attributes": True}
|
||||||
|
|
||||||
id: uuid.UUID
|
id: uuid.UUID
|
||||||
user_id: uuid.UUID
|
user_id: str
|
||||||
store_id: uuid.UUID
|
store_id: uuid.UUID
|
||||||
status: AccountStatus
|
status: AccountStatus
|
||||||
session_expires_at: datetime | None
|
session_expires_at: datetime | None
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import bcrypt
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
@@ -184,6 +186,65 @@ def run_seed(
|
|||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
_seed_uat_user(session)
|
||||||
|
|
||||||
elapsed = time.monotonic() - t0
|
elapsed = time.monotonic() - t0
|
||||||
_log("")
|
_log("")
|
||||||
_log(f"Seed complete in {elapsed:.1f}s")
|
_log(f"Seed complete in {elapsed:.1f}s")
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# UAT seed user
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
UAT_EMAIL = "uat@cartsnitch.com"
|
||||||
|
UAT_PASSWORD = "CartSnitch-UAT-2026!"
|
||||||
|
UAT_DISPLAY_NAME = "UAT Tester"
|
||||||
|
UAT_USER_ID = uuid.UUID("00000000-0000-0000-0000-000000000001")
|
||||||
|
|
||||||
|
|
||||||
|
def _seed_uat_user(session: Session) -> None:
|
||||||
|
"""Insert or verify the dedicated UAT test user.
|
||||||
|
|
||||||
|
The user is created via Better-Auth's bcrypt hashing path so credentials
|
||||||
|
work against the live auth service. Idempotent — skips if the user already
|
||||||
|
exists.
|
||||||
|
"""
|
||||||
|
existing = session.execute(
|
||||||
|
text("SELECT id FROM users WHERE email = :email"),
|
||||||
|
{"email": UAT_EMAIL},
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
if existing is not None:
|
||||||
|
_log(f"UAT user {UAT_EMAIL} already exists — skipping")
|
||||||
|
return
|
||||||
|
|
||||||
|
password_hash = bcrypt.hashpw(UAT_PASSWORD.encode(), bcrypt.gensalt()).decode()
|
||||||
|
|
||||||
|
session.execute(
|
||||||
|
text(
|
||||||
|
"INSERT INTO users (id, email, hashed_password, display_name, email_verified, created_at, updated_at) "
|
||||||
|
"VALUES (:id, :email, :hashed_password, :display_name, true, now(), now())"
|
||||||
|
),
|
||||||
|
{
|
||||||
|
"id": str(UAT_USER_ID),
|
||||||
|
"email": UAT_EMAIL,
|
||||||
|
"hashed_password": password_hash,
|
||||||
|
"display_name": UAT_DISPLAY_NAME,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
session.execute(
|
||||||
|
text(
|
||||||
|
"INSERT INTO accounts (id, user_id, account_id, provider_id, password, created_at, updated_at) "
|
||||||
|
"VALUES (gen_random_uuid()::text, :user_id, :account_id, 'credential', :password, now(), now())"
|
||||||
|
),
|
||||||
|
{
|
||||||
|
"user_id": str(UAT_USER_ID),
|
||||||
|
"account_id": str(UAT_USER_ID),
|
||||||
|
"password": password_hash,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
session.commit()
|
||||||
|
_log(f"UAT user {UAT_EMAIL} created")
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"ci": {
|
||||||
|
"collect": {
|
||||||
|
"staticDistDir": "./dist",
|
||||||
|
"url": ["http://localhost:4173/"],
|
||||||
|
"numberOfRuns": 1
|
||||||
|
},
|
||||||
|
"assert": {
|
||||||
|
"preset": "lighthouse:no-pwa",
|
||||||
|
"assertions": {
|
||||||
|
"categories:performance": ["warn", { "minScore": 0.5 }],
|
||||||
|
"categories:accessibility": ["error", { "minScore": 0.7 }],
|
||||||
|
"categories:best-practices": ["warn", { "minScore": 0.8 }],
|
||||||
|
"categories:seo": ["warn", { "minScore": 0.7 }],
|
||||||
|
"errors-in-console": ["warn"],
|
||||||
|
"network-dependency-tree-insight": ["warn"],
|
||||||
|
"robots-txt": ["warn"],
|
||||||
|
"unused-javascript": ["warn"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"upload": {
|
||||||
|
"target": "temporary-public-storage"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
User-agent: *
|
||||||
|
Allow: /
|
||||||
|
|
||||||
|
Sitemap: https://cartsnitch.com/sitemap.xml
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createAuthClient } from "better-auth/react"
|
import { createAuthClient } from "better-auth/react"
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient({
|
||||||
baseURL: import.meta.env.VITE_AUTH_URL ?? "http://localhost:3001",
|
baseURL: import.meta.env.VITE_AUTH_URL || "",
|
||||||
basePath: "/auth",
|
basePath: "/auth",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user