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 = {
|
||||
uuid: string
|
||||
username?: string
|
||||
publicKey: string
|
||||
currency: string
|
||||
uuid: string
|
||||
username?: string
|
||||
publicKey: string
|
||||
currency: string
|
||||
}
|
||||
|
|
363
entities/compose.d.ts
vendored
363
entities/compose.d.ts
vendored
|
@ -1,209 +1,220 @@
|
|||
type Label = {
|
||||
[label: string]: string
|
||||
[label: string]: string
|
||||
}
|
||||
|
||||
type WeightDevice = Array<{
|
||||
path: string
|
||||
weight: number
|
||||
path: string
|
||||
weight: number
|
||||
}>
|
||||
|
||||
type DeviceBLK = Array<{
|
||||
path: string
|
||||
rate: number | string
|
||||
path: string
|
||||
rate: number | string
|
||||
}>
|
||||
|
||||
type BuildServices = {
|
||||
context: string
|
||||
dockefile: string
|
||||
dockerfile_inline: string
|
||||
args: Label
|
||||
ssh: Array<string>
|
||||
cache_from: Array<string>
|
||||
cache_to: Array<string>
|
||||
additional_contexts: Array<Label>
|
||||
extra_hosts: Label
|
||||
labels: Label
|
||||
privileged: boolean
|
||||
no_cache: boolean
|
||||
network: "none" | "host" | string
|
||||
shm_size: number | string
|
||||
target: string
|
||||
secrets: Array<string>
|
||||
tags: Array<string>
|
||||
platforms: Array<string>
|
||||
ulimits: {
|
||||
nproc: number
|
||||
nofile: {
|
||||
soft: number
|
||||
hard: number
|
||||
}
|
||||
}
|
||||
context: string
|
||||
dockefile: string
|
||||
dockerfile_inline: string
|
||||
args: Label
|
||||
ssh: Array<string>
|
||||
cache_from: Array<string>
|
||||
cache_to: Array<string>
|
||||
additional_contexts: Array<Label>
|
||||
extra_hosts: Label
|
||||
labels: Label
|
||||
privileged: boolean
|
||||
no_cache: boolean
|
||||
network: "none" | "host" | string
|
||||
shm_size: number | string
|
||||
target: string
|
||||
secrets: Array<string>
|
||||
tags: Array<string>
|
||||
platforms: Array<string>
|
||||
ulimits: {
|
||||
nproc: number
|
||||
nofile: {
|
||||
soft: number
|
||||
hard: number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Runtimes {
|
||||
runc,
|
||||
crun,
|
||||
youki,
|
||||
inclavare,
|
||||
gvisor,
|
||||
wasmtime,
|
||||
katacontainers,
|
||||
runc,
|
||||
crun,
|
||||
youki,
|
||||
inclavare,
|
||||
gvisor,
|
||||
wasmtime,
|
||||
katacontainers,
|
||||
}
|
||||
|
||||
export type Services = {
|
||||
[name: string]: {
|
||||
annotations?: Label
|
||||
image: string
|
||||
ports?: Array<string>
|
||||
[name: string]: {
|
||||
annotations?: Label
|
||||
image: string
|
||||
ports?: Array<string>
|
||||
|
||||
attach?: boolean
|
||||
build?: BuildServices
|
||||
blkio_config?: {
|
||||
weight: number
|
||||
weight_device: Array<{
|
||||
path: string
|
||||
weight: number
|
||||
}>
|
||||
device_read_bps: DeviceBLK
|
||||
device_read_iops: DeviceBLK
|
||||
device_write_bps: DeviceBLK
|
||||
device_write_iops: DeviceBLK
|
||||
}
|
||||
cpu_count?: number
|
||||
cpu_persent?: number | string
|
||||
cpu_quota?: number | string
|
||||
cpu_rt_runtime?: number | string
|
||||
cpu_rt_period?: number | string
|
||||
cpus?: string
|
||||
cpuset?: string
|
||||
cap_add?: Array<string>
|
||||
cap_drop?: Array<string>
|
||||
cgroup?: "host" | "private"
|
||||
cpu_rt_period?: string
|
||||
command?: Array<string> | string
|
||||
configs?: Array<string> | Array<{
|
||||
source: string
|
||||
target: string
|
||||
uid: string
|
||||
gid: string
|
||||
mode: number
|
||||
}>
|
||||
container_name?: string
|
||||
credential_spec?: {
|
||||
file?: string
|
||||
registry?: string
|
||||
}
|
||||
depends_on?: Array<string>
|
||||
dns?: string | Array<string>
|
||||
dns_opt?: Array<string>
|
||||
dns_search?: string | Array<string>
|
||||
entrypoint?: string | Array<string>
|
||||
tmpfs?: string | Array<string>
|
||||
env_file?: Array<string> | Array<{
|
||||
path: string
|
||||
required: boolean
|
||||
}>
|
||||
environment?: Array<string>
|
||||
expose?: Array<string>
|
||||
extends?: {
|
||||
file: string
|
||||
service: string
|
||||
}
|
||||
}
|
||||
external_links?: Array<string>
|
||||
volumes_from?: Array<string>
|
||||
tty?: boolean
|
||||
sysctl?: Label
|
||||
runtime: Runtimes
|
||||
restart: "no" | "always" | "unless-stopped" | "on-failure" | { "on-failure": number }
|
||||
workdir?: string
|
||||
extra_hosts?: string
|
||||
stdin_open?: boolean
|
||||
init?: boolean
|
||||
profiles?: Array<string>
|
||||
network_mode?: "none" | "host"
|
||||
logging?: {
|
||||
driver: string
|
||||
options?: Label
|
||||
}
|
||||
links?: Array<string>
|
||||
labels?: Array<Label>
|
||||
group_add?: Array<string>
|
||||
pids_limit?: number
|
||||
pull_policy?: "always" | "never" | "missing" | "build"
|
||||
hostname?: string
|
||||
devices?: Array<string>
|
||||
volumes?: Array<string>
|
||||
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
|
||||
}
|
||||
attach?: boolean
|
||||
build?: BuildServices
|
||||
blkio_config?: {
|
||||
weight: number
|
||||
weight_device: Array<{
|
||||
path: string
|
||||
weight: number
|
||||
}>
|
||||
device_read_bps: DeviceBLK
|
||||
device_read_iops: DeviceBLK
|
||||
device_write_bps: DeviceBLK
|
||||
device_write_iops: DeviceBLK
|
||||
}
|
||||
cpu_count?: number
|
||||
cpu_persent?: number | string
|
||||
cpu_quota?: number | string
|
||||
cpu_rt_runtime?: number | string
|
||||
cpu_rt_period?: number | string
|
||||
cpus?: string
|
||||
cpuset?: string
|
||||
cap_add?: Array<string>
|
||||
cap_drop?: Array<string>
|
||||
cgroup?: "host" | "private"
|
||||
cpu_rt_period?: string
|
||||
command?: Array<string> | string
|
||||
configs?:
|
||||
| Array<string>
|
||||
| Array<{
|
||||
source: string
|
||||
target: string
|
||||
uid: string
|
||||
gid: string
|
||||
mode: number
|
||||
}>
|
||||
container_name?: string
|
||||
credential_spec?: {
|
||||
file?: string
|
||||
registry?: string
|
||||
}
|
||||
depends_on?: Array<string>
|
||||
dns?: string | Array<string>
|
||||
dns_opt?: Array<string>
|
||||
dns_search?: string | Array<string>
|
||||
entrypoint?: string | Array<string>
|
||||
tmpfs?: string | Array<string>
|
||||
env_file?:
|
||||
| Array<string>
|
||||
| Array<{
|
||||
path: string
|
||||
required: boolean
|
||||
}>
|
||||
environment?: Array<string>
|
||||
expose?: Array<string>
|
||||
extends?: {
|
||||
file: string
|
||||
service: string
|
||||
}
|
||||
}
|
||||
external_links?: Array<string>
|
||||
volumes_from?: Array<string>
|
||||
tty?: boolean
|
||||
sysctl?: Label
|
||||
runtime: Runtimes
|
||||
restart:
|
||||
| "no"
|
||||
| "always"
|
||||
| "unless-stopped"
|
||||
| "on-failure"
|
||||
| { "on-failure": number }
|
||||
workdir?: string
|
||||
extra_hosts?: string
|
||||
stdin_open?: boolean
|
||||
init?: boolean
|
||||
profiles?: Array<string>
|
||||
network_mode?: "none" | "host"
|
||||
logging?: {
|
||||
driver: string
|
||||
options?: Label
|
||||
}
|
||||
links?: Array<string>
|
||||
labels?: Array<Label>
|
||||
group_add?: Array<string>
|
||||
pids_limit?: number
|
||||
pull_policy?: "always" | "never" | "missing" | "build"
|
||||
hostname?: string
|
||||
devices?: Array<string>
|
||||
volumes?: Array<string>
|
||||
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 = {
|
||||
[name: string]: {
|
||||
driver?: string
|
||||
driver_opts?: Label
|
||||
attachable?: boolean
|
||||
enable_ipv6?: boolean
|
||||
external?: boolean
|
||||
name?: string
|
||||
ipam?: {
|
||||
driver?: string
|
||||
config?: Array<{
|
||||
subnet: string
|
||||
ip_range: string
|
||||
gateway: string
|
||||
aux_addresses: Array<Label>
|
||||
}>
|
||||
}
|
||||
labels?: Array<Label>
|
||||
options?: Array<Label>
|
||||
}
|
||||
[name: string]: {
|
||||
driver?: string
|
||||
driver_opts?: Label
|
||||
attachable?: boolean
|
||||
enable_ipv6?: boolean
|
||||
external?: boolean
|
||||
name?: string
|
||||
ipam?: {
|
||||
driver?: string
|
||||
config?: Array<{
|
||||
subnet: string
|
||||
ip_range: string
|
||||
gateway: string
|
||||
aux_addresses: Array<Label>
|
||||
}>
|
||||
}
|
||||
labels?: Array<Label>
|
||||
options?: Array<Label>
|
||||
}
|
||||
}
|
||||
|
||||
type Volumes = {
|
||||
[name: string]: {
|
||||
external?: boolean
|
||||
labels?: Array<Label>
|
||||
driver?: string
|
||||
driver_opts?: Label
|
||||
name?: string
|
||||
}
|
||||
[name: string]: {
|
||||
external?: boolean
|
||||
labels?: Array<Label>
|
||||
driver?: string
|
||||
driver_opts?: Label
|
||||
name?: string
|
||||
}
|
||||
}
|
||||
|
||||
type Configs = {
|
||||
[name: string]: {
|
||||
external?: boolean
|
||||
name?: string
|
||||
file?: string
|
||||
environment?: string
|
||||
content?: string
|
||||
}
|
||||
[name: string]: {
|
||||
external?: boolean
|
||||
name?: string
|
||||
file?: string
|
||||
environment?: string
|
||||
content?: string
|
||||
}
|
||||
}
|
||||
|
||||
type Secrets = {
|
||||
[name: string]: {
|
||||
file?: string
|
||||
} | {
|
||||
token: {
|
||||
environment: string
|
||||
}
|
||||
}
|
||||
[name: string]:
|
||||
| {
|
||||
file?: string
|
||||
}
|
||||
| {
|
||||
token: {
|
||||
environment: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type Compose = {
|
||||
version?: "3"
|
||||
services: Services
|
||||
networks?: Networks
|
||||
volumes?: Volumes
|
||||
configs?: Configs
|
||||
secrets?: Secrets
|
||||
version?: "3"
|
||||
services: Services
|
||||
networks?: Networks
|
||||
volumes?: Volumes
|
||||
configs?: Configs
|
||||
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 Simple = {
|
||||
container: string
|
||||
cpu?: Unit
|
||||
ram?: Unit
|
||||
name?: string
|
||||
envs?: string[]
|
||||
volumes?: string[]
|
||||
container: string
|
||||
cpu?: Unit
|
||||
ram?: Unit
|
||||
name?: string
|
||||
envs?: string[]
|
||||
volumes?: string[]
|
||||
}
|
||||
|
||||
export type Deployment = {
|
||||
kind: "compose" | "simple" | "deployment"
|
||||
spec: Spec
|
||||
promocode?: string
|
||||
kind: "compose" | "simple" | "deployment"
|
||||
spec: Spec
|
||||
promocode?: string
|
||||
}
|
||||
|
||||
export type DeploymentResponse = Deployment & {
|
||||
uuid: string
|
||||
payLink: string
|
||||
uuid: string
|
||||
payLink: string
|
||||
}
|
||||
|
|
66
entities/extensions/bitcart.d.ts
vendored
66
entities/extensions/bitcart.d.ts
vendored
|
@ -1,41 +1,41 @@
|
|||
export type Invoice = {
|
||||
metadata?: Object
|
||||
created?: string
|
||||
price: string
|
||||
store_id: string
|
||||
currency?: string
|
||||
order_id?: string
|
||||
notification_url?: string
|
||||
redirect_url?: string
|
||||
buyer_email?: string
|
||||
promocode?: string
|
||||
shipping_address?: string
|
||||
notes?: string
|
||||
status?: string
|
||||
exception_status?: string
|
||||
products?: string[] | Object[]
|
||||
tx_hashes?: string[]
|
||||
expiration?: number
|
||||
sent_amount?: number
|
||||
id: string
|
||||
user_id: string
|
||||
time_left: number
|
||||
expiration_seconds: number
|
||||
product_names?: Object
|
||||
payments: Object[]
|
||||
paid_date: string
|
||||
payment_id: string
|
||||
refund_id: string
|
||||
paid_currency: string | null
|
||||
discount: string | null
|
||||
metadata?: Object
|
||||
created?: string
|
||||
price: string
|
||||
store_id: string
|
||||
currency?: string
|
||||
order_id?: string
|
||||
notification_url?: string
|
||||
redirect_url?: string
|
||||
buyer_email?: string
|
||||
promocode?: string
|
||||
shipping_address?: string
|
||||
notes?: string
|
||||
status?: string
|
||||
exception_status?: string
|
||||
products?: string[] | Object[]
|
||||
tx_hashes?: string[]
|
||||
expiration?: number
|
||||
sent_amount?: number
|
||||
id: string
|
||||
user_id: string
|
||||
time_left: number
|
||||
expiration_seconds: number
|
||||
product_names?: Object
|
||||
payments: Object[]
|
||||
paid_date: string
|
||||
payment_id: string
|
||||
refund_id: string
|
||||
paid_currency: string | null
|
||||
discount: string | null
|
||||
}
|
||||
|
||||
type TError = {
|
||||
loc: string[] | number[]
|
||||
msg: string
|
||||
type: string
|
||||
loc: string[] | number[]
|
||||
msg: string
|
||||
type: string
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
export type Provider = {
|
||||
uuid: string
|
||||
name: string
|
||||
api: string
|
||||
description?: string
|
||||
price: PriceTable
|
||||
/* address for receive payments */
|
||||
address: string
|
||||
uuid: string
|
||||
name: string
|
||||
api: string
|
||||
description?: string
|
||||
price: PriceTable
|
||||
/* address for receive payments */
|
||||
address: string
|
||||
}
|
||||
|
||||
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 = {
|
||||
unit: string
|
||||
count: number
|
||||
unit: string
|
||||
count: number
|
||||
}
|
||||
|
||||
export type ComputingUnit = {
|
||||
cpu: number | Unit
|
||||
mem: number | Unit
|
||||
persistence: number | Unit
|
||||
bandwitch: number | Unit
|
||||
cpu: number | Unit
|
||||
mem: number | Unit
|
||||
persistence: 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"
|
||||
|
||||
export type Worker = {
|
||||
uuid: string
|
||||
/* address for receive payments */
|
||||
address?: string
|
||||
name?: string
|
||||
price?: ComputingUnit
|
||||
/* address to node server */
|
||||
node?: string
|
||||
uuid: string
|
||||
/* address for receive payments */
|
||||
address?: string
|
||||
name?: string
|
||||
price?: ComputingUnit
|
||||
/* address to node server */
|
||||
node?: string
|
||||
}
|
||||
|
|
23
package.json
23
package.json
|
@ -1,11 +1,14 @@
|
|||
{
|
||||
"name": "josal",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
"name": "josal",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@biomejs/biome": "^1.8.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue