@hogsend/engine 0.23.1 → 0.24.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hogsend/engine",
3
- "version": "0.23.1",
3
+ "version": "0.24.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -40,14 +40,14 @@
40
40
  "svix": "^1.95.1",
41
41
  "winston": "^3.19.0",
42
42
  "zod": "^4.4.3",
43
- "@hogsend/core": "^0.23.1",
44
- "@hogsend/db": "^0.23.1",
45
- "@hogsend/email": "^0.23.1",
46
- "@hogsend/plugin-posthog": "^0.23.1",
47
- "@hogsend/plugin-resend": "^0.23.1"
43
+ "@hogsend/core": "^0.24.0",
44
+ "@hogsend/db": "^0.24.0",
45
+ "@hogsend/email": "^0.24.0",
46
+ "@hogsend/plugin-posthog": "^0.24.0",
47
+ "@hogsend/plugin-resend": "^0.24.0"
48
48
  },
49
49
  "optionalDependencies": {
50
- "@hogsend/plugin-postmark": "^0.23.1"
50
+ "@hogsend/plugin-postmark": "^0.24.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^22.15.3",
@@ -21,6 +21,7 @@ import {
21
21
  import type {
22
22
  IfPast,
23
23
  JourneyContext,
24
+ RecentEvent,
24
25
  TimeOfDayBuilder,
25
26
  WaitForEventResult,
26
27
  Weekday,
@@ -451,6 +452,36 @@ export function createJourneyContext(
451
452
  count: total,
452
453
  };
453
454
  },
455
+
456
+ async events({
457
+ userId: targetUserId,
458
+ limit = 50,
459
+ within,
460
+ }): Promise<RecentEvent[]> {
461
+ const conditions = [eq(userEvents.userId, targetUserId)];
462
+ if (within) {
463
+ const since = new Date(Date.now() - durationToMs(within));
464
+ conditions.push(gte(userEvents.occurredAt, since));
465
+ }
466
+ const rows = await db
467
+ .select({
468
+ event: userEvents.event,
469
+ properties: userEvents.properties,
470
+ occurredAt: userEvents.occurredAt,
471
+ })
472
+ .from(userEvents)
473
+ .where(and(...conditions))
474
+ .orderBy(desc(userEvents.occurredAt))
475
+ .limit(limit);
476
+ return rows.map((row) => ({
477
+ event: row.event,
478
+ properties: row.properties ?? null,
479
+ occurredAt:
480
+ row.occurredAt instanceof Date
481
+ ? row.occurredAt.toISOString()
482
+ : String(row.occurredAt),
483
+ }));
484
+ },
454
485
  },
455
486
  };
456
487
  }
@@ -135,7 +135,15 @@ export function registerWebhookSourceRoutes(
135
135
  const rawBody = await c.req.text();
136
136
  const headers = headersToRecord(c.req.raw.headers);
137
137
 
138
- let secret = env[auth.envKey as keyof typeof env] as string | undefined;
138
+ // Engine-declared secrets (presets) resolve from the validated env. A
139
+ // CONSUMER-defined webhook source may name an env var the engine schema
140
+ // doesn't declare (a BYO signature/match source), so fall back to the raw
141
+ // process.env value for it. Both auth branches below gate on truthiness, so
142
+ // an unset/blank secret stays fail-closed (signature → 401) and
143
+ // open-when-unconfigured (match) exactly as before.
144
+ let secret =
145
+ (env[auth.envKey as keyof typeof env] as string | undefined) ??
146
+ process.env[auth.envKey];
139
147
 
140
148
  // For the inbound PostHog source, fall back to the secret minted by
141
149
  // `hogsend connect` (kind="derived" store) when env has none — so an