Renderer
Renderer Service
Renderer is a service that converts templates (HTML and CSS) into export formats (PDF, CSV, and HTML). It can then send these exported files to various targets (FileObject, SFTP, FTP, or base64 result).
Tip: To enable Renderer for your environment, please contact support.
module Renderer
constructor(apiKey)
Creates an instance of Renderer.
Arguments
apiKey
{ String } API key of an existing app.options
{ Object } Defines request options.encodeBase64
{ Boolean =false
} Enable base64 encoding.
Returns
{ renderer.Job } A new render job instance.
addObject(name, data)
Adds a single object array or plain JavaScript object. A template can reference an object directly.
Arguments
name
{ String } Top-level template data object key.data
{ Object|Array } Data to be referenced in the template.
Returns
{ renderer.Job }
this
.
addCursor(name, cursor)
Adds a QueryCursor or AggregationCursor. JSON Web Tokens (JWTs) are created from the current principal and cursor options.
Arguments
name
{ String } The input name for use in referencing the data in templates.cursor
{ QueryCursor|AggregationCursor } The cursor, for example,org.objects.c_studies.find().paths('c_name)
.
Returns
{ renderer.Job }
this
.
addApiRequest(name, path, environment, credentials, options, [requestOptions={}])
Adds a request object that will be used from Renderer. It can be a custom route or any other API request. You can use the result in the templates.
Arguments
name
{ String } Used to reference this data in the templates.path
{ String } Path to request, for example,/c_patients/234523423423
.environment
{ Object } Environment object.endpoint
: { String } Environment URL to use, for example,https://api.dev.medable.com
.env
: { String } Environment code, for example,dev
,prod
, orqa
.
credentials
{ Object } Credentials object.type
{ String } Token or signature types are allowed.token
{ String } Token data if type is set totoken
.signature
{ String } Signature data if type is set tosignature
.apiKey
{ String } If not set, default job apiKey is used.
options
{ Object } Describes request options such asmethod
,body
, andquery
.requestOptions
{ Object } Describes extra options likejson
andstrictSSL
.
Returns
{ renderer.Job }
this
.
addTemplate(name, [content, partial=false])
Adds an already saved HTML or CSS template, or can define an inline template. If you set the content argument, it behaves as an inline template.
Arguments
name
{ String } Defines the name that is used in the template.content
{ String } Inline content. You can reference objects, requests, and so on.partial
{ Boolean } Defines whether the template behaves as a partial template. You can exclude partial templates from other templates.
Returns
{ renderer.Job }
this
.
addOutput(name, type, templates, options)
Defines the output format of the entire process.
Arguments
name
{ String } Defines name. You can use this in the templates.type
{ String } Defines the output format type: PDF, CSV, or HTML.templates
{ String[] } Defines the templates to be used in the output. Templates are processed sequentially.options
{ Object | Array } Defines output options for CSV and PDF format types. There are no HTML output options. See the Output options section below for the full list of options. You can refer to the Prince command-line documentation for more details on the options listed below.
Returns
{ renderer.Job }
this
.
addSftpTarget(outputs, credentials, options)
Specifies an SFTP target.
Arguments
outputs
{ Object } Defines a key or value object, where key is the name of an output and value is the filename representing that output into the remote location.credentials
{ Object } Defines the credentials to connect to the remote server.host
{ String } Server domain name or IP address.port
{ Number =22
} SFTP server port.username
{ String } Username for authentication.password
{ String } Password for authentication.privateKey
{ String } String containing a private key for key-based or host-based user authentication.passphrase
{ String } The passphrase to decrypt an encrypted private key.localHostname
{ String } Along withlocalUsername
andprivateKey
, set this to a non-empty string for host-based user authentication.localUsername
{ String } Along withlocalHostname
andprivateKey
, set this value to a non-empty string for host-based user authentication.hostHash
{ String =md5
} A valid hash algorithm to check against the host fingerprint.hostFingerprint
{ String } Use together withhostHash
to verify the host fingerprint.
options
{ Object } Defines options for the target.compress
: { Object } Defines the compression options for the target.filename
: { String } Filename specifying the remote location, for example,/documents/my_document.zip
.outputs
: { String[] } Defines the outputs to include in the bundle.
Returns
{ renderer.Job }
this
.
addFtpTarget(outputs, credentials)
Specifies an FTP target.
Note: You must have access to an FTP server and know the following values: host, port, username, and password.
Tip: If you set the host
with an IP address, you should also set the secureOption rejectUnauthorized
to false
to avoid potential conflicts with the domain name on the server certificate, as provided by the TLS Server Name Indication (SNI) extension.
Arguments
outputs
{ Object } Defines a key or value object, where key is the name of an output and value is the filename representing that output into the remote location.credentials
{ Object } Defines the credentials to connect to the remote server.host
{ String =localhost
} FTP server domain name or IP address.port
{ Number =21
} FTP server port.username
{ String =anonymous
} Username for authentication.password
{ String =anonymous@
} Password for authentication.connTimeout
{ Number =10000
} Wait time in milliseconds to establish a control connection.pasvTimeout
{ Number =10000
} Wait time in milliseconds to establish aPASV
data connection.keepalive
{ Number =10000
} Wait time in milliseconds to send a dummy (NOOP) command to keep the connection alive.secure
{ Mixed =true
} Always set totrue
for control and data encryption.secureOptions
{ Object } Additional options to be passed totls.connect()
, as listed below. For more details, view the Node.js TLS module reference.ca
{ String, String[], Buffer, Buffer[] } Overrides default Certificate Authority (CA) certificates.cert
{ String, String[], Buffer, Buffer[] } Defines certification chains in Privacy-Enhanced Mail (PEM) format.sigalgs
{ String } Defines a list of supported signature algorithms.ciphers
{ String } Replaces the cipher suite specification.crl
{ String, String[], Buffer, Buffer[] } Defines PEM-formatted Certificate Revocation Lists (CRLs).dhparam
{ String, Buffer } Defines Diffie–Hellman parameters.ecdhCurve
{ String } Describes a named curve or a colon-separated list of curve NIDs or names to use for Elliptic-curve Diffie–Hellman (ECDH) key agreement. Default:tls.DEFAULT_ECDH_CURVE
.honorCipherOrder
{ Boolean } Attempts to use the cipher suite preferences of the server instead of the client.key
{ String, String[], Buffer, Buffer[], Object[] } Sets private keys in PEM format.minVersion
{ String } Allows you to choose the minimum allowable TLS version from the following:'TLSv1.3'
,'TLSv1.2'
,'TLSv1.1'
, or'TLSv1'
. Default:tls.DEFAULT_MIN_VERSION
.maxVersion
{ String } Allows you to choose the maximum allowable TLS version from the following:'TLSv1.3'
,'TLSv1.2'
,'TLSv1.1'
, or'TLSv1'
. This option cannot be used in conjunction withsecureProtocol
; you can only use one or the other. Default:tls.DEFAULT_MAX_VERSION
.passphrase
{ String } Shared passphrase used for a single private key or a PFX.pfx
{ String, String[], Buffer, Buffer[], Object[] } Defines the PFX or PKCS12 encoded private key and certificate chain.secureProtocol
{ String } Provides a legacy mechanism to select the TLS protocol version to use. It does not support independent control of the minimum and maximum versions. It also does not support limiting the protocol to TLSv1.3. If you wish to do so, useminVersion
andmaxVersion
instead. Default: none, seeminVersion
.rejectUnauthorized
{ Boolean =true
} Iftrue
, the server certificate is verified against the supplied list of CAs.
Returns
{ renderer.Job }
this
.
addFileTarget(path, data, options)
Specifies a File Object target in which to put the resultant file.
Arguments
path
{ String } Path to access the FileProperty used to put the resultant file, for example,path/to/234523423423/file
.data
{ Object } Specifies the facets to put the file in, where key is the facet name and value is the output format type defined, for example,{ facets: { content: 'my_pdf' } }
.options
{ Object } Defines options for the target.compress
: { Object } Defines the compression options for the target.facet
: { String } Name of the facet that will contain the compressed bundle.outputs
: { String[] } Defines the outputs to include in the bundle.
Returns
{ renderer.Job }
this
.
addCallback(name, path, environment, credentials, options, [requestOptions={}])
Similar to addApiRequest
but used when the process ends successfully or with error.
Returns
{ renderer.Job }
this
.
start()
Initiates the rendering process.
Returns
{ Object } A result object.
object
{ String } Type of result.data
{ Object } Data result object.jobId
{ String } Universally unique identifier (UUID) representing the current job.status
{ String } Job status text.
If you do not define a target, the response will contain the output process in base64 encoding.
Important! If you do not define a target and the process takes too long, you might receive a timeout error.
status(jobId)
Returns the status of an already initiated process.
Returns
{ Object } A result object.
object
{ String } Type of result.data
{ Object } Data result object.[cluster_name].jobId
{ String } UUID representing the current job.[cluster_name].status
{ String } Job status text.
cancel(jobId)
Cancels an already initiated process.
Returns
{ Object } A result object.
object
{ String } Type of result.data
{ Object } Data result object.[cluster_name].result
{ String } Text containing the UUID of the canceled job.
Examples
Example using an FTP target:
Example using an FTP target with more secureOptions:
Example using an SFTP target:
Example using a file target:
Example with multiple outputs:
Example with multiple templates in a single output:
Example with multiple templates in multiple outputs or targets:
Template helpers
Below is a list of helpers you can use in a template.
extend
: Allows you to extend a partial template.block
: Defines a content block that you can use withappend
,replace
, andprepend
.replace
: Replaces the content of a block.append
: Appends content into a block.prepend
: Prepends content into a block.each
if
with
unless
cursor
: Resolve a stream, cursor, or request returned from the Cortex API.log
lookup
Examples
A cursor helper can receive a CursorOperation
, Array
, or Stream
to help you iterate the results of cursor data.
Tip: If you use a cursor inside another helper, you must call it using a parenthesis, for example,(cursor parameter)
to resolve this first before you can iterate.
Example of a compiled template:
Example of defining a template as the master template (layout as name):
Example of a template that extends the master template:
Example of a compiled template:
Last updated