@k-msg/webhook 0.1.0 → 0.1.2

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,219 @@
1
+ import { z } from "zod";
2
+ export interface WebhookConfig {
3
+ maxRetries: number;
4
+ retryDelayMs: number;
5
+ maxDelayMs?: number;
6
+ backoffMultiplier?: number;
7
+ jitter?: boolean;
8
+ timeoutMs: number;
9
+ enableSecurity: boolean;
10
+ secretKey?: string;
11
+ algorithm?: "sha256" | "sha1";
12
+ signatureHeader?: string;
13
+ signaturePrefix?: string;
14
+ enabledEvents: WebhookEventType[];
15
+ batchSize: number;
16
+ batchTimeoutMs: number;
17
+ }
18
+ export declare enum WebhookEventType {
19
+ MESSAGE_SENT = "message.sent",
20
+ MESSAGE_DELIVERED = "message.delivered",
21
+ MESSAGE_FAILED = "message.failed",
22
+ MESSAGE_CLICKED = "message.clicked",
23
+ MESSAGE_READ = "message.read",
24
+ TEMPLATE_CREATED = "template.created",
25
+ TEMPLATE_APPROVED = "template.approved",
26
+ TEMPLATE_REJECTED = "template.rejected",
27
+ TEMPLATE_UPDATED = "template.updated",
28
+ TEMPLATE_DELETED = "template.deleted",
29
+ CHANNEL_CREATED = "channel.created",
30
+ CHANNEL_VERIFIED = "channel.verified",
31
+ SENDER_NUMBER_ADDED = "sender_number.added",
32
+ SENDER_NUMBER_VERIFIED = "sender_number.verified",
33
+ QUOTA_WARNING = "system.quota_warning",
34
+ QUOTA_EXCEEDED = "system.quota_exceeded",
35
+ PROVIDER_ERROR = "system.provider_error",
36
+ SYSTEM_MAINTENANCE = "system.maintenance",
37
+ ANOMALY_DETECTED = "analytics.anomaly_detected",
38
+ THRESHOLD_EXCEEDED = "analytics.threshold_exceeded"
39
+ }
40
+ export interface WebhookEvent<T = any> {
41
+ id: string;
42
+ type: WebhookEventType;
43
+ timestamp: Date;
44
+ data: T;
45
+ metadata: {
46
+ providerId?: string;
47
+ channelId?: string;
48
+ templateId?: string;
49
+ messageId?: string;
50
+ userId?: string;
51
+ organizationId?: string;
52
+ correlationId?: string;
53
+ retryCount?: number;
54
+ };
55
+ version: string;
56
+ }
57
+ export interface WebhookEndpoint {
58
+ id: string;
59
+ url: string;
60
+ name?: string;
61
+ description?: string;
62
+ active: boolean;
63
+ events: WebhookEventType[];
64
+ headers?: Record<string, string>;
65
+ secret?: string;
66
+ retryConfig?: {
67
+ maxRetries: number;
68
+ retryDelayMs: number;
69
+ backoffMultiplier: number;
70
+ };
71
+ filters?: {
72
+ providerId?: string[];
73
+ channelId?: string[];
74
+ templateId?: string[];
75
+ };
76
+ createdAt: Date;
77
+ updatedAt: Date;
78
+ lastTriggeredAt?: Date;
79
+ status: "active" | "inactive" | "error" | "suspended";
80
+ }
81
+ export interface WebhookDelivery {
82
+ id: string;
83
+ endpointId: string;
84
+ eventId: string;
85
+ url: string;
86
+ httpMethod: "POST" | "PUT" | "PATCH";
87
+ headers: Record<string, string>;
88
+ payload: string;
89
+ attempts: WebhookAttempt[];
90
+ status: "pending" | "success" | "failed" | "exhausted";
91
+ createdAt: Date;
92
+ completedAt?: Date;
93
+ nextRetryAt?: Date;
94
+ }
95
+ export interface WebhookAttempt {
96
+ attemptNumber: number;
97
+ timestamp: Date;
98
+ httpStatus?: number;
99
+ responseBody?: string;
100
+ responseHeaders?: Record<string, string>;
101
+ error?: string;
102
+ latencyMs: number;
103
+ }
104
+ export interface WebhookSecurity {
105
+ algorithm: "sha256" | "sha1";
106
+ header: string;
107
+ prefix?: string;
108
+ }
109
+ export interface WebhookBatch {
110
+ id: string;
111
+ endpointId: string;
112
+ events: WebhookEvent[];
113
+ createdAt: Date;
114
+ scheduledAt: Date;
115
+ status: "pending" | "processing" | "completed" | "failed";
116
+ }
117
+ export interface WebhookStats {
118
+ endpointId: string;
119
+ timeRange: {
120
+ start: Date;
121
+ end: Date;
122
+ };
123
+ totalDeliveries: number;
124
+ successfulDeliveries: number;
125
+ failedDeliveries: number;
126
+ averageLatencyMs: number;
127
+ successRate: number;
128
+ eventBreakdown: Record<WebhookEventType, number>;
129
+ errorBreakdown: Record<string, number>;
130
+ }
131
+ export interface WebhookTestResult {
132
+ endpointId: string;
133
+ url: string;
134
+ success: boolean;
135
+ httpStatus?: number;
136
+ responseTime: number;
137
+ error?: string;
138
+ testedAt: Date;
139
+ }
140
+ export declare const WebhookEventSchema: z.ZodObject<{
141
+ id: z.ZodString;
142
+ type: z.ZodString;
143
+ timestamp: z.ZodDate;
144
+ data: z.ZodAny;
145
+ metadata: z.ZodObject<{
146
+ providerId: z.ZodOptional<z.ZodString>;
147
+ channelId: z.ZodOptional<z.ZodString>;
148
+ templateId: z.ZodOptional<z.ZodString>;
149
+ messageId: z.ZodOptional<z.ZodString>;
150
+ userId: z.ZodOptional<z.ZodString>;
151
+ organizationId: z.ZodOptional<z.ZodString>;
152
+ correlationId: z.ZodOptional<z.ZodString>;
153
+ retryCount: z.ZodOptional<z.ZodNumber>;
154
+ }, z.core.$strip>;
155
+ version: z.ZodString;
156
+ }, z.core.$strip>;
157
+ export declare const WebhookEndpointSchema: z.ZodObject<{
158
+ id: z.ZodString;
159
+ url: z.ZodString;
160
+ name: z.ZodOptional<z.ZodString>;
161
+ description: z.ZodOptional<z.ZodString>;
162
+ active: z.ZodBoolean;
163
+ events: z.ZodArray<z.ZodString>;
164
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
165
+ secret: z.ZodOptional<z.ZodString>;
166
+ retryConfig: z.ZodOptional<z.ZodObject<{
167
+ maxRetries: z.ZodNumber;
168
+ retryDelayMs: z.ZodNumber;
169
+ backoffMultiplier: z.ZodNumber;
170
+ }, z.core.$strip>>;
171
+ filters: z.ZodOptional<z.ZodObject<{
172
+ providerId: z.ZodOptional<z.ZodArray<z.ZodString>>;
173
+ channelId: z.ZodOptional<z.ZodArray<z.ZodString>>;
174
+ templateId: z.ZodOptional<z.ZodArray<z.ZodString>>;
175
+ }, z.core.$strip>>;
176
+ createdAt: z.ZodDate;
177
+ updatedAt: z.ZodDate;
178
+ lastTriggeredAt: z.ZodOptional<z.ZodDate>;
179
+ status: z.ZodEnum<{
180
+ active: "active";
181
+ inactive: "inactive";
182
+ error: "error";
183
+ suspended: "suspended";
184
+ }>;
185
+ }, z.core.$strip>;
186
+ export declare const WebhookDeliverySchema: z.ZodObject<{
187
+ id: z.ZodString;
188
+ endpointId: z.ZodString;
189
+ eventId: z.ZodString;
190
+ url: z.ZodString;
191
+ httpMethod: z.ZodEnum<{
192
+ POST: "POST";
193
+ PUT: "PUT";
194
+ PATCH: "PATCH";
195
+ }>;
196
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
197
+ payload: z.ZodString;
198
+ attempts: z.ZodArray<z.ZodObject<{
199
+ attemptNumber: z.ZodNumber;
200
+ timestamp: z.ZodDate;
201
+ httpStatus: z.ZodOptional<z.ZodNumber>;
202
+ responseBody: z.ZodOptional<z.ZodString>;
203
+ responseHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
204
+ error: z.ZodOptional<z.ZodString>;
205
+ latencyMs: z.ZodNumber;
206
+ }, z.core.$strip>>;
207
+ status: z.ZodEnum<{
208
+ pending: "pending";
209
+ success: "success";
210
+ failed: "failed";
211
+ exhausted: "exhausted";
212
+ }>;
213
+ createdAt: z.ZodDate;
214
+ completedAt: z.ZodOptional<z.ZodDate>;
215
+ nextRetryAt: z.ZodOptional<z.ZodDate>;
216
+ }, z.core.$strip>;
217
+ export type WebhookEventData = z.infer<typeof WebhookEventSchema>;
218
+ export type WebhookEndpointData = z.infer<typeof WebhookEndpointSchema>;
219
+ export type WebhookDeliveryData = z.infer<typeof WebhookDeliverySchema>;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@k-msg/webhook",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
+ "packageManager": "bun@1.3.8",
4
5
  "description": "Webhook system for real-time message event notifications",
