authhero 4.102.0 → 4.103.0
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 +24 -25
- package/dist/authhero.cjs +87 -87
- package/dist/authhero.d.ts +127 -34
- package/dist/authhero.mjs +9217 -9071
- package/dist/stats.html +1 -1
- package/package.json +3 -3
package/dist/authhero.d.ts
CHANGED
|
@@ -51851,6 +51851,15 @@ export interface WebhookInvokerParams {
|
|
|
51851
51851
|
data: Record<string, unknown>;
|
|
51852
51852
|
/** The tenant ID */
|
|
51853
51853
|
tenant_id: string;
|
|
51854
|
+
/**
|
|
51855
|
+
* Outbox event id for this invocation. Matches the value the default
|
|
51856
|
+
* invoker sends as the `Idempotency-Key` header — custom invokers should
|
|
51857
|
+
* forward it as the same header (or an equivalent dedupe key) so
|
|
51858
|
+
* downstream receivers can dedupe on outbox retries. Only set when the
|
|
51859
|
+
* invocation originates from the transactional outbox; the legacy inline
|
|
51860
|
+
* dispatcher has no stable event id to forward.
|
|
51861
|
+
*/
|
|
51862
|
+
idempotency_key?: string;
|
|
51854
51863
|
/**
|
|
51855
51864
|
* Lazily creates a service token for authenticating with the webhook endpoint.
|
|
51856
51865
|
* Only creates the token when called — no overhead if you use your own auth.
|
|
@@ -52556,6 +52565,59 @@ export interface OutboxCleanupParams {
|
|
|
52556
52565
|
* Intended for use in a scheduled handler / cron job.
|
|
52557
52566
|
*/
|
|
52558
52567
|
export declare function cleanupOutbox(outbox: OutboxAdapter, params?: OutboxCleanupParams): Promise<number>;
|
|
52568
|
+
/**
|
|
52569
|
+
* Mints a Bearer token for a given tenant. `scope` is forwarded so a custom
|
|
52570
|
+
* `webhookInvoker` can request a non-default scope for its outbound call.
|
|
52571
|
+
*/
|
|
52572
|
+
export type GetServiceToken = (tenantId: string, scope?: string) => Promise<string>;
|
|
52573
|
+
export interface WebhookInvocation {
|
|
52574
|
+
eventId: string;
|
|
52575
|
+
tenantId: string;
|
|
52576
|
+
triggerId: string;
|
|
52577
|
+
payload: {
|
|
52578
|
+
tenant_id: string;
|
|
52579
|
+
trigger_id: string;
|
|
52580
|
+
user?: unknown;
|
|
52581
|
+
request?: unknown;
|
|
52582
|
+
};
|
|
52583
|
+
}
|
|
52584
|
+
export interface WebhookDestinationOptions {
|
|
52585
|
+
timeoutMs?: number;
|
|
52586
|
+
/**
|
|
52587
|
+
* Replaces the default HTTP invoker. When set, each matching webhook is
|
|
52588
|
+
* dispatched by calling `webhookInvoker({ hook, data, tenant_id,
|
|
52589
|
+
* createServiceToken })` instead of issuing a raw `fetch` with a Bearer
|
|
52590
|
+
* token. `createServiceToken(scope?)` lazily mints a token bound to the
|
|
52591
|
+
* invocation's tenant, matching the shape passed to the legacy inline
|
|
52592
|
+
* dispatcher in `hooks/webhooks.ts`.
|
|
52593
|
+
*/
|
|
52594
|
+
webhookInvoker?: WebhookInvoker;
|
|
52595
|
+
}
|
|
52596
|
+
/**
|
|
52597
|
+
* Delivers `hook.*` outbox events to HTTP webhooks configured for the matching
|
|
52598
|
+
* trigger_id. Each POST includes `Idempotency-Key: {event.id}` so downstream
|
|
52599
|
+
* webhook handlers can dedupe if the outbox retries.
|
|
52600
|
+
*
|
|
52601
|
+
* The destination is constructed per-request (via `outboxMiddleware`'s
|
|
52602
|
+
* `getDestinations(ctx)` factory) so it can close over a ctx-bound service
|
|
52603
|
+
* token generator. The same class is also used by the cron `runOutboxRelay`
|
|
52604
|
+
* helper — a consumer's `webhookInvoker` configured via `init()` propagates
|
|
52605
|
+
* to both paths so cron-drained deliveries don't diverge from per-request
|
|
52606
|
+
* ones.
|
|
52607
|
+
*/
|
|
52608
|
+
export declare class WebhookDestination implements EventDestination {
|
|
52609
|
+
name: string;
|
|
52610
|
+
private hooks;
|
|
52611
|
+
private getServiceToken;
|
|
52612
|
+
private timeoutMs;
|
|
52613
|
+
private webhookInvoker?;
|
|
52614
|
+
constructor(hooks: HooksAdapter, getServiceToken: GetServiceToken, options?: WebhookDestinationOptions);
|
|
52615
|
+
accepts(event: AuditEvent): boolean;
|
|
52616
|
+
transform(event: AuditEvent): WebhookInvocation;
|
|
52617
|
+
deliver(events: WebhookInvocation[]): Promise<void>;
|
|
52618
|
+
private invokeCustom;
|
|
52619
|
+
private invokeDefault;
|
|
52620
|
+
}
|
|
52559
52621
|
export interface CreateDefaultDestinationsConfig {
|
|
52560
52622
|
/**
|
|
52561
52623
|
* Data adapter — only the `logs`, `hooks`, and `users` adapters are used
|
|
@@ -52569,9 +52631,17 @@ export interface CreateDefaultDestinationsConfig {
|
|
|
52569
52631
|
* Required if you want `hook.*` events to be drained. Omit for cron
|
|
52570
52632
|
* drains that only need to sweep up log events.
|
|
52571
52633
|
*/
|
|
52572
|
-
getServiceToken?:
|
|
52634
|
+
getServiceToken?: GetServiceToken;
|
|
52573
52635
|
/** Webhook HTTP request timeout in ms (default: 10_000). */
|
|
52574
52636
|
webhookTimeoutMs?: number;
|
|
52637
|
+
/**
|
|
52638
|
+
* Custom webhook invoker — same shape as the `webhookInvoker` option on
|
|
52639
|
+
* `init()`. When provided, `hook.*` events are dispatched by calling this
|
|
52640
|
+
* function instead of issuing a raw `fetch` with a Bearer token. Use this
|
|
52641
|
+
* to match a consumer-configured invoker exactly, so cron-drained
|
|
52642
|
+
* deliveries don't diverge from inline per-request ones.
|
|
52643
|
+
*/
|
|
52644
|
+
webhookInvoker?: WebhookInvoker;
|
|
52575
52645
|
}
|
|
52576
52646
|
/**
|
|
52577
52647
|
* Build the same array of outbox destinations that authhero's per-request
|
|
@@ -52599,6 +52669,62 @@ export interface CreateDefaultDestinationsConfig {
|
|
|
52599
52669
|
* ```
|
|
52600
52670
|
*/
|
|
52601
52671
|
export declare function createDefaultDestinations(config: CreateDefaultDestinationsConfig): EventDestination[];
|
|
52672
|
+
export interface RunOutboxRelayConfig {
|
|
52673
|
+
/** Same `DataAdapters` passed to `init()`. Must include `outbox` to drain. */
|
|
52674
|
+
dataAdapter: DataAdapters;
|
|
52675
|
+
/**
|
|
52676
|
+
* Issuer URL used when minting per-tenant `auth-service` tokens (typically
|
|
52677
|
+
* your `env.ISSUER`). Webhook handlers that validate `iss` against this
|
|
52678
|
+
* URL will accept tokens from both the inline dispatcher and this cron
|
|
52679
|
+
* relay.
|
|
52680
|
+
*/
|
|
52681
|
+
issuer: string;
|
|
52682
|
+
/**
|
|
52683
|
+
* Optional webhook invoker — same shape as the one accepted by `init()`.
|
|
52684
|
+
* When provided, cron-drained `hook.*` events go through this invoker,
|
|
52685
|
+
* matching the inline per-request dispatch path exactly.
|
|
52686
|
+
*/
|
|
52687
|
+
webhookInvoker?: WebhookInvoker;
|
|
52688
|
+
/** Days to retain processed events before cleanup. Default 7. */
|
|
52689
|
+
retentionDays?: number;
|
|
52690
|
+
/** Forwarded to `drainOutbox`. */
|
|
52691
|
+
batchSize?: number;
|
|
52692
|
+
/** Forwarded to `drainOutbox`. */
|
|
52693
|
+
maxRetries?: number;
|
|
52694
|
+
/** Webhook HTTP timeout (ms), when the default invoker is used. */
|
|
52695
|
+
webhookTimeoutMs?: number;
|
|
52696
|
+
}
|
|
52697
|
+
/**
|
|
52698
|
+
* One-call outbox relay for cron / scheduled handlers.
|
|
52699
|
+
*
|
|
52700
|
+
* Internally:
|
|
52701
|
+
* 1. Skips gracefully when `dataAdapter.outbox` is undefined.
|
|
52702
|
+
* 2. Builds the same destination array as the inline dispatcher
|
|
52703
|
+
* (`LogsDestination`, `WebhookDestination`, `RegistrationFinalizerDestination`).
|
|
52704
|
+
* 3. Mints per-tenant service tokens via the same in-process path
|
|
52705
|
+
* (`createServiceTokenCore`) that the request-time webhookInvoker uses,
|
|
52706
|
+
* driven by the supplied dataAdapter.
|
|
52707
|
+
* 4. Runs `drainOutbox`, then `cleanupOutbox`.
|
|
52708
|
+
*
|
|
52709
|
+
* This is intended to be the entire body of a consumer's scheduled handler
|
|
52710
|
+
* for outbox maintenance — consumers should not need to call `drainOutbox` /
|
|
52711
|
+
* `cleanupOutbox` / `createDefaultDestinations` directly.
|
|
52712
|
+
*
|
|
52713
|
+
* @example
|
|
52714
|
+
* ```ts
|
|
52715
|
+
* export default {
|
|
52716
|
+
* async scheduled(_event, env) {
|
|
52717
|
+
* await runOutboxRelay({
|
|
52718
|
+
* dataAdapter,
|
|
52719
|
+
* issuer: env.ISSUER,
|
|
52720
|
+
* webhookInvoker, // same function passed to init()
|
|
52721
|
+
* retentionDays: 7,
|
|
52722
|
+
* });
|
|
52723
|
+
* },
|
|
52724
|
+
* };
|
|
52725
|
+
* ```
|
|
52726
|
+
*/
|
|
52727
|
+
export declare function runOutboxRelay(config: RunOutboxRelayConfig): Promise<void>;
|
|
52602
52728
|
export declare class LogsDestination implements EventDestination {
|
|
52603
52729
|
name: string;
|
|
52604
52730
|
private logs;
|
|
@@ -52617,39 +52743,6 @@ export declare class LogsDestination implements EventDestination {
|
|
|
52617
52743
|
log: LogInsert;
|
|
52618
52744
|
}[]): Promise<void>;
|
|
52619
52745
|
}
|
|
52620
|
-
export type GetServiceToken = (tenantId: string) => Promise<string>;
|
|
52621
|
-
export interface WebhookInvocation {
|
|
52622
|
-
eventId: string;
|
|
52623
|
-
tenantId: string;
|
|
52624
|
-
triggerId: string;
|
|
52625
|
-
payload: {
|
|
52626
|
-
tenant_id: string;
|
|
52627
|
-
trigger_id: string;
|
|
52628
|
-
user?: unknown;
|
|
52629
|
-
request?: unknown;
|
|
52630
|
-
};
|
|
52631
|
-
}
|
|
52632
|
-
/**
|
|
52633
|
-
* Delivers `hook.*` outbox events to HTTP webhooks configured for the matching
|
|
52634
|
-
* trigger_id. Each POST includes `Idempotency-Key: {event.id}` so downstream
|
|
52635
|
-
* webhook handlers can dedupe if the outbox retries.
|
|
52636
|
-
*
|
|
52637
|
-
* The destination is constructed per-request (via `outboxMiddleware`'s
|
|
52638
|
-
* `getDestinations(ctx)` factory) so it can close over a ctx-bound service
|
|
52639
|
-
* token generator.
|
|
52640
|
-
*/
|
|
52641
|
-
export declare class WebhookDestination implements EventDestination {
|
|
52642
|
-
name: string;
|
|
52643
|
-
private hooks;
|
|
52644
|
-
private getServiceToken;
|
|
52645
|
-
private timeoutMs;
|
|
52646
|
-
constructor(hooks: HooksAdapter, getServiceToken: GetServiceToken, options?: {
|
|
52647
|
-
timeoutMs?: number;
|
|
52648
|
-
});
|
|
52649
|
-
accepts(event: AuditEvent): boolean;
|
|
52650
|
-
transform(event: AuditEvent): WebhookInvocation;
|
|
52651
|
-
deliver(events: WebhookInvocation[]): Promise<void>;
|
|
52652
|
-
}
|
|
52653
52746
|
export interface FinalizationTask {
|
|
52654
52747
|
tenantId: string;
|
|
52655
52748
|
userId: string;
|