mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
new marketplace api service
This commit is contained in:
committed by
Aiden McClelland
parent
6d92c195e9
commit
48632271d5
@@ -2,6 +2,9 @@ import { HttpService } from '../http.service'
|
||||
import { MockApiService } from './mock-api.service'
|
||||
import { LiveApiService } from './live-api.service'
|
||||
import { ConfigService } from '../config.service'
|
||||
import { PatchDbModel } from '../patch-db/patch-db.service'
|
||||
import { MarketplaceLiveApiService } from './marketplace-live-api.service'
|
||||
import { MarketplaceMockApiService } from './marketplace-mock-api.service'
|
||||
|
||||
export function ApiServiceFactory (config: ConfigService, http: HttpService) {
|
||||
if (config.mocks.enabled) {
|
||||
@@ -10,3 +13,11 @@ export function ApiServiceFactory (config: ConfigService, http: HttpService) {
|
||||
return new LiveApiService(config, http)
|
||||
}
|
||||
}
|
||||
|
||||
export function MarketplaceApiServiceFactory (config: ConfigService, http: HttpService, patch: PatchDbModel) {
|
||||
if (config.mocks.enabled) {
|
||||
return new MarketplaceMockApiService(http, patch)
|
||||
} else {
|
||||
return new MarketplaceLiveApiService(http, patch)
|
||||
}
|
||||
}
|
||||
@@ -167,16 +167,6 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
|
||||
|
||||
abstract dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise<RR.DryConfigureDependencyRes>
|
||||
|
||||
// marketplace
|
||||
|
||||
abstract getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes>
|
||||
|
||||
abstract getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes>
|
||||
|
||||
abstract getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes>
|
||||
|
||||
abstract getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes>
|
||||
|
||||
// Helper allowing quick decoration to sync the response patch and return the response contents.
|
||||
// Pass in a tempUpdate function which returns a UpdateTemp corresponding to a temporary
|
||||
// state change you'd like to enact prior to request and expired when request terminates.
|
||||
@@ -195,13 +185,3 @@ export abstract class ApiService implements Source<DataModel>, Http<DataModel> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getMarketURL (eosOrPackage: 'eos' | 'package', data: DataModel): string {
|
||||
const eosMarketplace = data['server-info']['eos-marketplace']
|
||||
if (eosOrPackage === 'eos') {
|
||||
return eosMarketplace
|
||||
} else {
|
||||
const packageMarketplace = data['server-info']['package-marketplace']
|
||||
return packageMarketplace || eosMarketplace
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { HttpService, Method } from '../http.service'
|
||||
import { ApiService, getMarketURL } from './api.service'
|
||||
import { ApiService } from './api.service'
|
||||
import { RR } from './api-types'
|
||||
import { parsePropertiesPermissive } from 'src/app/util/properties.util'
|
||||
import { ConfigService } from '../config.service'
|
||||
@@ -211,22 +211,4 @@ export class LiveApiService extends ApiService {
|
||||
async dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise<RR.DryConfigureDependencyRes> {
|
||||
return this.http.rpcRequest({ method: 'package.dependency.configure.dry', params })
|
||||
}
|
||||
|
||||
// marketplace
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
|
||||
return this.http.simpleGet<RR.GetMarketplaceDataRes>(getMarketURL('package', this.patch.data), params)
|
||||
}
|
||||
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
return this.http.simpleGet<RR.GetMarketplaceEOSRes>(getMarketURL('eos', this.patch.data), params)
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
|
||||
return this.http.simpleGet<RR.GetMarketplacePackagesRes>(getMarketURL('package', this.patch.data), params)
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
|
||||
return this.http.simpleGet<RR.GetReleaseNotesRes>(getMarketURL('package', this.patch.data), params)
|
||||
}
|
||||
}
|
||||
|
||||
24
ui/src/app/services/api/marketplace-api.service.ts
Normal file
24
ui/src/app/services/api/marketplace-api.service.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { RR } from './api-types'
|
||||
// import { DataModel } from 'src/app/services/patch-db/data-model'
|
||||
import { DataModel } from '../../../../src/app/services/patch-db/data-model'
|
||||
|
||||
export abstract class MarketplaceApiService {
|
||||
abstract getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes>
|
||||
|
||||
abstract getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes>
|
||||
|
||||
abstract getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes>
|
||||
|
||||
abstract getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes>
|
||||
|
||||
}
|
||||
|
||||
export function getMarketURL (eosOrPackage: 'eos' | 'package', data: DataModel): string {
|
||||
const eosMarketplace = data['server-info']['eos-marketplace']
|
||||
if (eosOrPackage === 'eos') {
|
||||
return eosMarketplace
|
||||
} else {
|
||||
const packageMarketplace = data['server-info']['package-marketplace']
|
||||
return packageMarketplace || eosMarketplace
|
||||
}
|
||||
}
|
||||
31
ui/src/app/services/api/marketplace-live-api.service.ts
Normal file
31
ui/src/app/services/api/marketplace-live-api.service.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { HttpService } from '../http.service'
|
||||
import { getMarketURL } from './marketplace-api.service'
|
||||
import { RR } from './api-types'
|
||||
import { MarketplaceApiService } from './marketplace-api.service'
|
||||
import { PatchDbModel } from '../patch-db/patch-db.service'
|
||||
|
||||
@Injectable()
|
||||
export class MarketplaceLiveApiService extends MarketplaceApiService {
|
||||
|
||||
constructor (
|
||||
private readonly http: HttpService,
|
||||
private readonly patch: PatchDbModel,
|
||||
) { super() }
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
|
||||
return this.http.simpleGet<RR.GetMarketplaceDataRes>(getMarketURL('package', this.patch.data), params)
|
||||
}
|
||||
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
return this.http.simpleGet<RR.GetMarketplaceEOSRes>(getMarketURL('eos', this.patch.data), params)
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
|
||||
return this.http.simpleGet<RR.GetMarketplacePackagesRes>(getMarketURL('package', this.patch.data), params)
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
|
||||
return this.http.simpleGet<RR.GetReleaseNotesRes>(getMarketURL('package', this.patch.data), params)
|
||||
}
|
||||
}
|
||||
62
ui/src/app/services/api/marketplace-mock-api.service.ts
Normal file
62
ui/src/app/services/api/marketplace-mock-api.service.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { pauseFor } from '../../util/misc.util'
|
||||
import { RR } from './api-types'
|
||||
import { Mock } from './mock-app-fixures'
|
||||
import { HttpService } from '../http.service'
|
||||
import { MarketplaceApiService } from './marketplace-api.service'
|
||||
import { getMarketURL } from './marketplace-api.service'
|
||||
import { PatchDbModel } from '../patch-db/patch-db.service'
|
||||
|
||||
@Injectable()
|
||||
export class MarketplaceMockApiService extends MarketplaceApiService {
|
||||
welcomeAck = false
|
||||
|
||||
constructor (
|
||||
private readonly http: HttpService,
|
||||
private readonly patch: PatchDbModel,
|
||||
) { super() }
|
||||
|
||||
// marketplace
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
|
||||
const registryURL = getMarketURL('package', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
categories: ['featured', 'bitcoin', 'lightning', 'data', 'messaging', 'social', 'alt coin'],
|
||||
}
|
||||
}
|
||||
const url = `${registryURL}/marketplace/data`
|
||||
return this.http.simpleGet<RR.GetMarketplaceDataRes>(url)
|
||||
}
|
||||
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
const registryURL = getMarketURL('eos', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return Mock.MarketplaceEos
|
||||
}
|
||||
const url = `${registryURL}/sys/version/eos`
|
||||
return this.http.simpleGet<RR.GetMarketplaceEOSRes>(url)
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
|
||||
const registryURL = getMarketURL('package', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return Mock.AvailableList
|
||||
}
|
||||
const url = `${registryURL}/marketplace/packages`
|
||||
return this.http.simpleGet<RR.GetMarketplacePackagesRes>(url, params)
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
|
||||
const registryURL = getMarketURL('package', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return Mock.ReleaseNotes
|
||||
}
|
||||
const url = `${registryURL}/marketplace/release-notes`
|
||||
return this.http.simpleGet<RR.GetReleaseNotesRes>(url)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { pauseFor } from '../../util/misc.util'
|
||||
import { ApiService, getMarketURL } from './api.service'
|
||||
import { ApiService } from './api.service'
|
||||
import { PatchOp } from 'patch-db-client'
|
||||
import { PackageDataEntry, PackageMainStatus, PackageState, ServerStatus } from 'src/app/services/patch-db/data-model'
|
||||
import { RR, WithRevision } from './api-types'
|
||||
@@ -421,48 +421,4 @@ export class MockApiService extends ApiService {
|
||||
await pauseFor(2000)
|
||||
return { }
|
||||
}
|
||||
|
||||
// marketplace
|
||||
|
||||
async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise<RR.GetMarketplaceDataRes> {
|
||||
const registryURL = getMarketURL('package', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return {
|
||||
categories: ['featured', 'bitcoin', 'lightning', 'data', 'messaging', 'social', 'alt coin'],
|
||||
}
|
||||
}
|
||||
const url = `${registryURL}/marketplace/data`
|
||||
return this.http.simpleGet<RR.GetMarketplaceDataRes>(url)
|
||||
}
|
||||
|
||||
async getEos (params: RR.GetMarketplaceEOSReq): Promise<RR.GetMarketplaceEOSRes> {
|
||||
const registryURL = getMarketURL('eos', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return Mock.MarketplaceEos
|
||||
}
|
||||
const url = `${registryURL}/sys/version/eos`
|
||||
return this.http.simpleGet<RR.GetMarketplaceEOSRes>(url)
|
||||
}
|
||||
|
||||
async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise<RR.GetMarketplacePackagesRes> {
|
||||
const registryURL = getMarketURL('package', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return Mock.AvailableList
|
||||
}
|
||||
const url = `${registryURL}/marketplace/packages`
|
||||
return this.http.simpleGet<RR.GetMarketplacePackagesRes>(url, params)
|
||||
}
|
||||
|
||||
async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise<RR.GetReleaseNotesRes> {
|
||||
const registryURL = getMarketURL('package', this.patch.data)
|
||||
if (!registryURL) {
|
||||
await pauseFor(2000)
|
||||
return Mock.ReleaseNotes
|
||||
}
|
||||
const url = `${registryURL}/marketplace/release-notes`
|
||||
return this.http.simpleGet<RR.GetReleaseNotesRes>(url)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user