@k-msg/webhook 0.19.0 → 0.20.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.
@@ -0,0 +1,8 @@
1
+ import type { WebhookRuntimeSecurityOptions } from "./types";
2
+ export interface EndpointValidationOptions {
3
+ allowPrivateHosts: boolean;
4
+ allowHttpForLocalhost: boolean;
5
+ }
6
+ export declare const DEFAULT_ENDPOINT_VALIDATION_OPTIONS: EndpointValidationOptions;
7
+ export declare function resolveEndpointValidationOptions(security: WebhookRuntimeSecurityOptions | undefined): EndpointValidationOptions;
8
+ export declare function validateEndpointUrl(rawUrl: string, options?: EndpointValidationOptions): URL;
@@ -0,0 +1,2 @@
1
+ import type { WebhookEndpoint, WebhookEvent } from "../types/webhook.types";
2
+ export declare function endpointMatchesEvent(endpoint: WebhookEndpoint, event: WebhookEvent): boolean;
@@ -0,0 +1,16 @@
1
+ import type { WebhookDelivery, WebhookEndpoint } from "../types/webhook.types";
2
+ import type { WebhookDeliveryListOptions, WebhookDeliveryStore, WebhookEndpointStore, WebhookPersistence } from "./types";
3
+ export declare class InMemoryWebhookEndpointStore implements WebhookEndpointStore {
4
+ private readonly endpoints;
5
+ add(endpoint: WebhookEndpoint): Promise<void>;
6
+ update(endpointId: string, endpoint: WebhookEndpoint): Promise<void>;
7
+ remove(endpointId: string): Promise<void>;
8
+ get(endpointId: string): Promise<WebhookEndpoint | null>;
9
+ list(): Promise<WebhookEndpoint[]>;
10
+ }
11
+ export declare class InMemoryWebhookDeliveryStore implements WebhookDeliveryStore {
12
+ private readonly deliveries;
13
+ add(delivery: WebhookDelivery): Promise<void>;
14
+ list(options?: WebhookDeliveryListOptions): Promise<WebhookDelivery[]>;
15
+ }
16
+ export declare function createInMemoryWebhookPersistence(): WebhookPersistence;
@@ -0,0 +1,60 @@
1
+ import type { HttpClient } from "../services/webhook.dispatcher";
2
+ import type { WebhookConfig, WebhookDelivery, WebhookEndpoint, WebhookEvent, WebhookTestResult } from "../types/webhook.types";
3
+ export interface WebhookDeliveryListOptions {
4
+ endpointId?: string;
5
+ eventType?: WebhookEvent["type"];
6
+ status?: WebhookDelivery["status"];
7
+ limit?: number;
8
+ }
9
+ export interface WebhookEndpointStore {
10
+ add(endpoint: WebhookEndpoint): Promise<void>;
11
+ update(endpointId: string, endpoint: WebhookEndpoint): Promise<void>;
12
+ remove(endpointId: string): Promise<void>;
13
+ get(endpointId: string): Promise<WebhookEndpoint | null>;
14
+ list(): Promise<WebhookEndpoint[]>;
15
+ }
16
+ export interface WebhookDeliveryStore {
17
+ add(delivery: WebhookDelivery): Promise<void>;
18
+ list(options?: WebhookDeliveryListOptions): Promise<WebhookDelivery[]>;
19
+ }
20
+ export interface WebhookPersistence {
21
+ endpointStore: WebhookEndpointStore;
22
+ deliveryStore: WebhookDeliveryStore;
23
+ init?(): Promise<void>;
24
+ close?(): Promise<void>;
25
+ }
26
+ export interface WebhookRuntimeSecurityOptions {
27
+ allowPrivateHosts?: boolean;
28
+ allowHttpForLocalhost?: boolean;
29
+ }
30
+ export type WebhookEndpointInput = Omit<WebhookEndpoint, "id" | "createdAt" | "updatedAt" | "status"> & {
31
+ id?: string;
32
+ status?: WebhookEndpoint["status"];
33
+ };
34
+ export interface WebhookRuntimeConfig {
35
+ delivery: WebhookConfig;
36
+ persistence?: WebhookPersistence;
37
+ endpointStore?: WebhookEndpointStore;
38
+ deliveryStore?: WebhookDeliveryStore;
39
+ httpClient?: HttpClient;
40
+ security?: WebhookRuntimeSecurityOptions;
41
+ autoStart?: boolean;
42
+ }
43
+ export interface WebhookRuntimeTestPayload {
44
+ endpointId: string;
45
+ event?: Partial<WebhookEvent>;
46
+ }
47
+ export interface WebhookRuntime {
48
+ addEndpoint(input: WebhookEndpointInput): Promise<WebhookEndpoint>;
49
+ addEndpoints(inputs: readonly WebhookEndpointInput[]): Promise<WebhookEndpoint[]>;
50
+ updateEndpoint(endpointId: string, updates: Partial<WebhookEndpointInput>): Promise<WebhookEndpoint>;
51
+ removeEndpoint(endpointId: string): Promise<void>;
52
+ getEndpoint(endpointId: string): Promise<WebhookEndpoint | null>;
53
+ listEndpoints(): Promise<WebhookEndpoint[]>;
54
+ probeEndpoint(input: string | WebhookRuntimeTestPayload): Promise<WebhookTestResult>;
55
+ emit(event: WebhookEvent): Promise<void>;
56
+ emitSync(event: WebhookEvent): Promise<WebhookDelivery[]>;
57
+ flush(): Promise<void>;
58
+ listDeliveries(options?: WebhookDeliveryListOptions): Promise<WebhookDelivery[]>;
59
+ shutdown(): Promise<void>;
60
+ }
@@ -0,0 +1,41 @@
1
+ import { type HttpClient } from "../services/webhook.dispatcher";
2
+ import { type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookTestResult } from "../types/webhook.types";
3
+ import { resolveEndpointValidationOptions } from "./endpoint-validation";
4
+ import type { WebhookDeliveryListOptions, WebhookEndpointInput, WebhookRuntime, WebhookRuntimeConfig, WebhookRuntimeSecurityOptions, WebhookRuntimeTestPayload } from "./types";
5
+ export declare class WebhookRuntimeService implements WebhookRuntime {
6
+ private readonly config;
7
+ private readonly dispatcher;
8
+ private readonly endpointStore;
9
+ private readonly deliveryStore;
10
+ private readonly securityOptions;
11
+ private readonly persistence;
12
+ private readonly eventQueue;
13
+ private batchProcessor;
14
+ private initPromise;
15
+ private processing;
16
+ constructor(config: WebhookRuntimeConfig);
17
+ addEndpoint(input: WebhookEndpointInput): Promise<WebhookEndpoint>;
18
+ addEndpoints(inputs: readonly WebhookEndpointInput[]): Promise<WebhookEndpoint[]>;
19
+ updateEndpoint(endpointId: string, updates: Partial<WebhookEndpointInput>): Promise<WebhookEndpoint>;
20
+ removeEndpoint(endpointId: string): Promise<void>;
21
+ getEndpoint(endpointId: string): Promise<WebhookEndpoint | null>;
22
+ listEndpoints(): Promise<WebhookEndpoint[]>;
23
+ probeEndpoint(input: string | WebhookRuntimeTestPayload): Promise<WebhookTestResult>;
24
+ emit(event: WebhookEvent): Promise<void>;
25
+ emitSync(event: WebhookEvent): Promise<WebhookDelivery[]>;
26
+ flush(): Promise<void>;
27
+ listDeliveries(options?: WebhookDeliveryListOptions): Promise<WebhookDelivery[]>;
28
+ shutdown(): Promise<void>;
29
+ private resolvePersistence;
30
+ private ensureInitialized;
31
+ private validateEvent;
32
+ private processBatch;
33
+ private getMatchingEndpoints;
34
+ private createProbeEvent;
35
+ private generateEndpointId;
36
+ private startBatchProcessor;
37
+ }
38
+ export declare function probeEndpoint(runtime: WebhookRuntimeService, input: string | WebhookRuntimeTestPayload): Promise<WebhookTestResult>;
39
+ export declare function addEndpoints(runtime: WebhookRuntimeService, inputs: readonly WebhookEndpointInput[]): Promise<WebhookEndpoint[]>;
40
+ export declare function resolveWebhookSecurityOptions(security: WebhookRuntimeSecurityOptions | undefined): ReturnType<typeof resolveEndpointValidationOptions>;
41
+ export type { HttpClient };
@@ -3,12 +3,14 @@ export interface HttpClient {
3
3
  fetch(url: string, options: RequestInit): Promise<Response>;
4
4
  }
