Skip to main content
Internal reference — not the public API

This documents NearSync's internal action-dispatch surface, used by the apps themselves and by tenant automations. It is not the public API and carries no stability guarantee — actions may change or be removed without notice. For the supported, versioned public API see API Reference.

API Gateway Migration

The NearSync API Gateway is a typed, authenticated HTTP layer built on top of the hyper-worker edge function. It provides a single entry point for all platform write operations, replacing direct Supabase client calls with structured API actions routed through a central gateway.

Why the gateway exists

Direct Supabase calls from the frontend work but have limitations for enterprise deployment:

  • No centralized audit trail for write operations
  • No server-side business logic enforcement
  • No rate limiting on write operations
  • Tight coupling between UI code and database schema

The gateway solves all four. It also creates an auditable, rate-limited API surface that BYOK clients can integrate against, and decouples the frontend from direct database access - a prerequisite for the future public API and MCP server.

Architecture

All requests flow through the hyper-worker edge function:

Client -> @nearsync/api-client -> POST /functions/v1/hyper-worker -> JWT auth -> rate limiter -> service router -> response

The api-client package handles authentication headers, error parsing, streaming responses, and retry logic.

Dual-path migration pattern

The gateway is deployed using a dual-path pattern: each module's write operations check a feature flag before choosing between direct Supabase access (legacy) and the API gateway (new). This allows incremental migration with instant rollback.

const useGateway = manifest.features?.api_gateway_finance === true;

if (useGateway) {
await api.call("finance-create-invoice", payload);
} else {
await supabase.from("finance_invoices").insert(payload);
}

Read operations remain on direct Supabase - the gateway handles writes only. Reads through Supabase use RLS for row-level security, which is already battle-tested.

Feature flags by module

Feature FlagModuleEndpoints Gated
api_gateway_financeFinance HQ14 endpoints: invoice CRUD, expense CRUD + approve/reject, subscription CRUD, approval chains
api_gateway_hrmsPeople / HRMS14 endpoints: employee onboard/update, leave submit/approve/reject, payroll process/approve, KPI, SLA, commission
api_gateway_engEngineering9 endpoints: issue create, sprint lifecycle, epic CRUD, meeting CRUD
api_gateway_crmCRM / Sales2 endpoints: deal stage move, task create (+ automation triggers)
api_gateway_marketingMarketing8 endpoints: campaign/asset/brief/note save and delete
api_gateway_supportSupport4 endpoints: ticket create/move/close/delete
api_gateway_websiteWebsite / CMS8 endpoints: article/category/page CRUD
api_gateway_opsOperations1+ endpoints: procedure create, sentinel operations

All flags default to false (direct Supabase). Set to true in the SystemManifest to enable gateway routing.

Gateway endpoint reference

Finance endpoints (14)

ActionDescription
finance-create-invoiceCreate a draft invoice. Auto-generates invoice number.
finance-update-invoiceUpdate invoice fields. Triggers status recalculation.
finance-delete-invoiceSoft-delete an invoice.
finance-create-company-expenseLog a company expense.
finance-create-employee-expenseSubmit an employee expense claim.
finance-approve-expenseApprove an expense (requires approver role).
finance-reject-expenseReject an expense with reason.
finance-mark-expense-paidMark expense as paid/reimbursed.
finance-create-subscriptionCreate a recurring subscription.
finance-update-subscriptionUpdate subscription fields.
finance-cancel-subscriptionCancel a subscription.
finance-approve-expense-approvalApprove in the expense approval chain.
finance-reject-expense-approvalReject in the expense approval chain.
finance-approve-payroll-approvalApprove a payroll run.

People / HRMS endpoints (14)

ActionDescription
hrms-onboard-employeeOnboard a new employee.
hrms-update-employeeUpdate employee record.
hrms-link-system-userLink an employee to a system user account.
hrms-submit-leaveSubmit a leave request.
hrms-approve-leaveApprove a leave request.
hrms-reject-leaveReject a leave request.
hrms-create-leave-policyCreate a leave policy.
hrms-process-payrollProcess a payroll run for a period.
hrms-approve-payrollApprove a processed payroll run.
hrms-process-final-settlementCalculate final settlement for departing employee.
hrms-submit-kpi-scoreSubmit a KPI performance score.
hrms-log-sla-metricLog an SLA compliance metric.
hrms-update-commissionUpdate commission settings.
hrms-approve-change-requestApprove an employee change request.

Engineering endpoints (9)

ActionDescription
eng-create-issueCreate a new issue/ticket.
eng-create-sprintCreate a sprint.
eng-start-sprintStart a sprint (moves to active).
eng-complete-sprintComplete a sprint (unfinished issues move to backlog).
eng-reopen-sprintReopen a completed sprint.
eng-create-epicCreate an epic.
eng-update-epicUpdate epic fields.
eng-delete-epicDelete an epic.
eng-create-meetingCreate a meeting.

CRM / Sales endpoints (2)

ActionDescription
crm-move-deal-stageMove a deal to a different pipeline stage. Triggers governance rules and automations.
crm-create-taskCreate a task linked to a deal.

Marketing endpoints (8)

ActionDescription
marketing-save-campaignCreate or update a campaign.
marketing-delete-campaignDelete a campaign.
marketing-save-assetCreate or update a marketing asset.
marketing-delete-assetDelete an asset.
marketing-save-briefCreate or update a creative brief.
marketing-delete-briefDelete a brief.
marketing-save-noteCreate or update a note.
marketing-delete-noteDelete a note.

Support endpoints (4)

ActionDescription
support-create-ticketCreate a support ticket.
support-move-ticketMove ticket to a different stage.
support-close-ticketClose a ticket.
support-delete-ticketDelete a ticket.

Website / CMS endpoints (8)

ActionDescription
website-create-articleCreate a KB article.
website-update-articleUpdate article content.
website-delete-articleDelete an article.
website-create-categoryCreate a KB category.
website-delete-categoryDelete a category.
website-create-pageCreate a site page.
website-update-pageUpdate a page.
website-delete-pageDelete a page.

@nearsync/api-client package

The api-client package provides a typed wrapper for the hyper-worker edge function.

api.call()

Make a request to any hyper-worker endpoint:

import { api } from "@nearsync/api-client";

const result = await api.call<InvoiceResponse>("finance-create-invoice", {
client_name: "Acme Corp",
amount: 5000,
currency: "USD"
});

if (result.error) {
console.error(result.error.message);
} else {
console.log(result.data.id);
}

api.stream()

Stream an AI response:

for await (const chunk of api.stream("ai-chat", { prompt: "Summarize Q1" })) {
process.stdout.write(chunk);
}

api.configure()

Override the default base URL or token provider:

api.configure({
baseUrl: "https://your-supabase-project.supabase.co/functions/v1/hyper-worker",
getToken: async () => customJWT
});

BYOK clients: point baseUrl to your own Supabase project URL. The api-client works identically - the only difference is where the edge function runs.

Rollback

Rollback is instant: set the feature flag to false in the SystemManifest. The hook reverts to direct Supabase. No code deployment required.

Action string conventions

  • Gateway actions follow the pattern: <module>-<verb>-<entity> (e.g., finance-create-invoice, hrms-approve-leave, eng-start-sprint)
  • Legacy actions use shorter names (e.g., create-user, booking, ai-chat) and are not renamed for backward compatibility
  • Total registered actions: 86 (56 gateway + 30 legacy)