Skip to content

Commit 8627ea0

Browse files
authored
Merge pull request #17 from yepcode/feat/YEP-3134
YEP-3134 Update yepcode-run with new endpoints
2 parents 3274a99 + 124e42d commit 8627ea0

3 files changed

Lines changed: 157 additions & 6 deletions

File tree

CLAUDE.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
```bash
8+
# Build
9+
npm run build # Compile TypeScript to ./dist/
10+
11+
# Test
12+
npm test # Run all tests with coverage (requires .env file)
13+
npm run test:ci # Run tests for CI (no .env required)
14+
15+
# Run a single test file
16+
npx jest tests/run/yepcodeRun.test.ts
17+
18+
# Lint
19+
npm run lint # Check for lint errors
20+
npm run lint:fix # Auto-fix lint errors
21+
```
22+
23+
Tests require a `.env` file with `YEPCODE_*` credentials to run against the real API.
24+
25+
## Architecture
26+
27+
This is a zero-dependency TypeScript SDK for the YepCode Cloud API. It requires Node.js >= 18 (uses native `fetch`). Output is compiled CommonJS to `./dist/`.
28+
29+
### Public surface (`src/index.ts`)
30+
31+
Four exported classes:
32+
- **`YepCodeRun`** — Execute JavaScript/Python code in isolated YepCode sandboxes. Creates processes (deduplicated by SHA256 hash of code), executes them, and returns `Execution` instances.
33+
- **`YepCodeEnv`** — CRUD for team-level environment variables with auto-pagination.
34+
- **`YepCodeStorage`** — Upload/list/download/delete files (accepts `File`, `Blob`, or `Readable` streams).
35+
- **`YepCodeApi`** — Raw HTTP client exposing the full REST API (processes, executions, schedules, modules, sandboxes, service accounts).
36+
37+
### Key internals
38+
39+
**`src/api/yepcodeApi.ts`** — The core HTTP client (~820 lines). Handles:
40+
- Auth via API token, client credentials (OAuth), or direct access token
41+
- Auto-refresh of expired access tokens
42+
- All REST endpoints as typed methods
43+
44+
**`src/run/execution.ts`** — Wraps a running execution with adaptive polling:
45+
- 250ms × 4, then 500ms × 8, then 1000ms thereafter
46+
- Logs polled every 2s or on completion
47+
- Event callbacks: `onLog`, `onFinish`, `onError`
48+
49+
**`src/api/configManager.ts`** — Reads `YEPCODE_API_TOKEN`, `YEPCODE_CLIENT_ID`, `YEPCODE_CLIENT_SECRET`, `YEPCODE_TEAM_ID`, `YEPCODE_ACCESS_TOKEN`, `YEPCODE_API_HOST` from the environment.
50+
51+
**`src/utils/languageDetector.ts`** — Regex/scoring-based JS vs Python detection used when language is not specified explicitly.
52+
53+
## OpenAPI spec
54+
55+
The live spec is always available at:
56+
```
57+
https://cloud.yepcode.io/api/rest/public/api-docs
58+
```
59+
60+
Fetch it with `WebFetch` to audit which endpoints are missing from `src/api/yepcodeApi.ts` before adding new ones. New endpoints are deployed to that URL before this SDK is updated.

src/api/types.ts

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Readable } from "stream";
22

