@hookflo/tern 3.0.0 → 3.0.1

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.
@@ -114,10 +114,18 @@ class AlgorithmBasedVerifier extends base_1.WebhookVerifier {
114
114
  const customFormat = this.config.customConfig.payloadFormat;
115
115
  if (customFormat.includes("{id}") && customFormat.includes("{timestamp}")) {
116
116
  const id = request.headers.get(this.config.customConfig.idHeader || "x-webhook-id");
117
- const timestamp = request.headers.get(this.config.timestampHeader || "x-webhook-timestamp");
117
+ const timestamp = request.headers.get(this.config.timestampHeader ||
118
+ this.config.customConfig?.timestampHeader ||
119
+ "x-webhook-timestamp");
120
+ // if either is missing payload will be malformed — fail explicitly
121
+ if (!id || !timestamp) {
122
+ throw new Error(`Missing required headers for payload construction: ${!id ? this.config.customConfig.idHeader || "x-webhook-id" : ""} ${!timestamp
123
+ ? this.config.timestampHeader || "x-webhook-timestamp"
124
+ : ""}`.trim());
125
+ }
118
126
  return customFormat
119
- .replace("{id}", id || "")
120
- .replace("{timestamp}", timestamp || "")
127
+ .replace("{id}", id.trim() || "")
128
+ .replace("{timestamp}", timestamp.trim() || "")
121
129
  .replace("{body}", rawBody);
122
130
  }
123
131
  if (customFormat.includes("{timestamp}") &&
@@ -187,7 +195,9 @@ class AlgorithmBasedVerifier extends base_1.WebhookVerifier {
187
195
  case "workos":
188
196
  case "sentry":
189
197
  case "sanity":
190
- metadata.id = request.headers.get(this.config.idHeader || this.config.customConfig?.idHeader || "webhook-id");
198
+ metadata.id = request.headers.get(this.config.idHeader ||
199
+ this.config.customConfig?.idHeader ||
200
+ "webhook-id");
191
201
  break;
192
202
  default:
193
203
  if (this.config.idHeader) {
@@ -201,7 +211,10 @@ class AlgorithmBasedVerifier extends base_1.WebhookVerifier {
201
211
  exports.AlgorithmBasedVerifier = AlgorithmBasedVerifier;
202
212
  class GenericHMACVerifier extends AlgorithmBasedVerifier {
203
213
  resolveSentryPayloadCandidates(rawBody, request) {
204
- const candidates = [this.formatPayload(rawBody, request), rawBody];
214
+ const candidates = [
215
+ this.formatPayload(rawBody, request),
216
+ rawBody,
217
+ ];
205
218
  if (this.config.payloadFormat === "json-stringified") {
206
219
  try {
207
220
  const parsed = JSON.parse(rawBody);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hookflo/tern",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A robust, scalable webhook verification framework supporting multiple platforms and signature algorithms",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",