mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import type { Envelope } from '@prisma/client';
|
|
import { EnvelopeType } from '@prisma/client';
|
|
import { customAlphabet } from 'nanoid';
|
|
|
|
import { mapSecondaryIdToDocumentId, mapSecondaryIdToTemplateId } from '../utils/envelope';
|
|
|
|
export const alphaid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 21);
|
|
|
|
export { nanoid } from 'nanoid';
|
|
|
|
export const fancyId = customAlphabet('abcdefhiklmnorstuvwxyz', 16);
|
|
|
|
export const prefixedId = (prefix: string, length = 16) => {
|
|
return `${prefix}_${fancyId(length)}`;
|
|
};
|
|
|
|
type DatabaseIdPrefix =
|
|
| 'document'
|
|
| 'template'
|
|
| 'envelope'
|
|
| 'envelope_item'
|
|
| 'email_domain'
|
|
| 'org'
|
|
| 'org_email'
|
|
| 'org_claim'
|
|
| 'org_group'
|
|
| 'org_sso'
|
|
| 'org_setting'
|
|
| 'member'
|
|
| 'member_invite'
|
|
| 'group_member'
|
|
| 'team_group'
|
|
| 'team_setting';
|
|
|
|
export const generateDatabaseId = (prefix: DatabaseIdPrefix) => prefixedId(prefix, 16);
|
|
|
|
export const extractLegacyIds = (envelope: Pick<Envelope, 'type' | 'secondaryId'>) => {
|
|
return {
|
|
documentId:
|
|
envelope.type === EnvelopeType.DOCUMENT
|
|
? mapSecondaryIdToDocumentId(envelope.secondaryId)
|
|
: null,
|
|
templateId:
|
|
envelope.type === EnvelopeType.TEMPLATE
|
|
? mapSecondaryIdToTemplateId(envelope.secondaryId)
|
|
: null,
|
|
};
|
|
};
|