feat: create client way
refactor: formating using biome code
This commit is contained in:
parent
684b5b511a
commit
f44e830205
12 changed files with 347 additions and 279 deletions
14
biome.json
Normal file
14
biome.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"files": {
|
||||||
|
"ignore": ["**/node_modules", "node_modules/"]
|
||||||
|
},
|
||||||
|
"vcs": {
|
||||||
|
"enabled": true,
|
||||||
|
"clientKind": "git"
|
||||||
|
},
|
||||||
|
"javascript": {
|
||||||
|
"formatter": {
|
||||||
|
"semicolons": "asNeeded"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
42
client.ts
Normal file
42
client.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
type Headers = {
|
||||||
|
"Content-Type": string
|
||||||
|
"X-Version": string
|
||||||
|
Authorization?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createClient<T>(config: {
|
||||||
|
baseUrl: string
|
||||||
|
token: string
|
||||||
|
version: string
|
||||||
|
method: string
|
||||||
|
publicKey: string
|
||||||
|
}): Promise<T> {
|
||||||
|
const version = config.version ?? "1.0.1"
|
||||||
|
const method = config.method ?? "GET"
|
||||||
|
|
||||||
|
const headers: Headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-Version": version,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.token !== undefined) {
|
||||||
|
headers.Authorization = `Bearer ${config.token}`
|
||||||
|
const response = await fetch(config.baseUrl, { method: method, headers })
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(response.statusText)
|
||||||
|
}
|
||||||
|
return (await response.json()) as T
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${config.baseUrl}/token`, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({
|
||||||
|
publicKey: config.publicKey,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(response.statusText)
|
||||||
|
}
|
||||||
|
return (await response.json()) as T
|
||||||
|
}
|
8
entities/account.d.ts
vendored
8
entities/account.d.ts
vendored
|
@ -1,6 +1,6 @@
|
||||||
export type Account = {
|
export type Account = {
|
||||||
uuid: string
|
uuid: string
|
||||||
username?: string
|
username?: string
|
||||||
publicKey: string
|
publicKey: string
|
||||||
currency: string
|
currency: string
|
||||||
}
|
}
|
||||||
|
|
363
entities/compose.d.ts
vendored
363
entities/compose.d.ts
vendored
|
@ -1,209 +1,220 @@
|
||||||
type Label = {
|
type Label = {
|
||||||
[label: string]: string
|
[label: string]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type WeightDevice = Array<{
|
type WeightDevice = Array<{
|
||||||
path: string
|
path: string
|
||||||
weight: number
|
weight: number
|
||||||
}>
|
}>
|
||||||
|
|
||||||
type DeviceBLK = Array<{
|
type DeviceBLK = Array<{
|
||||||
path: string
|
path: string
|
||||||
rate: number | string
|
rate: number | string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
type BuildServices = {
|
type BuildServices = {
|
||||||
context: string
|
context: string
|
||||||
dockefile: string
|
dockefile: string
|
||||||
dockerfile_inline: string
|
dockerfile_inline: string
|
||||||
args: Label
|
args: Label
|
||||||
ssh: Array<string>
|
ssh: Array<string>
|
||||||
cache_from: Array<string>
|
cache_from: Array<string>
|
||||||
cache_to: Array<string>
|
cache_to: Array<string>
|
||||||
additional_contexts: Array<Label>
|
additional_contexts: Array<Label>
|
||||||
extra_hosts: Label
|
extra_hosts: Label
|
||||||
labels: Label
|
labels: Label
|
||||||
privileged: boolean
|
privileged: boolean
|
||||||
no_cache: boolean
|
no_cache: boolean
|
||||||
network: "none" | "host" | string
|
network: "none" | "host" | string
|
||||||
shm_size: number | string
|
shm_size: number | string
|
||||||
target: string
|
target: string
|
||||||
secrets: Array<string>
|
secrets: Array<string>
|
||||||
tags: Array<string>
|
tags: Array<string>
|
||||||
platforms: Array<string>
|
platforms: Array<string>
|
||||||
ulimits: {
|
ulimits: {
|
||||||
nproc: number
|
nproc: number
|
||||||
nofile: {
|
nofile: {
|
||||||
soft: number
|
soft: number
|
||||||
hard: number
|
hard: number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Runtimes {
|
enum Runtimes {
|
||||||
runc,
|
runc,
|
||||||
crun,
|
crun,
|
||||||
youki,
|
youki,
|
||||||
inclavare,
|
inclavare,
|
||||||
gvisor,
|
gvisor,
|
||||||
wasmtime,
|
wasmtime,
|
||||||
katacontainers,
|
katacontainers,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Services = {
|
export type Services = {
|
||||||
[name: string]: {
|
[name: string]: {
|
||||||
annotations?: Label
|
annotations?: Label
|
||||||
image: string
|
image: string
|
||||||
ports?: Array<string>
|
ports?: Array<string>
|
||||||
|
|
||||||
attach?: boolean
|
attach?: boolean
|
||||||
build?: BuildServices
|
build?: BuildServices
|
||||||
blkio_config?: {
|
blkio_config?: {
|
||||||
weight: number
|
weight: number
|
||||||
weight_device: Array<{
|
weight_device: Array<{
|
||||||
path: string
|
path: string
|
||||||
weight: number
|
weight: number
|
||||||
}>
|
}>
|
||||||
device_read_bps: DeviceBLK
|
device_read_bps: DeviceBLK
|
||||||
device_read_iops: DeviceBLK
|
device_read_iops: DeviceBLK
|
||||||
device_write_bps: DeviceBLK
|
device_write_bps: DeviceBLK
|
||||||
device_write_iops: DeviceBLK
|
device_write_iops: DeviceBLK
|
||||||
}
|
}
|
||||||
cpu_count?: number
|
cpu_count?: number
|
||||||
cpu_persent?: number | string
|
cpu_persent?: number | string
|
||||||
cpu_quota?: number | string
|
cpu_quota?: number | string
|
||||||
cpu_rt_runtime?: number | string
|
cpu_rt_runtime?: number | string
|
||||||
cpu_rt_period?: number | string
|
cpu_rt_period?: number | string
|
||||||
cpus?: string
|
cpus?: string
|
||||||
cpuset?: string
|
cpuset?: string
|
||||||
cap_add?: Array<string>
|
cap_add?: Array<string>
|
||||||
cap_drop?: Array<string>
|
cap_drop?: Array<string>
|
||||||
cgroup?: "host" | "private"
|
cgroup?: "host" | "private"
|
||||||
cpu_rt_period?: string
|
cpu_rt_period?: string
|
||||||
command?: Array<string> | string
|
command?: Array<string> | string
|
||||||
configs?: Array<string> | Array<{
|
configs?:
|
||||||
source: string
|
| Array<string>
|
||||||
target: string
|
| Array<{
|
||||||
uid: string
|
source: string
|
||||||
gid: string
|
target: string
|
||||||
mode: number
|
uid: string
|
||||||
}>
|
gid: string
|
||||||
container_name?: string
|
mode: number
|
||||||
credential_spec?: {
|
}>
|
||||||
file?: string
|
container_name?: string
|
||||||
registry?: string
|
credential_spec?: {
|
||||||
}
|
file?: string
|
||||||
depends_on?: Array<string>
|
registry?: string
|
||||||
dns?: string | Array<string>
|
}
|
||||||
dns_opt?: Array<string>
|
depends_on?: Array<string>
|
||||||
dns_search?: string | Array<string>
|
dns?: string | Array<string>
|
||||||
entrypoint?: string | Array<string>
|
dns_opt?: Array<string>
|
||||||
tmpfs?: string | Array<string>
|
dns_search?: string | Array<string>
|
||||||
env_file?: Array<string> | Array<{
|
entrypoint?: string | Array<string>
|
||||||
path: string
|
tmpfs?: string | Array<string>
|
||||||
required: boolean
|
env_file?:
|
||||||
}>
|
| Array<string>
|
||||||
environment?: Array<string>
|
| Array<{
|
||||||
expose?: Array<string>
|
path: string
|
||||||
extends?: {
|
required: boolean
|
||||||
file: string
|
}>
|
||||||
service: string
|
environment?: Array<string>
|
||||||
}
|
expose?: Array<string>
|
||||||
}
|
extends?: {
|
||||||
external_links?: Array<string>
|
file: string
|
||||||
volumes_from?: Array<string>
|
service: string
|
||||||
tty?: boolean
|
}
|
||||||
sysctl?: Label
|
}
|
||||||
runtime: Runtimes
|
external_links?: Array<string>
|
||||||
restart: "no" | "always" | "unless-stopped" | "on-failure" | { "on-failure": number }
|
volumes_from?: Array<string>
|
||||||
workdir?: string
|
tty?: boolean
|
||||||
extra_hosts?: string
|
sysctl?: Label
|
||||||
stdin_open?: boolean
|
runtime: Runtimes
|
||||||
init?: boolean
|
restart:
|
||||||
profiles?: Array<string>
|
| "no"
|
||||||
network_mode?: "none" | "host"
|
| "always"
|
||||||
logging?: {
|
| "unless-stopped"
|
||||||
driver: string
|
| "on-failure"
|
||||||
options?: Label
|
| { "on-failure": number }
|
||||||
}
|
workdir?: string
|
||||||
links?: Array<string>
|
extra_hosts?: string
|
||||||
labels?: Array<Label>
|
stdin_open?: boolean
|
||||||
group_add?: Array<string>
|
init?: boolean
|
||||||
pids_limit?: number
|
profiles?: Array<string>
|
||||||
pull_policy?: "always" | "never" | "missing" | "build"
|
network_mode?: "none" | "host"
|
||||||
hostname?: string
|
logging?: {
|
||||||
devices?: Array<string>
|
driver: string
|
||||||
volumes?: Array<string>
|
options?: Label
|
||||||
uts?: "host" | string
|
}
|
||||||
mem_limit?: number | string
|
links?: Array<string>
|
||||||
healthcheck?: {
|
labels?: Array<Label>
|
||||||
test: Array<string>
|
group_add?: Array<string>
|
||||||
timeout?: string
|
pids_limit?: number
|
||||||
interval?: string
|
pull_policy?: "always" | "never" | "missing" | "build"
|
||||||
start_period?: string
|
hostname?: string
|
||||||
start_interval?: string
|
devices?: Array<string>
|
||||||
retries: number
|
volumes?: Array<string>
|
||||||
disable?: true
|
uts?: "host" | string
|
||||||
}
|
mem_limit?: number | string
|
||||||
|
healthcheck?: {
|
||||||
|
test: Array<string>
|
||||||
|
timeout?: string
|
||||||
|
interval?: string
|
||||||
|
start_period?: string
|
||||||
|
start_interval?: string
|
||||||
|
retries: number
|
||||||
|
disable?: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Networks = {
|
type Networks = {
|
||||||
[name: string]: {
|
[name: string]: {
|
||||||
driver?: string
|
driver?: string
|
||||||
driver_opts?: Label
|
driver_opts?: Label
|
||||||
attachable?: boolean
|
attachable?: boolean
|
||||||
enable_ipv6?: boolean
|
enable_ipv6?: boolean
|
||||||
external?: boolean
|
external?: boolean
|
||||||
name?: string
|
name?: string
|
||||||
ipam?: {
|
ipam?: {
|
||||||
driver?: string
|
driver?: string
|
||||||
config?: Array<{
|
config?: Array<{
|
||||||
subnet: string
|
subnet: string
|
||||||
ip_range: string
|
ip_range: string
|
||||||
gateway: string
|
gateway: string
|
||||||
aux_addresses: Array<Label>
|
aux_addresses: Array<Label>
|
||||||
}>
|
}>
|
||||||
}
|
}
|
||||||
labels?: Array<Label>
|
labels?: Array<Label>
|
||||||
options?: Array<Label>
|
options?: Array<Label>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Volumes = {
|
type Volumes = {
|
||||||
[name: string]: {
|
[name: string]: {
|
||||||
external?: boolean
|
external?: boolean
|
||||||
labels?: Array<Label>
|
labels?: Array<Label>
|
||||||
driver?: string
|
driver?: string
|
||||||
driver_opts?: Label
|
driver_opts?: Label
|
||||||
name?: string
|
name?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Configs = {
|
type Configs = {
|
||||||
[name: string]: {
|
[name: string]: {
|
||||||
external?: boolean
|
external?: boolean
|
||||||
name?: string
|
name?: string
|
||||||
file?: string
|
file?: string
|
||||||
environment?: string
|
environment?: string
|
||||||
content?: string
|
content?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Secrets = {
|
type Secrets = {
|
||||||
[name: string]: {
|
[name: string]:
|
||||||
file?: string
|
| {
|
||||||
} | {
|
file?: string
|
||||||
token: {
|
}
|
||||||
environment: string
|
| {
|
||||||
}
|
token: {
|
||||||
}
|
environment: string
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Compose = {
|
export type Compose = {
|
||||||
version?: "3"
|
version?: "3"
|
||||||
services: Services
|
services: Services
|
||||||
networks?: Networks
|
networks?: Networks
|
||||||
volumes?: Volumes
|
volumes?: Volumes
|
||||||
configs?: Configs
|
configs?: Configs
|
||||||
secrets?: Secrets
|
secrets?: Secrets
|
||||||
}
|
}
|
||||||
|
|
22
entities/deployment.d.ts
vendored
22
entities/deployment.d.ts
vendored
|
@ -4,21 +4,21 @@ import type { Unit } from "./unit.d.ts"
|
||||||
type Spec = string | Compose | Simple
|
type Spec = string | Compose | Simple
|
||||||
|
|
||||||
type Simple = {
|
type Simple = {
|
||||||
container: string
|
container: string
|
||||||
cpu?: Unit
|
cpu?: Unit
|
||||||
ram?: Unit
|
ram?: Unit
|
||||||
name?: string
|
name?: string
|
||||||
envs?: string[]
|
envs?: string[]
|
||||||
volumes?: string[]
|
volumes?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Deployment = {
|
export type Deployment = {
|
||||||
kind: "compose" | "simple" | "deployment"
|
kind: "compose" | "simple" | "deployment"
|
||||||
spec: Spec
|
spec: Spec
|
||||||
promocode?: string
|
promocode?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DeploymentResponse = Deployment & {
|
export type DeploymentResponse = Deployment & {
|
||||||
uuid: string
|
uuid: string
|
||||||
payLink: string
|
payLink: string
|
||||||
}
|
}
|
||||||
|
|
66
entities/extensions/bitcart.d.ts
vendored
66
entities/extensions/bitcart.d.ts
vendored
|
@ -1,41 +1,41 @@
|
||||||
export type Invoice = {
|
export type Invoice = {
|
||||||
metadata?: Object
|
metadata?: Object
|
||||||
created?: string
|
created?: string
|
||||||
price: string
|
price: string
|
||||||
store_id: string
|
store_id: string
|
||||||
currency?: string
|
currency?: string
|
||||||
order_id?: string
|
order_id?: string
|
||||||
notification_url?: string
|
notification_url?: string
|
||||||
redirect_url?: string
|
redirect_url?: string
|
||||||
buyer_email?: string
|
buyer_email?: string
|
||||||
promocode?: string
|
promocode?: string
|
||||||
shipping_address?: string
|
shipping_address?: string
|
||||||
notes?: string
|
notes?: string
|
||||||
status?: string
|
status?: string
|
||||||
exception_status?: string
|
exception_status?: string
|
||||||
products?: string[] | Object[]
|
products?: string[] | Object[]
|
||||||
tx_hashes?: string[]
|
tx_hashes?: string[]
|
||||||
expiration?: number
|
expiration?: number
|
||||||
sent_amount?: number
|
sent_amount?: number
|
||||||
id: string
|
id: string
|
||||||
user_id: string
|
user_id: string
|
||||||
time_left: number
|
time_left: number
|
||||||
expiration_seconds: number
|
expiration_seconds: number
|
||||||
product_names?: Object
|
product_names?: Object
|
||||||
payments: Object[]
|
payments: Object[]
|
||||||
paid_date: string
|
paid_date: string
|
||||||
payment_id: string
|
payment_id: string
|
||||||
refund_id: string
|
refund_id: string
|
||||||
paid_currency: string | null
|
paid_currency: string | null
|
||||||
discount: string | null
|
discount: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type TError = {
|
type TError = {
|
||||||
loc: string[] | number[]
|
loc: string[] | number[]
|
||||||
msg: string
|
msg: string
|
||||||
type: string
|
type: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Errors = {
|
export type Errors = {
|
||||||
detail: TError[]
|
detail: TError[]
|
||||||
}
|
}
|
||||||
|
|
16
entities/provider.d.ts
vendored
16
entities/provider.d.ts
vendored
|
@ -1,15 +1,15 @@
|
||||||
import type { Unit } from "./unit.d.ts"
|
import type { Unit } from "./unit.d.ts"
|
||||||
|
|
||||||
export type Provider = {
|
export type Provider = {
|
||||||
uuid: string
|
uuid: string
|
||||||
name: string
|
name: string
|
||||||
api: string
|
api: string
|
||||||
description?: string
|
description?: string
|
||||||
price: PriceTable
|
price: PriceTable
|
||||||
/* address for receive payments */
|
/* address for receive payments */
|
||||||
address: string
|
address: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PriceTable = {
|
type PriceTable = {
|
||||||
[x: string]: ComputingUnit | Unit
|
[x: string]: ComputingUnit | Unit
|
||||||
}
|
}
|
||||||
|
|
14
entities/unit.d.ts
vendored
14
entities/unit.d.ts
vendored
|
@ -1,13 +1,11 @@
|
||||||
export type Unit = {
|
export type Unit = {
|
||||||
unit: string
|
unit: string
|
||||||
count: number
|
count: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ComputingUnit = {
|
export type ComputingUnit = {
|
||||||
cpu: number | Unit
|
cpu: number | Unit
|
||||||
mem: number | Unit
|
mem: number | Unit
|
||||||
persistence: number | Unit
|
persistence: number | Unit
|
||||||
bandwitch: number | Unit
|
bandwitch: number | Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
14
entities/worker.d.ts
vendored
14
entities/worker.d.ts
vendored
|
@ -1,11 +1,11 @@
|
||||||
import type { ComputingUnit } from "./unit.d.ts"
|
import type { ComputingUnit } from "./unit.d.ts"
|
||||||
|
|
||||||
export type Worker = {
|
export type Worker = {
|
||||||
uuid: string
|
uuid: string
|
||||||
/* address for receive payments */
|
/* address for receive payments */
|
||||||
address?: string
|
address?: string
|
||||||
name?: string
|
name?: string
|
||||||
price?: ComputingUnit
|
price?: ComputingUnit
|
||||||
/* address to node server */
|
/* address to node server */
|
||||||
node?: string
|
node?: string
|
||||||
}
|
}
|
||||||
|
|
21
package.json
21
package.json
|
@ -1,11 +1,14 @@
|
||||||
{
|
{
|
||||||
"name": "josal",
|
"name": "josal",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest"
|
"@types/bun": "latest"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
}
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@biomejs/biome": "^1.8.3"
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,27 +1,27 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
// Enable latest features
|
// Enable latest features
|
||||||
"lib": ["ESNext", "DOM"],
|
"lib": ["ESNext", "DOM"],
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleDetection": "force",
|
"moduleDetection": "force",
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
|
||||||
// Bundler mode
|
// Bundler mode
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
"allowImportingTsExtensions": true,
|
"allowImportingTsExtensions": true,
|
||||||
"verbatimModuleSyntax": true,
|
"verbatimModuleSyntax": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
|
|
||||||
// Best practices
|
// Best practices
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
|
||||||
// Some stricter flags (disabled by default)
|
// Some stricter flags (disabled by default)
|
||||||
"noUnusedLocals": false,
|
"noUnusedLocals": false,
|
||||||
"noUnusedParameters": false,
|
"noUnusedParameters": false,
|
||||||
"noPropertyAccessFromIndexSignature": false
|
"noPropertyAccessFromIndexSignature": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue