# 📱 ArcOps Complete API & SDK Specification (`CLIENT_SKILLS.md`)

This guide is designed for **application developers and AI coding agents** building applications on top of ArcOps. It provides an **exhaustive, 100% verified reference for all official client libraries (TypeScript, Python, Go, Java)** and raw HTTP/REST/ConnectRPC protocol payloads.

---

## 🔑 1. Gateway Base URL & Headers

* **Gateway Base URL**: `http://localhost:8000`
* **ConnectRPC Base Path**: `http://localhost:8000/dbmux.v1.<Service>/<Method>`

### HTTP Authentication Headers
```http
Content-Type: application/json
Authorization: Bearer <JWT_TOKEN>
X-Anon-Key: arc_live_...
X-Service-Role-Key: arc_secret_...
```

---

## 📦 2. Package Manager Installation & Initialization (All 4 Languages)

### 1. ⚡ TypeScript / JavaScript (`@arcops-cloud/sdk`)
```bash
npm install @arcops-cloud/sdk
```

```typescript
import { createClient } from "@arcops-cloud/sdk";

export const arcops = createClient({
  gatewayUrl: "http://localhost:8000",
  apiKey: "arc_live_...",                    // Public Anon API Key
  authToken: "eyJhbGciOiJIUzI1...",          // User JWT Session Token
});
```

---

### 2. 🐍 Python (`arcops-cloud`)
```bash
pip install arcops-cloud
```

```python
from arcops import ArcOpsClient

arcops = ArcOpsClient(
    gateway_url="http://localhost:8000",
    api_key="arc_live_...",
    auth_token="eyJhbGciOiJIUzI1..."
)
```

---

### 3. 🐹 Go (`arcops/sdk/go`)
```bash
go get github.com/arcops/arcops/sdk/go
```

```go
package main

import (
	"context"
	"fmt"
	"github.com/arcops/arcops/sdk/go"
)

func main() {
	client := arcops.NewClient(arcops.Config{
		BaseURL: "http://localhost:8000",
		APIKey:  "arc_live_...",
	})

	ctx := context.Background()
	res, err := client.DB.Query(ctx, "SELECT * FROM users WHERE active = $1", true)
	if err != nil {
		panic(err)
	}
	fmt.Println(res)
}
```

---

### 4. ☕ Java (`io.arcops:arcops-sdk`)
```xml
<dependency>
    <groupId>io.arcops</groupId>
    <artifactId>arcops-sdk</artifactId>
    <version>1.0.0</version>
</dependency>
```

```java
import io.arcops.ArcOpsClient;

public class Main {
    public static void main(String[] args) throws Exception {
        ArcOpsClient arcops = new ArcOpsClient(
            "http://localhost:8000",
            "arc_live_...",
            "eyJhbGciOiJIUzI1...",
            null
        );

        String result = arcops.db.query("SELECT * FROM users WHERE active = true");
        System.out.println(result);
    }
}
```

---

## 🔑 3. ArcAuth Identity Module (`arcops.auth.*` & `/api/auth/*`)

| SDK Function Call | HTTP Verb & Endpoint | Raw Request JSON Payload | Raw Response JSON Payload |
|:---|:---|:---|:---|
| `signup({ email, password, fullName })` | `POST /api/auth/register` | `{"email":"u@ex.com","password":"pass","full_name":"John"}` | `{"message":"Registered","token":"jwt...","user":{...}}` |
| `login({ email, password })` | `POST /api/auth/login` | `{"email":"u@ex.com","password":"pass"}` | `{"message":"Logged in","token":"jwt...","user":{...}}` |
| `me()` | `GET /api/auth/me` | *(None)* | `{"user":{"id":"usr_1","email":"u@ex.com"}}` |
| `logout()` | `POST /api/auth/logout` | `{}` | `{"message":"Logged out"}` |
| `sendOTP({ recipient })` | `POST /api/auth/otp/send` | `{"recipient":"+1234567890"}` | `{"message":"OTP sent"}` |
| `verifyOTP({ recipient, code })` | `POST /api/auth/otp/verify` | `{"recipient":"+1234567890","code":"123456"}` | `{"token":"jwt...","user":{...}}` |
| `sendMagicLink({ email })` | `POST /api/auth/magic-link/send` | `{"email":"u@ex.com"}` | `{"message":"Magic link sent"}` |
| `verifyMagicLink({ token })` | `POST /api/auth/magic-link/verify` | `{"token":"magic_123"}` | `{"token":"jwt...","user":{...}}` |
| `getOAuthURL(provider)` | `GET /api/auth/oauth/{provider}`| *(None)* | Redirects to Provider |
| `createAPIKey({ name })` | `POST /api/auth/api-keys` | `{"name":"Frontend Key"}` | `{"id":"key_1","raw_key":"arc_live_..."}` |
| `listAPIKeys()` | `GET /api/auth/api-keys` | *(None)* | `{"api_keys":[{"id":"key_1","name":"Key"}]}` |
| `revokeAPIKey(keyId)` | `DELETE /api/auth/api-keys/{id}` | *(None)* | `{"message":"Key revoked"}` |
| `getQuotas()` | `GET /api/auth/tenant/quotas` | *(None)* | `{"db_mode":"isolated","db_quota_mb":500}` |
| `updateQuotas({ mode, pgQuotaMB, mongoQuotaMB })` | `POST /api/auth/tenant/update-quotas` | `{"db_mode":"isolated","db_quota_mb":500}` | `{"message":"Quotas updated"}` |

