configurapi-handler-ws
Advanced tools
+5
-1
| { | ||
| "name": "configurapi-handler-ws", | ||
| "version": "1.3.0", | ||
| "version": "1.4.0", | ||
| "main": "src/index", | ||
@@ -10,2 +10,6 @@ "files": [ | ||
| "types": "src/index.d.ts", | ||
| "scripts": { | ||
| "test": "node --test --test-reporter=spec spec/**/*.spec.js", | ||
| "test-watch": "node --test --watch --test-reporter=spec spec/**/*.spec.js" | ||
| }, | ||
| "repository": { | ||
@@ -12,0 +16,0 @@ "type": "git", |
+3
-3
@@ -10,6 +10,6 @@ # configurapi-handler-ws | ||
| * If you want to stream data back to the client, return a `StreamResponse` with a readable stream. | ||
| * Use pushbackFunction(postbackFunction: Function, response: PostbackResponse) to send a response to the postback endpoint. The response will be wrapped in the specified postbackFunction. | ||
| * Use postbackFunction(postbackFunction: Function, response: PostbackResponse) to send a response to the postback endpoint. The response will be wrapped in the specified postbackFunction. | ||
| ``` | ||
| const { pushbackFunction, PostbackResponse } = require("configurapi-handler-ws"); | ||
| const { postbackFunction, PostbackResponse } = require("configurapi-handler-ws"); | ||
@@ -32,3 +32,3 @@ let callback = async (body:any, headers:Record<string,string>) => | ||
| await pushbackFunction(callback, new PostbackResponse('body', {'content-type': 'application/json'})) | ||
| await postbackFunction(callback, new PostbackResponse('body', {'content-type': 'application/json'})) | ||
| ``` | ||
@@ -35,0 +35,0 @@ |
@@ -33,3 +33,3 @@ const { v4: uuidv4 } = require('uuid'); | ||
| await postBackFunction.apply(undefined, [body, headers]) | ||
| break; | ||
| return; | ||
| } | ||
@@ -40,2 +40,4 @@ catch(e){ err = e}; | ||
| } | ||
| throw err; | ||
| } | ||
@@ -42,0 +44,0 @@ }; |
+33
-27
@@ -59,7 +59,10 @@ const MessageIdHeaderName = 'message-id'; | ||
| this.connecting = false; | ||
| // Fail all pending calls | ||
| for (const [id, waiter] of this.inflight) { | ||
| clearTimeout(waiter.timer); | ||
| for (const [id, waiter] of this.inflight) | ||
| { | ||
| if(waiter.timer) clearTimeout(waiter.timer); | ||
| waiter.reject(new Error(`WebSocket closed before response (id=${id})`)); | ||
| } | ||
| this.inflight.clear(); | ||
@@ -98,9 +101,14 @@ }); | ||
| let timer = null; | ||
| const waiter = { resolve, reject, timer: null, onChunk: opts?.onChunk, onDone: opts?.onDone, onError: opts?.onError, timedOut: false, muted: false }; | ||
| const waiter = { resolve, reject, timer: undefined, onChunk: opts?.onChunk, onDone: opts?.onDone, onError: opts?.onError }; | ||
| if (timeoutMs > 0) | ||
| { | ||
| timer = setTimeout(() => { | ||
| waiter.timedOut = true; | ||
| timer = setTimeout(() => | ||
| { | ||
| waiter.timer = undefined; | ||
| waiter.onChunk?.("\n\nI've reached my response time limit and couldn't complete my full answer. Could you let me know which part you'd like me to focus on?"); | ||
| waiter.onChunk?.("\n\nI've reached my response time limit and couldn't complete my full answer. Could you let me know which part you'd like me to focus on?"); | ||
| // Remove from inflight before rejecting | ||
| this.inflight.delete(id); | ||
| // Reject the promise so callers can show a warning, but keep waiter so 'done' can clean up | ||
@@ -122,3 +130,9 @@ reject(new Error(`Timed out waiting for response (messageId=${id})`)); | ||
| const waiter = this.inflight.get(id); | ||
| if (waiter) { clearTimeout(waiter.timer); this.inflight.delete(id); } | ||
| if(waiter) | ||
| { | ||
| if(waiter.timer) clearTimeout(waiter.timer); | ||
| this.inflight.delete(id); | ||
| } | ||
| throw e; | ||
@@ -156,4 +170,2 @@ } | ||
| { | ||
| if (waiter?.timedOut) return; | ||
| if (waiter) | ||
@@ -176,6 +188,14 @@ { | ||
| await waiter.onChunk?.(msg.body ?? msg.payload ?? ''); | ||
| await waiter.onDone?.(); | ||
| if(waiter.timer) clearTimeout(waiter.timer); | ||
| clearTimeout(waiter.timer); | ||
| if (streamFlag === 'done') | ||
| { | ||
| await waiter.onChunk?.(msg.body ?? msg.payload ?? ''); | ||
| await waiter.onDone?.(); | ||
| waiter.resolve(msg); | ||
| } | ||
| else if (streamFlag === 'error') | ||
| { | ||
| waiter.reject(msg); | ||
| } | ||
@@ -186,15 +206,2 @@ if(id) | ||
| } | ||
| // We alaready rejected if timed out. | ||
| if(waiter.timedOut) return | ||
| if (streamFlag === 'error') | ||
| { | ||
| waiter.reject(msg); | ||
| } | ||
| else | ||
| { | ||
| waiter.resolve(msg); | ||
| } | ||
| return; | ||
| } | ||
@@ -222,7 +229,6 @@ | ||
| clearTimeout(waiter.timer); | ||
| if(waiter.timer) clearTimeout(waiter.timer); | ||
| this.inflight.delete(id); | ||
| if(waiter.timedOut) return // Already rejected | ||
| waiter.resolve(msg); | ||
@@ -229,0 +235,0 @@ } |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
21765
1.18%502
0.8%