Skip to content

Commit

Permalink
feat: added templates
Browse files Browse the repository at this point in the history
  • Loading branch information
sangdth committed Nov 28, 2023
1 parent a5dd556 commit 2f7e979
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $fetch } from 'ofetch'
import type { ClientConfig, ClientResponse, NoResponse, UserRes } from './types'
import { monitor, projects, services, settings } from './service'
import { monitor, projects, services, settings, templates } from './service'
import { routes } from './utils/routes'

let token = ''
Expand Down Expand Up @@ -52,6 +52,7 @@ export function easypanel(config: ClientConfig) {
const _services = services(_client)
const _monitor = monitor(_client)
const _settings = settings(_client)
const _templates = templates(_client)

async function getUser(): Promise<UserRes> {
const res = await _client.get<UserRes>(routes.auth.GetUser, { json: null })
Expand All @@ -75,6 +76,7 @@ export function easypanel(config: ClientConfig) {
services: _services,
monitor: _monitor,
settings: _settings,
templates: _templates,
getUser,
getLicensePayload,
activateLicense,
Expand Down
1 change: 1 addition & 0 deletions src/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './projects'
export * from './monitors'
export * from './settings'
export * from './services'
export * from './templates'
15 changes: 15 additions & 0 deletions src/service/templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ClientResponse, NoResponse, ProjectFromSchema } from '../types'
import { routes } from '../utils/routes'

export function templates({ post }: ClientResponse) {
async function createFromSchema(body: ProjectFromSchema) {
const res = await post<NoResponse>(routes.templates.CreateFromSchema, {
json: body,
})
return res
}

return {
createFromSchema,
}
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type * from './monitor'
export type * from './projects'
export type * from './services'
export type * from './settings'
export type * from './templates'

export interface ClientConfig {
endpoint: string
Expand Down
17 changes: 17 additions & 0 deletions src/types/templates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Service, ServiceType } from './services'

/**
* Params
*/

export interface CreateServiceSchema {
type: ServiceType
data: Service
}

export interface ProjectFromSchema {
projectName: string
schema: Record<string, unknown> & {
services: CreateServiceSchema[]
}
}
5 changes: 5 additions & 0 deletions src/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ const settings = {
ChangeCredentials: '/api/trpc/settings.changeCredentials', // POST
}

const templates = {
CreateFromSchema: '/api/trpc/templates.createFromSchema', // POST
}

export const routes = {
projets,
services,
monitor,
auth,
license,
settings,
templates,
}

0 comments on commit 2f7e979

Please sign in to comment.