Skip to content

FYInbox docs

TypeScript SDK

Use the server-only TypeScript client for runtime validation, bounded responses, safe errors, deadlines, and conservative retry behavior.

Current availability

Create a client

TypeScript
import { NotificationsClient, NotificationsError } from "@notifications/sdk";

function requiredEnv(
  name: "NOTIFICATIONS_API_KEY" | "NOTIFICATIONS_URL",
): string {
  const value = process.env[name];
  if (value === undefined || value.length === 0) {
    throw new Error(`Set ${name} before running this example.`);
  }
  return value;
}

const client = new NotificationsClient({
  apiKey: requiredEnv("NOTIFICATIONS_API_KEY"),
  baseUrl: requiredEnv("NOTIFICATIONS_URL"),
});

try {
  const result = await client.createNotification({
    title: "Deployment finished",
    body: "billing-api is healthy in production.",
    severity: "success",
    tags: ["production", "deploy"],
    source: "billing-api",
    externalId: "deploy-abc124",
    deduplicationKey: "deploy:billing-api:abc124",
    metadata: {
      environment: "production",
      commit: "abc124",
    },
    actions: [
      {
        id: "open-deploy",
        type: "link",
        label: "Open deployment",
        href: "https://example.com/deployments/abc124",
        style: "primary",
      },
    ],
  });

  process.stdout.write(`${JSON.stringify(result)}\n`);
} catch (error) {
  const safeError =
    error instanceof NotificationsError
      ? error.toJSON()
      : { kind: "unexpected_error" };
  process.stderr.write(`${JSON.stringify(safeError)}\n`);
  process.exitCode = 1;
}

Safety behavior

  • Call getNotification(id) to retrieve the complete stored context for a notification in the API key's source.
  • The default total deadline is 10 seconds and can be overridden per client or request.
  • Read requests are safe to retry after network and transient server failures.
  • At most two retries are attempted, and ambiguous create failures are retried only when the request has a deduplicationKey.
  • Metadata mutations are not repeated after ambiguous network or server failures.
  • Typed errors omit the API key, Authorization header, request payload, and untrusted server message.
  • The client fails closed in browser runtimes because source API keys are server-side credentials.