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
460 changes: 301 additions & 159 deletions typescript/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flexmodel/sdk",
"version": "0.0.6",
"version": "0.0.7",
"description": "Flexmodel TypeScript SDK — Fluent query builder for data CRUD with API Key auth",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
170 changes: 170 additions & 0 deletions typescript/src/admin-namespaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// ============================================================
// Flexmodel SDK — Admin Namespaces
//
// Thin namespaces for admin API operations (project/user/apikey management).
// Only available on FlexmodelAdminClient.
// ============================================================

import type {HttpTransport} from './http.js'

// ---- Types ----

export interface Project {
id: string
name: string
databaseName?: string

[key: string]: unknown
}

export interface CreateProjectRequest {
name: string

[key: string]: unknown
}

export interface User {
id: string
username?: string

[key: string]: unknown
}

export interface ApiKey {
id: string
name: string
keyPrefix: string
scope: 'admin' | 'open'
projectIds?: string
readOnly: boolean
expiresAt?: string | null
lastUsedAt?: string | null
createdAt?: string
key?: string | null
}

export interface CreateApiKeyRequest {
name: string
scope?: string
projectIds?: string
readOnly?: boolean
}

export interface AdminFunction {
id: string
name: string

[key: string]: unknown
}

export interface DeployFunctionRequest {
sourceFiles: Record<string, string>

[key: string]: unknown
}

// ---- ProjectsNamespace ----

export class ProjectsNamespace {
private readonly http: HttpTransport

constructor(http: HttpTransport) {
this.http = http
}

async list(): Promise<Project[]> {
return this.http.request<Project[]>('GET', '/api/projects')
}

async create(data: CreateProjectRequest): Promise<Project> {
return this.http.request<Project>('POST', '/api/projects', {body: data})
}

async get(id: string): Promise<Project> {
return this.http.request<Project>('GET', `/api/projects/${id}`)
}

async update(id: string, data: Partial<Project>): Promise<Project> {
return this.http.request<Project>('PUT', `/api/projects/${id}`, {body: data})
}

async delete(id: string): Promise<void> {
await this.http.request<void>('DELETE', `/api/projects/${id}`)
}
}

// ---- UsersNamespace ----

export class UsersNamespace {
private readonly http: HttpTransport

constructor(http: HttpTransport) {
this.http = http
}

async list(): Promise<User[]> {
return this.http.request<User[]>('GET', '/api/users')
}

async create(data: Record<string, unknown>): Promise<User> {
return this.http.request<User>('POST', '/api/users', {body: data})
}

async delete(id: string): Promise<void> {
await this.http.request<void>('DELETE', `/api/users/${id}`)
}
}

// ---- ApiKeysNamespace ----

export class ApiKeysNamespace {
private readonly http: HttpTransport

constructor(http: HttpTransport) {
this.http = http
}

async list(): Promise<ApiKey[]> {
return this.http.request<ApiKey[]>('GET', '/api/api-keys')
}

async create(data: CreateApiKeyRequest): Promise<ApiKey> {
return this.http.request<ApiKey>('POST', '/api/api-keys', {body: data})
}

async regenerate(id: string): Promise<ApiKey> {
return this.http.request<ApiKey>('POST', `/api/api-keys/${id}/regenerate`)
}

async delete(id: string): Promise<void> {
await this.http.request<void>('DELETE', `/api/api-keys/${id}`)
}
}

// ---- AdminFunctionsNamespace ----

export class AdminFunctionsNamespace {
private readonly http: HttpTransport

constructor(http: HttpTransport) {
this.http = http
}

async list(projectId: string): Promise<AdminFunction[]> {
return this.http.request<AdminFunction[]>('GET', `/api/projects/${projectId}/functions`)
}

async get(projectId: string, name: string): Promise<AdminFunction> {
return this.http.request<AdminFunction>('GET', `/api/projects/${projectId}/functions/${name}`)
}

async deploy(projectId: string, name: string, sourceFiles: Record<string, string>): Promise<AdminFunction> {
return this.http.request<AdminFunction>('POST', `/api/projects/${projectId}/functions/${name}/deploy`, {
body: {sourceFiles},
})
}

async delete(projectId: string, name: string): Promise<void> {
await this.http.request<void>('DELETE', `/api/projects/${projectId}/functions/${name}`)
}
}
Loading
Loading