Skip to content

Commit

Permalink
feat: add support for templateId during sign request creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda committed Nov 19, 2024
1 parent 1a1d603 commit 5f5277d
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 133 deletions.
181 changes: 90 additions & 91 deletions src/commands/sign-requests/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SignRequestsCreateCommand extends BoxCommand {
document_preparation_needed: isDocumentPreparationNeeded,
text_signatures_enabled: areTextSignaturesEnabled,
reminders_enabled: areRemindersEnabled,
template_id: templateId,
...rest
} = mapKeys(omit(flags, Object.keys(BoxCommand.flags)), (value, key) => snakeCase(key)
);
Expand All @@ -31,6 +32,7 @@ class SignRequestsCreateCommand extends BoxCommand {
is_document_preparation_needed: isDocumentPreparationNeeded,
are_text_signatures_enabled: areTextSignaturesEnabled,
are_reminders_enabled: areRemindersEnabled,
template_id: templateId,
...rest,
});

Expand All @@ -57,84 +59,80 @@ SignRequestsCreateCommand.flags = {
};

for (const part of input.split(',')) {
const [
key,
value
] = part.split('=');
const [key, value] = part.split('=');

switch (key) {
case 'email':
signer.email = value;
break;

case 'role':
if (!ALLOWED_SIGNER_ROLES.includes(value)) {
throw new BoxCLIError(
`Invalid value for role property of signer: ${value}. Expecting one of: ${ALLOWED_SIGNER_ROLES.join(
', '
)}.`
);
}
signer.role = value;
break;

case 'is-in-person':
case 'is_in_person':
if (value !== '0' && value !== '1') {
throw new BoxCLIError(
`Invalid value for is_in_person property of signer: ${value}. Expecting either 0 or 1.`
);
}
signer.is_in_person = value === '1';
break;

case 'order':
signer.order = value;
break;

case 'embed-url-external-user-id':
case 'embed_url_external_user_id':
signer.embed_url_external_user_id = value;
break;

case 'redirect_url':
case 'redirect-url':
signer.redirect_url = value;
break;

case 'declined-redirect-url':
case 'declined_redirect_url':
signer.declined_redirect_url = value;
break;

case 'signer-group-id':
case 'signer_group_id':
case 'group-id':
case 'group_id':
signer.signer_group_id = value;
break;
default:
throw new BoxCLIError(`Unknown property for signer: ${key}`);
case 'email':
signer.email = value;
break;

case 'role':
if (!ALLOWED_SIGNER_ROLES.includes(value)) {
throw new BoxCLIError(
`Invalid value for role property of signer: ${value}. Expecting one of: ${ALLOWED_SIGNER_ROLES.join(
', '
)}.`
);
}
signer.role = value;
break;

case 'is-in-person':
case 'is_in_person':
if (value !== '0' && value !== '1') {
throw new BoxCLIError(
`Invalid value for is_in_person property of signer: ${value}. Expecting either 0 or 1.`
);
}
signer.is_in_person = value === '1';
break;

case 'order':
signer.order = value;
break;

case 'embed-url-external-user-id':
case 'embed_url_external_user_id':
signer.embed_url_external_user_id = value;
break;

case 'redirect_url':
case 'redirect-url':
signer.redirect_url = value;
break;

case 'declined-redirect-url':
case 'declined_redirect_url':
signer.declined_redirect_url = value;
break;

case 'signer-group-id':
case 'signer_group_id':
case 'group-id':
case 'group_id':
signer.signer_group_id = value;
break;
default:
throw new BoxCLIError(`Unknown property for signer: ${key}`);
}
}