5
6
  "type": "module",
6
7
  "main": "dist/index.js",
@@ -17,20 +18,24 @@
17
18
  "access": "public"
18
19
  },
19
20
  "scripts": {
20
- "build": "tsup",
21
+ "build": "bun run build:esm && bun run build:cjs && bun run build:types",
22
+ "build:esm": "bun build ./src/index.ts --outdir ./dist --format esm --minify --sourcemap --entry-naming '[name].mjs' --external 'bun:test'",
23
+ "build:cjs": "bun build ./src/index.ts --outdir ./dist --format cjs --minify --sourcemap --entry-naming '[name].js' --external 'bun:test'",
24
+ "build:types": "tsc",
21
25
  "dev": "tsc --watch",
22
26
  "test": "bun test",
23
- "clean": "rm -rf dist"
27
+ "clean": "rm -rf dist",
28
+ "pack": "bun pm pack",
29
+ "publish": "bun publish --access public"
24
30
  },
25
31
  "dependencies": {
26
- "zod": "catalog:",
27
- "@k-msg/messaging": "workspace:*"
32
+ "zod": "^4.0.14",
33
+ "@k-msg/messaging": "0.1.1"
28
34
  },
29
35
  "devDependencies": {
30
- "typescript": "catalog:",
31
- "@types/bun": "catalog:",
32
- "@types/node": "catalog:",
33
- "tsup": "^8.5.0"
36
+ "typescript": "^5.7.2",
37
+ "@types/bun": "latest",
38
+ "@types/node": "^22.0.0"
34
39
  },
35
40
  "keywords": [
36
41
  "webhook",
@@ -46,12 +51,12 @@
46
51
  ],
47
52
  "repository": {
48
53
  "type": "git",
49
- "url": "git+https://github.com/k-otp/k-message.git"
54
+ "url": "git+https://github.com/k-otp/k-msg.git"
50
55
  },
51
- "homepage": "https://github.com/k-otp/k-message",
56
+ "homepage": "https://github.com/k-otp/k-msg",
52
57
  "bugs": {
53
- "url": "https://github.com/k-otp/k-message/issues"
58
+ "url": "https://github.com/k-otp/k-msg/issues"
54
59
  },
55
60
  "author": "imjlk",
56
61
  "license": "MIT"
57
- }
62
+ }