Utils
The sdk.utils object on the Server SDK offers a wide array of helper methods to support backend logic in GridStudio Custom Functions. These utilities cover encoding, decoding, role checks, QR code generation, canvas image manipulation, and more.
Categories
Encoding & Decoding
encode(data, format)– Encodes a string usingbase64or other formats.decode(data, format)– Decodes a previously encoded string.serialize(obj)– Serializes a JavaScript object.deserialize(string)– Reconstructs object from serialized string.
Formatting
formatDate(date)– Returns formatted date string.formatDateTime(date)– Returns formatted date-time string.formatDateTimeLocal(date)– Locale-aware date-time string.currency.priceString(isoCode, price, options)– Returns a formatted price string.
Path & Slug
absoluteUrl(path)– Returns full absolute URL.absolutePathString(name)– Resolves relative file/function path.slugify(string)– Converts string to URL-safe slug.
QR Code
generateQrCodeAsync({ data })– Generates QR code image from data.
Canvas Helpers
canvas.create(width, height)– Creates a canvas object.canvas.loadImage(path)– Loads an image into canvas.
Base64 Upload
uploadBase64Async({ base64, mimeType, fileName })– Uploads base64-encoded file and returns URL.
Timer Helpers
setTimeout(fn, ms)– Delays execution.clearTimeout(id)– Clears timeout.setInterval(fn, ms)– Repeats execution.clearInterval(id)– Clears interval.
Translation
translate('i18n.key')– Translates a given key.
Role Check Utilities
roles.userIsInRoleAsync(roles)– Checks if current user is in roles.roles.userIsInParentRole(roles)– Checks parent tenant role.roles.userIsInRootRole(roles)– Checks root tenant role.roles.addRolesToParentAsync(childRoles, parentRole)– Assigns roles.
Logging
Use sdk.utils.logger instead of console.log on the server.
logger.info(...args)– Logs info-level messages.logger.warn(...args)– Logs warnings.logger.error(...args)– Logs error messages.logger.debug(...args)– Logs debugging info.
Example: QR Code Logging
const qr = await sdk.utils.generateQrCodeAsync({ data: 'https://gridstudio.ai' })
sdk.utils.logger.info('Generated QR Code:', qr)