Skip to main content

Function programming reference

A function is TypeScript that Owlie runs for you at one point in a workflow: to decide an approval, fulfill access, pick a reviewer, react to a lifecycle event, or run from a menu. You choose that purpose when you create the function, and it fixes what the function receives and what it must return. This page is the contract for each purpose and for the runtime they share. Functions covers creating, publishing and rolling back a function in the dashboard.

The shape of a function​

A function is a module whose default export is the handler:

export default async function approve(input: ApprovalInput, context: OwlieRuntimeContext): Promise<ApprovalResult> {
if (input.resource.name === "Ledger Admin" && input.beneficiary.identity.department !== "Finance") {
return { action: "REJECT", reason: "Ledger Admin is limited to Finance" };
}
return { action: "ASSIGN", assignee: { type: "MANAGER" } };
}

The types in the examples on this page (ApprovalInput, OwlieRuntimeContext, Identity and the rest) are declared for you in the function editor. You don't import them.

Every handler except a fulfillment handler receives two arguments: the purpose's input, and the runtime context.

The runtime context​

PropertyHolds
context.secretsThe function's secrets, as an object of strings keyed by secret name. Read-only.
context.owlieA typed Owlie API client. Present only when the function has Owlie Access turned on (below).
context.tenantDomainYour organization's Owlie host name, such as acme.owlie.com.
context.tenantIdYour organization's id.
context.functionIdThis function's id.
context.versionIdThe id of the version that is running.

Custom action functions get more on the context, listed with their contract.

Contracts by purpose​

Approval​

Runs as a step in a request's approval flow. The handler decides the step or hands it to a person.

type ApprovalHandler = (input: ApprovalInput, context: OwlieRuntimeContext) => Promise<ApprovalResult>;

input holds:

FieldHolds
requestThe request: id, request_number, requester_id, beneficiary_id, status, source, created_at, updated_at.
requestResourceThe requested resource item this step belongs to: id, request_id, resource_id, status.
resourceThe resource: id, name, description, picture.
form_data, form_definitionThe requester's answers to the resource's form, and the form as it was when the request was made. null when there is no form.
requester, beneficiaryEach an object with identity, the identity's groups and its roles.
managerThe same for the beneficiary's manager, or null.
stepThis approval step: id, stepOrder, functionId.

Return one of three results. reason and metadata are optional on each.

ResultEffect
{ action: "APPROVE" }Approves the step.
{ action: "REJECT" }Rejects the step.
{ action: "ASSIGN", assignee: { type: "USER" | "GROUP", id } }Hands the decision to that identity or group.
{ action: "ASSIGN", assignee: { type: "MANAGER" | "APP_OWNER" } }Hands the decision to the beneficiary's manager or the resource's owner.

Owlie waits 30 seconds for an approval function. If it takes longer, throws, or returns anything else, the step errors and the requested item moves to APPROVAL_ERROR.

Fulfillment​

Runs when Owlie provisions or revokes a resource whose fulfiller is this function. A fulfillment handler receives six arguments. The sixth is the runtime context.

export default async function fulfill(
action: FulfillmentAction, // "provision" | "revoke"
identity: Identity,
resource: FulfillmentResource, // { id, name, ... }
formData: Record<string, unknown> | null,
desiredState: FulfillmentDesiredState,
context: OwlieRuntimeContext,
): Promise<FulfillmentResult> {
return { success: true, message: `${action} completed for ${identity.email}` };
}

Read encrypted secrets from context.secrets. When Owlie Access is enabled, context.owlie provides the same bounded SDK access as other function types.

desiredState is the account Owlie wants to exist: attributes, an optional lifecycleState (ACTIVE, DISABLED or DELETED) and optional entitlements.

Return an object with a boolean success:

FieldHolds
successRequired. true when the change was made, false when it was not.
messageOptional text shown with the operation, up to 4,096 characters.
state.attributesOptional. The account's attributes as the function observed them. Owlie validates them and discards sensitive ones.

A result with no boolean success, or one that is too large (65,536 characters as JSON, 16 levels deep or 5,000 values), is not counted as success: the operation goes to manual review. The same happens when the function does not answer within 30 seconds, because Owlie cannot tell whether the change was made. Make the handler safe to run twice for the same identity and resource.

Review reviewer resolver​

Chooses who reviews one item in an access review, where the review policy names this function as a reviewer.

type ReviewerResolverHandler = (
input: ReviewerResolverInput,
context: OwlieRuntimeContext,
) => Promise<ReviewerResolverResult>;

input.context describes the access under review:

  • access: the identity, the resource and the item being reviewed, which is an account or one Grant
  • review: what triggered it, and the campaign
  • policy: the stages and decision rules
  • signals: risk_level
  • timing

