Skip to content

Interface: FormulaDef<ParamsT, ResultT, ContextT>

Base type for the inputs for creating a formula.

Extends

Extended by

Type Parameters

Type Parameter Default type
ParamsT extends ParamDefs -
ResultT extends FormulaResult -
ContextT extends ExecutionContext ExecutionContext

Properties

cacheTtlSecs?

readonly optional cacheTtlSecs: number

How long formulas running with the same values should cache their results for.

Inherited from

CommonFormulaDef.cacheTtlSecs


connectionRequirement?

readonly optional connectionRequirement: ConnectionRequirement

Does this formula require a connection (aka an account)?

Inherited from

CommonFormulaDef.connectionRequirement


description

readonly description: string

A brief description of what the formula does.

Inherited from

CommonFormulaDef.description


examples?

readonly optional examples: object[]

Sample inputs and outputs demonstrating usage of this formula.

params

params: (FormulaValue | undefined)[]

result

result: FormulaResult

Inherited from

CommonFormulaDef.examples


extraOAuthScopes?

readonly optional extraOAuthScopes: string[]

OAuth scopes that the formula needs that weren't requested in the connector's overall authentication config. For example, a Slack connector can have one formula that needs admin privileges, but non-admins can use the bulk of the connector without those privileges. The platform will give users help in understanding that they need additional authentication to use a formula with extra OAuth scopes. Note that these scopes will always be requested in addition to the default scopes for the connector, so an end user must have both sets of permissions.

Inherited from

CommonFormulaDef.extraOAuthScopes


instructions?

readonly optional instructions: string

Instructions for LLMs to use the formula, overrides the description for LLMs if set.

Inherited from

CommonFormulaDef.instructions


isAction?

readonly optional isAction: boolean

Does this formula take an action (vs retrieve data or make a calculation)? Actions are presented as buttons in the Superhuman Docs UI.

Inherited from

CommonFormulaDef.isAction


isExperimental?

readonly optional isExperimental: boolean

If specified, the formula will not be suggested to users in the formula autocomplete. The formula can still be invoked by manually typing its full name.

Inherited from

CommonFormulaDef.isExperimental


isSystem?

readonly optional isSystem: boolean

Whether this is a formula that will be used internally and not exposed directly to users. Not for use by connectors that are not Superhuman-authored.

Inherited from

CommonFormulaDef.isSystem


name

readonly name: string

The name of the formula, used to invoke it.

Inherited from

CommonFormulaDef.name


network?

readonly optional network: Network

Deprecated

use isAction and connectionRequirement instead

Inherited from

CommonFormulaDef.network


parameters

readonly parameters: ParamsT

The parameter inputs to the formula, if any.

Inherited from

CommonFormulaDef.parameters


validateParameters?

optional validateParameters: MetadataFormula<ExecutionContext, ParameterValidationResult>

The JavaScript function that implements parameter validation. This is only allowed on sync formulas.

This function takes in parameters and a context containing a PermissionSyncMode and validates the parameters. A formula may want to validate parameters differently for permissionSyncMode 'PermissionAware' vs 'Personal' vs undefined (which represents a formula).

Example

validateParameters: async function (context, _, params) {
  let {quantity, sku} = ensureExists(params);
  let errors = [];
  if (quantity < 0) {
    errors.push({message: "Must be a positive number.", propertyName: "quantity"});
  }
  if (!isValidSku(context, sku)) {
    errors.push({message: `Product SKU not found.`, propertyName: "sku"});
  }
  if (errors.length > 0) {
    return {
      isValid: false,
      message: "Invalid parameter values.",
      errors,
    };
  }
  return {
    isValid: true,
  };
},

Returns

a ParameterValidationResult

Inherited from

CommonFormulaDef.validateParameters


varargParameters?

readonly optional varargParameters: ParamDefs

Variable argument parameters, used if this formula should accept arbitrary numbers of inputs.

Only supported in Superhuman Docs.

Inherited from

CommonFormulaDef.varargParameters

Methods

execute()

execute(params, context): ResultT | Promise<ResultT>

The JavaScript function that implements this formula

Parameters

Parameter Type
params ParamValues<ParamsT>
context ContextT

Returns

ResultT | Promise<ResultT>