Skip to Content
Aperture

Node SDK

@acruxdynamics/aperture: read params, secrets and trigger payloads, fire triggers, and verify webhooks.

@acruxdynamics/aperture is a small, dependency-free helper library for Node.js (18 or later). It's ESM-only and ships TypeScript types.

npm install @acruxdynamics/aperture

Using it is optional: everything it reads is a plain environment variable.

Params and secrets

import { getApertureParam, getApertureSecret } from '@acruxdynamics/aperture';

const date = getApertureParam('REPORT_DATE', new Date().toISOString().slice(0, 10));
const slackUrl = getApertureSecret('SLACK_WEBHOOK_URL');

getApertureParam(name, defaultValue?)

Returns the value of the environment variable name. If it's unset or empty, returns defaultValue. If that's also missing or empty, throws ApertureRuntime: Parameter <name> is not set.

getApertureSecret(name, defaultValue?)

Same behavior; the error is ApertureRuntime: Secret <name> is not set. Remember to list the secret in the manifest's secrets.

Trigger payloads

import { getApertureTrigger, type EventBridgeEvent } from '@acruxdynamics/aperture';

const trigger = getApertureTrigger();

if (!trigger) {
  console.log('manual or scheduled run');
} else if (trigger.source === 'generic') {
  const event = trigger.json<EventBridgeEvent<{ severity: number }>>();
  console.log(event['detail-type'], event.detail.severity);
} else {
  console.log(trigger.sns?.subject, trigger.payload);
}

getApertureTrigger()

Returns null when the run wasn't started by a trigger. Otherwise returns an ApertureTriggerEvent:

interface ApertureTriggerEvent {
  triggerId: string;
  source: 'generic' | 'sns';
  payload: string; // raw body (generic) or SNS Message (sns)
  sns?: { subject?: string; messageId?: string; topicArn?: string };
  json<T = unknown>(): T; // JSON.parse(payload); throws if not JSON
}

requireApertureTrigger()

Like getApertureTrigger(), but throws when the run wasn't started by a trigger.

Firing a trigger

Start a run of another job from code, through its generic trigger:

import { fireApertureTrigger, ApertureTriggerError } from '@acruxdynamics/aperture';

try {
  const { executionId, duplicate } = await fireApertureTrigger({
    url: 'https://aperture-server.mountaindev.com/api/v1/triggers/<trigger-id>',
    token: process.env.REPORT_TRIGGER_TOKEN!,
    payload: { reportId: 42 }, // objects are sent as JSON, strings as text/plain
  });
  console.log('started', executionId, duplicate ? '(duplicate)' : '');
} catch (err) {
  if (err instanceof ApertureTriggerError) console.error(err.status, err.body);
  throw err;
}

Any response other than 202 throws an ApertureTriggerError with status and body. You can pass a custom fetch in the options.

Verifying webhooks

buildApertureWebhook checks an outbound webhook's signature and returns the parsed event. Pass the raw request body, not re-serialized JSON.

import express from 'express';
import { buildApertureWebhook } from '@acruxdynamics/aperture';

const app = express();

app.post('/hooks/aperture', express.raw({ type: 'application/json' }), (req, res) => {
  let event;
  try {
    event = buildApertureWebhook(process.env.APERTURE_WEBHOOK_SECRET!, {
      rawBody: req.body,
      headers: req.headers, // a plain object or a Fetch Headers instance
    });
  } catch {
    return res.sendStatus(400);
  }

  if (event.type === 'execution.failed') {
    console.log('job failed', event.data.object);
  }
  res.sendStatus(200);
});

It throws when the aperture-signature header is missing or malformed, the signature doesn't match, the body isn't JSON, or the envelope's api_version isn't 2025-05-01.

It doesn't check the timestamp. To guard against replayed requests, reject events whose created time is too old, or remember the event ids you've processed.

Exports

ExportKind
getApertureParam, getApertureSecretfunctions
getApertureTrigger, requireApertureTriggerfunctions
fireApertureTrigger, ApertureTriggerErrorfunction, error class
buildApertureWebhookfunction
ApertureTriggerEvent, ApertureTriggerSource, ApertureSnsMetadata, EventBridgeEventtypes
FireApertureTriggerOptions, FireApertureTriggerResulttypes
ApertureWebhookData, ApertureWebhookEnvelope, ApertureApiVersiontypes

TypeScript config

@acruxdynamics/tsconfig is a shared base config (ES2023, ESNext modules, bundler resolution, strict). It expects @types/node:

tsconfig.json
{
  "extends": "@acruxdynamics/tsconfig/tsconfig.json",
  "compilerOptions": { "outDir": "dist" },
  "include": ["src"]
}

On this page