Market over embassy (#404)

* marketplace proxy'd through embassy

* http not rpc

* fix up marketplace
This commit is contained in:
Drew Ansbacher
2021-08-12 10:49:41 -06:00
committed by Aiden McClelland
parent 73526976a1
commit 7661626a94
14 changed files with 116 additions and 713 deletions

View File

@@ -5,6 +5,7 @@ import { ConfigService } from '../config.service'
import { PatchDbService } from '../patch-db/patch-db.service'
import { MarketplaceLiveApiService } from './marketplace/marketplace-live-api.service'
import { MarketplaceMockApiService } from './marketplace/marketplace-mock-api.service'
import { ApiService } from './embassy/embassy-api.service'
export function ApiServiceFactory (config: ConfigService, http: HttpService) {
if (config.mocks.enabled) {
@@ -14,10 +15,10 @@ export function ApiServiceFactory (config: ConfigService, http: HttpService) {
}
}
export function MarketplaceApiServiceFactory (config: ConfigService, http: HttpService, patch: PatchDbService) {
export function MarketplaceApiServiceFactory (config: ConfigService, patch: PatchDbService, apiService: ApiService) {
if (config.mocks.enabled) {
return new MarketplaceMockApiService(http, config, patch)
return new MarketplaceMockApiService(config, patch)
} else {
return new MarketplaceLiveApiService(http, config, patch)
return new MarketplaceLiveApiService(apiService, config, patch)
}
}

View File

@@ -2,7 +2,7 @@ import { Subject, Observable } from 'rxjs'
import { Http, Update, Operation, Revision, Source, Store } from 'patch-db-client'
import { RR } from '../api.types'
import { DataModel } from 'src/app/services/patch-db/data-model'
import { RequestError, RPCError } from '../../http.service'
import { Method, RequestError } from '../../http.service'
export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
protected readonly sync = new Subject<Update<DataModel>>()
@@ -65,10 +65,7 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
// marketplace URLs
protected abstract setEosMarketplaceRaw (isTor: boolean): Promise<RR.SetEosMarketplaceRes>
setEosMarketplace = (isTor: boolean) => this.syncResponse(
() => this.setEosMarketplaceRaw(isTor),
)()
abstract marketplaceProxy (url: string, params: { [key: string]: any }): Promise<any>
// protected abstract setPackageMarketplaceRaw (params: RR.SetPackageMarketplaceReq): Promise<RR.SetPackageMarketplaceRes>
// setPackageMarketplace = (params: RR.SetPackageMarketplaceReq) => this.syncResponse(

View File

@@ -87,11 +87,12 @@ export class LiveApiService extends ApiService {
// marketplace URLs
async setEosMarketplaceRaw (isTor: boolean): Promise<RR.SetEosMarketplaceRes> {
const params: RR.SetEosMarketplaceReq = {
url: isTor ? this.config.start9Marketplace.tor : this.config.start9Marketplace.clearnet,
}
return this.http.rpcRequest({ method: 'marketplace.eos.set', params })
async marketplaceProxy (url: string, params: { [key: string]: any }) {
return this.http.httpRequest({
method: Method.GET,
url,
params,
})
}
// async setPackageMarketplaceRaw (params: RR.SetPackageMarketplaceReq): Promise<RR.SetPackageMarketplaceRes> {
@@ -105,130 +106,130 @@ export class LiveApiService extends ApiService {
// notification
async getNotificationsRaw (params: RR.GetNotificationsReq): Promise<RR.GetNotificationsRes> {
async getNotificationsRaw (params: RR.GetNotificationsReq): Promise < RR.GetNotificationsRes > {
return this.http.rpcRequest({ method: 'notification.list', params })
}
async deleteNotification (params: RR.DeleteNotificationReq): Promise<RR.DeleteNotificationRes> {
async deleteNotification (params: RR.DeleteNotificationReq): Promise < RR.DeleteNotificationRes > {
return this.http.rpcRequest({ method: 'notification.delete', params })
}
async deleteAllNotifications (params: RR.DeleteAllNotificationsReq): Promise<RR.DeleteAllNotificationsRes> {
async deleteAllNotifications (params: RR.DeleteAllNotificationsReq): Promise < RR.DeleteAllNotificationsRes > {
return this.http.rpcRequest({ method: 'notification.delete.all', params })
}
// wifi
async addWifi (params: RR.AddWifiReq): Promise<RR.AddWifiRes> {
async addWifi (params: RR.AddWifiReq): Promise < RR.AddWifiRes > {
return this.http.rpcRequest({ method: 'wifi.add', params })
}
async connectWifiRaw (params: RR.ConnectWifiReq): Promise<RR.ConnectWifiRes> {
async connectWifiRaw (params: RR.ConnectWifiReq): Promise < RR.ConnectWifiRes > {
return this.http.rpcRequest({ method: 'wifi.connect', params })
}
async deleteWifiRaw (params: RR.DeleteWifiReq): Promise<RR.DeleteWifiRes> {
async deleteWifiRaw (params: RR.DeleteWifiReq): Promise < RR.DeleteWifiRes > {
return this.http.rpcRequest({ method: 'wifi.delete', params })
}
// ssh
async getSshKeys (params: RR.GetSSHKeysReq): Promise<RR.GetSSHKeysRes> {
async getSshKeys (params: RR.GetSSHKeysReq): Promise < RR.GetSSHKeysRes > {
return this.http.rpcRequest({ method: 'ssh.get', params })
}
async addSshKey (params: RR.AddSSHKeyReq): Promise<RR.AddSSHKeyRes> {
async addSshKey (params: RR.AddSSHKeyReq): Promise < RR.AddSSHKeyRes > {
return this.http.rpcRequest({ method: 'ssh.add', params })
}
async deleteSshKey (params: RR.DeleteSSHKeyReq): Promise<RR.DeleteSSHKeyRes> {
async deleteSshKey (params: RR.DeleteSSHKeyReq): Promise < RR.DeleteSSHKeyRes > {
return this.http.rpcRequest({ method: 'ssh.delete', params })
}
// backup
async createBackupRaw (params: RR.CreateBackupReq): Promise<RR.CreateBackupRes> {
async createBackupRaw (params: RR.CreateBackupReq): Promise < RR.CreateBackupRes > {
return this.http.rpcRequest({ method: 'backup.create', params })
}
async restoreBackupRaw (params: RR.RestoreBackupReq): Promise<RR.RestoreBackupRes> {
async restoreBackupRaw (params: RR.RestoreBackupReq): Promise < RR.RestoreBackupRes > {
return this.http.rpcRequest({ method: 'backup.restore', params })
}
// disk
getDisks (params: RR.GetDisksReq): Promise<RR.GetDisksRes> {
getDisks (params: RR.GetDisksReq): Promise < RR.GetDisksRes > {
return this.http.rpcRequest({ method: 'disk.list', params })
}
ejectDisk (params: RR.EjectDisksReq): Promise<RR.EjectDisksRes> {
ejectDisk (params: RR.EjectDisksReq): Promise < RR.EjectDisksRes > {
return this.http.rpcRequest({ method: 'disk.eject', params })
}
// package
async getPackageProperties (params: RR.GetPackagePropertiesReq): Promise<RR.GetPackagePropertiesRes<any>['data']> {
async getPackageProperties (params: RR.GetPackagePropertiesReq): Promise < RR.GetPackagePropertiesRes < any > ['data'] > {
return this.http.rpcRequest({ method: 'package.properties', params })
.then(parsePropertiesPermissive)
}
async getPackageLogs (params: RR.GetPackageLogsReq): Promise<RR.GetPackageLogsRes> {
async getPackageLogs (params: RR.GetPackageLogsReq): Promise < RR.GetPackageLogsRes > {
return this.http.rpcRequest( { method: 'package.logs', params })
}
async getPkgMetrics (params: RR.GetPackageMetricsReq): Promise<RR.GetPackageMetricsRes> {
async getPkgMetrics (params: RR.GetPackageMetricsReq): Promise < RR.GetPackageMetricsRes > {
return this.http.rpcRequest({ method: 'package.metrics', params })
}
async installPackageRaw (params: RR.InstallPackageReq): Promise<RR.InstallPackageRes> {
async installPackageRaw (params: RR.InstallPackageReq): Promise < RR.InstallPackageRes > {
return this.http.rpcRequest({ method: 'package.install', params })
}
async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise<RR.DryUpdatePackageRes> {
async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise < RR.DryUpdatePackageRes > {
return this.http.rpcRequest({ method: 'package.update.dry', params })
}
async getPackageConfig (params: RR.GetPackageConfigReq): Promise<RR.GetPackageConfigRes> {
async getPackageConfig (params: RR.GetPackageConfigReq): Promise < RR.GetPackageConfigRes > {
return this.http.rpcRequest({ method: 'package.config.get', params })
}
async drySetPackageConfig (params: RR.DrySetPackageConfigReq): Promise<RR.DrySetPackageConfigRes> {
async drySetPackageConfig (params: RR.DrySetPackageConfigReq): Promise < RR.DrySetPackageConfigRes > {
return this.http.rpcRequest({ method: 'package.config.set.dry', params })
}
async setPackageConfigRaw (params: RR.SetPackageConfigReq): Promise<RR.SetPackageConfigRes> {
async setPackageConfigRaw (params: RR.SetPackageConfigReq): Promise < RR.SetPackageConfigRes > {
return this.http.rpcRequest({ method: 'package.config.set', params })
}
async restorePackageRaw (params: RR.RestorePackageReq): Promise<RR.RestorePackageRes> {
async restorePackageRaw (params: RR.RestorePackageReq): Promise < RR.RestorePackageRes > {
return this.http.rpcRequest({ method: 'package.restore', params })
}
async executePackageAction (params: RR.ExecutePackageActionReq): Promise<RR.ExecutePackageActionRes> {
async executePackageAction (params: RR.ExecutePackageActionReq): Promise < RR.ExecutePackageActionRes > {
return this.http.rpcRequest({ method: 'package.action', params })
}
async startPackageRaw (params: RR.StartPackageReq): Promise<RR.StartPackageRes> {
async startPackageRaw (params: RR.StartPackageReq): Promise < RR.StartPackageRes > {
return this.http.rpcRequest({ method: 'package.start', params })
}
async dryStopPackage (params: RR.DryStopPackageReq): Promise<RR.DryStopPackageRes> {
async dryStopPackage (params: RR.DryStopPackageReq): Promise < RR.DryStopPackageRes > {
return this.http.rpcRequest({ method: 'package.stop.dry', params })
}
async stopPackageRaw (params: RR.StopPackageReq): Promise<RR.StopPackageRes> {
async stopPackageRaw (params: RR.StopPackageReq): Promise < RR.StopPackageRes > {
return this.http.rpcRequest({ method: 'package.stop', params })
}
async dryRemovePackage (params: RR.DryRemovePackageReq): Promise<RR.DryRemovePackageRes> {
async dryRemovePackage (params: RR.DryRemovePackageReq): Promise < RR.DryRemovePackageRes > {
return this.http.rpcRequest({ method: 'package.remove.dry', params })
}
async removePackageRaw (params: RR.RemovePackageReq): Promise<RR.RemovePackageRes> {
async removePackageRaw (params: RR.RemovePackageReq): Promise < RR.RemovePackageRes > {
return this.http.rpcRequest({ method: 'package.remove', params })
}
async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise<RR.DryConfigureDependencyRes> {
async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise < RR.DryConfigureDependencyRes > {
return this.http.rpcRequest({ method: 'package.dependency.configure.dry', params })
}
}

View File

@@ -147,19 +147,8 @@ export class MockApiService extends ApiService {
// marketplace URLs
async setEosMarketplaceRaw (isTor: boolean): Promise<RR.SetEosMarketplaceRes> {
await pauseFor(2000)
const params: RR.SetEosMarketplaceReq = {
url: isTor ? this.config.start9Marketplace.tor : this.config.start9Marketplace.clearnet,
}
const patch = [
{
op: PatchOp.REPLACE,
path: '/server-info/eos-marketplace',
value: params.url,
},
]
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
async marketplaceProxy (params) {
return null
}
// async setPackageMarketplaceRaw (params: RR.SetPackageMarketplaceReq): Promise<RR.SetPackageMarketplaceRes> {

View File

@@ -32,17 +32,4 @@ export abstract class MarketplaceApiService {
abstract getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes>
abstract getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes>
getMarketplaceURL (type: 'eos' | 'package', defaultToTor = false): string {
const packageMarketplace = this.server['package-marketplace']
if (defaultToTor && !packageMarketplace) {
return this.config.start9Marketplace.tor
}
const eosMarketplace = this.server['eos-marketplace'] || this.config.start9Marketplace.clearnet
if (type === 'eos') {
return eosMarketplace
} else {
return packageMarketplace || eosMarketplace
}
}
}

View File

@@ -1,71 +1,39 @@
import { Injectable } from '@angular/core'
import { HttpService, Method } from '../../http.service'
import { Method } from '../../http.service'
import { RR } from '../api.types'
import { MarketplaceApiService } from './marketplace-api.service'
import { PatchDbService } from '../../patch-db/patch-db.service'
import { ConfigService } from '../../config.service'
import { ApiService } from '../embassy/embassy-api.service'
@Injectable()
export class MarketplaceLiveApiService extends MarketplaceApiService {
constructor (
private readonly http: HttpService,
private readonly embassyApiService: ApiService,
config: ConfigService,
patch: PatchDbService,
) {
super(config, patch)
super( config, patch)
}
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
const url = this.getMarketplaceURL('eos')
return this.http.httpRequest<RR.GetMarketplaceEOSRes>({
method: Method.GET,
url: url + '/eos',
params,
withCredentials: false,
})
return this.embassyApiService.marketplaceProxy('/marketplace/eos', params)
}
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
const url = this.getMarketplaceURL('package')
return this.http.httpRequest<RR.GetMarketplaceDataRes>({
method: Method.GET,
url: url + '/data',
params,
withCredentials: false,
})
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise < RR.GetMarketplaceDataRes > {
return this.embassyApiService.marketplaceProxy('/marketplace/package/data', params)
}
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
const url = this.getMarketplaceURL('package', params.ids?.length > 1)
return this.http.httpRequest<RR.GetMarketplacePackagesRes>({
method: Method.GET,
url: url + '/packages',
params: {
...params,
ids: JSON.stringify(params.ids),
},
withCredentials: false,
})
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise < RR.GetMarketplacePackagesRes > {
return this.embassyApiService.marketplaceProxy('/marketplace/package/packages', { ...params, ids: JSON.stringify(params.ids) })
}
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
const url = this.getMarketplaceURL('package')
return this.http.httpRequest<RR.GetReleaseNotesRes>({
method: Method.GET,
url: url + + '/release-notes',
params,
withCredentials: false,
})
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise < RR.GetReleaseNotesRes > {
return this.embassyApiService.marketplaceProxy('/marketplace/package/release-notes', params)
}
async getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes> {
const url = this.getMarketplaceURL('package', params.ids?.length > 1)
return this.http.httpRequest<RR.GetLatestVersionRes>({
method: Method.GET,
url: url + '/latest-version',
params,
withCredentials: false,
})
async getLatestVersion (params: RR.GetLatestVersionReq): Promise < RR.GetLatestVersionRes > {
return this.embassyApiService.marketplaceProxy('/marketplace/package/latest-version', params)
}
}

View File

@@ -2,7 +2,6 @@ import { Injectable } from '@angular/core'
import { pauseFor } from '../../../util/misc.util'
import { RR } from '../api.types'
import { Mock } from '../api.fixures'
import { HttpService, Method } from '../../http.service'
import { MarketplaceApiService } from './marketplace-api.service'
import { PatchDbService } from '../../patch-db/patch-db.service'
import { ConfigService } from '../../config.service'
@@ -10,7 +9,6 @@ import { ConfigService } from '../../config.service'
@Injectable()
export class MarketplaceMockApiService extends MarketplaceApiService {
constructor (
private readonly http: HttpService,
config: ConfigService,
patch: PatchDbService,
) {
@@ -20,85 +18,32 @@ export class MarketplaceMockApiService extends MarketplaceApiService {
// marketplace
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
const url = this.getMarketplaceURL('eos')
if (this.useLocal(url)) {
await pauseFor(2000)
return Mock.MarketplaceEos
}
return this.http.httpRequest<RR.GetMarketplaceEOSRes>({
method: Method.GET,
url: `${url}/eos`,
params,
withCredentials: false,
})
await pauseFor(2000)
return Mock.MarketplaceEos
}
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
const url = this.getMarketplaceURL('package')
if (this.useLocal(url)) {
await pauseFor(2000)
return {
categories: ['featured', 'bitcoin', 'lightning', 'data', 'messaging', 'social', 'alt coin'],
}
await pauseFor(2000)
return {
categories: ['featured', 'bitcoin', 'lightning', 'data', 'messaging', 'social', 'alt coin'],
}
return this.http.httpRequest<RR.GetMarketplaceDataRes>({
method: Method.GET,
url: `${url}/data`,
params,
withCredentials: false,
})
}
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
const url = this.getMarketplaceURL('package', params.ids?.length > 1)
if (this.useLocal(url)) {
await pauseFor(2000)
return Mock.MarketplacePkgsList
}
return this.http.httpRequest<RR.GetMarketplacePackagesRes>({
method: Method.GET,
url: `${url}/packages`,
params: {
...params,
ids: JSON.stringify(params.ids),
},
withCredentials: false,
})
await pauseFor(2000)
return Mock.MarketplacePkgsList
}
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
const url = this.getMarketplaceURL('package')
if (this.useLocal(url)) {
await pauseFor(2000)
return Mock.ReleaseNotes
}
return this.http.httpRequest<RR.GetReleaseNotesRes>({
method: Method.GET,
url: `${url}/release-notes`,
params,
withCredentials: false,
})
await pauseFor(2000)
return Mock.ReleaseNotes
}
async getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes> {
const url = this.getMarketplaceURL('package', params.ids?.length > 1)
if (this.useLocal(url)) {
await pauseFor(2000)
return params.ids.reduce((obj, id) => {
obj[id] = this.patch.getData()['package-data']?.[id]?.manifest.version.replace('0', '1')
return obj
}, { })
}
return this.http.httpRequest<RR.GetLatestVersionRes>({
method: Method.GET,
url: `${url}/latest-version`,
params,
withCredentials: false,
})
}
private useLocal (url: string): boolean {
return !url || this.config.mocks.marketplace
await pauseFor(2000)
return params.ids.reduce((obj, id) => {
obj[id] = this.patch.getData()['package-data']?.[id]?.manifest.version.replace('0', '1')
return obj
}, { })
}
}

View File

@@ -1,13 +1,9 @@
import { Injectable } from '@angular/core'
import { InterfaceDef, PackageDataEntry, PackageMainStatus, PackageState } from './patch-db/data-model'
const { start9Marketplace, patchDb, api, mocks } = require('../../../config.json') as UiConfig
const { patchDb, api, mocks } = require('../../../config.json') as UiConfig
type UiConfig = {
start9Marketplace: {
clearnet: string
tor: string
}
patchDb: {
poll: {
cooldown: number /* in ms */
@@ -19,7 +15,6 @@ type UiConfig = {
}
mocks: {
enabled: boolean
marketplace: boolean
connection: 'ws' | 'poll'
rpcPort: number
wsPort: number
@@ -35,7 +30,6 @@ export class ConfigService {
origin = removePort(removeProtocol(window.origin))
version = require('../../../package.json').version
start9Marketplace = start9Marketplace
patchDb = patchDb
api = api
mocks = mocks

View File

@@ -111,9 +111,9 @@ export class ServerConfigService {
ssh: async (pubkey: string) => {
return this.sshService.add(pubkey)
},
'eos-marketplace': async (enabled: boolean) => {
return this.embassyApi.setEosMarketplace(enabled)
},
// 'eos-marketplace': async () => {
// return this.embassyApi.setEosMarketplace()
// },
// 'package-marketplace': async (url: string) => {
// return this.embassyApi.setPackageMarketplace({ url })
// },
@@ -144,13 +144,13 @@ export const serverConfig: ConfigSpec = {
masked: false,
copyable: false,
},
'eos-marketplace': {
type: 'boolean',
name: 'Tor Only Marketplace',
description: `Use Start9's Tor (instead of clearnet) Marketplace.`,
'change-warning': 'This will result in higher latency and slower download times.',
default: false,
},
// 'eos-marketplace': {
// type: 'boolean',
// name: 'Tor Only Marketplace',
// description: `Use Start9's Tor (instead of clearnet) Marketplace.`,
// 'change-warning': 'This will result in higher latency and slower download times.',
// default: false,
// },
// 'package-marketplace': {
// type: 'string',
// name: 'Package Marketplace',