---

## 🗄️ 4. DBMux Multistore Data Engines (`arcops.db.*` & `/dbmux.v1.*`)

| SDK Function Call | ConnectRPC Path | Method | Raw Request JSON Payload | Raw Response JSON Payload |
|:---|:---|:---|:---|:---|
| `query(sql, params)` | `/dbmux.v1.Postgres/Query` | `POST` | `{"sql":"SELECT * FROM users WHERE active = $1","params":[true]}` | `{"rows":[{"id":1,"name":"Alice"}]}` |
| `exec(sql, params)` | `/dbmux.v1.Postgres/Exec` | `POST` | `{"sql":"UPDATE users SET active = $1","params":[false]}` | `{"rows_affected":1}` |
| `mysql.query(sql, params)` | `/dbmux.v1.MySQL/Query` | `POST` | `{"sql":"SELECT * FROM orders WHERE status = ?","params":["shipped"]}` | `{"rows":[{"id":10}]}` |
| `mysql.exec(sql, params)` | `/dbmux.v1.MySQL/Exec` | `POST` | `{"sql":"DELETE FROM cart WHERE id = ?","params":[10]}` | `{"rows_affected":1}` |
| `sqlite.query(sql, params)` | `/dbmux.v1.SQLite/Query` | `POST` | `{"sql":"SELECT * FROM cache WHERE key = ?","params":["k1"]}`| `{"rows":[{"key":"k1"}]}` |
| `sqlite.exec(sql, params)` | `/dbmux.v1.SQLite/Exec` | `POST` | `{"sql":"INSERT INTO cache VALUES (?,?)","params":["k1","v1"]}`| `{"rows_affected":1}` |
| `mongo.find(collection, filter)` | `/dbmux.v1.Mongo/Find` | `POST` | `{"collection":"logs","filter":{"level":"error"}}` | `{"documents":[{"_id":"1"}]}` |
| `mongo.insert(collection, document)` | `/dbmux.v1.Mongo/Insert` | `POST` | `{"collection":"logs","document":{"level":"info"}}` | `{"inserted_id":"1"}` |
| `mongo.update(collection, filter, update)` | `/dbmux.v1.Mongo/Update` | `POST` | `{"collection":"logs","filter":{},"update":{"$set":{"read":true}}}` | `{"matched":1,"modified":1}` |
| `mongo.delete(collection, filter)` | `/dbmux.v1.Mongo/Delete` | `POST` | `{"collection":"logs","filter":{"read":true}}` | `{"deleted_count":1}` |
| `mongo.count(collection, filter)` | `/dbmux.v1.Mongo/Count` | `POST` | `{"collection":"logs","filter":{}}` | `{"count":42}` |
| `vector.search(collection, vector, limit)` | `/dbmux.v1.Vector/Search` | `POST` | `{"collection":"docs","vector":[0.1,0.2],"limit":5}` | `{"results":[{"id":"d1","score":0.98}]}` |
| `vector.upsert(collection, id, vector, metadata)` | `/dbmux.v1.Vector/Upsert` | `POST` | `{"collection":"docs","id":"d1","vector":[0.1,0.2],"metadata":{}}` | `{"status":"upserted"}` |

---

## ⚡ 5. KV, State, Queue, PubSub, Secrets & Cron (`arcops.kv.*`, etc.)

