Skip to content

The Nimbu.Cloud.modules namespace exposes Ruby-powered helpers that complement the JavaScript SDK. Most modules are available via camelCase shortcuts (e.g. Nimbu.Cloud.http). Below is a reference to each module, its purpose, and notable functions. Refer to the Cloud Code source tree for implementation details.

Core Utilities

ModuleShortcutKey FunctionsNotes
AtobNimbu.Cloud.atobdecode(data)Base64 decode wrapper (returns empty string on failure).
BtoaNimbu.Cloud.btoaencode(data)Base64 encode (strict).
CryptoNimbu.Cloud.cryptosecure_random(length), uuid(), calculate_hash({ data, digest, algorithm }), calculate_hmac({ data, key, digest, algorithm }), encrypt({ data, algorithm, encoding, key, iv })Also exposes createHash, createHmac, createCipheriv JS helpers via crypto.js.
CsvNimbu.Cloud.csvparse(csvString, options), to_csv(arrayOfRows, options)Auto-detects encoding via charlock_holmes, outputs BOM-prefixed base64 CSV.
FsNimbu.Cloud.fsreadFileSync(path) (aliases: open, readFile)Reads bundled source files from the Cloud Code archive.
GcNimbu.Cloud.gcrun()Forces a Ruby GC run (enables GC, starts, then disables again). Useful after heavy background jobs.
HtmlNimbu.Cloud.htmlstrip_html, sanitize, to_text, encodeUses Loofah to scrub markup and HTMLEntities to encode strings.
I18nNimbu.Cloud.i18nt(key, variables)Fetches Copywriting translations from the site (supports default, locale, interpolation).
JwtNimbu.Cloud.jwtencode(payload, secret, algorithm, header), decode(token, secret, verify, options)Wraps the jwt gem. decode returns { error } on failure.
SiteVariablesNimbu.Site.envget(name), has(name), keys()Fetch secrets & variables defined in the backend. Implements RequestStore caching.
ZipNimbu.Cloud.zipcreate([{ filename, contents }])Build base64 ZIP archives from an array of files (contents must be base64 encoded).

Networking & Communication

ModuleShortcutKey FunctionsNotes
HttpNimbu.Cloud.httpget, head, post, put, patch, deleteValidates URLs with UrlSecurityService. post/put/patch accept payload and headers (extras hash). Optional extras: base64 (encode body), skipUrlNormalization.
MailNimbu.Cloud.mailsend(params), reply(params, rawHeaders, options)Supports plain emails (subject, text, html) or template-based messages (template, variables). Attachments are base64 arrays. Logs missing parameters instead of throwing.
PdfNimbu.Cloud.pdfrender(htmlOrUrl, options)Generates PDFs via Rendering::Pdf; returns base64 string. Rejects disallowed URLs or unsafe inline HTML references.
Oauth2Nimbu.Cloud.oauth2authorizeUrl(grantType, options), getToken(grantType, options)Uses site-level OAuth2 credential integrations. Supports auth_code and client_credentials grants.
GoogleauthNimbu.Cloud.googleauthtoken(scope)Fetches Google service account access tokens using stored credentials.
SoapNimbu.Cloud.soapcall(wsdlUrl, operation, message, options) (see soap.rb)Provides SOAP client access (driven by Savon).

Storage & Files

ModuleShortcutKey FunctionsNotes
S3Nimbu.Cloud.s3generate_get_url, generate_upload_url, generate_post_formGenerates pre-signed AWS S3 URLs/forms. Automatically uses site storage when credentials/bucket aren’t supplied; otherwise accepts custom AWS credentials.
AzureNimbu.Cloud.azuregenerate_sas(options) (see azure.rb)Produces SAS tokens for Azure Blob storage.
ImgkitNimbu.Cloud.imgkitMethods for image manipulation (HTML to image, etc.).
HtmlNimbu.Cloud.htmlSanitize and strip markup for safe storage or email bodies.

Commerce Helpers

ModuleShortcutKey FunctionsNotes
OrderHelpersNimbu.Cloud.orderHelpersqueueAttachmentProcessing(order), resetAttachmentDownloadCount(order, attachment)Queue order attachment processing or reset download quota. Accepts object drops or IDs.
MollieNimbu.Cloud.molliecreatePayment(params), getPayment(id) etc.Wraps Mollie API using credentials stored on the site (modules/mollie.rb).
StripeNimbu.Cloud.stripecreateCheckoutSession, createPaymentIntent, etc.Uses site Stripe integration; loads helper JS (stripe.js).
OAuth2Helps integrate third-party providers for customer flows.

Internationalisation & Formatting

ModuleShortcutKey FunctionsNotes
HtmlContent sanitisation and encoding for emails or exports.
CsvConvert arrays to encoded CSV exports and parse uploads (with BOM support).
I18nRetrieve Copywriting strings in Cloud Code contexts (match storefront translations).

Advanced Cryptography & Signing

ModuleShortcutKey FunctionsNotes
SignerNimbu.Cloud.signersign(data, secret), verify(data, signature)HMAC helpers for secure webhooks (see signer.rb).
CryptoKey generation, hashing, encryption.
JwtJSON Web Token encode/decode.
Btoa / AtobBase64 utilities for binary payloads.

Messaging & Identity

ModuleShortcutKey FunctionsNotes
MailOutbound email via Nimbu’s mailer (plain or template-based).
Oauth2Authorization URL/token helper for OAuth2 providers configured in the backend.
GoogleauthFetch Google service account tokens for Google API access.

Site Variables & Environment

The combination of Nimbu.Site.env, Nimbu.Cloud.s3, and other modules allows you to securely interact with credentials stored in the backend. Always prefer these over hard-coded secrets.

Error Handling Pattern

Every module rescues exceptions, stores the message with context.store_last_error_message, and re-raises. In JavaScript the thrown error exposes the stored message. Wrap calls in try/catch to surface actionable feedback:

js
try {
  const pdf = await Nimbu.Cloud.pdf.render('<html>...</html>');
  // use pdf (base64 string)
} catch (error) {
  console.error('PDF generation failed', error);
}

Extending with Custom Libraries

If you need functionality beyond these modules:

  1. Bundle third-party JS libraries inside your Cloud Code archive and require them.
  2. Or create your own helper module in JavaScript and export functions for reuse.

Remember that Cloud Code runs in a sandbox—network access must go through Nimbu.Cloud.http, and persistent storage should use site integrations or the Nimbu API.

Keep this page bookmarked when you need to send emails, generate files, talk to storage providers, or sign payloads from within Cloud Code.