TypeScript SDK
@owlieapp/sdk is Owlie's typed TypeScript client for the GraphQL API. It turns operations into
methods grouped by subject, such as owlie.identities.get(...) and owlie.requests.create(...), with
typed arguments and results, cursor paging and one error type.
Where you can use it
Today you get the SDK in one place: inside an Owlie function. When a function has Owlie Access
turned on, Owlie passes a ready client as context.owlie. You don't install or construct anything,
and the function holds no API key. The
function programming reference
describes how that access is set up and what it may do.
The package is not published to the public npm registry, so npm install @owlieapp/sdk does not
work for code that runs outside Owlie. From your own services, call the GraphQL API directly: the
developer quickstart shows a request with fetch, and every SDK
method is a GraphQL operation you can send yourself.
The rest of this page describes the client as you use it in a function.
export default async function onEvent(input: EventActionInput, context: OwlieRuntimeContext) {
const manager = input.identity.manager_id ? await context.owlie.identities.get(input.identity.manager_id) : null;
return {
message: { level: "info", text: `Manager: ${manager?.display_name ?? "none"}` },
};
}
The SDK adds no authority
Every method sends one GraphQL operation to the same API, and the API authorizes it against the
caller. In a function the caller is the function's own service account with the roles you assigned
it. A method the caller may not use fails with AUTHORIZATION_ERROR. The SDK cannot widen what a
caller is allowed to do.
Namespaces
Methods are grouped into namespaces on the client. Namespace names, method names and argument keys are snake_case. The objects that come back keep the API's field names.
A function's client has these namespaces:
| Namespace | Covers |
|---|---|
identities | Get, list, create, update and delete identities. |
groups | Get, list, create, update and delete groups. Members and nested groups. |
roles | Get and list roles and read the permission matrix. |
resources | Resources, their Grant targets and who holds them. |
requests | List and process requests, reassign an approval step. |
tickets | List tickets. |
reviews | Access review items and their evidence, ad-hoc review items, due dates and remediation. |
provisioning | Provisioning operations, observed Grants, access checks, retry, cancel and revoke. |
sync | Sync jobs and runs: read them, trigger a job, retry or cancel a run. |
settings | Organization settings. |
tenant | The organization record. |
The client also has methods a function may not use, because Owlie authorizes them per object and not by permission: getting, creating or cancelling one request, request comments, and getting or updating one ticket. Call Owlie from a function lists what a function's access excludes.
The function editor types context.owlie and completes its methods, so the editor is the fastest way
to see a method's exact arguments.
The typed methods are a chosen part of the API, not all of it. For anything else, use
raw_query.
Get and list
A namespace that holds a collection has the same three read methods:
// One object, or null when there is none.
const identity = await context.owlie.identities.get("019d1f36-0000-7000-8000-000000000005");
const byEmail = await context.owlie.identities.get({ email: "ava.moreau@acme.example" });
// Every match, one item at a time. The SDK fetches pages as you go.
for await (const person of context.owlie.identities.list({ filter: { department: "Finance" } })) {
console.log(person.display_name);
}
filter takes the same filter syntax as the API, described in
How to use the API.
identities.get({ email }) returns one identity or null. When several identities share the
address it throws AMBIGUOUS_IDENTITY_EMAIL instead of choosing one.
Paging
list() hides paging. When you want pages, use list_paged():
// Iterate pages.
for await (const page of context.owlie.resources.list_paged({ page_size: 200 })) {
console.log(page.data.length, page.pageInfo.hasNextPage);
}
// Or step through them yourself.
let page = await context.owlie.resources.list_paged({ page_size: 200 }).first();
while (page) {
// use page.data
page = await page.next();
}
| Input | Meaning |
|---|---|
page_size | Items a page. The default is 100. A value above 500 is lowered to 500. A value that is not a positive whole number throws. |
after | A cursor to start after: a previous page's pageInfo.nextCursor. Use it to continue without keeping the page object. |
A page is { data, pageInfo }, and pageInfo has hasNextPage, hasPreviousPage, nextCursor and
previousCursor. first() returns null when the list is empty, and next() returns null after
the last page.
A page has no total, and data.length is the size of one page. To count, call one of the API's
counting fields through raw_query (Count without paging).
In a function, every page is one of the invocation's 32 Owlie calls. Filter on the server and choose a page size that fits, instead of walking a long list.
Send any operation with raw_query
raw_query sends a GraphQL document you write, with variables, and returns data:
type Stats = { resourceStats: { total: number } };
const { resourceStats } = await context.owlie.raw_query<Stats>(
"query HighRisk($filter: JSONObject) { resourceStats(filter: $filter) { total } }",
{ filter: { risk_level: { $gte: 4 } } },
);
It goes through the same API and the same authorization as the typed methods. Variable names and field names are the API's own, not snake_case translations. The schema reference lists what you can send.
Errors
Every failure, whether the request never completed or the API refused the operation, throws an
OwlieSDKError. Branch on code, never on the message text:
try {
await context.owlie.identities.update(identityId, { department: "Finance Operations" });
} catch (error) {
if (error.name === "OwlieSDKError" && error.code === "AUTHORIZATION_ERROR") {
// the function's service account lacks the role for this
} else {
throw error;
}
}
| Property | Holds |
|---|---|
code | The kind of failure. Errors and API limits lists the codes. |
status | The status the failure stands for, such as 403. |
operation | The operation that failed. |
retryable | Whether sending the same call again can succeed. The SDK never retries for you. |
raw | The API's original error entries. |
The client outside a function
The same client class backs other parts of Owlie, and its constructor takes an API key and your domain:
import { OwlieSDK } from "@owlieapp/sdk";
const owlie = new OwlieSDK({
apiKey: process.env.OWLIE_API_KEY!,
tenantDomain: "acme.owlie.com",
});
tenantDomain is a host name only, optionally with a port: a value with a protocol or a path is
refused. Built this way, the client sends every operation to https://<tenantDomain>/api/graphql
with Authorization: Owlie <apiKey> and acts as the key's service account. This form needs the
package itself, which Owlie does not distribute publicly at present.