Skip to content

Commit

Permalink
feat: Support sign template (#848)
Browse files Browse the repository at this point in the history
* feat: Support sign template

* Update type field
  • Loading branch information
congminh1254 authored Sep 7, 2023
1 parent e156e9c commit 18d3413
Show file tree
Hide file tree
Showing 17 changed files with 475 additions and 23 deletions.
16 changes: 16 additions & 0 deletions codegen/codegen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ import { generateManagerClasses } from './generate-manager-classes';
},
],
},
{
name: 'SignTemplatesManager',
comment:
'Simple manager for interacting with all Sign Templates endpoints and actions.',
relativePath: '../src/managers/sign-templates.generated.ts',
operations: [
{
name: 'getById',
operationId: 'get_sign_templates_id',
},
{
name: 'getAll',
operationId: 'get_sign_templates',
},
],
},
{
name: 'ShieldInformationBarrierManager',
comment: '',
Expand Down
41 changes: 41 additions & 0 deletions docs/sign-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Sign Templates

<!-- TODO autogenerate description -->

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Get sign template by ID](#get-sign-template-by-id)
- [List sign templates](#list-sign-templates)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

<!-- TODO autogenerate -->

## Get sign template by ID

Gets a sign template by ID [`signTemplates.getById(options, callback)`](http://opensource.box.com/box-node-sdk/jsdoc/SignTemplatesManager.html#getById)
method.

<!-- sample get_sign_templates_id -->

```js
const sr = await client.signTemplates.getById({
sign_request_id: 12345,
});
console.log(
`Sign request id ${sr.id} contains ${sr.source_files.length} files`
);
```

## List sign templates

Gets sign templates created by a user [`signTemplates.getAll(options, callback)`](http://opensource.box.com/box-node-sdk/jsdoc/SignTemplatesManager.html#getAll)
method.

<!-- sample get_sign_templates -->

```js
const result = await client.signTemplates.getAll();
console.log(`There are ${result.count} sign templates`);
```
3 changes: 3 additions & 0 deletions src/box-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import RetentionPolicies from './managers/retention-policies';
import Search from './managers/search';
import SharedItems from './managers/shared-items';
import SignRequests from './managers/sign-requests.generated';
import SignTemplates from './managers/sign-templates.generated';
import StoragePolicies from './managers/storage-policies';
import Tasks from './managers/tasks';
import TermsOfService from './managers/terms-of-service';
Expand Down Expand Up @@ -200,6 +201,7 @@ class BoxClient {
termsOfService: any;
storagePolicies: any;
signRequests: SignRequests;
signTemplates: SignTemplates;
shieldInformationBarriers: ShieldInformationBarriers;
shieldInformationBarrierSegments: ShieldInformationBarrierSegments;
shieldInformationBarrierSegmentMembers: ShieldInformationBarrierSegmentMembers;
Expand Down Expand Up @@ -274,6 +276,7 @@ class BoxClient {
this.termsOfService = new TermsOfService(this);
this.storagePolicies = new StoragePolicies(this);
this.signRequests = new SignRequests(this);
this.signTemplates = new SignTemplates(this);
this.shieldInformationBarriers = new ShieldInformationBarriers(this);
this.shieldInformationBarrierSegments = new ShieldInformationBarrierSegments(this);
this.shieldInformationBarrierSegmentMembers = new ShieldInformationBarrierSegmentMembers(this);
Expand Down
82 changes: 82 additions & 0 deletions src/managers/sign-templates.generated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import BoxClient from '../box-client';
import urlPath from '../util/url-path';
import * as schemas from '../schemas';
/**
* Simple manager for interacting with all Sign Templates endpoints and actions.
*/
class SignTemplatesManager {
client: BoxClient;
/**
* @param {BoxClient} client The Box API Client that is responsible for making calls to the API
*/
constructor(client: BoxClient) {
this.client = client;
}
/**
* Get Box Sign template by ID
*
* Fetches details of a specific Box Sign template.
* @param {object} options Options for the request
* @param {string} options.template_id The ID of a Box Sign template.
* @param {Function} [callback] Passed the result if successful, error otherwise
* @returns {Promise<schemas.SignTemplate>} A promise resolving to the result or rejecting with an error
*/
getById(
options: {
/**
* The ID of a Box Sign template.
*/
readonly template_id: string;
},
callback?: Function
): Promise<schemas.SignTemplate> {
const { template_id: templateId, ...queryParams } = options,
apiPath = urlPath('sign_templates', templateId),
params = {
qs: queryParams,
};
return this.client.wrapWithDefaultHandler(this.client.get)(
apiPath,
params,
callback
);
}
/**
* List Box Sign templates
*
* Gets Box Sign templates created by a user.
* @param {object} [options] Options for the request
* @param {string} [options.marker] Defines the position marker at which to begin returning results. This is used when paginating using marker-based pagination. This requires `usemarker` to be set to `true`.
* @param {number} [options.limit] The maximum number of items to return per page.
* @param {Function} [callback] Passed the result if successful, error otherwise
* @returns {Promise<schemas.SignTemplates>} A promise resolving to the result or rejecting with an error
*/
getAll(
options?: {
/**
* Defines the position marker at which to begin returning results. This is
* used when paginating using marker-based pagination.
*
* This requires `usemarker` to be set to `true`.
*/
readonly marker?: string;
/**
* The maximum number of items to return per page.
*/
readonly limit?: number;
},
callback?: Function
): Promise<schemas.SignTemplates> {
const { ...queryParams } = options,
apiPath = urlPath('sign_templates'),
params = {
qs: queryParams,
};
return this.client.wrapWithDefaultHandler(this.client.get)(
apiPath,
params,
callback
);
}
}
export = SignTemplatesManager;
10 changes: 5 additions & 5 deletions src/schemas/folder-mini.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import * as schemas from '.';
* nested under another resource.
*/
export interface FolderMini extends schemas.FolderBase {
/**
* The name of the folder.
* Example: Contracts
*/
name?: string;
/**
* A numeric identifier that represents the most recent user event
* that has been applied to this item.
Expand All @@ -23,9 +28,4 @@ export interface FolderMini extends schemas.FolderBase {
* Example: 3
*/
sequence_id?: string;
/**
* The name of the folder.
* Example: Contracts
*/
name?: string;
}
4 changes: 4 additions & 0 deletions src/schemas/index.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ export * from './sign-request-signer-input.generated';
export * from './sign-request-signer.generated';
export * from './sign-request.generated';
export * from './sign-requests.generated';
export * from './sign-template.generated';
export * from './sign-templates.generated';
export * from './template-signer-input.generated';
export * from './template-signer.generated';
export * from './user-base.generated';
9 changes: 7 additions & 2 deletions src/schemas/sign-request-base.generated.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as schemas from '.';
/**
* Create a sign request
* Sign Request (Base)
*
* A request to create a sign request object
*/
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface SignRequestBase {
*/
prefill_tags?: schemas.SignRequestPrefillTag[];
/**
* Number of days after which this request will automatically expire if not completed.
* Set the number of days after which the created signature request will automatically expire if not completed. By default, we do not apply any expiration date on signature requests, and the signature request does not expire.
* Example: 2
*/
days_valid?: number;
Expand All @@ -71,4 +71,9 @@ export interface SignRequestBase {
* Example: true
*/
is_phone_verification_required_to_view?: boolean;
/**
* When a signature request is created from a template this field will indicate the id of that template.
* Example: 123075213-af2c8822-3ef2-4952-8557-52d69c2fe9cb
*/
template_id?: string;
}
12 changes: 2 additions & 10 deletions src/schemas/sign-request-create-request.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@ import * as schemas from '.';
*/
export interface SignRequestCreateRequest extends schemas.SignRequestBase {
/**
* List of files to create a signing document from. This is currently
* limited to 10 files. Only the ID and type fields are required
* for each file. The array will be empty if the `source_files`
* are deleted.
* List of files to create a signing document from. This is currently limited to ten files. Only the ID and type fields are required for each file.
*/
source_files?: schemas.FileMini[];
/**
* Force a specific signature color (blue, black, or red).
* Example: blue
*/
signature_color?: 'blue' | 'black' | 'red';
source_files?: schemas.FileBase[];
/**
* Array of signers for the sign request. 35 is the
* max number of signers permitted.
Expand Down
10 changes: 10 additions & 0 deletions src/schemas/sign-request-signer.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ export interface SignRequestSigner extends schemas.SignRequestCreateSigner {
* Example: https://example.com
*/
embed_url?: string;
/**
* This URL is specifically designed for
* signing documents within an HTML `iframe` tag.
* It will be returned in the response
* only if the `embed_url_external_user_id`
* parameter was passed in the
* `create sign request` call.
* Example: https://app.box.com/embed/sign/document/gfhr4222-a331-494b-808b-79bc7f3992a3/f14d7098-a331-494b-808b-79bc7f3992a4
*/
iframeable_embed_url?: string;
}
12 changes: 7 additions & 5 deletions src/schemas/sign-request.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface SignRequest extends schemas.SignRequestBase {
* Example: sign-request
*/
type?: 'sign-request';
/**
* List of files to create a signing document from. This is currently limited to ten files. Only the ID and type fields are required for each file.
*/
source_files?: schemas.FileBase[];
/**
* Array of signers for the sign request
*/
Expand Down Expand Up @@ -50,7 +54,9 @@ export interface SignRequest extends schemas.SignRequestBase {
| 'declined'
| 'error_converting'
| 'error_sending'
| 'expired';
| 'expired'
| 'finalizing'
| 'error_finalizing';
/**
* List of files that will be signed, which are copies of the original
* source files. A new version of these files are created as signers sign
Expand All @@ -62,8 +68,4 @@ export interface SignRequest extends schemas.SignRequestBase {
* Example: 2021-04-26T08:12:13.982Z
*/
auto_expire_at?: string;
/**
* List of files to create a signing document from. Only the ID and type fields are required for each file. The array will be empty if the `source_files` are deleted.
*/
source_files?: schemas.FileMini[];
}
3 changes: 3 additions & 0 deletions src/schemas/sign-requests.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ export interface SignRequests {
* Example: 1000
*/
prev_marker?: number;
/**
* A list of sign requests
*/
entries?: schemas.SignRequest[];
}
88 changes: 88 additions & 0 deletions src/schemas/sign-template.generated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as schemas from '.';
/**
* Box Sign template
*
* A Box Sign template object
*/
export interface SignTemplate {
/**
* object type
* Example: sign-template
*/
type?: 'sign-template';
/**
* Template identifier.
* Example: 4206996024-14944f75-c34b-478a-95a1-264b1ff80d35
*/
id?: string;
/**
* The name of the template.
* Example: Official contract
*/
name?: string;
/**
* Subject of signature request email. This is cleaned by sign request. If this field is not passed, a default subject will be used.
* Example: Sign Request from Acme
*/
email_subject?: string;
/**
* Message to include in signature request email. The field is cleaned through sanitization of specific characters. However, some html tags are allowed. Links included in the message are also converted to hyperlinks in the email. The message may contain the following html tags including `a`, `abbr`, `acronym`, `b`, `blockquote`, `code`, `em`, `i`, `ul`, `li`, `ol`, and `strong`. Be aware that when the text to html ratio is too high, the email may end up in spam filters. Custom styles on these tags are not allowed. If this field is not passed, a default message will be used.
* Example: Hello! Please sign the document below
*/
email_message?: string;
/**
* Set the number of days after which the created signature request will automatically expire if not completed. By default, we do not apply any expiration date on signature requests, and the signature request does not expire.
* Example: 2
*/
days_valid?: number;
/**
* The destination folder to place final, signed document and signing
* log. Only `ID` and `type` fields are required. The root folder,
* folder ID `0`, cannot be used.
*/
parent_folder?: schemas.FolderMini;
/**
* List of files to create a signing document from. Only the ID and type fields are required for each file.
*/
source_files?: schemas.FileMini[];
/**
* Indicates if the template input fields are editable or not.
*/
are_fields_locked?: boolean;
/**
* Indicates if the template document options are editable or not, for example renaming the document.
* Example: true
*/
are_options_locked?: boolean;
/**
* Indicates if the template signers are editable or not.
*/
are_recipients_locked?: boolean;
/**
* Indicates if the template email settings are editable or not.
* Example: true
*/
are_email_settings_locked?: boolean;
/**
* Indicates if the template files are editable or not. This includes deleting or renaming template files.
* Example: true
*/
are_files_locked?: boolean;
/**
* Array of signers for the template.
*/
signers?: schemas.TemplateSigner[];
/**
* Additional information on which fields are required and which fields are not editable.
*/
additional_info?: object;
/**
* Box's ready-sign link feature enables you to create a link to a signature request that you've created from a template. Use this link when you want to post a signature request on a public form — such as an email, social media post, or web page — without knowing who the signers will be. Note: The ready-sign link feature is limited to Enterprise Plus customers and not available to Box Verified Enterprises.
*/
ready_sign_link?: object;
/**
* Custom branding applied to notifications
* and signature requests.
*/
custom_branding?: object;
}
Loading

0 comments on commit 18d3413

Please sign in to comment.