input.dry_run is true when the function is called from a preview and no review is being created.

Return the reviewer, or null for no opinion:

return { reviewer: { type: "USER", reference_id: "019d1f36-0000-7000-8000-000000000009" } };
// or
return { reviewer: null };

type is USER or GROUP, and reference_id the identity's or group's id. With { reviewer: null }, Owlie uses the review policy's fallback reviewers.

Event action​

Runs from a lifecycle reaction after an event matches.

type EventActionHandler = (input: EventActionInput, context: OwlieRuntimeContext) => Promise<EventActionResult>;

Every input has:

FieldHolds
eventid, occurred_at, and type: one of IDENTITY.CREATE, IDENTITY.MODIFY, IDENTITY.DELETE, GROUP.ADD, GROUP.REMOVE, RESOURCE.ADD, RESOURCE.SET, RESOURCE.REMOVE. entity and operation are the two halves of type.
identity, identity_idThe identity the event is about, as it is after the change.
invocation_keyA string that stays the same if Owlie runs this step again. Use it to avoid repeating an external side effect.

The rest depends on event.entity:

event.entityExtra fields
IDENTITYchanged_keys, identity_changes_old, identity_changes_new: which attributes changed, with their old and new values.
GROUPgroup_id, is_direct, and path: the ids of the groups the membership runs through.
RESOURCEresource_id, assigned_resource_id, lifecycle_old, lifecycle_new, origin.

Return { message: { level, text } } to record a note with the run, where level is success, info, warn or error. data is optional.

Provisioning hook​

Runs as a before or after hook on a resource's provisioning profile (Hooks and delayed operations). A hook is a side effect: nothing it returns changes the account Owlie provisions.

