@hostwebhook/node 1.0.5 → 1.0.7

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
@@ -200,6 +200,22 @@ interface SendOptions {
200
200
  interface SendResult {
201
201
  /** The event ID assigned by HostWebhook. */
202
202
  eventId: string;
203
+ /** Sync mode: pipeline result status (200=delivered, 422=validation failed, 502=delivery failed, 408=timeout) */
204
+ syncStatus?: number;
205
+ /** Sync mode: delivery status ('delivered') */
206
+ deliveryStatus?: string;
207
+ /** Sync mode: HTTP status code from the target URL */
208
+ statusCode?: number;
209
+ /** Sync mode: response body from the target URL (truncated to 4KB) */
210
+ response?: string;
211
+ /** Sync mode: delivery latency in ms */
212
+ latencyMs?: number;
213
+ /** Sync mode: error message if pipeline/delivery failed */
214
+ error?: string;
215
+ /** Sync mode: validation error messages (schema validator) */
216
+ message?: string[];
217
+ /** Any additional fields from the sync response */
218
+ [key: string]: unknown;
203
219
  }
204
220
  /** Thrown when the HostWebhook API returns a non-2xx response. */
205
221
  declare class SendError extends Error {
@@ -218,12 +234,7 @@ declare class SendError extends Error {
218
234
  * ```
219
235
  */
220
236
  declare class HostWebhook {
221
- private readonly token;
222
- private readonly baseUrl;
223
- private readonly signingSecret?;
224
- private readonly signature?;
225
- private readonly defaultHeaders;
226
- private readonly timeoutMs;
237
+ #private;
227
238
  constructor(config: HostWebhookConfig);
228
239
  /**
229
240
  * Send a webhook payload through HostWebhook.
package/dist/index.d.ts CHANGED
@@ -200,6 +200,22 @@ interface SendOptions {
200
200
  interface SendResult {
201
201
  /** The event ID assigned by HostWebhook. */
202
202
  eventId: string;
203
+ /** Sync mode: pipeline result status (200=delivered, 422=validation failed, 502=delivery failed, 408=timeout) */
204
+ syncStatus?: number;
205
+ /** Sync mode: delivery status ('delivered') */
206
+ deliveryStatus?: string;
207
+ /** Sync mode: HTTP status code from the target URL */
208
+ statusCode?: number;
209
+ /** Sync mode: response body from the target URL (truncated to 4KB) */
210
+ response?: string;
211
+ /** Sync mode: delivery latency in ms */
212
+ latencyMs?: number;
213
+ /** Sync mode: error message if pipeline/delivery failed */
214
+ error?: string;
215
+ /** Sync mode: validation error messages (schema validator) */
216
+ message?: string[];
217
+ /** Any additional fields from the sync response */
218
+ [key: string]: unknown;
203
219
  }
204
220
  /** Thrown when the HostWebhook API returns a non-2xx response. */
205
221
  declare class SendError extends Error {
@@ -218,12 +234,7 @@ declare class SendError extends Error {
218
234
  * ```
219
235
  */
220
236
  declare class HostWebhook {
221
- private readonly token;
222
- private readonly baseUrl;
223
- private readonly signingSecret?;
224
- private readonly signature?;
225
- private readonly defaultHeaders;
226
- private readonly timeoutMs;
237
+ #private;
227
238
  constructor(config: HostWebhookConfig);
228
239
  /**
229
240
  * Send a webhook payload through HostWebhook.
package/dist/index.js CHANGED
@@ -3,6 +3,9 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
6
9
  var __export = (target, all) => {
7
10
  for (var name in all)
8
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
16
19
  return to;
17
20
  };
18
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
19
26
 
20
27
  // src/index.ts
21
28
  var index_exports = {};
@@ -199,8 +206,15 @@ var SendError = class extends Error {
199
206
  // src/client.ts
200
207
  var DEFAULT_BASE_URL = "https://api.hostwebhook.com";
201
208
  var DEFAULT_TIMEOUT = 1e4;
209
+ var _token, _baseUrl, _signingSecret, _signature, _defaultHeaders, _timeoutMs;
202
210
  var HostWebhook = class {
203
211
  constructor(config) {
212
+ __privateAdd(this, _token);
213
+ __privateAdd(this, _baseUrl);
214
+ __privateAdd(this, _signingSecret);
215
+ __privateAdd(this, _signature);
216
+ __privateAdd(this, _defaultHeaders);
217
+ __privateAdd(this, _timeoutMs);
204
218
  if (!config.token) {
205
219
  throw new Error("HostWebhook: token is required");
206
220
  }
@@ -209,12 +223,12 @@ var HostWebhook = class {
209
223
  "HostWebhook: use either signingSecret or signature, not both"
210
224
  );
211
225
  }
212
- this.token = config.token;
213
- this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
214
- this.signingSecret = config.signingSecret;
215
- this.signature = config.signature;
216
- this.defaultHeaders = config.defaultHeaders ?? {};
217
- this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT;
226
+ __privateSet(this, _token, config.token);
227
+ __privateSet(this, _baseUrl, (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, ""));
228
+ __privateSet(this, _signingSecret, config.signingSecret);
229
+ __privateSet(this, _signature, config.signature);
230
+ __privateSet(this, _defaultHeaders, config.defaultHeaders ?? {});
231
+ __privateSet(this, _timeoutMs, config.timeoutMs ?? DEFAULT_TIMEOUT);
218
232
  }
219
233
  /**
220
234
  * Send a webhook payload through HostWebhook.
@@ -230,27 +244,34 @@ var HostWebhook = class {
230
244
  */
231
245
  async send(payload, options) {
232
246
  const body = options?.rawBody !== void 0 ? typeof options.rawBody === "string" ? options.rawBody : options.rawBody.toString("utf8") : JSON.stringify(payload);
247
+ let tz = "";
248
+ try {
249
+ tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
250
+ } catch {
251
+ }
233
252
  const headers = {
234
253
  "Content-Type": options?.contentType ?? "application/json",
235
- "User-Agent": "HostWebhook-SDK/1.0",
236
- ...this.defaultHeaders,
254
+ "User-Agent": `HostWebhook-SDK/${"1.0.6"}`,
255
+ "X-HostWebhook-Sent-At": (/* @__PURE__ */ new Date()).toISOString(),
256
+ ...tz ? { "X-HostWebhook-Timezone": tz } : {},
257
+ ...__privateGet(this, _defaultHeaders),
237
258
  ...options?.headers
238
259
  };
239
- if (this.signature?.type === "static") {
240
- const { secret, header } = this.signature;
260
+ if (__privateGet(this, _signature)?.type === "static") {
261
+ const { secret, header } = __privateGet(this, _signature);
241
262
  if (header) {
242
263
  headers[header] = secret;
243
264
  } else {
244
265
  headers["Authorization"] = `Bearer ${secret}`;
245
266
  }
246
- } else if (this.signingSecret) {
267
+ } else if (__privateGet(this, _signingSecret)) {
247
268
  const timestamp = Math.floor(Date.now() / 1e3);
248
- const sig = (0, import_crypto2.createHmac)("sha256", this.signingSecret).update(`${timestamp}.${body}`).digest("hex");
269
+ const sig = (0, import_crypto2.createHmac)("sha256", __privateGet(this, _signingSecret)).update(`${timestamp}.${body}`).digest("hex");
249
270
  headers["X-HostWebhook-Signature"] = `t=${timestamp},v1=${sig}`;
250
271
  }
251
- const url = `${this.baseUrl}/api/in/${this.token}`;
272
+ const url = `${__privateGet(this, _baseUrl)}/api/in/${__privateGet(this, _token)}`;
252
273
  const controller = new AbortController();
253
- const timer = setTimeout(() => controller.abort(), this.timeoutMs);
274
+ const timer = setTimeout(() => controller.abort(), __privateGet(this, _timeoutMs));
254
275
  try {
255
276
  const res = await fetch(url, {
256
277
  method: "POST",
@@ -275,7 +296,7 @@ var HostWebhook = class {
275
296
  if (err instanceof SendError) throw err;
276
297
  if (err instanceof DOMException && err.name === "AbortError") {
277
298
  throw new SendError(
278
- `HostWebhook request timed out after ${this.timeoutMs}ms`,
299
+ `HostWebhook request timed out after ${__privateGet(this, _timeoutMs)}ms`,
279
300
  0,
280
301
  ""
281
302
  );
@@ -296,6 +317,12 @@ var HostWebhook = class {
296
317
  return Promise.all(payloads.map((p) => this.send(p, options)));
297
318
  }
298
319
  };
320
+ _token = new WeakMap();
321
+ _baseUrl = new WeakMap();
322
+ _signingSecret = new WeakMap();
323
+ _signature = new WeakMap();
324
+ _defaultHeaders = new WeakMap();
325
+ _timeoutMs = new WeakMap();
299
326
  async function send(config, payload, options) {
300
327
  const client = new HostWebhook(config);
301
328
  return client.send(payload, options);
package/dist/index.mjs CHANGED
@@ -1,3 +1,11 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+
1
9
  // src/verify.ts
2
10
  import { createHmac, timingSafeEqual } from "crypto";
3
11
  var VerificationError = class extends Error {
@@ -165,8 +173,15 @@ var SendError = class extends Error {
165
173
  // src/client.ts
166
174
  var DEFAULT_BASE_URL = "https://api.hostwebhook.com";
167
175
  var DEFAULT_TIMEOUT = 1e4;
176
+ var _token, _baseUrl, _signingSecret, _signature, _defaultHeaders, _timeoutMs;
168
177
  var HostWebhook = class {
169
178
  constructor(config) {
179
+ __privateAdd(this, _token);
180
+ __privateAdd(this, _baseUrl);
181
+ __privateAdd(this, _signingSecret);
182
+ __privateAdd(this, _signature);
183
+ __privateAdd(this, _defaultHeaders);
184
+ __privateAdd(this, _timeoutMs);
170
185
  if (!config.token) {
171
186
  throw new Error("HostWebhook: token is required");
172
187
  }
@@ -175,12 +190,12 @@ var HostWebhook = class {
175
190
  "HostWebhook: use either signingSecret or signature, not both"
176
191
  );
177
192
  }
178
- this.token = config.token;
179
- this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
180
- this.signingSecret = config.signingSecret;
181
- this.signature = config.signature;
182
- this.defaultHeaders = config.defaultHeaders ?? {};
183
- this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT;
193
+ __privateSet(this, _token, config.token);
194
+ __privateSet(this, _baseUrl, (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, ""));
195
+ __privateSet(this, _signingSecret, config.signingSecret);
196
+ __privateSet(this, _signature, config.signature);
197
+ __privateSet(this, _defaultHeaders, config.defaultHeaders ?? {});
198
+ __privateSet(this, _timeoutMs, config.timeoutMs ?? DEFAULT_TIMEOUT);
184
199
  }
185
200
  /**
186
201
  * Send a webhook payload through HostWebhook.
@@ -196,27 +211,34 @@ var HostWebhook = class {
196
211
  */
197
212
  async send(payload, options) {
198
213
  const body = options?.rawBody !== void 0 ? typeof options.rawBody === "string" ? options.rawBody : options.rawBody.toString("utf8") : JSON.stringify(payload);
214
+ let tz = "";
215
+ try {
216
+ tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
217
+ } catch {
218
+ }
199
219
  const headers = {
200
220
  "Content-Type": options?.contentType ?? "application/json",
201
- "User-Agent": "HostWebhook-SDK/1.0",
202
- ...this.defaultHeaders,
221
+ "User-Agent": `HostWebhook-SDK/${"1.0.6"}`,
222
+ "X-HostWebhook-Sent-At": (/* @__PURE__ */ new Date()).toISOString(),
223
+ ...tz ? { "X-HostWebhook-Timezone": tz } : {},
224
+ ...__privateGet(this, _defaultHeaders),
203
225
  ...options?.headers
204
226
  };
205
- if (this.signature?.type === "static") {
206
- const { secret, header } = this.signature;
227
+ if (__privateGet(this, _signature)?.type === "static") {
228
+ const { secret, header } = __privateGet(this, _signature);
207
229
  if (header) {
208
230
  headers[header] = secret;
209
231
  } else {
210
232
  headers["Authorization"] = `Bearer ${secret}`;
211
233
  }
212
- } else if (this.signingSecret) {
234
+ } else if (__privateGet(this, _signingSecret)) {
213
235
  const timestamp = Math.floor(Date.now() / 1e3);
214
- const sig = createHmac2("sha256", this.signingSecret).update(`${timestamp}.${body}`).digest("hex");
236
+ const sig = createHmac2("sha256", __privateGet(this, _signingSecret)).update(`${timestamp}.${body}`).digest("hex");
215
237
  headers["X-HostWebhook-Signature"] = `t=${timestamp},v1=${sig}`;
216
238
  }
217
- const url = `${this.baseUrl}/api/in/${this.token}`;
239
+ const url = `${__privateGet(this, _baseUrl)}/api/in/${__privateGet(this, _token)}`;
218
240
  const controller = new AbortController();
219
- const timer = setTimeout(() => controller.abort(), this.timeoutMs);
241
+ const timer = setTimeout(() => controller.abort(), __privateGet(this, _timeoutMs));
220
242
  try {
221
243
  const res = await fetch(url, {
222
244
  method: "POST",
@@ -241,7 +263,7 @@ var HostWebhook = class {
241
263
  if (err instanceof SendError) throw err;
242
264
  if (err instanceof DOMException && err.name === "AbortError") {
243
265
  throw new SendError(
244
- `HostWebhook request timed out after ${this.timeoutMs}ms`,
266
+ `HostWebhook request timed out after ${__privateGet(this, _timeoutMs)}ms`,
245
267
  0,
246
268
  ""
247
269
  );
@@ -262,6 +284,12 @@ var HostWebhook = class {
262
284
  return Promise.all(payloads.map((p) => this.send(p, options)));
263
285
  }
264
286
  };
287
+ _token = new WeakMap();
288
+ _baseUrl = new WeakMap();
289
+ _signingSecret = new WeakMap();
290
+ _signature = new WeakMap();
291
+ _defaultHeaders = new WeakMap();
292
+ _timeoutMs = new WeakMap();
265
293
  async function send(config, payload, options) {
266
294
  const client = new HostWebhook(config);
267
295
  return client.send(payload, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostwebhook/node",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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",
@@ -18,7 +18,7 @@
18
18
  "llms.txt"
19
19
  ],
20
20
  "scripts": {
21
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
21
+ "build": "tsup",
22
22
  "test": "node --test __tests__/sdk.test.mjs",
23
23
  "prepublishOnly": "npm run build"
24
24
  },