return signer;
},
}),
'source-files': flags.string({
required: true,
description:
'Comma separated list of files to create a signing document from. This is currently limited to 10 files, e.g. 12345',
parse: input => input.split(',').map(id => ({
type: 'file',
id,
})),
parse: (input) =>
input.split(',').map((id) => ({
type: 'file',
id,
})),
}),
'parent-folder': flags.string({
required: true,
description:
'The destination folder to place final, signed document and signing log',
parse: input => ({
parse: (input) => ({
type: 'folder',
id: input,
}),
Expand Down Expand Up @@ -169,35 +167,32 @@ SignRequestsCreateCommand.flags = {
const prefillTag = {};

for (const part of input.split(',')) {
const [
key,
value
] = part.split('=');
const [key, value] = part.split('=');

switch (key) {
case 'id':
prefillTag.document_tag_id = value;
break;

case 'text':
prefillTag.text_value = value;
break;

case 'checkbox':
if (value !== '0' && value !== '1') {
throw new BoxCLIError(
`Invalid value for checkbox property of prefill-tag: ${value}. Expecting either 0 or 1.`
);
}
prefillTag.checkbox_value = value === '1';
break;

case 'date':
prefillTag.date_value = value;
break;

default:
throw new BoxCLIError(`Unknown property for prefill-tag: ${key}`);
case 'id':
prefillTag.document_tag_id = value;
break;

case 'text':
prefillTag.text_value = value;
break;

case 'checkbox':
if (value !== '0' && value !== '1') {
throw new BoxCLIError(
`Invalid value for checkbox property of prefill-tag: ${value}. Expecting either 0 or 1.`
);
}
prefillTag.checkbox_value = value === '1';
break;

case 'date':
prefillTag.date_value = value;
break;

default:
throw new BoxCLIError(`Unknown property for prefill-tag: ${key}`);
}
}

Expand All @@ -214,12 +209,16 @@ SignRequestsCreateCommand.flags = {
}),
'redirect-url': flags.string({
description:
'The URL that a signer will be redirected to after signing a document. Defining this URL overrides the default redirect URL for all signers. If no declined redirect URL is specified, this URL will be used for decline actions as well.',
'The URL that a signer will be redirected to after signing a document. Defining this URL overrides the default redirect URL for all signers. If no declined redirect URL is specified, this URL will be used for decline actions as well.',
}),
'declined-redirect-url': flags.string({
description:
'The URL that a signer will be redirected to after declining to sign a document. Defining this URL overrides the default redirect URL for all signers.',
}),
'template-id': flags.string({
description:
'When a signature request is created from a template this field will indicate the id of that template.',
}),
};

module.exports = SignRequestsCreateCommand;
90 changes: 48 additions & 42 deletions test/commands/sign-requests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,52 @@ describe('Sign requests', () => {
fixture = getFixture('sign-requests/post_sign_requests'),
redirectUrl = 'https://box.com/redirect_url',
declinedRedirectUrl = 'https://box.com/declined_redirect_url',
signerGroupId = 'signers';
signerGroupId = 'signers',
templateId = 'c606e094-a843-4f67-9e00-542b6ce4b080';

test
.nock(TEST_API_ROOT, api => api
.post('/2.0/sign_requests', {
signers: [
{
role: 'approver',
email: signerEmail,
is_in_person: true,
redirect_url: signerRedirectUrl,
declined_redirect_url: signerDeclinedRedirectUrl,
signer_group_id: signerGroupId
},
],
source_files: [
{
type: 'file',
id: fileId,
},
{
type: 'file',
id: fileId2,
}
],
parent_folder: {
type: 'folder',
id: parentFolderId,
},
prefill_tags: [
{
document_tag_id: documentTag1Id,
text_value: documentTag1Value,
},
{
document_tag_id: documentTag2Id,
checkbox_value: false,
.nock(TEST_API_ROOT, (api) =>
api
.post('/2.0/sign_requests', {
signers: [
{
role: 'approver',
email: signerEmail,
is_in_person: true,
redirect_url: signerRedirectUrl,
declined_redirect_url: signerDeclinedRedirectUrl,
signer_group_id: signerGroupId,
},
],
source_files: [
{
type: 'file',
id: fileId,
},
{
type: 'file',
id: fileId2,
},
],
parent_folder: {
type: 'folder',
id: parentFolderId,
},
],
redirect_url: redirectUrl,
declined_redirect_url: declinedRedirectUrl
})
.reply(200, fixture)
prefill_tags: [
{
document_tag_id: documentTag1Id,
text_value: documentTag1Value,
},
{
document_tag_id: documentTag2Id,
checkbox_value: false,
},
],
redirect_url: redirectUrl,
declined_redirect_url: declinedRedirectUrl,
template_id: templateId
})
.reply(200, fixture)
)
.stdout()
.command([
Expand All @@ -113,10 +116,11 @@ describe('Sign requests', () => {
`--prefill-tag=id=${documentTag2Id},checkbox=0`,
`--redirect-url=${redirectUrl}`,
`--declined-redirect-url=${declinedRedirectUrl}`,
`--template-id=${templateId}`,
'--json',
'--token=test',
])
.it('should create a sign request with snake case', ctx => {
.it('should create a sign request with snake case', (ctx) => {
assert.equal(ctx.stdout, fixture);
});

Expand Down Expand Up @@ -158,7 +162,8 @@ describe('Sign requests', () => {
},
],
redirect_url: redirectUrl,
declined_redirect_url: declinedRedirectUrl
declined_redirect_url: declinedRedirectUrl,
template_id: templateId
})
.reply(200, fixture)
)
Expand All @@ -172,6 +177,7 @@ describe('Sign requests', () => {
`--prefill-tag=id=${documentTag2Id},checkbox=0`,
`--redirect-url=${redirectUrl}`,
`--declined-redirect-url=${declinedRedirectUrl}`,
`--template-id=${templateId}`,
'--json',
'--token=test',
])
Expand Down

0 comments on commit 5f5277d

Please sign in to comment.