mirror of
https://github.com/documenso/documenso.git
synced 2026-07-27 02:15:05 +10:00
Merge remote-tracking branch 'origin/main' into pr-2468
# Conflicts: # packages/lib/types/document-audit-logs.ts # packages/lib/utils/document-audit-logs.ts # packages/prisma/schema.prisma
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { isHttpUrl } from '@documenso/lib/utils/is-http-url';
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { TrpcRouteMeta } from '../../trpc';
|
||||
@@ -16,7 +17,7 @@ export const ZCreateAttachmentRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
data: z.object({
|
||||
label: z.string().min(1, 'Label is required'),
|
||||
data: z.string().url('Must be a valid URL'),
|
||||
data: z.string().url('Must be a valid URL').refine(isHttpUrl, 'URL must use the http or https protocol'),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { isHttpUrl } from '@documenso/lib/utils/is-http-url';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZSuccessResponseSchema } from '../../schema';
|
||||
@@ -17,7 +18,7 @@ export const ZUpdateAttachmentRequestSchema = z.object({
|
||||
id: z.string(),
|
||||
data: z.object({
|
||||
label: z.string().min(1, 'Label is required'),
|
||||
data: z.string().url('Must be a valid URL'),
|
||||
data: z.string().url('Must be a valid URL').refine(isHttpUrl, 'URL must use the http or https protocol'),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { cancelDocument } from '@documenso/lib/server-only/document/cancel-document';
|
||||
import { getMultipleEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelopes-by-ids';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
import pMap from 'p-map';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import { ZBulkCancelEnvelopesRequestSchema, ZBulkCancelEnvelopesResponseSchema } from './bulk-cancel-envelopes.types';
|
||||
|
||||
export const bulkCancelEnvelopesRoute = authenticatedProcedure
|
||||
.input(ZBulkCancelEnvelopesRequestSchema)
|
||||
.output(ZBulkCancelEnvelopesResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { teamId, user } = ctx;
|
||||
const { envelopeIds, reason } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeIds,
|
||||
},
|
||||
});
|
||||
|
||||
// Cancelling only applies to documents. Templates are filtered out here so
|
||||
// selecting a template never counts towards a cancellation.
|
||||
const { envelopeWhereInput } = await getMultipleEnvelopeWhereInput({
|
||||
ids: {
|
||||
type: 'envelopeId',
|
||||
ids: envelopeIds,
|
||||
},
|
||||
userId: user.id,
|
||||
teamId,
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
});
|
||||
|
||||
const envelopes = await prisma.envelope.findMany({
|
||||
where: envelopeWhereInput,
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
const results = await pMap(
|
||||
envelopes,
|
||||
async (envelope) => {
|
||||
const { id: envelopeId } = envelope;
|
||||
|
||||
try {
|
||||
await cancelDocument({
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
userId: user.id,
|
||||
teamId,
|
||||
reason,
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
envelopeId,
|
||||
};
|
||||
} catch (err) {
|
||||
ctx.logger.warn(
|
||||
{
|
||||
envelopeId,
|
||||
error: err,
|
||||
},
|
||||
'Failed to cancel envelope during bulk cancel',
|
||||
);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
envelopeId,
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
concurrency: 10,
|
||||
stopOnError: false,
|
||||
},
|
||||
);
|
||||
|
||||
const cancelledCount = results.filter((r) => r.success).length;
|
||||
const failedIds = results.filter((r) => !r.success).map((r) => r.envelopeId);
|
||||
|
||||
// Include envelope IDs that were not attempted (unauthorized/not found/not a document).
|
||||
const attemptedIds = new Set(envelopes.map((e) => e.id));
|
||||
const unattemptedIds = envelopeIds.filter((id) => !attemptedIds.has(id));
|
||||
|
||||
return {
|
||||
cancelledCount,
|
||||
failedIds: [...failedIds, ...unattemptedIds],
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// Keeping this as a private API for a little while until we're sure it's stable
|
||||
// and the request/response schemas are finalized.
|
||||
|
||||
export const ZBulkCancelEnvelopesRequestSchema = z.object({
|
||||
envelopeIds: z
|
||||
.array(z.string())
|
||||
.min(1)
|
||||
.max(100)
|
||||
.describe('The IDs of the envelopes to cancel. The maximum number of envelopes you can cancel at once is 100.'),
|
||||
reason: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ZBulkCancelEnvelopesResponseSchema = z.object({
|
||||
cancelledCount: z.number(),
|
||||
failedIds: z.array(z.string()),
|
||||
});
|
||||
|
||||
export type TBulkCancelEnvelopesRequest = z.infer<typeof ZBulkCancelEnvelopesRequestSchema>;
|
||||
export type TBulkCancelEnvelopesResponse = z.infer<typeof ZBulkCancelEnvelopesResponseSchema>;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { cancelDocument } from '@documenso/lib/server-only/document/cancel-document';
|
||||
|
||||
import { ZGenericSuccessResponse } from '../schema';
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
cancelEnvelopeMeta,
|
||||
ZCancelEnvelopeRequestSchema,
|
||||
ZCancelEnvelopeResponseSchema,
|
||||
} from './cancel-envelope.types';
|
||||
|
||||
export const cancelEnvelopeRoute = authenticatedProcedure
|
||||
.meta(cancelEnvelopeMeta)
|
||||
.input(ZCancelEnvelopeRequestSchema)
|
||||
.output(ZCancelEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { teamId } = ctx;
|
||||
const { envelopeId, reason } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
await cancelDocument({
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
reason,
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
|
||||
return ZGenericSuccessResponse;
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZSuccessResponseSchema } from '../schema';
|
||||
import type { TrpcRouteMeta } from '../trpc';
|
||||
|
||||
export const cancelEnvelopeMeta: TrpcRouteMeta = {
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/cancel',
|
||||
summary: 'Cancel envelope',
|
||||
tags: ['Envelope'],
|
||||
},
|
||||
};
|
||||
|
||||
export const ZCancelEnvelopeRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
reason: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ZCancelEnvelopeResponseSchema = ZSuccessResponseSchema;
|
||||
|
||||
export type TCancelEnvelopeRequest = z.infer<typeof ZCancelEnvelopeRequestSchema>;
|
||||
export type TCancelEnvelopeResponse = z.infer<typeof ZCancelEnvelopeResponseSchema>;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
downloadEnvelopeAuditLogPdfMeta,
|
||||
ZDownloadEnvelopeAuditLogPdfRequestSchema,
|
||||
ZDownloadEnvelopeAuditLogPdfResponseSchema,
|
||||
} from './download-envelope-audit-log-pdf.types';
|
||||
|
||||
export const downloadEnvelopeAuditLogPdfRoute = authenticatedProcedure
|
||||
.meta(downloadEnvelopeAuditLogPdfMeta)
|
||||
.input(ZDownloadEnvelopeAuditLogPdfRequestSchema)
|
||||
.output(ZDownloadEnvelopeAuditLogPdfResponseSchema)
|
||||
.query(({ input, ctx }) => {
|
||||
const { envelopeId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
// This endpoint is purely for V2 API, which is implemented in the Hono remix server.
|
||||
throw new Error('NOT_IMPLEMENTED');
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { TrpcRouteMeta } from '../trpc';
|
||||
|
||||
export const downloadEnvelopeAuditLogPdfMeta: TrpcRouteMeta = {
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/envelope/{envelopeId}/audit-log/download',
|
||||
summary: 'Download envelope audit log PDF',
|
||||
description: 'Download the audit log for a document as a PDF.',
|
||||
tags: ['Envelope'],
|
||||
responseHeaders: z.object({
|
||||
'Content-Type': z.literal('application/pdf'),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
export const ZDownloadEnvelopeAuditLogPdfRequestSchema = z.object({
|
||||
envelopeId: z.string().describe('The ID of the envelope to download the audit log for.'),
|
||||
});
|
||||
|
||||
export const ZDownloadEnvelopeAuditLogPdfResponseSchema = z.instanceof(Uint8Array);
|
||||
|
||||
export type TDownloadEnvelopeAuditLogPdfRequest = z.infer<typeof ZDownloadEnvelopeAuditLogPdfRequestSchema>;
|
||||
export type TDownloadEnvelopeAuditLogPdfResponse = z.infer<typeof ZDownloadEnvelopeAuditLogPdfResponseSchema>;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
downloadEnvelopeCertificatePdfMeta,
|
||||
ZDownloadEnvelopeCertificatePdfRequestSchema,
|
||||
ZDownloadEnvelopeCertificatePdfResponseSchema,
|
||||
} from './download-envelope-certificate-pdf.types';
|
||||
|
||||
export const downloadEnvelopeCertificatePdfRoute = authenticatedProcedure
|
||||
.meta(downloadEnvelopeCertificatePdfMeta)
|
||||
.input(ZDownloadEnvelopeCertificatePdfRequestSchema)
|
||||
.output(ZDownloadEnvelopeCertificatePdfResponseSchema)
|
||||
.query(({ input, ctx }) => {
|
||||
const { envelopeId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
// This endpoint is purely for V2 API, which is implemented in the Hono remix server.
|
||||
throw new Error('NOT_IMPLEMENTED');
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { TrpcRouteMeta } from '../trpc';
|
||||
|
||||
export const downloadEnvelopeCertificatePdfMeta: TrpcRouteMeta = {
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/envelope/{envelopeId}/certificate/download',
|
||||
summary: 'Download envelope certificate PDF',
|
||||
description: 'Download the signing certificate for a completed document as a PDF.',
|
||||
tags: ['Envelope'],
|
||||
responseHeaders: z.object({
|
||||
'Content-Type': z.literal('application/pdf'),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
export const ZDownloadEnvelopeCertificatePdfRequestSchema = z.object({
|
||||
envelopeId: z.string().describe('The ID of the envelope to download the certificate for.'),
|
||||
});
|
||||
|
||||
export const ZDownloadEnvelopeCertificatePdfResponseSchema = z.instanceof(Uint8Array);
|
||||
|
||||
export type TDownloadEnvelopeCertificatePdfRequest = z.infer<typeof ZDownloadEnvelopeCertificatePdfRequestSchema>;
|
||||
export type TDownloadEnvelopeCertificatePdfResponse = z.infer<typeof ZDownloadEnvelopeCertificatePdfResponseSchema>;
|
||||
@@ -13,7 +13,7 @@ export const duplicateEnvelopeRoute = authenticatedProcedure
|
||||
.output(ZDuplicateEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { teamId } = ctx;
|
||||
const { envelopeId } = input;
|
||||
const { envelopeId, includeRecipients, includeFields } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
@@ -28,6 +28,10 @@ export const duplicateEnvelopeRoute = authenticatedProcedure
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
overrides: {
|
||||
includeRecipients,
|
||||
includeFields,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -13,7 +13,17 @@ export const duplicateEnvelopeMeta: TrpcRouteMeta = {
|
||||
};
|
||||
|
||||
export const ZDuplicateEnvelopeRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
envelopeId: z.string().min(1).describe('The ID of the envelope to duplicate.'),
|
||||
includeRecipients: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.default(true)
|
||||
.describe('Whether to copy the recipients to the duplicated envelope. Defaults to true.'),
|
||||
includeFields: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.default(true)
|
||||
.describe('Whether to copy the fields to the duplicated envelope. Requires includeRecipients. Defaults to true.'),
|
||||
});
|
||||
|
||||
export const ZDuplicateEnvelopeResponseSchema = z.object({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
@@ -41,5 +42,26 @@ export const getEnvelopeRecipientRoute = authenticatedProcedure
|
||||
});
|
||||
}
|
||||
|
||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: recipient.envelopeId,
|
||||
},
|
||||
type: null,
|
||||
userId: user.id,
|
||||
teamId,
|
||||
});
|
||||
|
||||
// Additional validation to check visibility.
|
||||
const envelope = await prisma.envelope.findUnique({
|
||||
where: envelopeWhereInput,
|
||||
});
|
||||
|
||||
if (!envelope) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Recipient not found',
|
||||
});
|
||||
}
|
||||
|
||||
return recipient;
|
||||
});
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { rejectDocumentOnBehalfOf } from '@documenso/lib/server-only/document/reject-document-on-behalf-of';
|
||||
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
rejectEnvelopeRecipientOnBehalfOfMeta,
|
||||
ZRejectEnvelopeRecipientOnBehalfOfRequestSchema,
|
||||
ZRejectEnvelopeRecipientOnBehalfOfResponseSchema,
|
||||
} from './reject-envelope-recipient-on-behalf-of.types';
|
||||
|
||||
export const rejectEnvelopeRecipientOnBehalfOfRoute = authenticatedProcedure
|
||||
.meta(rejectEnvelopeRecipientOnBehalfOfMeta)
|
||||
.input(ZRejectEnvelopeRecipientOnBehalfOfRequestSchema)
|
||||
.output(ZRejectEnvelopeRecipientOnBehalfOfResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { teamId, user } = ctx;
|
||||
const { envelopeId, recipientId, reason, actAsEmail } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
recipientId,
|
||||
},
|
||||
});
|
||||
|
||||
// This is an external-only action: it must only be reachable through the
|
||||
// public API, never the internal app TRPC handler.
|
||||
if (ctx.metadata.source !== 'apiV2') {
|
||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||
message: 'This route is only accessible via the public API',
|
||||
});
|
||||
}
|
||||
|
||||
await rejectDocumentOnBehalfOf({
|
||||
envelopeId,
|
||||
recipientId,
|
||||
userId: user.id,
|
||||
teamId,
|
||||
reason,
|
||||
actAsEmail,
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
|
||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||
id: { type: 'envelopeId', id: envelopeId },
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
userId: user.id,
|
||||
teamId,
|
||||
});
|
||||
|
||||
const recipient = await prisma.recipient.findFirstOrThrow({
|
||||
where: {
|
||||
id: recipientId,
|
||||
envelope: envelopeWhereInput,
|
||||
},
|
||||
include: {
|
||||
fields: true,
|
||||
},
|
||||
});
|
||||
|
||||
return recipient;
|
||||
});
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import { ZEnvelopeRecipientSchema } from '@documenso/lib/types/recipient';
|
||||
import { zEmail } from '@documenso/lib/utils/zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { TrpcRouteMeta } from '../../trpc';
|
||||
|
||||
export const rejectEnvelopeRecipientOnBehalfOfMeta: TrpcRouteMeta = {
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/recipient/{recipientId}/reject',
|
||||
summary: 'Reject envelope recipient on behalf of',
|
||||
description:
|
||||
'Records a rejection on behalf of a recipient. Use this when a recipient has declined to ' +
|
||||
'sign outside of the platform. The rejection is flagged as external in the document audit ' +
|
||||
'log. By default the action is attributed to the API user; supply `actAsEmail` to attribute ' +
|
||||
'it to a specific team member.',
|
||||
tags: ['Envelope Recipients'],
|
||||
},
|
||||
};
|
||||
|
||||
export const ZRejectEnvelopeRecipientOnBehalfOfRequestSchema = z.object({
|
||||
envelopeId: z.string().describe('The ID of the envelope the recipient belongs to.'),
|
||||
recipientId: z.number().describe('The ID of the recipient to reject the document on behalf of.'),
|
||||
reason: z.string().min(1).describe('The reason the recipient rejected the document.'),
|
||||
actAsEmail: zEmail()
|
||||
.optional()
|
||||
.describe('The email of the team member to attribute the rejection to. Defaults to the API user when omitted.'),
|
||||
});
|
||||
|
||||
export const ZRejectEnvelopeRecipientOnBehalfOfResponseSchema = ZEnvelopeRecipientSchema;
|
||||
|
||||
export type TRejectEnvelopeRecipientOnBehalfOfRequest = z.infer<typeof ZRejectEnvelopeRecipientOnBehalfOfRequestSchema>;
|
||||
export type TRejectEnvelopeRecipientOnBehalfOfResponse = z.infer<
|
||||
typeof ZRejectEnvelopeRecipientOnBehalfOfResponseSchema
|
||||
>;
|
||||
@@ -0,0 +1,95 @@
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { reportSenderRateLimit } from '@documenso/lib/server-only/rate-limit/rate-limits';
|
||||
import { generateDatabaseId } from '@documenso/lib/universal/id';
|
||||
import { currentMonthlyPeriod } from '@documenso/lib/universal/monthly-period';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { procedure } from '../../trpc';
|
||||
import { ZReportRecipientRequestSchema, ZReportRecipientResponseSchema } from './report-recipient.types';
|
||||
|
||||
/**
|
||||
* NOTE: THIS IS A PUBLIC (UNAUTHENTICATED) PROCEDURE.
|
||||
* Recipients report a sender directly from a link in their email, so no session or
|
||||
* API token is required.
|
||||
*/
|
||||
export const reportRecipientRoute = procedure
|
||||
.input(ZReportRecipientRequestSchema)
|
||||
.output(ZReportRecipientResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { token } = input;
|
||||
|
||||
if (!token) {
|
||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||
message: 'Token is required',
|
||||
});
|
||||
}
|
||||
|
||||
const { ipAddress } = ctx.metadata.requestMetadata;
|
||||
|
||||
const recipient = await prisma.recipient.findFirst({
|
||||
where: { token },
|
||||
select: {
|
||||
id: true,
|
||||
envelopeId: true,
|
||||
envelope: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
organisationId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!recipient) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Recipient could not be found',
|
||||
});
|
||||
}
|
||||
|
||||
// Rate limit to ensure we aren't double reporting by accident.
|
||||
const rateLimitResult = await reportSenderRateLimit.check({
|
||||
ip: ipAddress ?? 'unknown',
|
||||
identifier: `${recipient.envelopeId}:${recipient.id}`,
|
||||
});
|
||||
|
||||
if (rateLimitResult.isLimited) {
|
||||
return;
|
||||
}
|
||||
|
||||
const period = currentMonthlyPeriod();
|
||||
const { organisationId } = recipient.envelope.team;
|
||||
|
||||
// Incrementing the stat is a non-critical side effect; fail soft so a transient
|
||||
// DB error never turns reporting into a user-facing error.
|
||||
await prisma.organisationMonthlyStat
|
||||
.upsert({
|
||||
where: {
|
||||
organisationId_period: {
|
||||
organisationId,
|
||||
period,
|
||||
},
|
||||
},
|
||||
update: {
|
||||
emailReports: { increment: 1 },
|
||||
},
|
||||
create: {
|
||||
id: generateDatabaseId('org_monthly_stat'),
|
||||
organisationId,
|
||||
period,
|
||||
emailReports: 1,
|
||||
},
|
||||
})
|
||||
.catch((error) => {
|
||||
ctx.logger.error({
|
||||
msg: 'Failed to increment organisation emailReports stat',
|
||||
error,
|
||||
});
|
||||
});
|
||||
|
||||
ctx.logger.info({
|
||||
msg: `Email reported. Recipient: ${recipient.id}. Envelope: ${recipient.envelopeId}.`,
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZReportRecipientRequestSchema = z.object({
|
||||
token: z.string().min(1).describe('The recipient token from the email link used to report the sender.'),
|
||||
});
|
||||
|
||||
export const ZReportRecipientResponseSchema = z.void();
|
||||
|
||||
export type TReportRecipientRequest = z.infer<typeof ZReportRecipientRequestSchema>;
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { assertEnvelopeMutable } from '@documenso/lib/server-only/envelope/assert-envelope-mutable';
|
||||
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
import { UNSAFE_replaceEnvelopeItemPdf } from '@documenso/lib/server-only/envelope-item/replace-envelope-item-pdf';
|
||||
import { getEnvelopeItemPermissions } from '@documenso/lib/utils/envelope';
|
||||
@@ -59,6 +60,8 @@ export const replaceEnvelopeItemPdfRoute = authenticatedProcedure
|
||||
});
|
||||
}
|
||||
|
||||
assertEnvelopeMutable(envelope);
|
||||
|
||||
if (envelope.internalVersion !== 2) {
|
||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||
message: 'PDF replacement is only supported for version 2 envelopes',
|
||||
|
||||
@@ -3,13 +3,17 @@ import { createAttachmentRoute } from './attachment/create-attachment';
|
||||
import { deleteAttachmentRoute } from './attachment/delete-attachment';
|
||||
import { findAttachmentsRoute } from './attachment/find-attachments';
|
||||
import { updateAttachmentRoute } from './attachment/update-attachment';
|
||||
import { bulkCancelEnvelopesRoute } from './bulk-cancel-envelopes';
|
||||
import { bulkDeleteEnvelopesRoute } from './bulk-delete-envelopes';
|
||||
import { bulkMoveEnvelopesRoute } from './bulk-move-envelopes';
|
||||
import { cancelEnvelopeRoute } from './cancel-envelope';
|
||||
import { createEnvelopeRoute } from './create-envelope';
|
||||
import { createEnvelopeItemsRoute } from './create-envelope-items';
|
||||
import { deleteEnvelopeRoute } from './delete-envelope';
|
||||
import { deleteEnvelopeItemRoute } from './delete-envelope-item';
|
||||
import { distributeEnvelopeRoute } from './distribute-envelope';
|
||||
import { downloadEnvelopeAuditLogPdfRoute } from './download-envelope-audit-log-pdf';
|
||||
import { downloadEnvelopeCertificatePdfRoute } from './download-envelope-certificate-pdf';
|
||||
import { downloadEnvelopeItemRoute } from './download-envelope-item';
|
||||
import { duplicateEnvelopeRoute } from './duplicate-envelope';
|
||||
import { createEnvelopeFieldsRoute } from './envelope-fields/create-envelope-fields';
|
||||
@@ -20,6 +24,8 @@ import { updateEnvelopeFieldsRoute } from './envelope-fields/update-envelope-fie
|
||||
import { createEnvelopeRecipientsRoute } from './envelope-recipients/create-envelope-recipients';
|
||||
import { deleteEnvelopeRecipientRoute } from './envelope-recipients/delete-envelope-recipient';
|
||||
import { getEnvelopeRecipientRoute } from './envelope-recipients/get-envelope-recipient';
|
||||
import { rejectEnvelopeRecipientOnBehalfOfRoute } from './envelope-recipients/reject-envelope-recipient-on-behalf-of';
|
||||
import { reportRecipientRoute } from './envelope-recipients/report-recipient';
|
||||
import { updateEnvelopeRecipientsRoute } from './envelope-recipients/update-envelope-recipients';
|
||||
import { findEnvelopeAuditLogsRoute } from './find-envelope-audit-logs';
|
||||
import { findEnvelopesRoute } from './find-envelopes';
|
||||
@@ -69,6 +75,8 @@ export const envelopeRouter = router({
|
||||
updateMany: updateEnvelopeRecipientsRoute,
|
||||
delete: deleteEnvelopeRecipientRoute,
|
||||
set: setEnvelopeRecipientsRoute,
|
||||
report: reportRecipientRoute,
|
||||
rejectOnBehalfOf: rejectEnvelopeRecipientOnBehalfOfRoute,
|
||||
},
|
||||
field: {
|
||||
get: getEnvelopeFieldRoute,
|
||||
@@ -82,10 +90,15 @@ export const envelopeRouter = router({
|
||||
find: findEnvelopesRoute,
|
||||
auditLog: {
|
||||
find: findEnvelopeAuditLogsRoute,
|
||||
downloadPdf: downloadEnvelopeAuditLogPdfRoute,
|
||||
},
|
||||
certificate: {
|
||||
downloadPdf: downloadEnvelopeCertificatePdfRoute,
|
||||
},
|
||||
bulk: {
|
||||
move: bulkMoveEnvelopesRoute,
|
||||
delete: bulkDeleteEnvelopesRoute,
|
||||
cancel: bulkCancelEnvelopesRoute,
|
||||
},
|
||||
editor: {
|
||||
get: getEditorEnvelopeRoute,
|
||||
@@ -96,6 +109,7 @@ export const envelopeRouter = router({
|
||||
use: useEnvelopeRoute,
|
||||
update: updateEnvelopeRoute,
|
||||
delete: deleteEnvelopeRoute,
|
||||
cancel: cancelEnvelopeRoute,
|
||||
duplicate: duplicateEnvelopeRoute,
|
||||
saveAsTemplate: saveAsTemplateRoute,
|
||||
distribute: distributeEnvelopeRoute,
|
||||
|
||||
Reference in New Issue
Block a user