@agentpost-tools/identityhound-sdk
v0.5.1
Published
A typed HTTP client for identityhound, for servers and browsers, with its client workflows (`./workflows`), which use no UI framework, and the security notices an app builds from the change feed (`./notices`).
Readme
IdentityHound SDK
A typed client for IdentityHound's HTTP API, with sign-in, session, invitation, and workspace workflows. It runs in Node 24, browsers, and React Native wherever fetch is available.
npm i @agentpost-tools/identityhound-sdkYou need an Agentpost workspace and a project key for a project that uses IdentityHound. Read the project's config on your server with its secret key:
import { createClient } from '@agentpost-tools/identityhound-sdk';
export async function readConfig(key: string) {
const identity = createClient({ token: key });
const { config } = await identity.config.get();
console.log(config.signUp.mode);
return config;
}Security notices
IdentityHound records each change in its change feed and sends no notice about it. @agentpost-tools/identityhound-sdk/notices turns a change into a notice your app chose to send, such as a new way to sign in, and reads the principal's verified addresses. You send it with your own mail:
import { createClient } from '@agentpost-tools/identityhound-sdk';
import {
noticeRecipients,
securityNotice,
} from '@agentpost-tools/identityhound-sdk/notices';
export async function sendNotices(
key: string,
after: number,
sendEmail: (to: string, subject: string, text: string) => Promise<void>,
) {
const identity = createClient({ token: key });
const { events, next } = await identity.events.read({ after });
for (const event of events) {
const notice = securityNotice(event, {
productName: 'Acme',
notices: { identity_linked: true, api_key_created: true },
});
if (!notice) continue;
for (const { to, message } of await noticeRecipients(identity, notice)) {
const text = message.blocks
.map((b) => (b.kind === 'text' ? b.text : ''))
.join('\n');
for (const address of to) await sendEmail(address, message.subject, text);
}
}
return next;
}IdentityHound SDK docs cover the client, workflows, and server helpers. Send security notices covers each notice and its wording.
On 0.x, changes that break existing calls, exports, types, or workflow behavior bump the minor version; other changes bump the patch.
Changelog
0.5.1. GrantsQueryInput has resourceType and resourceId, sent together, so grants.list can answer the grants on one resource, with or without entitlement. Only grants of an entitlement on exactly that resource match: a grant with no resource, or of a bundle, never does.
0.5.0. A project can allow one account per email:
IamConfigandConfigUpdateInputhavesignUp.oneAccountPerEmail, a boolean every config update must send. Stored configs readfalse. Withtrue, a sign-up whose verified email is already on another account answersaccount_exists, with the ways that account signs in indetails.methods, such asemail_codeoroauth:twitch.ErrorCodeandErrorDetailsnameaccount_exists, soIdentityhoundApiErrornarrows itsdetailsto{ methods }. The email-code and OAuth workflows fail withaccount_existstoo, with the samedetails, andemailCodeErrorMessagegives it words.
0.4.0. IdentityHound moved onto the API conventions every Agentpost service shares, and the types follow:
- A change-feed event's
data.contextis{ actor: { id }, onBehalfOf?: { id }, delegationId?, via }, the shape every Agentpost feed uses, instead of{ actorId, onBehalfOfId?, delegationId?, via }. A feed reader readscontext.actor.idandcontext.onBehalfOf?.id. Events already in the feed were moved to the new shape. - A stale
If-Matchonconfig.putanswersstale_versionwhere it answeredversion_conflict, andErrorCodenamesstale_versionandpayload_too_largeinstead. A body over 1 MiB answerspayload_too_large. - A refusal is kept and replayed with its
Idempotency-Keyfor 24 hours, like a success, exceptthrottled,guest_limit,provider_error,trusted_caller_required, andsecret_key_invalid, which a retry runs fresh. Refusals of the request, the caller, or the moment are never replayed either:invalid_request,payload_too_large,unauthenticated,forbidden,idempotency_mismatch,conflict,cursor_expired, andinternal_error. A key belongs to one operation, and is trimmed and at most 255 characters; a blank key isinvalid_request. The query andIf-Matchare part of the request a key stands for, beside the path and body, so the same key with another query orIf-Matchanswersidempotency_mismatch. A keyed request still running holds its key for 300 seconds, where it held it for 60; after that, a retry with the key takes it over and runs the request again. If-Matchis stricter: it takes the version you read,3or"3", of 1 or more. Anything else, such as0, answersinvalid_request, where it could answerversion_conflict.- A JSON body that isn't an object, such as an array or a string, answers
invalid_request.config.putandconfig.validatestill report it as a config issue. - The config a project adopts with is stamped
updatedBy: 'adopt', where it was'system'. events.readanswersnextpast the events atypesfilter skipped, and trims each entry intypes, soa, breads asa,b.- An anonymous caller is refused with
unauthenticatedbefore an operation checks its fields or looks anything up, so on operations that need a signed-in caller it getsunauthenticatedwhere it could getinvalid_request,forbidden,trusted_caller_required, ornot_found, and learns nothing about whether a record exists. That includesconfig.validate, which answered anyone and now needs a signed-in caller or your server, as its reference says. IdentityhoundApiErrornarrowsdetailsbycode: aftererror.code === 'cursor_expired',error.detailsis{ oldest, latest }, andcode_invalid,identity_in_use,throttled,merge_blocked,workspace_limit, andconfig_invalidhave their documented details too.codeis IdentityHound's codes, the Platform's,unknown, andoauth_failed, rather than any string, andErrorDetailsandErrorDetailsOfname the types.IdentityhoundApiErrorCode, that set of codes, andIdentityhoundApiErrorConstructor, the type ofIdentityhoundApiErroritself, are newly exported. Code that comparedcodewith a string outside those, or typed a narroweddetailsitself, may need to change.
Proprietary: use with Agentpost's hosted services under LICENSE.md.
