@verdocs/js-sdk 4.2.27 → 4.2.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -221,44 +221,6 @@ const formatShortTimeAgo = (val) => {
221
221
  }
222
222
  return `${timeDiff}S`;
223
223
  };
224
- function timePeriod(type) {
225
- let endDate = new Date().getTime();
226
- const today = new Date();
227
- const month = today.getMonth();
228
- const year = today.getFullYear();
229
- let startDate = null;
230
- switch (type) {
231
- case '30d':
232
- startDate = endDate - 60 * 60 * 24 * 30 * 1000;
233
- break;
234
- case '60d':
235
- startDate = endDate - 60 * 60 * 24 * 60 * 1000;
236
- break;
237
- case '6m':
238
- startDate = endDate - 60 * 60 * 24 * 30 * 6 * 1000;
239
- break;
240
- case 'this_month':
241
- startDate = new Date(year, month, 1).getTime();
242
- break;
243
- case 'last_month':
244
- startDate = new Date(year, month - 1, 1).getTime();
245
- endDate = new Date(year, month, 0).getTime();
246
- break;
247
- case 'this_year':
248
- startDate = new Date(year, 0, 1);
249
- break;
250
- case 'all_time':
251
- default:
252
- return null;
253
- }
254
- if (startDate === null && endDate === null) {
255
- return null;
256
- }
257
- return {
258
- start_time: new Date(startDate).toISOString(),
259
- end_time: new Date(endDate).toISOString(),
260
- };
261
- }
262
224
 
