@agentpost-tools/eventwolf-sdk
v0.2.1
Published
A typed client for eventwolf, for servers and browsers: a publisher that retries and holds events, query helpers, an inbox client, and verifyWebhook.
Readme
EventWolf SDK
A typed client for EventWolf's HTTP API, with a publisher that retries and holds events, an inbox client for a principal's notifications, and webhook verification. It runs in Node 24, browsers, and edge runtimes wherever fetch and Web Crypto are available.
npm i @agentpost-tools/eventwolf-sdkYou need an Agentpost workspace and a project key for a project that uses EventWolf. Publish an event from your server with its secret key:
import { createClient } from '@agentpost-tools/eventwolf-sdk';
export async function publishResolved(key: string, requestId: string) {
const eventwolf = createClient({ token: key });
const outcome = await eventwolf.events.publish({
specversion: '1.0',
source: '/support/backend',
type: 'request.resolved',
data: { requestId },
});
if (outcome.result === 'rejected') {
throw new Error(`${outcome.code}: ${outcome.issues.join('; ')}`);
}
return outcome.sequence;
}A rejected publish is a result, not an error. To publish without waiting, createPublisher({ client, source }) fills in each event's ID and time, batches events, and retries through an outage.
Webhooks
@agentpost-tools/eventwolf-sdk/webhooks has verifyWebhook, which checks a delivery's signature against the endpoint's secret and returns its event, or throws WebhookVerificationError. Give it the raw body, before any parsing:
import { verifyWebhook } from '@agentpost-tools/eventwolf-sdk/webhooks';
export async function receive(request: Request, secret: string) {
const { event, deliveryId } = await verifyWebhook({
secret,
headers: request.headers,
body: await request.text(),
});
console.log(deliveryId, event.type, event.sequence);
return new Response(null, { status: 204 });
}EventWolf SDK docs cover the client, the publisher, the inbox client, and webhooks.
Changes
On 0.x, changes that break existing calls, exports, types, or publisher behavior bump the minor version; other changes bump the patch.
0.2.0
PUT /configanswers a staleIf-Matchwithstale_versioninstead ofversion_conflict, andPUT /event-types/{type}answers a concurrent edit withstale_versiontoo. OnPUT /config, anIf-Matchof0, or a malformed one, isinvalid_request.- An
Idempotency-Keybelongs to one operation and one caller. A refusal such asnot_foundorstale_versionreplays for 24 hours;invalid_request,config_invalid, andinvalid_filterrun fresh. A blank key, or one over 255 characters, isinvalid_request. - Publishing an empty batch, and reading or cancelling a missing replay, ask your host's authorization first, so a caller without access gets
forbidden. - A JSON
nullrequest body isinvalid_request. eventTypes.listrefuses anafterlonger than 500 characters, the longest event type name.- The error check requires
messageanddocson an error body, and still accepts the Platform's codes such asthrottled. EventwolfApiErrornarrowsdetailsbycode: aftererror.code === 'invalid_filter',error.details?.issuesis typed (sincedetailsis optional), and so isconfig_invalid's, and a rejected publish's codes carry the rejection.codeis EventWolf's codes, the Platform's, andunknown, rather than any string. Code that comparedcodewith a string outside those, or typed a narroweddetailsitself, may need to change.EventwolfApiErroris now a type plus a constructor value rather than a class, sonew EventwolfApiError(...)andinstanceof EventwolfApiErrorstill work, whileclass X extends EventwolfApiErrorno longer works.- New type exports:
ErrorCode,ErrorDetails,ErrorDetailsOf,PublishRejectionDetails,EventwolfApiErrorCode, andEventwolfApiErrorConstructor.
Proprietary: use with Agentpost's hosted services under LICENSE.md.
