Skip to content

Commit

Permalink
Fixing front end build after sites cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Sep 18, 2023
1 parent 7ae5129 commit fb1b468
Show file tree
Hide file tree
Showing 6 changed files with 695 additions and 768 deletions.
30 changes: 1 addition & 29 deletions frontend/apps/site/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import {
Accounts,
Publications,
WebSite,
Daemon,
Networking,
Groups,
Expand Down Expand Up @@ -52,7 +51,7 @@ function getGRPCHost() {
return 'http://127.0.0.1:56001'
}

return 'https://gateway.mintter.com'
return 'https://hyper.media'
}

const IS_DEV = process.env.NODE_ENV == 'development'
Expand All @@ -78,34 +77,7 @@ export const transport = createGrpcWebTransport({
interceptors: IS_DEV ? DEV_INTERCEPTORS : [prodInter],
})

function augmentWebsiteClient(
client: ReturnType<typeof createPromiseClient<typeof WebSite>>,
) {
return {
...client,
getPath: async (req: {path: string}) => {
const result = await client.getPath(req).catch((error) => {
if (error.rawMessage?.match('Could not get record for path')) {
return null
}
if (
error.rawMessage?.match(
'Could not get local document although was found',
)
) {
return null
}
throw error
})
return result
},
}
}

export const publicationsClient = createPromiseClient(Publications, transport)
export const localWebsiteClient = augmentWebsiteClient(
createPromiseClient(WebSite, transport),
)
export const accountsClient = createPromiseClient(Accounts, transport)
export const groupsClient = createPromiseClient(Groups, transport)
export const daemonClient = createPromiseClient(Daemon, transport)
Expand Down
11 changes: 0 additions & 11 deletions frontend/apps/site/get-site-info.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
import {SiteInfo} from '@mintter/shared'
import {localWebsiteClient} from './client'