5
5
  export declare class DefaultHttpClient implements HttpClient {
6
- fetch(url: string, options: RequestInit): Promise<Response>;
6
+ fetch(url: string, _options: RequestInit): Promise<Response>;
7
7
  }
8
8
  export declare class MockHttpClient implements HttpClient {
9
9
  private responses;
10
+ private defaultResponse;
10
11
  setMockResponse(url: string, response: Response): void;
11
- fetch(url: string, options: RequestInit): Promise<Response>;
12
+ setDefaultResponse(response: Response): void;
13
+ fetch(url: string, _options: RequestInit): Promise<Response>;
12
14
  }
13
15
  export declare class WebhookDispatcher {
14
16
  private config;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Toolkit APIs (advanced building blocks)
3
+ */
4
+ export { BatchDispatcher } from "../dispatcher/batch.dispatcher";
5
+ export { LoadBalancer } from "../dispatcher/load-balancer";
6
+ export { QueueManager } from "../dispatcher/queue.manager";
7
+ export type { BatchConfig, CircuitBreakerState, DispatchConfig, DispatchJob, LoadBalancerConfig, QueueConfig, } from "../dispatcher/types";
8
+ export { DeliveryStore } from "../registry/delivery.store";
9
+ export { EndpointManager } from "../registry/endpoint.manager";
10
+ export { EventStore } from "../registry/event.store";
11
+ export type { DeliveryFilter, EndpointFilter, EventFilter, PaginationOptions, SearchResult, StorageConfig, } from "../registry/types";
12
+ export { RetryManager } from "../retry/retry.manager";
13
+ export { SecurityManager } from "../security/security.manager";
14
+ export { DefaultHttpClient, type HttpClient, MockHttpClient, WebhookDispatcher, } from "../services/webhook.dispatcher";
15
+ export { WebhookRegistry } from "../services/webhook.registry";
16
+ export type { FileStorageAdapter } from "../shared/file-storage";