The long tail of app-development - load that skill first for the core workflow (write a function, wire gipity.yaml, deploy, test). This reference covers the function runtime's module system in depth, verifying signed webhooks, choosing between a button-driven function and a workflow, plus operational details you reach for on demand.

ES module syntax - what you can write

The runtime compiles your code as a real ES module (since 2026-05-29). Any valid single-file ESM parses cleanly:

// All of this works in one file:
import { z } from './schemas.js';           // relative imports (multi-file only - see below)
export const VERSION = 3;                   // top-level const, exported or not
export function validate(input) { ... }     // named exports alongside the default
const cfg = await loadConfig();             // top-level await
export default async function handler(ctx, { db }) { ... }

What does NOT work and the exact error you'll see:

Multi-file functions

When a function grows past a single file - testable helpers, shared constants, etc. - turn it into a directory:

functions/
  song-render/
    index.js          # entry - must have `export default async function ...`
    sanitize.js       # helper - `export function sanitizeRenderOptions(...)`
    constants.js      # `export const DEFAULT_MODE = 'preview'`

index.js is the entry; sibling files are reached via relative import:

// functions/song-render/index.js
import { sanitizeRenderOptions } from './sanitize.js';

export default async function songRender(ctx, { db, jobs, guid }) {
  const opts = sanitizeRenderOptions(ctx.body?.render_options);
  // ...
}

Why use multi-file:

Pass services into helpers as arguments. The entry's handler receives (ctx, services). The service names also resolve as free globals in any module, but a helper that reaches for a global db can't be unit-tested from tests/, so keep helpers pure: if a helper needs the DB, the entry passes it in:

// functions/song-render/sanitize.js - PURE helper, no service access
export function sanitizeRenderOptions(raw) { /* validates raw, returns clean obj */ }

// functions/song-render/persist.js - needs db, so accept it as arg
export async function saveRender(db, songGuid, opts) {
  await db.query('INSERT INTO renders ...', [songGuid, opts]);
}

// functions/song-render/index.js - entry passes db down
import { sanitizeRenderOptions } from './sanitize.js';
import { saveRender } from './persist.js';
export default async function (ctx, { db }) {
  const opts = sanitizeRenderOptions(ctx.body);
  await saveRender(db, ctx.body.song_guid, opts);
}

Import rules and errors:

Limits: up to 20 files per function (shared _lib files count toward this), 256 KB total source, max 4 levels of nesting.

Pick the shape that fits: single functions/foo.js for simple handlers; functions/foo/ directory once you have a helper you'd like to unit-test.

Shared modules across functions (functions/_lib/)

When two or more functions need the same code - a schema registry, validation, SQL builders - put it in functions/_lib/ instead of copy-pasting it into each function directory (copies drift):

functions/
  _lib/
    registry.js       # shared - `export function describeObject(...)`
  record-read/
    index.js          # imports it: `import { describeObject } from '../_lib/registry.js'`
  record-write.js     # single-file functions can import it the same way

At deploy, _lib/ files are bundled into every function's payload, so editing a shared module re-deploys all functions automatically. The rules:

The function runtime supports single-file ESM (shipped 2026-05-29), multi-file functions with relative ./helper.js imports (2026-05-30), and shared _lib modules imported as ../_lib/<file>.js (2026-06-09).

Kits that ship backend pieces (gipity add contacts ...)

Some kits install more than frontend code. A kit whose manifest declares functions: true / migrations: true copies its functions/ and migrations/ trees into the app's own functions/ and migrations/: contacts (contact-* functions and the contact tables), stripe (payment-events, payment-status, the payments/subscriptions tables) and leaderboard (leaderboard-* functions and the board tables). They need a database template (web-fullstack or api). Rules:

Versioning & Rollback

A function is deployed from its source file, and every file save keeps a version. To roll a function back, restore the file and redeploy:

gipity file versions functions/my-function.js
gipity file restore functions/my-function.js 3
gipity deploy

Management Commands

gipity fn list                 # List all functions
gipity fn logs <name>          # Execution logs
gipity fn call <name> [body]   # Call one
gipity fn delete <name>        # Delete

Rate Limits


Verifying webhook signatures (via crypto)

Third-party webhooks (Stripe, GitHub, Shopify, Slack, Svix/Clerk) sign the raw request body with an HMAC of a shared secret and send the signature in a header. Point the provider at https://a.gipity.ai/api/<appGuid>/fn/<name> (an auth: public function, the default), store the signing secret with gipity secrets set WEBHOOK_SECRET <secret>, and verify before doing anything:

// functions/github-webhook.js
export default async function (ctx, { secrets, crypto }) {
    const secret = await secrets.get('WEBHOOK_SECRET');
    const expected = 'sha256=' + crypto.hmac('sha256', secret, ctx.rawBody);
    const got = ctx.headers['x-hub-signature-256'] || '';
    if (!crypto.timingSafeEqual(expected, got)) return { error: 'bad signature' };
    // Verified: now trust ctx.body (the same bytes, parsed).
    return { ok: true, action: ctx.body.action };
}

On-demand actions: button to function vs. a Gipity workflow

When the user wants to "trigger" or "run on demand" something, pick by where it runs:

A workflow can't read the user's device or DOM, so don't model a browser-driven button as one.


Related Skills