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
fix: move delegated request statusReason into details and record providerType
adilsonf2924c21694b
diff --git a/backend/src/services/delegated-approval/delegated-approval-request-dal.ts b/backend/src/services/delegated-approval/delegated-approval-request-dal.tsindex b03168321c..c9707fcebd 100644--- a/backend/src/services/delegated-approval/delegated-approval-request-dal.ts+++ b/backend/src/services/delegated-approval/delegated-approval-request-dal.ts@@ -1,7 +1,12 @@+import { Knex } from "knex";+import { TDbClient } from "@app/db";-import { TableName } from "@app/db/schemas";+import { TableName, TDelegatedApprovalRequests, TDelegatedApprovalRequestsUpdate } from "@app/db/schemas";+import { DatabaseError } from "@app/lib/errors";import { ormify } from "@app/lib/knex";+import { TDelegatedApprovalRequestDetails } from "./delegated-approval-schemas";+export type TDelegatedApprovalRequestDALFactory = ReturnType<typeof delegatedApprovalRequestDALFactory>;export const delegatedApprovalRequestDALFactory = (db: TDbClient) => {@@ -9,5 +14,28 @@ export const delegatedApprovalRequestDALFactory = (db: TDbClient) => {const primaryNode = () => db.primaryNode();- return { ...orm, primaryNode };+ const updateWithDetails = async (+ filter: Partial<Pick<TDelegatedApprovalRequests, "id" | "requestId" | "status" | "dispatchEventId">>,+ {+ details,+ ...columns+ }: Omit<TDelegatedApprovalRequestsUpdate, "details"> & { details?: Partial<TDelegatedApprovalRequestDetails> },+ tx?: Knex+ ) => {+ try {+ const patch = details ? JSON.stringify(details) : "{}";+ const rows = await (tx || db)(TableName.DelegatedApprovalRequests)+ .where(filter)+ .update({+ ...columns,+ ...(patch !== "{}" ? { details: db.raw(`COALESCE("details", '{}'::jsonb) || ?::jsonb`, [patch]) } : {})+ })+ .returning("*");+ return rows as TDelegatedApprovalRequests[];+ } catch (error) {+ throw new DatabaseError({ error, name: "DelegatedApprovalRequest: updateWithDetails" });+ }+ };++ return { ...orm, primaryNode, updateWithDetails };};diff --git a/backend/src/services/delegated-approval/delegated-approval-request-fns.ts b/backend/src/services/delegated-approval/delegated-approval-request-fns.tsnew file mode 100644index 0000000000..cd059b4bae--- /dev/null+++ b/backend/src/services/delegated-approval/delegated-approval-request-fns.ts@@ -0,0 +1,32 @@+import { TDelegatedApprovalRequests } from "@app/db/schemas";+import { logger } from "@app/lib/logger";++import { DelegatedApprovalPolicyType, DelegatedApprovalRequestStatus } from "./delegated-approval-enums";+import { DelegatedApprovalRequestDetailsSchema } from "./delegated-approval-schemas";+import { TDelegatedApprovalRequest, TDelegatedApprovalRequestDetails } from "./delegated-approval-types";+import { DELEGATED_APPROVAL_STATUS_REASON_MAX_CHARS } from "./dispatch/delegated-approval-dispatch-constants";++export const toDelegatedApprovalStatusReason = (reason: string) =>+ reason.slice(0, DELEGATED_APPROVAL_STATUS_REASON_MAX_CHARS);++// A row whose details cannot be read is served as if it had none, so one bad row cannot take the+// request list down with it.+export const parseDelegatedApprovalRequestDetails = (+ row: Pick<TDelegatedApprovalRequests, "id" | "details">+): TDelegatedApprovalRequestDetails => {+ const parsed = DelegatedApprovalRequestDetailsSchema.safeParse(row.details ?? {});+ if (parsed.success) return parsed.data;++ logger.warn(+ { issues: parsed.error.issues },+ `Delegated approval request has unreadable details, treating them as empty [delegatedRequestId=${row.id}]`+ );+ return {};+};++export const toDelegatedApprovalRequest = (row: TDelegatedApprovalRequests): TDelegatedApprovalRequest => ({+ ...row,+ providerType: row.providerType as DelegatedApprovalPolicyType,+ status: row.status as DelegatedApprovalRequestStatus,+ details: parseDelegatedApprovalRequestDetails(row)+});diff --git a/backend/src/services/delegated-approval/delegated-approval-schemas.ts b/backend/src/services/delegated-approval/delegated-approval-schemas.tsindex c1245e60d7..0005dbbe68 100644--- a/backend/src/services/delegated-approval/delegated-approval-schemas.ts+++ b/backend/src/services/delegated-approval/delegated-approval-schemas.ts@@ -9,6 +9,14 @@ export const DelegatedApprovalSchema = z.object({connectionId: z.string().uuid().describe("The ID of the App Connection used to reach the delegated approval system.")});+// Shape of the `details` column. Bounds are enforced where values enter (toDelegatedApprovalStatusReason), so a+// stored row always reads back.+export const DelegatedApprovalRequestDetailsSchema = z.object({+ statusReason: z.string().nullable().optional()+});++export type TDelegatedApprovalRequestDetails = z.infer<typeof DelegatedApprovalRequestDetailsSchema>;+export const DelegatedApprovalRequestSchema = z.object({status: z.nativeEnum(DelegatedApprovalRequestStatus)diff --git a/backend/src/services/delegated-approval/delegated-approval-service.test.ts b/backend/src/services/delegated-approval/delegated-approval-service.test.tsindex 2987a7128f..dd65cd6f24 100644--- a/backend/src/services/delegated-approval/delegated-approval-service.test.ts+++ b/backend/src/services/delegated-approval/delegated-approval-service.test.ts@@ -11,6 +11,7 @@ const failedRequest = {id: "delegated-1",requestId: "req-1",status: DelegatedApprovalRequestStatus.FailedDispatch,+ details: { statusReason: "ServiceNow could not be reached." },dispatchEventId: "44444444-4444-4444-8444-444444444444"};const serviceNowPolicy = {@@ -37,7 +38,7 @@ const createService = ({} = {}) => {const emit = vi.fn().mockResolvedValue(undefined);const findOne = vi.fn().mockResolvedValue(delegatedRequest);- const create = vi.fn().mockImplementation(async (row: { requestId: string; status: string }) => ({+ const create = vi.fn().mockImplementation(async (row: { requestId: string; status: string; details: object }) => ({id: "delegated-1",...row}));@@ -72,13 +73,22 @@ describe("delegatedApprovalService.createRequest", () => {test("records the dispatch event in the same transaction as the request row", async () => {const { service, emit, create } = createService();- const request = await service.createRequest({ approvalRequest: pendingApprovalRequest as never }, TX);+ const request = await service.createRequest(+ { approvalRequest: pendingApprovalRequest as never, delegatedPolicy: serviceNowPolicy },+ TX+ );- expect(request).toMatchObject({ id: "delegated-1", status: DelegatedApprovalRequestStatus.PendingDispatch });+ expect(request).toMatchObject({+ id: "delegated-1",+ providerType: DelegatedApprovalPolicyType.ServiceNow,+ status: DelegatedApprovalRequestStatus.PendingDispatch+ });expect(create).toHaveBeenCalledWith({requestId: "req-1",+ providerType: DelegatedApprovalPolicyType.ServiceNow,status: DelegatedApprovalRequestStatus.PendingDispatch,+ details: {},dispatchEventId: expect.any(String) as string},TXdiff --git a/backend/src/services/delegated-approval/delegated-approval-service.ts b/backend/src/services/delegated-approval/delegated-approval-service.tsindex 5f752d6949..1175b95e63 100644--- a/backend/src/services/delegated-approval/delegated-approval-service.ts+++ b/backend/src/services/delegated-approval/delegated-approval-service.ts@@ -20,14 +20,13 @@ import { assertPolicyTypeSupportsDelegatedApproval, listDelegatedApprovalOptionsimport { DELEGATED_APPROVAL_CONNECTION_MAP, DELEGATED_APPROVAL_NAME_MAP } from "./delegated-approval-maps";import { TDelegatedApprovalPolicyDALFactory } from "./delegated-approval-policy-dal";import { TDelegatedApprovalRequestDALFactory } from "./delegated-approval-request-dal";+import { toDelegatedApprovalRequest } from "./delegated-approval-request-fns";import {TCreateDelegatedApprovalPolicyDTO,TCreateDelegatedApprovalRequestDTO,TDelegatedApprovalPolicy,- TDelegatedApprovalRequest,TRetryDelegatedApprovalRequestDispatchDTO,TUpdateDelegatedApprovalPolicyDTO,- TUpdateDelegatedApprovalRequestDTO,TValidateDelegatedApprovalConnectionDTO} from "./delegated-approval-types";@@ -151,21 +150,27 @@ export const delegatedApprovalServiceFactory = ({return (policy as TDelegatedApprovalPolicy | undefined) ?? null;};- const createRequest = async ({ approvalRequest }: TCreateDelegatedApprovalRequestDTO, tx?: Knex) => {+ const createRequest = async ({ approvalRequest, delegatedPolicy }: TCreateDelegatedApprovalRequestDTO, tx?: Knex) => {assertPolicyTypeSupportsDelegatedApproval(approvalRequest.type);const dispatchEventId = crypto.randomUUID();try {- const request = (await delegatedApprovalRequestDAL.create(- { requestId: approvalRequest.id, status: DelegatedApprovalRequestStatus.PendingDispatch, dispatchEventId },+ const request = await delegatedApprovalRequestDAL.create(+ {+ requestId: approvalRequest.id,+ providerType: delegatedPolicy.type,+ status: DelegatedApprovalRequestStatus.PendingDispatch,+ details: {},+ dispatchEventId+ },tx- )) as TDelegatedApprovalRequest;+ );await emitDelegatedApprovalDispatchRequested(eventEmitter,{ delegatedRequestId: request.id, dispatchEventId },tx);- return request;+ return toDelegatedApprovalRequest(request);} catch (err) {if (hasPostgresErrorCode(err, DatabaseErrorCode.UniqueViolation)) {throw new BadRequestError({@@ -181,13 +186,13 @@ export const delegatedApprovalServiceFactory = ({const getRequestByRequestId = async (requestId: string, tx?: Knex) => {const request = await delegatedApprovalRequestDAL.findOne({ requestId }, tx);- return (request as TDelegatedApprovalRequest | undefined) ?? null;+ return request ? toDelegatedApprovalRequest(request) : null;};const getRequestsByRequestIds = async (requestIds: string[], tx?: Knex) => {if (!requestIds.length) return [];const requests = await delegatedApprovalRequestDAL.find({ $in: { requestId: requestIds } }, { tx });- return requests as TDelegatedApprovalRequest[];+ return requests.map(toDelegatedApprovalRequest);};const retryDispatch = async ({ approvalRequest }: TRetryDelegatedApprovalRequestDispatchDTO) => {@@ -237,38 +242,15 @@ export const delegatedApprovalServiceFactory = ({{ delegatedRequestId: resent.id, dispatchEventId },tx);- return resent as TDelegatedApprovalRequest;+ return toDelegatedApprovalRequest(resent);});return { delegatedRequest: resentRequest, delegatedPolicy };};- const updateRequest = async ({ requestId, status, statusReason }: TUpdateDelegatedApprovalRequestDTO, tx?: Knex) => {- const patch = {- ...(status !== undefined && { status }),- ...(statusReason !== undefined && { statusReason })- };-- if (Object.keys(patch).length === 0) {- const existing = await delegatedApprovalRequestDAL.findOne({ requestId }, tx);- if (!existing) {- throw new NotFoundError({- message: `Approval request with ID '${requestId}' has no delegated approval request`- });- }- return existing as TDelegatedApprovalRequest;- }-- const [request] = await delegatedApprovalRequestDAL.update({ requestId }, patch, tx);- if (!request) {- throw new NotFoundError({ message: `Approval request with ID '${requestId}' has no delegated approval request` });- }- return request as TDelegatedApprovalRequest;- };-const deleteRequestByRequestId = async (requestId: string, tx?: Knex) => {const [request] = await delegatedApprovalRequestDAL.delete({ requestId }, tx);- return (request as TDelegatedApprovalRequest | undefined) ?? null;+ return request ? toDelegatedApprovalRequest(request) : null;};return {@@ -282,7 +264,6 @@ export const delegatedApprovalServiceFactory = ({getRequestByRequestId,getRequestsByRequestIds,retryDispatch,- updateRequest,deleteRequestByRequestId};};diff --git a/backend/src/services/delegated-approval/delegated-approval-types.ts b/backend/src/services/delegated-approval/delegated-approval-types.tsindex c051fc5c25..cd1b50ba31 100644--- a/backend/src/services/delegated-approval/delegated-approval-types.ts+++ b/backend/src/services/delegated-approval/delegated-approval-types.ts@@ -2,6 +2,7 @@ import { TApprovalRequests, TDelegatedApprovalPolicies, TDelegatedApprovalRequesimport { AppConnection } from "@app/services/app-connection/app-connection-enums";import { DelegatedApprovalPolicyType, DelegatedApprovalRequestStatus } from "./delegated-approval-enums";+import { TDelegatedApprovalRequestDetails } from "./delegated-approval-schemas";export type TDelegatedApprovalListItem = {name: string;@@ -13,8 +14,12 @@ export type TDelegatedApprovalPolicy = Omit<TDelegatedApprovalPolicies, "type">type: DelegatedApprovalPolicyType;};-export type TDelegatedApprovalRequest = Omit<TDelegatedApprovalRequests, "status"> & {+export type { TDelegatedApprovalRequestDetails };++export type TDelegatedApprovalRequest = Omit<TDelegatedApprovalRequests, "providerType" | "status" | "details"> & {+ providerType: DelegatedApprovalPolicyType;status: DelegatedApprovalRequestStatus;+ details: TDelegatedApprovalRequestDetails;};export type TValidateDelegatedApprovalConnectionDTO = {@@ -40,14 +45,9 @@ export type TUpdateDelegatedApprovalPolicyDTO = {export type TCreateDelegatedApprovalRequestDTO = {approvalRequest: Pick<TApprovalRequests, "id" | "type">;+ delegatedPolicy: Pick<TDelegatedApprovalPolicy, "type">;};export type TRetryDelegatedApprovalRequestDispatchDTO = {approvalRequest: Pick<TApprovalRequests, "id" | "policyId" | "status" | "expiresAt">;};--export type TUpdateDelegatedApprovalRequestDTO = {- requestId: string;- status?: DelegatedApprovalRequestStatus;- statusReason?: string | null;-};diff --git a/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.test.ts b/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.test.tsindex 9304339089..ef62d2d09b 100644--- a/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.test.ts+++ b/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.test.ts@@ -14,6 +14,7 @@ import {import { DelegatedApprovalPolicyType, DelegatedApprovalRequestStatus } from "../delegated-approval-enums";import { DELEGATED_APPROVAL_DISPATCH_REQUESTED_EVENT } from "../delegated-approval-events";+import { TDelegatedApprovalRequestDetails } from "../delegated-approval-schemas";import { delegatedApprovalDispatchConsumerFactory } from "./delegated-approval-dispatch-consumer";vi.mock("@app/lib/logger", () => ({@@ -60,7 +61,7 @@ const pendingDelegatedRequest = {id: DELEGATED_REQUEST_ID,requestId: "req-1",status: DelegatedApprovalRequestStatus.PendingDispatch,- statusReason: null as string | null,+ details: {} as TDelegatedApprovalRequestDetails,providerRequestId: null as string | null,encryptedCallbackToken: null,dispatchEventId: "event-1"@@ -98,14 +99,17 @@ const buildConsumer = ({} = {}) => {let row: TRow | null = delegatedRequest ? { ...delegatedRequest } : null;- const update = vi.fn(async (filter: Partial<TRow>, patch: Partial<TRow>) => {- const current = row;- if (!current) return [];- const matches = Object.entries(filter).every(([key, value]) => current[key as keyof TRow] === value);- if (!matches) return [];- row = { ...current, ...patch };- return [row];- });+ // Merges details the way the DAL's jsonb concatenation does.+ const updateWithDetails = vi.fn(+ async (filter: Partial<TRow>, { details, ...columns }: Partial<TRow> & { details?: Partial<TRow["details"]> }) => {+ const current = row;+ if (!current) return [];+ const matches = Object.entries(filter).every(([key, value]) => current[key as keyof TRow] === value);+ if (!matches) return [];+ row = { ...current, ...columns, details: { ...current.details, ...details } };+ return [row];+ }+ );const updateById = vi.fn(async (_id: string, patch: Partial<TRow>) => {row = row ? { ...row, ...patch } : row;return row;@@ -118,8 +122,8 @@ const buildConsumer = ({findById: findById ?? vi.fn(async () => row),primaryNode: () => PRIMARY,transaction: async (cb: (tx: never) => Promise<unknown>) => cb(TX),- update,- updateById+ updateById,+ updateWithDetails},delegatedApprovalPolicyDAL: { findOne: vi.fn().mockResolvedValue(policy) },delegatedApprovalCallbackService: {@@ -134,7 +138,7 @@ const buildConsumer = ({kmsService: { createCipherPairWithDataKey: vi.fn() }} as never);- return { consumer, row: () => row, update, approvalUpdate };+ return { consumer, row: () => row, updateWithDetails, approvalUpdate };};const makeEvent = (overrides?: Partial<TEvent>): TEvent => ({@@ -169,7 +173,7 @@ describe("delegatedApprovalDispatchConsumer", () => {expect(row()).toMatchObject({status: DelegatedApprovalRequestStatus.WaitingApproval,providerRequestId: "snow-1",- statusReason: null+ details: { statusReason: null }});});@@ -180,7 +184,10 @@ describe("delegatedApprovalDispatchConsumer", () => {const results = await consumer.handle([makeEvent()]);expect(results).toEqual([{ id: "event-1", status: EventResultStatus.Retry, error: "ServiceNow did not respond." }]);- expect(row()).toMatchObject({ status: DelegatedApprovalRequestStatus.FailedDispatch, statusReason: RETRY_REASON });+ expect(row()).toMatchObject({+ status: DelegatedApprovalRequestStatus.FailedDispatch,+ details: { statusReason: RETRY_REASON }+ });});test("fails terminally on an unrecoverable error without promising a retry", async () => {@@ -194,7 +201,7 @@ describe("delegatedApprovalDispatchConsumer", () => {]);expect(row()).toMatchObject({status: DelegatedApprovalRequestStatus.FailedDispatch,- statusReason: "ServiceNow rejected the credentials."+ details: { statusReason: "ServiceNow rejected the credentials." }});});@@ -209,7 +216,9 @@ describe("delegatedApprovalDispatchConsumer", () => {]);expect(row()).toMatchObject({status: DelegatedApprovalRequestStatus.Failed,- statusReason: `ServiceNow did not respond. Infisical could not send this request after ${MAX_OUTBOX_ATTEMPTS} attempts and closed it. Create a new request.`+ details: {+ statusReason: `ServiceNow did not respond. Infisical could not send this request after ${MAX_OUTBOX_ATTEMPTS} attempts and closed it. Create a new request.`+ }});expect(approvalUpdate).toHaveBeenCalledWith({ id: "req-1", status: ApprovalRequestStatus.Pending },@@ -227,7 +236,7 @@ describe("delegatedApprovalDispatchConsumer", () => {expect(result.status).toBe(EventResultStatus.Failed);expect(row()).toMatchObject({status: DelegatedApprovalRequestStatus.FailedDispatch,- statusReason: "ServiceNow rejected the credentials."+ details: { statusReason: "ServiceNow rejected the credentials." }});expect(approvalUpdate).not.toHaveBeenCalled();});@@ -254,7 +263,7 @@ describe("delegatedApprovalDispatchConsumer", () => {expect(result.status).toBe(EventResultStatus.Failed);expect(dispatch).not.toHaveBeenCalled();expect(row()?.status).toBe(DelegatedApprovalRequestStatus.FailedDispatch);- expect(row()?.statusReason).toContain("expired");+ expect(row()?.details.statusReason).toContain("expired");});test.each([@@ -370,16 +379,16 @@ describe("delegatedApprovalDispatchConsumer", () => {const resent = {...pendingDelegatedRequest,status: DelegatedApprovalRequestStatus.FailedDispatch,- statusReason: RETRY_REASON,+ details: { statusReason: RETRY_REASON },dispatchEventId: "event-2"};- const { consumer, row, update, approvalUpdate } = buildConsumer({ delegatedRequest: resent });+ const { consumer, row, updateWithDetails, approvalUpdate } = buildConsumer({ delegatedRequest: resent });const results = await consumer.handle([makeEvent({ id: "event-1", isFinalAttempt })]);expect(results).toEqual([{ id: "event-1", status: EventResultStatus.Delivered }]);expect(dispatch).not.toHaveBeenCalled();- expect(update).not.toHaveBeenCalled();+ expect(updateWithDetails).not.toHaveBeenCalled();expect(approvalUpdate).not.toHaveBeenCalled();expect(row()).toEqual(resent);}@@ -389,7 +398,7 @@ describe("delegatedApprovalDispatchConsumer", () => {const resent = {...pendingDelegatedRequest,status: DelegatedApprovalRequestStatus.FailedDispatch,- statusReason: RETRY_REASON,+ details: { statusReason: RETRY_REASON },dispatchEventId: "event-2"};const { consumer, row } = buildConsumer({@@ -513,7 +522,10 @@ describe("delegatedApprovalDispatchConsumer through the outbox", () => {attempts: 1,lastError: "ServiceNow did not respond."});- expect(row()).toMatchObject({ status: DelegatedApprovalRequestStatus.FailedDispatch, statusReason: RETRY_REASON });+ expect(row()).toMatchObject({+ status: DelegatedApprovalRequestStatus.FailedDispatch,+ details: { statusReason: RETRY_REASON }+ });await service.drain({ consumer: consumer.name });expect(rows[0].status).toBe(EventOutboxStatus.Retry);@@ -526,7 +538,7 @@ describe("delegatedApprovalDispatchConsumer through the outbox", () => {expect(row()).toMatchObject({status: DelegatedApprovalRequestStatus.WaitingApproval,providerRequestId: "snow-1",- statusReason: null+ details: { statusReason: null }});expect(dispatch).toHaveBeenCalledTimes(2);});@@ -566,7 +578,9 @@ describe("delegatedApprovalDispatchConsumer through the outbox", () => {test("lets a resend replace the event still retrying, so its last attempt neither dispatches nor closes", async () => {dispatch.mockRejectedValue(new Error("ServiceNow did not respond."));- const { consumer, row, update, approvalUpdate } = buildConsumer({ delegatedRequest: outboxDelegatedRequest });+ const { consumer, row, updateWithDetails, approvalUpdate } = buildConsumer({+ delegatedRequest: outboxDelegatedRequest+ });const { service, rows, elapseBackoff } = buildOutbox(consumer);const emitDispatch = (id: string) =>service.emit(@@ -583,7 +597,7 @@ describe("delegatedApprovalDispatchConsumer through the outbox", () => {expect(rows[0]).toMatchObject({ status: EventOutboxStatus.Retry, attempts: MAX_OUTBOX_ATTEMPTS - 1 });expect(row()?.status).toBe(DelegatedApprovalRequestStatus.FailedDispatch);- await update(+ await updateWithDetails({ id: DELEGATED_REQUEST_ID, status: DelegatedApprovalRequestStatus.FailedDispatch },{ dispatchEventId: RESENT_EVENT_ID });diff --git a/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.ts b/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.tsindex f4ae9a0b6a..d08ce35eee 100644--- a/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.ts+++ b/backend/src/services/delegated-approval/dispatch/delegated-approval-dispatch-consumer.ts@@ -28,7 +28,7 @@ import {import { DELEGATED_APPROVAL_CONNECTION_MAP } from "../delegated-approval-maps";import { TDelegatedApprovalPolicyDALFactory } from "../delegated-approval-policy-dal";import { TDelegatedApprovalRequestDALFactory } from "../delegated-approval-request-dal";-import { DELEGATED_APPROVAL_STATUS_REASON_MAX_CHARS } from "./delegated-approval-dispatch-constants";+import { toDelegatedApprovalStatusReason } from "../delegated-approval-request-fns";import {getDelegatedApprovalDispatchDetailsBuilder,getDelegatedApprovalProvider@@ -42,7 +42,7 @@ const DELEGATED_APPROVAL_DISPATCH_CONCURRENCY = 10;type TDelegatedApprovalDispatchConsumerDep = {delegatedApprovalRequestDAL: Pick<TDelegatedApprovalRequestDALFactory,- "findById" | "primaryNode" | "transaction" | "update" | "updateById"+ "findById" | "primaryNode" | "transaction" | "updateById" | "updateWithDetails">;delegatedApprovalPolicyDAL: Pick<TDelegatedApprovalPolicyDALFactory, "findOne">;delegatedApprovalCallbackService: Pick<@@ -68,11 +68,11 @@ export const delegatedApprovalDispatchConsumerFactory = ({}: TDelegatedApprovalDispatchConsumerDep): IEventConsumer<TDelegatedApprovalDispatchRequestedPayload> => {const $markDispatchFailed = async (delegatedRequestId: string, eventId: string, statusReason: string) => {try {- await delegatedApprovalRequestDAL.update(+ await delegatedApprovalRequestDAL.updateWithDetails({ id: delegatedRequestId, status: DelegatedApprovalRequestStatus.PendingDispatch, dispatchEventId: eventId },{status: DelegatedApprovalRequestStatus.FailedDispatch,- statusReason: statusReason.slice(0, DELEGATED_APPROVAL_STATUS_REASON_MAX_CHARS)+ details: { statusReason: toDelegatedApprovalStatusReason(statusReason) }});} catch (error) {@@ -96,11 +96,11 @@ export const delegatedApprovalDispatchConsumerFactory = ({}) => {try {await delegatedApprovalRequestDAL.transaction(async (tx) => {- const [closed] = await delegatedApprovalRequestDAL.update(+ const [closed] = await delegatedApprovalRequestDAL.updateWithDetails({ id: delegatedRequestId, status: DelegatedApprovalRequestStatus.PendingDispatch, dispatchEventId: eventId },{status: DelegatedApprovalRequestStatus.Failed,- statusReason: statusReason.slice(0, DELEGATED_APPROVAL_STATUS_REASON_MAX_CHARS)+ details: { statusReason: toDelegatedApprovalStatusReason(statusReason) }},tx);@@ -175,9 +175,9 @@ export const delegatedApprovalDispatchConsumerFactory = ({}if (delegatedRequest.status === DelegatedApprovalRequestStatus.FailedDispatch) {- const [reopened] = await delegatedApprovalRequestDAL.update(+ const [reopened] = await delegatedApprovalRequestDAL.updateWithDetails({ id: delegatedRequestId, status: DelegatedApprovalRequestStatus.FailedDispatch, dispatchEventId: eventId },- { status: DelegatedApprovalRequestStatus.PendingDispatch, statusReason: null }+ { status: DelegatedApprovalRequestStatus.PendingDispatch, details: { statusReason: null } });if (!reopened) {logger.info(@@ -256,9 +256,13 @@ export const delegatedApprovalDispatchConsumerFactory = ({const { providerRequestId } = await provider.dispatch(input, connection);- const [waitingRequest] = await delegatedApprovalRequestDAL.update(+ const [waitingRequest] = await delegatedApprovalRequestDAL.updateWithDetails({ id: delegatedRequestId, status: DelegatedApprovalRequestStatus.PendingDispatch },- { status: DelegatedApprovalRequestStatus.WaitingApproval, statusReason: null, providerRequestId }+ {+ status: DelegatedApprovalRequestStatus.WaitingApproval,+ providerRequestId,+ details: { statusReason: null }+ });if (!waitingRequest) {await delegatedApprovalRequestDAL.updateById(delegatedRequestId, { providerRequestId });diff --git a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.test.ts b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.test.tsindex 82f208f06f..0c2e103793 100644--- a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.test.ts+++ b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.test.ts@@ -432,7 +432,7 @@ describe("composeSecretAccessRequestRows", () => {{requestId: "req-1",status: DelegatedApprovalRequestStatus.FailedDispatch,- statusReason: "ServiceNow could not be reached."+ details: { statusReason: "ServiceNow could not be reached." }}]})@@ -501,7 +501,7 @@ describe("toSecretAccessRequestListItem", () => {const item = toItem({requests: [request({ policyId: null, status: ApprovalRequestStatus.Cancelled })],delegatedRequests: [- { requestId: "req-1", status: DelegatedApprovalRequestStatus.WaitingApproval, statusReason: null }+ { requestId: "req-1", status: DelegatedApprovalRequestStatus.WaitingApproval, details: { statusReason: null } }]});diff --git a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.ts b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.tsindex 5d5736fa67..353351d9eb 100644--- a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.ts+++ b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-fns.ts@@ -332,7 +332,7 @@ export type TSecretAccessRequestListInput = {groupMembers: { groupId: string; userId: string }[];users: Pick<TUsers, "id" | "email" | "username" | "firstName" | "lastName">[];orgMemberships: { actorUserId?: string | null; isActive: boolean }[];- delegatedRequests: Pick<TDelegatedApprovalRequest, "requestId" | "status" | "statusReason">[];+ delegatedRequests: Pick<TDelegatedApprovalRequest, "requestId" | "status" | "details">[];};export type TPolicySubject = { type: string; id?: string | null };@@ -489,7 +489,7 @@ export const composeSecretAccessRequestRows = ({delegatedApproval: delegatedRequest? {status: delegatedRequest.status,- statusReason: delegatedRequest.statusReason ?? null+ statusReason: delegatedRequest.details.statusReason ?? null}: null,environment: policy?.environment ?? null,diff --git a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.ts b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.tsindex 18b12ccb5e..576c4e2099 100644--- a/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.ts+++ b/backend/src/services/secret-access-approval-global-request-bridge/secret-access-approval-global-request-bridge-service.ts@@ -399,7 +399,7 @@ export const secretAccessApprovalGlobalRequestBridgeServiceFactory = ({tx);if (delegatedPolicy) {- await delegatedApprovalService.createRequest({ approvalRequest }, tx);+ await delegatedApprovalService.createRequest({ approvalRequest, delegatedPolicy }, tx);}return { approvalRequest, policySteps: currentSteps };});