@furlow/pipes 0.1.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,152 @@
1
+ /**
2
+ * Pipe types
3
+ */
4
+ interface PipeResponse<T = unknown> {
5
+ success: boolean;
6
+ data?: T;
7
+ error?: string;
8
+ status?: number;
9
+ headers?: Record<string, string>;
10
+ }
11
+ interface Pipe {
12
+ name: string;
13
+ type: string;
14
+ connect?(): Promise<void>;
15
+ disconnect?(): Promise<void>;
16
+ isConnected(): boolean;
17
+ }
18
+ /** HTTP authentication type */
19
+ type HttpAuthType = 'none' | 'header' | 'bearer' | 'basic';
20
+ /** HTTP authentication config */
21
+ interface HttpAuthConfig {
22
+ type: HttpAuthType;
23
+ token?: string;
24
+ username?: string;
25
+ password?: string;
26
+ header_name?: string;
27
+ }
28
+ /** HTTP rate limit config */
29
+ interface HttpRateLimitConfig {
30
+ requests: number;
31
+ per: string;
32
+ retry_after?: boolean;
33
+ }
34
+ /** HTTP pipe configuration */
35
+ interface HttpPipeConfig {
36
+ type: 'http';
37
+ base_url: string;
38
+ auth?: HttpAuthConfig;
39
+ headers?: Record<string, string>;
40
+ rate_limit?: HttpRateLimitConfig;
41
+ timeout?: string;
42
+ retry?: {
43
+ attempts?: number;
44
+ delay?: string;
45
+ };
46
+ }
47
+ /** Webhook verification configuration */
48
+ interface WebhookVerification {
49
+ type: 'hmac' | 'signature' | 'token';
50
+ secret?: string;
51
+ header?: string;
52
+ algorithm?: 'sha1' | 'sha256' | 'sha512';
53
+ }
54
+ /** Webhook pipe configuration */
55
+ interface WebhookPipeConfig {
56
+ type: 'webhook';
57
+ path: string;
58
+ method?: 'POST' | 'PUT' | 'PATCH';
59
+ verification?: WebhookVerification;
60
+ handlers?: {
61
+ event?: string;
62
+ when?: string;
63
+ actions: unknown[];
64
+ }[];
65
+ }
66
+ /** WebSocket pipe configuration */
67
+ interface WebSocketPipeConfig {
68
+ type: 'websocket';
69
+ url: string;
70
+ headers?: Record<string, string>;
71
+ reconnect?: {
72
+ enabled?: boolean;
73
+ delay?: string;
74
+ max_attempts?: number;
75
+ };
76
+ heartbeat?: {
77
+ interval?: string;
78
+ message?: string;
79
+ };
80
+ handlers?: {
81
+ event: string;
82
+ when?: string;
83
+ actions: unknown[];
84
+ }[];
85
+ }
86
+ /** MQTT authentication config */
87
+ interface MqttAuthConfig {
88
+ username?: string;
89
+ password?: string;
90
+ clientId?: string;
91
+ }
92
+ /** MQTT QoS level */
93
+ type MqttQoS = 0 | 1 | 2;
94
+ /** MQTT pipe configuration */
95
+ interface MqttPipeConfig {
96
+ type: 'mqtt';
97
+ broker: string;
98
+ port?: number;
99
+ protocol?: 'mqtt' | 'mqtts' | 'ws' | 'wss';
100
+ auth?: MqttAuthConfig;
101
+ keepalive?: number;
102
+ clean?: boolean;
103
+ reconnect?: {
104
+ enabled?: boolean;
105
+ delay?: string;
106
+ max_attempts?: number;
107
+ };
108
+ will?: {
109
+ topic: string;
110
+ payload: string;
111
+ qos?: MqttQoS;
112
+ retain?: boolean;
113
+ };
114
+ handlers?: {
115
+ topic: string;
116
+ qos?: MqttQoS;
117
+ when?: string;
118
+ actions: unknown[];
119
+ }[];
120
+ }
121
+ /** TCP pipe configuration */
122
+ interface TcpPipeConfig {
123
+ type: 'tcp';
124
+ host: string;
125
+ port: number;
126
+ reconnect?: {
127
+ enabled?: boolean;
128
+ delay?: string;
129
+ max_attempts?: number;
130
+ };
131
+ encoding?: BufferEncoding;
132
+ handlers?: {
133
+ event: string;
134
+ when?: string;
135
+ actions: unknown[];
136
+ }[];
137
+ }
138
+ /** UDP pipe configuration */
139
+ interface UdpPipeConfig {
140
+ type: 'udp';
141
+ host?: string;
142
+ port: number;
143
+ multicast?: string;
144
+ broadcast?: boolean;
145
+ handlers?: {
146
+ event: string;
147
+ when?: string;
148
+ actions: unknown[];
149
+ }[];
150
+ }
151
+
152
+ export type { HttpAuthConfig as H, MqttAuthConfig as M, Pipe as P, TcpPipeConfig as T, UdpPipeConfig as U, WebSocketPipeConfig as W, HttpAuthType as a, HttpPipeConfig as b, HttpRateLimitConfig as c, MqttPipeConfig as d, MqttQoS as e, PipeResponse as f, WebhookPipeConfig as g, WebhookVerification as h };
@@ -0,0 +1,70 @@
1
+ import { P as Pipe, g as WebhookPipeConfig, f as PipeResponse } from '../types-BW9r2ksN.js';
2
+
3
+ /**
4
+ * Webhook pipe for incoming and outgoing webhooks
5
+ */
6
+
7
+ interface WebhookPipeOptions {
8
+ name: string;
9
+ config: WebhookPipeConfig;
10
+ }
11
+ type WebhookHandler = (body: unknown, headers: Record<string, string>) => void | Promise<void>;
12
+ declare class WebhookPipe implements Pipe {
13
+ readonly name: string;
14
+ readonly type = "webhook";
15
+ private config;
16
+ private handlers;
17
+ constructor(options: WebhookPipeOptions);
18
+ isConnected(): boolean;
19
+ /**
20
+ * Get the webhook path
21
+ */
22
+ getPath(): string;
23
+ /**
24
+ * Get the expected method
25
+ */
26
+ getMethod(): string;
27
+ /**
28
+ * Register a handler for incoming webhooks
29
+ */
30
+ onWebhook(handler: WebhookHandler): () => void;
31
+ /**
32
+ * Handle an incoming webhook request
33
+ */
34
+ handleRequest(body: unknown, headers: Record<string, string>): Promise<PipeResponse>;
35
+ /**
36
+ * Verify webhook signature
37
+ */
38
+ private verifySignature;
39
+ /**
40
+ * Timing-safe string comparison
41
+ */
42
+ private timingSafeEqual;
43
+ }
44
+ /**
45
+ * Outgoing webhook sender
46
+ */
47
+ declare class WebhookSender {
48
+ /**
49
+ * Send a Discord webhook
50
+ */
51
+ static sendDiscordWebhook(url: string, options: {
52
+ content?: string;
53
+ username?: string;
54
+ avatar_url?: string;
55
+ embeds?: Record<string, unknown>[];
56
+ }): Promise<PipeResponse>;
57
+ /**
58
+ * Send a generic webhook
59
+ */
60
+ static send(url: string, body: unknown, options?: {
61
+ headers?: Record<string, string>;
62
+ method?: string;
63
+ }): Promise<PipeResponse>;
64
+ }
65
+ /**
66
+ * Create a webhook pipe
67
+ */
68
+ declare function createWebhookPipe(options: WebhookPipeOptions): WebhookPipe;
69
+
70
+ export { type WebhookHandler, WebhookPipe, type WebhookPipeOptions, WebhookSender, createWebhookPipe };
@@ -0,0 +1,169 @@
1
+ // src/webhook/index.ts
2
+ import { createHmac } from "crypto";
3
+ var WebhookPipe = class {
4
+ name;
5
+ type = "webhook";
6
+ config;
7
+ handlers = [];
8
+ constructor(options) {
9
+ this.name = options.name;
10
+ this.config = options.config;
11
+ }
12
+ isConnected() {
13
+ return true;
14
+ }
15
+ /**
16
+ * Get the webhook path
17
+ */
18
+ getPath() {
19
+ return this.config.path;
20
+ }
21
+ /**
22
+ * Get the expected method
23
+ */
24
+ getMethod() {
25
+ return this.config.method ?? "POST";
26
+ }
27
+ /**
28
+ * Register a handler for incoming webhooks
29
+ */
30
+ onWebhook(handler) {
31
+ this.handlers.push(handler);
32
+ return () => {
33
+ const index = this.handlers.indexOf(handler);
34
+ if (index !== -1) {
35
+ this.handlers.splice(index, 1);
36
+ }
37
+ };
38
+ }
39
+ /**
40
+ * Handle an incoming webhook request
41
+ */
42
+ async handleRequest(body, headers) {
43
+ if (this.config.verification) {
44
+ const valid = this.verifySignature(body, headers);
45
+ if (!valid) {
46
+ return { success: false, error: "Invalid signature", status: 401 };
47
+ }
48
+ }
49
+ for (const handler of this.handlers) {
50
+ try {
51
+ await handler(body, headers);
52
+ } catch (error) {
53
+ console.error(`Webhook handler error:`, error);
54
+ }
55
+ }
56
+ if (this.config.handlers) {
57
+ }
58
+ return { success: true, status: 200 };
59
+ }
60
+ /**
61
+ * Verify webhook signature
62
+ */
63
+ verifySignature(body, headers) {
64
+ if (!this.config.verification) return true;
65
+ const { type, secret, header, algorithm } = this.config.verification;
66
+ const signatureHeader = header ?? "x-signature";
67
+ const receivedSignature = headers[signatureHeader.toLowerCase()];
68
+ if (!receivedSignature || !secret) {
69
+ return false;
70
+ }
71
+ const bodyString = typeof body === "string" ? body : JSON.stringify(body);
72
+ switch (type) {
73
+ case "hmac": {
74
+ const algo = algorithm ?? "sha256";
75
+ const expectedSignature = createHmac(algo, secret).update(bodyString).digest("hex");
76
+ const cleanReceived = receivedSignature.replace(/^sha\d+=/, "");
77
+ return this.timingSafeEqual(cleanReceived, expectedSignature);
78
+ }
79
+ case "token": {
80
+ return receivedSignature === secret;
81
+ }
82
+ case "signature": {
83
+ return true;
84
+ }
85
+ default:
86
+ return true;
87
+ }
88
+ }
89
+ /**
90
+ * Timing-safe string comparison
91
+ */
92
+ timingSafeEqual(a, b) {
93
+ if (a.length !== b.length) {
94
+ return false;
95
+ }
96
+ let result = 0;
97
+ for (let i = 0; i < a.length; i++) {
98
+ result |= a.charCodeAt(i) ^ b.charCodeAt(i);
99
+ }
100
+ return result === 0;
101
+ }
102
+ };
103
+ var WebhookSender = class {
104
+ /**
105
+ * Send a Discord webhook
106
+ */
107
+ static async sendDiscordWebhook(url, options) {
108
+ try {
109
+ const response = await fetch(url, {
110
+ method: "POST",
111
+ headers: { "Content-Type": "application/json" },
112
+ body: JSON.stringify(options)
113
+ });
114
+ if (!response.ok) {
115
+ return {
116
+ success: false,
117
+ error: `HTTP ${response.status}`,
118
+ status: response.status
119
+ };
120
+ }
121
+ return { success: true, status: response.status };
122
+ } catch (error) {
123
+ return {
124
+ success: false,
125
+ error: error instanceof Error ? error.message : "Unknown error"
126
+ };
127
+ }
128
+ }
129
+ /**
130
+ * Send a generic webhook
131
+ */
132
+ static async send(url, body, options = {}) {
133
+ try {
134
+ const response = await fetch(url, {
135
+ method: options.method ?? "POST",
136
+ headers: {
137
+ "Content-Type": "application/json",
138
+ ...options.headers
139
+ },
140
+ body: typeof body === "string" ? body : JSON.stringify(body)
141
+ });
142
+ let data;
143
+ try {
144
+ data = await response.json();
145
+ } catch {
146
+ data = await response.text();
147
+ }
148
+ return {
149
+ success: response.ok,
150
+ data,
151
+ status: response.status
152
+ };
153
+ } catch (error) {
154
+ return {
155
+ success: false,
156
+ error: error instanceof Error ? error.message : "Unknown error"
157
+ };
158
+ }
159
+ }
160
+ };
161
+ function createWebhookPipe(options) {
162
+ return new WebhookPipe(options);
163
+ }
164
+ export {
165
+ WebhookPipe,
166
+ WebhookSender,
167
+ createWebhookPipe
168
+ };
169
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/webhook/index.ts"],"sourcesContent":["/**\n * Webhook pipe for incoming and outgoing webhooks\n */\n\nimport { createHmac } from 'node:crypto';\nimport type { Pipe, PipeResponse, WebhookPipeConfig } from '../types.js';\n\nexport interface WebhookPipeOptions {\n name: string;\n config: WebhookPipeConfig;\n}\n\nexport type WebhookHandler = (\n body: unknown,\n headers: Record<string, string>\n) => void | Promise<void>;\n\nexport class WebhookPipe implements Pipe {\n public readonly name: string;\n public readonly type = 'webhook';\n private config: WebhookPipeConfig;\n private handlers: WebhookHandler[] = [];\n\n constructor(options: WebhookPipeOptions) {\n this.name = options.name;\n this.config = options.config;\n }\n\n isConnected(): boolean {\n return true;\n }\n\n /**\n * Get the webhook path\n */\n getPath(): string {\n return this.config.path;\n }\n\n /**\n * Get the expected method\n */\n getMethod(): string {\n return this.config.method ?? 'POST';\n }\n\n /**\n * Register a handler for incoming webhooks\n */\n onWebhook(handler: WebhookHandler): () => void {\n this.handlers.push(handler);\n return () => {\n const index = this.handlers.indexOf(handler);\n if (index !== -1) {\n this.handlers.splice(index, 1);\n }\n };\n }\n\n /**\n * Handle an incoming webhook request\n */\n async handleRequest(\n body: unknown,\n headers: Record<string, string>\n ): Promise<PipeResponse> {\n // Verify signature if configured\n if (this.config.verification) {\n const valid = this.verifySignature(body, headers);\n if (!valid) {\n return { success: false, error: 'Invalid signature', status: 401 };\n }\n }\n\n // Call handlers\n for (const handler of this.handlers) {\n try {\n await handler(body, headers);\n } catch (error) {\n console.error(`Webhook handler error:`, error);\n }\n }\n\n // Check for config handlers\n if (this.config.handlers) {\n // These would be processed by the action executor\n }\n\n return { success: true, status: 200 };\n }\n\n /**\n * Verify webhook signature\n */\n private verifySignature(\n body: unknown,\n headers: Record<string, string>\n ): boolean {\n if (!this.config.verification) return true;\n\n const { type, secret, header, algorithm } = this.config.verification;\n const signatureHeader = header ?? 'x-signature';\n const receivedSignature = headers[signatureHeader.toLowerCase()];\n\n if (!receivedSignature || !secret) {\n return false;\n }\n\n const bodyString = typeof body === 'string' ? body : JSON.stringify(body);\n\n switch (type) {\n case 'hmac': {\n const algo = algorithm ?? 'sha256';\n const expectedSignature = createHmac(algo, secret)\n .update(bodyString)\n .digest('hex');\n\n // Handle both raw and prefixed signatures\n const cleanReceived = receivedSignature.replace(/^sha\\d+=/, '');\n return this.timingSafeEqual(cleanReceived, expectedSignature);\n }\n\n case 'token': {\n return receivedSignature === secret;\n }\n\n case 'signature': {\n // Custom signature verification\n // This would depend on the specific service\n return true;\n }\n\n default:\n return true;\n }\n }\n\n /**\n * Timing-safe string comparison\n */\n private timingSafeEqual(a: string, b: string): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n }\n}\n\n/**\n * Outgoing webhook sender\n */\nexport class WebhookSender {\n /**\n * Send a Discord webhook\n */\n static async sendDiscordWebhook(\n url: string,\n options: {\n content?: string;\n username?: string;\n avatar_url?: string;\n embeds?: Record<string, unknown>[];\n }\n ): Promise<PipeResponse> {\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(options),\n });\n\n if (!response.ok) {\n return {\n success: false,\n error: `HTTP ${response.status}`,\n status: response.status,\n };\n }\n\n return { success: true, status: response.status };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n\n /**\n * Send a generic webhook\n */\n static async send(\n url: string,\n body: unknown,\n options: { headers?: Record<string, string>; method?: string } = {}\n ): Promise<PipeResponse> {\n try {\n const response = await fetch(url, {\n method: options.method ?? 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n body: typeof body === 'string' ? body : JSON.stringify(body),\n });\n\n let data: unknown;\n try {\n data = await response.json();\n } catch {\n data = await response.text();\n }\n\n return {\n success: response.ok,\n data,\n status: response.status,\n };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n}\n\n/**\n * Create a webhook pipe\n */\nexport function createWebhookPipe(options: WebhookPipeOptions): WebhookPipe {\n return new WebhookPipe(options);\n}\n"],"mappings":";AAIA,SAAS,kBAAkB;AAapB,IAAM,cAAN,MAAkC;AAAA,EACvB;AAAA,EACA,OAAO;AAAA,EACf;AAAA,EACA,WAA6B,CAAC;AAAA,EAEtC,YAAY,SAA6B;AACvC,SAAK,OAAO,QAAQ;AACpB,SAAK,SAAS,QAAQ;AAAA,EACxB;AAAA,EAEA,cAAuB;AACrB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,UAAkB;AAChB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,YAAoB;AAClB,WAAO,KAAK,OAAO,UAAU;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU,SAAqC;AAC7C,SAAK,SAAS,KAAK,OAAO;AAC1B,WAAO,MAAM;AACX,YAAM,QAAQ,KAAK,SAAS,QAAQ,OAAO;AAC3C,UAAI,UAAU,IAAI;AAChB,aAAK,SAAS,OAAO,OAAO,CAAC;AAAA,MAC/B;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cACJ,MACA,SACuB;AAEvB,QAAI,KAAK,OAAO,cAAc;AAC5B,YAAM,QAAQ,KAAK,gBAAgB,MAAM,OAAO;AAChD,UAAI,CAAC,OAAO;AACV,eAAO,EAAE,SAAS,OAAO,OAAO,qBAAqB,QAAQ,IAAI;AAAA,MACnE;AAAA,IACF;AAGA,eAAW,WAAW,KAAK,UAAU;AACnC,UAAI;AACF,cAAM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1E,SAAO,IAAI,YAAY,OAAO;AAChC;","names":[]}
@@ -0,0 +1,84 @@
1
+ import { P as Pipe, W as WebSocketPipeConfig, f as PipeResponse } from '../types-BW9r2ksN.js';
2
+
3
+ /**
4
+ * WebSocket pipe for bidirectional communication
5
+ */
6
+
7
+ interface WebSocketPipeOptions {
8
+ name: string;
9
+ config: WebSocketPipeConfig;
10
+ }
11
+ type WebSocketMessageHandler = (data: unknown) => void | Promise<void>;
12
+ declare class WebSocketPipe implements Pipe {
13
+ readonly name: string;
14
+ readonly type = "websocket";
15
+ private ws;
16
+ private config;
17
+ private reconnectAttempts;
18
+ private reconnecting;
19
+ private heartbeatInterval;
20
+ private messageHandlers;
21
+ private connected;
22
+ constructor(options: WebSocketPipeOptions);
23
+ /**
24
+ * Connect to the WebSocket server
25
+ */
26
+ connect(): Promise<void>;
27
+ /**
28
+ * Disconnect from the server
29
+ */
30
+ disconnect(): Promise<void>;
31
+ /**
32
+ * Check if connected
33
+ */
34
+ isConnected(): boolean;
35
+ /**
36
+ * Send a message
37
+ */
38
+ send(data: unknown): boolean;
39
+ /**
40
+ * Send and wait for a response (request-response pattern)
41
+ */
42
+ request<T = unknown>(data: unknown, options?: {
43
+ timeout?: number;
44
+ responseEvent?: string;
45
+ }): Promise<PipeResponse<T>>;
46
+ /**
47
+ * Register a message handler
48
+ */
49
+ on(event: string, handler: WebSocketMessageHandler): void;
50
+ /**
51
+ * Remove a message handler
52
+ */
53
+ off(event: string, handler: WebSocketMessageHandler): void;
54
+ /**
55
+ * Emit an event to handlers
56
+ */
57
+ private emit;
58
+ /**
59
+ * Handle incoming messages
60
+ */
61
+ private handleMessage;
62
+ /**
63
+ * Handle disconnection
64
+ */
65
+ private handleDisconnect;
66
+ /**
67
+ * Start heartbeat
68
+ */
69
+ private startHeartbeat;
70
+ /**
71
+ * Stop heartbeat
72
+ */
73
+ private stopHeartbeat;
74
+ /**
75
+ * Parse duration string to milliseconds
76
+ */
77
+ private parseDuration;
78
+ }
79
+ /**
80
+ * Create a WebSocket pipe
81
+ */
82
+ declare function createWebSocketPipe(options: WebSocketPipeOptions): WebSocketPipe;
83
+
84
+ export { type WebSocketMessageHandler, WebSocketPipe, type WebSocketPipeOptions, createWebSocketPipe };