Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/clients.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Clients (CLI + VSCode)

# Compile/test gate for the TypeScript packages under cli/. This exists so a broken
# build (like the extension being uncompilable for months) is caught on every PR.

on:
push:
branches: [ main ]
paths:
- 'cli/**'
- '.github/workflows/clients.yaml'
pull_request:
branches: [ main ]
paths:
- 'cli/**'
- '.github/workflows/clients.yaml'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
shared:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Build @flapi/shared
working-directory: cli/shared
run: |
npm ci
npm run build

cli:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Build & test flapii CLI
working-directory: cli
run: |
npm ci
npm run build
npm test

vscode-extension:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Build, typecheck & test the VSCode extension
working-directory: cli/vscode-extension
run: |
npm ci
npm run typecheck
npm run build
npm test
6 changes: 3 additions & 3 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flapii",
"version": "0.1.0",
"version": "26.6.13",
"description": "CLI client for flapi ConfigService",
"license": "MIT",
"type": "module",
Expand Down
7 changes: 2 additions & 5 deletions cli/shared/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flapi/shared",
"version": "0.1.0",
"version": "26.6.13",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
46 changes: 44 additions & 2 deletions cli/shared/src/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import type { AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios';
import { pathToSlug, slugToPath } from './lib/url';
import type { ValidationResult, ReloadResult } from './lib/types';

/**
* Configuration options for FlapiApiClient
Expand Down Expand Up @@ -188,8 +189,14 @@ export class FlapiApiClient {
/**
* Update authentication token
*/
setToken(token: string) {
this.client.defaults.headers.common['Authorization'] = `Bearer ${token}`;
setToken(token: string | undefined) {
if (token) {
this.client.defaults.headers.common['Authorization'] = `Bearer ${token}`;
this.client.defaults.headers.common['X-Config-Token'] = token;
} else {
delete this.client.defaults.headers.common['Authorization'];
delete this.client.defaults.headers.common['X-Config-Token'];
}
if (this.debug) {
console.log('[FlapiAPI] Token updated');
}
Expand Down Expand Up @@ -347,6 +354,41 @@ export class FlapiApiClient {
const response = await this.client.get('/api/v1/_config/endpoints');
return response.data;
}

/**
* Validate raw endpoint YAML for an already-encoded endpoint slug.
* A 400 (invalid config) is returned as a normalized result rather than thrown.
*/
async validateEndpointConfig(slug: string, yamlContent: string): Promise<ValidationResult> {
const response = await this.client.post(
`/api/v1/_config/endpoints/${encodeURIComponent(slug)}/validate`,
yamlContent,
{
headers: { 'Content-Type': 'application/x-yaml' },
validateStatus: (status) => status < 500,
},
);
const result = response.data ?? {};
return {
valid: result.valid ?? false,
errors: result.errors ?? [],
warnings: result.warnings ?? [],
};
}

/**
* Reload an endpoint configuration from disk by already-encoded slug.
*/
async reloadEndpointConfig(slug: string): Promise<ReloadResult> {
const response = await this.client.post(
`/api/v1/_config/endpoints/${encodeURIComponent(slug)}/reload`,
);
const result = response.data ?? {};
return {
success: result.success ?? false,
message: result.message ?? '',
};
}
}

/**
Expand Down
Loading
Loading