UNPKG

@croct/plug

Version:

A fully-featured devkit for building natively personalized applications.

23 lines (22 loc) 749 B
import { Evaluator } from "@croct/sdk/evaluator"; import { formatCause } from "@croct/sdk/error"; function evaluate(query, options) { const { baseEndpointUrl, fallback, apiKey, appId, logger, ...evaluation } = options; const auth = apiKey !== void 0 ? { apiKey } : { appId }; const promise = new Evaluator({ ...auth, baseEndpointUrl }).evaluate(query, evaluation); if (fallback !== void 0) { return promise.catch( (error) => { if (logger !== void 0) { const reference = query.length > 20 ? `${query.slice(0, 20)}...` : query; logger.error(`Failed to evaluate query "${reference}": ${formatCause(error)}`); } return fallback; } ); } return promise; } export { evaluate };