refine startup alerts, reversions in mocks

This commit is contained in:
Matt Hill
2021-07-16 17:58:53 -06:00
committed by Aiden McClelland
parent 3ddfcd7895
commit 65c4db09f3
18 changed files with 473 additions and 314 deletions

View File

@@ -1,12 +1,15 @@
import { DependencyErrorType, DockerIoFormat, Manifest, PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
import { MarketplacePkg, Metric, NotificationLevel, RR, ServerNotification, ServerNotifications } from './api.types'
import { DockerIoFormat, Manifest, PackageDataEntry, PackageMainStatus, PackageState } from 'src/app/services/patch-db/data-model'
import { MarketplacePkg, Metric, NotificationLevel, RR, ServerNotifications } from './api.types'
export module Mock {
export const MarketplaceEos: RR.GetMarketplaceEOSRes = {
version: '1.0.0',
version: '0.3.1',
headline: 'Our biggest release ever.',
'release-notes': { '1.0.0': 'Some **Markdown** release _notes_' },
'release-notes': {
'0.3.1': 'Some **Markdown** release _notes_ for 0.3.1',
'0.3.0': 'Some **Markdown** release _notes_ from a prior version',
},
}
export const ReleaseNotes: RR.GetReleaseNotesRes = {
@@ -375,7 +378,7 @@ export module Mock {
},
}
export const AvailableShow: {
export const MarketplacePkgs: {
[id: string]: {
[version: string]: MarketplacePkg
}
@@ -513,108 +516,7 @@ export module Mock {
},
}
export const AvailableList: RR.GetMarketplacePackagesRes = Object.values(Mock.AvailableShow).map(service => service['latest'])
export const bitcoind: PackageDataEntry = {
state: PackageState.Installed,
'static-files': {
license: 'licenseUrl', // /public/package-data/bitcoind/0.21.1/LICENSE.md,
icon: 'assets/img/service-icons/bitcoind.png',
instructions: 'instructionsUrl', // /public/package-data/bitcoind/0.21.1/INSTRUCTIONS.md
},
manifest: {
...MockManifestBitcoind,
version: '0.20.0',
},
installed: {
status: {
configured: true,
main: {
status: PackageMainStatus.Running,
started: new Date().toISOString(),
health: { },
},
'dependency-errors': { },
},
'interface-info': {
ip: '10.0.0.1',
addresses: {
ui: {
'tor-address': 'bitcoind-ui-address.onion',
'lan-address': 'bitcoind-ui-address.local',
},
rpc: {
'tor-address': 'bitcoind-rpc-address.onion',
'lan-address': 'bitcoind-rpc-address.local',
},
p2p: {
'tor-address': 'bitcoind-p2p-address.onion',
'lan-address': 'bitcoind-p2p-address.local',
},
},
},
'system-pointers': [],
'current-dependents': {
'lnd': {
pointers: [],
'health-checks': [],
},
},
'current-dependencies': { },
},
'install-progress': undefined,
}
export const lnd: PackageDataEntry = {
state: PackageState.Installed,
'static-files': {
license: 'licenseUrl', // /public/package-data/lnd/0.21.1/LICENSE.md,
icon: 'assets/img/service-icons/lnd.png',
instructions: 'instructionsUrl', // /public/package-data/lnd/0.21.1/INSTRUCTIONS.md
},
manifest: MockManifestLnd,
installed: {
status: {
configured: true,
main: {
status: PackageMainStatus.Stopped,
},
'dependency-errors': {
'bitcoin-proxy': {
type: DependencyErrorType.NotInstalled,
title: Mock.MockManifestBitcoinProxy.title,
icon: 'assets/img/service-icons/bitcoin-proxy.png',
},
},
},
'interface-info': {
ip: '10.0.0.1',
addresses: {
rpc: {
'tor-address': 'lnd-rpc-address.onion',
'lan-address': 'lnd-rpc-address.local',
},
grpc: {
'tor-address': 'lnd-grpc-address.onion',
'lan-address': 'lnd-grpc-address.local',
},
},
},
'system-pointers': [],
'current-dependents': { },
'current-dependencies': {
'bitcoind': {
pointers: [],
'health-checks': [],
},
'bitcoin-proxy': {
pointers: [],
'health-checks': [],
},
},
},
'install-progress': undefined,
}
export const MarketplacePkgsList: RR.GetMarketplacePackagesRes = Object.values(Mock.MarketplacePkgs).map(service => service['latest'])
export const bitcoinproxy: PackageDataEntry = {
state: PackageState.Installed,
@@ -660,68 +562,27 @@ export module Mock {
'install-progress': undefined,
}
export const DbDump: RR.GetDumpRes = {
id: 1,
expireId: null,
value: {
'server-info': {
id: 'start9-abcdefgmm',
version: '1.0.0',
status: ServerStatus.Running,
'lan-address': 'start9-abcdefgh.local',
'tor-address': 'myveryownspecialtoraddress.onion',
wifi: {
ssids: ['Goosers', 'Goosers5G'],
selected: 'Goosers5G',
connected: 'Goosers5G',
},
'package-marketplace': 'https://registry.start9.com',
'eos-marketplace': 'https://registry.start9.com',
'unread-notification-count': 4,
specs: {
CPU: 'Cortex-A72: 4 Cores @1500MHz',
Disk: '1TB SSD',
Memory: '8GB',
},
'connection-addresses': {
tor: [],
clearnet: [],
},
},
'package-data': {
'bitcoind': bitcoind,
'lnd': lnd,
},
ui: {
'welcome-ack': '1.0.0',
'auto-check-updates': true,
},
},
}
export const notification1: ServerNotification<1> = {
id: '123e4567-e89b-12d3-a456-426655440000',
'package-id': null,
'created-at': '2019-12-26T14:20:30.872Z',
code: 1,
level: NotificationLevel.Success,
title: 'Backup Complete',
message: 'Embassy and services have been successfully backed up.',
data: {
server: {
attempted: true,
error: null,
},
packages: {
'bitcoind': {
export const Notifications: ServerNotifications = [
{
id: '123e4567-e89b-12d3-a456-426655440000',
'package-id': null,
'created-at': '2019-12-26T14:20:30.872Z',
code: 1,
level: NotificationLevel.Success,
title: 'Backup Complete',
message: 'Embassy and services have been successfully backed up.',
data: {
server: {
attempted: true,
error: null,
},
packages: {
'bitcoind': {
error: null,
},
},
},
},
}
export const Notifications: ServerNotifications = [
notification1,
{
id: '123e4567-e89b-12d3-a456-426655440001',
'package-id': 'bitcoind',
@@ -1435,4 +1296,144 @@ export module Mock {
rpcallowip: [],
rpcauth: ['matt: 8273gr8qwoidm1uid91jeh8y23gdio1kskmwejkdnm'],
}
// export const bitcoind: PackageDataEntry = {
// state: PackageState.Installed,
// 'static-files': {
// license: 'licenseUrl', // /public/package-data/bitcoind/0.21.1/LICENSE.md,
// icon: 'assets/img/service-icons/bitcoind.png',
// instructions: 'instructionsUrl', // /public/package-data/bitcoind/0.21.1/INSTRUCTIONS.md
// },
// manifest: {
// ...MockManifestBitcoind,
// version: '0.20.0',
// },
// installed: {
// status: {
// configured: true,
// main: {
// status: PackageMainStatus.Running,
// started: new Date().toISOString(),
// health: { },
// },
// 'dependency-errors': { },
// },
// 'interface-info': {
// ip: '10.0.0.1',
// addresses: {
// ui: {
// 'tor-address': 'bitcoind-ui-address.onion',
// 'lan-address': 'bitcoind-ui-address.local',
// },
// rpc: {
// 'tor-address': 'bitcoind-rpc-address.onion',
// 'lan-address': 'bitcoind-rpc-address.local',
// },
// p2p: {
// 'tor-address': 'bitcoind-p2p-address.onion',
// 'lan-address': 'bitcoind-p2p-address.local',
// },
// },
// },
// 'system-pointers': [],
// 'current-dependents': {
// 'lnd': {
// pointers: [],
// 'health-checks': [],
// },
// },
// 'current-dependencies': { },
// },
// 'install-progress': undefined,
// }
// export const lnd: PackageDataEntry = {
// state: PackageState.Installed,
// 'static-files': {
// license: 'licenseUrl', // /public/package-data/lnd/0.21.1/LICENSE.md,
// icon: 'assets/img/service-icons/lnd.png',
// instructions: 'instructionsUrl', // /public/package-data/lnd/0.21.1/INSTRUCTIONS.md
// },
// manifest: MockManifestLnd,
// installed: {
// status: {
// configured: true,
// main: {
// status: PackageMainStatus.Stopped,
// },
// 'dependency-errors': {
// 'bitcoin-proxy': {
// type: DependencyErrorType.NotInstalled,
// title: Mock.MockManifestBitcoinProxy.title,
// icon: 'assets/img/service-icons/bitcoin-proxy.png',
// },
// },
// },
// 'interface-info': {
// ip: '10.0.0.1',
// addresses: {
// rpc: {
// 'tor-address': 'lnd-rpc-address.onion',
// 'lan-address': 'lnd-rpc-address.local',
// },
// grpc: {
// 'tor-address': 'lnd-grpc-address.onion',
// 'lan-address': 'lnd-grpc-address.local',
// },
// },
// },
// 'system-pointers': [],
// 'current-dependents': { },
// 'current-dependencies': {
// 'bitcoind': {
// pointers: [],
// 'health-checks': [],
// },
// 'bitcoin-proxy': {
// pointers: [],
// 'health-checks': [],
// },
// },
// },
// 'install-progress': undefined,
// }
// export const DbDump: RR.GetDumpRes = {
// id: 1,
// expireId: null,
// value: {
// 'server-info': {
// id: 'start9-abcdefgmm',
// version: '1.0.0',
// status: ServerStatus.Running,
// 'lan-address': 'start9-abcdefgh.local',
// 'tor-address': 'myveryownspecialtoraddress.onion',
// wifi: {
// ssids: ['Goosers', 'Goosers5G'],
// selected: 'Goosers5G',
// connected: 'Goosers5G',
// },
// 'eos-marketplace': 'https://registry.start9.com',
// 'package-marketplace': 'https://registry.start9.com',
// 'unread-notification-count': 4,
// specs: {
// CPU: 'Cortex-A72: 4 Cores @1500MHz',
// Disk: '1TB SSD',
// Memory: '8GB',
// },
// 'connection-addresses': {
// tor: ['http://privacy34kn4ez3y3nijweec6w4g54i3g54sdv7r5mr6soma3w4begyd.onion'],
// clearnet: ['https://start9.com'],
// },
// },
// 'package-data': {
// 'bitcoind': bitcoind,
// 'lnd': lnd,
// },
// ui: {
// 'welcome-ack': '1.0.0',
// 'auto-check-updates': true,
// },
// },
// }
}

View File

@@ -66,7 +66,7 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
// )()
// password
abstract updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes>
// abstract updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes>
// notification

View File

@@ -83,9 +83,9 @@ export class LiveApiService extends ApiService {
// }
// password
async updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes> {
return this.http.rpcRequest({ method: 'password.set', params })
}
// async updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes> {
// return this.http.rpcRequest({ method: 'password.set', params })
// }
// notification

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core'
import { pauseFor } from '../../../util/misc.util'
import { ApiService } from './embassy-api.service'
import { PatchOp } from 'patch-db-client'
import { Operation, PatchOp } from 'patch-db-client'
import { PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
import { RR, WithRevision } from '../api.types'
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
@@ -12,7 +12,7 @@ import { ConfigService } from '../../config.service'
@Injectable()
export class MockApiService extends ApiService {
welcomeAck = false
private readonly revertTime = 4000
constructor (
private readonly http: HttpService,
@@ -32,7 +32,7 @@ export class MockApiService extends ApiService {
// ...Mock.DbDump,
// id: this.nextSequence(),
// }
return this.http.rpcRequest({ method: 'db.revisions', params: { since } })
return this.http.rpcRequest<RR.GetRevisionsRes>({ method: 'db.revisions', params: { since } })
}
async getDump (): Promise<RR.GetDumpRes> {
@@ -41,7 +41,7 @@ export class MockApiService extends ApiService {
// ...Mock.DbDump,
// id: this.nextSequence(),
// }
return this.http.rpcRequest({ method: 'db.dump' })
return this.http.rpcRequest<RR.GetDumpRes>({ method: 'db.dump' })
}
async setDbValueRaw (params: RR.SetDBValueReq): Promise<RR.SetDBValueRes> {
@@ -60,7 +60,7 @@ export class MockApiService extends ApiService {
// expireId: null,
// },
// }
return this.http.rpcRequest({ method: 'db.put.ui', params })
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.put.ui', params })
}
// auth
@@ -94,14 +94,41 @@ export class MockApiService extends ApiService {
async updateServerRaw (params: RR.UpdateServerReq): Promise<RR.UpdateServerRes> {
await pauseFor(2000)
const path = '/server-info/status'
const patch = [
{
op: PatchOp.REPLACE,
path: '/server-info/status',
path,
value: ServerStatus.Updating,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
const res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
setTimeout(() => {
const patch = [
{
op: PatchOp.REPLACE,
path,
value: ServerStatus.Running,
},
{
op: PatchOp.REPLACE,
path: '/server-info/version',
value: this.config.version + '.1',
},
]
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
// quickly revert patch to proper version to prevent infinite refresh loop
const patch2 = [
{
op: PatchOp.REPLACE,
path: '/server-info/version',
value: this.config.version,
},
]
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch: patch2 } })
}, this.revertTime)
return res
}
async restartServer (params: RR.RestartServerReq): Promise<RR.RestartServerRes> {
@@ -135,7 +162,7 @@ export class MockApiService extends ApiService {
value: params.url,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}
// async setPackageMarketplaceRaw (params: RR.SetPackageMarketplaceReq): Promise<RR.SetPackageMarketplaceRes> {
@@ -147,14 +174,14 @@ export class MockApiService extends ApiService {
// value: params.url,
// },
// ]
// return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
// return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
// }
// password
async updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes> {
await pauseFor(2000)
return null
}
// async updatePassword (params: RR.UpdatePasswordReq): Promise<RR.UpdatePasswordRes> {
// await pauseFor(2000)
// return null
// }
// notification
@@ -167,7 +194,7 @@ export class MockApiService extends ApiService {
value: 0,
},
]
const { revision } = await this.http.rpcRequest({ method: 'db.patch', params: { patch } }) as WithRevision<null>
const { revision } = await this.http.rpcRequest<WithRevision<RR.GetNotificationsRes>>({ method: 'db.patch', params: { patch } }) as WithRevision<null>
return {
response: Mock.Notifications,
revision,
@@ -200,24 +227,28 @@ export class MockApiService extends ApiService {
value: params.ssid,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}
async deleteWifiRaw (params: RR.DeleteWifiReq): Promise<RR.DeleteWifiRes> {
await pauseFor(2000)
const patch = [
const patch: Operation[] = [
{
op: PatchOp.REPLACE,
path: '/server-info/wifi/selected',
value: null,
},
{
op: PatchOp.REPLACE,
path: '/server-info/wifi/connected',
value: null,
op: PatchOp.REMOVE,
path: `/server-info/wifi/ssids/${params.ssid}`,
},
// {
// op: PatchOp.REPLACE,
// path: '/server-info/wifi/selected',
// value: null,
// },
// {
// op: PatchOp.REPLACE,
// path: '/server-info/wifi/connected',
// value: null,
// },
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}
// ssh
@@ -241,14 +272,26 @@ export class MockApiService extends ApiService {
async createBackupRaw (params: RR.CreateBackupReq): Promise<RR.CreateBackupRes> {
await pauseFor(2000)
const path = '/server-info/status'
const patch = [
{
op: PatchOp.REPLACE,
path: '/server-info/status',
path,
value: ServerStatus.BackingUp,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
const res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
setTimeout(() => {
const patch = [
{
op: PatchOp.REPLACE,
path,
value: ServerStatus.Running,
},
]
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}, this.revertTime)
return res
}
async restoreBackupRaw (params: RR.RestoreBackupReq): Promise<RR.RestoreBackupRes> {
@@ -302,7 +345,7 @@ export class MockApiService extends ApiService {
value: pkg,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}
async dryUpdatePackage (params: RR.DryUpdatePackageReq): Promise<RR.DryUpdatePackageRes> {
@@ -328,25 +371,32 @@ export class MockApiService extends ApiService {
path: `/package-data/${params.id}/installed/status/configured`,
value: true,
},
{
op: PatchOp.REPLACE,
path: `/package-data/${params.id}/installed/status/main/status`,
value: PackageMainStatus.Running,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}
async restorePackageRaw (params: RR.RestorePackageReq): Promise<RR.RestorePackageRes> {
await pauseFor(2000)
const path = `/package-data/${params.id}/installed/status/main/status`
const patch = [
{
op: PatchOp.REPLACE,
path: `/package-data/${params.id}/installed/status/main/status`,
path,
value: PackageMainStatus.Restoring,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
const res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
setTimeout(() => {
const patch = [
{
op: PatchOp.REPLACE,
path,
value: PackageMainStatus.Stopped,
},
]
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}, this.revertTime)
return res
}
async executePackageAction (params: RR.ExecutePackageActionReq): Promise<RR.ExecutePackageActionRes> {
@@ -361,14 +411,15 @@ export class MockApiService extends ApiService {
async startPackageRaw (params: RR.StartPackageReq): Promise<RR.StartPackageRes> {
await pauseFor(2000)
const path = `/package-data/${params.id}/installed/status/main/status`
const patch = [
{
op: PatchOp.REPLACE,
path: `/package-data/${params.id}/installed/status/main/status`,
path,
value: PackageMainStatus.Running,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
return this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}
async dryStopPackage (params: RR.DryStopPackageReq): Promise<RR.DryStopPackageRes> {
@@ -378,10 +429,11 @@ export class MockApiService extends ApiService {
async stopPackageRaw (params: RR.StopPackageReq): Promise<RR.StopPackageRes> {
await pauseFor(2000)
const path = `/package-data/${params.id}/installed/status/main/status`
const patch = [
{
op: PatchOp.REPLACE,
path: `/package-data/${params.id}/installed/status/main/status`,
path,
value: PackageMainStatus.Stopping,
},
]
@@ -390,12 +442,12 @@ export class MockApiService extends ApiService {
const patch = [
{
op: PatchOp.REPLACE,
path: `/package-data/${params.id}/installed/status/main/status`,
path,
value: PackageMainStatus.Stopped,
},
]
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}, 2000)
}, this.revertTime)
return res
}
@@ -414,7 +466,17 @@ export class MockApiService extends ApiService {
value: PackageState.Removing,
},
]
return this.http.rpcRequest({ method: 'db.patch', params: { patch } })
const res = await this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
setTimeout(async () => {
const patch = [
{
op: PatchOp.REMOVE,
path: `/package-data/${params.id}`,
},
]
this.http.rpcRequest<WithRevision<null>>({ method: 'db.patch', params: { patch } })
}, this.revertTime)
return res
}
async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise<RR.DryConfigureDependencyRes> {

View File

@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'
import { HttpService } from '../../http.service'
import { HttpService, Method } from '../../http.service'
import { RR } from '../api.types'
import { MarketplaceApiService } from './marketplace-api.service'
import { PatchDbService } from '../../patch-db/patch-db.service'
@@ -17,29 +17,55 @@ export class MarketplaceLiveApiService extends MarketplaceApiService {
}
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
return this.http.simpleGet<RR.GetMarketplaceEOSRes>(this.getMarketplaceURL('eos'), params)
const url = this.getMarketplaceURL('eos')
return this.http.httpRequest<RR.GetMarketplaceEOSRes>({
method: Method.GET,
url: url + '/eos',
params,
withCredentials: false,
})
}
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
return this.http.simpleGet<RR.GetMarketplaceDataRes>(this.getMarketplaceURL('package'), params)
const url = this.getMarketplaceURL('package')
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)
const threadParams = {
...params,
ids: JSON.stringify(params.ids),
}
return this.http.simpleGet<RR.GetMarketplacePackagesRes>(url, threadParams)
return this.http.httpRequest<RR.GetMarketplacePackagesRes>({
method: Method.GET,
url: url + '/packages',
params: {
...params,
ids: JSON.stringify(params.ids),
},
withCredentials: false,
})
}
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
return this.http.simpleGet<RR.GetReleaseNotesRes>(this.getMarketplaceURL('package'), params)
const url = this.getMarketplaceURL('package')
return this.http.httpRequest<RR.GetReleaseNotesRes>({
method: Method.GET,
url: url + + '/release-notes',
params,
withCredentials: false,
})
}
async getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes> {
const url = this.getMarketplaceURL('package', params.ids?.length > 1)
return this.http.simpleGet<RR.GetLatestVersionRes>(url, params)
return this.http.httpRequest<RR.GetLatestVersionRes>({
method: Method.GET,
url: url + '/latest-version',
params,
withCredentials: false,
})
}
}

View File

@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'
import { pauseFor } from '../../../util/misc.util'
import { RR } from '../api.types'
import { Mock } from '../api.fixures'
import { HttpService } from '../../http.service'
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'
@@ -20,53 +20,68 @@ export class MarketplaceMockApiService extends MarketplaceApiService {
// marketplace
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
let url = this.getMarketplaceURL('eos')
const url = this.getMarketplaceURL('eos')
if (this.useLocal(url)) {
await pauseFor(2000)
return Mock.MarketplaceEos
}
url = `${url}/sys/version/eos`
return this.http.simpleGet<RR.GetMarketplaceEOSRes>(url)
return this.http.httpRequest<RR.GetMarketplaceEOSRes>({
method: Method.GET,
url: `${url}/eos`,
params,
withCredentials: false,
})
}
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
let url = this.getMarketplaceURL('package')
const url = this.getMarketplaceURL('package')
if (this.useLocal(url)) {
await pauseFor(2000)
return {
categories: ['featured', 'bitcoin', 'lightning', 'data', 'messaging', 'social', 'alt coin'],
}
}
url = `${url}/data`
return this.http.simpleGet<RR.GetMarketplaceDataRes>(url)
return this.http.httpRequest<RR.GetMarketplaceDataRes>({
method: Method.GET,
url: `${url}/data`,
params,
withCredentials: false,
})
}
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
let url = this.getMarketplaceURL('package', params.ids?.length > 1)
const threadParams = {
...params,
ids: JSON.stringify(params.ids),
}
const url = this.getMarketplaceURL('package', params.ids?.length > 1)
if (this.useLocal(url)) {
await pauseFor(2000)
return Mock.AvailableList
return Mock.MarketplacePkgsList
}
url = `${url}/packages`
return this.http.simpleGet<RR.GetMarketplacePackagesRes>(url, threadParams)
return this.http.httpRequest<RR.GetMarketplacePackagesRes>({
method: Method.GET,
url: `${url}/packages`,
params: {
...params,
ids: JSON.stringify(params.ids),
},
withCredentials: false,
})
}
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
let url = this.getMarketplaceURL('package')
const url = this.getMarketplaceURL('package')
if (this.useLocal(url)) {
await pauseFor(2000)
return Mock.ReleaseNotes
}
url = `${url}/release-notes`
return this.http.simpleGet<RR.GetReleaseNotesRes>(url, params)
return this.http.httpRequest<RR.GetReleaseNotesRes>({
method: Method.GET,
url: `${url}/release-notes`,
params,
withCredentials: false,
})
}
async getLatestVersion (params: RR.GetLatestVersionReq): Promise<RR.GetLatestVersionRes> {
let url = this.getMarketplaceURL('package', params.ids?.length > 1)
const url = this.getMarketplaceURL('package', params.ids?.length > 1)
if (this.useLocal(url)) {
await pauseFor(2000)
return params.ids.reduce((obj, id) => {
@@ -74,8 +89,13 @@ export class MarketplaceMockApiService extends MarketplaceApiService {
return obj
}, { })
}
url = `${url}/latest-version`
return this.http.simpleGet<RR.GetLatestVersionRes>(url)
return this.http.httpRequest<RR.GetLatestVersionRes>({
method: Method.GET,
url: `${url}/latest-version`,
params,
withCredentials: false,
})
}
private useLocal (url: string): boolean {