refactor downstream for 036 changes (#2577)

refactor codebase for 036 changes
This commit is contained in:
Matt Hill
2024-03-24 12:12:55 -06:00
committed by GitHub
parent 22cd2e3337
commit 3b669193f6
152 changed files with 1360 additions and 1352 deletions

View File

@@ -644,23 +644,23 @@ export module Mock {
name: 'My Backup Job',
target: BackupTargets.saved[0],
cron: '0 3 * * *',
'package-ids': ['bitcoind', 'lnd'],
packageIds: ['bitcoind', 'lnd'],
},
{
id: 'hahahahaha-mwmwmwmwmwmw',
name: 'Another Backup Job',
target: BackupTargets.saved[1],
cron: '0 * * * *',
'package-ids': ['lnd'],
packageIds: ['lnd'],
},
]
export const BackupRuns: RR.GetBackupRunsRes = [
{
id: 'kladhbfweubdsk',
'started-at': new Date().toISOString(),
'completed-at': new Date(new Date().valueOf() + 10000).toISOString(),
'package-ids': ['bitcoind', 'lnd'],
startedAt: new Date().toISOString(),
completedAt: new Date(new Date().valueOf() + 10000).toISOString(),
packageIds: ['bitcoind', 'lnd'],
job: BackupJobs[0],
report: {
server: {
@@ -675,9 +675,9 @@ export module Mock {
},
{
id: 'kladhbfwhrfeubdsk',
'started-at': new Date().toISOString(),
'completed-at': new Date(new Date().valueOf() + 10000).toISOString(),
'package-ids': ['bitcoind', 'lnd'],
startedAt: new Date().toISOString(),
completedAt: new Date(new Date().valueOf() + 10000).toISOString(),
packageIds: ['bitcoind', 'lnd'],
job: BackupJobs[0],
report: {
server: {
@@ -1267,6 +1267,7 @@ export module Mock {
manifest: MockManifestBitcoind,
},
icon: '/assets/img/service-icons/bitcoind.svg',
installedAt: new Date().toISOString(),
lastBackup: null,
status: {
configured: true,
@@ -1507,6 +1508,7 @@ export module Mock {
manifest: MockManifestBitcoinProxy,
},
icon: '/assets/img/service-icons/btc-rpc-proxy.png',
installedAt: new Date().toISOString(),
lastBackup: null,
status: {
configured: false,
@@ -1647,6 +1649,7 @@ export module Mock {
manifest: MockManifestLnd,
},
icon: '/assets/img/service-icons/lnd.png',
installedAt: new Date().toISOString(),
lastBackup: null,
status: {
configured: true,

View File

@@ -4,8 +4,6 @@ import {
DataModel,
DomainInfo,
NetworkStrategy,
OsOutboundProxy,
ServiceOutboundProxy,
HealthCheckResult,
} from 'src/app/services/patch-db/data-model'
import {
@@ -90,7 +88,7 @@ export module RR {
export type ResetTorRes = null
export type SetOsOutboundProxyReq = {
proxy: OsOutboundProxy
proxy: string | null
} // server.proxy.set-outbound
export type SetOsOutboundProxyRes = null
@@ -140,9 +138,7 @@ export module RR {
export type AddProxyRes = null
export type UpdateProxyReq = {
name?: string
primaryInbound?: true
primaryOutbound?: true
name: string
} // net.proxy.update
export type UpdateProxyRes = null
@@ -305,8 +301,8 @@ export module RR {
// package
export type GetPackageCredentialsReq = { id: string } // package.credentials
export type GetPackageCredentialsRes = Record<string, string>
export type GetPackagePropertiesReq = { id: string } // package.properties
export type GetPackagePropertiesRes = Record<string, string>
export type GetPackageLogsReq = FetchLogsReq & { id: string } // package.logs
export type GetPackageLogsRes = FetchLogsRes
@@ -335,7 +331,6 @@ export module RR {
// package.backup.restore
ids: string[]
targetId: string
oldPassword: string | null
password: string
}
export type RestorePackagesRes = null
@@ -384,7 +379,7 @@ export module RR {
export type SetServiceOutboundProxyReq = {
packageId: string
proxy: ServiceOutboundProxy
proxy: string | null
} // package.proxy.set-outbound
export type SetServiceOutboundProxyRes = null
@@ -533,9 +528,9 @@ export interface CloudBackupTarget extends BaseBackupTarget {
export interface BackupRun {
id: string
'started-at': string
'completed-at': string
'package-ids': string[]
startedAt: string
completedAt: string
packageIds: string[]
job: BackupJob
report: BackupReport
}
@@ -598,8 +593,8 @@ export enum NotificationLevel {
export type NotificationData<T> = T extends 0
? null
: T extends 1
? BackupReport
: any
? BackupReport
: any
export interface BackupReport {
server: {

View File

@@ -256,9 +256,9 @@ export abstract class ApiService {
// package
abstract getPackageCredentials(
params: RR.GetPackageCredentialsReq,
): Promise<RR.GetPackageCredentialsRes>
abstract getPackageProperties(
params: RR.GetPackagePropertiesReq,
): Promise<RR.GetPackagePropertiesRes>
abstract getPackageLogs(
params: RR.GetPackageLogsReq,

View File

@@ -450,10 +450,10 @@ export class LiveApiService extends ApiService {
// package
async getPackageCredentials(
params: RR.GetPackageCredentialsReq,
): Promise<RR.GetPackageCredentialsRes> {
return this.rpcRequest({ method: 'package.credentials', params })
async getPackageProperties(
params: RR.GetPackagePropertiesReq,
): Promise<RR.GetPackagePropertiesRes> {
return this.rpcRequest({ method: 'package.properties', params })
}
async getPackageLogs(

View File

@@ -538,11 +538,6 @@ export class MockApiService extends ApiService {
domains: [],
services: [],
},
primaryInbound: type === 'inbound-outbound' ? true : false,
primaryOutbound:
type === 'inbound-outbound' || type === 'outbound' ? true : false,
// primaryInbound: false,
// primaryOutbound: false,
},
],
},
@@ -555,13 +550,11 @@ export class MockApiService extends ApiService {
async updateProxy(params: RR.UpdateProxyReq): Promise<RR.UpdateProxyRes> {
await pauseFor(2000)
const value = params.name || params.primaryInbound || params.primaryOutbound
const patch = [
{
op: PatchOp.REPLACE,
path: `/server-info/network/proxies/0/${Object.keys(params)[0]}`,
value,
path: `/server-info/network/proxies/0/name`,
value: params.name,
},
]
this.mockRevision(patch)
@@ -926,9 +919,9 @@ export class MockApiService extends ApiService {
// package
async getPackageCredentials(
params: RR.GetPackageCredentialsReq,
): Promise<RR.GetPackageCredentialsRes> {
async getPackageProperties(
params: RR.GetPackagePropertiesReq,
): Promise<RR.GetPackagePropertiesRes> {
await pauseFor(2000)
return {
password: 'specialPassword$',

View File

@@ -110,10 +110,6 @@ export const mockPatchData: DataModel = {
],
},
proxies: [],
primaryProxies: {
inbound: null,
outbound: null,
},
outboundProxy: null,
},
lastBackup: new Date(new Date().valueOf() - 604800001).toISOString(),
@@ -153,6 +149,7 @@ export const mockPatchData: DataModel = {
},
},
icon: '/assets/img/service-icons/bitcoind.svg',
installedAt: new Date().toISOString(),
lastBackup: null,
status: {
configured: true,
@@ -419,6 +416,7 @@ export const mockPatchData: DataModel = {
},
},
icon: '/assets/img/service-icons/lnd.png',
installedAt: new Date().toISOString(),
lastBackup: null,
status: {
configured: true,

View File

@@ -1,16 +1,13 @@
import { DOCUMENT } from '@angular/common'
import { Inject, Injectable } from '@angular/core'
import { WorkspaceConfig } from '@start9labs/shared'
import { types } from '@start9labs/start-sdk'
import { T } from '@start9labs/start-sdk'
import {
PackageDataEntry,
PackageMainStatus,
PackageState,
} from 'src/app/services/patch-db/data-model'
type HostnameInfoIp = types.HostnameInfoIp
type HostnameInfoOnion = types.HostnameInfoOnion
const {
gitHash,
useMocks,
@@ -87,10 +84,8 @@ export class ConfigService {
}
/** ${scheme}://${username}@${host}:${externalPort}${suffix} */
launchableAddress(interfaces: PackageDataEntry['serviceInterfaces']): string {
const ui = Object.values(interfaces).find(i => i.type === 'ui')
if (!ui) return ''
launchableAddress(ui: T.ServiceInterfaceWithHostInfo): string {
if (ui.type !== 'ui') return ''
const host = ui.hostInfo
const addressInfo = ui.addressInfo
@@ -102,14 +97,14 @@ export class ConfigService {
if (host.kind === 'multi') {
const onionHostname = host.hostnames.find(
(h: any) => h.kind === 'onion',
) as HostnameInfoOnion
) as T.HostnameInfoOnion
if (this.isTor() && onionHostname) {
url.hostname = onionHostname.hostname.value
} else {
const ipHostname = host.hostnames.find(
(h: any) => h.kind === 'ip',
) as HostnameInfoIp
) as T.HostnameInfoIp
if (!ipHostname) return ''

View File

@@ -30,7 +30,7 @@ import {
unionSelectKey,
unionValueKey,
isValueSpecListOf,
} from '@start9labs/start-sdk/lib/config/configTypes'
} from '@start9labs/start-sdk/cjs/sdk/lib/config/configTypes'
const Mustache = require('mustache')
@Injectable({

View File

@@ -1,15 +1,13 @@
import { BackupJob, ServerNotifications } from '../api/api.types'
import { Url } from '@start9labs/shared'
import { Manifest } from '@start9labs/marketplace'
import { types } from '@start9labs/start-sdk'
import { T } from '@start9labs/start-sdk'
import {
ActionMetadata,
HostnameInfo,
} from '@start9labs/start-sdk/cjs/sdk/lib/types'
import { customSmtp } from '@start9labs/start-sdk/cjs/sdk/lib/config/configConstants'
type ServiceInterfaceWithHostInfo = types.ServiceInterfaceWithHostInfo
export interface DataModel {
serverInfo: ServerInfo
packageData: { [id: string]: PackageDataEntry }
@@ -87,11 +85,7 @@ export type NetworkInfo = {
forwards: PortForward[]
}
proxies: Proxy[]
outboundProxy: OsOutboundProxy
primaryProxies: {
inbound: string | null
outbound: string | null
}
outboundProxy: string | null
}
export type DomainInfo = {
@@ -99,10 +93,6 @@ export type DomainInfo = {
subdomain: string | null
}
export type InboundProxy = { proxyId: string } | 'primary' | null
export type OsOutboundProxy = InboundProxy
export type ServiceOutboundProxy = OsOutboundProxy | 'mirror'
export type PortForward = {
assigned: number
override: number | null
@@ -127,7 +117,7 @@ export type Domain = {
}
export type NetworkStrategy =
| { proxyId: string | null } // null means system primary
| { proxy: string }
| { ipStrategy: 'ipv4' | 'ipv6' | 'dualstack' }
export type Proxy = {
@@ -141,8 +131,6 @@ export type Proxy = {
services: { id: string | null; title: string }[] // implies outbound - null means startos
domains: string[] // implies inbound
}
primaryInbound: boolean
primaryOutbound: boolean
}
export interface IpInfo {
@@ -164,12 +152,6 @@ export interface ServerStatusInfo {
shuttingDown: boolean
}
export enum ServerStatus {
Running = 'running',
Updated = 'updated',
BackingUp = 'backing-up',
}
export type PackageDataEntry<T extends StateInfo = StateInfo> = {
stateInfo: T
icon: Url
@@ -183,10 +165,11 @@ export type PackageDataEntry<T extends StateInfo = StateInfo> = {
icon: Url
}
}
serviceInterfaces: Record<string, ServiceInterfaceWithHostInfo>
serviceInterfaces: Record<string, T.ServiceInterfaceWithHostInfo>
marketplaceUrl: string | null
developerKey: string
outboundProxy: ServiceOutboundProxy
installedAt: string
outboundProxy: string | null
}
export type StateInfo = InstalledState | InstallingState | UpdatingState
@@ -194,11 +177,13 @@ export type StateInfo = InstalledState | InstallingState | UpdatingState
export type InstalledState = {
state: PackageState.Installed | PackageState.Removing
manifest: Manifest
installingInfo?: undefined
}
export type InstallingState = {
state: PackageState.Installing | PackageState.Restoring
installingInfo: InstallingInfo
manifest?: undefined
}
export type UpdatingState = {

View File

@@ -52,10 +52,6 @@ function getHealthStatus(status: Status): HealthStatus | null {
const values = Object.values(status.main.health)
if (values.some(h => !h.result)) {
return HealthStatus.Waiting
}
if (values.some(h => h.result === 'failure')) {
return HealthStatus.Failure
}
@@ -101,7 +97,6 @@ export enum DependencyStatus {
export enum HealthStatus {
Failure = 'failure',
Waiting = 'waiting',
Starting = 'starting',
Loading = 'loading',
Healthy = 'healthy',

View File

@@ -1,8 +1,5 @@
import { Injectable } from '@angular/core'
import { ErrorService, LoadingService } from '@start9labs/shared'
import { Config } from '@start9labs/start-sdk/lib/config/builder/config'
import { Value } from '@start9labs/start-sdk/lib/config/builder/value'
import { Variants } from '@start9labs/start-sdk/lib/config/builder/variants'
import { TuiDialogOptions } from '@taiga-ui/core'
import { PatchDB } from 'patch-db-client'
import { firstValueFrom } from 'rxjs'
@@ -13,11 +10,9 @@ import {
import { FormDialogService } from 'src/app/services/form-dialog.service'
import { configBuilderToSpec } from 'src/app/util/configBuilderToSpec'
import { ApiService } from './api/embassy-api.service'
import {
DataModel,
OsOutboundProxy,
ServiceOutboundProxy,
} from './patch-db/data-model'
import { DataModel } from './patch-db/data-model'
import { Config } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/config'
import { Value } from '@start9labs/start-sdk/cjs/sdk/lib/config/builder/value'
@Injectable({
providedIn: 'root',
@@ -31,84 +26,25 @@ export class ProxyService {
private readonly errorService: ErrorService,
) {}
async presentModalSetOutboundProxy(serviceContext?: {
packageId: string
outboundProxy: ServiceOutboundProxy
hasP2P: boolean
}) {
async presentModalSetOutboundProxy(current: string | null, pkgId?: string) {
const network = await firstValueFrom(
this.patch.watch$('server-info', 'network'),
this.patch.watch$('serverInfo', 'network'),
)
const outboundProxy = serviceContext?.outboundProxy
const defaultValue = !outboundProxy
? 'none'
: outboundProxy === 'primary'
? 'primary'
: outboundProxy === 'mirror'
? 'mirror'
: 'other'
let variants: Record<string, { name: string; spec: Config<any> }> = {}
if (serviceContext) {
variants['mirror'] = {
name: 'Mirror P2P Interface',
spec: Config.of({}),
}
}
variants = {
...variants,
primary: {
name: 'Use System Primary',
spec: Config.of({}),
},
other: {
name: 'Other',
spec: Config.of({
proxyId: Value.select({
name: 'Select Specific Proxy',
required: {
default:
outboundProxy && typeof outboundProxy !== 'string'
? outboundProxy.proxyId
: null,
},
values: network.proxies
.filter(
p => p.type === 'outbound' || p.type === 'inbound-outbound',
)
.reduce((prev, curr) => {
return {
[curr.id]: curr.name,
...prev,
}
}, {}),
}),
}),
},
none: {
name: 'None',
spec: Config.of({}),
},
}
const config = Config.of({
proxy: Value.union(
{
name: 'Select Proxy',
required: { default: defaultValue },
description: `
<h5>Use System Primary</h5>The primary <i>inbound</i> proxy will be used. If you do not have a primary inbound proxy, no proxy will be used
<h5>Mirror Primary Interface</h5>If you have an inbound proxy enabled for the primary interface, outbound traffic will flow through the same proxy
<h5>Other</h5>The specific proxy you select will be used, overriding the default
`,
disabled: serviceContext?.hasP2P ? [] : ['mirror'],
},
Variants.of(variants),
),
proxyId: Value.select({
name: 'Select Proxy',
required: { default: current },
values: network.proxies
.filter(
p => p.type === 'outbound' || p.type === 'inbound-outbound',
)
.reduce((prev, curr) => {
return {
[curr.id]: curr.name,
...prev,
}
}, {}),
}),
})
const options: Partial<
@@ -125,15 +61,7 @@ export class ProxyService {
{
text: 'Save',
handler: async value => {
const proxy =
value.proxy.unionSelectKey === 'none'
? null
: value.proxy.unionSelectKey === 'primary'
? 'primary'
: value.proxy.unionSelectKey === 'mirror'
? 'mirror'
: { proxyId: value.proxy.unionValueKey.proxyId }
await this.saveOutboundProxy(proxy, serviceContext?.packageId)
await this.saveOutboundProxy(value.proxyId, pkgId)
return true
},
},
@@ -144,7 +72,7 @@ export class ProxyService {
}
private async saveOutboundProxy(
proxy: OsOutboundProxy | ServiceOutboundProxy,
proxy: string | null,
packageId?: string,
) {
const loader = this.loader.open(`Saving`).subscribe()
@@ -153,7 +81,7 @@ export class ProxyService {
if (packageId) {
await this.api.setServiceOutboundProxy({ packageId, proxy })
} else {
await this.api.setOsOutboundProxy({ proxy: proxy as OsOutboundProxy })
await this.api.setOsOutboundProxy({ proxy })
}
} catch (e: any) {
this.errorService.handleError(e)