Compare commits
3 Commits
7e38d06ef5
...
feat/webho
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bcd023b00 | |||
| f6f66272b2 | |||
| 776cd3aa8b |
@ -22,6 +22,15 @@ Documenso supports Webhooks and allows you to subscribe to the following events:
|
|||||||
- `document.completed`
|
- `document.completed`
|
||||||
- `document.rejected`
|
- `document.rejected`
|
||||||
- `document.cancelled`
|
- `document.cancelled`
|
||||||
|
- `document.viewed`
|
||||||
|
- `document.recipient.completed`
|
||||||
|
- `document.downloaded`
|
||||||
|
- `document.reminder.sent`
|
||||||
|
- `template.created`
|
||||||
|
- `template.updated`
|
||||||
|
- `template.deleted`
|
||||||
|
- `template.used`
|
||||||
|
- `recipient.authentication.failed`
|
||||||
|
|
||||||
## Create a webhook subscription
|
## Create a webhook subscription
|
||||||
|
|
||||||
@ -38,7 +47,7 @@ Clicking on the "**Create Webhook**" button opens a modal to create a new webhoo
|
|||||||
To create a new webhook subscription, you need to provide the following information:
|
To create a new webhook subscription, you need to provide the following information:
|
||||||
|
|
||||||
- Enter the webhook URL that will receive the event payload.
|
- Enter the webhook URL that will receive the event payload.
|
||||||
- Select the event(s) you want to subscribe to: `document.created`, `document.sent`, `document.opened`, `document.signed`, `document.completed`, `document.rejected`, `document.cancelled`.
|
- Select the event(s) you want to subscribe to: `document.created`, `document.sent`, `document.opened`, `document.signed`, `document.completed`, `document.rejected`, `document.cancelled`, `document.viewed`, `document.recipient.completed`, `document.downloaded`, `document.reminder.sent`, `template.created`, `template.updated`, `template.deleted`, `template.used`, `recipient.authentication.failed`.
|
||||||
- Optionally, you can provide a secret key that will be used to sign the payload. This key will be included in the `X-Documenso-Secret` header of the request.
|
- Optionally, you can provide a secret key that will be used to sign the payload. This key will be included in the `X-Documenso-Secret` header of the request.
|
||||||
|
|
||||||

|

