//
// $Id$
//
import { Context } from "../infohub/Context.js"
import { RestServices, RestResponse } from "../tools/RestServices.js"
/**
@category Infohub Hub and Routines
@classdesc PDF, XLS Reports
*/
export class ServiceRender {
#_ctx = null;
/**
*
* @param {Context} ctx
*
*/
constructor( ctx ) {
this.#_ctx = ctx
}
/**
*
* Create XLS file from node tree.
*
* Uses endpoint: `https://.SERVICE_RENDER./{scope}/xls/nodes/{node}/tree`
*
* Get access token and scope from infohub context.
*
* @param {string} parent_sid Create the new document as child of this node
* @param {object} request_data Sources and configuration, see documentation of endpoint for more details
*
* @returns {RestResponse} Response of REST call
*
* @since 08.2025, jh
*
*/
async createXlsFromTree( parent_sid , request_data ) {
let scope = this.#_ctx.getScope()
let node = parent_sid
let path_endpoint = `${this.#_ctx.getServiceUrl(Context.SERVICE.RENDER)}/${scope}/xls/nodes/${node}/tree`
console.log(`### <createXlsFromTree()> ENDPOINT : ${path_endpoint}`)
let resp = await RestServices.makeApiCall( this.#_ctx.getToken() , RestServices.METHODS.POST , path_endpoint , request_data , "application/json" )
// console.log( "RESPONSE:" )
// console.log( JSON.stringify(resp.getData()) )
return resp
}
/**
*
* Create PDF file from html template and save it in infohub under given shortid of parent.
*
* Uses endpoint: `https://.SERVICE_RENDER./{scope}/pdf/nodes/{node}`
*
* Get access token and scope from infohub context.
*
* @param {string} parent_sid Create the new document as child of this node
* @param {object} request_data Sources and configuration, see documentation of endpoint for more details
*
* @returns {RestResponse} Response of REST call
*
* @since 10.12.2025, ar
*
*/
async createPdfFromHtmlTemplate(parent_sid, request_data) {
let scope = this.#_ctx.getScope()
let node = parent_sid
let path_endpoint = `${this.#_ctx.getServiceUrl(Context.SERVICE.RENDER)}/${scope}/pdf/nodes/${node}`
console.log(`### <createPdfFromHtmlTemplate()> ENDPOINT : ${path_endpoint}`)
let resp = await RestServices.makeApiCall(
this.#_ctx.getToken(),
RestServices.METHODS.POST,
path_endpoint,
request_data,
"application/json"
)
// console.log( "RESPONSE:" )
// console.log( JSON.stringify(resp.getData()) )
return resp
}
}
Source