Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
remove outbox nomenclature from interfaces
Thiago Araujo da Silva25bac21dece8
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex 68125975bc..1b525eba67 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -648,12 +648,19 @@ whenever the pod dies or Redis is down in that window. It's not alert-specific:`alert-event-consumer.ts` is one consumer on the shared registry, and anything else that needsat-least-once delivery of a domain event registers next to it.-**Emitting:** `eventOutboxService.emit(event, tx)`. `tx` is required on purpose.+**Naming:** the outbox is an implementation detail to both sides of it. Emitters depend on+`TEventEmitter` and pass a `TEventInput`; consumers implement `IEventConsumer`, receive `TEvent[]`+(the row minus its lock, attempt, and status columns) and return `TEventConsumerResult` with an+`EventResultStatus`. Names with "outbox" in them (the DAL, queue, cron jobs, metrics,+`EventOutboxStatus`, `TOutboxFlushKey`) describe the mechanism and stay inside the module and its+wiring. A dependency field for the emitter is `eventEmitter`, not `eventOutboxService`.++**Emitting:** `eventEmitter.emit(event, tx)`. `tx` is required on purpose.```tsawait someDAL.transaction(async (tx) => {const request = await approvalRequestDAL.create({ ... }, tx);- await eventOutbox.emit(+ await eventEmitter.emit({eventType: "approval.workflow.request_opened",resourceType: "approval.workflow",@@ -678,7 +685,7 @@ await someDAL.transaction(async (tx) => {**How delivery works:**- **The row owns retry state** (`attempts`, `nextRetryAt`, backoff, terminal `failed`); the consumer- owns what "delivered" means and reports `Delivered` / `Retry` / `Failed` plus `progress` per row.+ owns what "delivered" means and reports `Delivered` / `Retry` / `Failed` plus `progress` per event.Backoff is exponential with jitter from 30s, and `MAX_OUTBOX_ATTEMPTS` puts the last attempt about anhour after the first, because a `failed` row is a notification nobody will receive. To replay failedrows by hand: `status = 'retry', attempts = 0, nextRetryAt = now()`.@@ -695,8 +702,8 @@ await someDAL.transaction(async (tx) => {- **Discovery only looks at consumers registered in this process.** Rows for any other name would sortfirst forever and, past the limit, hide every real key. They wait and show up on the oldest-pendinggauge instead.-- **Don't let one row's failure escape `handle`.** The outbox retries the whole batch when `handle`- throws. Catch per row and report `Retry` for that row alone (see `alert-event-consumer.ts`).+- **Don't let one event's failure escape `handle`.** The outbox retries the whole batch when `handle`+ throws. Catch per event and report `Retry` for that event alone (see `alert-event-consumer.ts`).- **BullMQ owns latency, not correctness.** `attempts: 1` on the flush job is intentional; retry liveson the row. A lost job costs one relay interval.- **The relay is a `setInterval`, not a cron job.** It doesn't need exactly-once (`FOR UPDATE SKIPdiff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex e173a4b6ea..7da4cc81ad 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -2632,7 +2632,7 @@ export const registerRoutes = async (});const identityTokenAuthService = identityTokenAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityTokenAuthDAL,identityAccessTokenDAL,permissionService,@@ -2644,7 +2644,7 @@ export const registerRoutes = async (});const identityUaService = identityUaServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,permissionService,identityUaClientSecretDAL,@@ -2657,7 +2657,7 @@ export const registerRoutes = async (});const identityKubernetesAuthService = identityKubernetesAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityKubernetesAuthDAL,identityAuthTemplateDAL,@@ -2677,7 +2677,7 @@ export const registerRoutes = async (identityAccessTokenService});const identityGcpAuthService = identityGcpAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityGcpAuthDAL,orgDAL,@@ -2690,7 +2690,7 @@ export const registerRoutes = async (});const identityAliCloudAuthService = identityAliCloudAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityAccessTokenDAL,orgDAL,@@ -2703,7 +2703,7 @@ export const registerRoutes = async (});const identityTlsCertAuthService = identityTlsCertAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityAccessTokenDAL,identityTlsCertAuthDAL,@@ -2717,7 +2717,7 @@ export const registerRoutes = async (});const identityAwsAuthService = identityAwsAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityAccessTokenDAL,orgDAL,@@ -2730,7 +2730,7 @@ export const registerRoutes = async (});const identityAzureAuthService = identityAzureAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityAzureAuthDAL,orgDAL,@@ -2743,7 +2743,7 @@ export const registerRoutes = async (});const identityOciAuthService = identityOciAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityAccessTokenDAL,orgDAL,@@ -2771,7 +2771,7 @@ export const registerRoutes = async (});const identityOidcAuthService = identityOidcAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityOidcAuthDAL,identityAuthTemplateDAL,@@ -2786,7 +2786,7 @@ export const registerRoutes = async (});const identityJwtAuthService = identityJwtAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identityJwtAuthDAL,orgDAL,@@ -2800,7 +2800,7 @@ export const registerRoutes = async (});const identitySpiffeAuthService = identitySpiffeAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityDAL,identitySpiffeAuthDAL,orgDAL,@@ -2814,7 +2814,7 @@ export const registerRoutes = async (});const identityLdapAuthService = identityLdapAuthServiceFactory({- eventOutboxService,+ eventEmitter: eventOutboxService,identityLdapAuthDAL,orgDAL,permissionService,diff --git a/backend/src/services/alert/alert-dal.test.ts b/backend/src/services/alert/alert-dal.test.tsindex 32af238c80..731e94bc1b 100644--- a/backend/src/services/alert/alert-dal.test.ts+++ b/backend/src/services/alert/alert-dal.test.ts@@ -120,7 +120,7 @@ describe("alert dal", () => {expect(calls.where).toContainEqual([`${TableName.Alert}.resourceType`, "approval.workflow"]);expect(calls.where).toContainEqual([`${TableName.Alert}.resourceId`, "policy-1"]);expect(calls.where).toContainEqual([`${TableName.Alert}.eventType`, "approval.workflow.request_opened"]);- // Mirrors the cron's filter: the outbox must never pick up a scheduled alert.+ // Mirrors the cron's filter: an event must never trigger a scheduled alert.expect(calls.where).toContainEqual([`${TableName.Alert}.triggerType`, "event"]);expect(calls.where).toContainEqual([`${TableName.Alert}.enabled`, true]);});diff --git a/backend/src/services/alert/alert-event-consumer.test.ts b/backend/src/services/alert/alert-event-consumer.test.tsindex 9863e9173c..a469ebb66b 100644--- a/backend/src/services/alert/alert-event-consumer.test.ts+++ b/backend/src/services/alert/alert-event-consumer.test.ts@@ -1,6 +1,5 @@-import { TEventOutbox } from "@app/db/schemas";import { AlertDispatchOutcome } from "@app/lib/telemetry/metrics";-import { EventOutboxStatus } from "@app/services/event-outbox/event-outbox-types";+import { EventResultStatus, TEvent } from "@app/services/event-outbox/event-outbox-types";import { alertEventConsumerFactory } from "./alert-event-consumer";import { AlertTriggerType } from "./alert-types";@@ -15,10 +14,9 @@ const EVENT_TYPE = "approval.workflow.request_opened";const makeAlert = (id: string) => ({ id, resourceType: "approval.workflow", orgId: ORG_ID }) as never;-const makeEvent = (overrides?: Partial<TEventOutbox>): TEventOutbox =>+const makeEvent = (overrides?: Partial<TEvent>): TEvent =>({id: 1,- consumer: "alert",eventType: EVENT_TYPE,resourceType: "approval.workflow",resourceId: "policy-1",@@ -26,11 +24,9 @@ const makeEvent = (overrides?: Partial<TEventOutbox>): TEventOutbox =>projectId: null,payload: { targetIds: ["req-1"] },occurredAt: new Date(),- status: EventOutboxStatus.Processing,- attempts: 0,progress: null,...overrides- }) as TEventOutbox;+ }) as TEvent;const buildConsumer = (opts?: {alerts?: unknown[];@@ -84,7 +80,7 @@ const buildConsumer = (opts?: {return { consumer, runs, getLookups: () => lookups };};-describe("alert outbox consumer", () => {+describe("alert event consumer", () => {test("subscribes only to event keys a registered provider declares as event-triggered", () => {const { consumer } = buildConsumer();@@ -97,7 +93,7 @@ describe("alert outbox consumer", () => {const [result] = await consumer.handle([makeEvent()]);- expect(result.status).toBe(EventOutboxStatus.Delivered);+ expect(result.status).toBe(EventResultStatus.Delivered);expect(runs[0].targetIds).toEqual(["req-1"]);// The provider sees everything the emitter wrote, not only the ids the consumer validated.expect(runs[0].payload).toEqual({ targetIds: ["req-1"] });@@ -111,7 +107,7 @@ describe("alert outbox consumer", () => {const [result] = await consumer.handle([makeEvent()]);- expect(result.status).toBe(EventOutboxStatus.Delivered);+ expect(result.status).toBe(EventResultStatus.Delivered);expect(runs).toHaveLength(0);});@@ -122,7 +118,7 @@ describe("alert outbox consumer", () => {const [result] = await consumer.handle([makeEvent()]);- expect(result.status).toBe(EventOutboxStatus.Retry);+ expect(result.status).toBe(EventResultStatus.Retry);expect(result.progress).toEqual({ deliveredChannelIds: ["c-1"] });});@@ -140,7 +136,7 @@ describe("alert outbox consumer", () => {const [result] = await consumer.handle([makeEvent({ payload: { targetIds: [] } })]);- expect(result.status).toBe(EventOutboxStatus.Failed);+ expect(result.status).toBe(EventResultStatus.Failed);expect(result.error).toContain("Unreadable alert event payload");});@@ -166,7 +162,7 @@ describe("alert outbox consumer", () => {const [result] = await consumer.handle([makeEvent({ resourceType: "pki.certificate" })]);- expect(result.status).toBe(EventOutboxStatus.Failed);+ expect(result.status).toBe(EventResultStatus.Failed);expect(result.error).toContain("pki.certificate");expect(result.error).toContain("approval.workflow.request_opened");expect(runs).toHaveLength(0);@@ -193,9 +189,9 @@ describe("alert outbox consumer", () => {]);expect(results.map((result) => result.status)).toEqual([- EventOutboxStatus.Delivered,- EventOutboxStatus.Retry,- EventOutboxStatus.Delivered+ EventResultStatus.Delivered,+ EventResultStatus.Retry,+ EventResultStatus.Delivered]);expect(results[1].error).toBe("connection reset");expect(runs.map((run) => run.alertId)).toEqual(["alert-1", "alert-3"]);diff --git a/backend/src/services/alert/alert-event-consumer.ts b/backend/src/services/alert/alert-event-consumer.tsindex ca97c93ed7..a37a6c3eae 100644--- a/backend/src/services/alert/alert-event-consumer.ts+++ b/backend/src/services/alert/alert-event-consumer.ts@@ -1,15 +1,19 @@import { z } from "zod";-import { TEventOutbox } from "@app/db/schemas";import { AlertDispatchOutcome, recordAlertDispatchOutcomeMetric } from "@app/lib/telemetry/metrics";-import { EventOutboxStatus, IEventConsumer, TEventConsumerResult } from "@app/services/event-outbox/event-outbox-types";+import {+ EventResultStatus,+ IEventConsumer,+ TEvent,+ TEventConsumerResult+} from "@app/services/event-outbox/event-outbox-types";import { TAlertDALFactory } from "./alert-dal";import { TAlertEngine } from "./alert-engine";import { TAlertProviderRegistry } from "./alert-provider-registry";import { AlertTriggerType, MAX_TARGET_IDS_PER_EVENT } from "./alert-types";-export const ALERT_OUTBOX_CONSUMER = "alert";+export const ALERT_EVENT_CONSUMER = "alert";// Emitters name targets by id and the provider rehydrates them at delivery. Keeping the payload to// ids is what lets one consumer serve every provider.@@ -38,20 +42,20 @@ export const alertEventConsumerFactory = ({// subscribesTo only sees the event type, so a valid event key on the wrong resourceType gets past it.// Fail here, terminally and naming both, instead of marking the event delivered as "no matching alert".- const $isDeclaredEvent = (event: TEventOutbox): boolean =>+ const $isDeclaredEvent = (event: TEvent): boolean =>Boolean(alertProviderRegistry.get(event.resourceType)?.events.some((declared) => declared.key === event.eventType && declared.triggerType === AlertTriggerType.Event));- const $handleEvent = async (event: TEventOutbox, findAlerts: TAlertLookup): Promise<TEventConsumerResult> => {+ const $handleEvent = async (event: TEvent, findAlerts: TAlertLookup): Promise<TEventConsumerResult> => {const id = String(event.id);if (!$isDeclaredEvent(event)) {return {id,- status: EventOutboxStatus.Failed,+ status: EventResultStatus.Failed,error: `No alert provider for resource type '${event.resourceType}' declares '${event.eventType}' as an event-triggered alert`};}@@ -60,7 +64,7 @@ export const alertEventConsumerFactory = ({if (!payload.success) {return {id,- status: EventOutboxStatus.Failed,+ status: EventResultStatus.Failed,error: `Unreadable alert event payload: ${payload.error.issues.map((issue) => issue.message).join(", ")}`};}@@ -81,7 +85,7 @@ export const alertEventConsumerFactory = ({resourceType: event.resourceType,outcome: AlertDispatchOutcome.NoMatchingAlert});- return { id, status: EventOutboxStatus.Delivered };+ return { id, status: EventResultStatus.Delivered };}const errors: string[] = [];@@ -107,12 +111,12 @@ export const alertEventConsumerFactory = ({const outcome = { id, progress: { deliveredChannelIds: [...delivered] } };if (errors.length > 0) {- return { ...outcome, status: EventOutboxStatus.Retry, error: errors.join("; ") };+ return { ...outcome, status: EventResultStatus.Retry, error: errors.join("; ") };}- return { ...outcome, status: EventOutboxStatus.Delivered };+ return { ...outcome, status: EventResultStatus.Delivered };};- const handle = async (events: TEventOutbox[]): Promise<TEventConsumerResult[]> => {+ const handle = async (events: TEvent[]): Promise<TEventConsumerResult[]> => {const alertsByScope = new Map<string, ReturnType<TAlertLookup>>();const findAlerts: TAlertLookup = (filter) => {const key = `${filter.orgId}|${filter.projectId ?? ""}|${filter.eventType}`;@@ -133,7 +137,7 @@ export const alertEventConsumerFactory = ({} catch (error) {results.push({id: String(event.id),- status: EventOutboxStatus.Retry,+ status: EventResultStatus.Retry,error: error instanceof Error ? error.message : "Unknown error"});}@@ -143,7 +147,7 @@ export const alertEventConsumerFactory = ({};return {- name: ALERT_OUTBOX_CONSUMER,+ name: ALERT_EVENT_CONSUMER,payloadSchema: AlertEventPayloadSchema,subscribesTo,handlediff --git a/backend/src/services/alert/alert-provider-registry.test.ts b/backend/src/services/alert/alert-provider-registry.test.tsindex fa07b8c81d..7f2ef49abd 100644--- a/backend/src/services/alert/alert-provider-registry.test.ts+++ b/backend/src/services/alert/alert-provider-registry.test.ts@@ -66,7 +66,7 @@ describe("alert provider registry", () => {).not.toThrow();});- test("reports only the event-triggered keys, so the outbox consumer ignores scheduled ones", () => {+ test("reports only the event-triggered keys, so the event consumer ignores scheduled ones", () => {const registry = alertProviderRegistryFactory();registry.register(baseProvider({diff --git a/backend/src/services/alert/alert-service.test.ts b/backend/src/services/alert/alert-service.test.tsindex d344a80243..5d7d057335 100644--- a/backend/src/services/alert/alert-service.test.ts+++ b/backend/src/services/alert/alert-service.test.ts@@ -275,7 +275,7 @@ describe("alert service", () => {});// triggerType comes from the provider's event definition, never from the request, so an alert on an- // event-triggered key is invisible to the daily scan and reachable only from the outbox.+ // event-triggered key is invisible to the daily scan and reachable only from an event.test("stores the trigger type its event declares", async () => {const { service, alerts } = buildService();diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.test.tsindex 07c86bb3fb..a048ed59c7 100644--- a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts@@ -252,7 +252,7 @@ describe("identity credential alert provider", () => {expect(byPlatform[0].kind === "auth-method-change" && byPlatform[0].actorLabel).toBe("Infisical");});- // A drifted emit site must surface in the outbox error, not as a notification with blank fields.+ // A drifted emit site must fail the event with a clear error, not send a notification with blank fields.test("findTargetsByIds rejects a payload the emitter contract does not describe", async () => {const provider = buildProvider();await expect(diff --git a/backend/src/services/event-outbox/event-outbox-registry.ts b/backend/src/services/event-outbox/event-outbox-registry.tsindex 60cca823b7..e229967c7e 100644--- a/backend/src/services/event-outbox/event-outbox-registry.ts+++ b/backend/src/services/event-outbox/event-outbox-registry.ts@@ -7,7 +7,7 @@ export const eventOutboxRegistryFactory = () => {const register = (consumer: IEventConsumer) => {if (consumers.has(consumer.name)) {- throw new Error(`Event outbox consumer already registered under the name '${consumer.name}'`);+ throw new Error(`Event consumer already registered under the name '${consumer.name}'`);}consumers.set(consumer.name, consumer);};diff --git a/backend/src/services/event-outbox/event-outbox-service.test.ts b/backend/src/services/event-outbox/event-outbox-service.test.tsindex d53d80a0d7..dd75fa7960 100644--- a/backend/src/services/event-outbox/event-outbox-service.test.ts+++ b/backend/src/services/event-outbox/event-outbox-service.test.ts@@ -6,10 +6,11 @@ import { eventOutboxRegistryFactory } from "./event-outbox-registry";import { eventOutboxServiceFactory } from "./event-outbox-service";import {EventOutboxStatus,+ EventResultStatus,IEventConsumer,MAX_OUTBOX_ATTEMPTS,MAX_OUTBOX_PAYLOAD_BYTES,- TOutboxEvent+ TEventInput} from "./event-outbox-types";const { loggerWarn } = vi.hoisted(() => ({ loggerWarn: vi.fn<(...args: unknown[]) => void>() }));@@ -28,7 +29,7 @@ vi.mock("@app/lib/telemetry/metrics", () => ({const ORG_ID = "11111111-1111-1111-1111-111111111111";-const makeEvent = (overrides?: Partial<TOutboxEvent>): TOutboxEvent => ({+const makeEvent = (overrides?: Partial<TEventInput>): TEventInput => ({eventType: "approval.workflow.request_opened",resourceType: "approval.workflow",resourceId: "policy-1",@@ -223,7 +224,7 @@ describe("event outbox drain", () => {test("commits a delivered result and stops when a claim comes back empty", async () => {const { service, commits } = buildDrain({batches: [[makeRow()]],- handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Delivered }))+ handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Delivered }))});const result = await service.drain({@@ -264,7 +265,7 @@ describe("event outbox drain", () => {test("fails a row terminally once it has used up its attempts", async () => {const { service, commits } = buildDrain({batches: [[makeRow({ attempts: MAX_OUTBOX_ATTEMPTS - 1 })]],- handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Retry })),+ handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Retry })),consumerName: "alert"});@@ -282,8 +283,8 @@ describe("event outbox drain", () => {handle: async (rows) =>rows.map((row) =>Number(row.id) <= 2- ? { id: String(row.id), status: EventOutboxStatus.Delivered }- : { id: String(row.id), status: EventOutboxStatus.Retry, error: "slack 502" }+ ? { id: String(row.id), status: EventResultStatus.Delivered }+ : { id: String(row.id), status: EventResultStatus.Retry, error: "slack 502" })});@@ -301,7 +302,7 @@ describe("event outbox drain", () => {handle: async (rows) =>rows.map((row) => ({id: String(row.id),- status: EventOutboxStatus.Delivered,+ status: EventResultStatus.Delivered,progress: { deliveredChannelIds: [`c-${row.id}`] }}))});@@ -316,7 +317,7 @@ describe("event outbox drain", () => {test("commits under the token the batch was claimed with", async () => {const { service, commits, claimTokens } = buildDrain({batches: [[makeRow()]],- handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Delivered }))+ handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Delivered }))});await service.drain(KEY);@@ -330,7 +331,7 @@ describe("event outbox drain", () => {loggerWarn.mockClear();const { service } = buildDrain({batches: [[makeRow({ id: 1 }), makeRow({ id: 2 })]],- handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Delivered })),+ handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Delivered })),settled: () => 1});@@ -344,7 +345,7 @@ describe("event outbox drain", () => {loggerWarn.mockClear();const { service } = buildDrain({batches: [[makeRow()]],- handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Delivered }))+ handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Delivered }))});await service.drain(KEY);@@ -362,8 +363,7 @@ describe("event outbox drain", () => {batches: [[makeRow({ id: 1 }), makeRow({ id: 2 })]],handle: (rows) =>new Promise((resolve) => {- release = () =>- resolve(rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Delivered as const })));+ release = () => resolve(rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Delivered })));})});@@ -405,7 +405,7 @@ describe("event outbox drain", () => {registry.register(makeConsumer({name: "alert",- handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Delivered }))+ handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Delivered }))}));let commitCalls = 0;@@ -443,7 +443,7 @@ describe("event outbox drain", () => {registry.register(makeConsumer({name: "alert",- handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Delivered }))+ handle: async (rows) => rows.map((row) => ({ id: String(row.id), status: EventResultStatus.Delivered }))}));let commitCalls = 0;diff --git a/backend/src/services/event-outbox/event-outbox-service.ts b/backend/src/services/event-outbox/event-outbox-service.tsindex 3130cc58eb..d6a67d6599 100644--- a/backend/src/services/event-outbox/event-outbox-service.ts+++ b/backend/src/services/event-outbox/event-outbox-service.ts@@ -10,17 +10,18 @@ import { TEventOutboxRegistry } from "./event-outbox-registry";import {computeBackoffMs,DELIVERED_RETENTION_MS,+ EventInputSchema,EventOutboxStatus,+ EventResultStatus,FAILED_RETENTION_MS,IEventConsumer,MAX_BATCHES_PER_FLUSH,MAX_OUTBOX_ATTEMPTS,MAX_OUTBOX_PAYLOAD_BYTES,OUTBOX_CLAIM_BATCH_SIZE,- OutboxEventSchema,STALE_CLAIM_THRESHOLD_MS,TEventConsumerResult,- TOutboxEvent,+ TEventInput,TOutboxFlushKey} from "./event-outbox-types";@@ -74,8 +75,8 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistry// `tx` is required on purpose: the row has to commit with the business write. Nothing here reads the// DB or calls into a consumer, and nothing is caught: a bad event is a bug at the emit site (so 500,// not 400), and swallowing a failed insert would leave the caller with a poisoned transaction.- const emit = async (event: TOutboxEvent, tx: Knex): Promise<void> => {- const parsed = OutboxEventSchema.safeParse(event);+ const emit = async (event: TEventInput, tx: Knex): Promise<void> => {+ const parsed = EventInputSchema.safeParse(event);if (!parsed.success) {throw new InternalServerError({name: "EventOutboxInvalidEvent",@@ -165,16 +166,16 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistry// No result means unaccounted for, not delivered.const result = byId.get(id) ?? {id,- status: EventOutboxStatus.Retry as const,+ status: EventResultStatus.Retry,error: "Consumer returned no result for this event"};const attempts = row.attempts + 1;- let finalStatus: TEventConsumerResult["status"];- if (result.status === EventOutboxStatus.Delivered) {+ let finalStatus: EventOutboxStatus;+ if (result.status === EventResultStatus.Delivered) {finalStatus = EventOutboxStatus.Delivered;delivered.push({ id, progress: result.progress });- } else if (result.status === EventOutboxStatus.Failed || attempts >= MAX_OUTBOX_ATTEMPTS) {+ } else if (result.status === EventResultStatus.Failed || attempts >= MAX_OUTBOX_ATTEMPTS) {finalStatus = EventOutboxStatus.Failed;failed.push({ id, error: result.error });} else {@@ -245,7 +246,7 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistryerror,`event-outbox: consumer '${key.consumer}' threw while handling a batch [resourceType=${key.resourceType}] [resourceId=${key.resourceId}]`);- return claimed.map((row) => ({ id: String(row.id), status: EventOutboxStatus.Retry as const, error: message }));+ return claimed.map((row) => ({ id: String(row.id), status: EventResultStatus.Retry, error: message }));} finally {clearInterval(heartbeat);}@@ -335,5 +336,3 @@ export const eventOutboxServiceFactory = ({ eventOutboxDAL, eventOutboxRegistryreturn { emit, drain, sweepStaleClaims, pruneTerminalRows };};--export type TEventOutboxEmitter = Pick<TEventOutboxServiceFactory, "emit">;diff --git a/backend/src/services/event-outbox/event-outbox-types.ts b/backend/src/services/event-outbox/event-outbox-types.tsindex 3d1796cf8c..939f86f02b 100644--- a/backend/src/services/event-outbox/event-outbox-types.ts+++ b/backend/src/services/event-outbox/event-outbox-types.ts@@ -1,3 +1,4 @@+import { Knex } from "knex";import RE2 from "re2";import { z } from "zod";@@ -49,7 +50,7 @@ const keySchema = z"Must be lowercase and dot-namespaced, e.g. 'pki.certificate.issued'");-export const OutboxEventSchema = z.object({+export const EventInputSchema = z.object({eventType: keySchema,resourceType: keySchema,resourceId: z.string().trim().min(1).max(MAX_OUTBOX_KEY_LENGTH),@@ -60,11 +61,27 @@ export const OutboxEventSchema = z.object({occurredAt: z.date().optional()});-export type TOutboxEvent = z.input<typeof OutboxEventSchema>;+export type TEventInput = z.input<typeof EventInputSchema>;++export type TEventEmitter = {+ emit: (event: TEventInput, tx: Knex) => Promise<void>;+};++// What a consumer sees. Lock, attempt, and status columns are the outbox's business, not the consumer's.+export type TEvent = Pick<+ TEventOutbox,+ "id" | "eventType" | "resourceType" | "resourceId" | "orgId" | "projectId" | "payload" | "progress" | "occurredAt"+>;++export enum EventResultStatus {+ Delivered = "delivered",+ Retry = "retry",+ Failed = "failed"+}export type TEventConsumerResult = {id: string;- status: EventOutboxStatus.Delivered | EventOutboxStatus.Retry | EventOutboxStatus.Failed;+ status: EventResultStatus;error?: string;// Opaque to the outbox; handed back on the next attempt so a retry can skip what already landed.progress?: Record<string, unknown> | null;@@ -89,5 +106,5 @@ export interface IEventConsumer<TPayload = unknown> {subscribesTo(eventType: string): boolean;// Events for a single (resourceType, resourceId), in id order. Must return one result per event.- handle(events: TEventOutbox[]): Promise<TEventConsumerResult[]>;+ handle(events: TEvent[]): Promise<TEventConsumerResult[]>;}diff --git a/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts b/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.tsindex aae638799d..46aa48a175 100644--- a/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts+++ b/backend/src/services/identity-alicloud-auth/identity-alicloud-auth-service.ts@@ -33,7 +33,7 @@ import {authAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -73,7 +73,7 @@ type TIdentityAliCloudAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityAliCloudAuthServiceFactory = ReturnType<typeof identityAliCloudAuthServiceFactory>;@@ -88,7 +88,7 @@ export const identityAliCloudAuthServiceFactory = ({permissionService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityAliCloudAuthServiceFactoryDep) => {const login = async ({ identityId, organizationSlug, ...params }: TLoginAliCloudAuthDTO) => {const authMetricStartTime = performance.now();@@ -352,7 +352,7 @@ export const identityAliCloudAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.ALICLOUD_AUTH,@@ -472,7 +472,7 @@ export const identityAliCloudAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.ALICLOUD_AUTH,@@ -628,7 +628,7 @@ export const identityAliCloudAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.ALICLOUD_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.ALICLOUD_AUTH,diff --git a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts b/backend/src/services/identity-aws-auth/identity-aws-auth-service.tsindex 1bef75295e..c78dbf780d 100644--- a/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts+++ b/backend/src/services/identity-aws-auth/identity-aws-auth-service.ts@@ -34,7 +34,7 @@ import {authAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -73,7 +73,7 @@ type TIdentityAwsAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityAwsAuthServiceFactory = ReturnType<typeof identityAwsAuthServiceFactory>;@@ -122,7 +122,7 @@ export const identityAwsAuthServiceFactory = ({permissionService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityAwsAuthServiceFactoryDep) => {const login = async ({identityId,@@ -452,7 +452,7 @@ export const identityAwsAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.AWS_AUTH,@@ -575,7 +575,7 @@ export const identityAwsAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.AWS_AUTH,@@ -730,7 +730,7 @@ export const identityAwsAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.AWS_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.AWS_AUTH,diff --git a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts b/backend/src/services/identity-azure-auth/identity-azure-auth-service.tsindex 7b648e0d44..1d640a7400 100644--- a/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts+++ b/backend/src/services/identity-azure-auth/identity-azure-auth-service.ts@@ -29,7 +29,7 @@ import {authAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -69,7 +69,7 @@ type TIdentityAzureAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityAzureAuthServiceFactory = ReturnType<typeof identityAzureAuthServiceFactory>;@@ -84,7 +84,7 @@ export const identityAzureAuthServiceFactory = ({licenseService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityAzureAuthServiceFactoryDep) => {const login = async ({ identityId, jwt: azureJwt, organizationSlug }: TLoginAzureAuthDTO) => {const authMetricStartTime = performance.now();@@ -353,7 +353,7 @@ export const identityAzureAuthServiceFactory = ({);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.AZURE_AUTH,@@ -476,7 +476,7 @@ export const identityAzureAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.AZURE_AUTH,@@ -632,7 +632,7 @@ export const identityAzureAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.AZURE_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.AZURE_AUTH,diff --git a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.tsindex 3d6f01acd3..cfa08cc0d8 100644--- a/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts+++ b/backend/src/services/identity-gcp-auth/identity-gcp-auth-service.ts@@ -29,7 +29,7 @@ import {authAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -67,7 +67,7 @@ type TIdentityGcpAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityGcpAuthServiceFactory = ReturnType<typeof identityGcpAuthServiceFactory>;@@ -82,7 +82,7 @@ export const identityGcpAuthServiceFactory = ({licenseService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityGcpAuthServiceFactoryDep) => {const login = async ({ identityId, jwt: gcpJwt, organizationSlug }: TLoginGcpAuthDTO) => {const authMetricStartTime = performance.now();@@ -398,7 +398,7 @@ export const identityGcpAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.GCP_AUTH,@@ -523,7 +523,7 @@ export const identityGcpAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.GCP_AUTH,@@ -679,7 +679,7 @@ export const identityGcpAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.GCP_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.GCP_AUTH,diff --git a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.tsindex e071c5b933..7e0b987b0c 100644--- a/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts+++ b/backend/src/services/identity-jwt-auth/identity-jwt-auth-service.ts@@ -41,7 +41,7 @@ import {} from "@app/lib/telemetry/metrics";import { getValueByDot } from "@app/lib/template/dot-access";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -82,7 +82,7 @@ type TIdentityJwtAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityJwtAuthServiceFactory = ReturnType<typeof identityJwtAuthServiceFactory>;@@ -98,7 +98,7 @@ export const identityJwtAuthServiceFactory = ({kmsService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityJwtAuthServiceFactoryDep) => {const login = async ({ identityId, jwt: jwtValue, organizationSlug }: TLoginJwtAuthDTO) => {const authMetricStartTime = performance.now();@@ -542,7 +542,7 @@ export const identityJwtAuthServiceFactory = ({);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.JWT_AUTH,@@ -698,7 +698,7 @@ export const identityJwtAuthServiceFactory = ({const updatedJwtAuth = await identityJwtAuthDAL.transaction(async (tx) => {const doc = await identityJwtAuthDAL.updateById(identityJwtAuth.id, updateQuery, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.JWT_AUTH,@@ -881,7 +881,7 @@ export const identityJwtAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.JWT_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.JWT_AUTH,diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.tsindex b2e7634d03..aa9ba09567 100644--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.test.ts@@ -141,7 +141,7 @@ const createService = ({revokeTokensForIdentityAuthMethod: vi.fn(),invalidateTrustedIpsCache: vi.fn()},- eventOutboxService: { emit: vi.fn() }+ eventEmitter: { emit: vi.fn() }} as unknown as Parameters<typeof identityKubernetesAuthServiceFactory>[0]);return { service, identityKubernetesAuthDAL };diff --git a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.tsindex d7c56f4df9..359beb0615 100644--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts@@ -62,7 +62,7 @@ import {} from "@app/lib/telemetry/metrics";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";import { getSharedHttpsAgent, safeRequest } from "@app/lib/validator/safe-request";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -132,7 +132,7 @@ type TIdentityKubernetesAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityKubernetesAuthServiceFactory = ReturnType<typeof identityKubernetesAuthServiceFactory>;@@ -157,7 +157,7 @@ export const identityKubernetesAuthServiceFactory = ({gatewayPoolDAL,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityKubernetesAuthServiceFactoryDep) => {const $gatewayProxyWrapper = async <T>(inputs: {@@ -1144,7 +1144,7 @@ export const identityKubernetesAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.KUBERNETES_AUTH,@@ -1617,7 +1617,7 @@ export const identityKubernetesAuthServiceFactory = ({const updatedKubernetesAuth = await identityKubernetesAuthDAL.transaction(async (tx) => {const doc = await identityKubernetesAuthDAL.updateById(identityKubernetesAuth.id, updateQuery, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.KUBERNETES_AUTH,@@ -1829,7 +1829,7 @@ export const identityKubernetesAuthServiceFactory = ({const deletedKubernetesAuth = await identityKubernetesAuthDAL.delete({ identityId }, tx);await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.KUBERNETES_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.KUBERNETES_AUTH,diff --git a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.tsindex b10743cf2c..2e90d7c693 100644--- a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts+++ b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts@@ -40,7 +40,7 @@ import {recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -101,7 +101,7 @@ type TIdentityLdapAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityLdapAuthServiceFactory = ReturnType<typeof identityLdapAuthServiceFactory>;@@ -118,7 +118,7 @@ export const identityLdapAuthServiceFactory = ({keyStore,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityLdapAuthServiceFactoryDep) => {const getLdapConfig = async (identityId: string) => {const identity = await identityDAL.findOne({ id: identityId });@@ -528,7 +528,7 @@ export const identityLdapAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.LDAP_AUTH,@@ -774,7 +774,7 @@ export const identityLdapAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.LDAP_AUTH,@@ -942,7 +942,7 @@ export const identityLdapAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.LDAP_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.LDAP_AUTH,diff --git a/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts b/backend/src/services/identity-oci-auth/identity-oci-auth-service.tsindex 7f81a3f125..23ea38fb2f 100644--- a/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts+++ b/backend/src/services/identity-oci-auth/identity-oci-auth-service.ts@@ -34,7 +34,7 @@ import {authAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -71,7 +71,7 @@ type TIdentityOciAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityOciAuthServiceFactory = ReturnType<typeof identityOciAuthServiceFactory>;@@ -86,7 +86,7 @@ export const identityOciAuthServiceFactory = ({permissionService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityOciAuthServiceFactoryDep) => {const login = async ({ identityId, headers, userOcid, organizationSlug }: TLoginOciAuthDTO) => {const authMetricStartTime = performance.now();@@ -366,7 +366,7 @@ export const identityOciAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.OCI_AUTH,@@ -488,7 +488,7 @@ export const identityOciAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.OCI_AUTH,@@ -644,7 +644,7 @@ export const identityOciAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.OCI_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.OCI_AUTH,diff --git a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.tsindex 6fdb671103..0cdca953eb 100644--- a/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts+++ b/backend/src/services/identity-oidc-auth/identity-oidc-auth-service.ts@@ -51,7 +51,7 @@ import {} from "@app/lib/telemetry/metrics";import { getValueByDot } from "@app/lib/template/dot-access";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -92,7 +92,7 @@ type TIdentityOidcAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityOidcAuthServiceFactory = ReturnType<typeof identityOidcAuthServiceFactory>;@@ -109,7 +109,7 @@ export const identityOidcAuthServiceFactory = ({kmsService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityOidcAuthServiceFactoryDep) => {const login = async ({ identityId, jwt: oidcJwt, organizationSlug }: TLoginOidcAuthDTO) => {const authMetricStartTime = performance.now();@@ -775,7 +775,7 @@ export const identityOidcAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.OIDC_AUTH,@@ -993,7 +993,7 @@ export const identityOidcAuthServiceFactory = ({const updatedOidcAuth = await identityOidcAuthDAL.transaction(async (tx) => {const doc = await identityOidcAuthDAL.updateById(identityOidcAuth.id, updateQuery, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.OIDC_AUTH,@@ -1178,7 +1178,7 @@ export const identityOidcAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.OIDC_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.OIDC_AUTH,diff --git a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.tsindex c33a80ab2c..f06fbc151c 100644--- a/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts+++ b/backend/src/services/identity-spiffe-auth/identity-spiffe-auth-service.ts@@ -39,7 +39,7 @@ import {recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -88,7 +88,7 @@ type TIdentitySpiffeAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentitySpiffeAuthServiceFactory = ReturnType<typeof identitySpiffeAuthServiceFactory>;@@ -148,7 +148,7 @@ export const identitySpiffeAuthServiceFactory = ({kmsService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentitySpiffeAuthServiceFactoryDep) => {type TFlattenedTrustBundle = {configurationType: string;@@ -620,7 +620,7 @@ export const identitySpiffeAuthServiceFactory = ({);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.SPIFFE_AUTH,@@ -778,7 +778,7 @@ export const identitySpiffeAuthServiceFactory = ({const updatedSpiffeAuth = await identitySpiffeAuthDAL.transaction(async (tx) => {const doc = await identitySpiffeAuthDAL.updateById(identitySpiffeAuth.id, updateQuery, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.SPIFFE_AUTH,@@ -970,7 +970,7 @@ export const identitySpiffeAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.SPIFFE_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.SPIFFE_AUTH,diff --git a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.tsindex 145e09aeb9..7febaf7117 100644--- a/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts+++ b/backend/src/services/identity-tls-cert-auth/identity-tls-cert-auth-service.ts@@ -32,7 +32,7 @@ import {authAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -190,7 +190,7 @@ type TIdentityTlsCertAuthServiceFactoryDep = {TIdentityAccessTokenServiceFactory,"issueIdentityAccessToken" | "revokeTokensForIdentityAuthMethod" | "invalidateTrustedIpsCache">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export const identityTlsCertAuthServiceFactory = ({@@ -204,7 +204,7 @@ export const identityTlsCertAuthServiceFactory = ({kmsService,orgDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityTlsCertAuthServiceFactoryDep): TIdentityTlsCertAuthServiceFactory => {const login: TIdentityTlsCertAuthServiceFactory["login"] = async ({identityId,@@ -591,7 +591,7 @@ export const identityTlsCertAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TLS_CERT_AUTH,@@ -731,7 +731,7 @@ export const identityTlsCertAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TLS_CERT_AUTH,@@ -900,7 +900,7 @@ export const identityTlsCertAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.TLS_CERT_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TLS_CERT_AUTH,diff --git a/backend/src/services/identity-token-auth/identity-token-auth-service.ts b/backend/src/services/identity-token-auth/identity-token-auth-service.tsindex 091410820f..5576ae3959 100644--- a/backend/src/services/identity-token-auth/identity-token-auth-service.ts+++ b/backend/src/services/identity-token-auth/identity-token-auth-service.ts@@ -26,7 +26,7 @@ import {import { extractIPDetails, isValidIpOrCidr, TIp } from "@app/lib/ip";import { requestMemoKeys } from "@app/lib/request-context/memo-keys";import { requestMemoize } from "@app/lib/request-context/request-memoizer";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -74,7 +74,7 @@ type TIdentityTokenAuthServiceFactoryDep = {permissionService: Pick<TPermissionServiceFactory, "getOrgPermission" | "getProjectPermission">;licenseService: Pick<TLicenseServiceFactory, "getPlan">;orgDAL: Pick<TOrgDALFactory, "findById" | "findOne" | "findEffectiveOrgMembership">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityTokenAuthServiceFactory = ReturnType<typeof identityTokenAuthServiceFactory>;@@ -88,7 +88,7 @@ export const identityTokenAuthServiceFactory = ({permissionService,licenseService,orgDAL,- eventOutboxService+ eventEmitter}: TIdentityTokenAuthServiceFactoryDep) => {const attachTokenAuth = async ({identityId,@@ -185,7 +185,7 @@ export const identityTokenAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TOKEN_AUTH,@@ -304,7 +304,7 @@ export const identityTokenAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TOKEN_AUTH,@@ -464,7 +464,7 @@ export const identityTokenAuthServiceFactory = ({await identityAccessTokenDAL.delete({ identityId, authMethod: IdentityAuthMethod.TOKEN_AUTH }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TOKEN_AUTH,@@ -648,7 +648,7 @@ export const identityTokenAuthServiceFactory = ({persistToPg: { tx, name }});await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TOKEN_AUTH,@@ -897,7 +897,7 @@ export const identityTokenAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.TOKEN_AUTH,@@ -984,7 +984,7 @@ export const identityTokenAuthServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityOrgMembership,authMethod: IdentityAuthMethod.TOKEN_AUTH,diff --git a/backend/src/services/identity-ua/identity-ua-service.ts b/backend/src/services/identity-ua/identity-ua-service.tsindex c1f151da46..a045555c54 100644--- a/backend/src/services/identity-ua/identity-ua-service.ts+++ b/backend/src/services/identity-ua/identity-ua-service.ts@@ -32,7 +32,7 @@ import {authAttemptCounter,recordAuthAttemptMetric} from "@app/lib/telemetry/metrics";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";import {emitIdentityAuthMethodChanged,IdentityAuthMethodChange@@ -91,7 +91,7 @@ type TIdentityUaServiceFactoryDep = {| "sortedSetMembersPrimary"| "acquireLock">;- eventOutboxService: TEventOutboxEmitter;+ eventEmitter: TEventEmitter;};export type TIdentityUaServiceFactory = ReturnType<typeof identityUaServiceFactory>;@@ -109,7 +109,7 @@ export const identityUaServiceFactory = ({keyStore,identityDAL,identityAccessTokenService,- eventOutboxService+ eventEmitter}: TIdentityUaServiceFactoryDep) => {const login = async ({ clientId, clientSecret, ip, organizationSlug }: TLoginUaDTO) => {const authMetricStartTime = performance.now();@@ -553,7 +553,7 @@ export const identityUaServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.UNIVERSAL_AUTH,@@ -708,7 +708,7 @@ export const identityUaServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.UNIVERSAL_AUTH,@@ -862,7 +862,7 @@ export const identityUaServiceFactory = ({const revokedIdentityUniversalAuth = await identityUaDAL.transaction(async (tx) => {const deletedUniversalAuth = await identityUaDAL.delete({ identityId }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.UNIVERSAL_AUTH,@@ -999,7 +999,7 @@ export const identityUaServiceFactory = ({tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.UNIVERSAL_AUTH,@@ -1307,7 +1307,7 @@ export const identityUaServiceFactory = ({const updatedClientSecret = await identityUaDAL.transaction(async (tx) => {const doc = await identityUaClientSecretDAL.updateById(clientSecretId, { isClientSecretRevoked: true }, tx);await emitIdentityAuthMethodChanged(- eventOutboxService,+ eventEmitter,{membership: identityMembershipOrg,authMethod: IdentityAuthMethod.UNIVERSAL_AUTH,diff --git a/backend/src/services/identity/identity-auth-method-events.ts b/backend/src/services/identity/identity-auth-method-events.tsindex 5f152f443f..04200c0024 100644--- a/backend/src/services/identity/identity-auth-method-events.ts+++ b/backend/src/services/identity/identity-auth-method-events.ts@@ -3,7 +3,7 @@ import { z } from "zod";import { IdentityAuthMethod } from "@app/db/schemas";import { ActorType } from "@app/services/auth/auth-type";-import { TEventOutboxEmitter } from "@app/services/event-outbox/event-outbox-service";+import { TEventEmitter } from "@app/services/event-outbox/event-outbox-types";export const IDENTITY_AUTHENTICATION_RESOURCE_TYPE = "identity.authentication";export const IDENTITY_AUTH_METHOD_CHANGED_EVENT = "identity.authentication.auth-method-changed";@@ -37,11 +37,11 @@ export type TIdentityAuthMethodChangeInput = {};export const emitIdentityAuthMethodChanged = (- eventOutbox: TEventOutboxEmitter,+ eventEmitter: TEventEmitter,{ membership, authMethod, change, actor, actorId, credential }: TIdentityAuthMethodChangeInput,tx: Knex): Promise<void> =>- eventOutbox.emit(+ eventEmitter.emit({eventType: IDENTITY_AUTH_METHOD_CHANGED_EVENT,resourceType: IDENTITY_AUTHENTICATION_RESOURCE_TYPE,