@hostwebhook/node 1.1.1 → 1.2.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.
package/dist/index.d.mts CHANGED
@@ -208,12 +208,33 @@ interface SendOptions {
208
208
  */
209
209
  rawBody?: string | Buffer;
210
210
  /**
211
- * Wait for the full pipeline result via SSE streaming.
211
+ * Wait for the full pipeline result via SSE streaming (blocking).
212
212
  * The SDK will POST the payload, then open an SSE stream to receive
213
213
  * pipeline steps and the final result. Returns when the pipeline completes.
214
214
  * Timeout: ~125s (slightly above the server's 120s SSE timeout).
215
215
  */
216
216
  waitForResult?: boolean;
217
+ /**
218
+ * Non-blocking pipeline result callback. `send()` returns immediately with
219
+ * the eventId, and the callback fires in the background when the pipeline
220
+ * completes (via SSE stream). Perfect for UIs that shouldn't block.
221
+ *
222
+ * Requires the endpoint to be in `none` response mode (async).
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * const { eventId } = await hw.send(payload, {
227
+ * onResult: (result) => console.log('Pipeline done:', result.syncStatus),
228
+ * });
229
+ * // UI shows "Sent!" immediately here
230
+ * ```
231
+ */
232
+ onResult?: (result: SendResult) => void;
233
+ /**
234
+ * Called for each pipeline step during SSE streaming.
235
+ * Only fires when `onResult` or `waitForResult` is used.
236
+ */
237
+ onStep?: (step: PipelineStep) => void;
217
238
  }
218
239
  /** Result returned after a successful send. */