| SDK Function Call | ConnectRPC Path | Method | Raw Request JSON Payload | Raw Response JSON Payload |
|:---|:---|:---|:---|:---|
| `kv.set(key, value, ttlSeconds)` | `/dbmux.v1.KV/Set` | `POST` | `{"key":"theme","value":"dark","ttl_seconds":3600}` | `{"status":"ok"}` |
| `kv.get(key)` | `/dbmux.v1.KV/Get` | `POST` | `{"key":"theme"}` | `{"key":"theme","value":"dark"}` |
| `kv.delete(key)` | `/dbmux.v1.KV/Delete` | `POST` | `{"key":"theme"}` | `{"status":"deleted"}` |
| `state.save(key, value, ttlSeconds)` | `/dbmux.v1.State/SaveState` | `POST` | `{"key":"s1","value":{"step":2}}` | `{"status":"ok"}` |
| `state.get(key)` | `/dbmux.v1.State/GetState` | `POST` | `{"key":"s1"}` | `{"key":"s1","value":{"step":2}}` |
| `state.delete(key)` | `/dbmux.v1.State/DeleteState` | `POST` | `{"key":"s1"}` | `{"status":"deleted"}` |
| `queue.enqueue(queueName, payload)` | `/dbmux.v1.Queue/Enqueue` | `POST` | `{"queue_name":"pdf","payload":"{}"}` | `{"message_id":"msg_1"}` |
| `queue.dequeue(queueName)` | `/dbmux.v1.Queue/Dequeue` | `POST` | `{"queue_name":"pdf"}` | `{"message_id":"msg_1","payload":"{}"}` |
| `pubsub.publish(channel, payload)` | `/dbmux.v1.PubSub/Publish` | `POST` | `{"channel":"events","payload":"{}"}` | `{"receivers":3}` |
| `secret.getSecret(key)` | `/dbmux.v1.Secret/GetSecret` | `POST` | `{"key":"STRIPE_KEY"}` | `{"key":"STRIPE_KEY","value":"sk_123"}` |
| `secret.getBulkSecrets()` | `/dbmux.v1.Secret/GetBulkSecrets` | `POST` | `{}` | `{"secrets":{"STRIPE_KEY":"sk_123"}}` |
| `cron.registerCron(cronName, cronExpr, payload)` | `/dbmux.v1.Cron/RegisterCron` | `POST` | `{"cron_name":"c1","cron_expr":"0 0 * * *","payload":"{}"}` | `{"cron_id":"c1"}` |

---

## 📦 6. BuckStream Storage Module (`arcops.storage.*` & `/api/storage/*`)

### 🎯 Automatic Smart Upload & Download Engine

The client SDK method `arcops.storage.upload(fileKey, file)` automatically calculates file size from the passed `File`, `Blob`, `Buffer`, or `string`, sends intent to `POST /api/storage/intent`, and dynamically executes the optimal transfer mode:
* **Files $\le$ 5MB**: Uploads via **Broker Proxy Stream** (`POST /api/upload/proxy?key=...`).
* **Files $>$ 5MB**: Uploads via direct **Presigned S3/GCS PUT URL**.

| SDK Function Call | HTTP Verb & Endpoint | Raw Request JSON Payload | Raw Response JSON Payload |
|:---|:---|:---|:---|
| `upload(fileKey, file)` | `POST /api/storage/intent` & `/api/upload/proxy` | `{"filename":"avatar.png","size":1024}` | `{"status":"uploaded","key":"uploads/avatar.png"}` |
| `download(fileKey)` | `GET /api/storage/download/{key}` | *(None)* | Binary Stream ($\le$ 5MB) or HTTP 302 Redirect ($>$ 5MB) |
| `list(prefix)` | `GET /api/storage/list?prefix=...` | *(None)* | `{"files":[{"key":"file1.png","size":1024}]}` |
| `delete(fileKey)` | `DELETE /api/storage/delete/{key}` | *(None)* | `{"message":"File deleted"}` |

---

## 🛠️ 7. Frontedge CI/CD Build Engine (`arcops.deploy.*` & `/api/frontedge/*`)

| SDK Function Call | HTTP Verb & Endpoint | Raw Request JSON Payload | Raw Response JSON Payload |
|:---|:---|:---|:---|
| `listProjects()` | `GET /api/frontedge/projects` | *(None)* | `{"projects":[{"id":"prj_1","name":"App"}]}` |
| `createProject({ name, repositoryUrl, framework })` | `POST /api/frontedge/projects` | `{"name":"App","repository_url":"https://...","framework":"nextjs"}` | `{"id":"prj_1","name":"App"}` |
| `getProject(projectId)` | `GET /api/frontedge/projects/{id}` | *(None)* | `{"id":"prj_1","name":"App"}` |
| `deleteProject(projectId)` | `DELETE /api/frontedge/projects/{id}` | *(None)* | `{"message":"Project deleted"}` |
| `triggerBuild({ projectId, branch })` | `POST /api/frontedge/builds` | `{"project_id":"prj_1","branch":"main"}` | `{"id":"bld_1","status":"queued"}` |
| `listBuilds(projectId)` | `GET /api/frontedge/builds/{projectId}` | *(None)* | `{"builds":[{"id":"bld_1","status":"success"}]}` |
| `getBuildLogs(buildId)` | `GET /api/frontedge/builds/logs/{buildId}` | *(None)* | `{"logs":"[BUILD] Compiling..."}` |