|
||||||
@ -619,6 +628,591 @@ Example payload for the `document.rejected` event:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example payload for the `document.viewed` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "DOCUMENT_VIEWED",
|
||||||
|
"payload": {
|
||||||
|
"id": 10,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "documenso.pdf",
|
||||||
|
"status": "PENDING",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T11:48:07.569Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": null,
|
||||||
|
"templateId": null,
|
||||||
|
"source": "DOCUMENT",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_123",
|
||||||
|
"subject": "Please sign this document",
|
||||||
|
"message": "Hello, please review and sign this document.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 52,
|
||||||
|
"documentId": 10,
|
||||||
|
"templateId": null,
|
||||||
|
"email": "signer@documenso.com",
|
||||||
|
"name": "John Doe",
|
||||||
|
"token": "vbT8hi3jKQmrFP_LN1WcS",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": null,
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T11:50:26.174Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `document.recipient.completed` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "DOCUMENT_RECIPIENT_COMPLETED",
|
||||||
|
"payload": {
|
||||||
|
"id": 10,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "documenso.pdf",
|
||||||
|
"status": "PENDING",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T11:51:10.055Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": null,
|
||||||
|
"templateId": null,
|
||||||
|
"source": "DOCUMENT",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_123",
|
||||||
|
"subject": "Please sign this document",
|
||||||
|
"message": "Hello, please review and sign this document.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 50,
|
||||||
|
"documentId": 10,
|
||||||
|
"templateId": null,
|
||||||
|
"email": "signer1@documenso.com",
|
||||||
|
"name": "Signer 1",
|
||||||
|
"token": "vbT8hi3jKQmrFP_LN1WcS",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": "2024-04-22T11:51:10.055Z",
|
||||||
|
"authOptions": {
|
||||||
|
"accessAuth": null,
|
||||||
|
"actionAuth": null
|
||||||
|
},
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "OPENED",
|
||||||
|
"signingStatus": "SIGNED",
|
||||||
|
"sendStatus": "SENT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 51,
|
||||||
|
"documentId": 10,
|
||||||
|
"templateId": null,
|
||||||
|
"email": "signer2@documenso.com",
|
||||||
|
"name": "Signer 2",
|
||||||
|
"token": "HkrptwS42ZBXdRKj1TyUo",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": null,
|
||||||
|
"signingOrder": 2,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "NOT_OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T11:51:10.577Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `document.downloaded` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "DOCUMENT_DOWNLOADED",
|
||||||
|
"payload": {
|
||||||
|
"id": 10,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "documenso.pdf",
|
||||||
|
"status": "COMPLETED",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T11:52:05.708Z",
|
||||||
|
"completedAt": "2024-04-22T11:52:05.707Z",
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": null,
|
||||||
|
"templateId": null,
|
||||||
|
"source": "DOCUMENT",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_123",
|
||||||
|
"subject": "Please sign this document",
|
||||||
|
"message": "Hello, please review and sign this document.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 51,
|
||||||
|
"documentId": 10,
|
||||||
|
"templateId": null,
|
||||||
|
"email": "signer@documenso.com",
|
||||||
|
"name": "Signer",
|
||||||
|
"token": "HkrptwS42ZBXdRKj1TyUo",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": "2024-04-22T11:52:05.688Z",
|
||||||
|
"authOptions": {
|
||||||
|
"accessAuth": null,
|
||||||
|
"actionAuth": null
|
||||||
|
},
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "OPENED",
|
||||||
|
"signingStatus": "SIGNED",
|
||||||
|
"sendStatus": "SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T11:53:18.577Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `document.reminder.sent` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "DOCUMENT_REMINDER_SENT",
|
||||||
|
"payload": {
|
||||||
|
"id": 10,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "documenso.pdf",
|
||||||
|
"status": "PENDING",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T11:48:07.569Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": null,
|
||||||
|
"templateId": null,
|
||||||
|
"source": "DOCUMENT",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_123",
|
||||||
|
"subject": "Please sign this document",
|
||||||
|
"message": "Hello, please review and sign this document.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 52,
|
||||||
|
"documentId": 10,
|
||||||
|
"templateId": null,
|
||||||
|
"email": "signer@documenso.com",
|
||||||
|
"name": "Signer",
|
||||||
|
"token": "vbT8hi3jKQmrFP_LN1WcS",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": null,
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T12:00:00.000Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `template.created` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "TEMPLATE_CREATED",
|
||||||
|
"payload": {
|
||||||
|
"id": 5,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "employment_contract.pdf",
|
||||||
|
"status": "DRAFT",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": 2,
|
||||||
|
"templateId": 5,
|
||||||
|
"source": "TEMPLATE",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_456",
|
||||||
|
"subject": "Employment Contract",
|
||||||
|
"message": "Please review and sign your employment contract.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 25,
|
||||||
|
"documentId": null,
|
||||||
|
"templateId": 5,
|
||||||
|
"email": "employee@company.com",
|
||||||
|
"name": "Employee",
|
||||||
|
"token": "TemplateToken123",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": null,
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "NOT_OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "NOT_SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T11:44:44.779Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `template.updated` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "TEMPLATE_UPDATED",
|
||||||
|
"payload": {
|
||||||
|
"id": 5,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "employment_contract_v2.pdf",
|
||||||
|
"status": "DRAFT",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T12:30:00.000Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": 2,
|
||||||
|
"templateId": 5,
|
||||||
|
"source": "TEMPLATE",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_456",
|
||||||
|
"subject": "Employment Contract - Updated",
|
||||||
|
"message": "Please review and sign your employment contract.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 25,
|
||||||
|
"documentId": null,
|
||||||
|
"templateId": 5,
|
||||||
|
"email": "employee@company.com",
|
||||||
|
"name": "Employee",
|
||||||
|
"token": "TemplateToken123",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": null,
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "NOT_OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "NOT_SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T12:30:01.000Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `template.deleted` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "TEMPLATE_DELETED",
|
||||||
|
"payload": {
|
||||||
|
"id": 5,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "employment_contract.pdf",
|
||||||
|
"status": "DRAFT",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": 2,
|
||||||
|
"templateId": 5,
|
||||||
|
"source": "TEMPLATE",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_456",
|
||||||
|
"subject": "Employment Contract",
|
||||||
|
"message": "Please review and sign your employment contract.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 25,
|
||||||
|
"documentId": null,
|
||||||
|
"templateId": 5,
|
||||||
|
"email": "employee@company.com",
|
||||||
|
"name": "Employee",
|
||||||
|
"token": "TemplateToken123",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": null,
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "NOT_OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "NOT_SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T13:00:00.000Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `template.used` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "TEMPLATE_USED",
|
||||||
|
"payload": {
|
||||||
|
"id": 15,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "employment_contract.pdf",
|
||||||
|
"status": "DRAFT",
|
||||||
|
"documentDataId": "new_doc_data_123",
|
||||||
|
"createdAt": "2024-04-22T14:00:00.000Z",
|
||||||
|
"updatedAt": "2024-04-22T14:00:00.000Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": 2,
|
||||||
|
"templateId": 5,
|
||||||
|
"source": "TEMPLATE",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_789",
|
||||||
|
"subject": "Employment Contract",
|
||||||
|
"message": "Please review and sign your employment contract.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 60,
|
||||||
|
"documentId": 15,
|
||||||
|
"templateId": 5,
|
||||||
|
"email": "newemployee@company.com",
|
||||||
|
"name": "New Employee",
|
||||||
|
"token": "DocToken456",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": null,
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "NOT_OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "NOT_SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T14:00:01.000Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example payload for the `recipient.authentication.failed` event:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "RECIPIENT_AUTHENTICATION_FAILED",
|
||||||
|
"payload": {
|
||||||
|
"id": 10,
|
||||||
|
"externalId": null,
|
||||||
|
"userId": 1,
|
||||||
|
"authOptions": null,
|
||||||
|
"formValues": null,
|
||||||
|
"visibility": "EVERYONE",
|
||||||
|
"title": "documenso.pdf",
|
||||||
|
"status": "PENDING",
|
||||||
|
"documentDataId": "hs8qz1ktr9204jn7mg6c5dxy0",
|
||||||
|
"createdAt": "2024-04-22T11:44:43.341Z",
|
||||||
|
"updatedAt": "2024-04-22T11:48:07.569Z",
|
||||||
|
"completedAt": null,
|
||||||
|
"deletedAt": null,
|
||||||
|
"teamId": null,
|
||||||
|
"templateId": null,
|
||||||
|
"source": "DOCUMENT",
|
||||||
|
"documentMeta": {
|
||||||
|
"id": "doc_meta_123",
|
||||||
|
"subject": "Please sign this document",
|
||||||
|
"message": "Hello, please review and sign this document.",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"password": null,
|
||||||
|
"dateFormat": "MM/DD/YYYY",
|
||||||
|
"redirectUrl": null,
|
||||||
|
"signingOrder": "PARALLEL",
|
||||||
|
"typedSignatureEnabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"distributionMethod": "EMAIL",
|
||||||
|
"emailSettings": null
|
||||||
|
},
|
||||||
|
"Recipient": [
|
||||||
|
{
|
||||||
|
"id": 52,
|
||||||
|
"documentId": 10,
|
||||||
|
"templateId": null,
|
||||||
|
"email": "signer@documenso.com",
|
||||||
|
"name": "Signer",
|
||||||
|
"token": "vbT8hi3jKQmrFP_LN1WcS",
|
||||||
|
"documentDeletedAt": null,
|
||||||
|
"expired": null,
|
||||||
|
"signedAt": null,
|
||||||
|
"authOptions": {
|
||||||
|
"accessAuth": "TWO_FACTOR_AUTH",
|
||||||
|
"actionAuth": null
|
||||||
|
},
|
||||||
|
"signingOrder": 1,
|
||||||
|
"rejectionReason": null,
|
||||||
|
"role": "SIGNER",
|
||||||
|
"readStatus": "NOT_OPENED",
|
||||||
|
"signingStatus": "NOT_SIGNED",
|
||||||
|
"sendStatus": "SENT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"createdAt": "2024-04-22T11:49:00.000Z",
|
||||||
|
"webhookEndpoint": "https://mywebhooksite.com/mywebhook"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Webhook Events Testing
|
## Webhook Events Testing
|
||||||
|
|
||||||
You can trigger test webhook events to test the webhook functionality. To trigger a test webhook, navigate to the [Webhooks page](/developers/webhooks) and click on the "Test Webhook" button.
|
You can trigger test webhook events to test the webhook functionality. To trigger a test webhook, navigate to the [Webhooks page](/developers/webhooks) and click on the "Test Webhook" button.
|
||||||
|
|||||||
@ -242,6 +242,7 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
try {
|
try {
|
||||||
await updateEnvelope({
|
await updateEnvelope({
|
||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
|
envelopeType: envelope.type,
|
||||||
data: {
|
data: {
|
||||||
externalId: data.externalId || null,
|
externalId: data.externalId || null,
|
||||||
visibility: data.visibility,
|
visibility: data.visibility,
|
||||||
|
|||||||
@ -142,7 +142,7 @@ export const EnvelopeEditorUploadPage = () => {
|
|||||||
|
|
||||||
const { createdEnvelopeItems } = await createEnvelopeItems({
|
const { createdEnvelopeItems } = await createEnvelopeItems({
|
||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
data: envelopeItemsToCreate,
|
items: envelopeItemsToCreate,
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
|
|||||||
38
package-lock.json
generated
@ -12557,16 +12557,6 @@
|
|||||||
"@types/pg": "*"
|
"@types/pg": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/pngjs": {
|
|
||||||
"version": "6.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/pngjs/-/pngjs-6.0.5.tgz",
|
|
||||||
"integrity": "sha512-0k5eKfrA83JOZPppLtS2C7OUtyNAl2wKNxfyYl9Q5g9lPkgBl/9hNyAu6HuEH2J4XmIv2znEpkDd0SaZVxW6iQ==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/prop-types": {
|
"node_modules/@types/prop-types": {
|
||||||
"version": "15.7.14",
|
"version": "15.7.14",
|
||||||
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.14.tgz",
|
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.14.tgz",
|
||||||
@ -27554,19 +27544,6 @@
|
|||||||
"node": ">= 6"
|
"node": ">= 6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/pixelmatch": {
|
|
||||||
"version": "7.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pixelmatch/-/pixelmatch-7.1.0.tgz",
|
|
||||||
"integrity": "sha512-1wrVzJ2STrpmONHKBy228LM1b84msXDUoAzVEl0R8Mz4Ce6EPr+IVtxm8+yvrqLYMHswREkjYFaMxnyGnaY3Ng==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"pngjs": "^7.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"pixelmatch": "bin/pixelmatch"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pkg-dir": {
|
"node_modules/pkg-dir": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz",
|
||||||
@ -27763,16 +27740,6 @@
|
|||||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/pngjs": {
|
|
||||||
"version": "7.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-7.0.0.tgz",
|
|
||||||
"integrity": "sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=14.19.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/pofile": {
|
"node_modules/pofile": {
|
||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/pofile/-/pofile-1.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/pofile/-/pofile-1.1.4.tgz",
|
||||||
@ -36216,10 +36183,7 @@
|
|||||||
"@documenso/lib": "*",
|
"@documenso/lib": "*",
|
||||||
"@documenso/prisma": "*",
|
"@documenso/prisma": "*",
|
||||||
"@playwright/test": "1.52.0",
|
"@playwright/test": "1.52.0",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20"
|
||||||
"@types/pngjs": "^6.0.5",
|
|
||||||
"pixelmatch": "^7.1.0",
|
|
||||||
"pngjs": "^7.0.0"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/app-tests/node_modules/@playwright/test": {
|
"packages/app-tests/node_modules/@playwright/test": {
|
||||||
|
|||||||
@ -20,12 +20,12 @@ import {
|
|||||||
getEnvelopeWhereInput,
|
getEnvelopeWhereInput,
|
||||||
} from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
} from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||||
import { deleteDocumentField } from '@documenso/lib/server-only/field/delete-document-field';
|
import { deleteDocumentField } from '@documenso/lib/server-only/field/delete-document-field';
|
||||||
import { updateEnvelopeFields } from '@documenso/lib/server-only/field/update-envelope-fields';
|
import { updateDocumentFields } from '@documenso/lib/server-only/field/update-document-fields';
|
||||||
import { insertFormValuesInPdf } from '@documenso/lib/server-only/pdf/insert-form-values-in-pdf';
|
import { insertFormValuesInPdf } from '@documenso/lib/server-only/pdf/insert-form-values-in-pdf';
|
||||||
import { deleteEnvelopeRecipient } from '@documenso/lib/server-only/recipient/delete-envelope-recipient';
|
import { deleteDocumentRecipient } from '@documenso/lib/server-only/recipient/delete-document-recipient';
|
||||||
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
||||||
import { setDocumentRecipients } from '@documenso/lib/server-only/recipient/set-document-recipients';
|
import { setDocumentRecipients } from '@documenso/lib/server-only/recipient/set-document-recipients';
|
||||||
import { updateEnvelopeRecipients } from '@documenso/lib/server-only/recipient/update-envelope-recipients';
|
import { updateDocumentRecipients } from '@documenso/lib/server-only/recipient/update-document-recipients';
|
||||||
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
||||||
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
||||||
import { findTemplates } from '@documenso/lib/server-only/template/find-templates';
|
import { findTemplates } from '@documenso/lib/server-only/template/find-templates';
|
||||||
@ -1285,7 +1285,7 @@ export const ApiContractV1Implementation = tsr.router(ApiContractV1, {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedRecipient = await updateEnvelopeRecipients({
|
const updatedRecipient = await updateDocumentRecipients({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
id: {
|
id: {
|
||||||
@ -1336,7 +1336,7 @@ export const ApiContractV1Implementation = tsr.router(ApiContractV1, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const deletedRecipient = await deleteEnvelopeRecipient({
|
const deletedRecipient = await deleteDocumentRecipient({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
recipientId: Number(recipientId),
|
recipientId: Number(recipientId),
|
||||||
@ -1634,13 +1634,10 @@ export const ApiContractV1Implementation = tsr.router(ApiContractV1, {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { fields } = await updateEnvelopeFields({
|
const { fields } = await updateDocumentFields({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
id: {
|
documentId: legacyDocumentId,
|
||||||
type: 'documentId',
|
|
||||||
id: legacyDocumentId,
|
|
||||||
},
|
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
id: Number(fieldId),
|
id: Number(fieldId),
|
||||||
|
|||||||
@ -1,498 +0,0 @@
|
|||||||
import { FieldType } from '@prisma/client';
|
|
||||||
|
|
||||||
import type { TFieldAndMeta } from '@documenso/lib/types/field-meta';
|
|
||||||
import { toCheckboxCustomText } from '@documenso/lib/utils/fields';
|
|
||||||
|
|
||||||
export type FieldTestData = TFieldAndMeta & {
|
|
||||||
page: number;
|
|
||||||
positionX: number;
|
|
||||||
positionY: number;
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
customText: string;
|
|
||||||
signature?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const columnWidth = 19.125;
|
|
||||||
const rowHeight = 6.7;
|
|
||||||
|
|
||||||
const alignmentGridStartX = 31;
|
|
||||||
const alignmentGridStartY = 19.02;
|
|
||||||
|
|
||||||
export const ALIGNMENT_TEST_FIELDS: FieldTestData[] = [
|
|
||||||
/**
|
|
||||||
* Row 1 EMAIL
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.EMAIL,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
textAlign: 'left',
|
|
||||||
type: 'email',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'admin@documenso.com',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.EMAIL,
|
|
||||||
fieldMeta: {
|
|
||||||
textAlign: 'center',
|
|
||||||
type: 'email',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'admin@documenso.com',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.EMAIL,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
textAlign: 'right',
|
|
||||||
type: 'email',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'admin@documenso.com',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 2 NAME
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.NAME,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
textAlign: 'left',
|
|
||||||
type: 'name',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'John Doe',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NAME,
|
|
||||||
fieldMeta: {
|
|
||||||
textAlign: 'center',
|
|
||||||
type: 'name',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'John Doe',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NAME,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
textAlign: 'right',
|
|
||||||
type: 'name',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'John Doe',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 3 DATE
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.DATE,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
textAlign: 'left',
|
|
||||||
type: 'date',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.DATE,
|
|
||||||
fieldMeta: {
|
|
||||||
textAlign: 'center',
|
|
||||||
type: 'date',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.DATE,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
textAlign: 'right',
|
|
||||||
type: 'date',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 4 TEXT
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
textAlign: 'left',
|
|
||||||
type: 'text',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
textAlign: 'center',
|
|
||||||
type: 'text',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
textAlign: 'right',
|
|
||||||
type: 'text',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 5 NUMBER
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
textAlign: 'left',
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
textAlign: 'center',
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
textAlign: 'right',
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 6 Initials
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.INITIALS,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
textAlign: 'left',
|
|
||||||
type: 'initials',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'JD',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.INITIALS,
|
|
||||||
fieldMeta: {
|
|
||||||
textAlign: 'center',
|
|
||||||
type: 'initials',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'JD',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.INITIALS,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
textAlign: 'right',
|
|
||||||
type: 'initials',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'JD',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 7 Radio
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.RADIO,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'radio',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: true, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '0',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.RADIO,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'radio',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: true, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '2',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.RADIO,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
direction: 'horizontal',
|
|
||||||
type: 'radio',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 8 Checkbox
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: true, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: toCheckboxCustomText([0]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: true, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: toCheckboxCustomText([1]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
direction: 'horizontal',
|
|
||||||
type: 'checkbox',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 8 Dropdown
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.DROPDOWN,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
|
||||||
type: 'dropdown',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'Option 1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.DROPDOWN,
|
|
||||||
fieldMeta: {
|
|
||||||
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
|
||||||
type: 'dropdown',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'Option 1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.DROPDOWN,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
values: [{ value: 'Option 1' }, { value: 'Option 2' }, { value: 'Option 3' }],
|
|
||||||
type: 'dropdown',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: 'Option 1',
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Row 9 Signature
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.SIGNATURE,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 10,
|
|
||||||
type: 'signature',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '',
|
|
||||||
signature: 'My Signature',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.SIGNATURE,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'signature',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '',
|
|
||||||
signature: 'My Signature',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.SIGNATURE,
|
|
||||||
fieldMeta: {
|
|
||||||
fontSize: 20,
|
|
||||||
type: 'signature',
|
|
||||||
},
|
|
||||||
page: 1,
|
|
||||||
height: rowHeight,
|
|
||||||
width: columnWidth,
|
|
||||||
positionX: 0,
|
|
||||||
positionY: 0,
|
|
||||||
customText: '',
|
|
||||||
signature: 'My Signature',
|
|
||||||
},
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export const formatAlignmentTestFields = ALIGNMENT_TEST_FIELDS.map((field, index) => {
|
|
||||||
const row = Math.floor(index / 3);
|
|
||||||
const column = index % 3;
|
|
||||||
|
|
||||||
return {
|
|
||||||
...field,
|
|
||||||
positionX: alignmentGridStartX + column * columnWidth,
|
|
||||||
positionY: alignmentGridStartY + row * rowHeight,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
@ -1,482 +0,0 @@
|
|||||||
import { FieldType } from '@prisma/client';
|
|
||||||
|
|
||||||
import { toCheckboxCustomText } from '@documenso/lib/utils/fields';
|
|
||||||
import {
|
|
||||||
CheckboxValidationRules,
|
|
||||||
numberFormatValues,
|
|
||||||
} from '@documenso/ui/primitives/document-flow/field-items-advanced-settings/constants';
|
|
||||||
|
|
||||||
import type { FieldTestData } from './field-alignment-pdf';
|
|
||||||
|
|
||||||
const columnWidth = 20.1;
|
|
||||||
const fullColumnWidth = 75.8;
|
|
||||||
const rowHeight = 9.8;
|
|
||||||
const rowPadding = 1.8;
|
|
||||||
|
|
||||||
const alignmentGridStartX = 11.85;
|
|
||||||
const alignmentGridStartY = 15.07;
|
|
||||||
|
|
||||||
const calculatePosition = (row: number, column: number, width: 'full' | 'column' = 'column') => {
|
|
||||||
return {
|
|
||||||
height: rowHeight,
|
|
||||||
width: width === 'full' ? fullColumnWidth : columnWidth,
|
|
||||||
positionX: alignmentGridStartX + (column ?? 0) * columnWidth,
|
|
||||||
positionY: alignmentGridStartY + row * (rowHeight + rowPadding),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const FIELD_META_TEST_FIELDS: FieldTestData[] = [
|
|
||||||
/**
|
|
||||||
* PAGE 2 Signature
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.SIGNATURE,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'signature',
|
|
||||||
},
|
|
||||||
page: 2,
|
|
||||||
...calculatePosition(0, 0),
|
|
||||||
customText: '',
|
|
||||||
signature: 'My Signature',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.SIGNATURE,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'signature',
|
|
||||||
},
|
|
||||||
page: 2,
|
|
||||||
...calculatePosition(1, 0),
|
|
||||||
customText: '',
|
|
||||||
signature: 'My Signature',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.SIGNATURE,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'signature',
|
|
||||||
},
|
|
||||||
page: 2,
|
|
||||||
...calculatePosition(2, 0),
|
|
||||||
customText: '',
|
|
||||||
signature: 'My Signature',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.SIGNATURE,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'signature',
|
|
||||||
},
|
|
||||||
page: 2,
|
|
||||||
...calculatePosition(3, 0),
|
|
||||||
customText: '',
|
|
||||||
signature: 'My Signature',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PAGE 3 TEXT
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(0, 0, 'full'),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(1, 0),
|
|
||||||
customText: '123456789123456789123456789123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
characterLimit: 5,
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(2, 0),
|
|
||||||
customText: '12345',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
placeholder: 'Demo Placeholder',
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(3, 0),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
label: 'Demo Label',
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(3, 1),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
text: 'Prefilled text',
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(3, 2),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(4, 0),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.TEXT,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'text',
|
|
||||||
readOnly: true,
|
|
||||||
text: 'Readonly Value',
|
|
||||||
},
|
|
||||||
page: 3,
|
|
||||||
...calculatePosition(4, 1),
|
|
||||||
customText: 'Readonly Value',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PAGE 4 NUMBER
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(0, 0, 'full'),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(1, 0),
|
|
||||||
customText: '123456789123456789123456789123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
minValue: 0,
|
|
||||||
maxValue: 100,
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(2, 0),
|
|
||||||
customText: '50',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
numberFormat: numberFormatValues[0].value, // Todo: Envelopes - Check this.
|
|
||||||
value: '123,456,789.00',
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(2, 1),
|
|
||||||
customText: '123,456,789.00',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
placeholder: 'Demo Placeholder',
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(3, 0),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
label: 'Demo Label',
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(3, 1),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
value: '123',
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(3, 2),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(4, 0),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
fieldMeta: {
|
|
||||||
type: 'number',
|
|
||||||
readOnly: true,
|
|
||||||
},
|
|
||||||
page: 4,
|
|
||||||
...calculatePosition(4, 1),
|
|
||||||
customText: '123456789',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PAGE 5 RADIO
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.RADIO,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'horizontal',
|
|
||||||
type: 'radio',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: true, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
{ id: 3, checked: false, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 5,
|
|
||||||
...calculatePosition(0, 0, 'full'),
|
|
||||||
customText: '0',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.RADIO,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'radio',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: true, value: 'Option 2' },
|
|
||||||
{ id: 3, checked: false, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 5,
|
|
||||||
...calculatePosition(1, 0),
|
|
||||||
customText: '2',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.RADIO,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'radio',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
{ id: 3, checked: false, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 5,
|
|
||||||
...calculatePosition(2, 0),
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.RADIO,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'radio',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
{ id: 3, checked: false, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 5,
|
|
||||||
...calculatePosition(2, 1),
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PAGE 6 CHECKBOX
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'horizontal',
|
|
||||||
type: 'checkbox',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: true, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 3' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 4' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 6,
|
|
||||||
...calculatePosition(0, 0, 'full'),
|
|
||||||
customText: toCheckboxCustomText([0]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: true, value: 'Option 2' },
|
|
||||||
{ id: 2, checked: true, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 6,
|
|
||||||
...calculatePosition(1, 0),
|
|
||||||
customText: toCheckboxCustomText([1]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
required: true,
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 6,
|
|
||||||
...calculatePosition(2, 0),
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
readOnly: true,
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 6,
|
|
||||||
...calculatePosition(2, 1),
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
validationRule: CheckboxValidationRules.SELECT_AT_LEAST,
|
|
||||||
validationLength: 2,
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
{ id: 3, checked: false, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 6,
|
|
||||||
...calculatePosition(3, 0),
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
validationRule: CheckboxValidationRules.SELECT_EXACTLY,
|
|
||||||
validationLength: 2,
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
{ id: 3, checked: false, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 6,
|
|
||||||
...calculatePosition(3, 1),
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.CHECKBOX,
|
|
||||||
fieldMeta: {
|
|
||||||
direction: 'vertical',
|
|
||||||
type: 'checkbox',
|
|
||||||
validationRule: CheckboxValidationRules.SELECT_AT_MOST,
|
|
||||||
validationLength: 2,
|
|
||||||
values: [
|
|
||||||
{ id: 1, checked: false, value: 'Option 1' },
|
|
||||||
{ id: 2, checked: false, value: 'Option 2' },
|
|
||||||
{ id: 3, checked: false, value: 'Option 3' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
page: 6,
|
|
||||||
...calculatePosition(3, 2),
|
|
||||||
customText: '',
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PAGE 7 DROPDOWN
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
type: FieldType.DROPDOWN,
|
|
||||||
fieldMeta: {
|
|
||||||
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
|
||||||
type: 'dropdown',
|
|
||||||
},
|
|
||||||
page: 7,
|
|
||||||
...calculatePosition(0, 0, 'full'),
|
|
||||||
customText: 'Option 1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.DROPDOWN,
|
|
||||||
fieldMeta: {
|
|
||||||
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
|
||||||
type: 'dropdown',
|
|
||||||
defaultValue: 'Option 1',
|
|
||||||
},
|
|
||||||
page: 7,
|
|
||||||
...calculatePosition(1, 0),
|
|
||||||
customText: 'Option 1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.DROPDOWN,
|
|
||||||
fieldMeta: {
|
|
||||||
values: [{ value: 'Option 1' }, { value: 'Option 2' }, { value: 'Option 3' }],
|
|
||||||
type: 'dropdown',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
page: 7,
|
|
||||||
...calculatePosition(2, 0),
|
|
||||||
customText: 'Option 1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: FieldType.DROPDOWN,
|
|
||||||
fieldMeta: {
|
|
||||||
values: [{ value: 'Option 1' }, { value: 'Option 2' }, { value: 'Option 3' }],
|
|
||||||
type: 'dropdown',
|
|
||||||
readOnly: true,
|
|
||||||
},
|
|
||||||
page: 7,
|
|
||||||
...calculatePosition(2, 1),
|
|
||||||
customText: 'Option 1',
|
|
||||||
},
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export const formatFieldMetaTestFields = FIELD_META_TEST_FIELDS.map((field, index) => {
|
|
||||||
return {
|
|
||||||
...field,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
@ -1,264 +0,0 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
|
||||||
import type { Team, User } from '@prisma/client';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
|
||||||
import { incrementDocumentId } from '@documenso/lib/server-only/envelope/increment-id';
|
|
||||||
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
|
||||||
import { prefixedId } from '@documenso/lib/universal/id';
|
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
import {
|
|
||||||
DocumentSource,
|
|
||||||
DocumentVisibility,
|
|
||||||
EnvelopeType,
|
|
||||||
RecipientRole,
|
|
||||||
} from '@documenso/prisma/client';
|
|
||||||
import { seedUser } from '@documenso/prisma/seed/users';
|
|
||||||
import type { TCreateEnvelopeItemsRequest } from '@documenso/trpc/server/envelope-router/create-envelope-items.types';
|
|
||||||
import type { TCreateEnvelopeRecipientsRequest } from '@documenso/trpc/server/envelope-router/envelope-recipients/create-envelope-recipients.types';
|
|
||||||
import type { TGetEnvelopeResponse } from '@documenso/trpc/server/envelope-router/get-envelope.types';
|
|
||||||
import type { TUpdateEnvelopeRequest } from '@documenso/trpc/server/envelope-router/update-envelope.types';
|
|
||||||
|
|
||||||
import { formatAlignmentTestFields } from '../../../constants/field-alignment-pdf';
|
|
||||||
import { FIELD_META_TEST_FIELDS } from '../../../constants/field-meta-pdf';
|
|
||||||
|
|
||||||
const WEBAPP_BASE_URL = NEXT_PUBLIC_WEBAPP_URL();
|
|
||||||
const baseUrl = `${WEBAPP_BASE_URL}/api/v2-beta`;
|
|
||||||
|
|
||||||
test.describe.configure({
|
|
||||||
mode: 'parallel',
|
|
||||||
});
|
|
||||||
|
|
||||||
test.describe('API V2 Envelopes', () => {
|
|
||||||
let userA: User, teamA: Team, userB: User, teamB: Team, tokenA: string, tokenB: string;
|
|
||||||
|
|
||||||
test.beforeEach(async () => {
|
|
||||||
({ user: userA, team: teamA } = await seedUser());
|
|
||||||
({ token: tokenA } = await createApiToken({
|
|
||||||
userId: userA.id,
|
|
||||||
teamId: teamA.id,
|
|
||||||
tokenName: 'userA',
|
|
||||||
expiresIn: null,
|
|
||||||
}));
|
|
||||||
|
|
||||||
({ user: userB, team: teamB } = await seedUser());
|
|
||||||
({ token: tokenB } = await createApiToken({
|
|
||||||
userId: userB.id,
|
|
||||||
teamId: teamB.id,
|
|
||||||
tokenName: 'userB',
|
|
||||||
expiresIn: null,
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates envelopes with the two field test PDFs.
|
|
||||||
*/
|
|
||||||
test('Envelope full test', async ({ request }) => {
|
|
||||||
// Step 1: Create initial envelope with Prisma (with first envelope item)
|
|
||||||
const alignmentPdf = fs
|
|
||||||
.readFileSync(path.join(__dirname, '../../../../../assets/field-font-alignment.pdf'))
|
|
||||||
.toString('base64');
|
|
||||||
|
|
||||||
const fieldMetaPdf = fs
|
|
||||||
.readFileSync(path.join(__dirname, '../../../../../assets/field-meta.pdf'))
|
|
||||||
.toString('base64');
|
|
||||||
|
|
||||||
const alignmentDocumentData = await prisma.documentData.create({
|
|
||||||
data: {
|
|
||||||
type: 'BYTES_64',
|
|
||||||
data: alignmentPdf,
|
|
||||||
initialData: alignmentPdf,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const documentId = await incrementDocumentId();
|
|
||||||
const documentMeta = await prisma.documentMeta.create({
|
|
||||||
data: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
const createdEnvelope = await prisma.envelope.create({
|
|
||||||
data: {
|
|
||||||
id: prefixedId('envelope'),
|
|
||||||
secondaryId: documentId.formattedDocumentId,
|
|
||||||
internalVersion: 2,
|
|
||||||
type: EnvelopeType.DOCUMENT,
|
|
||||||
documentMetaId: documentMeta.id,
|
|
||||||
source: DocumentSource.DOCUMENT,
|
|
||||||
title: `Envelope Full Field Test`,
|
|
||||||
status: 'DRAFT',
|
|
||||||
userId: userA.id,
|
|
||||||
teamId: teamA.id,
|
|
||||||
envelopeItems: {
|
|
||||||
create: {
|
|
||||||
id: prefixedId('envelope_item'),
|
|
||||||
title: `Alignment Test`,
|
|
||||||
documentDataId: alignmentDocumentData.id,
|
|
||||||
order: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
envelopeItems: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Step 2: Create second envelope item via API
|
|
||||||
const fieldMetaDocumentData = await prisma.documentData.create({
|
|
||||||
data: {
|
|
||||||
type: 'BYTES_64',
|
|
||||||
data: fieldMetaPdf,
|
|
||||||
initialData: fieldMetaPdf,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const createEnvelopeItemsRequest: TCreateEnvelopeItemsRequest = {
|
|
||||||
envelopeId: createdEnvelope.id,
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
title: 'Field Meta Test',
|
|
||||||
documentDataId: fieldMetaDocumentData.id,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const createItemsRes = await request.post(`${baseUrl}/envelope/item/create-many`, {
|
|
||||||
headers: { Authorization: `Bearer ${tokenA}` },
|
|
||||||
data: createEnvelopeItemsRequest,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(createItemsRes.ok()).toBeTruthy();
|
|
||||||
expect(createItemsRes.status()).toBe(200);
|
|
||||||
|
|
||||||
// Step 3: Update envelope via API
|
|
||||||
const updateEnvelopeRequest: TUpdateEnvelopeRequest = {
|
|
||||||
envelopeId: createdEnvelope.id,
|
|
||||||
envelopeType: EnvelopeType.DOCUMENT,
|
|
||||||
data: {
|
|
||||||
title: 'Envelope Full Field Test',
|
|
||||||
visibility: DocumentVisibility.MANAGER_AND_ABOVE,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateRes = await request.post(`${baseUrl}/envelope/update`, {
|
|
||||||
headers: { Authorization: `Bearer ${tokenA}` },
|
|
||||||
data: updateEnvelopeRequest,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(updateRes.ok()).toBeTruthy();
|
|
||||||
expect(updateRes.status()).toBe(200);
|
|
||||||
|
|
||||||
// Step 4: Create recipient via API
|
|
||||||
const createRecipientsRequest: TCreateEnvelopeRecipientsRequest = {
|
|
||||||
envelopeId: createdEnvelope.id,
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
email: userA.email,
|
|
||||||
name: userA.name || '',
|
|
||||||
role: RecipientRole.SIGNER,
|
|
||||||
accessAuth: [],
|
|
||||||
actionAuth: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const createRecipientsRes = await request.post(`${baseUrl}/envelope/recipient/create-many`, {
|
|
||||||
headers: { Authorization: `Bearer ${tokenA}` },
|
|
||||||
data: createRecipientsRequest,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(createRecipientsRes.ok()).toBeTruthy();
|
|
||||||
expect(createRecipientsRes.status()).toBe(200);
|
|
||||||
|
|
||||||
// Step 5: Get envelope to retrieve recipients and envelope items
|
|
||||||
const getRes = await request.get(`${baseUrl}/envelope/${createdEnvelope.id}`, {
|
|
||||||
headers: { Authorization: `Bearer ${tokenA}` },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(getRes.ok()).toBeTruthy();
|
|
||||||
expect(getRes.status()).toBe(200);
|
|
||||||
|
|
||||||
const envelopeResponse = (await getRes.json()) as TGetEnvelopeResponse;
|
|
||||||
|
|
||||||
const recipientId = envelopeResponse.recipients[0].id;
|
|
||||||
const alignmentItem = envelopeResponse.envelopeItems.find(
|
|
||||||
(item: { order: number }) => item.order === 1,
|
|
||||||
);
|
|
||||||
const fieldMetaItem = envelopeResponse.envelopeItems.find(
|
|
||||||
(item: { order: number }) => item.order === 2,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(recipientId).toBeDefined();
|
|
||||||
expect(alignmentItem).toBeDefined();
|
|
||||||
expect(fieldMetaItem).toBeDefined();
|
|
||||||
|
|
||||||
if (!alignmentItem || !fieldMetaItem) {
|
|
||||||
throw new Error('Envelope items not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 6: Create fields for first PDF (alignment fields)
|
|
||||||
const alignmentFieldsRequest = {
|
|
||||||
envelopeId: createdEnvelope.id,
|
|
||||||
data: formatAlignmentTestFields.map((field) => ({
|
|
||||||
recipientId,
|
|
||||||
envelopeItemId: alignmentItem.id,
|
|
||||||
type: field.type,
|
|
||||||
page: field.page,
|
|
||||||
positionX: field.positionX,
|
|
||||||
positionY: field.positionY,
|
|
||||||
width: field.width,
|
|
||||||
height: field.height,
|
|
||||||
fieldMeta: field.fieldMeta,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
|
|
||||||
const createAlignmentFieldsRes = await request.post(`${baseUrl}/envelope/field/create-many`, {
|
|
||||||
headers: { Authorization: `Bearer ${tokenA}` },
|
|
||||||
data: alignmentFieldsRequest,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(createAlignmentFieldsRes.ok()).toBeTruthy();
|
|
||||||
expect(createAlignmentFieldsRes.status()).toBe(200);
|
|
||||||
|
|
||||||
// Step 7: Create fields for second PDF (field-meta fields)
|
|
||||||
const fieldMetaFieldsRequest = {
|
|
||||||
envelopeId: createdEnvelope.id,
|
|
||||||
data: FIELD_META_TEST_FIELDS.map((field) => ({
|
|
||||||
recipientId,
|
|
||||||
envelopeItemId: fieldMetaItem.id,
|
|
||||||
type: field.type,
|
|
||||||
page: field.page,
|
|
||||||
positionX: field.positionX,
|
|
||||||
positionY: field.positionY,
|
|
||||||
width: field.width,
|
|
||||||
height: field.height,
|
|
||||||
fieldMeta: field.fieldMeta,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
|
|
||||||
const createFieldMetaFieldsRes = await request.post(`${baseUrl}/envelope/field/create-many`, {
|
|
||||||
headers: { Authorization: `Bearer ${tokenA}` },
|
|
||||||
data: fieldMetaFieldsRequest,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(createFieldMetaFieldsRes.ok()).toBeTruthy();
|
|
||||||
expect(createFieldMetaFieldsRes.status()).toBe(200);
|
|
||||||
|
|
||||||
// Step 8: Verify final envelope structure
|
|
||||||
const finalGetRes = await request.get(`${baseUrl}/envelope/${createdEnvelope.id}`, {
|
|
||||||
headers: { Authorization: `Bearer ${tokenA}` },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(finalGetRes.ok()).toBeTruthy();
|
|
||||||
const finalEnvelope = (await finalGetRes.json()) as TGetEnvelopeResponse;
|
|
||||||
|
|
||||||
// Verify structure
|
|
||||||
expect(finalEnvelope.envelopeItems.length).toBe(2);
|
|
||||||
expect(finalEnvelope.recipients.length).toBe(1);
|
|
||||||
expect(finalEnvelope.fields.length).toBe(
|
|
||||||
formatAlignmentTestFields.length + FIELD_META_TEST_FIELDS.length,
|
|
||||||
);
|
|
||||||
expect(finalEnvelope.title).toBe('Envelope Full Field Test');
|
|
||||||
expect(finalEnvelope.type).toBe(EnvelopeType.DOCUMENT);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,282 +0,0 @@
|
|||||||
// sort-imports-ignore
|
|
||||||
|
|
||||||
// ---- PATCH pdfjs-dist's canvas require BEFORE importing it ----
|
|
||||||
import Module from 'module';
|
|
||||||
import { Canvas, Image } from 'skia-canvas';
|
|
||||||
|
|
||||||
// Intercept require('canvas') and return skia-canvas equivalents
|
|
||||||
const originalRequire = Module.prototype.require;
|
|
||||||
Module.prototype.require = function (path: string) {
|
|
||||||
if (path === 'canvas') {
|
|
||||||
return {
|
|
||||||
createCanvas: (width: number, height: number) => new Canvas(width, height),
|
|
||||||
Image, // needed by pdfjs-dist
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line prefer-rest-params, @typescript-eslint/consistent-type-assertions
|
|
||||||
return originalRequire.apply(this, arguments as unknown as [string]);
|
|
||||||
};
|
|
||||||
|
|
||||||
import pixelMatch from 'pixelmatch';
|
|
||||||
import { PNG } from 'pngjs';
|
|
||||||
import type { TestInfo } from '@playwright/test';
|
|
||||||
import { expect, test } from '@playwright/test';
|
|
||||||
import { DocumentStatus } from '@prisma/client';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import path from 'node:path';
|
|
||||||
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.js';
|
|
||||||
|
|
||||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
import { seedAlignmentTestDocument } from '@documenso/prisma/seed/initial-seed';
|
|
||||||
import { seedUser } from '@documenso/prisma/seed/users';
|
|
||||||
|
|
||||||
import { apiSignin } from '../fixtures/authentication';
|
|
||||||
|
|
||||||
test.describe.configure({ mode: 'parallel', timeout: 60000 });
|
|
||||||
|
|
||||||
test('field placement visual regression', async ({ page }, testInfo) => {
|
|
||||||
const { user, team } = await seedUser();
|
|
||||||
|
|
||||||
const envelope = await seedAlignmentTestDocument({
|
|
||||||
userId: user.id,
|
|
||||||
teamId: team.id,
|
|
||||||
recipientName: user.name || '',
|
|
||||||
recipientEmail: user.email,
|
|
||||||
insertFields: true,
|
|
||||||
status: DocumentStatus.PENDING,
|
|
||||||
});
|
|
||||||
|
|
||||||
const token = envelope.recipients[0].token;
|
|
||||||
|
|
||||||
const signUrl = `/sign/${token}`;
|
|
||||||
|
|
||||||
await apiSignin({
|
|
||||||
page,
|
|
||||||
email: user.email,
|
|
||||||
redirectPath: signUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
|
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Complete' }).click();
|
|
||||||
await page.getByRole('button', { name: 'Sign' }).click();
|
|
||||||
await page.waitForURL(`${signUrl}/complete`);
|
|
||||||
|
|
||||||
await expect(async () => {
|
|
||||||
const { status } = await prisma.envelope.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
id: envelope.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(status).toBe(DocumentStatus.COMPLETED);
|
|
||||||
}).toPass({
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
const completedDocument = await prisma.envelope.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
id: envelope.id,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
envelopeItems: {
|
|
||||||
orderBy: {
|
|
||||||
order: 'asc',
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
documentData: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const storedImages = fs.readdirSync(path.join(__dirname, '../../visual-regression'));
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
completedDocument.envelopeItems.map(async (item) => {
|
|
||||||
const pdfData = await getFile(item.documentData);
|
|
||||||
|
|
||||||
const loadedImages = storedImages
|
|
||||||
.filter((image) => image.includes(item.title))
|
|
||||||
.map((image) => fs.readFileSync(path.join(__dirname, '../../visual-regression', image)));
|
|
||||||
|
|
||||||
await compareSignedPdfWithImages({
|
|
||||||
id: item.title.replaceAll(' ', '-').toLowerCase(),
|
|
||||||
pdfData,
|
|
||||||
images: loadedImages,
|
|
||||||
testInfo,
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to download the envelope images when updating the visual regression test.
|
|
||||||
*
|
|
||||||
* DON'T COMMIT THIS WITHOUT THE "SKIP" COMMAND.
|
|
||||||
*/
|
|
||||||
test.skip('download envelope images', async ({ page }) => {
|
|
||||||
const { user, team } = await seedUser();
|
|
||||||
|
|
||||||
const envelope = await seedAlignmentTestDocument({
|
|
||||||
userId: user.id,
|
|
||||||
teamId: team.id,
|
|
||||||
recipientName: user.name || '',
|
|
||||||
recipientEmail: user.email,
|
|
||||||
insertFields: true,
|
|
||||||
status: DocumentStatus.PENDING,
|
|
||||||
});
|
|
||||||
|
|
||||||
const token = envelope.recipients[0].token;
|
|
||||||
|
|
||||||
const signUrl = `/sign/${token}`;
|
|
||||||
|
|
||||||
await apiSignin({
|
|
||||||
page,
|
|
||||||
email: user.email,
|
|
||||||
redirectPath: signUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
|
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Complete' }).click();
|
|
||||||
await page.getByRole('button', { name: 'Sign' }).click();
|
|
||||||
await page.waitForURL(`${signUrl}/complete`);
|
|
||||||
|
|
||||||
await expect(async () => {
|
|
||||||
const { status } = await prisma.envelope.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
id: envelope.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(status).toBe(DocumentStatus.COMPLETED);
|
|
||||||
}).toPass({
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
const completedDocument = await prisma.envelope.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
id: envelope.id,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
envelopeItems: {
|
|
||||||
orderBy: {
|
|
||||||
order: 'asc',
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
documentData: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
completedDocument.envelopeItems.map(async (item) => {
|
|
||||||
const pdfData = await getFile(item.documentData);
|
|
||||||
|
|
||||||
const pdfImages = await renderPdfToImage(pdfData);
|
|
||||||
|
|
||||||
for (const [index, { image }] of pdfImages.entries()) {
|
|
||||||
fs.writeFileSync(
|
|
||||||
path.join(__dirname, '../../visual-regression', `${item.title}-${index}.png`),
|
|
||||||
new Uint8Array(image),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
async function renderPdfToImage(pdfBytes: Uint8Array) {
|
|
||||||
const loadingTask = pdfjsLib.getDocument({ data: pdfBytes });
|
|
||||||
const pdf = await loadingTask.promise;
|
|
||||||
|
|
||||||
// Increase for higher resolution
|
|
||||||
const scale = 4;
|
|
||||||
|
|
||||||
return await Promise.all(
|
|
||||||
Array.from({ length: pdf.numPages }, async (_, index) => {
|
|
||||||
const page = await pdf.getPage(index + 1);
|
|
||||||
|
|
||||||
const viewport = page.getViewport({ scale });
|
|
||||||
|
|
||||||
const virtualCanvas = new Canvas(viewport.width, viewport.height);
|
|
||||||
const context = virtualCanvas.getContext('2d');
|
|
||||||
context.imageSmoothingEnabled = false;
|
|
||||||
|
|
||||||
// @ts-expect-error skia-canvas context satisfies runtime requirements for pdfjs
|
|
||||||
await page.render({ canvasContext: context, viewport }).promise;
|
|
||||||
|
|
||||||
return {
|
|
||||||
image: await virtualCanvas.toBuffer('png'),
|
|
||||||
|
|
||||||
// Rounded down because the certificate page somehow gives dimensions with decimals
|
|
||||||
width: Math.floor(viewport.width),
|
|
||||||
height: Math.floor(viewport.height),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type CompareSignedPdfWithImagesOptions = {
|
|
||||||
id: string;
|
|
||||||
pdfData: Uint8Array;
|
|
||||||
images: Buffer[];
|
|
||||||
testInfo: TestInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
const compareSignedPdfWithImages = async ({
|
|
||||||
id,
|
|
||||||
pdfData,
|
|
||||||
images,
|
|
||||||
testInfo,
|
|
||||||
}: CompareSignedPdfWithImagesOptions) => {
|
|
||||||
const renderedImages = await renderPdfToImage(pdfData);
|
|
||||||
|
|
||||||
const blankCertificateFile = fs.readFileSync(
|
|
||||||
path.join(__dirname, '../../visual-regression/blank-certificate.png'),
|
|
||||||
);
|
|
||||||
const blankCertificateImage = PNG.sync.read(blankCertificateFile).data;
|
|
||||||
|
|
||||||
for (const [index, { image, width, height }] of renderedImages.entries()) {
|
|
||||||
const isCertificate = index === renderedImages.length - 1;
|
|
||||||
|
|
||||||
const diff = new PNG({ width, height });
|
|
||||||
|
|
||||||
const storedImage = PNG.sync.read(images[index]).data;
|
|
||||||
|
|
||||||
const newImage = PNG.sync.read(image).data;
|
|
||||||
|
|
||||||
const oldImage = isCertificate ? blankCertificateImage : storedImage;
|
|
||||||
|
|
||||||
const comparison = pixelMatch(
|
|
||||||
new Uint8Array(oldImage),
|
|
||||||
new Uint8Array(newImage),
|
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
||||||
diff.data as unknown as Uint8Array,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
{
|
|
||||||
threshold: 0.25,
|
|
||||||
// includeAA: true, // This allows stricter testing.
|
|
||||||
},
|
|
||||||
);
|
|
||||||
console.log(`${id}-${index}: ${comparison}`);
|
|
||||||
|
|
||||||
const diffFilePath = path.join(testInfo.outputPath(), `${id}-${index}-diff.png`);
|
|
||||||
const oldFilePath = path.join(testInfo.outputPath(), `${id}-${index}-old.png`);
|
|
||||||
const newFilePath = path.join(testInfo.outputPath(), `${id}-${index}-new.png`);
|
|
||||||
|
|
||||||
fs.writeFileSync(diffFilePath, new Uint8Array(PNG.sync.write(diff)));
|
|
||||||
fs.writeFileSync(oldFilePath, new Uint8Array(images[index]));
|
|
||||||
fs.writeFileSync(newFilePath, new Uint8Array(image));
|
|
||||||
|
|
||||||
if (isCertificate) {
|
|
||||||
// Expect the certificate to NOT be blank. Since the storedImage is blank.
|
|
||||||
expect.soft(comparison).toBeGreaterThan(20000);
|
|
||||||
} else {
|
|
||||||
expect.soft(comparison).toEqual(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -15,10 +15,7 @@
|
|||||||
"@documenso/lib": "*",
|
"@documenso/lib": "*",
|
||||||
"@documenso/prisma": "*",
|
"@documenso/prisma": "*",
|
||||||
"@playwright/test": "1.52.0",
|
"@playwright/test": "1.52.0",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20"
|
||||||
"@types/pngjs": "^6.0.5",
|
|
||||||
"pixelmatch": "^7.1.0",
|
|
||||||
"pngjs": "^7.0.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"start-server-and-test": "^2.0.12"
|
"start-server-and-test": "^2.0.12"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 134 KiB |
|
Before Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 144 KiB |
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 117 KiB |
@ -215,6 +215,7 @@ export const EnvelopeEditorProvider = ({
|
|||||||
} = useEnvelopeAutosave(async (envelopeUpdates: UpdateEnvelopePayload) => {
|
} = useEnvelopeAutosave(async (envelopeUpdates: UpdateEnvelopePayload) => {
|
||||||
await envelopeUpdateMutationQuery.mutateAsync({
|
await envelopeUpdateMutationQuery.mutateAsync({
|
||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
|
envelopeType: envelope.type,
|
||||||
data: envelopeUpdates.data,
|
data: envelopeUpdates.data,
|
||||||
meta: envelopeUpdates.meta,
|
meta: envelopeUpdates.meta,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -97,7 +97,9 @@ export const completeDocumentWithToken = async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (envelope.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
if (envelope.documentMeta?.signingOrder === DocumentSigningOrder.SEQUENTIAL) {
|
||||||
const isRecipientsTurn = await getIsRecipientsTurnToSign({ token: recipient.token });
|
const isRecipientsTurn = await getIsRecipientsTurnToSign({
|
||||||
|
token: recipient.token,
|
||||||
|
});
|
||||||
|
|
||||||
if (!isRecipientsTurn) {
|
if (!isRecipientsTurn) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -151,6 +153,18 @@ export const completeDocumentWithToken = async ({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const envelopeForFailure = await prisma.envelope.findUniqueOrThrow({
|
||||||
|
where: { id: envelope.id },
|
||||||
|
include: { documentMeta: true, recipients: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.RECIPIENT_AUTHENTICATION_FAILED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(envelopeForFailure)),
|
||||||
|
userId: envelope.userId,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
throw new AppError(AppErrorCode.TWO_FACTOR_AUTH_FAILED, {
|
throw new AppError(AppErrorCode.TWO_FACTOR_AUTH_FAILED, {
|
||||||
message: 'Invalid 2FA authentication',
|
message: 'Invalid 2FA authentication',
|
||||||
});
|
});
|
||||||
@ -205,6 +219,18 @@ export const completeDocumentWithToken = async ({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const envelopeWithRelations = await prisma.envelope.findUniqueOrThrow({
|
||||||
|
where: { id: envelope.id },
|
||||||
|
include: { documentMeta: true, recipients: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.DOCUMENT_RECIPIENT_COMPLETED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(envelopeWithRelations)),
|
||||||
|
userId: envelope.userId,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
await jobs.triggerJob({
|
await jobs.triggerJob({
|
||||||
name: 'send.recipient.signed.email',
|
name: 'send.recipient.signed.email',
|
||||||
payload: {
|
payload: {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import {
|
|||||||
OrganisationType,
|
OrganisationType,
|
||||||
RecipientRole,
|
RecipientRole,
|
||||||
SigningStatus,
|
SigningStatus,
|
||||||
|
WebhookTriggerEvents,
|
||||||
} from '@prisma/client';
|
} from '@prisma/client';
|
||||||
|
|
||||||
import { mailer } from '@documenso/email/mailer';
|
import { mailer } from '@documenso/email/mailer';
|
||||||
@ -24,11 +25,16 @@ import { prisma } from '@documenso/prisma';
|
|||||||
import { getI18nInstance } from '../../client-only/providers/i18n-server';
|
import { getI18nInstance } from '../../client-only/providers/i18n-server';
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||||
|
import {
|
||||||
|
ZWebhookDocumentSchema,
|
||||||
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
|
} from '../../types/webhook-payload';
|
||||||
import { isDocumentCompleted } from '../../utils/document';
|
import { isDocumentCompleted } from '../../utils/document';
|
||||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
|
|
||||||
export type ResendDocumentOptions = {
|
export type ResendDocumentOptions = {
|
||||||
id: EnvelopeIdOptions;
|
id: EnvelopeIdOptions;
|
||||||
@ -230,4 +236,11 @@ export const resendDocument = async ({
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.DOCUMENT_REMINDER_SENT,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(envelope)),
|
||||||
|
userId: envelope.userId,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -20,12 +20,7 @@ import { validateCheckboxLength } from '../../advanced-fields-validation/validat
|
|||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import { jobs } from '../../jobs/client';
|
import { jobs } from '../../jobs/client';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||||
import {
|
import { ZCheckboxFieldMeta, ZDropdownFieldMeta, ZRadioFieldMeta } from '../../types/field-meta';
|
||||||
ZCheckboxFieldMeta,
|
|
||||||
ZDropdownFieldMeta,
|
|
||||||
ZFieldAndMetaSchema,
|
|
||||||
ZRadioFieldMeta,
|
|
||||||
} from '../../types/field-meta';
|
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapEnvelopeToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
@ -179,20 +174,9 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
const fieldsToAutoInsert: { fieldId: number; customText: string }[] = [];
|
const fieldsToAutoInsert: { fieldId: number; customText: string }[] = [];
|
||||||
|
|
||||||
// Validate and autoinsert fields for V2 envelopes.
|
// Auto insert radio and checkboxes that have default values.
|
||||||
if (envelope.internalVersion === 2) {
|
if (envelope.internalVersion === 2) {
|
||||||
for (const unknownField of envelope.fields) {
|
for (const field of envelope.fields) {
|
||||||
const parsedField = ZFieldAndMetaSchema.safeParse(unknownField);
|
|
||||||
|
|
||||||
if (parsedField.error) {
|
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
|
||||||
message: 'One or more fields have invalid metadata. Error: ' + parsedField.error.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const field = parsedField.data;
|
|
||||||
const fieldId = unknownField.id;
|
|
||||||
|
|
||||||
if (field.type === FieldType.RADIO) {
|
if (field.type === FieldType.RADIO) {
|
||||||
const { values = [] } = ZRadioFieldMeta.parse(field.fieldMeta);
|
const { values = [] } = ZRadioFieldMeta.parse(field.fieldMeta);
|
||||||
|
|
||||||
@ -200,7 +184,7 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
if (checkedItemIndex !== -1) {
|
if (checkedItemIndex !== -1) {
|
||||||
fieldsToAutoInsert.push({
|
fieldsToAutoInsert.push({
|
||||||
fieldId,
|
fieldId: field.id,
|
||||||
customText: toRadioCustomText(checkedItemIndex),
|
customText: toRadioCustomText(checkedItemIndex),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -211,7 +195,7 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
if (defaultValue && values.some((value) => value.value === defaultValue)) {
|
if (defaultValue && values.some((value) => value.value === defaultValue)) {
|
||||||
fieldsToAutoInsert.push({
|
fieldsToAutoInsert.push({
|
||||||
fieldId,
|
fieldId: field.id,
|
||||||
customText: defaultValue,
|
customText: defaultValue,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -252,7 +236,7 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
fieldsToAutoInsert.push({
|
fieldsToAutoInsert.push({
|
||||||
fieldId,
|
fieldId: field.id,
|
||||||
customText: toCheckboxCustomText(checkedIndices),
|
customText: toCheckboxCustomText(checkedIndices),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { EnvelopeType, ReadStatus, SendStatus } from '@prisma/client';
|
import { EnvelopeType, ReadStatus, SendStatus, WebhookTriggerEvents } from '@prisma/client';
|
||||||
import { WebhookTriggerEvents } from '@prisma/client';
|
|
||||||
|
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||||
import type { RequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
import type { RequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
@ -66,6 +65,13 @@ export const viewedDocument = async ({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.DOCUMENT_VIEWED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(envelope)),
|
||||||
|
userId: envelope.userId,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
// Early return if already opened.
|
// Early return if already opened.
|
||||||
if (recipient.readStatus === ReadStatus.OPENED) {
|
if (recipient.readStatus === ReadStatus.OPENED) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -386,6 +386,13 @@ export const createEnvelope = async ({
|
|||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
} else if (type === EnvelopeType.TEMPLATE) {
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.TEMPLATE_CREATED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(createdEnvelope)),
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return createdEnvelope;
|
return createdEnvelope;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import type { DocumentMeta, DocumentVisibility, Prisma, TemplateType } from '@prisma/client';
|
import type { DocumentMeta, DocumentVisibility, Prisma, TemplateType } from '@prisma/client';
|
||||||
import { EnvelopeType, FolderType } from '@prisma/client';
|
import { DocumentStatus, EnvelopeType, FolderType, WebhookTriggerEvents } from '@prisma/client';
|
||||||
import { DocumentStatus } from '@prisma/client';
|
|
||||||
import { isDeepEqual } from 'remeda';
|
import { isDeepEqual } from 'remeda';
|
||||||
|
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||||
@ -12,9 +11,14 @@ import { prisma } from '@documenso/prisma';
|
|||||||
import { TEAM_DOCUMENT_VISIBILITY_MAP } from '../../constants/teams';
|
import { TEAM_DOCUMENT_VISIBILITY_MAP } from '../../constants/teams';
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import type { TDocumentAccessAuthTypes, TDocumentActionAuthTypes } from '../../types/document-auth';
|
import type { TDocumentAccessAuthTypes, TDocumentActionAuthTypes } from '../../types/document-auth';
|
||||||
|
import {
|
||||||
|
ZWebhookDocumentSchema,
|
||||||
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
|
} from '../../types/webhook-payload';
|
||||||
import { createDocumentAuthOptions, extractDocumentAuthMethods } from '../../utils/document-auth';
|
import { createDocumentAuthOptions, extractDocumentAuthMethods } from '../../utils/document-auth';
|
||||||
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
import { buildTeamWhereQuery, canAccessTeamDocument } from '../../utils/teams';
|
import { buildTeamWhereQuery, canAccessTeamDocument } from '../../utils/teams';
|
||||||
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
import { getEnvelopeWhereInput } from './get-envelope-by-id';
|
import { getEnvelopeWhereInput } from './get-envelope-by-id';
|
||||||
|
|
||||||
export type UpdateEnvelopeOptions = {
|
export type UpdateEnvelopeOptions = {
|
||||||
@ -339,6 +343,22 @@ export const updateEnvelope = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (envelope.type === EnvelopeType.TEMPLATE) {
|
||||||
|
const envelopeWithRelations = await tx.envelope.findUniqueOrThrow({
|
||||||
|
where: { id: updatedEnvelope.id },
|
||||||
|
include: { documentMeta: true, recipients: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
void triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.TEMPLATE_UPDATED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(
|
||||||
|
mapEnvelopeToWebhookDocumentPayload(envelopeWithRelations),
|
||||||
|
),
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return updatedEnvelope;
|
return updatedEnvelope;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -26,9 +26,9 @@ export interface CreateEnvelopeFieldsOptions {
|
|||||||
envelopeItemId?: string;
|
envelopeItemId?: string;
|
||||||
|
|
||||||
recipientId: number;
|
recipientId: number;
|
||||||
page: number;
|
pageNumber: number;
|
||||||
positionX: number;
|
pageX: number;
|
||||||
positionY: number;
|
pageY: number;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
})[];
|
})[];
|
||||||
@ -122,9 +122,9 @@ export const createEnvelopeFields = async ({
|
|||||||
const newlyCreatedFields = await tx.field.createManyAndReturn({
|
const newlyCreatedFields = await tx.field.createManyAndReturn({
|
||||||
data: validatedFields.map((field) => ({
|
data: validatedFields.map((field) => ({
|
||||||
type: field.type,
|
type: field.type,
|
||||||
page: field.page,
|
page: field.pageNumber,
|
||||||
positionX: field.positionX,
|
positionX: field.pageX,
|
||||||
positionY: field.positionY,
|
positionY: field.pageY,
|
||||||
width: field.width,
|
width: field.width,
|
||||||
height: field.height,
|
height: field.height,
|
||||||
customText: '',
|
customText: '',
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export type GetFieldByIdOptions = {
|
|||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
fieldId: number;
|
fieldId: number;
|
||||||
envelopeType?: EnvelopeType;
|
envelopeType: EnvelopeType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFieldById = async ({
|
export const getFieldById = async ({
|
||||||
@ -41,7 +41,7 @@ export const getFieldById = async ({
|
|||||||
type: 'envelopeId',
|
type: 'envelopeId',
|
||||||
id: field.envelopeId,
|
id: field.envelopeId,
|
||||||
},
|
},
|
||||||
type: envelopeType ?? null,
|
type: envelopeType,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -158,7 +158,7 @@ export const setFieldsForDocument = async ({
|
|||||||
const numberFieldParsedMeta = ZNumberFieldMeta.parse(field.fieldMeta);
|
const numberFieldParsedMeta = ZNumberFieldMeta.parse(field.fieldMeta);
|
||||||
|
|
||||||
const errors = validateNumberField(
|
const errors = validateNumberField(
|
||||||
String(numberFieldParsedMeta.value || ''),
|
String(numberFieldParsedMeta.value),
|
||||||
numberFieldParsedMeta,
|
numberFieldParsedMeta,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,21 +10,18 @@ import {
|
|||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import { type EnvelopeIdOptions } from '../../utils/envelope';
|
|
||||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||||
import { canRecipientFieldsBeModified } from '../../utils/recipients';
|
import { canRecipientFieldsBeModified } from '../../utils/recipients';
|
||||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export interface UpdateEnvelopeFieldsOptions {
|
export interface UpdateDocumentFieldsOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
id: EnvelopeIdOptions;
|
documentId: number;
|
||||||
type?: EnvelopeType | null; // Only used to enforce the type.
|
|
||||||
fields: {
|
fields: {
|
||||||
id: number;
|
id: number;
|
||||||
type?: FieldType;
|
type?: FieldType;
|
||||||
pageNumber?: number;
|
pageNumber?: number;
|
||||||
envelopeItemId?: string;
|
|
||||||
pageX?: number;
|
pageX?: number;
|
||||||
pageY?: number;
|
pageY?: number;
|
||||||
width?: number;
|
width?: number;
|
||||||
@ -34,17 +31,19 @@ export interface UpdateEnvelopeFieldsOptions {
|
|||||||
requestMetadata: ApiRequestMetadata;
|
requestMetadata: ApiRequestMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateEnvelopeFields = async ({
|
export const updateDocumentFields = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
id,
|
documentId,
|
||||||
type = null,
|
|
||||||
fields,
|
fields,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: UpdateEnvelopeFieldsOptions) => {
|
}: UpdateDocumentFieldsOptions) => {
|
||||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
id,
|
id: {
|
||||||
type,
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
@ -54,19 +53,18 @@ export const updateEnvelopeFields = async ({
|
|||||||
include: {
|
include: {
|
||||||
recipients: true,
|
recipients: true,
|
||||||
fields: true,
|
fields: true,
|
||||||
envelopeItems: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!envelope) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Envelope not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envelope.completedAt) {
|
if (envelope.completedAt) {
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
message: 'Envelope already complete',
|
message: 'Document already complete',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,29 +96,6 @@ export const updateEnvelopeFields = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldType = field.type || originalField.type;
|
|
||||||
const fieldMetaType = field.fieldMeta?.type || originalField.fieldMeta?.type;
|
|
||||||
|
|
||||||
// Not going to mess with V1 envelopes.
|
|
||||||
if (
|
|
||||||
envelope.internalVersion === 2 &&
|
|
||||||
fieldMetaType &&
|
|
||||||
fieldMetaType.toLowerCase() !== fieldType.toLowerCase()
|
|
||||||
) {
|
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
|
||||||
message: 'Field meta type does not match the field type',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
field.envelopeItemId &&
|
|
||||||
!envelope.envelopeItems.some((item) => item.id === field.envelopeItemId)
|
|
||||||
) {
|
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
|
||||||
message: 'Envelope item not found',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
originalField,
|
originalField,
|
||||||
updateData: field,
|
updateData: field,
|
||||||
@ -143,14 +118,12 @@ export const updateEnvelopeFields = async ({
|
|||||||
width: updateData.width,
|
width: updateData.width,
|
||||||
height: updateData.height,
|
height: updateData.height,
|
||||||
fieldMeta: updateData.fieldMeta,
|
fieldMeta: updateData.fieldMeta,
|
||||||
envelopeItemId: updateData.envelopeItemId,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle field updated audit log.
|
|
||||||
if (envelope.type === EnvelopeType.DOCUMENT) {
|
|
||||||
const changes = diffFieldChanges(originalField, updatedField);
|
const changes = diffFieldChanges(originalField, updatedField);
|
||||||
|
|
||||||
|
// Handle field updated audit log.
|
||||||
if (changes.length > 0) {
|
if (changes.length > 0) {
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
@ -167,7 +140,6 @@ export const updateEnvelopeFields = async ({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return updatedField;
|
return updatedField;
|
||||||
}),
|
}),
|
||||||
116
packages/lib/server-only/field/update-template-fields.ts
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
import { EnvelopeType, type FieldType } from '@prisma/client';
|
||||||
|
|
||||||
|
import type { TFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
|
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||||
|
import { canRecipientFieldsBeModified } from '../../utils/recipients';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
|
export interface UpdateTemplateFieldsOptions {
|
||||||
|
userId: number;
|
||||||
|
teamId: number;
|
||||||
|
templateId: number;
|
||||||
|
fields: {
|
||||||
|
id: number;
|
||||||
|
type?: FieldType;
|
||||||
|
pageNumber?: number;
|
||||||
|
pageX?: number;
|
||||||
|
pageY?: number;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
fieldMeta?: TFieldMetaSchema;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateTemplateFields = async ({
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
templateId,
|
||||||
|
fields,
|
||||||
|
}: UpdateTemplateFieldsOptions) => {
|
||||||
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
|
id: {
|
||||||
|
type: 'templateId',
|
||||||
|
id: templateId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.TEMPLATE,
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const envelope = await prisma.envelope.findFirst({
|
||||||
|
where: envelopeWhereInput,
|
||||||
|
include: {
|
||||||
|
recipients: true,
|
||||||
|
fields: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelope) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: 'Document not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldsToUpdate = fields.map((field) => {
|
||||||
|
const originalField = envelope.fields.find((existingField) => existingField.id === field.id);
|
||||||
|
|
||||||
|
if (!originalField) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: `Field with id ${field.id} not found`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const recipient = envelope.recipients.find(
|
||||||
|
(recipient) => recipient.id === originalField.recipientId,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Each field MUST have a recipient associated with it.
|
||||||
|
if (!recipient) {
|
||||||
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
|
message: `Recipient attached to field ${field.id} not found`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether the recipient associated with the field can be modified.
|
||||||
|
if (!canRecipientFieldsBeModified(recipient, envelope.fields)) {
|
||||||
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
|
message:
|
||||||
|
'Cannot modify a field where the recipient has already interacted with the document',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
updateData: field,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedFields = await prisma.$transaction(async (tx) => {
|
||||||
|
return await Promise.all(
|
||||||
|
fieldsToUpdate.map(async ({ updateData }) => {
|
||||||
|
const updatedField = await tx.field.update({
|
||||||
|
where: {
|
||||||
|
id: updateData.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
type: updateData.type,
|
||||||
|
page: updateData.pageNumber,
|
||||||
|
positionX: updateData.pageX,
|
||||||
|
positionY: updateData.pageY,
|
||||||
|
width: updateData.width,
|
||||||
|
height: updateData.height,
|
||||||
|
fieldMeta: updateData.fieldMeta,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return updatedField;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
fields: updatedFields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -15,7 +15,7 @@ import type { EnvelopeIdOptions } from '../../utils/envelope';
|
|||||||
import { mapRecipientToLegacyRecipient } from '../../utils/recipients';
|
import { mapRecipientToLegacyRecipient } from '../../utils/recipients';
|
||||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export interface CreateEnvelopeRecipientsOptions {
|
export interface CreateDocumentRecipientsOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
id: EnvelopeIdOptions;
|
id: EnvelopeIdOptions;
|
||||||
@ -30,16 +30,16 @@ export interface CreateEnvelopeRecipientsOptions {
|
|||||||
requestMetadata: ApiRequestMetadata;
|
requestMetadata: ApiRequestMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createEnvelopeRecipients = async ({
|
export const createDocumentRecipients = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
id,
|
id,
|
||||||
recipients: recipientsToCreate,
|
recipients: recipientsToCreate,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: CreateEnvelopeRecipientsOptions) => {
|
}: CreateDocumentRecipientsOptions) => {
|
||||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
id,
|
id,
|
||||||
type: null,
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
@ -62,13 +62,13 @@ export const createEnvelopeRecipients = async ({
|
|||||||
|
|
||||||
if (!envelope) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Envelope not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envelope.completedAt) {
|
if (envelope.completedAt) {
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
message: 'Envelope already complete',
|
message: 'Document already complete',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,6 @@ export const createEnvelopeRecipients = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle recipient created audit log.
|
// Handle recipient created audit log.
|
||||||
if (envelope.type === EnvelopeType.DOCUMENT) {
|
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_CREATED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_CREATED,
|
||||||
@ -128,7 +127,6 @@ export const createEnvelopeRecipients = async ({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return createdRecipient;
|
return createdRecipient;
|
||||||
}),
|
}),
|
||||||
115
packages/lib/server-only/recipient/create-template-recipients.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import { EnvelopeType, RecipientRole } from '@prisma/client';
|
||||||
|
import { SendStatus, SigningStatus } from '@prisma/client';
|
||||||
|
|
||||||
|
import type { TRecipientAccessAuthTypes } from '@documenso/lib/types/document-auth';
|
||||||
|
import { type TRecipientActionAuthTypes } from '@documenso/lib/types/document-auth';
|
||||||
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
|
import { createRecipientAuthOptions } from '@documenso/lib/utils/document-auth';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
|
import { mapRecipientToLegacyRecipient } from '../../utils/recipients';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
|
export interface CreateTemplateRecipientsOptions {
|
||||||
|
userId: number;
|
||||||
|
teamId: number;
|
||||||
|
templateId: number;
|
||||||
|
recipients: {
|
||||||
|
email: string;
|
||||||
|
name: string;
|
||||||
|
role: RecipientRole;
|
||||||
|
signingOrder?: number | null;
|
||||||
|
accessAuth?: TRecipientAccessAuthTypes[];
|
||||||
|
actionAuth?: TRecipientActionAuthTypes[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createTemplateRecipients = async ({
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
templateId,
|
||||||
|
recipients: recipientsToCreate,
|
||||||
|
}: CreateTemplateRecipientsOptions) => {
|
||||||
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
|
id: {
|
||||||
|
type: 'templateId',
|
||||||
|
id: templateId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.TEMPLATE,
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const template = await prisma.envelope.findFirst({
|
||||||
|
where: envelopeWhereInput,
|
||||||
|
include: {
|
||||||
|
recipients: true,
|
||||||
|
team: {
|
||||||
|
select: {
|
||||||
|
organisation: {
|
||||||
|
select: {
|
||||||
|
organisationClaim: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!template) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: 'Template not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const recipientsHaveActionAuth = recipientsToCreate.some(
|
||||||
|
(recipient) => recipient.actionAuth && recipient.actionAuth.length > 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if user has permission to set the global action auth.
|
||||||
|
if (recipientsHaveActionAuth && !template.team.organisation.organisationClaim.flags.cfr21) {
|
||||||
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
|
message: 'You do not have permission to set the action auth',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedRecipients = recipientsToCreate.map((recipient) => ({
|
||||||
|
...recipient,
|
||||||
|
email: recipient.email.toLowerCase(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const createdRecipients = await prisma.$transaction(async (tx) => {
|
||||||
|
return await Promise.all(
|
||||||
|
normalizedRecipients.map(async (recipient) => {
|
||||||
|
const authOptions = createRecipientAuthOptions({
|
||||||
|
accessAuth: recipient.accessAuth ?? [],
|
||||||
|
actionAuth: recipient.actionAuth ?? [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const createdRecipient = await tx.recipient.create({
|
||||||
|
data: {
|
||||||
|
envelopeId: template.id,
|
||||||
|
name: recipient.name,
|
||||||
|
email: recipient.email,
|
||||||
|
role: recipient.role,
|
||||||
|
signingOrder: recipient.signingOrder,
|
||||||
|
token: nanoid(),
|
||||||
|
sendStatus: recipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT,
|
||||||
|
signingStatus:
|
||||||
|
recipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED,
|
||||||
|
authOptions,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return createdRecipient;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
recipients: createdRecipients.map((recipient) =>
|
||||||
|
mapRecipientToLegacyRecipient(recipient, template),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -14,27 +14,26 @@ import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
|||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||||
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '../../utils/document-audit-logs';
|
||||||
import { canRecipientBeModified } from '../../utils/recipients';
|
|
||||||
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
import { renderEmailWithI18N } from '../../utils/render-email-with-i18n';
|
||||||
import { buildTeamWhereQuery } from '../../utils/teams';
|
import { buildTeamWhereQuery } from '../../utils/teams';
|
||||||
import { getEmailContext } from '../email/get-email-context';
|
import { getEmailContext } from '../email/get-email-context';
|
||||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
|
||||||
|
|
||||||
export interface DeleteEnvelopeRecipientOptions {
|
export interface DeleteDocumentRecipientOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
recipientId: number;
|
recipientId: number;
|
||||||
requestMetadata: ApiRequestMetadata;
|
requestMetadata: ApiRequestMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteEnvelopeRecipient = async ({
|
export const deleteDocumentRecipient = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
recipientId,
|
recipientId,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: DeleteEnvelopeRecipientOptions) => {
|
}: DeleteDocumentRecipientOptions) => {
|
||||||
const envelope = await prisma.envelope.findFirst({
|
const envelope = await prisma.envelope.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
recipients: {
|
recipients: {
|
||||||
some: {
|
some: {
|
||||||
id: recipientId,
|
id: recipientId,
|
||||||
@ -49,9 +48,6 @@ export const deleteEnvelopeRecipient = async ({
|
|||||||
where: {
|
where: {
|
||||||
id: recipientId,
|
id: recipientId,
|
||||||
},
|
},
|
||||||
include: {
|
|
||||||
fields: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -93,24 +89,7 @@ export const deleteEnvelopeRecipient = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canRecipientBeModified(recipientToDelete, recipientToDelete.fields)) {
|
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
|
||||||
message: 'Recipient has already interacted with the document.',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
|
||||||
id: {
|
|
||||||
type: 'envelopeId',
|
|
||||||
id: envelope.id,
|
|
||||||
},
|
|
||||||
type: null,
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const deletedRecipient = await prisma.$transaction(async (tx) => {
|
const deletedRecipient = await prisma.$transaction(async (tx) => {
|
||||||
if (envelope.type === EnvelopeType.DOCUMENT) {
|
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_DELETED,
|
type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_DELETED,
|
||||||
@ -124,12 +103,10 @@ export const deleteEnvelopeRecipient = async ({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return await tx.recipient.delete({
|
return await tx.recipient.delete({
|
||||||
where: {
|
where: {
|
||||||
id: recipientId,
|
id: recipientId,
|
||||||
envelope: envelopeWhereInput,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -139,11 +116,7 @@ export const deleteEnvelopeRecipient = async ({
|
|||||||
).recipientRemoved;
|
).recipientRemoved;
|
||||||
|
|
||||||
// Send email to deleted recipient.
|
// Send email to deleted recipient.
|
||||||
if (
|
if (recipientToDelete.sendStatus === SendStatus.SENT && isRecipientRemovedEmailEnabled) {
|
||||||
recipientToDelete.sendStatus === SendStatus.SENT &&
|
|
||||||
isRecipientRemovedEmailEnabled &&
|
|
||||||
envelope.type === EnvelopeType.DOCUMENT
|
|
||||||
) {
|
|
||||||
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
const assetBaseUrl = NEXT_PUBLIC_WEBAPP_URL() || 'http://localhost:3000';
|
||||||
|
|
||||||
const template = createElement(RecipientRemovedFromDocumentTemplate, {
|
const template = createElement(RecipientRemovedFromDocumentTemplate, {
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
|
import { buildTeamWhereQuery } from '../../utils/teams';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
|
export interface DeleteTemplateRecipientOptions {
|
||||||
|
userId: number;
|
||||||
|
teamId: number;
|
||||||
|
recipientId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const deleteTemplateRecipient = async ({
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
recipientId,
|
||||||
|
}: DeleteTemplateRecipientOptions): Promise<void> => {
|
||||||
|
const recipientToDelete = await prisma.recipient.findFirst({
|
||||||
|
where: {
|
||||||
|
id: recipientId,
|
||||||
|
envelope: {
|
||||||
|
type: EnvelopeType.TEMPLATE,
|
||||||
|
team: buildTeamWhereQuery({ teamId, userId }),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!recipientToDelete) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: 'Recipient not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
|
id: {
|
||||||
|
type: 'envelopeId',
|
||||||
|
id: recipientToDelete.envelopeId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.TEMPLATE,
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!recipientToDelete || recipientToDelete.id !== recipientId) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: 'Recipient not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await prisma.recipient.delete({
|
||||||
|
where: {
|
||||||
|
id: recipientId,
|
||||||
|
envelope: envelopeWhereInput,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import { EnvelopeType, RecipientRole, SendStatus, SigningStatus } from '@prisma/client';
|
import { EnvelopeType, RecipientRole } from '@prisma/client';
|
||||||
|
import { SendStatus, SigningStatus } from '@prisma/client';
|
||||||
|
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||||
import type { TRecipientAccessAuthTypes } from '@documenso/lib/types/document-auth';
|
import type { TRecipientAccessAuthTypes } from '@documenso/lib/types/document-auth';
|
||||||
@ -15,38 +16,29 @@ import { createRecipientAuthOptions } from '@documenso/lib/utils/document-auth';
|
|||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import { extractLegacyIds } from '../../universal/id';
|
import { type EnvelopeIdOptions, mapSecondaryIdToDocumentId } from '../../utils/envelope';
|
||||||
import { type EnvelopeIdOptions } from '../../utils/envelope';
|
|
||||||
import { mapFieldToLegacyField } from '../../utils/fields';
|
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||||
import { canRecipientBeModified } from '../../utils/recipients';
|
import { canRecipientBeModified } from '../../utils/recipients';
|
||||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
export interface UpdateEnvelopeRecipientsOptions {
|
export interface UpdateDocumentRecipientsOptions {
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
id: EnvelopeIdOptions;
|
id: EnvelopeIdOptions;
|
||||||
recipients: {
|
recipients: RecipientData[];
|
||||||
id: number;
|
|
||||||
email?: string;
|
|
||||||
name?: string;
|
|
||||||
role?: RecipientRole;
|
|
||||||
signingOrder?: number | null;
|
|
||||||
accessAuth?: TRecipientAccessAuthTypes[];
|
|
||||||
actionAuth?: TRecipientActionAuthTypes[];
|
|
||||||
}[];
|
|
||||||
requestMetadata: ApiRequestMetadata;
|
requestMetadata: ApiRequestMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateEnvelopeRecipients = async ({
|
export const updateDocumentRecipients = async ({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
id,
|
id,
|
||||||
recipients,
|
recipients,
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
}: UpdateEnvelopeRecipientsOptions) => {
|
}: UpdateDocumentRecipientsOptions) => {
|
||||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
id,
|
id,
|
||||||
type: null,
|
type: EnvelopeType.DOCUMENT,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
@ -70,13 +62,13 @@ export const updateEnvelopeRecipients = async ({
|
|||||||
|
|
||||||
if (!envelope) {
|
if (!envelope) {
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
message: 'Envelope not found',
|
message: 'Document not found',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envelope.completedAt) {
|
if (envelope.completedAt) {
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
message: 'Envelope already complete',
|
message: 'Document already complete',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,10 +160,9 @@ export const updateEnvelopeRecipients = async ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle recipient updated audit log.
|
|
||||||
if (envelope.type === EnvelopeType.DOCUMENT) {
|
|
||||||
const changes = diffRecipientChanges(originalRecipient, updatedRecipient);
|
const changes = diffRecipientChanges(originalRecipient, updatedRecipient);
|
||||||
|
|
||||||
|
// Handle recipient updated audit log.
|
||||||
if (changes.length > 0) {
|
if (changes.length > 0) {
|
||||||
await tx.documentAuditLog.create({
|
await tx.documentAuditLog.create({
|
||||||
data: createDocumentAuditLogData({
|
data: createDocumentAuditLogData({
|
||||||
@ -188,7 +179,6 @@ export const updateEnvelopeRecipients = async ({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return updatedRecipient;
|
return updatedRecipient;
|
||||||
}),
|
}),
|
||||||
@ -198,8 +188,19 @@ export const updateEnvelopeRecipients = async ({
|
|||||||
return {
|
return {
|
||||||
recipients: updatedRecipients.map((recipient) => ({
|
recipients: updatedRecipients.map((recipient) => ({
|
||||||
...recipient,
|
...recipient,
|
||||||
...extractLegacyIds(envelope),
|
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
templateId: null,
|
||||||
fields: recipient.fields.map((field) => mapFieldToLegacyField(field, envelope)),
|
fields: recipient.fields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type RecipientData = {
|
||||||
|
id: number;
|
||||||
|
email?: string;
|
||||||
|
name?: string;
|
||||||
|
role?: RecipientRole;
|
||||||
|
signingOrder?: number | null;
|
||||||
|
accessAuth?: TRecipientAccessAuthTypes[];
|
||||||
|
actionAuth?: TRecipientActionAuthTypes[];
|
||||||
|
};
|
||||||
168
packages/lib/server-only/recipient/update-template-recipients.ts
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
import { EnvelopeType, RecipientRole } from '@prisma/client';
|
||||||
|
import { SendStatus, SigningStatus } from '@prisma/client';
|
||||||
|
|
||||||
|
import type { TRecipientAccessAuthTypes } from '@documenso/lib/types/document-auth';
|
||||||
|
import {
|
||||||
|
type TRecipientActionAuthTypes,
|
||||||
|
ZRecipientAuthOptionsSchema,
|
||||||
|
} from '@documenso/lib/types/document-auth';
|
||||||
|
import { createRecipientAuthOptions } from '@documenso/lib/utils/document-auth';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
|
import { mapSecondaryIdToTemplateId } from '../../utils/envelope';
|
||||||
|
import { mapFieldToLegacyField } from '../../utils/fields';
|
||||||
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
|
||||||
|
export interface UpdateTemplateRecipientsOptions {
|
||||||
|
userId: number;
|
||||||
|
teamId: number;
|
||||||
|
templateId: number;
|
||||||
|
recipients: {
|
||||||
|
id: number;
|
||||||
|
email?: string;
|
||||||
|
name?: string;
|
||||||
|
role?: RecipientRole;
|
||||||
|
signingOrder?: number | null;
|
||||||
|
accessAuth?: TRecipientAccessAuthTypes[];
|
||||||
|
actionAuth?: TRecipientActionAuthTypes[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateTemplateRecipients = async ({
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
templateId,
|
||||||
|
recipients,
|
||||||
|
}: UpdateTemplateRecipientsOptions) => {
|
||||||
|
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||||
|
id: {
|
||||||
|
type: 'templateId',
|
||||||
|
id: templateId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.TEMPLATE,
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const envelope = await prisma.envelope.findFirst({
|
||||||
|
where: envelopeWhereInput,
|
||||||
|
include: {
|
||||||
|
recipients: true,
|
||||||
|
team: {
|
||||||
|
select: {
|
||||||
|
organisation: {
|
||||||
|
select: {
|
||||||
|
organisationClaim: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelope) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: 'Template not found',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const recipientsHaveActionAuth = recipients.some(
|
||||||
|
(recipient) => recipient.actionAuth && recipient.actionAuth.length > 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if user has permission to set the global action auth.
|
||||||
|
if (recipientsHaveActionAuth && !envelope.team.organisation.organisationClaim.flags.cfr21) {
|
||||||
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
|
message: 'You do not have permission to set the action auth',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const recipientsToUpdate = recipients.map((recipient) => {
|
||||||
|
const originalRecipient = envelope.recipients.find(
|
||||||
|
(existingRecipient) => existingRecipient.id === recipient.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!originalRecipient) {
|
||||||
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||||
|
message: `Recipient with id ${recipient.id} not found`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
originalRecipient,
|
||||||
|
recipientUpdateData: recipient,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedRecipients = await prisma.$transaction(async (tx) => {
|
||||||
|
return await Promise.all(
|
||||||
|
recipientsToUpdate.map(async ({ originalRecipient, recipientUpdateData }) => {
|
||||||
|
let authOptions = ZRecipientAuthOptionsSchema.parse(originalRecipient.authOptions);
|
||||||
|
|
||||||
|
if (
|
||||||
|
recipientUpdateData.actionAuth !== undefined ||
|
||||||
|
recipientUpdateData.accessAuth !== undefined
|
||||||
|
) {
|
||||||
|
authOptions = createRecipientAuthOptions({
|
||||||
|
accessAuth: recipientUpdateData.accessAuth || authOptions.accessAuth,
|
||||||
|
actionAuth: recipientUpdateData.actionAuth || authOptions.actionAuth,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const mergedRecipient = {
|
||||||
|
...originalRecipient,
|
||||||
|
...recipientUpdateData,
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatedRecipient = await tx.recipient.update({
|
||||||
|
where: {
|
||||||
|
id: originalRecipient.id,
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name: mergedRecipient.name,
|
||||||
|
email: mergedRecipient.email,
|
||||||
|
role: mergedRecipient.role,
|
||||||
|
signingOrder: mergedRecipient.signingOrder,
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
sendStatus:
|
||||||
|
mergedRecipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT,
|
||||||
|
signingStatus:
|
||||||
|
mergedRecipient.role === RecipientRole.CC
|
||||||
|
? SigningStatus.SIGNED
|
||||||
|
: SigningStatus.NOT_SIGNED,
|
||||||
|
authOptions,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
fields: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear all fields if the recipient role is changed to a type that cannot have fields.
|
||||||
|
if (
|
||||||
|
originalRecipient.role !== updatedRecipient.role &&
|
||||||
|
(updatedRecipient.role === RecipientRole.CC ||
|
||||||
|
updatedRecipient.role === RecipientRole.VIEWER)
|
||||||
|
) {
|
||||||
|
await tx.field.deleteMany({
|
||||||
|
where: {
|
||||||
|
recipientId: updatedRecipient.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return updatedRecipient;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
recipients: updatedRecipients.map((recipient) => ({
|
||||||
|
...recipient,
|
||||||
|
documentId: null,
|
||||||
|
templateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||||
|
fields: recipient.fields.map((field) => mapFieldToLegacyField(field, envelope)),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -725,6 +725,13 @@ export const createDocumentFromTemplate = async ({
|
|||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.TEMPLATE_USED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(createdEnvelope)),
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
|
||||||
return envelope;
|
return envelope;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
import { EnvelopeType } from '@prisma/client';
|
import { EnvelopeType, WebhookTriggerEvents } from '@prisma/client';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ZWebhookDocumentSchema,
|
||||||
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
|
} from '../../types/webhook-payload';
|
||||||
import { type EnvelopeIdOptions } from '../../utils/envelope';
|
import { type EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id';
|
||||||
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
|
|
||||||
export type DeleteTemplateOptions = {
|
export type DeleteTemplateOptions = {
|
||||||
id: EnvelopeIdOptions;
|
id: EnvelopeIdOptions;
|
||||||
@ -19,6 +24,18 @@ export const deleteTemplate = async ({ id, userId, teamId }: DeleteTemplateOptio
|
|||||||
teamId,
|
teamId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const templateToDelete = await prisma.envelope.findUniqueOrThrow({
|
||||||
|
where: envelopeWhereInput,
|
||||||
|
include: { documentMeta: true, recipients: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
await triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.TEMPLATE_DELETED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(templateToDelete)),
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
|
|
||||||
return await prisma.envelope.delete({
|
return await prisma.envelope.delete({
|
||||||
where: envelopeWhereInput,
|
where: envelopeWhereInput,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -480,5 +480,198 @@ export const generateSampleWebhookPayload = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.DOCUMENT_VIEWED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
status: DocumentStatus.PENDING,
|
||||||
|
recipients: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.OPENED,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Recipient: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.OPENED,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.DOCUMENT_RECIPIENT_COMPLETED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
status: DocumentStatus.PENDING,
|
||||||
|
recipients: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.OPENED,
|
||||||
|
signingStatus: SigningStatus.SIGNED,
|
||||||
|
signedAt: now,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Recipient: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.OPENED,
|
||||||
|
signingStatus: SigningStatus.SIGNED,
|
||||||
|
signedAt: now,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.DOCUMENT_DOWNLOADED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
status: DocumentStatus.COMPLETED,
|
||||||
|
completedAt: now,
|
||||||
|
recipients: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.OPENED,
|
||||||
|
signingStatus: SigningStatus.SIGNED,
|
||||||
|
signedAt: now,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Recipient: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.OPENED,
|
||||||
|
signingStatus: SigningStatus.SIGNED,
|
||||||
|
signedAt: now,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.DOCUMENT_REMINDER_SENT) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
status: DocumentStatus.PENDING,
|
||||||
|
recipients: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
sendStatus: SendStatus.SENT,
|
||||||
|
signingStatus: SigningStatus.NOT_SIGNED,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Recipient: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
sendStatus: SendStatus.SENT,
|
||||||
|
signingStatus: SigningStatus.NOT_SIGNED,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.RECIPIENT_AUTHENTICATION_FAILED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
status: DocumentStatus.PENDING,
|
||||||
|
recipients: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.NOT_OPENED,
|
||||||
|
signingStatus: SigningStatus.NOT_SIGNED,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Recipient: [
|
||||||
|
{
|
||||||
|
...basePayload.recipients[0],
|
||||||
|
readStatus: ReadStatus.NOT_OPENED,
|
||||||
|
signingStatus: SigningStatus.NOT_SIGNED,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.TEMPLATE_CREATED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
title: 'My Template',
|
||||||
|
status: DocumentStatus.DRAFT,
|
||||||
|
templateId: 10,
|
||||||
|
source: DocumentSource.TEMPLATE,
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.TEMPLATE_UPDATED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
title: 'My Updated Template',
|
||||||
|
status: DocumentStatus.DRAFT,
|
||||||
|
templateId: 10,
|
||||||
|
source: DocumentSource.TEMPLATE,
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.TEMPLATE_DELETED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
title: 'Deleted Template',
|
||||||
|
status: DocumentStatus.DRAFT,
|
||||||
|
templateId: 10,
|
||||||
|
source: DocumentSource.TEMPLATE,
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event === WebhookTriggerEvents.TEMPLATE_USED) {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
payload: {
|
||||||
|
...basePayload,
|
||||||
|
title: 'Document from Template',
|
||||||
|
status: DocumentStatus.DRAFT,
|
||||||
|
templateId: 10,
|
||||||
|
source: DocumentSource.TEMPLATE,
|
||||||
|
},
|
||||||
|
createdAt: now.toISOString(),
|
||||||
|
webhookEndpoint: webhookUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
throw new Error(`Unsupported event type: ${event}`);
|
throw new Error(`Unsupported event type: ${event}`);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -37,8 +37,11 @@ export const ZEnvelopeSchema = EnvelopeSchema.pick({
|
|||||||
userId: true,
|
userId: true,
|
||||||
teamId: true,
|
teamId: true,
|
||||||
folderId: true,
|
folderId: true,
|
||||||
templateId: true,
|
|
||||||
}).extend({
|
}).extend({
|
||||||
|
templateId: z
|
||||||
|
.number()
|
||||||
|
.nullish()
|
||||||
|
.describe('The ID of the template that the document was created from, if any.'),
|
||||||
documentMeta: DocumentMetaSchema.pick({
|
documentMeta: DocumentMetaSchema.pick({
|
||||||
signingOrder: true,
|
signingOrder: true,
|
||||||
distributionMethod: true,
|
distributionMethod: true,
|
||||||
|
|||||||
@ -188,7 +188,7 @@ export type TFieldMetaSchema = z.infer<typeof ZFieldMetaSchema>;
|
|||||||
export const ZFieldAndMetaSchema = z.discriminatedUnion('type', [
|
export const ZFieldAndMetaSchema = z.discriminatedUnion('type', [
|
||||||
z.object({
|
z.object({
|
||||||
type: z.literal(FieldType.SIGNATURE),
|
type: z.literal(FieldType.SIGNATURE),
|
||||||
fieldMeta: ZSignatureFieldMeta.optional(),
|
fieldMeta: z.undefined(),
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
type: z.literal(FieldType.FREE_SIGNATURE),
|
type: z.literal(FieldType.FREE_SIGNATURE),
|
||||||
|
|||||||
@ -50,11 +50,6 @@ export const ZFieldSchema = FieldSchema.pick({
|
|||||||
templateId: z.number().nullish(),
|
templateId: z.number().nullish(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZEnvelopeFieldSchema = ZFieldSchema.omit({
|
|
||||||
documentId: true,
|
|
||||||
templateId: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZFieldPageNumberSchema = z
|
export const ZFieldPageNumberSchema = z
|
||||||
.number()
|
.number()
|
||||||
.min(1)
|
.min(1)
|
||||||
@ -74,30 +69,6 @@ export const ZFieldWidthSchema = z.number().min(1).describe('The width of the fi
|
|||||||
|
|
||||||
export const ZFieldHeightSchema = z.number().min(1).describe('The height of the field.');
|
export const ZFieldHeightSchema = z.number().min(1).describe('The height of the field.');
|
||||||
|
|
||||||
export const ZClampedFieldPositionXSchema = z
|
|
||||||
.number()
|
|
||||||
.min(0)
|
|
||||||
.max(100)
|
|
||||||
.describe('The percentage based X coordinate where the field will be placed.');
|
|
||||||
|
|
||||||
export const ZClampedFieldPositionYSchema = z
|
|
||||||
.number()
|
|
||||||
.min(0)
|
|
||||||
.max(100)
|
|
||||||
.describe('The percentage based Y coordinate where the field will be placed.');
|
|
||||||
|
|
||||||
export const ZClampedFieldWidthSchema = z
|
|
||||||
.number()
|
|
||||||
.min(0)
|
|
||||||
.max(100)
|
|
||||||
.describe('The percentage based width of the field on the page.');
|
|
||||||
|
|
||||||
export const ZClampedFieldHeightSchema = z
|
|
||||||
.number()
|
|
||||||
.min(0)
|
|
||||||
.max(100)
|
|
||||||
.describe('The percentage based height of the field on the page.');
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
|
|
||||||
const PrismaDecimalSchema = z.preprocess(
|
const PrismaDecimalSchema = z.preprocess(
|
||||||
|
|||||||
@ -95,18 +95,3 @@ export const ZRecipientManySchema = RecipientSchema.pick({
|
|||||||
documentId: z.number().nullish(),
|
documentId: z.number().nullish(),
|
||||||
templateId: z.number().nullish(),
|
templateId: z.number().nullish(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZEnvelopeRecipientSchema = ZRecipientSchema.omit({
|
|
||||||
documentId: true,
|
|
||||||
templateId: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZEnvelopeRecipientLiteSchema = ZRecipientLiteSchema.omit({
|
|
||||||
documentId: true,
|
|
||||||
templateId: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZEnvelopeRecipientManySchema = ZRecipientManySchema.omit({
|
|
||||||
documentId: true,
|
|
||||||
templateId: true,
|
|
||||||
});
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { match } from 'ts-pattern';
|
|||||||
|
|
||||||
import { DEFAULT_STANDARD_FONT_SIZE } from '../../constants/pdf';
|
import { DEFAULT_STANDARD_FONT_SIZE } from '../../constants/pdf';
|
||||||
import type { TCheckboxFieldMeta } from '../../types/field-meta';
|
import type { TCheckboxFieldMeta } from '../../types/field-meta';
|
||||||
import { parseCheckboxCustomText } from '../../utils/fields';
|
|
||||||
import {
|
import {
|
||||||
createFieldHoverInteraction,
|
createFieldHoverInteraction,
|
||||||
konvaTextFill,
|
konvaTextFill,
|
||||||
@ -131,7 +130,7 @@ export const renderCheckboxFieldElement = (
|
|||||||
pageLayer.batchDraw();
|
pageLayer.batchDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkedValues: number[] = field.customText ? parseCheckboxCustomText(field.customText) : [];
|
const checkedValues: number[] = field.customText ? JSON.parse(field.customText) : [];
|
||||||
|
|
||||||
checkboxValues.forEach(({ value, checked }, index) => {
|
checkboxValues.forEach(({ value, checked }, index) => {
|
||||||
const isCheckboxChecked = match(mode)
|
const isCheckboxChecked = match(mode)
|
||||||
@ -171,7 +170,7 @@ export const renderCheckboxFieldElement = (
|
|||||||
width: itemSize,
|
width: itemSize,
|
||||||
height: itemSize,
|
height: itemSize,
|
||||||
stroke: '#374151',
|
stroke: '#374151',
|
||||||
strokeWidth: 1.5,
|
strokeWidth: 2,
|
||||||
cornerRadius: 2,
|
cornerRadius: 2,
|
||||||
fill: 'white',
|
fill: 'white',
|
||||||
});
|
});
|
||||||
|
|||||||
@ -159,7 +159,7 @@ export const renderRadioFieldElement = (
|
|||||||
y: itemInputY,
|
y: itemInputY,
|
||||||
radius: calculateRadioSize(fontSize) / 2,
|
radius: calculateRadioSize(fontSize) / 2,
|
||||||
stroke: '#374151',
|
stroke: '#374151',
|
||||||
strokeWidth: 1.5,
|
strokeWidth: 2,
|
||||||
fill: 'white',
|
fill: 'white',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -81,10 +81,6 @@ export const mapFieldToLegacyField = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const parseCheckboxCustomText = (customText: string): number[] => {
|
export const parseCheckboxCustomText = (customText: string): number[] => {
|
||||||
if (!customText) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return JSON.parse(customText);
|
return JSON.parse(customText);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
-- AlterEnum
|
||||||
|
-- This migration adds more than one value to an enum.
|
||||||
|
-- With PostgreSQL versions 11 and earlier, this is not possible
|
||||||
|
-- in a single migration. This can be worked around by creating
|
||||||
|
-- multiple migrations, each migration adding only one value to
|
||||||
|
-- the enum.
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'DOCUMENT_VIEWED';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'DOCUMENT_RECIPIENT_COMPLETED';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'DOCUMENT_DOWNLOADED';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'DOCUMENT_REMINDER_SENT';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'TEMPLATE_CREATED';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'TEMPLATE_UPDATED';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'TEMPLATE_DELETED';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'TEMPLATE_USED';
|
||||||
|
ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'RECIPIENT_AUTHENTICATION_FAILED';
|
||||||
@ -172,6 +172,15 @@ enum WebhookTriggerEvents {
|
|||||||
DOCUMENT_COMPLETED
|
DOCUMENT_COMPLETED
|
||||||
DOCUMENT_REJECTED
|
DOCUMENT_REJECTED
|
||||||
DOCUMENT_CANCELLED
|
DOCUMENT_CANCELLED
|
||||||
|
DOCUMENT_VIEWED
|
||||||
|
DOCUMENT_RECIPIENT_COMPLETED
|
||||||
|
DOCUMENT_DOWNLOADED
|
||||||
|
DOCUMENT_REMINDER_SENT
|
||||||
|
TEMPLATE_CREATED
|
||||||
|
TEMPLATE_UPDATED
|
||||||
|
TEMPLATE_DELETED
|
||||||
|
TEMPLATE_USED
|
||||||
|
RECIPIENT_AUTHENTICATION_FAILED
|
||||||
}
|
}
|
||||||
|
|
||||||
model Webhook {
|
model Webhook {
|
||||||
|
|||||||
@ -1,22 +1,11 @@
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import { formatAlignmentTestFields } from '@documenso/app-tests/constants/field-alignment-pdf';
|
|
||||||
import { FIELD_META_TEST_FIELDS } from '@documenso/app-tests/constants/field-meta-pdf';
|
|
||||||
import { isBase64Image } from '@documenso/lib/constants/signatures';
|
|
||||||
import { incrementDocumentId } from '@documenso/lib/server-only/envelope/increment-id';
|
import { incrementDocumentId } from '@documenso/lib/server-only/envelope/increment-id';
|
||||||
import { nanoid, prefixedId } from '@documenso/lib/universal/id';
|
import { prefixedId } from '@documenso/lib/universal/id';
|
||||||
|
|
||||||
import { prisma } from '..';
|
import { prisma } from '..';
|
||||||
import {
|
import { DocumentDataType, DocumentSource, EnvelopeType } from '../client';
|
||||||
DocumentDataType,
|
|
||||||
DocumentSource,
|
|
||||||
DocumentStatus,
|
|
||||||
EnvelopeType,
|
|
||||||
ReadStatus,
|
|
||||||
SendStatus,
|
|
||||||
SigningStatus,
|
|
||||||
} from '../client';
|
|
||||||
import { seedPendingDocument } from './documents';
|
import { seedPendingDocument } from './documents';
|
||||||
import { seedDirectTemplate, seedTemplate } from './templates';
|
import { seedDirectTemplate, seedTemplate } from './templates';
|
||||||
import { seedUser } from './users';
|
import { seedUser } from './users';
|
||||||
@ -166,6 +155,7 @@ export const seedDatabase = async () => {
|
|||||||
userId: exampleUser.user.id,
|
userId: exampleUser.user.id,
|
||||||
teamId: exampleUser.team.id,
|
teamId: exampleUser.team.id,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
seedTemplate({
|
seedTemplate({
|
||||||
title: 'Template 1',
|
title: 'Template 1',
|
||||||
userId: adminUser.user.id,
|
userId: adminUser.user.id,
|
||||||
@ -176,185 +166,5 @@ export const seedDatabase = async () => {
|
|||||||
userId: adminUser.user.id,
|
userId: adminUser.user.id,
|
||||||
teamId: adminUser.team.id,
|
teamId: adminUser.team.id,
|
||||||
}),
|
}),
|
||||||
seedAlignmentTestDocument({
|
|
||||||
userId: exampleUser.user.id,
|
|
||||||
teamId: exampleUser.team.id,
|
|
||||||
recipientName: exampleUser.user.name || '',
|
|
||||||
recipientEmail: exampleUser.user.email,
|
|
||||||
insertFields: false,
|
|
||||||
status: DocumentStatus.DRAFT,
|
|
||||||
}),
|
|
||||||
seedAlignmentTestDocument({
|
|
||||||
userId: exampleUser.user.id,
|
|
||||||
teamId: exampleUser.team.id,
|
|
||||||
recipientName: exampleUser.user.name || '',
|
|
||||||
recipientEmail: exampleUser.user.email,
|
|
||||||
insertFields: true,
|
|
||||||
status: DocumentStatus.PENDING,
|
|
||||||
}),
|
|
||||||
seedAlignmentTestDocument({
|
|
||||||
userId: adminUser.user.id,
|
|
||||||
teamId: adminUser.team.id,
|
|
||||||
recipientName: adminUser.user.name || '',
|
|
||||||
recipientEmail: adminUser.user.email,
|
|
||||||
insertFields: false,
|
|
||||||
status: DocumentStatus.DRAFT,
|
|
||||||
}),
|
|
||||||
seedAlignmentTestDocument({
|
|
||||||
userId: adminUser.user.id,
|
|
||||||
teamId: adminUser.team.id,
|
|
||||||
recipientName: adminUser.user.name || '',
|
|
||||||
recipientEmail: adminUser.user.email,
|
|
||||||
insertFields: true,
|
|
||||||
status: DocumentStatus.PENDING,
|
|
||||||
}),
|
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const seedAlignmentTestDocument = async ({
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
recipientName,
|
|
||||||
recipientEmail,
|
|
||||||
insertFields,
|
|
||||||
status,
|
|
||||||
}: {
|
|
||||||
userId: number;
|
|
||||||
teamId: number;
|
|
||||||
recipientName: string;
|
|
||||||
recipientEmail: string;
|
|
||||||
insertFields: boolean;
|
|
||||||
status: DocumentStatus;
|
|
||||||
}) => {
|
|
||||||
const alignmentPdf = fs
|
|
||||||
.readFileSync(path.join(__dirname, '../../../assets/field-font-alignment.pdf'))
|
|
||||||
.toString('base64');
|
|
||||||
|
|
||||||
const fieldMetaPdf = fs
|
|
||||||
.readFileSync(path.join(__dirname, '../../../assets/field-meta.pdf'))
|
|
||||||
.toString('base64');
|
|
||||||
|
|
||||||
const alignmentDocumentData = await createDocumentData({ documentData: alignmentPdf });
|
|
||||||
const fieldMetaDocumentData = await createDocumentData({ documentData: fieldMetaPdf });
|
|
||||||
|
|
||||||
const documentId = await incrementDocumentId();
|
|
||||||
|
|
||||||
const documentMeta = await prisma.documentMeta.create({
|
|
||||||
data: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
const createdEnvelope = await prisma.envelope.create({
|
|
||||||
data: {
|
|
||||||
id: prefixedId('envelope'),
|
|
||||||
secondaryId: documentId.formattedDocumentId,
|
|
||||||
internalVersion: 2,
|
|
||||||
type: EnvelopeType.DOCUMENT,
|
|
||||||
documentMetaId: documentMeta.id,
|
|
||||||
source: DocumentSource.DOCUMENT,
|
|
||||||
title: `Envelope Full Field Test`,
|
|
||||||
status,
|
|
||||||
envelopeItems: {
|
|
||||||
createMany: {
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: prefixedId('envelope_item'),
|
|
||||||
title: `alignment-pdf`,
|
|
||||||
documentDataId: alignmentDocumentData.id,
|
|
||||||
order: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: prefixedId('envelope_item'),
|
|
||||||
title: `field-meta-pdf`,
|
|
||||||
documentDataId: fieldMetaDocumentData.id,
|
|
||||||
order: 2,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
userId,
|
|
||||||
teamId,
|
|
||||||
recipients: {
|
|
||||||
create: {
|
|
||||||
name: recipientName,
|
|
||||||
email: recipientEmail,
|
|
||||||
token: nanoid(),
|
|
||||||
sendStatus: status === 'DRAFT' ? SendStatus.NOT_SENT : SendStatus.SENT,
|
|
||||||
signingStatus: status === 'COMPLETED' ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED,
|
|
||||||
readStatus: status !== 'DRAFT' ? ReadStatus.OPENED : ReadStatus.NOT_OPENED,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
recipients: true,
|
|
||||||
envelopeItems: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { id, recipients, envelopeItems } = createdEnvelope;
|
|
||||||
|
|
||||||
const recipientId = recipients[0].id;
|
|
||||||
const envelopeItemAlignmentItem = envelopeItems.find((item) => item.order === 1)?.id;
|
|
||||||
const envelopeItemFieldMetaItem = envelopeItems.find((item) => item.order === 2)?.id;
|
|
||||||
|
|
||||||
if (!envelopeItemAlignmentItem || !envelopeItemFieldMetaItem) {
|
|
||||||
throw new Error('Envelope item not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
formatAlignmentTestFields.map(async (field) => {
|
|
||||||
await prisma.field.create({
|
|
||||||
data: {
|
|
||||||
...field,
|
|
||||||
recipientId,
|
|
||||||
envelopeItemId: envelopeItemAlignmentItem,
|
|
||||||
envelopeId: id,
|
|
||||||
customText: insertFields ? field.customText : '',
|
|
||||||
inserted: insertFields,
|
|
||||||
signature: field.signature
|
|
||||||
? {
|
|
||||||
create: {
|
|
||||||
recipientId,
|
|
||||||
signatureImageAsBase64: isBase64Image(field.signature) ? field.signature : null,
|
|
||||||
typedSignature: isBase64Image(field.signature) ? null : field.signature,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
FIELD_META_TEST_FIELDS.map(async (field) => {
|
|
||||||
await prisma.field.create({
|
|
||||||
data: {
|
|
||||||
...field,
|
|
||||||
recipientId,
|
|
||||||
envelopeItemId: envelopeItemFieldMetaItem,
|
|
||||||
envelopeId: id,
|
|
||||||
customText: insertFields ? field.customText : '',
|
|
||||||
inserted: insertFields,
|
|
||||||
signature: field.signature
|
|
||||||
? {
|
|
||||||
create: {
|
|
||||||
recipientId,
|
|
||||||
signatureImageAsBase64: isBase64Image(field.signature) ? field.signature : null,
|
|
||||||
typedSignature: isBase64Image(field.signature) ? null : field.signature,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
return await prisma.envelope.findFirstOrThrow({
|
|
||||||
where: {
|
|
||||||
id: createdEnvelope.id,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
recipients: true,
|
|
||||||
envelopeItems: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
import type { DocumentData } from '@prisma/client';
|
import type { DocumentData } from '@prisma/client';
|
||||||
import { DocumentDataType, EnvelopeType } from '@prisma/client';
|
import { DocumentDataType, EnvelopeType, WebhookTriggerEvents } from '@prisma/client';
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { getEnvelopeById } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
import { getEnvelopeById } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||||
|
import { triggerWebhook } from '@documenso/lib/server-only/webhooks/trigger/trigger-webhook';
|
||||||
|
import {
|
||||||
|
ZWebhookDocumentSchema,
|
||||||
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
|
} from '@documenso/lib/types/webhook-payload';
|
||||||
import { getPresignGetUrl } from '@documenso/lib/universal/upload/server-actions';
|
import { getPresignGetUrl } from '@documenso/lib/universal/upload/server-actions';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
|
|
||||||
@ -76,6 +81,13 @@ export const downloadDocumentRoute = authenticatedProcedure
|
|||||||
const suffix = version === 'signed' ? '_signed.pdf' : '.pdf';
|
const suffix = version === 'signed' ? '_signed.pdf' : '.pdf';
|
||||||
const filename = `${baseTitle}${suffix}`;
|
const filename = `${baseTitle}${suffix}`;
|
||||||
|
|
||||||
|
void triggerWebhook({
|
||||||
|
event: WebhookTriggerEvents.DOCUMENT_DOWNLOADED,
|
||||||
|
data: ZWebhookDocumentSchema.parse(mapEnvelopeToWebhookDocumentPayload(envelope)),
|
||||||
|
userId: envelope.userId,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
downloadUrl: url,
|
downloadUrl: url,
|
||||||
filename,
|
filename,
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export const createAttachmentRoute = authenticatedProcedure
|
|||||||
path: '/envelope/attachment/create',
|
path: '/envelope/attachment/create',
|
||||||
summary: 'Create attachment',
|
summary: 'Create attachment',
|
||||||
description: 'Create a new attachment for an envelope',
|
description: 'Create a new attachment for an envelope',
|
||||||
tags: ['Envelope Attachment'],
|
tags: ['Envelope'],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(ZCreateAttachmentRequestSchema)
|
.input(ZCreateAttachmentRequestSchema)
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export const deleteAttachmentRoute = authenticatedProcedure
|
|||||||
path: '/envelope/attachment/delete',
|
path: '/envelope/attachment/delete',
|
||||||
summary: 'Delete attachment',
|
summary: 'Delete attachment',
|
||||||
description: 'Delete an attachment from an envelope',
|
description: 'Delete an attachment from an envelope',
|
||||||
tags: ['Envelope Attachment'],
|
tags: ['Envelope'],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(ZDeleteAttachmentRequestSchema)
|
.input(ZDeleteAttachmentRequestSchema)
|
||||||
|
|||||||
@ -2,20 +2,20 @@ import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|||||||
import { findAttachmentsByEnvelopeId } from '@documenso/lib/server-only/envelope-attachment/find-attachments-by-envelope-id';
|
import { findAttachmentsByEnvelopeId } from '@documenso/lib/server-only/envelope-attachment/find-attachments-by-envelope-id';
|
||||||
import { findAttachmentsByToken } from '@documenso/lib/server-only/envelope-attachment/find-attachments-by-token';
|
import { findAttachmentsByToken } from '@documenso/lib/server-only/envelope-attachment/find-attachments-by-token';
|
||||||
|
|
||||||
import { maybeAuthenticatedProcedure } from '../../trpc';
|
import { procedure } from '../../trpc';
|
||||||
import {
|
import {
|
||||||
ZFindAttachmentsRequestSchema,
|
ZFindAttachmentsRequestSchema,
|
||||||
ZFindAttachmentsResponseSchema,
|
ZFindAttachmentsResponseSchema,
|
||||||
} from './find-attachments.types';
|
} from './find-attachments.types';
|
||||||
|
|
||||||
export const findAttachmentsRoute = maybeAuthenticatedProcedure
|
export const findAttachmentsRoute = procedure
|
||||||
.meta({
|
.meta({
|
||||||
openapi: {
|
openapi: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/envelope/attachment',
|
path: '/envelope/attachment',
|
||||||
summary: 'Find attachments',
|
summary: 'Find attachments',
|
||||||
description: 'Find all attachments for an envelope',
|
description: 'Find all attachments for an envelope',
|
||||||
tags: ['Envelope Attachment'],
|
tags: ['Envelope'],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(ZFindAttachmentsRequestSchema)
|
.input(ZFindAttachmentsRequestSchema)
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export const updateAttachmentRoute = authenticatedProcedure
|
|||||||
path: '/envelope/attachment/update',
|
path: '/envelope/attachment/update',
|
||||||
summary: 'Update attachment',
|
summary: 'Update attachment',
|
||||||
description: 'Update an existing attachment',
|
description: 'Update an existing attachment',
|
||||||
tags: ['Envelope Attachment'],
|
tags: ['Envelope'],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(ZUpdateAttachmentRequestSchema)
|
.input(ZUpdateAttachmentRequestSchema)
|
||||||
|
|||||||
@ -13,21 +13,11 @@ import {
|
|||||||
} from './create-envelope-items.types';
|
} from './create-envelope-items.types';
|
||||||
|
|
||||||
export const createEnvelopeItemsRoute = authenticatedProcedure
|
export const createEnvelopeItemsRoute = authenticatedProcedure
|
||||||
// Todo: Envelopes - Pending direct uploads
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/item/create-many',
|
|
||||||
summary: 'Create envelope items',
|
|
||||||
description: 'Create multiple envelope items for an envelope',
|
|
||||||
tags: ['Envelope Item'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZCreateEnvelopeItemsRequestSchema)
|
.input(ZCreateEnvelopeItemsRequestSchema)
|
||||||
.output(ZCreateEnvelopeItemsResponseSchema)
|
.output(ZCreateEnvelopeItemsResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { user, teamId, metadata } = ctx;
|
const { user, teamId, metadata } = ctx;
|
||||||
const { envelopeId, data: items } = input;
|
const { envelopeId, items } = input;
|
||||||
|
|
||||||
ctx.logger.info({
|
ctx.logger.info({
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { ZDocumentTitleSchema } from '../document-router/schema';
|
|||||||
|
|
||||||
export const ZCreateEnvelopeItemsRequestSchema = z.object({
|
export const ZCreateEnvelopeItemsRequestSchema = z.object({
|
||||||
envelopeId: z.string(),
|
envelopeId: z.string(),
|
||||||
data: z
|
items: z
|
||||||
.object({
|
.object({
|
||||||
title: ZDocumentTitleSchema,
|
title: ZDocumentTitleSchema,
|
||||||
documentDataId: z.string(),
|
documentDataId: z.string(),
|
||||||
|
|||||||
@ -9,15 +9,6 @@ import {
|
|||||||
} from './create-envelope.types';
|
} from './create-envelope.types';
|
||||||
|
|
||||||
export const createEnvelopeRoute = authenticatedProcedure
|
export const createEnvelopeRoute = authenticatedProcedure
|
||||||
// Todo: Envelopes - Pending direct uploads
|
|
||||||
// .meta({
|
|
||||||
// openapi: {
|
|
||||||
// method: 'POST',
|
|
||||||
// path: '/envelope/create',
|
|
||||||
// summary: 'Create envelope',
|
|
||||||
// tags: ['Envelope'],
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
.input(ZCreateEnvelopeRequestSchema)
|
.input(ZCreateEnvelopeRequestSchema)
|
||||||
.output(ZCreateEnvelopeResponseSchema)
|
.output(ZCreateEnvelopeResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -24,6 +24,16 @@ import {
|
|||||||
} from '../document-router/schema';
|
} from '../document-router/schema';
|
||||||
import { ZCreateRecipientSchema } from '../recipient-router/schema';
|
import { ZCreateRecipientSchema } from '../recipient-router/schema';
|
||||||
|
|
||||||
|
// Currently not in use until we allow passthrough documents on create.
|
||||||
|
// export const createEnvelopeMeta: TrpcRouteMeta = {
|
||||||
|
// openapi: {
|
||||||
|
// method: 'POST',
|
||||||
|
// path: '/envelope/create',
|
||||||
|
// summary: 'Create envelope',
|
||||||
|
// tags: ['Envelope'],
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
export const ZCreateEnvelopeRequestSchema = z.object({
|
export const ZCreateEnvelopeRequestSchema = z.object({
|
||||||
title: ZDocumentTitleSchema,
|
title: ZDocumentTitleSchema,
|
||||||
type: z.nativeEnum(EnvelopeType),
|
type: z.nativeEnum(EnvelopeType),
|
||||||
|
|||||||
@ -12,15 +12,6 @@ import {
|
|||||||
} from './delete-envelope-item.types';
|
} from './delete-envelope-item.types';
|
||||||
|
|
||||||
export const deleteEnvelopeItemRoute = authenticatedProcedure
|
export const deleteEnvelopeItemRoute = authenticatedProcedure
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/item/delete',
|
|
||||||
summary: 'Delete envelope item',
|
|
||||||
description: 'Delete an envelope item from an envelope',
|
|
||||||
tags: ['Envelope Item'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZDeleteEnvelopeItemRequestSchema)
|
.input(ZDeleteEnvelopeItemRequestSchema)
|
||||||
.output(ZDeleteEnvelopeItemResponseSchema)
|
.output(ZDeleteEnvelopeItemResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
import { EnvelopeType } from '@prisma/client';
|
import { EnvelopeType } from '@prisma/client';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
||||||
import { deleteDocument } from '@documenso/lib/server-only/document/delete-document';
|
import { deleteDocument } from '@documenso/lib/server-only/document/delete-document';
|
||||||
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../trpc';
|
import { authenticatedProcedure } from '../trpc';
|
||||||
import {
|
import {
|
||||||
@ -13,19 +11,12 @@ import {
|
|||||||
} from './delete-envelope.types';
|
} from './delete-envelope.types';
|
||||||
|
|
||||||
export const deleteEnvelopeRoute = authenticatedProcedure
|
export const deleteEnvelopeRoute = authenticatedProcedure
|
||||||
.meta({
|
// .meta(deleteEnvelopeMeta)
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/delete',
|
|
||||||
summary: 'Delete envelope',
|
|
||||||
tags: ['Envelope'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZDeleteEnvelopeRequestSchema)
|
.input(ZDeleteEnvelopeRequestSchema)
|
||||||
.output(ZDeleteEnvelopeResponseSchema)
|
.output(ZDeleteEnvelopeResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const { teamId } = ctx;
|
const { teamId } = ctx;
|
||||||
const { envelopeId } = input;
|
const { envelopeId, envelopeType } = input;
|
||||||
|
|
||||||
ctx.logger.info({
|
ctx.logger.info({
|
||||||
input: {
|
input: {
|
||||||
@ -33,22 +24,7 @@ export const deleteEnvelopeRoute = authenticatedProcedure
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const unsafeEnvelope = await prisma.envelope.findUnique({
|
await match(envelopeType)
|
||||||
where: {
|
|
||||||
id: envelopeId,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
type: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!unsafeEnvelope) {
|
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
||||||
message: 'Envelope not found',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await match(unsafeEnvelope.type)
|
|
||||||
.with(EnvelopeType.DOCUMENT, async () =>
|
.with(EnvelopeType.DOCUMENT, async () =>
|
||||||
deleteDocument({
|
deleteDocument({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
|
|||||||
@ -1,7 +1,18 @@
|
|||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
// export const deleteEnvelopeMeta: TrpcRouteMeta = {
|
||||||
|
// openapi: {
|
||||||
|
// method: 'POST',
|
||||||
|
// path: '/envelope/delete',
|
||||||
|
// summary: 'Delete envelope',
|
||||||
|
// tags: ['Envelope'],
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
export const ZDeleteEnvelopeRequestSchema = z.object({
|
export const ZDeleteEnvelopeRequestSchema = z.object({
|
||||||
envelopeId: z.string(),
|
envelopeId: z.string(),
|
||||||
|
envelopeType: z.nativeEnum(EnvelopeType),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZDeleteEnvelopeResponseSchema = z.void();
|
export const ZDeleteEnvelopeResponseSchema = z.void();
|
||||||
|
|||||||
@ -8,15 +8,7 @@ import {
|
|||||||
} from './distribute-envelope.types';
|
} from './distribute-envelope.types';
|
||||||
|
|
||||||
export const distributeEnvelopeRoute = authenticatedProcedure
|
export const distributeEnvelopeRoute = authenticatedProcedure
|
||||||
.meta({
|
// .meta(distributeEnvelopeMeta)
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/distribute',
|
|
||||||
summary: 'Distribute envelope',
|
|
||||||
description: 'Send the envelope to recipients based on your distribution method',
|
|
||||||
tags: ['Envelope'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZDistributeEnvelopeRequestSchema)
|
.input(ZDistributeEnvelopeRequestSchema)
|
||||||
.output(ZDistributeEnvelopeResponseSchema)
|
.output(ZDistributeEnvelopeResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -2,6 +2,16 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
import { ZDocumentMetaUpdateSchema } from '@documenso/lib/types/document-meta';
|
import { ZDocumentMetaUpdateSchema } from '@documenso/lib/types/document-meta';
|
||||||
|
|
||||||
|
// export const distributeEnvelopeMeta: TrpcRouteMeta = {
|
||||||
|
// openapi: {
|
||||||
|
// method: 'POST',
|
||||||
|
// path: '/envelope/distribute',
|
||||||
|
// summary: 'Distribute envelope',
|
||||||
|
// description: 'Send the document out to recipients based on your distribution method',
|
||||||
|
// tags: ['Envelope'],
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
export const ZDistributeEnvelopeRequestSchema = z.object({
|
export const ZDistributeEnvelopeRequestSchema = z.object({
|
||||||
envelopeId: z.string().describe('The ID of the envelope to send.'),
|
envelopeId: z.string().describe('The ID of the envelope to send.'),
|
||||||
meta: ZDocumentMetaUpdateSchema.pick({
|
meta: ZDocumentMetaUpdateSchema.pick({
|
||||||
|
|||||||
@ -7,15 +7,6 @@ import {
|
|||||||
} from './duplicate-envelope.types';
|
} from './duplicate-envelope.types';
|
||||||
|
|
||||||
export const duplicateEnvelopeRoute = authenticatedProcedure
|
export const duplicateEnvelopeRoute = authenticatedProcedure
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/duplicate',
|
|
||||||
summary: 'Duplicate envelope',
|
|
||||||
description: 'Duplicate an envelope with all its settings',
|
|
||||||
tags: ['Envelope'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZDuplicateEnvelopeRequestSchema)
|
.input(ZDuplicateEnvelopeRequestSchema)
|
||||||
.output(ZDuplicateEnvelopeResponseSchema)
|
.output(ZDuplicateEnvelopeResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -1,41 +0,0 @@
|
|||||||
import { createEnvelopeFields } from '@documenso/lib/server-only/field/create-envelope-fields';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZCreateEnvelopeFieldsRequestSchema,
|
|
||||||
ZCreateEnvelopeFieldsResponseSchema,
|
|
||||||
} from './create-envelope-fields.types';
|
|
||||||
|
|
||||||
export const createEnvelopeFieldsRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/field/create-many',
|
|
||||||
summary: 'Create envelope fields',
|
|
||||||
description: 'Create multiple fields for an envelope',
|
|
||||||
tags: ['Envelope Fields'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZCreateEnvelopeFieldsRequestSchema)
|
|
||||||
.output(ZCreateEnvelopeFieldsResponseSchema)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
|
||||||
const { user, teamId, metadata } = ctx;
|
|
||||||
const { envelopeId, data: fields } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
envelopeId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return await createEnvelopeFields({
|
|
||||||
userId: user.id,
|
|
||||||
teamId,
|
|
||||||
id: {
|
|
||||||
type: 'envelopeId',
|
|
||||||
id: envelopeId,
|
|
||||||
},
|
|
||||||
fields,
|
|
||||||
requestMetadata: metadata,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ZClampedFieldHeightSchema,
|
|
||||||
ZClampedFieldPositionXSchema,
|
|
||||||
ZClampedFieldPositionYSchema,
|
|
||||||
ZClampedFieldWidthSchema,
|
|
||||||
ZFieldPageNumberSchema,
|
|
||||||
ZFieldSchema,
|
|
||||||
} from '@documenso/lib/types/field';
|
|
||||||
import { ZFieldAndMetaSchema } from '@documenso/lib/types/field-meta';
|
|
||||||
|
|
||||||
const ZCreateFieldSchema = ZFieldAndMetaSchema.and(
|
|
||||||
z.object({
|
|
||||||
recipientId: z.number().describe('The ID of the recipient to create the field for'),
|
|
||||||
envelopeItemId: z
|
|
||||||
.string()
|
|
||||||
.optional()
|
|
||||||
.describe(
|
|
||||||
'The ID of the envelope item to put the field on. If not provided, field will be placed on the first item.',
|
|
||||||
),
|
|
||||||
page: ZFieldPageNumberSchema,
|
|
||||||
positionX: ZClampedFieldPositionXSchema,
|
|
||||||
positionY: ZClampedFieldPositionYSchema,
|
|
||||||
width: ZClampedFieldWidthSchema,
|
|
||||||
height: ZClampedFieldHeightSchema,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const ZCreateEnvelopeFieldsRequestSchema = z.object({
|
|
||||||
envelopeId: z.string(),
|
|
||||||
data: ZCreateFieldSchema.array(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZCreateEnvelopeFieldsResponseSchema = z.object({
|
|
||||||
fields: z.array(ZFieldSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TCreateEnvelopeFieldsRequest = z.infer<typeof ZCreateEnvelopeFieldsRequestSchema>;
|
|
||||||
export type TCreateEnvelopeFieldsResponse = z.infer<typeof ZCreateEnvelopeFieldsResponseSchema>;
|
|
||||||
@ -1,125 +0,0 @@
|
|||||||
import { EnvelopeType } from '@prisma/client';
|
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
||||||
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
|
||||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
|
||||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
|
||||||
import { canRecipientFieldsBeModified } from '@documenso/lib/utils/recipients';
|
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZDeleteEnvelopeFieldRequestSchema,
|
|
||||||
ZDeleteEnvelopeFieldResponseSchema,
|
|
||||||
} from './delete-envelope-field.types';
|
|
||||||
|
|
||||||
export const deleteEnvelopeFieldRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/field/delete',
|
|
||||||
summary: 'Delete envelope field',
|
|
||||||
description: 'Delete an envelope field',
|
|
||||||
tags: ['Envelope Field'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZDeleteEnvelopeFieldRequestSchema)
|
|
||||||
.output(ZDeleteEnvelopeFieldResponseSchema)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
|
||||||
const { user, teamId, metadata } = ctx;
|
|
||||||
const { fieldId } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
fieldId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const unsafeField = await prisma.field.findUnique({
|
|
||||||
where: {
|
|
||||||
id: fieldId,
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
envelopeId: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!unsafeField) {
|
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
||||||
message: 'Field not found',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
|
||||||
id: {
|
|
||||||
type: 'envelopeId',
|
|
||||||
id: unsafeField.envelopeId,
|
|
||||||
},
|
|
||||||
type: null,
|
|
||||||
userId: user.id,
|
|
||||||
teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const envelope = await prisma.envelope.findUnique({
|
|
||||||
where: envelopeWhereInput,
|
|
||||||
include: {
|
|
||||||
recipients: {
|
|
||||||
include: {
|
|
||||||
fields: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const recipientWithFields = envelope?.recipients.find((recipient) =>
|
|
||||||
recipient.fields.some((field) => field.id === fieldId),
|
|
||||||
);
|
|
||||||
const fieldToDelete = recipientWithFields?.fields.find((field) => field.id === fieldId);
|
|
||||||
|
|
||||||
if (!envelope || !recipientWithFields || !fieldToDelete) {
|
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
||||||
message: 'Field not found',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (envelope.completedAt) {
|
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
|
||||||
message: 'Envelope already complete',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether the recipient associated with the field can have new fields created.
|
|
||||||
if (!canRecipientFieldsBeModified(recipientWithFields, recipientWithFields.fields)) {
|
|
||||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
|
||||||
message: 'Recipient has already interacted with the document.',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await prisma.$transaction(async (tx) => {
|
|
||||||
const deletedField = await tx.field.delete({
|
|
||||||
where: {
|
|
||||||
id: fieldToDelete.id,
|
|
||||||
envelopeId: envelope.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle field deleted audit log.
|
|
||||||
if (envelope.type === EnvelopeType.DOCUMENT) {
|
|
||||||
await tx.documentAuditLog.create({
|
|
||||||
data: createDocumentAuditLogData({
|
|
||||||
type: DOCUMENT_AUDIT_LOG_TYPE.FIELD_DELETED,
|
|
||||||
envelopeId: envelope.id,
|
|
||||||
metadata,
|
|
||||||
data: {
|
|
||||||
fieldId: deletedField.secondaryId,
|
|
||||||
fieldRecipientEmail: recipientWithFields.email,
|
|
||||||
fieldRecipientId: deletedField.recipientId,
|
|
||||||
fieldType: deletedField.type,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return deletedField;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const ZDeleteEnvelopeFieldRequestSchema = z.object({
|
|
||||||
fieldId: z.number(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZDeleteEnvelopeFieldResponseSchema = z.void();
|
|
||||||
|
|
||||||
export type TDeleteEnvelopeFieldRequest = z.infer<typeof ZDeleteEnvelopeFieldRequestSchema>;
|
|
||||||
export type TDeleteEnvelopeFieldResponse = z.infer<typeof ZDeleteEnvelopeFieldResponseSchema>;
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
import { getFieldById } from '@documenso/lib/server-only/field/get-field-by-id';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZGetEnvelopeFieldRequestSchema,
|
|
||||||
ZGetEnvelopeFieldResponseSchema,
|
|
||||||
} from './get-envelope-field.types';
|
|
||||||
|
|
||||||
export const getEnvelopeFieldRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'GET',
|
|
||||||
path: '/envelope/field/{fieldId}',
|
|
||||||
summary: 'Get envelope field',
|
|
||||||
description: 'Returns an envelope field given an ID',
|
|
||||||
tags: ['Envelope Field'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZGetEnvelopeFieldRequestSchema)
|
|
||||||
.output(ZGetEnvelopeFieldResponseSchema)
|
|
||||||
.query(async ({ input, ctx }) => {
|
|
||||||
const { teamId, user } = ctx;
|
|
||||||
const { fieldId } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
fieldId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return await getFieldById({
|
|
||||||
userId: user.id,
|
|
||||||
teamId,
|
|
||||||
fieldId,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { ZEnvelopeFieldSchema } from '@documenso/lib/types/field';
|
|
||||||
|
|
||||||
export const ZGetEnvelopeFieldRequestSchema = z.object({
|
|
||||||
fieldId: z.number(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZGetEnvelopeFieldResponseSchema = ZEnvelopeFieldSchema;
|
|
||||||
|
|
||||||
export type TGetEnvelopeFieldRequest = z.infer<typeof ZGetEnvelopeFieldRequestSchema>;
|
|
||||||
export type TGetEnvelopeFieldResponse = z.infer<typeof ZGetEnvelopeFieldResponseSchema>;
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
import { updateEnvelopeFields } from '@documenso/lib/server-only/field/update-envelope-fields';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZUpdateEnvelopeFieldsRequestSchema,
|
|
||||||
ZUpdateEnvelopeFieldsResponseSchema,
|
|
||||||
} from './update-envelope-fields.types';
|
|
||||||
|
|
||||||
export const updateEnvelopeFieldsRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/field/update-many',
|
|
||||||
summary: 'Update envelope fields',
|
|
||||||
description: 'Update multiple envelope fields for an envelope',
|
|
||||||
tags: ['Envelope Field'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZUpdateEnvelopeFieldsRequestSchema)
|
|
||||||
.output(ZUpdateEnvelopeFieldsResponseSchema)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
|
||||||
const { user, teamId } = ctx;
|
|
||||||
const { envelopeId, data: fields } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
envelopeId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return await updateEnvelopeFields({
|
|
||||||
userId: user.id,
|
|
||||||
teamId,
|
|
||||||
id: {
|
|
||||||
type: 'envelopeId',
|
|
||||||
id: envelopeId,
|
|
||||||
},
|
|
||||||
type: null,
|
|
||||||
fields,
|
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ZClampedFieldHeightSchema,
|
|
||||||
ZClampedFieldPositionXSchema,
|
|
||||||
ZClampedFieldPositionYSchema,
|
|
||||||
ZClampedFieldWidthSchema,
|
|
||||||
ZFieldPageNumberSchema,
|
|
||||||
ZFieldSchema,
|
|
||||||
} from '@documenso/lib/types/field';
|
|
||||||
import { ZFieldAndMetaSchema } from '@documenso/lib/types/field-meta';
|
|
||||||
|
|
||||||
const ZUpdateFieldSchema = ZFieldAndMetaSchema.and(
|
|
||||||
z.object({
|
|
||||||
id: z.number().describe('The ID of the field to update.'),
|
|
||||||
envelopeItemId: z
|
|
||||||
.string()
|
|
||||||
.optional()
|
|
||||||
.describe(
|
|
||||||
'The ID of the envelope item to put the field on. If not provided, field will be placed on the first item.',
|
|
||||||
),
|
|
||||||
page: ZFieldPageNumberSchema.optional(),
|
|
||||||
positionX: ZClampedFieldPositionXSchema.optional(),
|
|
||||||
positionY: ZClampedFieldPositionYSchema.optional(),
|
|
||||||
width: ZClampedFieldWidthSchema.optional(),
|
|
||||||
height: ZClampedFieldHeightSchema.optional(),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const ZUpdateEnvelopeFieldsRequestSchema = z.object({
|
|
||||||
envelopeId: z.string(),
|
|
||||||
data: ZUpdateFieldSchema.array(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZUpdateEnvelopeFieldsResponseSchema = z.object({
|
|
||||||
fields: z.array(ZFieldSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TUpdateEnvelopeFieldsRequest = z.infer<typeof ZUpdateEnvelopeFieldsRequestSchema>;
|
|
||||||
export type TUpdateEnvelopeFieldsResponse = z.infer<typeof ZUpdateEnvelopeFieldsResponseSchema>;
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
import { createEnvelopeRecipients } from '@documenso/lib/server-only/recipient/create-envelope-recipients';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZCreateEnvelopeRecipientsRequestSchema,
|
|
||||||
ZCreateEnvelopeRecipientsResponseSchema,
|
|
||||||
} from './create-envelope-recipients.types';
|
|
||||||
|
|
||||||
export const createEnvelopeRecipientsRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/recipient/create-many',
|
|
||||||
summary: 'Create envelope recipients',
|
|
||||||
description: 'Create multiple recipients for an envelope',
|
|
||||||
tags: ['Envelope Recipients'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZCreateEnvelopeRecipientsRequestSchema)
|
|
||||||
.output(ZCreateEnvelopeRecipientsResponseSchema)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
|
||||||
const { user, teamId, metadata } = ctx;
|
|
||||||
const { envelopeId, data: recipients } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
envelopeId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return await createEnvelopeRecipients({
|
|
||||||
userId: user.id,
|
|
||||||
teamId,
|
|
||||||
id: {
|
|
||||||
type: 'envelopeId',
|
|
||||||
id: envelopeId,
|
|
||||||
},
|
|
||||||
recipients,
|
|
||||||
requestMetadata: metadata,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { ZEnvelopeRecipientLiteSchema } from '@documenso/lib/types/recipient';
|
|
||||||
|
|
||||||
import { ZCreateRecipientSchema } from '../../recipient-router/schema';
|
|
||||||
|
|
||||||
export const ZCreateEnvelopeRecipientsRequestSchema = z.object({
|
|
||||||
envelopeId: z.string(),
|
|
||||||
data: ZCreateRecipientSchema.array(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZCreateEnvelopeRecipientsResponseSchema = z.object({
|
|
||||||
recipients: ZEnvelopeRecipientLiteSchema.array(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TCreateEnvelopeRecipientsRequest = z.infer<
|
|
||||||
typeof ZCreateEnvelopeRecipientsRequestSchema
|
|
||||||
>;
|
|
||||||
export type TCreateEnvelopeRecipientsResponse = z.infer<
|
|
||||||
typeof ZCreateEnvelopeRecipientsResponseSchema
|
|
||||||
>;
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
import { deleteEnvelopeRecipient } from '@documenso/lib/server-only/recipient/delete-envelope-recipient';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZDeleteEnvelopeRecipientRequestSchema,
|
|
||||||
ZDeleteEnvelopeRecipientResponseSchema,
|
|
||||||
} from './delete-envelope-recipient.types';
|
|
||||||
|
|
||||||
export const deleteEnvelopeRecipientRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/recipient/delete',
|
|
||||||
summary: 'Delete envelope recipient',
|
|
||||||
description: 'Delete an envelope recipient',
|
|
||||||
tags: ['Envelope Recipient'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZDeleteEnvelopeRecipientRequestSchema)
|
|
||||||
.output(ZDeleteEnvelopeRecipientResponseSchema)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
|
||||||
const { user, teamId, metadata } = ctx;
|
|
||||||
const { recipientId } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
recipientId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await deleteEnvelopeRecipient({
|
|
||||||
userId: user.id,
|
|
||||||
teamId,
|
|
||||||
recipientId,
|
|
||||||
requestMetadata: metadata,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
export const ZDeleteEnvelopeRecipientRequestSchema = z.object({
|
|
||||||
recipientId: z.number(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZDeleteEnvelopeRecipientResponseSchema = z.void();
|
|
||||||
|
|
||||||
export type TDeleteEnvelopeRecipientRequest = z.infer<typeof ZDeleteEnvelopeRecipientRequestSchema>;
|
|
||||||
export type TDeleteEnvelopeRecipientResponse = z.infer<
|
|
||||||
typeof ZDeleteEnvelopeRecipientResponseSchema
|
|
||||||
>;
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
||||||
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZGetEnvelopeRecipientRequestSchema,
|
|
||||||
ZGetEnvelopeRecipientResponseSchema,
|
|
||||||
} from './get-envelope-recipient.types';
|
|
||||||
|
|
||||||
export const getEnvelopeRecipientRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'GET',
|
|
||||||
path: '/envelope/recipient/{recipientId}',
|
|
||||||
summary: 'Get envelope recipient',
|
|
||||||
description: 'Returns an envelope recipient given an ID',
|
|
||||||
tags: ['Envelope Recipient'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZGetEnvelopeRecipientRequestSchema)
|
|
||||||
.output(ZGetEnvelopeRecipientResponseSchema)
|
|
||||||
.query(async ({ input, ctx }) => {
|
|
||||||
const { teamId, user } = ctx;
|
|
||||||
const { recipientId } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
recipientId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const recipient = await prisma.recipient.findFirst({
|
|
||||||
where: {
|
|
||||||
id: recipientId,
|
|
||||||
envelope: {
|
|
||||||
team: buildTeamWhereQuery({ teamId, userId: user.id }),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
fields: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!recipient) {
|
|
||||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
||||||
message: 'Recipient not found',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return recipient;
|
|
||||||
});
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { ZEnvelopeRecipientSchema } from '@documenso/lib/types/recipient';
|
|
||||||
|
|
||||||
export const ZGetEnvelopeRecipientRequestSchema = z.object({
|
|
||||||
recipientId: z.number(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZGetEnvelopeRecipientResponseSchema = ZEnvelopeRecipientSchema;
|
|
||||||
|
|
||||||
export type TGetEnvelopeRecipientRequest = z.infer<typeof ZGetEnvelopeRecipientRequestSchema>;
|
|
||||||
export type TGetEnvelopeRecipientResponse = z.infer<typeof ZGetEnvelopeRecipientResponseSchema>;
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
import { updateEnvelopeRecipients } from '@documenso/lib/server-only/recipient/update-envelope-recipients';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../../trpc';
|
|
||||||
import {
|
|
||||||
ZUpdateEnvelopeRecipientsRequestSchema,
|
|
||||||
ZUpdateEnvelopeRecipientsResponseSchema,
|
|
||||||
} from './update-envelope-recipients.types';
|
|
||||||
|
|
||||||
export const updateEnvelopeRecipientsRoute = authenticatedProcedure
|
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/recipient/update-many',
|
|
||||||
summary: 'Update envelope recipients',
|
|
||||||
description: 'Update multiple recipients for an envelope',
|
|
||||||
tags: ['Envelope Recipient'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZUpdateEnvelopeRecipientsRequestSchema)
|
|
||||||
.output(ZUpdateEnvelopeRecipientsResponseSchema)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
|
||||||
const { user, teamId } = ctx;
|
|
||||||
const { envelopeId, data: recipients } = input;
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
input: {
|
|
||||||
envelopeId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return await updateEnvelopeRecipients({
|
|
||||||
userId: user.id,
|
|
||||||
teamId,
|
|
||||||
id: {
|
|
||||||
type: 'envelopeId',
|
|
||||||
id: envelopeId,
|
|
||||||
},
|
|
||||||
recipients,
|
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { ZRecipientLiteSchema } from '@documenso/lib/types/recipient';
|
|
||||||
|
|
||||||
import { ZUpdateRecipientSchema } from '../../recipient-router/schema';
|
|
||||||
|
|
||||||
export const ZUpdateEnvelopeRecipientsRequestSchema = z.object({
|
|
||||||
envelopeId: z.string(),
|
|
||||||
data: ZUpdateRecipientSchema.array(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZUpdateEnvelopeRecipientsResponseSchema = z.object({
|
|
||||||
recipients: ZRecipientLiteSchema.array(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TUpdateEnvelopeRecipientsRequest = z.infer<
|
|
||||||
typeof ZUpdateEnvelopeRecipientsRequestSchema
|
|
||||||
>;
|
|
||||||
export type TUpdateEnvelopeRecipientsResponse = z.infer<
|
|
||||||
typeof ZUpdateEnvelopeRecipientsResponseSchema
|
|
||||||
>;
|
|
||||||
@ -4,15 +4,7 @@ import { authenticatedProcedure } from '../trpc';
|
|||||||
import { ZGetEnvelopeRequestSchema, ZGetEnvelopeResponseSchema } from './get-envelope.types';
|
import { ZGetEnvelopeRequestSchema, ZGetEnvelopeResponseSchema } from './get-envelope.types';
|
||||||
|
|
||||||
export const getEnvelopeRoute = authenticatedProcedure
|
export const getEnvelopeRoute = authenticatedProcedure
|
||||||
.meta({
|
// .meta(getEnvelopeMeta)
|
||||||
openapi: {
|
|
||||||
method: 'GET',
|
|
||||||
path: '/envelope/{envelopeId}',
|
|
||||||
summary: 'Get envelope',
|
|
||||||
description: 'Returns an envelope given an ID',
|
|
||||||
tags: ['Envelope'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZGetEnvelopeRequestSchema)
|
.input(ZGetEnvelopeRequestSchema)
|
||||||
.output(ZGetEnvelopeResponseSchema)
|
.output(ZGetEnvelopeResponseSchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -2,6 +2,16 @@ import { z } from 'zod';
|
|||||||
|
|
||||||
import { ZEnvelopeSchema } from '@documenso/lib/types/envelope';
|
import { ZEnvelopeSchema } from '@documenso/lib/types/envelope';
|
||||||
|
|
||||||
|
// export const getEnvelopeMeta: TrpcRouteMeta = {
|
||||||
|
// openapi: {
|
||||||
|
// method: 'GET',
|
||||||
|
// path: '/envelope/{envelopeId}',
|
||||||
|
// summary: 'Get envelope',
|
||||||
|
// description: 'Returns a envelope given an ID',
|
||||||
|
// tags: ['Envelope'],
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
export const ZGetEnvelopeRequestSchema = z.object({
|
export const ZGetEnvelopeRequestSchema = z.object({
|
||||||
envelopeId: z.string(),
|
envelopeId: z.string(),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,16 +7,7 @@ import {
|
|||||||
} from './redistribute-envelope.types';
|
} from './redistribute-envelope.types';
|
||||||
|
|
||||||
export const redistributeEnvelopeRoute = authenticatedProcedure
|
export const redistributeEnvelopeRoute = authenticatedProcedure
|
||||||
.meta({
|
// .meta(redistributeEnvelopeMeta)
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/redistribute',
|
|
||||||
summary: 'Redistribute envelope',
|
|
||||||
description:
|
|
||||||
'Redistribute the envelope to the provided recipients who have not actioned the envelope. Will use the distribution method set in the envelope',
|
|
||||||
tags: ['Envelope'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZRedistributeEnvelopeRequestSchema)
|
.input(ZRedistributeEnvelopeRequestSchema)
|
||||||
.output(ZRedistributeEnvelopeResponseSchema)
|
.output(ZRedistributeEnvelopeResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -1,5 +1,16 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
// export const redistributeEnvelopeMeta: TrpcRouteMeta = {
|
||||||
|
// openapi: {
|
||||||
|
// method: 'POST',
|
||||||
|
// path: '/envelope/redistribute',
|
||||||
|
// summary: 'Redistribute document',
|
||||||
|
// description:
|
||||||
|
// 'Redistribute the document to the provided recipients who have not actioned the document. Will use the distribution method set in the document',
|
||||||
|
// tags: ['Envelope'],
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
export const ZRedistributeEnvelopeRequestSchema = z.object({
|
export const ZRedistributeEnvelopeRequestSchema = z.object({
|
||||||
envelopeId: z.string(),
|
envelopeId: z.string(),
|
||||||
recipients: z
|
recipients: z
|
||||||
|
|||||||
@ -9,14 +9,6 @@ import { deleteEnvelopeRoute } from './delete-envelope';
|
|||||||
import { deleteEnvelopeItemRoute } from './delete-envelope-item';
|
import { deleteEnvelopeItemRoute } from './delete-envelope-item';
|
||||||
import { distributeEnvelopeRoute } from './distribute-envelope';
|
import { distributeEnvelopeRoute } from './distribute-envelope';
|
||||||
import { duplicateEnvelopeRoute } from './duplicate-envelope';
|
import { duplicateEnvelopeRoute } from './duplicate-envelope';
|
||||||
import { createEnvelopeFieldsRoute } from './envelope-fields/create-envelope-fields';
|
|
||||||
import { deleteEnvelopeFieldRoute } from './envelope-fields/delete-envelope-field';
|
|
||||||
import { getEnvelopeFieldRoute } from './envelope-fields/get-envelope-field';
|
|
||||||
import { updateEnvelopeFieldsRoute } from './envelope-fields/update-envelope-fields';
|
|
||||||
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 { updateEnvelopeRecipientsRoute } from './envelope-recipients/update-envelope-recipients';
|
|
||||||
import { getEnvelopeRoute } from './get-envelope';
|
import { getEnvelopeRoute } from './get-envelope';
|
||||||
import { getEnvelopeItemsRoute } from './get-envelope-items';
|
import { getEnvelopeItemsRoute } from './get-envelope-items';
|
||||||
import { getEnvelopeItemsByTokenRoute } from './get-envelope-items-by-token';
|
import { getEnvelopeItemsByTokenRoute } from './get-envelope-items-by-token';
|
||||||
@ -27,18 +19,16 @@ import { signEnvelopeFieldRoute } from './sign-envelope-field';
|
|||||||
import { updateEnvelopeRoute } from './update-envelope';
|
import { updateEnvelopeRoute } from './update-envelope';
|
||||||
import { updateEnvelopeItemsRoute } from './update-envelope-items';
|
import { updateEnvelopeItemsRoute } from './update-envelope-items';
|
||||||
|
|
||||||
/**
|
|
||||||
* Note: The order of the routes is important for public API routes.
|
|
||||||
*
|
|
||||||
* Example: GET /envelope/attachment must appear before GET /envelope/:id
|
|
||||||
*/
|
|
||||||
export const envelopeRouter = router({
|
export const envelopeRouter = router({
|
||||||
attachment: {
|
get: getEnvelopeRoute,
|
||||||
find: findAttachmentsRoute,
|
create: createEnvelopeRoute,
|
||||||
create: createAttachmentRoute,
|
update: updateEnvelopeRoute,
|
||||||
update: updateAttachmentRoute,
|
delete: deleteEnvelopeRoute,
|
||||||
delete: deleteAttachmentRoute,
|
duplicate: duplicateEnvelopeRoute,
|
||||||
},
|
distribute: distributeEnvelopeRoute,
|
||||||
|
redistribute: redistributeEnvelopeRoute,
|
||||||
|
// share: shareEnvelopeRoute,
|
||||||
|
|
||||||
item: {
|
item: {
|
||||||
getMany: getEnvelopeItemsRoute,
|
getMany: getEnvelopeItemsRoute,
|
||||||
getManyByToken: getEnvelopeItemsByTokenRoute,
|
getManyByToken: getEnvelopeItemsByTokenRoute,
|
||||||
@ -47,25 +37,16 @@ export const envelopeRouter = router({
|
|||||||
delete: deleteEnvelopeItemRoute,
|
delete: deleteEnvelopeItemRoute,
|
||||||
},
|
},
|
||||||
recipient: {
|
recipient: {
|
||||||
get: getEnvelopeRecipientRoute,
|
|
||||||
createMany: createEnvelopeRecipientsRoute,
|
|
||||||
updateMany: updateEnvelopeRecipientsRoute,
|
|
||||||
delete: deleteEnvelopeRecipientRoute,
|
|
||||||
set: setEnvelopeRecipientsRoute,
|
set: setEnvelopeRecipientsRoute,
|
||||||
},
|
},
|
||||||
field: {
|
field: {
|
||||||
get: getEnvelopeFieldRoute,
|
|
||||||
createMany: createEnvelopeFieldsRoute,
|
|
||||||
updateMany: updateEnvelopeFieldsRoute,
|
|
||||||
delete: deleteEnvelopeFieldRoute,
|
|
||||||
set: setEnvelopeFieldsRoute,
|
set: setEnvelopeFieldsRoute,
|
||||||
sign: signEnvelopeFieldRoute,
|
sign: signEnvelopeFieldRoute,
|
||||||
},
|
},
|
||||||
get: getEnvelopeRoute,
|
attachment: {
|
||||||
create: createEnvelopeRoute,
|
find: findAttachmentsRoute,
|
||||||
update: updateEnvelopeRoute,
|
create: createAttachmentRoute,
|
||||||
delete: deleteEnvelopeRoute,
|
update: updateAttachmentRoute,
|
||||||
duplicate: duplicateEnvelopeRoute,
|
delete: deleteAttachmentRoute,
|
||||||
distribute: distributeEnvelopeRoute,
|
},
|
||||||
redistribute: redistributeEnvelopeRoute,
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,12 +1,6 @@
|
|||||||
import { EnvelopeType, FieldType } from '@prisma/client';
|
import { EnvelopeType, FieldType } from '@prisma/client';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import {
|
|
||||||
ZClampedFieldHeightSchema,
|
|
||||||
ZClampedFieldPositionXSchema,
|
|
||||||
ZClampedFieldPositionYSchema,
|
|
||||||
ZClampedFieldWidthSchema,
|
|
||||||
} from '@documenso/lib/types/field';
|
|
||||||
import { ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
import { ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||||
|
|
||||||
export const ZSetEnvelopeFieldsRequestSchema = z.object({
|
export const ZSetEnvelopeFieldsRequestSchema = z.object({
|
||||||
@ -26,11 +20,28 @@ export const ZSetEnvelopeFieldsRequestSchema = z.object({
|
|||||||
.number()
|
.number()
|
||||||
.min(1)
|
.min(1)
|
||||||
.describe('The page number of the field on the envelope. Starts from 1.'),
|
.describe('The page number of the field on the envelope. Starts from 1.'),
|
||||||
positionX: ZClampedFieldPositionXSchema,
|
// Todo: Envelopes - Extract these 0-100 schemas with better descriptions.
|
||||||
positionY: ZClampedFieldPositionYSchema,
|
positionX: z
|
||||||
width: ZClampedFieldWidthSchema,
|
.number()
|
||||||
height: ZClampedFieldHeightSchema,
|
.min(0)
|
||||||
fieldMeta: ZFieldMetaSchema,
|
.max(100)
|
||||||
|
.describe('The percentage based X position of the field on the envelope.'),
|
||||||
|
positionY: z
|
||||||
|
.number()
|
||||||
|
.min(0)
|
||||||
|
.max(100)
|
||||||
|
.describe('The percentage based Y position of the field on the envelope.'),
|
||||||
|
width: z
|
||||||
|
.number()
|
||||||
|
.min(0)
|
||||||
|
.max(100)
|
||||||
|
.describe('The percentage based width of the field on the envelope.'),
|
||||||
|
height: z
|
||||||
|
.number()
|
||||||
|
.min(0)
|
||||||
|
.max(100)
|
||||||
|
.describe('The percentage based height of the field on the envelope.'),
|
||||||
|
fieldMeta: ZFieldMetaSchema, // Todo: Envelopes - Use a more strict form?
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -10,15 +10,6 @@ import {
|
|||||||
} from './update-envelope-items.types';
|
} from './update-envelope-items.types';
|
||||||
|
|
||||||
export const updateEnvelopeItemsRoute = authenticatedProcedure
|
export const updateEnvelopeItemsRoute = authenticatedProcedure
|
||||||
.meta({
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/item/update-many',
|
|
||||||
summary: 'Update envelope items',
|
|
||||||
description: 'Update multiple envelope items for an envelope',
|
|
||||||
tags: ['Envelope Item'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZUpdateEnvelopeItemsRequestSchema)
|
.input(ZUpdateEnvelopeItemsRequestSchema)
|
||||||
.output(ZUpdateEnvelopeItemsResponseSchema)
|
.output(ZUpdateEnvelopeItemsResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -7,14 +7,7 @@ import {
|
|||||||
} from './update-envelope.types';
|
} from './update-envelope.types';
|
||||||
|
|
||||||
export const updateEnvelopeRoute = authenticatedProcedure
|
export const updateEnvelopeRoute = authenticatedProcedure
|
||||||
.meta({
|
// .meta(updateEnvelopeTrpcMeta)
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/envelope/update',
|
|
||||||
summary: 'Update envelope',
|
|
||||||
tags: ['Envelope'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.input(ZUpdateEnvelopeRequestSchema)
|
.input(ZUpdateEnvelopeRequestSchema)
|
||||||
.output(ZUpdateEnvelopeResponseSchema)
|
.output(ZUpdateEnvelopeResponseSchema)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
// import type { OpenApiMeta } from 'trpc-to-openapi';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -13,8 +15,18 @@ import {
|
|||||||
ZDocumentVisibilitySchema,
|
ZDocumentVisibilitySchema,
|
||||||
} from '../document-router/schema';
|
} from '../document-router/schema';
|
||||||
|
|
||||||
|
// export const updateEnvelopeMeta: TrpcRouteMeta = {
|
||||||
|
// openapi: {
|
||||||
|
// method: 'POST',
|
||||||
|
// path: '/envelope/update',
|
||||||
|
// summary: 'Update envelope',
|
||||||
|
// tags: ['Envelope'],
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
|
||||||
export const ZUpdateEnvelopeRequestSchema = z.object({
|
export const ZUpdateEnvelopeRequestSchema = z.object({
|
||||||
envelopeId: z.string(),
|
envelopeId: z.string(),
|
||||||
|
envelopeType: z.nativeEnum(EnvelopeType),
|
||||||
data: z
|
data: z
|
||||||
.object({
|
.object({
|
||||||
title: ZDocumentTitleSchema.optional(),
|
title: ZDocumentTitleSchema.optional(),
|
||||||
|
|||||||
@ -8,7 +8,8 @@ import { removeSignedFieldWithToken } from '@documenso/lib/server-only/field/rem
|
|||||||
import { setFieldsForDocument } from '@documenso/lib/server-only/field/set-fields-for-document';
|
import { setFieldsForDocument } from '@documenso/lib/server-only/field/set-fields-for-document';
|
||||||
import { setFieldsForTemplate } from '@documenso/lib/server-only/field/set-fields-for-template';
|
import { setFieldsForTemplate } from '@documenso/lib/server-only/field/set-fields-for-template';
|
||||||
import { signFieldWithToken } from '@documenso/lib/server-only/field/sign-field-with-token';
|
import { signFieldWithToken } from '@documenso/lib/server-only/field/sign-field-with-token';
|
||||||
import { updateEnvelopeFields } from '@documenso/lib/server-only/field/update-envelope-fields';
|
import { updateDocumentFields } from '@documenso/lib/server-only/field/update-document-fields';
|
||||||
|
import { updateTemplateFields } from '@documenso/lib/server-only/field/update-template-fields';
|
||||||
|
|
||||||
import { ZGenericSuccessResponse, ZSuccessResponseSchema } from '../document-router/schema';
|
import { ZGenericSuccessResponse, ZSuccessResponseSchema } from '../document-router/schema';
|
||||||
import { authenticatedProcedure, procedure, router } from '../trpc';
|
import { authenticatedProcedure, procedure, router } from '../trpc';
|
||||||
@ -108,14 +109,7 @@ export const fieldRouter = router({
|
|||||||
type: 'documentId',
|
type: 'documentId',
|
||||||
id: documentId,
|
id: documentId,
|
||||||
},
|
},
|
||||||
fields: [
|
fields: [field],
|
||||||
{
|
|
||||||
...field,
|
|
||||||
page: field.pageNumber,
|
|
||||||
positionX: field.pageX,
|
|
||||||
positionY: field.pageY,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
requestMetadata: ctx.metadata,
|
requestMetadata: ctx.metadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,12 +148,7 @@ export const fieldRouter = router({
|
|||||||
type: 'documentId',
|
type: 'documentId',
|
||||||
id: documentId,
|
id: documentId,
|
||||||
},
|
},
|
||||||
fields: fields.map((field) => ({
|
fields,
|
||||||
...field,
|
|
||||||
page: field.pageNumber,
|
|
||||||
positionX: field.pageX,
|
|
||||||
positionY: field.pageY,
|
|
||||||
})),
|
|
||||||
requestMetadata: ctx.metadata,
|
requestMetadata: ctx.metadata,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@ -189,14 +178,10 @@ export const fieldRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedFields = await updateEnvelopeFields({
|
const updatedFields = await updateDocumentFields({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
documentId,
|
||||||
type: 'documentId',
|
|
||||||
id: documentId,
|
|
||||||
},
|
|
||||||
type: EnvelopeType.DOCUMENT,
|
|
||||||
fields: [field],
|
fields: [field],
|
||||||
requestMetadata: ctx.metadata,
|
requestMetadata: ctx.metadata,
|
||||||
});
|
});
|
||||||
@ -229,14 +214,10 @@ export const fieldRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return await updateEnvelopeFields({
|
return await updateDocumentFields({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
documentId,
|
||||||
type: 'documentId',
|
|
||||||
id: documentId,
|
|
||||||
},
|
|
||||||
type: EnvelopeType.DOCUMENT,
|
|
||||||
fields,
|
fields,
|
||||||
requestMetadata: ctx.metadata,
|
requestMetadata: ctx.metadata,
|
||||||
});
|
});
|
||||||
@ -347,14 +328,7 @@ export const fieldRouter = router({
|
|||||||
type: 'templateId',
|
type: 'templateId',
|
||||||
id: templateId,
|
id: templateId,
|
||||||
},
|
},
|
||||||
fields: [
|
fields: [field],
|
||||||
{
|
|
||||||
...field,
|
|
||||||
page: field.pageNumber,
|
|
||||||
positionX: field.pageX,
|
|
||||||
positionY: field.pageY,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
requestMetadata: ctx.metadata,
|
requestMetadata: ctx.metadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -427,12 +401,7 @@ export const fieldRouter = router({
|
|||||||
type: 'templateId',
|
type: 'templateId',
|
||||||
id: templateId,
|
id: templateId,
|
||||||
},
|
},
|
||||||
fields: fields.map((field) => ({
|
fields,
|
||||||
...field,
|
|
||||||
page: field.pageNumber,
|
|
||||||
positionX: field.pageX,
|
|
||||||
positionY: field.pageY,
|
|
||||||
})),
|
|
||||||
requestMetadata: ctx.metadata,
|
requestMetadata: ctx.metadata,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@ -462,16 +431,11 @@ export const fieldRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedFields = await updateEnvelopeFields({
|
const updatedFields = await updateTemplateFields({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
templateId,
|
||||||
type: 'templateId',
|
|
||||||
id: templateId,
|
|
||||||
},
|
|
||||||
type: EnvelopeType.TEMPLATE,
|
|
||||||
fields: [field],
|
fields: [field],
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return updatedFields.fields[0];
|
return updatedFields.fields[0];
|
||||||
@ -502,16 +466,11 @@ export const fieldRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return await updateEnvelopeFields({
|
return await updateTemplateFields({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
templateId,
|
||||||
type: 'templateId',
|
|
||||||
id: templateId,
|
|
||||||
},
|
|
||||||
type: EnvelopeType.TEMPLATE,
|
|
||||||
fields,
|
fields,
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,15 @@ import { EnvelopeType } from '@prisma/client';
|
|||||||
|
|
||||||
import { completeDocumentWithToken } from '@documenso/lib/server-only/document/complete-document-with-token';
|
import { completeDocumentWithToken } from '@documenso/lib/server-only/document/complete-document-with-token';
|
||||||
import { rejectDocumentWithToken } from '@documenso/lib/server-only/document/reject-document-with-token';
|
import { rejectDocumentWithToken } from '@documenso/lib/server-only/document/reject-document-with-token';
|
||||||
import { createEnvelopeRecipients } from '@documenso/lib/server-only/recipient/create-envelope-recipients';
|
import { createDocumentRecipients } from '@documenso/lib/server-only/recipient/create-document-recipients';
|
||||||
import { deleteEnvelopeRecipient } from '@documenso/lib/server-only/recipient/delete-envelope-recipient';
|
import { createTemplateRecipients } from '@documenso/lib/server-only/recipient/create-template-recipients';
|
||||||
|
import { deleteDocumentRecipient } from '@documenso/lib/server-only/recipient/delete-document-recipient';
|
||||||
|
import { deleteTemplateRecipient } from '@documenso/lib/server-only/recipient/delete-template-recipient';
|
||||||
import { getRecipientById } from '@documenso/lib/server-only/recipient/get-recipient-by-id';
|
import { getRecipientById } from '@documenso/lib/server-only/recipient/get-recipient-by-id';
|
||||||
import { setDocumentRecipients } from '@documenso/lib/server-only/recipient/set-document-recipients';
|
import { setDocumentRecipients } from '@documenso/lib/server-only/recipient/set-document-recipients';
|
||||||
import { setTemplateRecipients } from '@documenso/lib/server-only/recipient/set-template-recipients';
|
import { setTemplateRecipients } from '@documenso/lib/server-only/recipient/set-template-recipients';
|
||||||
import { updateEnvelopeRecipients } from '@documenso/lib/server-only/recipient/update-envelope-recipients';
|
import { updateDocumentRecipients } from '@documenso/lib/server-only/recipient/update-document-recipients';
|
||||||
|
import { updateTemplateRecipients } from '@documenso/lib/server-only/recipient/update-template-recipients';
|
||||||
|
|
||||||
import { ZGenericSuccessResponse, ZSuccessResponseSchema } from '../document-router/schema';
|
import { ZGenericSuccessResponse, ZSuccessResponseSchema } from '../document-router/schema';
|
||||||
import { authenticatedProcedure, procedure, router } from '../trpc';
|
import { authenticatedProcedure, procedure, router } from '../trpc';
|
||||||
@ -105,7 +108,7 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const createdRecipients = await createEnvelopeRecipients({
|
const createdRecipients = await createDocumentRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
id: {
|
||||||
@ -144,7 +147,7 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return await createEnvelopeRecipients({
|
return await createDocumentRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
id: {
|
||||||
@ -181,7 +184,7 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedRecipients = await updateEnvelopeRecipients({
|
const updatedRecipients = await updateDocumentRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
id: {
|
||||||
@ -220,7 +223,7 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return await updateEnvelopeRecipients({
|
return await updateDocumentRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
id: {
|
||||||
@ -256,7 +259,7 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await deleteEnvelopeRecipient({
|
await deleteDocumentRecipient({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
recipientId,
|
recipientId,
|
||||||
@ -360,15 +363,11 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const createdRecipients = await createEnvelopeRecipients({
|
const createdRecipients = await createTemplateRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
templateId,
|
||||||
id: templateId,
|
|
||||||
type: 'templateId',
|
|
||||||
},
|
|
||||||
recipients: [recipient],
|
recipients: [recipient],
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return createdRecipients.recipients[0];
|
return createdRecipients.recipients[0];
|
||||||
@ -399,15 +398,11 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return await createEnvelopeRecipients({
|
return await createTemplateRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
templateId,
|
||||||
id: templateId,
|
|
||||||
type: 'templateId',
|
|
||||||
},
|
|
||||||
recipients,
|
recipients,
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -436,15 +431,11 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedRecipients = await updateEnvelopeRecipients({
|
const updatedRecipients = await updateTemplateRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
templateId,
|
||||||
type: 'templateId',
|
|
||||||
id: templateId,
|
|
||||||
},
|
|
||||||
recipients: [recipient],
|
recipients: [recipient],
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return updatedRecipients.recipients[0];
|
return updatedRecipients.recipients[0];
|
||||||
@ -475,15 +466,11 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return await updateEnvelopeRecipients({
|
return await updateTemplateRecipients({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
id: {
|
templateId,
|
||||||
type: 'templateId',
|
|
||||||
id: templateId,
|
|
||||||
},
|
|
||||||
recipients,
|
recipients,
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -511,11 +498,10 @@ export const recipientRouter = router({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await deleteEnvelopeRecipient({
|
await deleteTemplateRecipient({
|
||||||
recipientId,
|
recipientId,
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return ZGenericSuccessResponse;
|
return ZGenericSuccessResponse;
|
||||||
|
|||||||
@ -164,62 +164,14 @@ export const maybeAuthenticatedMiddleware = t.middleware(async ({ ctx, next, pat
|
|||||||
nonBatchedRequestId: alphaid(),
|
nonBatchedRequestId: alphaid(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const infoToLog: TrpcApiLog = {
|
ctx.logger.info({
|
||||||
path,
|
path,
|
||||||
auth: ctx.metadata.auth,
|
auth: ctx.metadata.auth,
|
||||||
source: ctx.metadata.source,
|
source: ctx.metadata.source,
|
||||||
trpcMiddleware: 'maybeAuthenticated',
|
|
||||||
unverifiedTeamId: ctx.teamId,
|
|
||||||
};
|
|
||||||
|
|
||||||
const authorizationHeader = ctx.req.headers.get('authorization');
|
|
||||||
|
|
||||||
// Taken from `authenticatedMiddleware` in `@documenso/api/v1/middleware/authenticated.ts`.
|
|
||||||
if (authorizationHeader) {
|
|
||||||
// Support for both "Authorization: Bearer api_xxx" and "Authorization: api_xxx"
|
|
||||||
const [token] = (authorizationHeader || '').split('Bearer ').filter((s) => s.length > 0);
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
throw new Error('Token was not provided for authenticated middleware');
|
|
||||||
}
|
|
||||||
|
|
||||||
const apiToken = await getApiTokenByToken({ token });
|
|
||||||
|
|
||||||
ctx.logger.info({
|
|
||||||
...infoToLog,
|
|
||||||
userId: apiToken.user.id,
|
|
||||||
apiTokenId: apiToken.id,
|
|
||||||
} satisfies TrpcApiLog);
|
|
||||||
|
|
||||||
return await next({
|
|
||||||
ctx: {
|
|
||||||
...ctx,
|
|
||||||
user: apiToken.user,
|
|
||||||
teamId: apiToken.teamId,
|
|
||||||
session: null,
|
|
||||||
metadata: {
|
|
||||||
...ctx.metadata,
|
|
||||||
auditUser: apiToken.team
|
|
||||||
? {
|
|
||||||
id: null,
|
|
||||||
email: null,
|
|
||||||
name: apiToken.team.name,
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
id: apiToken.user.id,
|
|
||||||
email: apiToken.user.email,
|
|
||||||
name: apiToken.user.name,
|
|
||||||
},
|
|
||||||
auth: 'api',
|
|
||||||
} satisfies ApiRequestMetadata,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
trpcSessionLogger.info({
|
|
||||||
...infoToLog,
|
|
||||||
userId: ctx.user?.id,
|
userId: ctx.user?.id,
|
||||||
apiTokenId: null,
|
apiTokenId: null,
|
||||||
|
trpcMiddleware: 'maybeAuthenticated',
|
||||||
|
unverifiedTeamId: ctx.teamId,
|
||||||
} satisfies TrpcApiLog);
|
} satisfies TrpcApiLog);
|
||||||
|
|
||||||
return await next({
|
return await next({
|
||||||
|
|||||||
@ -16,12 +16,6 @@ export const numberFormatValues = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export enum CheckboxValidationRules {
|
|
||||||
SELECT_AT_LEAST = 'Select at least',
|
|
||||||
SELECT_EXACTLY = 'Select exactly',
|
|
||||||
SELECT_AT_MOST = 'Select at most',
|
|
||||||
}
|
|
||||||
|
|
||||||
export const checkboxValidationRules = ['Select at least', 'Select exactly', 'Select at most'];
|
export const checkboxValidationRules = ['Select at least', 'Select exactly', 'Select at most'];
|
||||||
export const checkboxValidationLength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
export const checkboxValidationLength = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||||
export const checkboxValidationSigns = [
|
export const checkboxValidationSigns = [
|
||||||
|
|||||||