219
240
  interface SendResult {
package/dist/index.d.ts CHANGED
@@ -208,12 +208,33 @@ interface SendOptions {
208
208
  */
209
209
  rawBody?: string | Buffer;
210
210
  /**
211
- * Wait for the full pipeline result via SSE streaming.
211
+ * Wait for the full pipeline result via SSE streaming (blocking).
212
212
  * The SDK will POST the payload, then open an SSE stream to receive
213
213
  * pipeline steps and the final result. Returns when the pipeline completes.
214
214
  * Timeout: ~125s (slightly above the server's 120s SSE timeout).
215
215
  */
216
216
  waitForResult?: boolean;
217
+ /**
218
+ * Non-blocking pipeline result callback. `send()` returns immediately with
219
+ * the eventId, and the callback fires in the background when the pipeline
220
+ * completes (via SSE stream). Perfect for UIs that shouldn't block.
221
+ *
222
+ * Requires the endpoint to be in `none` response mode (async).
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * const { eventId } = await hw.send(payload, {
227
+ * onResult: (result) => console.log('Pipeline done:', result.syncStatus),
228
+ * });
229
+ * // UI shows "Sent!" immediately here
230
+ * ```
231
+ */
232
+ onResult?: (result: SendResult) => void;
233
+ /**
234
+ * Called for each pipeline step during SSE streaming.
235
+ * Only fires when `onResult` or `waitForResult` is used.
236
+ */
237
+ onStep?: (step: PipelineStep) => void;
217
238
  }
218
239
  /** Result returned after a successful send. */
219
240
  interface SendResult {
package/dist/index.js CHANGED
@@ -253,7 +253,7 @@ var HostWebhook = class {
253
253
  }
254
254
  const headers = {
255
255
  "Content-Type": options?.contentType ?? "application/json",
256
- "User-Agent": `HostWebhook-SDK/${"1.1.0"}`,
256
+ "User-Agent": `HostWebhook-SDK/${"1.2.0"}`,
257
257
  "X-HostWebhook-Sent-At": (/* @__PURE__ */ new Date()).toISOString(),
258
258
  ...tz ? { "X-HostWebhook-Timezone": tz } : {},
259
259
  ...__privateGet(this, _defaultHeaders),
@@ -308,9 +308,16 @@ var HostWebhook = class {
308
308
  } finally {
309
309
  clearTimeout(timer);
310
310
  }
311
- if (ingressResult.syncStatus !== void 0) return ingressResult;
311
+ if (ingressResult.syncStatus !== void 0) {
312
+ if (options?.onResult) options.onResult(ingressResult);
313
+ return ingressResult;
314
+ }
312
315
  if (options?.waitForResult && ingressResult.streamToken) {
313
- return __privateMethod(this, _HostWebhook_instances, waitForStream_fn).call(this, ingressResult);
316
+ return __privateMethod(this, _HostWebhook_instances, waitForStream_fn).call(this, ingressResult, options?.onStep);
317
+ }
318
+ if (options?.onResult && ingressResult.streamToken) {
319
+ __privateMethod(this, _HostWebhook_instances, waitForStream_fn).call(this, ingressResult, options?.onStep).then((result) => options.onResult(result)).catch(() => {
320
+ });
314
321
  }
315
322
  return ingressResult;
316
323
  }
@@ -332,7 +339,7 @@ _signature = new WeakMap();
332
339
  _defaultHeaders = new WeakMap();
333
340
  _timeoutMs = new WeakMap();
334
341
  _HostWebhook_instances = new WeakSet();
335
- waitForStream_fn = async function(ingressResult) {
342
+ waitForStream_fn = async function(ingressResult, onStep) {
336
343
  const { eventId, streamToken } = ingressResult;
337
344
  const streamUrl = `${__privateGet(this, _baseUrl)}/api/events/${eventId}/stream?token=${streamToken}`;
338
345
  const controller = new AbortController();
@@ -364,6 +371,7 @@ waitForStream_fn = async function(ingressResult) {
364
371
  const parsed = JSON.parse(data);
365
372
  if (currentEvent === "step") {
366
373
  steps.push(parsed);
374
+ if (onStep) onStep(parsed);
367
375
  } else if (currentEvent === "done") {
368
376
  doneResult = parsed;
369
377
  } else if (currentEvent === "timeout") {
package/dist/index.mjs CHANGED
@@ -220,7 +220,7 @@ var HostWebhook = class {
220
220
  }
221
221
  const headers = {
222
222
  "Content-Type": options?.contentType ?? "application/json",
223
- "User-Agent": `HostWebhook-SDK/${"1.1.0"}`,
223
+ "User-Agent": `HostWebhook-SDK/${"1.2.0"}`,
224
224
  "X-HostWebhook-Sent-At": (/* @__PURE__ */ new Date()).toISOString(),
225
225
  ...tz ? { "X-HostWebhook-Timezone": tz } : {},
226
226
  ...__privateGet(this, _defaultHeaders),
@@ -275,9 +275,16 @@ var HostWebhook = class {
275
275
  } finally {
276
276
  clearTimeout(timer);
277
277
  }
278
- if (ingressResult.syncStatus !== void 0) return ingressResult;
278
+ if (ingressResult.syncStatus !== void 0) {
279
+ if (options?.onResult) options.onResult(ingressResult);
280
+ return ingressResult;
281
+ }
279
282
  if (options?.waitForResult && ingressResult.streamToken) {
280
- return __privateMethod(this, _HostWebhook_instances, waitForStream_fn).call(this, ingressResult);
283
+ return __privateMethod(this, _HostWebhook_instances, waitForStream_fn).call(this, ingressResult, options?.onStep);
284
+ }
285
+ if (options?.onResult && ingressResult.streamToken) {
286
+ __privateMethod(this, _HostWebhook_instances, waitForStream_fn).call(this, ingressResult, options?.onStep).then((result) => options.onResult(result)).catch(() => {
287
+ });
281
288
  }
282
289
  return ingressResult;
283
290
  }
@@ -299,7 +306,7 @@ _signature = new WeakMap();
299
306
  _defaultHeaders = new WeakMap();
300
307
  _timeoutMs = new WeakMap();
301
308
  _HostWebhook_instances = new WeakSet();
302
- waitForStream_fn = async function(ingressResult) {
309
+ waitForStream_fn = async function(ingressResult, onStep) {
303
310
  const { eventId, streamToken } = ingressResult;
304
311
  const streamUrl = `${__privateGet(this, _baseUrl)}/api/events/${eventId}/stream?token=${streamToken}`;
305
312
  const controller = new AbortController();
@@ -331,6 +338,7 @@ waitForStream_fn = async function(ingressResult) {
331
338
  const parsed = JSON.parse(data);
332
339
  if (currentEvent === "step") {
333
340
  steps.push(parsed);
341
+ if (onStep) onStep(parsed);
334
342
  } else if (currentEvent === "done") {
335
343
  doneResult = parsed;
336
344
  } else if (currentEvent === "timeout") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostwebhook/node",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Official HostWebhook SDK — verify signatures, parse headers, and send webhooks",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",