263
225
  function getRTop(y, fieldHeight, iTextHeight, yRatio) {
264
226
  return iTextHeight - (y + fieldHeight) * yRatio;
@@ -2372,21 +2334,39 @@ const hasRequiredPermissions = (profile, permissions) => permissions.every((perm
2372
2334
 
2373
2335
  /**
2374
2336
  * Add a field to a template.
2337
+ *
2338
+ * ```typescript
2339
+ * import {createField} from '@verdocs/js-sdk/Templates';
2340
+ *
2341
+ * await createField((VerdocsEndpoint.getDefault(), template_id, { ... });
2342
+ * ```
2375
2343
  */
2376
2344
  const createField = (endpoint, templateId, params) => endpoint.api //
2377
- .post(`/templates/${templateId}/fields`, params)
2345
+ .post(`/v2/fields/${templateId}`, params)
2378
2346
  .then((r) => r.data);
2379
2347
  /**
2380
2348
  * Update a template field.
2349
+ *
2350
+ * ```typescript
2351
+ * import {updateField} from '@verdocs/js-sdk/Templates';
2352
+ *
2353
+ * await updateField((VerdocsEndpoint.getDefault(), template_id, field_name, { ... });
2354
+ * ```
2381
2355
  */
2382
- const updateField = (endpoint, templateId, fieldName, params) => endpoint.api //
2383
- .put(`/templates/${templateId}/fields/${fieldName}`, params)
2356
+ const updateField = (endpoint, templateId, name, params) => endpoint.api //
2357
+ .patch(`/fields/${templateId}/${name}`, params)
2384
2358
  .then((r) => r.data);
2385
2359
  /**
2386
- * REmove a field from a template.
2360
+ * Remove a field from a template.
2361
+ *
2362
+ * ```typescript
2363
+ * import {deleteField} from '@verdocs/js-sdk/Templates';
2364
+ *
2365
+ * await deleteField((VerdocsEndpoint.getDefault(), template_id, field_name);
2366
+ * ```
2387
2367
  */
2388
- const deleteField = (endpoint, templateId, fieldName) => endpoint.api //
2389
- .delete(`/templates/${templateId}/fields/${fieldName}`)
2368
+ const deleteField = (endpoint, templateId, name) => endpoint.api //
2369
+ .delete(`/fields/${templateId}/${name}`)
2390
2370
  .then((r) => r.data);
2391
2371
 
2392
2372
  /**
@@ -2633,46 +2613,24 @@ const getAllTags = (endpoint) => endpoint.api //
2633
2613
  * Get all templates accessible by the caller, with optional filters.
2634
2614
  *
2635
2615
  * ```typescript
2636
- * import {Templates} from '@verdocs/js-sdk/Templates';
2616
+ * import {getTemplates} from '@verdocs/js-sdk/Templates';
2637
2617
  *
2638
- * await Templates.getTemplates((VerdocsEndpoint.getDefault());
2639
- * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_starred: true });
2640
- * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_creator: true });
2641
- * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_organization: true });
2618
+ * await getTemplates((VerdocsEndpoint.getDefault());
2619
+ * await getTemplates((VerdocsEndpoint.getDefault(), { is_starred: true });
2620
+ * await getTemplates((VerdocsEndpoint.getDefault(), { is_creator: true });
2621
+ * await getTemplates((VerdocsEndpoint.getDefault(), { is_organization: true });
2642
2622
  * ```
2643
2623
  */
2644
2624
  const getTemplates = (endpoint, params) => endpoint.api //
2645
2625
  .post('/v2/templates', { params })
2646
2626
  .then((r) => r.data);
2647
- // export interface IListTemplatesParams {
2648
- // name?: string;
2649
- // sharing?: 'all' | 'personal' | 'shared' | 'public';
2650
- // starred?: 'all' | 'starred' | 'unstarred';
2651
- // sort?: 'name' | 'created_at' | 'updated_at' | 'last_used_at' | 'counter' | 'star_counter';
2652
- // direction?: 'asc' | 'desc';
2653
- // page?: number;
2654
- // rows?: number;
2655
- // }
2656
- /**
2657
- * Lists all templates accessible by the caller, with optional filters.
2658
- *
2659
- * ```typescript
2660
- * import {Templates} from '@verdocs/js-sdk/Templates';
2661
- *
2662
- * await Templates.listTemplates((VerdocsEndpoint.getDefault(), { sharing: 'personal', sort: 'last_used_at' });
2663
- * ```
2664
- */
2665
- // export const listTemplates = (endpoint: VerdocsEndpoint, params?: IListTemplatesParams) =>
2666
- // endpoint.api //
2667
- // .post<ITemplateSummaries>('/templates/list', params, {baseURL: endpoint.getBaseURLv2()})
2668
- // .then((r) => r.data);
2669
2627
  /**
2670
2628
  * Get one template by its ID.
2671
2629
  *
2672
2630
  * ```typescript
2673
- * import {Templates} from '@verdocs/js-sdk/Templates';
2631
+ * import {getTemplate} from '@verdocs/js-sdk/Templates';
2674
2632
  *
2675
- * const template = await Templates.getTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2633
+ * const template = await getTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2676
2634
  * ```
2677
2635
  */
2678
2636
  const getTemplate = (endpoint, templateId) => endpoint.api //
@@ -2692,6 +2650,7 @@ const getTemplate = (endpoint, templateId) => endpoint.api //
2692
2650
  document.pages = document.page_numbers;
2693
2651
  }
2694
2652
  });