3+
export type ProgrammingLanguage = "JAVASCRIPT" | "PYTHON";
4+
35
export interface YepCodeApiConfig {
46
apiHost?: string;
57
timeout?: number;
@@ -15,7 +17,7 @@ export interface CreateProcessInput {
1517
slug?: string;
1618
description?: string;
1719
readme?: string;
18-
programmingLanguage?: "JAVASCRIPT" | "PYTHON";
20+
programmingLanguage?: ProgrammingLanguage;
1921
sourceCode?: string;
2022
parametersSchema?: string;
2123
webhook?: WebhookInput;
@@ -141,7 +143,7 @@ export interface Process {
141143
[key: string]: any;
142144
};
143145
};
144-
programmingLanguage?: "JAVASCRIPT" | "PYTHON";
146+
programmingLanguage?: ProgrammingLanguage;
145147
sourceCode?: string;
146148
webhook?: ProcessWebhook;
147149
settings?: ProcessSettings;
@@ -279,7 +281,7 @@ export interface WebhookInput {
279281

280282
export interface VersionedProcess {
281283
id: string;
282-
programmingLanguage: "JAVASCRIPT" | "PYTHON";
284+
programmingLanguage: ProgrammingLanguage;
283285
sourceCode: string;
284286
parametersSchema: string;
285287
readme: string;
@@ -330,7 +332,7 @@ export interface VersionedProcessAliasesPaginatedResult {
330332
export interface Module {
331333
id: string;
332334
name: string;
333-
programmingLanguage?: "JAVASCRIPT" | "PYTHON";
335+
programmingLanguage?: ProgrammingLanguage;
334336
sourceCode?: string;
335337
createdBy?: string;
336338
createdAt?: string;
@@ -340,7 +342,7 @@ export interface Module {
340342

341343
export interface CreateModuleInput {
342344
name: string;
343-
programmingLanguage?: "JAVASCRIPT" | "PYTHON";
345+
programmingLanguage?: ProgrammingLanguage;
344346
sourceCode?: string;
345347
script?: {
346348
programmingLanguage?: string;
@@ -367,7 +369,7 @@ export interface ModulesPaginatedResult {
367369

368370
export interface VersionedModule {
369371
id: string;
370-
programmingLanguage: "JAVASCRIPT" | "PYTHON";
372+
programmingLanguage: ProgrammingLanguage;
371373
sourceCode: string;
372374
comment?: string;
373375
createdBy?: string;
@@ -488,3 +490,54 @@ export interface ServiceAccountsListResult {
488490
total: number;
489491
data: ServiceAccount[];
490492
}
493+
494+
/**
495+
* Teams
496+
*/
497+
export interface ErrorHandlerConfig {
498+
processId?: string;
499+
tag?: string;
500+
}
501+
502+
export interface ErrorHandlerConfigInput {
503+
processId?: string;
504+
tag?: string;
505+
}
506+
507+
export interface Team {
508+
slug?: string;
509+
name?: string;
510+
zoneId?: string;
511+
parentTeamSlugs?: string[];
512+
paramsSchemaValidationEnabled?: boolean;
513+
errorHandlerConfig?: ErrorHandlerConfig | null;
514+
createdAt?: string;
515+
}
516+
517+
export interface UpdateTeamInput {
518+
name?: string;
519+
zoneId?: string;
520+
parentTeamSlugs?: string[] | null;
521+
paramsSchemaValidationEnabled?: boolean;
522+
errorHandlerConfig?: ErrorHandlerConfigInput | null;
523+
}
524+
525+
/**
526+
* Dependencies
527+
*/
528+
export interface ProgrammingLanguageManifestInstallation {
529+
status?: "PENDING" | "INSTALLING" | "INSTALLED" | "FAILED";
530+
error?: string;
531+
dependencies?: { [name: string]: string };
532+
}
533+
534+
export interface ProgrammingLanguageManifest {
535+
id?: string;
536+
programmingLanguage?: ProgrammingLanguage;
537+
dependencies?: { [name: string]: string };
538+
nextInstallation?: ProgrammingLanguageManifestInstallation;
539+
}
540+
541+
export interface UpdateTeamDependenciesInput {
542+
dependencies?: { [name: string]: string };
543+
}

src/api/yepcodeApi.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ import {
4141
Sandbox,
4242
CreateSandboxInput,
4343
UpdateSandboxInput,
44+
Team,
45+
UpdateTeamInput,
46+
ProgrammingLanguage,
47+
ProgrammingLanguageManifest,
48+
UpdateTeamDependenciesInput,
4449
} from "./types";
4550
import { Readable } from "stream";
4651

@@ -816,4 +821,37 @@ export class YepCodeApi {
816821
async deleteServiceAccount(id: string): Promise<void> {
817822
return this.request("DELETE", `/auth/service-accounts/${id}`);
818823
}
824+
825+
// Team endpoints
826+
async getTeam(): Promise<Team> {
827+
return this.request("GET", "/team");
828+
}
829+
830+
async updateTeam(data: UpdateTeamInput): Promise<Team> {
831+
return this.request("PATCH", "/team", { data });
832+
}
833+
834+
// Dependencies endpoints
835+
async getTeamDependencies(
836+
language: ProgrammingLanguage
837+
): Promise<ProgrammingLanguageManifest> {
838+
return this.request("GET", `/dependencies/${language}`);
839+
}
840+
841+
async updateTeamDependencies(
842+
language: ProgrammingLanguage,
843+
data: UpdateTeamDependenciesInput
844+
): Promise<ProgrammingLanguageManifest> {
845+
return this.request("PUT", `/dependencies/${language}`, { data });
846+
}
847+
848+
async installTeamDependencies(language: ProgrammingLanguage): Promise<void> {
849+
return this.request("POST", `/dependencies/${language}/install`);
850+
}
851+
852+
async discardTeamDependenciesInstallation(
853+
language: ProgrammingLanguage
854+
): Promise<ProgrammingLanguageManifest> {
855+
return this.request("DELETE", `/dependencies/${language}/install`);
856+
}
819857
}

0 commit comments

Comments
 (0)