@agentuity/webhook 1.0.54

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/AGENTS.md ADDED
@@ -0,0 +1,39 @@
1
+ # Agent Guidelines for @agentuity/webhook
2
+
3
+ ## Package Overview
4
+
5
+ Standalone package for the Agentuity Webhook service. Provides a simple, ergonomic client for creating and managing webhook endpoints.
6
+
7
+ ## Commands
8
+
9
+ - **Build**: `bun run build`
10
+ - **Typecheck**: `bun run typecheck`
11
+ - **Clean**: `rm -rf dist`
12
+
13
+ ## Architecture
14
+
15
+ - **Runtime**: Node.js and Bun compatible
16
+ - **Exports**: WebhookClient and all types from @agentuity/core/webhook
17
+ - **Dependencies**: @agentuity/core, @agentuity/server, zod
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import { WebhookClient } from '@agentuity/webhook';
23
+
24
+ const client = new WebhookClient();
25
+
26
+ // Create a webhook
27
+ const { webhook } = await client.create({ name: 'GitHub Events' });
28
+
29
+ // Add a destination
30
+ await client.createDestination(webhook.id, {
31
+ type: 'url',
32
+ config: { url: 'https://example.com/webhook' }
33
+ });
34
+ ```
35
+
36
+ ## Publishing
37
+
38
+ 1. Run `bun run build`
39
+ 2. Must publish **after** @agentuity/core
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @agentuity/webhook
2
+
3
+ A standalone package for the Agentuity Webhook service.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @agentuity/webhook
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { WebhookClient } from '@agentuity/webhook';
15
+
16
+ const client = new WebhookClient();
17
+
18
+ // Create a webhook
19
+ const { webhook } = await client.create({
20
+ name: 'GitHub Events',
21
+ description: 'Receives GitHub webhook events'
22
+ });
23
+
24
+ console.log('Ingest URL:', webhook.url);
25
+
26
+ // Add a destination
27
+ await client.createDestination(webhook.id, {
28
+ type: 'url',
29
+ config: { url: 'https://example.com/webhook' }
30
+ });
31
+
32
+ // List receipts
33
+ const { receipts } = await client.listReceipts(webhook.id);
34
+ for (const receipt of receipts) {
35
+ console.log(`Received: ${receipt.id} at ${receipt.date}`);
36
+ }
37
+
38
+ // Check delivery status
39
+ const { deliveries } = await client.listDeliveries(webhook.id);
40
+ for (const d of deliveries) {
41
+ console.log(`${d.status} → ${d.webhook_destination_id}`);
42
+ }
43
+ ```
44
+
45
+ ## Configuration
46
+
47
+ ```typescript
48
+ const client = new WebhookClient({
49
+ apiKey: 'your-api-key',
50
+ url: 'https://api.agentuity.com',
51
+ });
52
+ ```
53
+
54
+ ### Environment Variables
55
+
56
+ | Variable | Description | Default |
57
+ |----------|-------------|---------|
58
+ | `AGENTUITY_SDK_KEY` | API key for authentication | Required |
59
+ | `AGENTUITY_REGION` | Region for API endpoints | `usc` |
60
+ | `AGENTUITY_WEBHOOK_URL` | Override Webhook API URL | Auto-detected |
61
+
62
+ ## License
63
+
64
+ Apache-2.0
@@ -0,0 +1,59 @@
1
+ export { WebhookService, type Webhook, type WebhookDestination, type WebhookDelivery, type WebhookReceipt, type CreateWebhookRequest, type CreateWebhookDestinationRequest, type UpdateWebhookRequest, type WebhookApiOptions, type WebhookDeliveryStatus, type WebhookDestinationType, type WebhookAnalyticsGranularity, type WebhookAnalyticsOptions, type WebhookAnalyticsSummary, type WebhookOrgAnalytics, type WebhookTimePeriod, type WebhookTimeSeriesData, type WebhookTimeSeriesPoint, type CreateWebhookParams, type UpdateWebhookParams, type CreateWebhookDestinationParams, type WebhookListResult, type WebhookGetResult, type WebhookCreateResult, type UpdateWebhookResult, type CreateDestinationResult, type ListDestinationsResult, type WebhookReceiptListResult, type WebhookDeliveryListResult, WebhookSchema, WebhookDestinationSchema, WebhookDeliverySchema, WebhookReceiptSchema, CreateWebhookRequestSchema, CreateWebhookDestinationRequestSchema, UpdateWebhookRequestSchema, WebhookApiOptionsSchema, WebhookDeliveryStatusSchema, WebhookDestinationTypeSchema, WebhookAnalyticsGranularitySchema, WebhookAnalyticsOptionsSchema, WebhookAnalyticsSummarySchema, WebhookOrgAnalyticsSchema, WebhookTimePeriodSchema, WebhookTimeSeriesDataSchema, WebhookTimeSeriesPointSchema, WebhookNotFoundError, WebhookDestinationNotFoundError, WebhookDeliveryNotFoundError, WebhookReceiptNotFoundError, WebhookError, } from '@agentuity/core/webhook';
2
+ import { type CreateWebhookParams, type UpdateWebhookParams, type CreateWebhookDestinationParams, type WebhookCreateResult, type WebhookListResult, type WebhookGetResult, type UpdateWebhookResult, type CreateDestinationResult, type ListDestinationsResult, type WebhookReceiptListResult, type WebhookDeliveryListResult, type WebhookOrgAnalytics, type WebhookReceipt } from '@agentuity/core/webhook';
3
+ import { type Logger } from '@agentuity/server';
4
+ import { z } from 'zod';
5
+ export declare const WebhookClientOptionsSchema: z.ZodObject<{
6
+ apiKey: z.ZodOptional<z.ZodString>;
7
+ url: z.ZodOptional<z.ZodString>;
8
+ orgId: z.ZodOptional<z.ZodString>;
9
+ logger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
10
+ }, z.core.$strip>;
11
+ export type WebhookClientOptions = z.infer<typeof WebhookClientOptionsSchema>;
12
+ export declare class WebhookClient {
13
+ #private;
14
+ constructor(options?: WebhookClientOptions);
15
+ create(params: CreateWebhookParams): Promise<WebhookCreateResult>;
16
+ list(params?: {
17
+ limit?: number;
18
+ offset?: number;
19
+ }): Promise<WebhookListResult>;
20
+ get(webhookId: string): Promise<WebhookGetResult>;
21
+ update(webhookId: string, params: UpdateWebhookParams): Promise<UpdateWebhookResult>;
22
+ delete(webhookId: string): Promise<void>;
23
+ createDestination(webhookId: string, params: CreateWebhookDestinationParams): Promise<CreateDestinationResult>;
24
+ listDestinations(webhookId: string): Promise<ListDestinationsResult>;
25
+ deleteDestination(webhookId: string, destinationId: string): Promise<void>;
26
+ listReceipts(webhookId: string, params?: {
27
+ limit?: number;
28
+ offset?: number;
29
+ }): Promise<WebhookReceiptListResult>;
30
+ getReceipt(webhookId: string, receiptId: string): Promise<WebhookReceipt>;
31
+ listDeliveries(webhookId: string, params?: {
32
+ limit?: number;
33
+ offset?: number;
34
+ }): Promise<WebhookDeliveryListResult>;
35
+ retryDelivery(webhookId: string, deliveryId: string): Promise<void>;
36
+ getOrgAnalytics(options?: {
37
+ start?: string;
38
+ end?: string;
39
+ granularity?: string;
40
+ }): Promise<WebhookOrgAnalytics>;
41
+ getOrgTimeSeries(options?: {
42
+ start?: string;
43
+ end?: string;
44
+ granularity?: string;
45
+ }): Promise<{
46
+ period: {
47
+ start: string;
48
+ end: string;
49
+ granularity?: string;
50
+ };
51
+ series: Array<{
52
+ timestamp: string;
53
+ received: number;
54
+ delivered: number;
55
+ failed: number;
56
+ }>;
57
+ }>;
58
+ }
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EACd,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,+BAA+B,EACpC,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,aAAa,EACb,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B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AAC;QACX,MAAM,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,WAAW,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC7D,MAAM,EAAE,KAAK,CAAC;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC1F,CAAC;CAGF"}
package/dist/index.js ADDED
@@ -0,0 +1,76 @@
1
+ export { WebhookService, WebhookSchema, WebhookDestinationSchema, WebhookDeliverySchema, WebhookReceiptSchema, CreateWebhookRequestSchema, CreateWebhookDestinationRequestSchema, UpdateWebhookRequestSchema, WebhookApiOptionsSchema, WebhookDeliveryStatusSchema, WebhookDestinationTypeSchema, WebhookAnalyticsGranularitySchema, WebhookAnalyticsOptionsSchema, WebhookAnalyticsSummarySchema, WebhookOrgAnalyticsSchema, WebhookTimePeriodSchema, WebhookTimeSeriesDataSchema, WebhookTimeSeriesPointSchema, WebhookNotFoundError, WebhookDestinationNotFoundError, WebhookDeliveryNotFoundError, WebhookReceiptNotFoundError, WebhookError, } from '@agentuity/core/webhook';
2
+ import { WebhookService, } from '@agentuity/core/webhook';
3
+ import { createServerFetchAdapter, buildClientHeaders } from '@agentuity/server';
4
+ import { createMinimalLogger } from '@agentuity/core';
5
+ import { getEnv } from '@agentuity/core';
6
+ import { getServiceUrls } from '@agentuity/core/config';
7
+ import { z } from 'zod';
8
+ const isLogger = (val) => typeof val === 'object' &&
9
+ val !== null &&
10
+ ['info', 'warn', 'error', 'debug', 'trace'].every((m) => typeof val[m] === 'function');
11
+ export const WebhookClientOptionsSchema = z.object({
12
+ apiKey: z.string().optional().describe('API key for authentication'),
13
+ url: z.string().optional().describe('Base URL for the Webhook API'),
14
+ orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
15
+ logger: z.custom(isLogger).optional().describe('Custom logger instance'),
16
+ });
17
+ export class WebhookClient {
18
+ #service;
19
+ constructor(options = {}) {
20
+ const validatedOptions = WebhookClientOptionsSchema.parse(options);
21
+ const apiKey = validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
22
+ const region = getEnv('AGENTUITY_REGION') ?? 'usc';
23
+ const serviceUrls = getServiceUrls(region);
24
+ const url = validatedOptions.url || getEnv('AGENTUITY_WEBHOOK_URL') || serviceUrls.catalyst;
25
+ const logger = validatedOptions.logger ?? createMinimalLogger();
26
+ const headers = buildClientHeaders({
27
+ apiKey,
28
+ orgId: validatedOptions.orgId,
29
+ });
30
+ const adapter = createServerFetchAdapter({ headers }, logger);
31
+ this.#service = new WebhookService(url, adapter);
32
+ }
33
+ async create(params) {
34
+ return this.#service.create(params);
35
+ }
36
+ async list(params) {
37
+ return this.#service.list(params);
38
+ }
39
+ async get(webhookId) {
40
+ return this.#service.get(webhookId);
41
+ }
42
+ async update(webhookId, params) {
43
+ return this.#service.update(webhookId, params);
44
+ }
45
+ async delete(webhookId) {
46
+ return this.#service.delete(webhookId);
47
+ }
48
+ async createDestination(webhookId, params) {
49
+ return this.#service.createDestination(webhookId, params);
50
+ }
51
+ async listDestinations(webhookId) {
52
+ return this.#service.listDestinations(webhookId);
53
+ }
54
+ async deleteDestination(webhookId, destinationId) {
55
+ return this.#service.deleteDestination(webhookId, destinationId);
56
+ }
57
+ async listReceipts(webhookId, params) {
58
+ return this.#service.listReceipts(webhookId, params);
59
+ }
60
+ async getReceipt(webhookId, receiptId) {
61
+ return this.#service.getReceipt(webhookId, receiptId);
62
+ }
63
+ async listDeliveries(webhookId, params) {
64
+ return this.#service.listDeliveries(webhookId, params);
65
+ }
66
+ async retryDelivery(webhookId, deliveryId) {
67
+ return this.#service.retryDelivery(webhookId, deliveryId);
68
+ }
69
+ async getOrgAnalytics(options) {
70
+ return this.#service.getOrgAnalytics(options);
71
+ }
72
+ async getOrgTimeSeries(options) {
73
+ return this.#service.getOrgTimeSeries(options);
74
+ }
75
+ }
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EA6Bd,aAAa,EACb,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,qCAAqC,EACrC,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC3B,4BAA4B,EAC5B,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,+BAA+B,EAC/B,4BAA4B,EAC5B,2BAA2B,EAC3B,YAAY,GACZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACN,cAAc,GAcd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAe,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAiB,EAAE,CAChD,OAAO,GAAG,KAAK,QAAQ;IACvB,GAAG,KAAK,IAAI;IACZ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,CAChD,CAAC,CAAC,EAAE,EAAE,CAAC,OAAQ,GAA+B,CAAC,CAAC,CAAC,KAAK,UAAU,CAChE,CAAC;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CA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,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,cAAc,CACnB,SAAiB,EACjB,MAA4C;QAE5C,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,UAAkB;QACxD,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAIrB;QACA,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAItB;QAIA,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;CACD"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@agentuity/webhook",
3
+ "version": "1.0.54",
4
+ "license": "Apache-2.0",
5
+ "author": "Agentuity employees and contributors",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "AGENTS.md",
11
+ "README.md",
12
+ "src",
13
+ "dist"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
23
+ "build": "bunx tsc --build --force",
24
+ "typecheck": "bunx tsc --noEmit",
25
+ "prepublishOnly": "bun run clean && bun run build"
26
+ },
27
+ "dependencies": {
28
+ "@agentuity/core": "1.0.54",
29
+ "@agentuity/server": "1.0.54",
30
+ "zod": "^4.3.5"
31
+ },
32
+ "devDependencies": {
33
+ "@types/bun": "latest",
34
+ "@types/node": "^22.0.0",
35
+ "bun-types": "latest",
36
+ "typescript": "^5.9.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "sideEffects": false
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,190 @@
1
+ export {
2
+ WebhookService,
3
+ type Webhook,
4
+ type WebhookDestination,
5
+ type WebhookDelivery,
6
+ type WebhookReceipt,
7
+ type CreateWebhookRequest,
8
+ type CreateWebhookDestinationRequest,
9
+ type UpdateWebhookRequest,
10
+ type WebhookApiOptions,
11
+ type WebhookDeliveryStatus,
12
+ type WebhookDestinationType,
13
+ type WebhookAnalyticsGranularity,
14
+ type WebhookAnalyticsOptions,
15
+ type WebhookAnalyticsSummary,
16
+ type WebhookOrgAnalytics,
17
+ type WebhookTimePeriod,
18
+ type WebhookTimeSeriesData,
19
+ type WebhookTimeSeriesPoint,
20
+ type CreateWebhookParams,
21
+ type UpdateWebhookParams,
22
+ type CreateWebhookDestinationParams,
23
+ type WebhookListResult,
24
+ type WebhookGetResult,
25
+ type WebhookCreateResult,
26
+ type UpdateWebhookResult,
27
+ type CreateDestinationResult,
28
+ type ListDestinationsResult,
29
+ type WebhookReceiptListResult,
30
+ type WebhookDeliveryListResult,
31
+ WebhookSchema,
32
+ WebhookDestinationSchema,
33
+ WebhookDeliverySchema,
34
+ WebhookReceiptSchema,
35
+ CreateWebhookRequestSchema,
36
+ CreateWebhookDestinationRequestSchema,
37
+ UpdateWebhookRequestSchema,
38
+ WebhookApiOptionsSchema,
39
+ WebhookDeliveryStatusSchema,
40
+ WebhookDestinationTypeSchema,
41
+ WebhookAnalyticsGranularitySchema,
42
+ WebhookAnalyticsOptionsSchema,
43
+ WebhookAnalyticsSummarySchema,
44
+ WebhookOrgAnalyticsSchema,
45
+ WebhookTimePeriodSchema,
46
+ WebhookTimeSeriesDataSchema,
47
+ WebhookTimeSeriesPointSchema,
48
+ WebhookNotFoundError,
49
+ WebhookDestinationNotFoundError,
50
+ WebhookDeliveryNotFoundError,
51
+ WebhookReceiptNotFoundError,
52
+ WebhookError,
53
+ } from '@agentuity/core/webhook';
54
+
55
+ import {
56
+ WebhookService,
57
+ type CreateWebhookParams,
58
+ type UpdateWebhookParams,
59
+ type CreateWebhookDestinationParams,
60
+ type WebhookCreateResult,
61
+ type WebhookListResult,
62
+ type WebhookGetResult,
63
+ type UpdateWebhookResult,
64
+ type CreateDestinationResult,
65
+ type ListDestinationsResult,
66
+ type WebhookReceiptListResult,
67
+ type WebhookDeliveryListResult,
68
+ type WebhookOrgAnalytics,
69
+ type WebhookReceipt,
70
+ } from '@agentuity/core/webhook';
71
+ import { createServerFetchAdapter, buildClientHeaders, type Logger } from '@agentuity/server';
72
+ import { createMinimalLogger } from '@agentuity/core';
73
+ import { getEnv } from '@agentuity/core';
74
+ import { getServiceUrls } from '@agentuity/core/config';
75
+ import { z } from 'zod';
76
+
77
+ const isLogger = (val: unknown): val is Logger =>
78
+ typeof val === 'object' &&
79
+ val !== null &&
80
+ ['info', 'warn', 'error', 'debug', 'trace'].every(
81
+ (m) => typeof (val as Record<string, unknown>)[m] === 'function'
82
+ );
83
+
84
+ export const WebhookClientOptionsSchema = z.object({
85
+ apiKey: z.string().optional().describe('API key for authentication'),
86
+ url: z.string().optional().describe('Base URL for the Webhook API'),
87
+ orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
88
+ logger: z.custom<Logger>(isLogger).optional().describe('Custom logger instance'),
89
+ });
90
+ export type WebhookClientOptions = z.infer<typeof WebhookClientOptionsSchema>;
91
+
92
+ export class WebhookClient {
93
+ readonly #service: WebhookService;
94
+
95
+ constructor(options: WebhookClientOptions = {}) {
96
+ const validatedOptions = WebhookClientOptionsSchema.parse(options);
97
+ const apiKey =
98
+ validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
99
+ const region = getEnv('AGENTUITY_REGION') ?? 'usc';
100
+ const serviceUrls = getServiceUrls(region);
101
+
102
+ const url = validatedOptions.url || getEnv('AGENTUITY_WEBHOOK_URL') || serviceUrls.catalyst;
103
+
104
+ const logger = validatedOptions.logger ?? createMinimalLogger();
105
+
106
+ const headers = buildClientHeaders({
107
+ apiKey,
108
+ orgId: validatedOptions.orgId,
109
+ });
110
+
111
+ const adapter = createServerFetchAdapter({ headers }, logger);
112
+ this.#service = new WebhookService(url, adapter);
113
+ }
114
+
115
+ async create(params: CreateWebhookParams): Promise<WebhookCreateResult> {
116
+ return this.#service.create(params);
117
+ }
118
+
119
+ async list(params?: { limit?: number; offset?: number }): Promise<WebhookListResult> {
120
+ return this.#service.list(params);
121
+ }
122
+
123
+ async get(webhookId: string): Promise<WebhookGetResult> {
124
+ return this.#service.get(webhookId);
125
+ }
126
+
127
+ async update(webhookId: string, params: UpdateWebhookParams): Promise<UpdateWebhookResult> {
128
+ return this.#service.update(webhookId, params);
129
+ }
130
+
131
+ async delete(webhookId: string): Promise<void> {
132
+ return this.#service.delete(webhookId);
133
+ }
134
+
135
+ async createDestination(
136
+ webhookId: string,
137
+ params: CreateWebhookDestinationParams
138
+ ): Promise<CreateDestinationResult> {
139
+ return this.#service.createDestination(webhookId, params);
140
+ }
141
+
142
+ async listDestinations(webhookId: string): Promise<ListDestinationsResult> {
143
+ return this.#service.listDestinations(webhookId);
144
+ }
145
+
146
+ async deleteDestination(webhookId: string, destinationId: string): Promise<void> {
147
+ return this.#service.deleteDestination(webhookId, destinationId);
148
+ }
149
+
150
+ async listReceipts(
151
+ webhookId: string,
152
+ params?: { limit?: number; offset?: number }
153
+ ): Promise<WebhookReceiptListResult> {
154
+ return this.#service.listReceipts(webhookId, params);
155
+ }
156
+
157
+ async getReceipt(webhookId: string, receiptId: string): Promise<WebhookReceipt> {
158
+ return this.#service.getReceipt(webhookId, receiptId);
159
+ }
160
+
161
+ async listDeliveries(
162
+ webhookId: string,
163
+ params?: { limit?: number; offset?: number }
164
+ ): Promise<WebhookDeliveryListResult> {
165
+ return this.#service.listDeliveries(webhookId, params);
166
+ }
167
+
168
+ async retryDelivery(webhookId: string, deliveryId: string): Promise<void> {
169
+ return this.#service.retryDelivery(webhookId, deliveryId);
170
+ }
171
+
172
+ async getOrgAnalytics(options?: {
173
+ start?: string;
174
+ end?: string;
175
+ granularity?: string;
176
+ }): Promise<WebhookOrgAnalytics> {
177
+ return this.#service.getOrgAnalytics(options);
178
+ }
179
+
180
+ async getOrgTimeSeries(options?: {
181
+ start?: string;
182
+ end?: string;
183
+ granularity?: string;
184
+ }): Promise<{
185
+ period: { start: string; end: string; granularity?: string };
186
+ series: Array<{ timestamp: string; received: number; delivered: number; failed: number }>;
187
+ }> {
188
+ return this.#service.getOrgTimeSeries(options);
189
+ }
190
+ }