2653
+ // Temporary upgrade from legacy app
2695
2654
  template.fields?.forEach((field) => {
2696
2655
  if (field.setting) {
2697
2656
  field.settings = field.setting;
@@ -2712,9 +2671,9 @@ const ALLOWED_CREATE_FIELDS = [
2712
2671
  * Create a template.
2713
2672
  *
2714
2673
  * ```typescript
2715
- * import {Templates} from '@verdocs/js-sdk/Templates';
2674
+ * import {createTemplate} from '@verdocs/js-sdk/Templates';
2716
2675
  *
2717
- * const newTemplate = await Templates.createTemplatev2((VerdocsEndpoint.getDefault(), {...});
2676
+ * const newTemplate = await createTemplate((VerdocsEndpoint.getDefault(), {...});
2718
2677
  * ```
2719
2678
  */
2720
2679
  const createTemplate = (endpoint, params, onUploadProgress) => {
@@ -2746,63 +2705,40 @@ const createTemplate = (endpoint, params, onUploadProgress) => {
2746
2705
  * Create a template from a Sharepoint asset.
2747
2706
  *
2748
2707
  * ```typescript
2749
- * import {Templates} from '@verdocs/js-sdk/Templates';
2708
+ * import {createTemplateFromSharepoint} from '@verdocs/js-sdk/Templates';
2750
2709
  *
2751
- * const newTemplate = await Templates.createTemplateFromSharepoint((VerdocsEndpoint.getDefault(), {...});
2710
+ * const newTemplate = await createTemplateFromSharepoint((VerdocsEndpoint.getDefault(), {...});
2752
2711
  * ```
2753
2712
  */
2754
2713
  const createTemplateFromSharepoint = (endpoint, params) => {
2755
2714
  const options = {
2756
2715
  timeout: 120000,
2757
2716
  };
2758
- return endpoint.api.post('/templates/from-sharepoint', params, options).then((r) => r.data);
2717
+ return endpoint.api.post('/v2/templates/from-sharepoint', params, options).then((r) => r.data);
2759
2718
  };
2760
2719
  /**
2761
2720
  * Update a template.
2762
2721
  *
2763
2722
  * ```typescript
2764
- * import {Templates} from '@verdocs/js-sdk/Templates';
2723
+ * import {updateTemplate} from '@verdocs/js-sdk/Templates';
2765
2724
  *
2766
- * const updatedTemplate = await Templates.updateTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9', { name: 'New Name' });
2725
+ * const updatedTemplate = await updateTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9', { name: 'New Name' });
2767
2726
  * ```
2768
2727
  */
2769
2728
  const updateTemplate = (endpoint, templateId, params) => endpoint.api //
2770
- .put(`/templates/${templateId}`, params)
2729
+ .put(`/v2/templates/${templateId}`, params)
2771
2730
  .then((r) => r.data);
2772
2731
  /**
2773
2732
  * Delete a template.
2774
2733
  *
2775
2734
  * ```typescript
2776
- * import {Templates} from '@verdocs/js-sdk/Templates';
2735
+ * import {deleteTemplate} from '@verdocs/js-sdk/Templates';
2777
2736
  *
2778
- * await Templates.deleteTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2737
+ * await deleteTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2779
2738
  * ```
2780
2739
  */
2781
2740
  const deleteTemplate = (endpoint, templateId) => endpoint.api //
2782
- .delete(`/templates/${templateId}`)
2783
- .then((r) => r.data);
2784
- /**
2785
- * Search for templates matching various criteria.
2786
- *
2787
- * ```typescript
2788
- * import {Templates} from '@verdocs/js-sdk/Templates';
2789
- *
2790
- * const {result, page, total} = await Templates.search((VerdocsEndpoint.getDefault(), { ... });
2791
- * ```
2792
- */
2793
- const searchTemplates = async (endpoint, params) => endpoint.api //
2794
- .post('/templates/search', params)
2795
- .then((r) => r.data);
2796
- /**
2797
- * List templates.
2798
- *
2799
- * ```typescript
2800
- * import {Templates} from '@verdocs/js-sdk/Templates';
2801
- *
2802
- * const {totals, templates} = await Templates.listTemplates((VerdocsEndpoint.getDefault(), { q: 'test', sort: 'created_at' }); * ```
2803
- */
2804
- const listTemplates = async (endpoint, params = {}) => endpoint.api //
2805
- .post('/templates/list', params)
2741
+ .delete(`/v2/templates/${templateId}`)
2806
2742
  .then((r) => r.data);
2807
2743
 
2808
2744
  /**
@@ -2917,5 +2853,5 @@ const isValidRoleName = (value, roles) => roles.findIndex((role) => role.name ==
2917
2853
  const TagRegEx = /^[a-zA-Z0-9-]{0,32}$/;
2918
2854
  const isValidTag = (value, tags) => TagRegEx.test(value) || tags.findIndex((tag) => tag === value) !== -1;
2919
2855
 
2920
- export { AtoB, Countries, DEFAULT_FIELD_HEIGHTS, DEFAULT_FIELD_SETTINGS, DEFAULT_FIELD_WIDTHS, FIELD_TYPES, RolePermissions, VerdocsEndpoint, acceptOrganizationInvitation, addGroupMember, addTemplateTag, authenticate, blobToBase64, canPerformTemplateAction, cancelEnvelope, capitalize, changePassword, convertToE164, createApiKey, createEnvelope, createEnvelopeReminder, createField, createGroup, createInitials, createOrganizationInvitation, createProfile, createSignature, createTag, createTemplate, createTemplateDocument, createTemplateFromSharepoint, createTemplateReminder, createTemplateRole, declineOrganizationInvitation, decodeAccessTokenBody, decodeJWTBody, deleteApiKey, deleteEnvelopeFieldAttachment, deleteEnvelopeReminder, deleteField, deleteGroupMember, deleteOrganizationInvitation, deleteOrganizationMember, deleteProfile, deleteSignature, deleteTemplate, deleteTemplateDocument, deleteTemplateReminder, deleteTemplateRole, deleteTemplateTag, downloadBlob, envelopeIsActive, envelopeIsComplete, envelopeRecipientAgree, envelopeRecipientChangeOwner, envelopeRecipientDecline, envelopeRecipientPrepare, envelopeRecipientSubmit, envelopeRecipientUpdateName, fileToDataUrl, formatFullName, formatInitials, formatShortTimeAgo, fullNameToInitials, getAllTags, getApiKeys, getCountryByCode, getCurrentProfile, getDocumentDownloadLink, getDocumentPreviewLink, getEnvelope, getEnvelopeDocument, getEnvelopeDocumentPageDisplayUri, getEnvelopeFile, getEnvelopeRecipients, getEnvelopeReminder, getEnvelopes, getEnvelopesSummary, getFieldAttachment, getFieldsForRole, getGroup, getGroups, getInPersonLink, getKbaStep, getMatchingCountry, getMyUser, getNextRecipient, getNotifications, getOrganization, getOrganizationInvitation, getOrganizationInvitations, getOrganizationMembers, getPlusOneCountry, getProfiles, getRGB, getRGBA, getRLeft, getRTop, getRValue, getRecipientsWithActions, getRoleColor, getSignature, getSignatures, getSignerToken, getSigningSession, getStars, getTag, getTemplate, getTemplateDocument, getTemplateDocumentFile, getTemplateDocumentPageDisplayUri, getTemplateDocumentThumbnail, getTemplateDocuments, getTemplateReminder, getTemplateTags, getTemplates, getValidator, getValidators, getWebhooks, hasRequiredPermissions, integerSequence, isAmericanSamoa, isCanada, isDominicanRepublic, isFrenchGuiana, isGuadeloupe, isMartinique, isMayotte, isPuertoRico, isValidEmail, isValidPhone, isValidRoleName, isValidTag, listTemplates, nameToRGBA, recipientCanAct, recipientHasAction, refreshToken, rescale, resendInvitation, resendOrganizationInvitation, resendVerification, resetPassword, rotateApiKey, searchTemplates, sendDelegate, setWebhooks, submitKbaChallengeResponse, submitKbaIdentity, submitKbaPin, switchProfile, timePeriod, toggleStar, updateApiKey, updateEnvelopeField, updateEnvelopeFieldInitials, updateEnvelopeFieldSignature, updateEnvelopeReminder, updateField, updateGroup, updateOrganization, updateOrganizationInvitation, updateOrganizationLogo, updateOrganizationMember, updateOrganizationThumbnail, updateProfile, updateProfilePhoto, updateRecipient, updateTemplate, updateTemplateReminder, updateTemplateRole, uploadEnvelopeFieldAttachment, userCanAct, userCanBuildTemplate, userCanCancelEnvelope, userCanChangeOrgVisibility, userCanCreateOrgTemplate, userCanCreatePersonalTemplate, userCanCreatePublicTemplate, userCanCreateTemplate, userCanDeleteTemplate, userCanFinishEnvelope, userCanMakeTemplatePrivate, userCanMakeTemplatePublic, userCanMakeTemplateShared, userCanPreviewTemplate, userCanReadTemplate, userCanSendTemplate, userCanSignNow, userCanUpdateTemplate, userHasPermissions, userHasSharedTemplate, userIsEnvelopeOwner, userIsEnvelopeRecipient, userIsTemplateCreator, verifyEmail };
2856
+ export { AtoB, Countries, DEFAULT_FIELD_HEIGHTS, DEFAULT_FIELD_SETTINGS, DEFAULT_FIELD_WIDTHS, FIELD_TYPES, RolePermissions, VerdocsEndpoint, acceptOrganizationInvitation, addGroupMember, addTemplateTag, authenticate, blobToBase64, canPerformTemplateAction, cancelEnvelope, capitalize, changePassword, convertToE164, createApiKey, createEnvelope, createEnvelopeReminder, createField, createGroup, createInitials, createOrganizationInvitation, createProfile, createSignature, createTag, createTemplate, createTemplateDocument, createTemplateFromSharepoint, createTemplateReminder, createTemplateRole, declineOrganizationInvitation, decodeAccessTokenBody, decodeJWTBody, deleteApiKey, deleteEnvelopeFieldAttachment, deleteEnvelopeReminder, deleteField, deleteGroupMember, deleteOrganizationInvitation, deleteOrganizationMember, deleteProfile, deleteSignature, deleteTemplate, deleteTemplateDocument, deleteTemplateReminder, deleteTemplateRole, deleteTemplateTag, downloadBlob, envelopeIsActive, envelopeIsComplete, envelopeRecipientAgree, envelopeRecipientChangeOwner, envelopeRecipientDecline, envelopeRecipientPrepare, envelopeRecipientSubmit, envelopeRecipientUpdateName, fileToDataUrl, formatFullName, formatInitials, formatShortTimeAgo, fullNameToInitials, getAllTags, getApiKeys, getCountryByCode, getCurrentProfile, getDocumentDownloadLink, getDocumentPreviewLink, getEnvelope, getEnvelopeDocument, getEnvelopeDocumentPageDisplayUri, getEnvelopeFile, getEnvelopeRecipients, getEnvelopeReminder, getEnvelopes, getEnvelopesSummary, getFieldAttachment, getFieldsForRole, getGroup, getGroups, getInPersonLink, getKbaStep, getMatchingCountry, getMyUser, getNextRecipient, getNotifications, getOrganization, getOrganizationInvitation, getOrganizationInvitations, getOrganizationMembers, getPlusOneCountry, getProfiles, getRGB, getRGBA, getRLeft, getRTop, getRValue, getRecipientsWithActions, getRoleColor, getSignature, getSignatures, getSignerToken, getSigningSession, getStars, getTag, getTemplate, getTemplateDocument, getTemplateDocumentFile, getTemplateDocumentPageDisplayUri, getTemplateDocumentThumbnail, getTemplateDocuments, getTemplateReminder, getTemplateTags, getTemplates, getValidator, getValidators, getWebhooks, hasRequiredPermissions, integerSequence, isAmericanSamoa, isCanada, isDominicanRepublic, isFrenchGuiana, isGuadeloupe, isMartinique, isMayotte, isPuertoRico, isValidEmail, isValidPhone, isValidRoleName, isValidTag, nameToRGBA, recipientCanAct, recipientHasAction, refreshToken, rescale, resendInvitation, resendOrganizationInvitation, resendVerification, resetPassword, rotateApiKey, sendDelegate, setWebhooks, submitKbaChallengeResponse, submitKbaIdentity, submitKbaPin, switchProfile, toggleStar, updateApiKey, updateEnvelopeField, updateEnvelopeFieldInitials, updateEnvelopeFieldSignature, updateEnvelopeReminder, updateField, updateGroup, updateOrganization, updateOrganizationInvitation, updateOrganizationLogo, updateOrganizationMember, updateOrganizationThumbnail, updateProfile, updateProfilePhoto, updateRecipient, updateTemplate, updateTemplateReminder, updateTemplateRole, uploadEnvelopeFieldAttachment, userCanAct, userCanBuildTemplate, userCanCancelEnvelope, userCanChangeOrgVisibility, userCanCreateOrgTemplate, userCanCreatePersonalTemplate, userCanCreatePublicTemplate, userCanCreateTemplate, userCanDeleteTemplate, userCanFinishEnvelope, userCanMakeTemplatePrivate, userCanMakeTemplatePublic, userCanMakeTemplateShared, userCanPreviewTemplate, userCanReadTemplate, userCanSendTemplate, userCanSignNow, userCanUpdateTemplate, userHasPermissions, userHasSharedTemplate, userIsEnvelopeOwner, userIsEnvelopeRecipient, userIsTemplateCreator, verifyEmail };
2921
2857
  //# sourceMappingURL=index.mjs.map