@omneo/extension-kit
Shared, versioned infrastructure for Omneo extensions. The package provides small, framework-independent building blocks for services that need consistent logging redaction, tenant and webhook security checks, and in-process caching.
The package has no Fastify, Datastore, or Omneo SDK dependency, so it can be used by extensions with different application and provider integrations.
Setup
Requires Node.js 24.x.
npm install @omneo/extension-kit
The package exposes focused subpath imports:
import { MemoryCache } from '@omneo/extension-kit/cache'
import { sensitiveLogRedaction } from '@omneo/extension-kit/logging'
import { sanitizeTenant, verifyHmacSha256 } from '@omneo/extension-kit/security'
import { checkTenantStatus, TenantUnavailableError } from '@omneo/extension-kit/tenant-status'
import { resolveTenantContext } from '@omneo/extension-kit/tenant'
import { getInstallableCustomFields, readOptionalField } from '@omneo/extension-kit/provisioning'
Use Cases
- Configure Pino or another compatible logger to redact credentials, tokens, secrets, and webhook signatures, and lint for code that bypasses it.
- Validate tenant identifiers and compare SHA-256 webhook signatures using timing-safe checks.
- Cache tenant context or short-lived request state with optional TTL and bounded memory usage.
- Mark rarely-needed custom fields
opt-in so they are not created on every new install, and read them safely when absent.
- Short-circuit requests for a tenant whose service has been permanently decommissioned, without re-checking the source of truth on every request.
API
Cache
const cache = new MemoryCache({ maxEntries: 1000 })
cache.set('tenant-context', context, 300)
const cachedContext = cache.get<unknown>('tenant-context')
cache.delete('tenant-context')
Security
const tenant = sanitizeTenant(request.params.tenant)
const valid = verifyHmacSha256({
body: request.rawBody,
secret: webhookSecret,
signature: request.headers['x-omneo-hmac-sha256'],
})
sanitizeTenant, validateHmacSignature, and verifyHmacSha256 throw SecurityValidationError for invalid input. verifyHmacSha256 returns false when a validly formatted signature does not match.
Logging
gcpLoggerOptions() returns Pino options that write the shape every extension shares on Cloud Run: GCP severity, message, an ISO time, no pid or hostname, and sensitiveLogRedaction. Every line also passes through scrubLogPayload and limitLogPayload, which mask credentials and personal data and cap the size by the same rules as the Core API. The kit does not depend on Pino; pass the options to pino() or to Fastify's logger option.
import { errorReport, gcpLoggerOptions, gcpLogBindings, payloadForLog } from '@omneo/extension-kit/logging'
const server = Fastify({ logger: gcpLoggerOptions({ level: process.env.LOG_LEVEL ?? 'info' }) })
// Once the tenant is validated: tenant and trace on every line of the request.
request.log = request.log.child(
gcpLogBindings({ tenant, traceparent: request.headers.traceparent, projectId: process.env.GOOGLE_CLOUD_PROJECT })
)
// Success: size, hash and field names; the masked payload only while the tenant's debug switch is on.
request.log.info({ orderId: order.id, ...payloadForLog(order, { debugUntil: config.log_payload_until }) }, 'Order synced to Omneo')
// Failure: the masked payload, and the stack Error Reporting groups by.
request.log.error({ orderId: order.id, ...payloadForLog(order, { full: true }), ...errorReport(err) }, 'Order sync failed')
The levels, the payload rule and the set-up are in docs/logging-contract.md. To use only the redaction paths with another logger, pass { redact: sensitiveLogRedaction }.
Redaction only works on object paths. Log errors through safeErrorInfo, which keeps the message, status code and response body and drops the request config that HTTP/SDK errors carry (the Authorization header and request body):
import { safeErrorInfo } from '@omneo/extension-kit/logging'
request.log.error({ tenant, ...safeErrorInfo(err) }, 'Upstream call failed')
ESLint (log safety)
@omneo/extension-kit/eslint exports flat-config entries that fail the build when code bypasses redaction: console.*, and raw error objects passed to a logger (log.error(err), log.error({ error }), JSON.stringify(err)).
import { logSafetyConfig } from '@omneo/extension-kit/eslint'
export default [
// ...recommended configs
...logSafetyConfig(), // options: { files, errorHelper, noConsole }
]
If the extension already sets no-restricted-syntax, spread logSafetyRestrictedSyntax() into its own array instead, because a later config replaces that rule's options rather than merging them. See docs/log-safety.md for adoption steps and the AGENTS.md snippet to copy into each extension.
Tenant status
await checkTenantStatus(
tenant,
async (tenant) => {
// Look up the tenant's status from whatever store the extension uses
// (e.g. a shared Datastore kind). Must resolve 'active' or 'decommissioned'.
return fetchTenantStatusFromDatastore(tenant)
},
cache
)
checkTenantStatus throws TenantUnavailableError (statusCode: 410) when the tenant is decommissioned, and resolves otherwise. It caches the result in the given CacheStore so fetchStatus is not called on every request; a decommissioned result is cached far longer than an active one by default, since decommissioning does not reverse under normal operation. The kit does not read the tenant's status itself — the calling extension supplies fetchStatus, keeping this package free of any Datastore/provider dependency.
Tenant context
const config = await resolveTenantContext(request.params.tenant, {
cache,
fetchConfig: async (tenant) => {
// Look up and assemble the tenant's config (Omneo tokens, webhook secrets,
// provider credentials, custom fields, ...) from whatever source the extension uses.
return fetchTenantConfigFromOmneo(tenant)
},
logger: request.log,
})
resolveTenantContext sanitizes the tenant id, returns a cached config on a hit, and otherwise calls fetchConfig and caches its result. It only ever logs the tenant id — never the resolved config or the cache contents — so tokens, webhook signing secrets, and other credentials embedded in tenant config cannot leak into structured logs through this path. Do not add logging around the resolved config or the CacheStore at the call site for the same reason; if a call site needs a "cache hit/miss" trace for debugging, pass a logger instead of dumping the config or cache directly.
Provisioning (opt-in custom fields)
Mark a custom field in the extension's config.ts with provision: 'opt-in' to keep it out of new installs. Fields without provision (or with 'default') are created as before.
// config.ts
customFields: [
{ name: 'Enabled', handle: 'enabled', namespace: NAMESPACE, value: true, type: 'boolean' },
{ name: 'Hidden Sections', handle: 'hidden_sections', namespace: NAMESPACE, value: {}, type: 'json', provision: 'opt-in' },
]
// install step
const fields = getInstallableCustomFields(configTemplate.customFields)
await Promise.all(fields.map((field) => omneoClient.tenants.createCustomField(field)))
// wherever the field is used: it will not exist on tenants that never opted in
const hidden = readOptionalField<Record<string, boolean>>(config.extension, 'hidden_sections', {})
getInstallableCustomFields drops opt-in fields, strips the provision marker so it never reaches the Omneo API, and returns copies (the template is never mutated). An unrecognised provision value throws rather than silently installing the field.
readOptionalField(config, handle, fallback) returns fallback when the config is missing, the handle is absent, or the value is null/undefined. Deliberately set falsy values ('', 0, false) are returned as-is. Every reader of an opt-in field must go through it (or an equivalent check).
opt-in only affects what is created on a new install. It never deletes anything: tenants installed before a field became opt-in keep their existing field and its value. Uninstall/cleanup is unaffected. A tenant that wants an opt-in feature creates the field afterwards (e.g. in CX Manager).
Development
The repository uses Yarn 1.22.22 for development.
yarn install --frozen-lockfile
yarn lint
yarn build
yarn test:exports
yarn test
npm pack --dry-run