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
| Property | Holds |
|---|---|
context.secrets | The function's secrets, as an object of strings keyed by secret name. Read-only. |
context.owlie | A typed Owlie API client. Present only when the function has Owlie Access turned on (below). |
context.tenantDomain | Your organization's Owlie host name, such as acme.owlie.com. |
context.tenantId | Your organization's id. |
context.functionId | This function's id. |
context.versionId | The 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:
| Field | Holds |
|---|---|
request | The request: id, request_number, requester_id, beneficiary_id, status, source, created_at, updated_at. |
requestResource | The requested resource item this step belongs to: id, request_id, resource_id, status. |
resource | The resource: id, name, description, picture. |
form_data, form_definition | The 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, beneficiary | Each an object with identity, the identity's groups and its roles. |
manager | The same for the beneficiary's manager, or null. |
step | This approval step: id, stepOrder, functionId. |
Return one of three results. reason and metadata are optional on each.
| Result | Effect |
|---|---|
{ 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:
| Field | Holds |
|---|---|
success | Required. true when the change was made, false when it was not. |
message | Optional text shown with the operation, up to 4,096 characters. |
state.attributes | Optional. 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: theidentity, theresourceand the item being reviewed, which is an account or one Grantreview: what triggered it, and the campaignpolicy: the stages and decision rulessignals:risk_leveltiming
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:
| Field | Holds |
|---|---|
event | id, 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_id | The identity the event is about, as it is after the change. |
invocation_key | A 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.entity | Extra fields |
|---|---|
IDENTITY | changed_keys, identity_changes_old, identity_changes_new: which attributes changed, with their old and new values. |
GROUP | group_id, is_direct, and path: the ids of the groups the membership runs through. |
RESOURCE | resource_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>;
| Field | Holds |
|---|---|
action | The provisioning action behind the hook, such as PROVISION, REVOKE or DISABLE. |
identity | The identity being provisioned. |
resource | The resource: id, name. |
desired_state | The account Owlie wants: attributes, lifecycleState, entitlements. |
account | The 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. |
params | The parameters configured on the hook. Any parameter written as an OXL expression is already evaluated. |
items | What the operation changes, each with its kind and its result so far. An after hook sees which items failed. |
operation_payload | The 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
manageradded: the manager'sid,display_nameandemail, ornull. - A request action receives
id,request_number,status,created_at,updated_at,requester,beneficiary,resources(each withrequest_resource_id,resource_id,resource_nameandstatus) andticket(idandstatus, ornull).
Both are copies taken when the action runs. Changing them changes nothing in Owlie.
The context has the standard properties plus:
| Property | Holds |
|---|---|
context.actor | Who ran the action: identityId, email, displayName, roleSlugs. Owlie sets it, and the caller cannot. |
context.action | The action: id, slug, label. |
context.entityType | identity or request. |
context.formData | The validated answers to the action's form, or null when it has none. |
context.input | The value passed with the run, if any. |
Every field of the result is optional:
| Field | Effect in the dashboard |
|---|---|
message | Shows { level, text } as a notification. text is shown as plain text, never as HTML. |
refresh | true reloads the page's data. |
navigate | { to } opens that path. |
data | Returned 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,emailand 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,customandsources
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
nullresult. Fulfillment handlers must still return an object with a booleansuccessvalue. - The value can be at most 1 MiB as JSON. Values JSON cannot represent, such as a
Dateobject, aMapor 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.exampleallowshooks.acme.example. Wildcards,localhostand private addresses are refused. - Only
https://requests leave. A plainhttp://request fails. - With network access off,
fetchfails withNetwork 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
AuthorizationandCookieheaders. - 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,myRequestsandmyTickets, 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:
requestswithrequest.read, andticketswithticket.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:
| Limit | Value |
|---|---|
| Owlie calls in one run | 32 |
| Calls in flight at once | 4 |
| One call's GraphQL document | 64 KiB |
| One call's variables | 256 KiB |
| One call's response | 1 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.