@hookflo/tern 4.2.3-beta → 4.2.5-beta

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/alerts.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './notifications';
2
- export declare const __alertInternals: {
2
+ export declare const alertInternals: {
3
3
  resolveDestinations: typeof import("./notifications/utils").resolveDestinations;
4
4
  normalizeAlertOptions: typeof import("./notifications/utils").normalizeAlertOptions;
5
5
  buildSlackPayload: typeof import("./notifications/channels/slack").buildSlackPayload;
package/dist/alerts.js CHANGED
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.__alertInternals = void 0;
18
- __exportStar(require("./notifications"), exports);
17
+ exports.alertInternals = void 0;
19
18
  const notifications_1 = require("./notifications");
19
+ __exportStar(require("./notifications"), exports);
20
20
  // Backward-compatible alias used by previous version internals.
21
- exports.__alertInternals = notifications_1.__notificationInternals;
21
+ exports.alertInternals = notifications_1.notificationInternals;
@@ -1,8 +1,8 @@
1
- export * from './types';
2
1
  import { normalizeAlertOptions, resolveDestinations } from './utils';
3
2
  import { buildSlackPayload } from './channels/slack';
4
3
  import { buildDiscordPayload } from './channels/discord';
5
- export declare const __notificationInternals: {
4
+ export * from './types';
5
+ export declare const notificationInternals: {
6
6
  resolveDestinations: typeof resolveDestinations;
7
7
  normalizeAlertOptions: typeof normalizeAlertOptions;
8
8
  buildSlackPayload: typeof buildSlackPayload;
@@ -14,12 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.__notificationInternals = void 0;
18
- __exportStar(require("./types"), exports);
17
+ exports.notificationInternals = void 0;
19
18
  const utils_1 = require("./utils");
20
19
  const slack_1 = require("./channels/slack");
21
20
  const discord_1 = require("./channels/discord");
22
- exports.__notificationInternals = {
21
+ __exportStar(require("./types"), exports);
22
+ exports.notificationInternals = {
23
23
  resolveDestinations: utils_1.resolveDestinations,
24
24
  normalizeAlertOptions: utils_1.normalizeAlertOptions,
25
25
  buildSlackPayload: slack_1.buildSlackPayload,
@@ -10,6 +10,36 @@ function compactMetadata(metadata) {
10
10
  const entries = Object.entries(metadata).slice(0, 8);
11
11
  return entries.map(([key, value]) => `${key}: ${String(value)}`).join('\n');
12
12
  }
13
+ function asNonEmptyString(value) {
14
+ return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
15
+ }
16
+ function asObject(value) {
17
+ return value && typeof value === 'object' ? value : undefined;
18
+ }
19
+ function resolveSource(options) {
20
+ const metadata = options.metadata || {};
21
+ return asNonEmptyString(options.source)
22
+ || asNonEmptyString(metadata.source)
23
+ || asNonEmptyString(metadata.platform)
24
+ || asNonEmptyString(metadata.provider);
25
+ }
26
+ function resolveEventId(options) {
27
+ const metadata = options.metadata || {};
28
+ const metadataPayload = asObject(metadata.payload);
29
+ const metadataEvent = asObject(metadata.event);
30
+ const metadataData = asObject(metadata.data);
31
+ return asNonEmptyString(options.eventId)
32
+ || asNonEmptyString(options.dlqId)
33
+ || asNonEmptyString(metadata.eventId)
34
+ || asNonEmptyString(metadata.messageId)
35
+ || asNonEmptyString(metadata.webhookId)
36
+ || asNonEmptyString(metadata.id)
37
+ || asNonEmptyString(metadataPayload?.id)
38
+ || asNonEmptyString(metadataPayload?.eventId)
39
+ || asNonEmptyString(metadataPayload?.request_id)
40
+ || asNonEmptyString(metadataEvent?.id)
41
+ || asNonEmptyString(metadataData?.id);
42
+ }
13
43
  function resolveDestinations(config) {
14
44
  const destinations = [];
15
45
  if (config.slack?.enabled !== false && config.slack?.webhookUrl) {
@@ -29,10 +59,11 @@ function normalizeAlertOptions(options) {
29
59
  return {
30
60
  ...options,
31
61
  dlq: isDlq,
62
+ source: resolveSource(options),
32
63
  title,
33
64
  message,
34
65
  severity,
35
66
  replayLabel,
36
- eventId: options.eventId || options.dlqId,
67
+ eventId: resolveEventId(options),
37
68
  };
38
69
  }
@@ -117,6 +117,22 @@ function createTernControls(config) {
117
117
  },
118
118
  async alert(options = {}) {
119
119
  let replayMeta = {};
120
+ let resolvedSource = options.source;
121
+ let resolvedEventId = options.eventId;
122
+ if (options.dlq && (!resolvedSource || !resolvedEventId)) {
123
+ try {
124
+ const dlqMessages = await this.dlq();
125
+ const matchingMessage = dlqMessages.find((message) => message.dlqId === options.dlqId);
126
+ resolvedSource = resolvedSource || matchingMessage?.platform;
127
+ resolvedEventId = resolvedEventId || matchingMessage?.id;
128
+ }
129
+ catch (error) {
130
+ replayMeta = {
131
+ ...replayMeta,
132
+ dlqLookupError: error.message,
133
+ };
134
+ }
135
+ }
120
136
  if (options.dlq) {
121
137
  if (!options.dlqId || options.dlqId.trim() === '') {
122
138
  throw new Error('[tern] controls.alert() with dlq: true requires dlqId.');
@@ -148,9 +164,12 @@ function createTernControls(config) {
148
164
  : undefined,
149
165
  }, {
150
166
  ...options,
151
- eventId: options.eventId || options.dlqId,
167
+ source: resolvedSource,
168
+ eventId: resolvedEventId || options.dlqId,
152
169
  metadata: {
153
170
  ...(options.metadata || {}),
171
+ source: resolvedSource || options.metadata?.source,
172
+ eventId: resolvedEventId || options.metadata?.eventId,
154
173
  ...replayMeta,
155
174
  },
156
175
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hookflo/tern",
3
- "version": "4.2.3-beta",
3
+ "version": "4.2.5-beta",
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",