@@ -11,9 +11,14 @@ import { renderIntegrationUi } from './server-actions';
1111
1212export async function IntegrationBlock ( props : BlockProps < DocumentBlockIntegration > ) {
1313 const { block, context, style } = props ;
14+ const { spaceId } = props . block . data
1415
15- if ( ! context . contentContext ?. space ) {
16- throw new Error ( 'integration block requires a content.spaceId' ) ;
16+ if ( ! context . contentContext ) {
17+ throw new Error ( 'Expected a content context to render an block' ) ;
18+ }
19+
20+ if ( ! context . contentContext ?. space && ! spaceId ) {
21+ throw new Error ( 'integration block requires a spaceId' ) ;
1722 }
1823
1924 const initialInput : RenderIntegrationUI = {
@@ -22,13 +27,22 @@ export async function IntegrationBlock(props: BlockProps<DocumentBlockIntegratio
2227 action : block . data . action ,
2328 context : {
2429 type : 'document' ,
25- spaceId : context . contentContext ?. space . id ,
30+ // When the block originates from a cross-space reusable content, the server adds a spaceId so the integration is
31+ // looked up in the correct source space.
32+ spaceId : spaceId ?? context . contentContext . space . id ,
2633 editable : false ,
2734 theme : 'light' , // TODO: how to handle this without moving rendering to the client side?
2835 } ,
2936 } ;
3037
31- const initialResponse = await fetchSafeIntegrationUI ( context . contentContext , {
38+ const dataFetcher = block . meta ?. token
39+ ? context . contentContext . dataFetcher . withToken ( { apiToken : block . meta . token } )
40+ : context . contentContext . dataFetcher ;
41+
42+ const initialResponse = await fetchSafeIntegrationUI ( {
43+ ...context . contentContext ,
44+ dataFetcher
45+ } , {
3246 integrationName : block . data . integration ,
3347 request : initialInput ,
3448 } ) ;
0 commit comments