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
| Module | Shortcut | Key Functions | Notes |
|---|---|---|---|
Atob | Nimbu.Cloud.atob | decode(data) | Base64 decode wrapper (returns empty string on failure). |
Btoa | Nimbu.Cloud.btoa | encode(data) | Base64 encode (strict). |
Crypto | Nimbu.Cloud.crypto | secure_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. |
Csv | Nimbu.Cloud.csv | parse(csvString, options), to_csv(arrayOfRows, options) | Auto-detects encoding via charlock_holmes, outputs BOM-prefixed base64 CSV. |
Fs | Nimbu.Cloud.fs | readFileSync(path) (aliases: open, readFile) | Reads bundled source files from the Cloud Code archive. |
Gc | Nimbu.Cloud.gc | run() | Forces a Ruby GC run (enables GC, starts, then disables again). Useful after heavy background jobs. |
Html | Nimbu.Cloud.html | strip_html, sanitize, to_text, encode | Uses Loofah to scrub markup and HTMLEntities to encode strings. |
I18n | Nimbu.Cloud.i18n | t(key, variables) | Fetches Copywriting translations from the site (supports default, locale, interpolation). |
Jwt | Nimbu.Cloud.jwt | encode(payload, secret, algorithm, header), decode(token, secret, verify, options) | Wraps the jwt gem. decode returns { error } on failure. |
SiteVariables | Nimbu.Site.env | get(name), has(name), keys() | Fetch secrets & variables defined in the backend. Implements RequestStore caching. |
Zip | Nimbu.Cloud.zip | create([{ filename, contents }]) | Build base64 ZIP archives from an array of files (contents must be base64 encoded). |
Networking & Communication
| Module | Shortcut | Key Functions | Notes |
|---|---|---|---|
Http | Nimbu.Cloud.http | get, head, post, put, patch, delete | Validates URLs with UrlSecurityService. post/put/patch accept payload and headers (extras hash). Optional extras: base64 (encode body), skipUrlNormalization. |
Mail | Nimbu.Cloud.mail | send(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. |
Pdf | Nimbu.Cloud.pdf | render(htmlOrUrl, options) | Generates PDFs via Rendering::Pdf; returns base64 string. Rejects disallowed URLs or unsafe inline HTML references. |
Oauth2 | Nimbu.Cloud.oauth2 | authorizeUrl(grantType, options), getToken(grantType, options) | Uses site-level OAuth2 credential integrations. Supports auth_code and client_credentials grants. |
Googleauth | Nimbu.Cloud.googleauth | token(scope) | Fetches Google service account access tokens using stored credentials. |
Soap | Nimbu.Cloud.soap | call(wsdlUrl, operation, message, options) (see soap.rb) | Provides SOAP client access (driven by Savon). |
Storage & Files
| Module | Shortcut | Key Functions | Notes |
|---|---|---|---|
S3 | Nimbu.Cloud.s3 | generate_get_url, generate_upload_url, generate_post_form | Generates pre-signed AWS S3 URLs/forms. Automatically uses site storage when credentials/bucket aren’t supplied; otherwise accepts custom AWS credentials. |
Azure | Nimbu.Cloud.azure | generate_sas(options) (see azure.rb) | Produces SAS tokens for Azure Blob storage. |
Imgkit | Nimbu.Cloud.imgkit | Methods for image manipulation (HTML to image, etc.). | |
Html | Nimbu.Cloud.html | Sanitize and strip markup for safe storage or email bodies. |
Commerce Helpers
| Module | Shortcut | Key Functions | Notes |
|---|---|---|---|
OrderHelpers | Nimbu.Cloud.orderHelpers | queueAttachmentProcessing(order), resetAttachmentDownloadCount(order, attachment) | Queue order attachment processing or reset download quota. Accepts object drops or IDs. |
Mollie | Nimbu.Cloud.mollie | createPayment(params), getPayment(id) etc. | Wraps Mollie API using credentials stored on the site (modules/mollie.rb). |
Stripe | Nimbu.Cloud.stripe | createCheckoutSession, createPaymentIntent, etc. | Uses site Stripe integration; loads helper JS (stripe.js). |
OAuth2 | Helps integrate third-party providers for customer flows. |
Internationalisation & Formatting
| Module | Shortcut | Key Functions | Notes |
|---|---|---|---|
Html | Content sanitisation and encoding for emails or exports. | ||
Csv | Convert arrays to encoded CSV exports and parse uploads (with BOM support). | ||
I18n | Retrieve Copywriting strings in Cloud Code contexts (match storefront translations). |
Advanced Cryptography & Signing
| Module | Shortcut | Key Functions | Notes |
|---|---|---|---|
Signer | Nimbu.Cloud.signer | sign(data, secret), verify(data, signature) | HMAC helpers for secure webhooks (see signer.rb). |
Crypto | Key generation, hashing, encryption. | ||
Jwt | JSON Web Token encode/decode. | ||
Btoa / Atob | Base64 utilities for binary payloads. |
Messaging & Identity
| Module | Shortcut | Key Functions | Notes |
|---|---|---|---|
Mail | Outbound email via Nimbu’s mailer (plain or template-based). | ||
Oauth2 | Authorization URL/token helper for OAuth2 providers configured in the backend. | ||
Googleauth | Fetch 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:
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:
- Bundle third-party JS libraries inside your Cloud Code archive and require them.
- 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.