diff --git a/ui/src/app/app.module.ts b/ui/src/app/app.module.ts index b547c5ab7..29247bc54 100644 --- a/ui/src/app/app.module.ts +++ b/ui/src/app/app.module.ts @@ -8,7 +8,7 @@ import { HttpClientModule } from '@angular/common/http' import { AppComponent } from './app.component' import { AppRoutingModule } from './app-routing.module' import { ApiService } from './services/api/api.service' -import { ApiServiceFactory } from './services/api/api.service.factory' +import { ApiServiceFactory, MarketplaceApiServiceFactory } from './services/api/api.service.factory' import { PatchDbModelFactory } from './services/patch-db/patch-db.factory' import { HttpService } from './services/http.service' import { ConfigService } from './services/config.service' @@ -20,6 +20,7 @@ import { PatchDbModel } from './services/patch-db/patch-db.service' import { LocalStorageBootstrap } from './services/patch-db/local-storage-bootstrap' import { SharingModule } from './modules/sharing.module' import { APP_CONFIG_COMPONENT_MAPPING } from './services/tracking-modal-controller.service' +import { MarketplaceApiService } from './services/api/marketplace-api.service' @NgModule({ declarations: [AppComponent], @@ -43,7 +44,8 @@ import { APP_CONFIG_COMPONENT_MAPPING } from './services/tracking-modal-controll providers: [ Storage, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, - { provide: ApiService , useFactory: ApiServiceFactory, deps: [ConfigService, HttpService] }, + { provide: ApiService , useFactory: ApiServiceFactory, deps: [ConfigService, HttpService] }, { provide: ApiService , useFactory: ApiServiceFactory, deps: [ConfigService, HttpService] }, + { provide: MarketplaceApiService , useFactory: MarketplaceApiServiceFactory, deps: [ConfigService, HttpService, PatchDbModel] }, { provide: PatchDbModel, useFactory: PatchDbModelFactory, deps: [ConfigService, LocalStorageBootstrap, ApiService] }, { provide: APP_CONFIG_COMPONENT_MAPPING, useValue: appConfigComponents }, ], diff --git a/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.ts b/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.ts index ba5a08d97..643158cfc 100644 --- a/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.ts +++ b/ui/src/app/pages/marketplace-routes/marketplace-list/marketplace-list.page.ts @@ -8,6 +8,7 @@ import { PackageState } from 'src/app/services/patch-db/data-model' import { Subscription } from 'rxjs' import { ErrorToastService } from 'src/app/services/error-toast.service' import { MarketplaceService } from '../marketplace.service' +import { MarketplaceApiService } from 'src/app/services/api/marketplace-api.service' @Component({ selector: 'marketplace-list', @@ -36,6 +37,7 @@ export class MarketplaceListPage { constructor ( private readonly marketplaceService: MarketplaceService, + private readonly marketplaceApiService: MarketplaceApiService, private readonly modalCtrl: ModalController, private readonly errToast: ErrorToastService, private readonly wizardBaker: WizardBaker, @@ -46,8 +48,8 @@ export class MarketplaceListPage { try { const [data, eos, pkgs] = await Promise.all([ - this.marketplaceService.getMarketplaceData(), - this.marketplaceService.getEos(), + this.marketplaceApiService.getMarketplaceData({ }), + this.marketplaceApiService.getEos({ }), this.getPkgs(), ]) this.data = data diff --git a/ui/src/app/pages/marketplace-routes/marketplace.service.ts b/ui/src/app/pages/marketplace-routes/marketplace.service.ts index 2b3da29f2..1476c79b4 100644 --- a/ui/src/app/pages/marketplace-routes/marketplace.service.ts +++ b/ui/src/app/pages/marketplace-routes/marketplace.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core' import { MarketplacePkg } from 'src/app/services/api/api-types' -import { ApiService } from 'src/app/services/api/api.service' +import { MarketplaceApiService } from 'src/app/services/api/marketplace-api.service' @Injectable({ providedIn: 'root', @@ -12,19 +12,11 @@ export class MarketplaceService { } } constructor ( - private readonly apiService: ApiService, + private readonly marketplaceApiService: MarketplaceApiService, ) { } - async getMarketplaceData () { - return this.apiService.getMarketplaceData({ }) - } - - async getEos () { - return this.apiService.getEos({ }) - } - async getPkgs (category: string, query: string, page: number, perPage: number) : Promise { - const pkgs = await this.apiService.getMarketplacePkgs({ + const pkgs = await this.marketplaceApiService.getMarketplacePkgs({ category: category !== 'all' ? category : undefined, query, page: String(page), @@ -38,7 +30,7 @@ export class MarketplaceService { } async getPkg (id: string, version?: string): Promise { - const pkg = (await this.apiService.getMarketplacePkgs({ id, version }))[0] + const pkg = (await this.marketplaceApiService.getMarketplacePkgs({ id, version }))[0] if (pkg) { this.pkgs[id] = pkg } else { @@ -47,7 +39,7 @@ export class MarketplaceService { } async getReleaseNotes (id: string): Promise { - this.releaseNotes[id] = await this.apiService.getReleaseNotes({ id }) + this.releaseNotes[id] = await this.marketplaceApiService.getReleaseNotes({ id }) } } diff --git a/ui/src/app/services/api/api.service.factory.ts b/ui/src/app/services/api/api.service.factory.ts index 6dbce96fa..d671fca03 100644 --- a/ui/src/app/services/api/api.service.factory.ts +++ b/ui/src/app/services/api/api.service.factory.ts @@ -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) + } +} \ No newline at end of file diff --git a/ui/src/app/services/api/api.service.ts b/ui/src/app/services/api/api.service.ts index 86dd58dc7..2a84abd46 100644 --- a/ui/src/app/services/api/api.service.ts +++ b/ui/src/app/services/api/api.service.ts @@ -167,16 +167,6 @@ export abstract class ApiService implements Source, Http { abstract dryConfigureDependency (params: RR.DryConfigureDependencyReq): Promise - // marketplace - - abstract getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise - - abstract getEos (params: RR.GetMarketplaceEOSReq): Promise - - abstract getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise - - abstract getReleaseNotes (params: RR.GetReleaseNotesReq): Promise - // 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, Http { } } } - -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 - } -} \ No newline at end of file diff --git a/ui/src/app/services/api/live-api.service.ts b/ui/src/app/services/api/live-api.service.ts index 4707d28f9..a501adf44 100644 --- a/ui/src/app/services/api/live-api.service.ts +++ b/ui/src/app/services/api/live-api.service.ts @@ -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 { return this.http.rpcRequest({ method: 'package.dependency.configure.dry', params }) } - - // marketplace - - async getMarketplaceData (params: RR.GetMarketplaceDataReq): Promise { - return this.http.simpleGet(getMarketURL('package', this.patch.data), params) - } - - async getEos (params: RR.GetMarketplaceEOSReq): Promise { - return this.http.simpleGet(getMarketURL('eos', this.patch.data), params) - } - - async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise { - return this.http.simpleGet(getMarketURL('package', this.patch.data), params) - } - - async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise { - return this.http.simpleGet(getMarketURL('package', this.patch.data), params) - } } diff --git a/ui/src/app/services/api/marketplace-api.service.ts b/ui/src/app/services/api/marketplace-api.service.ts new file mode 100644 index 000000000..dff685697 --- /dev/null +++ b/ui/src/app/services/api/marketplace-api.service.ts @@ -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 + + abstract getEos (params: RR.GetMarketplaceEOSReq): Promise + + abstract getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise + + abstract getReleaseNotes (params: RR.GetReleaseNotesReq): Promise + +} + +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 + } +} \ No newline at end of file diff --git a/ui/src/app/services/api/marketplace-live-api.service.ts b/ui/src/app/services/api/marketplace-live-api.service.ts new file mode 100644 index 000000000..f92c18478 --- /dev/null +++ b/ui/src/app/services/api/marketplace-live-api.service.ts @@ -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 { + return this.http.simpleGet(getMarketURL('package', this.patch.data), params) + } + + async getEos (params: RR.GetMarketplaceEOSReq): Promise { + return this.http.simpleGet(getMarketURL('eos', this.patch.data), params) + } + + async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise { + return this.http.simpleGet(getMarketURL('package', this.patch.data), params) + } + + async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise { + return this.http.simpleGet(getMarketURL('package', this.patch.data), params) + } +} diff --git a/ui/src/app/services/api/marketplace-mock-api.service.ts b/ui/src/app/services/api/marketplace-mock-api.service.ts new file mode 100644 index 000000000..c98facd45 --- /dev/null +++ b/ui/src/app/services/api/marketplace-mock-api.service.ts @@ -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 { + 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(url) + } + + async getEos (params: RR.GetMarketplaceEOSReq): Promise { + 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(url) + } + + async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise { + const registryURL = getMarketURL('package', this.patch.data) + if (!registryURL) { + await pauseFor(2000) + return Mock.AvailableList + } + const url = `${registryURL}/marketplace/packages` + return this.http.simpleGet(url, params) + } + + async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise { + 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(url) + } +} diff --git a/ui/src/app/services/api/mock-api.service.ts b/ui/src/app/services/api/mock-api.service.ts index 9868cc413..4b835a652 100644 --- a/ui/src/app/services/api/mock-api.service.ts +++ b/ui/src/app/services/api/mock-api.service.ts @@ -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 { - 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(url) - } - - async getEos (params: RR.GetMarketplaceEOSReq): Promise { - 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(url) - } - - async getMarketplacePkgs (params: RR.GetMarketplacePackagesReq): Promise { - const registryURL = getMarketURL('package', this.patch.data) - if (!registryURL) { - await pauseFor(2000) - return Mock.AvailableList - } - const url = `${registryURL}/marketplace/packages` - return this.http.simpleGet(url, params) - } - - async getReleaseNotes (params: RR.GetReleaseNotesReq): Promise { - 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(url) - } }