Skip to content

Commit

Permalink
Merge pull request #165 from Holo-Host/chore/update-holochain-api-end…
Browse files Browse the repository at this point in the history
…points

chore/update holochain api endpoints
  • Loading branch information
peeech authored Jul 3, 2024
2 parents b32e8a0 + a3fe440 commit 8c1888d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Start UI server
yarn serve
```

Using this command, all requests to `localhost:8080/api/` and `localhost:8080/holochain-api/` are forwarded to the holoport. This is really helpful for development/testing.
Using this command, all requests to `localhost:8080/api/` are forwarded to the holoport. This is really helpful for development/testing.

If you want to run it against mocked data you will need to run it as below.

Expand Down
22 changes: 11 additions & 11 deletions mock-hpos-api/defaultResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,27 +639,27 @@ let mockDefaultHappPreferences = {
price_storage: (Math.random() * 10).toFixed(5).toString()
}

// NB: both /api and /holochain-api calls are mocked here
// NB: both /api calls are mocked here
const data = {
get: {
'/api/v1/config': userConfig,
'/api/v1/status': holoNixpkgs,
'/api/v2/hosted_happs': happs,
'/holochain-api/v1/get_happs': mockHapps,
'/holochain-api/v1/get_hosts': mockHosts,
'/holochain-api/v1/usage': usage,
'/holochain-api/v1/host_earnings': earnings,
'/holochain-api/v1/core_app_version': coreAppVersion,
'/holochain-api/v1/host_invoices': mockPaidInvoicesData,
'/holochain-api/v1/redemptions': mockRedemptionHistoryData,
'/holochain-api/v1/kyc': mockKycData.kyc
'/api/v2/apps/hosted': happs,
'/api/v1/get_happs': mockHapps,
'/api/v1/get_hosts': mockHosts,
'/api/v2/holoport/usage': usage,
'/api/v2/host/earnings': earnings,
'/api/v2/apps/core/version': coreAppVersion,
'/api/v2/host/invoices': mockPaidInvoicesData,
'/api/v2/host/redemptions': mockRedemptionHistoryData,
'/api/v2/host/kyc_level': mockKycData.kyc
},
put: {
'/api/v1/config': (args) => args,
'/api/v1/holoport/name': {}
},
post: {
'/holochain-api/v1/zome_call': (args) => {
'/api/v2/apps/call_zome': (args) => {
switch (args.fnName) {
case 'get_my_profile':
return getMyProfile
Expand Down
58 changes: 22 additions & 36 deletions src/interfaces/HposInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ interface HoloFuelProfileResponse {
avatar_url: string
}

interface CoreAppVersionResponse {
version: string
}
type CoreAppVersionResponse = string | null

export interface HostPreferencesResponse {
price_compute: string
Expand Down Expand Up @@ -421,7 +419,7 @@ export function useHposInterface(): HposInterface {
// On 401 redirect to login and unset authToken because the reason for 401 might be it's expired
try {
return await hposCall({
pathPrefix: '/holochain-api/v1',
pathPrefix: '/api/v2',
...args
})
} catch (err) {
Expand All @@ -438,7 +436,7 @@ export function useHposInterface(): HposInterface {
try {
return await hposHolochainCall({
method: 'get',
path: '/usage',
path: '/holoport/usage',
params: {
usage_interval: 1
}
Expand All @@ -453,8 +451,7 @@ export function useHposInterface(): HposInterface {
try {
const result = await hposHolochainCall({
method: 'get',
pathPrefix: '/api/v2',
path: '/hosted_happs',
path: '/apps/hosted',
params: {
usage_interval: 7
}
Expand All @@ -478,8 +475,7 @@ export function useHposInterface(): HposInterface {
try {
const result = await hposHolochainCall({
method: 'get',
pathPrefix: '/api/v2',
path: `/hosted_happs/${id}`
path: `/apps/hosted/${id}`
})

if (isHAppDetails(result)) {
Expand All @@ -500,8 +496,7 @@ export function useHposInterface(): HposInterface {
try {
const result = await hposHolochainCall({
method: 'post',
pathPrefix: '/api/v2',
path: `/hosted_happs/${id}/enable`
path: `/apps/hosted/${id}/enable`
})

return result
Expand All @@ -517,8 +512,7 @@ export function useHposInterface(): HposInterface {
try {
const result = await hposHolochainCall({
method: 'post',
pathPrefix: '/api/v2',
path: `/hosted_happs/${id}/disable`
path: `/apps/hosted/${id}/disable`
})

return result
Expand All @@ -542,8 +536,7 @@ export function useHposInterface(): HposInterface {

await hposHolochainCall({
method: 'post',
path: '/zome_call',
pathPrefix: '/api/v2',
path: '/apps/call_zome',
responseType: 'arraybuffer',
params
})
Expand All @@ -563,8 +556,7 @@ export function useHposInterface(): HposInterface {
promises.push(
hposHolochainCall({
method: 'get',
pathPrefix: '/api/v2',
path: `/hosted_happs/${id}/logs?days=30`
path: `/apps/hosted/${id}/logs?days=30`
})
)
})
Expand Down Expand Up @@ -618,8 +610,7 @@ export function useHposInterface(): HposInterface {

await hposHolochainCall({
method: 'post',
path: '/zome_call',
pathPrefix: '/api/v2',
path: '/apps/call_zome',
responseType: 'arraybuffer',
params
})
Expand All @@ -634,7 +625,7 @@ export function useHposInterface(): HposInterface {
try {
return await hposHolochainCall({
method: 'get',
path: '/host_earnings'
path: '/host/earnings'
})
} catch (error) {
console.error('getHostEarnings encountered an error: ', error)
Expand All @@ -654,8 +645,7 @@ export function useHposInterface(): HposInterface {
try {
const hostPreferences = await hposHolochainCall({
method: 'post',
path: '/zome_call',
pathPrefix: '/api/v2',
path: '/apps/call_zome',
responseType: 'arraybuffer',
params
})
Expand Down Expand Up @@ -763,8 +753,7 @@ export function useHposInterface(): HposInterface {

const response = await hposHolochainCall({
method: 'post',
path: '/zome_call',
pathPrefix: '/api/v2',
path: '/apps/call_zome',
responseType: 'arraybuffer',
params
})
Expand Down Expand Up @@ -819,8 +808,7 @@ export function useHposInterface(): HposInterface {

await hposHolochainCall({
method: 'post',
path: '/zome_call',
pathPrefix: '/api/v2',
path: '/apps/call_zome',
responseType: 'arraybuffer',
params
})
Expand All @@ -835,7 +823,7 @@ export function useHposInterface(): HposInterface {
try {
return await hposHolochainCall({
method: 'get',
path: '/host_invoices',
path: '/host/invoices',
params: { invoice_set: 'paid' }
})
} catch (error) {
Expand All @@ -847,7 +835,7 @@ export function useHposInterface(): HposInterface {
try {
return await hposHolochainCall({
method: 'get',
path: '/host_invoices',
path: '/host/invoices',
params: { invoice_set: 'unpaid' }
})
} catch (error) {
Expand All @@ -859,7 +847,7 @@ export function useHposInterface(): HposInterface {
try {
return await hposHolochainCall({
method: 'get',
path: '/redemptions'
path: '/host/redemptions'
})
} catch (error) {
return false
Expand All @@ -870,9 +858,9 @@ export function useHposInterface(): HposInterface {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { version: coreAppVersion } = await hposHolochainCall({
const coreAppVersion = await hposHolochainCall({
method: 'get',
path: '/core_app_version'
path: '/apps/core/version'
})

if (typeof coreAppVersion === 'string') {
Expand All @@ -894,7 +882,7 @@ export function useHposInterface(): HposInterface {
// @ts-ignore
const data = await hposHolochainCall({
method: 'get',
path: '/kyc'
path: '/host/kyc_level'
})

if (isKycLevel(data)) {
Expand Down Expand Up @@ -923,8 +911,7 @@ export function useHposInterface(): HposInterface {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const response = await hposHolochainCall({
method: 'post',
path: '/zome_call',
pathPrefix: '/api/v2',
path: '/apps/call_zome',
responseType: 'arraybuffer',
params: getReserveDetailsParams
})
Expand All @@ -950,8 +937,7 @@ export function useHposInterface(): HposInterface {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const response = await hposHolochainCall({
method: 'post',
path: '/zome_call',
pathPrefix: '/api/v2',
path: '/apps/call_zome',
responseType: 'arraybuffer',
params: initiateRedemptionParams
})
Expand Down
2 changes: 1 addition & 1 deletion src/pages/__tests__/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('dashboard page', () => {
return Promise.resolve(defaultSshAccessResult)
}

if (path.endsWith('hosted_happs')) {
if (path.endsWith('hosted')) {
return hostedHappsResult
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/__tests__/HApps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('hApps page', () => {
}

axios.get.mockImplementation((path) => {
if (path.endsWith('hosted_happs')) {
if (path.endsWith('hosted')) {
return hostedHAppsResult
}

Expand Down
7 changes: 1 addition & 6 deletions src/store/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { defineStore } from 'pinia'
import { HApp, HostEarnings, UsageResponse, useHposInterface } from '@/interfaces/HposInterface'
import type { EarningsData } from '@/types/types'

const {
getUsage,
getHostedHApps,
getHostEarnings,
getHoloFuelDailyStats
} = useHposInterface()
const { getUsage, getHostedHApps, getHostEarnings, getHoloFuelDailyStats } = useHposInterface()

interface State {
usage: UsageResponse | { error: unknown }
Expand Down
4 changes: 0 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export default defineConfig(({ mode }) => {
port: 8080,
proxy: {
'^/api/*': {
target: env.VITE_HOLOPORT_URL,
changeOrigin: true
},
'^/holochain-api/*': {
target: env.VITE_HOLOPORT_URL,
changeOrigin: true
}
Expand Down

0 comments on commit 8c1888d

Please sign in to comment.