diff --git a/.github/workflows/cleanup-report.yml b/.github/workflows/cleanup-report.yml index e3e7daf1f9e..b7866097d0c 100644 --- a/.github/workflows/cleanup-report.yml +++ b/.github/workflows/cleanup-report.yml @@ -9,6 +9,7 @@ permissions: pull-requests: write jobs: cleanup-report: + if: github.repository == 'calcom/cal.diy' runs-on: ubuntu-latest steps: - name: Generate GitHub App token diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml index 6e7fd6140ee..6dd14c6f986 100644 --- a/.github/workflows/cleanup.yml +++ b/.github/workflows/cleanup.yml @@ -17,6 +17,7 @@ concurrency: jobs: delete_reports: name: Delete Reports + if: github.repository == 'calcom/cal.diy' runs-on: ubuntu-latest env: # Contains all reports for deleted branch diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 8ac3f3cf24e..7a93f2f4fcd 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -14,6 +14,7 @@ permissions: jobs: draft_release: + if: github.repository == 'calcom/cal.diy' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/i18n.yml b/.github/workflows/i18n.yml index b44abad56b6..41627798637 100644 --- a/.github/workflows/i18n.yml +++ b/.github/workflows/i18n.yml @@ -10,7 +10,7 @@ concurrency: jobs: i18n: name: Run i18n - if: ${{ secrets.CI_LINGO_DOT_DEV_API_KEY != '' }} + if: ${{ github.repository == 'calcom/cal.diy' && secrets.CI_LINGO_DOT_DEV_API_KEY != '' }} runs-on: ubuntu-latest permissions: actions: write diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml index ddcef9f5ce8..d444b834bea 100644 --- a/.github/workflows/post-release.yml +++ b/.github/workflows/post-release.yml @@ -11,6 +11,7 @@ permissions: jobs: release: + if: github.repository == 'calcom/cal.diy' runs-on: ubuntu-latest steps: - name: Generate GitHub App token diff --git a/.github/workflows/release-docker.yaml b/.github/workflows/release-docker.yaml index e9012e3ebcb..debb358f30b 100644 --- a/.github/workflows/release-docker.yaml +++ b/.github/workflows/release-docker.yaml @@ -32,6 +32,7 @@ on: jobs: prepare: name: "Prepare Release" + if: github.repository == 'calcom/cal.diy' runs-on: ubuntu-latest outputs: release_tag: ${{ steps.determine-tag.outputs.release_tag }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000000..218bbedac4d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,30 @@ +# Changelog — Crove Cal + +All notable changes to the **Crove Cal** platform will be documented in this file. + +--- + +## [2.0.0] - 2026-08-26 + +### Added +- **2-Tier Hybrid Architecture Adoption**: Implemented standard Crove OS 2-tier architecture combining Database/Webhook sync (Tier 1) and MCP protocol for AI agentic actions (Tier 2). +- **DOS.Me ID Centralized Authentication (OIDC / OAuth 2.1)**: + - Native integration with Supabase OAuth 2.1 + PKCE server. + - Configured `ES256` token signature algorithm for Supabase Auth JWT compatibility. + - Implemented `allowDangerousEmailAccountLinking` and dynamic runtime provider evaluation. +- **Two-Way Organization Synchronization (Hybrid Sync)**: + - Inbound JIT (Just-In-Time) organization & profile sync on OIDC login (`syncDosOrganizations`). + - Real-time webhook listener at `/api/webhooks/dos-org-sync` with HMAC-SHA256 signature verification supporting `organization.*` and `org.*` event conventions. +- **Automated Branding Pipeline**: + - Standardized environment variables: `NEXT_PUBLIC_APP_NAME`, `NEXT_PUBLIC_COMPANY_NAME`, `NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS`. + - Added automated localization patching script `yarn patch:branding` (`scripts/patch-crove-branding.ts`). + - Added comprehensive architecture specification at `docs/Architecture.md`. + +### Fixed +- Fixed NextAuth OIDC discovery and token exchange by properly registering `wellKnown` and PKCE checks. +- Fixed root route rewrite collision by scoping routing configurations. +- Guarded upstream-only CI workflows against failing on fork repository. + +### Optimized +- Optimized Docker container startup by pre-baking production URL `https://cal.crove.com`, eliminating cold start string replacement overhead. +- Automated Docker image build and push to GHCR (`ghcr.io/dos/crove-cal:latest`). diff --git a/docs/Architecture.md b/docs/Architecture.md new file mode 100644 index 00000000000..b0eeb687bfc --- /dev/null +++ b/docs/Architecture.md @@ -0,0 +1,119 @@ +# Crove Cal — Architecture & Ecosystem Integration Guide + +**Phiên bản:** 2.0.0 +**Cập nhật lần cuối:** 2026-08-26 +**Chủ quản:** Crove OS & DOS.Me Ecosystem + +--- + +## I. Tổng quan Kiến trúc (Architectural Overview) + +**Crove Cal** là nền tảng đặt lịch hẹn & quản lý lịch thông minh thế hệ mới (fork từ Cal.com / Cal.diy `v6.2.0`), được tối ưu hóa và tích hợp sâu vào hệ điều hành doanh nghiệp **Crove OS** và hệ thống định danh tập trung **DOS ID** (`id.dos.me` / `api.dos.me`). + +Căn cứ theo quy chuẩn kiến trúc toàn hệ sinh thái, Crove Cal tuân thủ mô hình **Kiến trúc Lai 2 Tầng (2-Tier Hybrid Architecture)** kết hợp giữa đồng bộ dữ liệu cốt lõi (Database / Webhook Sync) và giao thức điều khiển nghiệp vụ sâu qua AI Agent (**Model Context Protocol - MCP**). + +--- + +## II. Chuẩn Kiến trúc Đồng bộ 2 Tầng (2-Tier Hybrid Architecture) + +``` +┌─────────────────────────────────────────────────────────────────────────────────────────┐ +│ CROVE OS 2-TIER HYBRID ARCHITECTURE │ +├──────────────────────────────────────────┬──────────────────────────────────────────────┤ +│ TẦNG 1: Đồng bộ Dữ liệu Danh tính & Tổ chức│ TẦNG 2: Deep Agentic Business Actions │ +│ (Organizations, Memberships, Contacts) │ (Lên lịch, Tạo Booking, Tra cứu Rảnh/Bận) │ +├──────────────────────────────────────────┼──────────────────────────────────────────────┤ +│ DATABASE & WEBHOOK SYNC │ MCP PROTOCOL │ +│ (Local Mirror & Realtime Events) │ (Model Context Protocol Tool Calling) │ +│ │ │ │ │ +│ • DOS-Me (api.dos.me): Master SSOT │ • crove_cal.get_available_slots(...) │ +│ • Schema Isolation: cal.users, cal.Team │ • crove_cal.create_booking(...) │ +│ • Inbound JIT OIDC Sync │ • crove_cal.reschedule_booking(...) │ +│ • Bi-directional Webhook Dispatch │ • twenty_crm, crove_sign, crove_desk tools │ +└──────────────────────────────────────────┴──────────────────────────────────────────────┘ +``` + +### 1. Tầng 1: Đồng bộ Dữ liệu Danh tính & Tổ chức (Identity & Organization Sync) + +Tầng 1 đảm bảo dữ liệu danh tính người dùng và cấu trúc tổ chức luôn nhất quán trên toàn hệ sinh thái mà không phụ thuộc vào độ trễ mạng: + +1. **Single Source of Truth (SSOT)**: + - Hệ thống trung tâm `api.dos.me` và bảng `public.organizations`, `public.org_members` trên Supabase là nơi lưu trữ gốc duy nhất cho danh tính và tổ chức. +2. **Cách ly Dữ liệu (Schema Isolation)**: + - Cơ sở dữ liệu của Crove Cal hoạt động độc lập trên schema `cal` với role chuyên dụng `cal_app`, bảo vệ an toàn toàn vẹn dữ liệu. +3. **Đồng bộ Tức thời khi Đăng nhập (Inbound JIT Sync)**: + - Khi người dùng đăng nhập qua DOS ID (OIDC / OAuth 2.1), hàm `syncDosOrganizations` đọc mảng claims `organizations` trong JWT token / UserInfo: + ```json + { + "sub": "48fc3631-ec8c-4e78-aa98-ec89c1c3624d", + "email": "joy@dos.ai", + "name": "JOY", + "active_org_id": "acbb5565-bdbb-43f9-a658-2bc8a326c85f", + "organizations": [ + { + "id": "acbb5565-bdbb-43f9-a658-2bc8a326c85f", + "name": "JOY", + "slug": "joy", + "role": "OWNER" + } + ] + } + ``` + - Tự động tạo / cập nhật `cal.Team` (với `isOrganization = true` và `metadata.dosOrgId`), bản ghi `cal.Membership`, và `cal.Profile`. +4. **Đồng bộ Thời gian thực qua Webhook (Event-Driven Webhook Sync)**: + - Endpoint: `/api/webhooks/dos-org-sync` tiếp nhận các sự kiện được ký HMAC-SHA256: + - `organization.created` / `org.created` + - `organization.updated` / `org.updated` + - `organization.deleted` / `org.deleted` + - `organization.member_added` / `org.member_added` + - `organization.member_removed` / `org.member_removed` + - `user.updated` +5. **Tạo Tổ chức Chiều đi (Outbound Creation Protocol)**: + - Khi tạo tổ chức mới từ giao diện Crove Cal, backend gọi trực tiếp `POST https://api.dos.me/organizations` kèm `Authorization: Bearer `. Không tự sinh UUID local ngẫu nhiên. + +--- + +### 2. Tầng 2: Deep Agentic Business Actions (Giao thức MCP cho AI Agent) + +Khi AI Agent (như Crove Desk AI, DOSClaw, DOS AI) cần thực hiện các tác vụ nghiệp vụ có side-effect hoặc tra cứu phức tạp, hệ thống sử dụng **Model Context Protocol (MCP)**: + +| MCP Tool Name | Mục đích | +|---|---| +| `crove_cal.get_available_slots` | Tra cứu các khung giờ rảnh khả dụng của người dùng hoặc nhóm | +| `crove_cal.create_booking` | Tự động đặt lịch hẹn mới từ hội thoại hoặc ticket hỗ trợ | +| `crove_cal.reschedule_booking` | Đổi lịch hẹn theo yêu cầu của khách hàng | +| `crove_cal.cancel_booking` | Hủy lịch hẹn và giải phóng slot | +| `twenty_crm.*` | Tương tác dữ liệu CRM (khách hàng, cơ hội, nhiệm vụ) | +| `crove_sign.*` | Tra cứu và gửi hợp đồng điện tử | + +--- + +## III. Xác thực Tập trung (OIDC / OAuth 2.1 via DOS ID) + +Crove Cal kết nối trực tiếp với OIDC Server chuẩn của DOS ID: + +- **Issuer URL**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1` +- **Discovery Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/.well-known/openid-configuration` +- **Authorization Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/oauth/authorize` +- **Token Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/oauth/token` +- **UserInfo Endpoint**: `https://gulptwduchsjcsbndmua.supabase.co/auth/v1/oauth/userinfo` +- **Client ID**: `18790ccb-4d71-48cd-ad24-aee5f3ced3da` +- **Client Secret**: Quản lý an toàn qua GCP Secret Manager (`CROVE_OAUTH_CLIENT_SECRET`) +- **PKCE**: Bắt buộc (`checks: ["pkce", "state"]`) +- **JWT Signature Algorithm**: `ES256` + +--- + +## IV. Quy chuẩn Nhận diện Thương hiệu & Fork Maintenance + +Để đảm bảo khả năng merge và đồng bộ mượt mà với phiên bản gốc (`upstream/main` của Cal.com): + +1. **Configuration Over Code**: + - Tất cả thông tin nhận diện được cấu hình qua biến môi trường: + - `NEXT_PUBLIC_APP_NAME="Crove"` + - `NEXT_PUBLIC_COMPANY_NAME="MetaDOS LLC"` + - `NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS="help@crove.com"` +2. **Kịch bản Patch Branding Tự động**: + - Chạy lệnh `yarn patch:branding` (`scripts/patch-crove-branding.ts`) để tự động cập nhật localization catalogs khi sync code mới từ upstream. +3. **Root URL Optimization**: + - Trực tiếp bake URL sản xuất `https://cal.crove.com` vào Dockerfile để loại bỏ quét sed khi khởi động container, đảm bảo thời gian khởi động tức thì (<2 giây).