mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 11:41:44 +10:00
Merge branch 'main' into feat/signing-reminders
This commit is contained in:
29
packages/lib/types/api-logs.ts
Normal file
29
packages/lib/types/api-logs.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import type { ApiRequestMetadata } from '../universal/extract-request-metadata';
|
||||
|
||||
/**
|
||||
* The minimum required fields that the parent API logger must contain.
|
||||
*/
|
||||
export type RootApiLog = {
|
||||
ipAddress?: string;
|
||||
userAgent?: string;
|
||||
requestId: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* The minimum API log that must be logged at the start of every API request.
|
||||
*/
|
||||
export type BaseApiLog = Partial<RootApiLog> & {
|
||||
path: string;
|
||||
auth: ApiRequestMetadata['auth'];
|
||||
source: ApiRequestMetadata['source'];
|
||||
userId?: number | null;
|
||||
apiTokenId?: number | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* The TRPC API log.
|
||||
*/
|
||||
export type TrpcApiLog = BaseApiLog & {
|
||||
trpcMiddleware: string;
|
||||
unverifiedTeamId?: number | null;
|
||||
};
|
||||
@ -33,6 +33,7 @@ export const ZDocumentAuditLogTypeSchema = z.enum([
|
||||
'DOCUMENT_GLOBAL_AUTH_ACTION_UPDATED', // When the global action authentication is updated.
|
||||
'DOCUMENT_META_UPDATED', // When the document meta data is updated.
|
||||
'DOCUMENT_OPENED', // When the document is opened by a recipient.
|
||||
'DOCUMENT_VIEWED', // When the document is viewed by a recipient.
|
||||
'DOCUMENT_RECIPIENT_REJECTED', // When a recipient rejects the document.
|
||||
'DOCUMENT_RECIPIENT_COMPLETED', // When a recipient completes all their required tasks for the document.
|
||||
'DOCUMENT_SENT', // When the document transitions from DRAFT to PENDING.
|
||||
@ -58,6 +59,9 @@ export const ZDocumentMetaDiffTypeSchema = z.enum([
|
||||
'REDIRECT_URL',
|
||||
'SUBJECT',
|
||||
'TIMEZONE',
|
||||
'EMAIL_ID',
|
||||
'EMAIL_REPLY_TO',
|
||||
'EMAIL_SETTINGS',
|
||||
]);
|
||||
|
||||
export const ZFieldDiffTypeSchema = z.enum(['DIMENSION', 'POSITION']);
|
||||
@ -109,6 +113,9 @@ export const ZDocumentAuditLogDocumentMetaSchema = z.union([
|
||||
z.literal(DOCUMENT_META_DIFF_TYPE.REDIRECT_URL),
|
||||
z.literal(DOCUMENT_META_DIFF_TYPE.SUBJECT),
|
||||
z.literal(DOCUMENT_META_DIFF_TYPE.TIMEZONE),
|
||||
z.literal(DOCUMENT_META_DIFF_TYPE.EMAIL_ID),
|
||||
z.literal(DOCUMENT_META_DIFF_TYPE.EMAIL_REPLY_TO),
|
||||
z.literal(DOCUMENT_META_DIFF_TYPE.EMAIL_SETTINGS),
|
||||
]),
|
||||
from: z.string().nullable(),
|
||||
to: z.string().nullable(),
|
||||
@ -124,8 +131,8 @@ export const ZDocumentAuditLogFieldDiffSchema = z.union([
|
||||
]);
|
||||
|
||||
export const ZGenericFromToSchema = z.object({
|
||||
from: z.string().nullable(),
|
||||
to: z.string().nullable(),
|
||||
from: z.union([z.string(), z.array(z.string())]).nullable(),
|
||||
to: z.union([z.string(), z.array(z.string())]).nullable(),
|
||||
});
|
||||
|
||||
export const ZRecipientDiffActionAuthSchema = ZGenericFromToSchema.extend({
|
||||
@ -297,7 +304,7 @@ export const ZDocumentAuditLogEventDocumentFieldInsertedSchema = z.object({
|
||||
},
|
||||
z
|
||||
.object({
|
||||
type: ZRecipientActionAuthTypesSchema,
|
||||
type: ZRecipientActionAuthTypesSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
),
|
||||
@ -385,7 +392,7 @@ export const ZDocumentAuditLogEventDocumentFieldPrefilledSchema = z.object({
|
||||
},
|
||||
z
|
||||
.object({
|
||||
type: ZRecipientActionAuthTypesSchema,
|
||||
type: ZRecipientActionAuthTypesSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
),
|
||||
@ -429,7 +436,29 @@ export const ZDocumentAuditLogEventDocumentMetaUpdatedSchema = z.object({
|
||||
export const ZDocumentAuditLogEventDocumentOpenedSchema = z.object({
|
||||
type: z.literal(DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_OPENED),
|
||||
data: ZBaseRecipientDataSchema.extend({
|
||||
accessAuth: z.string().optional(),
|
||||
accessAuth: z.preprocess((unknownValue) => {
|
||||
if (!unknownValue) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.isArray(unknownValue) ? unknownValue : [unknownValue];
|
||||
}, z.array(ZRecipientAccessAuthTypesSchema)),
|
||||
}),
|
||||
});
|
||||
|
||||
/**
|
||||
* Event: Document viewed.
|
||||
*/
|
||||
export const ZDocumentAuditLogEventDocumentViewedSchema = z.object({
|
||||
type: z.literal(DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_VIEWED),
|
||||
data: ZBaseRecipientDataSchema.extend({
|
||||
accessAuth: z.preprocess((unknownValue) => {
|
||||
if (!unknownValue) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.isArray(unknownValue) ? unknownValue : [unknownValue];
|
||||
}, z.array(ZRecipientAccessAuthTypesSchema)),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -439,7 +468,13 @@ export const ZDocumentAuditLogEventDocumentOpenedSchema = z.object({
|
||||
export const ZDocumentAuditLogEventDocumentRecipientCompleteSchema = z.object({
|
||||
type: z.literal(DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED),
|
||||
data: ZBaseRecipientDataSchema.extend({
|
||||
actionAuth: z.string().optional(),
|
||||
actionAuth: z.preprocess((unknownValue) => {
|
||||
if (!unknownValue) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.isArray(unknownValue) ? unknownValue : [unknownValue];
|
||||
}, z.array(ZRecipientActionAuthTypesSchema)),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -517,8 +552,20 @@ export const ZDocumentAuditLogEventFieldUpdatedSchema = z.object({
|
||||
export const ZDocumentAuditLogEventRecipientAddedSchema = z.object({
|
||||
type: z.literal(DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_CREATED),
|
||||
data: ZBaseRecipientDataSchema.extend({
|
||||
accessAuth: ZRecipientAccessAuthTypesSchema.optional(),
|
||||
actionAuth: ZRecipientActionAuthTypesSchema.optional(),
|
||||
accessAuth: z.preprocess((unknownValue) => {
|
||||
if (!unknownValue) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.isArray(unknownValue) ? unknownValue : [unknownValue];
|
||||
}, z.array(ZRecipientAccessAuthTypesSchema)),
|
||||
actionAuth: z.preprocess((unknownValue) => {
|
||||
if (!unknownValue) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.isArray(unknownValue) ? unknownValue : [unknownValue];
|
||||
}, z.array(ZRecipientActionAuthTypesSchema)),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -578,6 +625,7 @@ export const ZDocumentAuditLogSchema = ZDocumentAuditLogBaseSchema.and(
|
||||
ZDocumentAuditLogEventDocumentGlobalAuthActionUpdatedSchema,
|
||||
ZDocumentAuditLogEventDocumentMetaUpdatedSchema,
|
||||
ZDocumentAuditLogEventDocumentOpenedSchema,
|
||||
ZDocumentAuditLogEventDocumentViewedSchema,
|
||||
ZDocumentAuditLogEventDocumentRecipientCompleteSchema,
|
||||
ZDocumentAuditLogEventDocumentRecipientRejectedSchema,
|
||||
ZDocumentAuditLogEventDocumentSentSchema,
|
||||
|
||||
@ -9,8 +9,10 @@ export const ZDocumentAuthTypesSchema = z.enum([
|
||||
'ACCOUNT',
|
||||
'PASSKEY',
|
||||
'TWO_FACTOR_AUTH',
|
||||
'PASSWORD',
|
||||
'EXPLICIT_NONE',
|
||||
]);
|
||||
|
||||
export const DocumentAuth = ZDocumentAuthTypesSchema.Enum;
|
||||
|
||||
const ZDocumentAuthAccountSchema = z.object({
|
||||
@ -27,6 +29,11 @@ const ZDocumentAuthPasskeySchema = z.object({
|
||||
tokenReference: z.string().min(1),
|
||||
});
|
||||
|
||||
const ZDocumentAuthPasswordSchema = z.object({
|
||||
type: z.literal(DocumentAuth.PASSWORD),
|
||||
password: z.string().min(1),
|
||||
});
|
||||
|
||||
const ZDocumentAuth2FASchema = z.object({
|
||||
type: z.literal(DocumentAuth.TWO_FACTOR_AUTH),
|
||||
token: z.string().min(4).max(10),
|
||||
@ -40,6 +47,7 @@ export const ZDocumentAuthMethodsSchema = z.discriminatedUnion('type', [
|
||||
ZDocumentAuthExplicitNoneSchema,
|
||||
ZDocumentAuthPasskeySchema,
|
||||
ZDocumentAuth2FASchema,
|
||||
ZDocumentAuthPasswordSchema,
|
||||
]);
|
||||
|
||||
/**
|
||||
@ -61,9 +69,15 @@ export const ZDocumentActionAuthSchema = z.discriminatedUnion('type', [
|
||||
ZDocumentAuthAccountSchema,
|
||||
ZDocumentAuthPasskeySchema,
|
||||
ZDocumentAuth2FASchema,
|
||||
ZDocumentAuthPasswordSchema,
|
||||
]);
|
||||
export const ZDocumentActionAuthTypesSchema = z
|
||||
.enum([DocumentAuth.ACCOUNT, DocumentAuth.PASSKEY, DocumentAuth.TWO_FACTOR_AUTH])
|
||||
.enum([
|
||||
DocumentAuth.ACCOUNT,
|
||||
DocumentAuth.PASSKEY,
|
||||
DocumentAuth.TWO_FACTOR_AUTH,
|
||||
DocumentAuth.PASSWORD,
|
||||
])
|
||||
.describe(
|
||||
'The type of authentication required for the recipient to sign the document. This field is restricted to Enterprise plan users only.',
|
||||
);
|
||||
@ -89,6 +103,7 @@ export const ZRecipientActionAuthSchema = z.discriminatedUnion('type', [
|
||||
ZDocumentAuthAccountSchema,
|
||||
ZDocumentAuthPasskeySchema,
|
||||
ZDocumentAuth2FASchema,
|
||||
ZDocumentAuthPasswordSchema,
|
||||
ZDocumentAuthExplicitNoneSchema,
|
||||
]);
|
||||
export const ZRecipientActionAuthTypesSchema = z
|
||||
@ -96,6 +111,7 @@ export const ZRecipientActionAuthTypesSchema = z
|
||||
DocumentAuth.ACCOUNT,
|
||||
DocumentAuth.PASSKEY,
|
||||
DocumentAuth.TWO_FACTOR_AUTH,
|
||||
DocumentAuth.PASSWORD,
|
||||
DocumentAuth.EXPLICIT_NONE,
|
||||
])
|
||||
.describe('The type of authentication required for the recipient to sign the document.');
|
||||
@ -110,18 +126,26 @@ export const RecipientActionAuth = ZRecipientActionAuthTypesSchema.Enum;
|
||||
*/
|
||||
export const ZDocumentAuthOptionsSchema = z.preprocess(
|
||||
(unknownValue) => {
|
||||
if (unknownValue) {
|
||||
return unknownValue;
|
||||
if (!unknownValue || typeof unknownValue !== 'object') {
|
||||
return {
|
||||
globalAccessAuth: [],
|
||||
globalActionAuth: [],
|
||||
};
|
||||
}
|
||||
|
||||
const globalAccessAuth =
|
||||
'globalAccessAuth' in unknownValue ? processAuthValue(unknownValue.globalAccessAuth) : [];
|
||||
const globalActionAuth =
|
||||
'globalActionAuth' in unknownValue ? processAuthValue(unknownValue.globalActionAuth) : [];
|
||||
|
||||
return {
|
||||
globalAccessAuth: null,
|
||||
globalActionAuth: null,
|
||||
globalAccessAuth,
|
||||
globalActionAuth,
|
||||
};
|
||||
},
|
||||
z.object({
|
||||
globalAccessAuth: ZDocumentAccessAuthTypesSchema.nullable(),
|
||||
globalActionAuth: ZDocumentActionAuthTypesSchema.nullable(),
|
||||
globalAccessAuth: z.array(ZDocumentAccessAuthTypesSchema),
|
||||
globalActionAuth: z.array(ZDocumentActionAuthTypesSchema),
|
||||
}),
|
||||
);
|
||||
|
||||
@ -130,21 +154,46 @@ export const ZDocumentAuthOptionsSchema = z.preprocess(
|
||||
*/
|
||||
export const ZRecipientAuthOptionsSchema = z.preprocess(
|
||||
(unknownValue) => {
|
||||
if (unknownValue) {
|
||||
return unknownValue;
|
||||
if (!unknownValue || typeof unknownValue !== 'object') {
|
||||
return {
|
||||
accessAuth: [],
|
||||
actionAuth: [],
|
||||
};
|
||||
}
|
||||
|
||||
const accessAuth =
|
||||
'accessAuth' in unknownValue ? processAuthValue(unknownValue.accessAuth) : [];
|
||||
const actionAuth =
|
||||
'actionAuth' in unknownValue ? processAuthValue(unknownValue.actionAuth) : [];
|
||||
|
||||
return {
|
||||
accessAuth: null,
|
||||
actionAuth: null,
|
||||
accessAuth,
|
||||
actionAuth,
|
||||
};
|
||||
},
|
||||
z.object({
|
||||
accessAuth: ZRecipientAccessAuthTypesSchema.nullable(),
|
||||
actionAuth: ZRecipientActionAuthTypesSchema.nullable(),
|
||||
accessAuth: z.array(ZRecipientAccessAuthTypesSchema),
|
||||
actionAuth: z.array(ZRecipientActionAuthTypesSchema),
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* Utility function to process the auth value.
|
||||
*
|
||||
* Converts the old singular auth value to an array of auth values.
|
||||
*/
|
||||
const processAuthValue = (value: unknown) => {
|
||||
if (value === null || value === undefined) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return [value];
|
||||
};
|
||||
|
||||
export type TDocumentAuth = z.infer<typeof ZDocumentAuthTypesSchema>;
|
||||
export type TDocumentAuthMethods = z.infer<typeof ZDocumentAuthMethodsSchema>;
|
||||
export type TDocumentAuthOptions = z.infer<typeof ZDocumentAuthOptionsSchema>;
|
||||
|
||||
@ -54,15 +54,7 @@ export const ZDocumentEmailSettingsSchema = z
|
||||
.default(true),
|
||||
})
|
||||
.strip()
|
||||
.catch(() => ({
|
||||
recipientSigningRequest: true,
|
||||
recipientRemoved: true,
|
||||
recipientSigned: true,
|
||||
documentPending: true,
|
||||
documentCompleted: true,
|
||||
documentDeleted: true,
|
||||
ownerDocumentCompleted: true,
|
||||
}));
|
||||
.catch(() => ({ ...DEFAULT_DOCUMENT_EMAIL_SETTINGS }));
|
||||
|
||||
export type TDocumentEmailSettings = z.infer<typeof ZDocumentEmailSettingsSchema>;
|
||||
|
||||
@ -88,3 +80,13 @@ export const extractDerivedDocumentEmailSettings = (
|
||||
ownerDocumentCompleted: emailSettings.ownerDocumentCompleted,
|
||||
};
|
||||
};
|
||||
|
||||
export const DEFAULT_DOCUMENT_EMAIL_SETTINGS: TDocumentEmailSettings = {
|
||||
recipientSigningRequest: true,
|
||||
recipientRemoved: true,
|
||||
recipientSigned: true,
|
||||
documentPending: true,
|
||||
documentCompleted: true,
|
||||
documentDeleted: true,
|
||||
ownerDocumentCompleted: true,
|
||||
};
|
||||
|
||||
@ -3,6 +3,7 @@ import type { z } from 'zod';
|
||||
import { DocumentDataSchema } from '@documenso/prisma/generated/zod/modelSchema/DocumentDataSchema';
|
||||
import { DocumentMetaSchema } from '@documenso/prisma/generated/zod/modelSchema/DocumentMetaSchema';
|
||||
import { DocumentSchema } from '@documenso/prisma/generated/zod/modelSchema/DocumentSchema';
|
||||
import { FolderSchema } from '@documenso/prisma/generated/zod/modelSchema/FolderSchema';
|
||||
import { TeamSchema } from '@documenso/prisma/generated/zod/modelSchema/TeamSchema';
|
||||
import { UserSchema } from '@documenso/prisma/generated/zod/modelSchema/UserSchema';
|
||||
|
||||
@ -31,6 +32,7 @@ export const ZDocumentSchema = DocumentSchema.pick({
|
||||
deletedAt: true,
|
||||
teamId: true,
|
||||
templateId: true,
|
||||
folderId: true,
|
||||
}).extend({
|
||||
// Todo: Maybe we want to alter this a bit since this returns a lot of data.
|
||||
documentData: DocumentDataSchema.pick({
|
||||
@ -58,6 +60,20 @@ export const ZDocumentSchema = DocumentSchema.pick({
|
||||
emailSettings: true,
|
||||
reminderInterval: true,
|
||||
lastReminderSentAt: true,
|
||||
emailId: true,
|
||||
emailReplyTo: true,
|
||||
}).nullable(),
|
||||
folder: FolderSchema.pick({
|
||||
id: true,
|
||||
name: true,
|
||||
type: true,
|
||||
visibility: true,
|
||||
userId: true,
|
||||
teamId: true,
|
||||
pinned: true,
|
||||
parentId: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
}).nullable(),
|
||||
recipients: ZRecipientLiteSchema.array(),
|
||||
fields: ZFieldSchema.array(),
|
||||
@ -85,8 +101,12 @@ export const ZDocumentLiteSchema = DocumentSchema.pick({
|
||||
deletedAt: true,
|
||||
teamId: true,
|
||||
templateId: true,
|
||||
folderId: true,
|
||||
useLegacyFieldInsertion: true,
|
||||
});
|
||||
|
||||
export type TDocumentLite = z.infer<typeof ZDocumentLiteSchema>;
|
||||
|
||||
/**
|
||||
* A version of the document response schema when returning multiple documents at once from a single API endpoint.
|
||||
*/
|
||||
@ -107,6 +127,8 @@ export const ZDocumentManySchema = DocumentSchema.pick({
|
||||
deletedAt: true,
|
||||
teamId: true,
|
||||
templateId: true,
|
||||
folderId: true,
|
||||
useLegacyFieldInsertion: true,
|
||||
}).extend({
|
||||
user: UserSchema.pick({
|
||||
id: true,
|
||||
@ -119,3 +141,5 @@ export const ZDocumentManySchema = DocumentSchema.pick({
|
||||
url: true,
|
||||
}).nullable(),
|
||||
});
|
||||
|
||||
export type TDocumentMany = z.infer<typeof ZDocumentManySchema>;
|
||||
|
||||
40
packages/lib/types/email-domain.ts
Normal file
40
packages/lib/types/email-domain.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { EmailDomainSchema } from '@documenso/prisma/generated/zod/modelSchema/EmailDomainSchema';
|
||||
|
||||
import { ZOrganisationEmailLiteSchema } from './organisation-email';
|
||||
|
||||
/**
|
||||
* The full email domain response schema.
|
||||
*
|
||||
* Mainly used for returning a single email domain from the API.
|
||||
*/
|
||||
export const ZEmailDomainSchema = EmailDomainSchema.pick({
|
||||
id: true,
|
||||
status: true,
|
||||
organisationId: true,
|
||||
domain: true,
|
||||
selector: true,
|
||||
publicKey: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
}).extend({
|
||||
emails: ZOrganisationEmailLiteSchema.array(),
|
||||
});
|
||||
|
||||
export type TEmailDomain = z.infer<typeof ZEmailDomainSchema>;
|
||||
|
||||
/**
|
||||
* A version of the email domain response schema when returning multiple email domains at once from a single API endpoint.
|
||||
*/
|
||||
export const ZEmailDomainManySchema = EmailDomainSchema.pick({
|
||||
id: true,
|
||||
status: true,
|
||||
organisationId: true,
|
||||
domain: true,
|
||||
selector: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
export type TEmailDomainMany = z.infer<typeof ZEmailDomainManySchema>;
|
||||
@ -96,6 +96,7 @@ export const ZCheckboxFieldMeta = ZBaseFieldMeta.extend({
|
||||
.optional(),
|
||||
validationRule: z.string().optional(),
|
||||
validationLength: z.number().optional(),
|
||||
direction: z.enum(['vertical', 'horizontal']).optional().default('vertical'),
|
||||
});
|
||||
|
||||
export type TCheckboxFieldMeta = z.infer<typeof ZCheckboxFieldMeta>;
|
||||
@ -155,6 +156,10 @@ export const ZFieldMetaPrefillFieldsSchema = z
|
||||
label: z.string().optional(),
|
||||
value: z.string().optional(),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal('date'),
|
||||
value: z.string().optional(),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
|
||||
|
||||
9
packages/lib/types/folder-type.ts
Normal file
9
packages/lib/types/folder-type.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const FolderType = {
|
||||
DOCUMENT: 'DOCUMENT',
|
||||
TEMPLATE: 'TEMPLATE',
|
||||
} as const;
|
||||
|
||||
export const ZFolderTypeSchema = z.enum([FolderType.DOCUMENT, FolderType.TEMPLATE]);
|
||||
export type TFolderType = z.infer<typeof ZFolderTypeSchema>;
|
||||
42
packages/lib/types/organisation-email.ts
Normal file
42
packages/lib/types/organisation-email.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { EmailDomainStatus } from '@prisma/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { OrganisationEmailSchema } from '@documenso/prisma/generated/zod/modelSchema/OrganisationEmailSchema';
|
||||
|
||||
export const ZOrganisationEmailSchema = OrganisationEmailSchema.pick({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
email: true,
|
||||
emailName: true,
|
||||
// replyTo: true,
|
||||
emailDomainId: true,
|
||||
organisationId: true,
|
||||
}).extend({
|
||||
emailDomain: z.object({
|
||||
id: z.string(),
|
||||
status: z.nativeEnum(EmailDomainStatus),
|
||||
}),
|
||||
});
|
||||
|
||||
export type TOrganisationEmail = z.infer<typeof ZOrganisationEmailSchema>;
|
||||
|
||||
/**
|
||||
* A lite version of the organisation email response schema without relations.
|
||||
*/
|
||||
export const ZOrganisationEmailLiteSchema = OrganisationEmailSchema.pick({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
email: true,
|
||||
emailName: true,
|
||||
// replyTo: true,
|
||||
emailDomainId: true,
|
||||
organisationId: true,
|
||||
});
|
||||
|
||||
export const ZOrganisationEmailManySchema = ZOrganisationEmailLiteSchema.extend({
|
||||
// Put anything extra here.
|
||||
});
|
||||
|
||||
export type TOrganisationEmailMany = z.infer<typeof ZOrganisationEmailManySchema>;
|
||||
45
packages/lib/types/organisation.ts
Normal file
45
packages/lib/types/organisation.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
import OrganisationClaimSchema from '@documenso/prisma/generated/zod/modelSchema/OrganisationClaimSchema';
|
||||
import { OrganisationSchema } from '@documenso/prisma/generated/zod/modelSchema/OrganisationSchema';
|
||||
|
||||
export const ZOrganisationSchema = OrganisationSchema.pick({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
type: true,
|
||||
name: true,
|
||||
url: true,
|
||||
avatarImageId: true,
|
||||
customerId: true,
|
||||
ownerUserId: true,
|
||||
}).extend({
|
||||
organisationClaim: OrganisationClaimSchema.pick({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
originalSubscriptionClaimId: true,
|
||||
teamCount: true,
|
||||
memberCount: true,
|
||||
flags: true,
|
||||
}),
|
||||
});
|
||||
|
||||
export type TOrganisation = z.infer<typeof ZOrganisationSchema>;
|
||||
|
||||
export const ZOrganisationLiteSchema = OrganisationSchema.pick({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
type: true,
|
||||
name: true,
|
||||
url: true,
|
||||
avatarImageId: true,
|
||||
customerId: true,
|
||||
ownerUserId: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* A version of the organisation response schema when returning multiple organisations at once from a single API endpoint.
|
||||
*/
|
||||
export const ZOrganisationManySchema = ZOrganisationLiteSchema;
|
||||
185
packages/lib/types/subscription.ts
Normal file
185
packages/lib/types/subscription.ts
Normal file
@ -0,0 +1,185 @@
|
||||
import type { SubscriptionClaim } from '@prisma/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZOrganisationNameSchema } from '@documenso/trpc/server/organisation-router/create-organisation.types';
|
||||
|
||||
/**
|
||||
* README:
|
||||
* - If you update this you MUST update the `backport-subscription-claims` schema as well.
|
||||
*/
|
||||
export const ZClaimFlagsSchema = z.object({
|
||||
/**
|
||||
* Allows disabling of Documenso branding for:
|
||||
* - Certificates
|
||||
* - Emails
|
||||
* - Other?
|
||||
*/
|
||||
allowCustomBranding: z.boolean().optional(),
|
||||
hidePoweredBy: z.boolean().optional(),
|
||||
|
||||
unlimitedDocuments: z.boolean().optional(),
|
||||
|
||||
emailDomains: z.boolean().optional(),
|
||||
|
||||
embedAuthoring: z.boolean().optional(),
|
||||
embedAuthoringWhiteLabel: z.boolean().optional(),
|
||||
|
||||
embedSigning: z.boolean().optional(),
|
||||
embedSigningWhiteLabel: z.boolean().optional(),
|
||||
|
||||
cfr21: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type TClaimFlags = z.infer<typeof ZClaimFlagsSchema>;
|
||||
|
||||
// When adding keys, update internal documentation with this.
|
||||
export const SUBSCRIPTION_CLAIM_FEATURE_FLAGS: Record<
|
||||
keyof TClaimFlags,
|
||||
{
|
||||
label: string;
|
||||
key: keyof TClaimFlags;
|
||||
}
|
||||
> = {
|
||||
unlimitedDocuments: {
|
||||
key: 'unlimitedDocuments',
|
||||
label: 'Unlimited documents',
|
||||
},
|
||||
allowCustomBranding: {
|
||||
key: 'allowCustomBranding',
|
||||
label: 'Branding',
|
||||
},
|
||||
hidePoweredBy: {
|
||||
key: 'hidePoweredBy',
|
||||
label: 'Hide Documenso branding by',
|
||||
},
|
||||
emailDomains: {
|
||||
key: 'emailDomains',
|
||||
label: 'Email domains',
|
||||
},
|
||||
embedAuthoring: {
|
||||
key: 'embedAuthoring',
|
||||
label: 'Embed authoring',
|
||||
},
|
||||
embedSigning: {
|
||||
key: 'embedSigning',
|
||||
label: 'Embed signing',
|
||||
},
|
||||
embedAuthoringWhiteLabel: {
|
||||
key: 'embedAuthoringWhiteLabel',
|
||||
label: 'White label for embed authoring',
|
||||
},
|
||||
embedSigningWhiteLabel: {
|
||||
key: 'embedSigningWhiteLabel',
|
||||
label: 'White label for embed signing',
|
||||
},
|
||||
cfr21: {
|
||||
key: 'cfr21',
|
||||
label: '21 CFR',
|
||||
},
|
||||
};
|
||||
|
||||
export enum INTERNAL_CLAIM_ID {
|
||||
FREE = 'free',
|
||||
INDIVIDUAL = 'individual',
|
||||
TEAM = 'team',
|
||||
EARLY_ADOPTER = 'earlyAdopter',
|
||||
PLATFORM = 'platform',
|
||||
ENTERPRISE = 'enterprise',
|
||||
}
|
||||
|
||||
export type InternalClaim = Omit<SubscriptionClaim, 'createdAt' | 'updatedAt'>;
|
||||
|
||||
export type InternalClaims = {
|
||||
[key in INTERNAL_CLAIM_ID]: InternalClaim;
|
||||
};
|
||||
|
||||
export const internalClaims: InternalClaims = {
|
||||
[INTERNAL_CLAIM_ID.FREE]: {
|
||||
id: INTERNAL_CLAIM_ID.FREE,
|
||||
name: 'Free',
|
||||
teamCount: 1,
|
||||
memberCount: 1,
|
||||
locked: true,
|
||||
flags: {},
|
||||
},
|
||||
[INTERNAL_CLAIM_ID.INDIVIDUAL]: {
|
||||
id: INTERNAL_CLAIM_ID.INDIVIDUAL,
|
||||
name: 'Individual',
|
||||
teamCount: 1,
|
||||
memberCount: 1,
|
||||
locked: true,
|
||||
flags: {
|
||||
unlimitedDocuments: true,
|
||||
},
|
||||
},
|
||||
[INTERNAL_CLAIM_ID.TEAM]: {
|
||||
id: INTERNAL_CLAIM_ID.TEAM,
|
||||
name: 'Teams',
|
||||
teamCount: 1,
|
||||
memberCount: 5,
|
||||
locked: true,
|
||||
flags: {
|
||||
unlimitedDocuments: true,
|
||||
allowCustomBranding: true,
|
||||
embedSigning: true,
|
||||
},
|
||||
},
|
||||
[INTERNAL_CLAIM_ID.PLATFORM]: {
|
||||
id: INTERNAL_CLAIM_ID.PLATFORM,
|
||||
name: 'Platform',
|
||||
teamCount: 1,
|
||||
memberCount: 0,
|
||||
locked: true,
|
||||
flags: {
|
||||
unlimitedDocuments: true,
|
||||
allowCustomBranding: true,
|
||||
hidePoweredBy: true,
|
||||
emailDomains: false,
|
||||
embedAuthoring: false,
|
||||
embedAuthoringWhiteLabel: true,
|
||||
embedSigning: false,
|
||||
embedSigningWhiteLabel: true,
|
||||
},
|
||||
},
|
||||
[INTERNAL_CLAIM_ID.ENTERPRISE]: {
|
||||
id: INTERNAL_CLAIM_ID.ENTERPRISE,
|
||||
name: 'Enterprise',
|
||||
teamCount: 0,
|
||||
memberCount: 0,
|
||||
locked: true,
|
||||
flags: {
|
||||
unlimitedDocuments: true,
|
||||
allowCustomBranding: true,
|
||||
hidePoweredBy: true,
|
||||
emailDomains: true,
|
||||
embedAuthoring: true,
|
||||
embedAuthoringWhiteLabel: true,
|
||||
embedSigning: true,
|
||||
embedSigningWhiteLabel: true,
|
||||
cfr21: true,
|
||||
},
|
||||
},
|
||||
[INTERNAL_CLAIM_ID.EARLY_ADOPTER]: {
|
||||
id: INTERNAL_CLAIM_ID.EARLY_ADOPTER,
|
||||
name: 'Early Adopter',
|
||||
teamCount: 0,
|
||||
memberCount: 0,
|
||||
locked: true,
|
||||
flags: {
|
||||
unlimitedDocuments: true,
|
||||
allowCustomBranding: true,
|
||||
hidePoweredBy: true,
|
||||
embedSigning: true,
|
||||
embedSigningWhiteLabel: true,
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const ZStripeOrganisationCreateMetadataSchema = z.object({
|
||||
organisationName: ZOrganisationNameSchema,
|
||||
userId: z.number(),
|
||||
});
|
||||
|
||||
export type StripeOrganisationCreateMetadata = z.infer<
|
||||
typeof ZStripeOrganisationCreateMetadataSchema
|
||||
>;
|
||||
@ -1,6 +1,7 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { DocumentDataSchema } from '@documenso/prisma/generated/zod/modelSchema/DocumentDataSchema';
|
||||
import { FolderSchema } from '@documenso/prisma/generated/zod/modelSchema/FolderSchema';
|
||||
import TeamSchema from '@documenso/prisma/generated/zod/modelSchema/TeamSchema';
|
||||
import { TemplateDirectLinkSchema } from '@documenso/prisma/generated/zod/modelSchema/TemplateDirectLinkSchema';
|
||||
import { TemplateMetaSchema } from '@documenso/prisma/generated/zod/modelSchema/TemplateMetaSchema';
|
||||
@ -29,6 +30,7 @@ export const ZTemplateSchema = TemplateSchema.pick({
|
||||
updatedAt: true,
|
||||
publicTitle: true,
|
||||
publicDescription: true,
|
||||
folderId: true,
|
||||
}).extend({
|
||||
// Todo: Maybe we want to alter this a bit since this returns a lot of data.
|
||||
templateDocumentData: DocumentDataSchema.pick({
|
||||
@ -53,6 +55,8 @@ export const ZTemplateSchema = TemplateSchema.pick({
|
||||
redirectUrl: true,
|
||||
language: true,
|
||||
emailSettings: true,
|
||||
emailId: true,
|
||||
emailReplyTo: true,
|
||||
}).nullable(),
|
||||
directLink: TemplateDirectLinkSchema.nullable(),
|
||||
user: UserSchema.pick({
|
||||
@ -62,6 +66,18 @@ export const ZTemplateSchema = TemplateSchema.pick({
|
||||
}),
|
||||
recipients: ZRecipientLiteSchema.array(),
|
||||
fields: ZFieldSchema.array(),
|
||||
folder: FolderSchema.pick({
|
||||
id: true,
|
||||
name: true,
|
||||
type: true,
|
||||
visibility: true,
|
||||
userId: true,
|
||||
teamId: true,
|
||||
pinned: true,
|
||||
parentId: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
}).nullable(),
|
||||
});
|
||||
|
||||
export type TTemplate = z.infer<typeof ZTemplateSchema>;
|
||||
@ -83,6 +99,8 @@ export const ZTemplateLiteSchema = TemplateSchema.pick({
|
||||
updatedAt: true,
|
||||
publicTitle: true,
|
||||
publicDescription: true,
|
||||
folderId: true,
|
||||
useLegacyFieldInsertion: true,
|
||||
});
|
||||
|
||||
/**
|
||||
@ -102,6 +120,8 @@ export const ZTemplateManySchema = TemplateSchema.pick({
|
||||
updatedAt: true,
|
||||
publicTitle: true,
|
||||
publicDescription: true,
|
||||
folderId: true,
|
||||
useLegacyFieldInsertion: true,
|
||||
}).extend({
|
||||
team: TeamSchema.pick({
|
||||
id: true,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { Document, DocumentMeta, Recipient } from '@prisma/client';
|
||||
import type { Document, DocumentMeta, Recipient, WebhookTriggerEvents } from '@prisma/client';
|
||||
import {
|
||||
DocumentDistributionMethod,
|
||||
DocumentSigningOrder,
|
||||
@ -87,6 +87,13 @@ export const ZWebhookDocumentSchema = z.object({
|
||||
export type TWebhookRecipient = z.infer<typeof ZWebhookRecipientSchema>;
|
||||
export type TWebhookDocument = z.infer<typeof ZWebhookDocumentSchema>;
|
||||
|
||||
export type WebhookPayload = {
|
||||
event: WebhookTriggerEvents;
|
||||
payload: TWebhookDocument;
|
||||
createdAt: string;
|
||||
webhookEndpoint: string;
|
||||
};
|
||||
|
||||
export const mapDocumentToWebhookDocumentPayload = (
|
||||
document: Document & {
|
||||
recipients: Recipient[];
|
||||
|
||||
Reference in New Issue
Block a user