export async function getSiteInfo() {
if (process.env.GW_NEXT_HOST) {
try {
let info: SiteInfo = await localWebsiteClient.getSiteInfo({})
return info
} catch (error) {
return null
}
}
return null
}
76 changes: 37 additions & 39 deletions frontend/apps/site/server/routers/_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import {
Groups,
Publications,
Role,
WebPublishing,
unpackDocId,
unpackHmId,
} from '@mintter/shared'
import {localWebsiteClient, transport} from 'client'
import {transport} from 'client'
import {getSiteInfo} from 'get-site-info'
import {HMChangeInfo} from '@mintter/ui'
import {
Expand All @@ -26,7 +25,6 @@ import {procedure, router} from '../trpc'

const contentGraphClient = createPromiseClient(ContentGraph, transport)
const publicationsClient = createPromiseClient(Publications, transport)
const webClient = createPromiseClient(WebPublishing, transport)
const accountsClient = createPromiseClient(Accounts, transport)
const groupsClient = createPromiseClient(Groups, transport)
const changesClient = createPromiseClient(Changes, transport)
Expand All @@ -40,13 +38,13 @@ const publicationRouter = router({
}),
)
.query(async ({input}) => {
const records = await webClient.listWebPublicationRecords({
documentId: input.documentId,
version: input.versionId,
})
return {
webPublications: records.publications,
}
// const records = await webClient.listWebPublicationRecords({
// documentId: input.documentId,
// version: input.versionId,
// })
// return {
// webPublications: records.publications,
// }
}),
getPath: procedure
.input(
Expand All @@ -56,17 +54,17 @@ const publicationRouter = router({
)
.query(async ({input}) => {
if (!input.pathName) return null
const pathRecord = await localWebsiteClient.getPath({
path: input.pathName,
})
const publication = pathRecord?.publication
const documentId = publication?.document?.id
if (!publication || !documentId) return null
return {
versionId: publication.version,
documentId,
publishTime: publication.document?.publishTime?.toJson() as string,
}
// const pathRecord = await localWebsiteClient.getPath({
// path: input.pathName,
// })
// const publication = pathRecord?.publication
// const documentId = publication?.document?.id
// if (!publication || !documentId) return null
// return {
// versionId: publication.version,
// documentId,
// publishTime: publication.document?.publishTime?.toJson() as string,
// }
}),
getDocRecord: procedure
.input(
Expand All @@ -76,16 +74,16 @@ const publicationRouter = router({
)
.query(async ({input}) => {
if (!input.documentId) return null
const webPubs = await localWebsiteClient.listWebPublications({})
const pub = webPubs.publications.find(
(pub) => pub.documentId === input.documentId,
)
if (!pub) return null
return {
path: pub.path,
versionId: pub.version,
documentId: pub.documentId,
}
// const webPubs = await localWebsiteClient.listWebPublications({})
// const pub = webPubs.publications.find(
// (pub) => pub.documentId === input.documentId,
// )
// if (!pub) return null
// return {
// path: pub.path,
// versionId: pub.version,
// documentId: pub.documentId,
// }
}),
get: procedure
.input(
Expand Down Expand Up @@ -232,14 +230,14 @@ const groupRouter = router({
.query(async ({input}) => {
// todo. get current group content and find the pathName, return the corresponding doc
console.log('getting site info')
const siteInfo = await groupsClient.getSiteInfo({
hostname: input.hostname,
})
return {
groupId: siteInfo.groupId,
ownerId: siteInfo.ownerId,
version: siteInfo.version,
}
// const siteInfo = await groupsClient.getGroup({
// hostname: input.hostname,
// })
// return {
// groupId: siteInfo.groupId,
// ownerId: siteInfo.ownerId,
// version: siteInfo.version,
// }
}),
getGroupPath: procedure
.input(
Expand Down
7 changes: 0 additions & 7 deletions frontend/packages/shared/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import {
Publication as APIPublication,
Document,
} from './.generated/documents/v1alpha/documents_pb'
import {
WebPublishing,
WebSite,
} from './.generated/documents/v1alpha/web_publishing_connect'
import {Networking} from './.generated/networking/v1alpha/networking_connect'
import {Entities} from './.generated/entities/v1alpha/entities_connect'
export {
Expand Down Expand Up @@ -81,7 +77,6 @@ export {
ListPublicationsResponse,
PublishDraftRequest,
} from './.generated/documents/v1alpha/documents_pb'
export * from './.generated/documents/v1alpha/web_publishing_pb'
export {ConnectionStatus} from './.generated/networking/v1alpha/networking_pb'
export type {
ConnectRequest,
Expand All @@ -106,8 +101,6 @@ export {
Groups,
Networking,
Publications,
WebPublishing,
WebSite,
}
export type Publication = APIPublication & {
document?: PartialMessage<Document>
Expand Down
25 changes: 0 additions & 25 deletions frontend/packages/shared/src/grpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
Drafts,
Networking,
Publications,
WebPublishing,
WebSite,
Groups,
Entities,
} from './client'
Expand All @@ -25,14 +23,9 @@ export type GRPCClient = {
publications: PromiseClient<typeof Publications>
daemon: PromiseClient<typeof Daemon>
networking: PromiseClient<typeof Networking>
webPublishing: PromiseClient<typeof WebPublishing>
webSite: PromiseClient<typeof WebSite>
getRemoteWebClient: (siteOrigin: string) => PromiseClient<typeof WebSite>
}

export function createGRPCClient(transport: any): GRPCClient {
const localWebSite = createPromiseClient(WebSite, transport)

return {
accounts: createPromiseClient(Accounts, transport),
contentGraph: createPromiseClient(ContentGraph, transport),
Expand All @@ -42,25 +35,7 @@ export function createGRPCClient(transport: any): GRPCClient {
publications: createPromiseClient(Publications, transport),
daemon: createPromiseClient(Daemon, transport),
networking: createPromiseClient(Networking, transport),
webPublishing: createPromiseClient(WebPublishing, transport),
groups: createPromiseClient(Groups, transport),
entities: createPromiseClient(Entities, transport),
webSite: localWebSite,
getRemoteWebClient: (siteOrigin: string) => {
return Object.fromEntries(
Object.entries(localWebSite).map(([rpcCallName, rpcHandler]) => {
return [
rpcCallName,
async (input: Parameters<typeof rpcHandler>[0]) => {
return rpcHandler(input, {
headers: {
'x-mintter-site-hostname': siteOrigin,
},
})
},
]
}),
) as typeof localWebSite
},
} as const
}
Loading

0 comments on commit fb1b468

Please sign in to comment.