@hostwebhook/node 1.0.4 → 1.0.5

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
@@ -140,6 +140,18 @@ declare function createNestGuard(secret: string, options?: VerifyOptions): {
140
140
  */
141
141
  declare function fastifyHook(secret: string, options?: VerifyOptions): (req: ExpressRequest, reply: ExpressResponse, done: NextFn) => void;
142
142
 
143
+ /** Static secret signature — sends the secret as-is in a header (no HMAC). */
144
+ interface StaticSignature {
145
+ type: 'static';
146
+ /** The secret/token value to send. */
147
+ secret: string;
148
+ /**
149
+ * Header name to send the secret in.
150
+ * Default: `Authorization` with `Bearer <secret>` format.
151
+ * @example 'X-My-Custom-Key'
152
+ */
153
+ header?: string;
154
+ }
143
155
  /** Configuration for the HostWebhook client. */
144
156
  interface HostWebhookConfig {
145
157
  /** Ingress token from your endpoint settings. */
@@ -147,12 +159,26 @@ interface HostWebhookConfig {
147
159
  /** Base URL of the HostWebhook API. Default: `https://api.hostwebhook.com` */
148
160
  baseUrl?: string;
149
161
  /**
150
- * Signing secret for incoming signature verification.
151
- * When provided, every request is signed with HMAC-SHA256 using the `custom`
152
- * format (`X-Webhook-Signature: sha256=<hex>`), which HostWebhook verifies
153
- * if the endpoint has `incomingSignatureType: 'custom'` configured.
162
+ * HMAC-SHA256 signing secret. When set, every request is signed with the
163
+ * HostWebhook signature format (`X-HostWebhook-Signature: t=<ts>,v1=<hmac>`).
164
+ * Pair with `incomingSignatureType: 'hostwebhook'` on the endpoint.
165
+ * @deprecated Prefer `signature` for new integrations.
154
166
  */
155
167
  signingSecret?: string;
168
+ /**
169
+ * Signature configuration for incoming webhook verification.
170
+ * Cannot be used together with `signingSecret`.
171
+ *
172
+ * @example Static with default header (Authorization: Bearer)
173
+ * ```ts
174
+ * { type: 'static', secret: 'my-secret' }
175
+ * ```
176
+ * @example Static with custom header
177
+ * ```ts
178
+ * { type: 'static', secret: 'my-secret', header: 'X-My-Custom-Key' }
179
+ * ```
180
+ */
181
+ signature?: StaticSignature;
156
182
  /** Custom headers to include in every request. */
157
183
  defaultHeaders?: Record<string, string>;
158
184
  /** Request timeout in milliseconds. Default: 10000 (10s). */
@@ -195,6 +221,7 @@ declare class HostWebhook {
195
221
  private readonly token;
196
222
  private readonly baseUrl;
197
223
  private readonly signingSecret?;
224
+ private readonly signature?;
198
225
  private readonly defaultHeaders;
199
226
  private readonly timeoutMs;
200
227
  constructor(config: HostWebhookConfig);
@@ -231,4 +258,4 @@ declare class HostWebhook {
231
258
  */
232
259
  declare function send(config: HostWebhookConfig, payload: Record<string, unknown>, options?: SendOptions): Promise<SendResult>;
233
260
 
234
- export { HostWebhook, type HostWebhookConfig, SendError, type SendOptions, type SendResult, VerificationError, type VerifyOptions, type WebhookHeaders, createNestGuard, expressMiddleware, fastifyHook, parseHeaders, send, verify };
261
+ export { HostWebhook, type HostWebhookConfig, SendError, type SendOptions, type SendResult, type StaticSignature, VerificationError, type VerifyOptions, type WebhookHeaders, createNestGuard, expressMiddleware, fastifyHook, parseHeaders, send, verify };
package/dist/index.d.ts CHANGED
@@ -140,6 +140,18 @@ declare function createNestGuard(secret: string, options?: VerifyOptions): {
140
140
  */
141
141
  declare function fastifyHook(secret: string, options?: VerifyOptions): (req: ExpressRequest, reply: ExpressResponse, done: NextFn) => void;
142
142
 
143
+ /** Static secret signature — sends the secret as-is in a header (no HMAC). */
144
+ interface StaticSignature {
145
+ type: 'static';
146
+ /** The secret/token value to send. */
147
+ secret: string;
148
+ /**
149
+ * Header name to send the secret in.
150
+ * Default: `Authorization` with `Bearer <secret>` format.
151
+ * @example 'X-My-Custom-Key'
152
+ */
153
+ header?: string;
154
+ }
143
155
  /** Configuration for the HostWebhook client. */
144
156
  interface HostWebhookConfig {
145
157
  /** Ingress token from your endpoint settings. */
@@ -147,12 +159,26 @@ interface HostWebhookConfig {
147
159
  /** Base URL of the HostWebhook API. Default: `https://api.hostwebhook.com` */
148
160
  baseUrl?: string;
149
161
  /**
150
- * Signing secret for incoming signature verification.
151
- * When provided, every request is signed with HMAC-SHA256 using the `custom`
152
- * format (`X-Webhook-Signature: sha256=<hex>`), which HostWebhook verifies
153
- * if the endpoint has `incomingSignatureType: 'custom'` configured.
162
+ * HMAC-SHA256 signing secret. When set, every request is signed with the
163
+ * HostWebhook signature format (`X-HostWebhook-Signature: t=<ts>,v1=<hmac>`).
164
+ * Pair with `incomingSignatureType: 'hostwebhook'` on the endpoint.
165
+ * @deprecated Prefer `signature` for new integrations.
154
166
  */
155
167
  signingSecret?: string;
168
+ /**
169
+ * Signature configuration for incoming webhook verification.
170
+ * Cannot be used together with `signingSecret`.
171
+ *
172
+ * @example Static with default header (Authorization: Bearer)
173
+ * ```ts
174
+ * { type: 'static', secret: 'my-secret' }
175
+ * ```
176
+ * @example Static with custom header
177
+ * ```ts
178
+ * { type: 'static', secret: 'my-secret', header: 'X-My-Custom-Key' }
179
+ * ```
180
+ */
181
+ signature?: StaticSignature;
156
182
  /** Custom headers to include in every request. */
157
183
  defaultHeaders?: Record<string, string>;
158
184
  /** Request timeout in milliseconds. Default: 10000 (10s). */
@@ -195,6 +221,7 @@ declare class HostWebhook {
195
221
  private readonly token;
196
222
  private readonly baseUrl;
197
223
  private readonly signingSecret?;
224
+ private readonly signature?;
198
225
  private readonly defaultHeaders;
199
226
  private readonly timeoutMs;
200
227
  constructor(config: HostWebhookConfig);
@@ -231,4 +258,4 @@ declare class HostWebhook {
231
258
  */
232
259
  declare function send(config: HostWebhookConfig, payload: Record<string, unknown>, options?: SendOptions): Promise<SendResult>;
233
260
 
234
- export { HostWebhook, type HostWebhookConfig, SendError, type SendOptions, type SendResult, VerificationError, type VerifyOptions, type WebhookHeaders, createNestGuard, expressMiddleware, fastifyHook, parseHeaders, send, verify };
261
+ export { HostWebhook, type HostWebhookConfig, SendError, type SendOptions, type SendResult, type StaticSignature, VerificationError, type VerifyOptions, type WebhookHeaders, createNestGuard, expressMiddleware, fastifyHook, parseHeaders, send, verify };
package/dist/index.js CHANGED
@@ -204,9 +204,15 @@ var HostWebhook = class {
204
204
  if (!config.token) {
205
205
  throw new Error("HostWebhook: token is required");
206
206
  }
207
+ if (config.signingSecret && config.signature) {
208
+ throw new Error(
209
+ "HostWebhook: use either signingSecret or signature, not both"
210
+ );
211
+ }
207
212
  this.token = config.token;
208
213
  this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
209
214
  this.signingSecret = config.signingSecret;
215
+ this.signature = config.signature;
210
216
  this.defaultHeaders = config.defaultHeaders ?? {};
211
217
  this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT;
212
218
  }
@@ -230,7 +236,14 @@ var HostWebhook = class {
230
236
  ...this.defaultHeaders,
231
237
  ...options?.headers
232
238
  };
233
- if (this.signingSecret) {
239
+ if (this.signature?.type === "static") {
240
+ const { secret, header } = this.signature;
241
+ if (header) {
242
+ headers[header] = secret;
243
+ } else {
244
+ headers["Authorization"] = `Bearer ${secret}`;
245
+ }
246
+ } else if (this.signingSecret) {
234
247
  const timestamp = Math.floor(Date.now() / 1e3);
235
248
  const sig = (0, import_crypto2.createHmac)("sha256", this.signingSecret).update(`${timestamp}.${body}`).digest("hex");
236
249
  headers["X-HostWebhook-Signature"] = `t=${timestamp},v1=${sig}`;
package/dist/index.mjs CHANGED
@@ -170,9 +170,15 @@ var HostWebhook = class {
170
170
  if (!config.token) {
171
171
  throw new Error("HostWebhook: token is required");
172
172
  }
173
+ if (config.signingSecret && config.signature) {
174
+ throw new Error(
175
+ "HostWebhook: use either signingSecret or signature, not both"
176
+ );
177
+ }
173
178
  this.token = config.token;
174
179
  this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
175
180
  this.signingSecret = config.signingSecret;
181
+ this.signature = config.signature;
176
182
  this.defaultHeaders = config.defaultHeaders ?? {};
177
183
  this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT;
178
184
  }
@@ -196,7 +202,14 @@ var HostWebhook = class {
196
202
  ...this.defaultHeaders,
197
203
  ...options?.headers
198
204
  };
199
- if (this.signingSecret) {
205
+ if (this.signature?.type === "static") {
206
+ const { secret, header } = this.signature;
207
+ if (header) {
208
+ headers[header] = secret;
209
+ } else {
210
+ headers["Authorization"] = `Bearer ${secret}`;
211
+ }
212
+ } else if (this.signingSecret) {
200
213
  const timestamp = Math.floor(Date.now() / 1e3);
201
214
  const sig = createHmac2("sha256", this.signingSecret).update(`${timestamp}.${body}`).digest("hex");
202
215
  headers["X-HostWebhook-Signature"] = `t=${timestamp},v1=${sig}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostwebhook/node",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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",