Augur

augur-server

Server-side utilities for Next.js — Redis caching, SDK helpers, action factories, and query prefetching.

@simpleapps-com/augur-server

Server-side utilities for Next.js applications. Provides Redis caching, SDK call helpers, server action factories for every Augur microservice, and query prefetching for App Router.

npm install @simpleapps-com/augur-server

Environment

import { env, isDev, isStaging, isProduction } from "@simpleapps-com/augur-server";
ExportDescription
envCurrent environment string
isDevtrue in development
isStagingtrue in staging
isProductiontrue in production

Redis Cache

import { cacheGet, cacheSet, isRedisConnected, getCircuitState } from "@simpleapps-com/augur-server";
ExportDescription
cacheGet(key)Read from Redis cache
cacheSet(key, value, ttl)Write to Redis cache
isRedisConnected()Check Redis connection status
getCircuitState()Get circuit breaker state

withServerCache

Higher-order wrapper for caching any async function result in Redis:

import { withServerCache } from "@simpleapps-com/augur-server";

const getCachedProducts = withServerCache(fetchProducts, {
  key: "products",
  ttl: 300,
});

SDK Call Helpers

import { sdkCall, safeAction } from "@simpleapps-com/augur-server";
ExportDescription
sdkCall(fn)Execute an SDK call with error handling
safeAction(fn)Wrap a server action with standardized error handling

Server Query Client

import { createServerQueryClient, getServerQueryClient } from "@simpleapps-com/augur-server";
ExportDescription
createServerQueryClient()Create a new server-side QueryClient
getServerQueryClient()Get or create a per-request singleton QueryClient

Query Options Helpers

import { createQueryOptions, createSuspenseQueryOptions } from "@simpleapps-com/augur-server";
ExportDescription
createQueryOptions(config)Build TanStack Query options for prefetching
createSuspenseQueryOptions(config)Build suspense-enabled query options

Pagination

import { paginateOffset } from "@simpleapps-com/augur-server";

Utility for offset-based pagination across Augur API list endpoints.

Batch Fetch

import { batchFetch } from "@simpleapps-com/augur-server";

Fetch multiple resources in parallel with concurrency control.

Server Actions

createSiteActions() returns a deep proxy covering every SDK method with automatic Redis caching, edge cache headers, and cache tier resolution. The entire Augur microservices API is covered by the SDK, and the entire SDK is covered by this single factory. No hand-written wrappers needed.

import { createSiteActions } from "@simpleapps-com/augur-server";

const actions = createSiteActions(api, {
  cachePrefix: "my-site:",
  edgeCache: 1,
  redisTtl: 3600,
  longEdgeCache: 8,
  longRedisTtl: 28800,
});

// Every SDK method — naming matches exactly
const item = await actions.items.invMast.doc.get(42);
const stock = await actions.items.invMast.stock.get(42);
const price = await actions.pricing.priceEngine.get({ itemId: "X", customerId: 1 });
const menu = await actions.joomla.menu.doc.get(menuId);
const orders = await actions.customers.customer.orders.list(custId);

Full coverage — same 27 services, 122+ methods as augur-hooks.

Transforms

Custom pre/post processing per method path:

const actions = createSiteActions(api, {
  transforms: {
    "commerce.cartLine.add.create": {
      pre: (args) => args.map(item => ({ ...item, uom: convertUom(item.uom) })),
    },
    "items.categories.get": {
      post: (result) => ({ ...result, children: sortChildren(result.children) }),
    },
  },
});

"use server" Compatibility

The proxy is not serializable across the Next.js server boundary, so sites need thin "use server" wrappers:

// lib/actions/items.ts
"use server";
import { actions } from "@/lib/augur-actions";

export const getInvMastDoc = (id: number) => actions.items.invMast.doc.get(id);
export const getStock = (id: number) => actions.items.invMast.stock.get(id);

Individual Factories (Legacy)

The individual factory functions (createPricingActions, createItemActions, etc.) still work and are not removed. createSiteActions() is the recommended approach for all new code.