type HookActionHandler = (input: HookActionInput, context: OwlieRuntimeContext) => Promise<HookActionResult>;
FieldHolds
actionThe provisioning action behind the hook, such as PROVISION, REVOKE or DISABLE.
identityThe identity being provisioned.
resourceThe resource: id, name.
desired_stateThe account Owlie wants: attributes, lifecycleState, entitlements.
accountThe account as known when the hook runs: identifiers (the account's ids in the application), observed_attributes when Owlie has read them, and lifecycle_state.
paramsThe parameters configured on the hook. Any parameter written as an OXL expression is already evaluated.
itemsWhat the operation changes, each with its kind and its result so far. An after hook sees which items failed.
operation_payloadThe originating operation's payload, or null.

Return { success: true }, optionally with a message. Returning { success: false, message } fails the hook, and the hook's failure setting decides what happens to the operation.

Identity action and request action​

Run when someone picks a custom action from an identity's or a request's Quick Actions menu.

type IdentityActionHandler = (
identity: IdentityActionInput,
context: CustomActionContext<"identity">,
) => Promise<CustomActionResult>;
type RequestActionHandler = (
request: RequestActionInput,
context: CustomActionContext<"request">,
) => Promise<CustomActionResult>;

The first argument is the object the action was run on:

  • An identity action receives the identity, with manager added: the manager's id, display_name and email, or null.
  • A request action receives id, request_number, status, created_at, updated_at, requester, beneficiary, resources (each with request_resource_id, resource_id, resource_name and status) and ticket (id and status, or null).

Both are copies taken when the action runs. Changing them changes nothing in Owlie.

The context has the standard properties plus:

PropertyHolds
context.actorWho ran the action: identityId, email, displayName, roleSlugs. Owlie sets it, and the caller cannot.
context.actionThe action: id, slug, label.
context.entityTypeidentity or request.
context.formDataThe validated answers to the action's form, or null when it has none.
context.inputThe value passed with the run, if any.

Every field of the result is optional:

FieldEffect in the dashboard
messageShows { level, text } as a notification. text is shown as plain text, never as HTML.
refreshtrue reloads the page's data.
navigate{ to } opens that path.
dataReturned to an API caller.

Endpoint​

New Endpoint functions cannot be created in the dashboard or API. Existing functions remain available for editor runs.

An endpoint function takes a request-like input and returns a response-like result:

type EndpointHandler = (input: EndpointInput, context: OwlieRuntimeContext) => Promise<EndpointResult>;

input.payload is an object, and input.request can carry path, method, headers and query. Return { status, body?, headers? }. No workflow in Owlie calls an endpoint function: you run it from the function editor with a test payload.

The identity object​

Wherever a contract passes an identity, it has the same fields:

  • id, type, status, display_name, email and the name fields
  • the organization fields: title, department, division, business_unit, organization, team, cost_center, location, region
  • the employment fields: employee_id, external_id, employee_type, employment_status, hire_date, start_date, end_date, contract_end_date, job_code, job_family, job_level, job_function, is_manager, manager_id
  • lifecycle_state, tags, custom and sources

Any profile field can be null. custom holds your custom attributes, and sources says where each attribute's value came from.

An identity in an input is a copy. To change an identity, call Owlie through context.owlie.

Return values​

A function's return value crosses back to Owlie as JSON:

  • A handler that returns nothing succeeds with a JSON null result. Fulfillment handlers must still return an object with a boolean success value.
  • The value can be at most 1 MiB as JSON. Values JSON cannot represent, such as a Date object, a Map or a function, are converted or dropped, and a value with a cycle fails.
  • A thrown error fails the run. Its message is recorded with the run.

Secrets​

A secret is a named string stored encrypted with the function and passed to the handler in context.secrets:

const response = await fetch("https://hooks.acme.example/owlie", {
method: "POST",
headers: { authorization: `Bearer ${context.secrets.WEBHOOK_TOKEN}` },
body: JSON.stringify({ identity: input.identity_id }),
});
  • A name is uppercase letters, digits and underscores, starts with a letter or underscore, and is at most 64 characters: WEBHOOK_TOKEN.
  • A value is at most 8,192 characters.
  • A version holds at most 20 secrets.
  • On a published version you can replace a secret's value without publishing again. Adding or removing a secret name needs a new version.

Owlie replaces secret values with a placeholder in a run's recorded logs, input and output. That covers the exact value only: a secret you encode or split is not recognized, so don't log one.

Network access​

A function has no network access until you turn it on and list the hosts it may reach.

  • Each entry is a public host name, and covers its subdomains: acme.example allows hooks.acme.example. Wildcards, localhost and private addresses are refused.
  • Only https:// requests leave. A plain http:// request fails.
  • With network access off, fetch fails with Network access is not enabled for this function. Enable it in the function settings and add allowed domains.
  • A redirect is checked against the list at every hop. When a redirect leaves the original host, Owlie drops the Authorization and Cookie headers.
  • A function with network access on and an empty list cannot be published.

Call Owlie from a function​

A function reaches Owlie's own API through context.owlie, the TypeScript SDK. It exists only when the function has Owlie Access turned on.

Turning Owlie Access on creates a service account for the function, with no roles. You then assign it the roles the function needs. The function never holds a key: context.owlie works only inside the run it was passed to, so there is no credential to copy, leak or rotate. Turning Owlie Access off stops the function's calls at once.

export default async function onEvent(input: EventActionInput, context: OwlieRuntimeContext) {
if (input.event.type !== "IDENTITY.MODIFY") return {};

const manager = input.identity.manager_id ? await context.owlie.identities.get(input.identity.manager_id) : null;
return { message: { level: "info", text: `Manager is ${manager?.display_name ?? "not set"}` } };
}

A function's access is narrower than an API key's with the same roles:

  • Roles only. Only permissions from roles assigned directly to the function's service account count. Group membership and access granted in other ways do not.
  • No caller-scoped fields. Fields that answer for the caller, such as myProfile, myRequests and myTickets, are refused.
  • Nothing decided per object. Operations that Owlie authorizes by the caller's relationship to one object, instead of by a permission, are refused. That covers creating a request, reading or cancelling one request by id, request comments, and reading one ticket by id or the tickets of one request. The lists behind a permission still work: requests with request.read, and tickets with ticket.read.
  • No reusable authority. A function can never manage API keys, role assignments, functions, gateways or the Owlie identity provider, even if one of its roles has those permissions.
  • No schema introspection.

Each run has a budget:

LimitValue
Owlie calls in one run32
Calls in flight at once4
One call's GraphQL document64 KiB
One call's variables256 KiB
One call's response1 MiB

A call the service account may not make throws an OwlieSDKError with the code AUTHORIZATION_ERROR.

Logs and runs​

console.log, info, warn, error and debug are captured with the run, not printed anywhere else. A run keeps the most recent 200 entries, 4,096 characters an argument and 128 KB in all.

Owlie records every run's outcome, duration and version. It keeps the input, output and logs for a test run from the editor and for a run that fails. A successful run in a live workflow keeps only its outcome and timing.

Runtime rules​

  • Each run starts fresh. Module-level variables do not carry from one run to the next, so keep no state in memory.
  • A run is one handler call. There is no way to keep working after it returns.
  • A function runs only its published version in workflows. A draft runs only when you test it.
  • Functions never run OXL, and OXL never runs functions: OXL is the expression language for mappings and conditions.