authhero 4.100.0 → 4.101.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -110,6 +110,50 @@ const dataAdapter = {
110
110
  const { app } = init({ dataAdapter });
111
111
  ```
112
112
 
113
+ ## Outbox: draining from a cron / scheduled handler
114
+
115
+ Authhero uses a transactional outbox to deliver audit events and webhook
116
+ dispatches. Events are delivered per-request by default, but you should also
117
+ run `drainOutbox` on a schedule as a safety net for events that failed
118
+ in-request delivery (e.g. a transient webhook 5xx).
119
+
120
+ Use `createDefaultDestinations` to get the exact same set of destinations the
121
+ in-request middleware uses — that way the cron drain and the per-request
122
+ dispatcher stay in lock-step (hook.\* filtering, retry semantics, the
123
+ `registration_completed_at` finalizer, etc.):
124
+
125
+ ```ts
126
+ import {
127
+ createDefaultDestinations,
128
+ drainOutbox,
129
+ cleanupOutbox,
130
+ } from "authhero";
131
+
132
+ // Cloudflare Workers scheduled handler (one per cron trigger)
133
+ export default {
134
+ async scheduled(_event, env) {
135
+ const destinations = createDefaultDestinations({
136
+ dataAdapter,
137
+ // Called per tenant when draining hook.* events. Return a Bearer
138
+ // access token that your webhook endpoints will accept.
139
+ getServiceToken: async (tenantId) =>
140
+ (await mintServiceToken(tenantId, "webhook")).access_token,
141
+ });
142
+
143
+ await drainOutbox(dataAdapter.outbox, destinations);
144
+ await cleanupOutbox(dataAdapter.outbox, { retentionDays: 7 });
145
+ },
146
+ };
147
+ ```
148
+
149
+ `getServiceToken` is optional: omit it if your cron only needs to sweep up
150
+ log events. When omitted, `hook.*` events are left in the outbox for a later
151
+ run that does provide a token.
152
+
153
+ If you need something custom, the underlying classes are also exported:
154
+ `LogsDestination`, `WebhookDestination`, `RegistrationFinalizerDestination`,
155
+ and the `EventDestination` interface.
156
+
113
157
  ## Contributing
114
158
 
115
159
  Contributions are welcome! Feel free to open issues and submit pull requests to improve Authhero.