@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.js CHANGED
@@ -223,44 +223,6 @@ const formatShortTimeAgo = (val) => {
223
223
  }
224
224
  return `${timeDiff}S`;
225
225
  };
226
- function timePeriod(type) {
227
- let endDate = new Date().getTime();
228
- const today = new Date();
229
- const month = today.getMonth();
230
- const year = today.getFullYear();
231
- let startDate = null;
232
- switch (type) {
233
- case '30d':
234
- startDate = endDate - 60 * 60 * 24 * 30 * 1000;
235
- break;
236
- case '60d':
237
- startDate = endDate - 60 * 60 * 24 * 60 * 1000;
238
- break;
239
- case '6m':
240
- startDate = endDate - 60 * 60 * 24 * 30 * 6 * 1000;
241
- break;
242
- case 'this_month':
243
- startDate = new Date(year, month, 1).getTime();
244
- break;
245
- case 'last_month':
246
- startDate = new Date(year, month - 1, 1).getTime();
247
- endDate = new Date(year, month, 0).getTime();
248
- break;
249
- case 'this_year':
250
- startDate = new Date(year, 0, 1);
251
- break;
252
- case 'all_time':
253
- default:
254
- return null;
255
- }
256
- if (startDate === null && endDate === null) {
257
- return null;
258
- }
259
- return {
260
- start_time: new Date(startDate).toISOString(),
261
- end_time: new Date(endDate).toISOString(),
262
- };
263
- }
264
226
 
265
227
  function getRTop(y, fieldHeight, iTextHeight, yRatio) {
266
228
  return iTextHeight - (y + fieldHeight) * yRatio;
@@ -2374,21 +2336,39 @@ const hasRequiredPermissions = (profile, permissions) => permissions.every((perm
2374
2336
 
2375
2337
  /**
2376
2338
  * Add a field to a template.
2339
+ *
2340
+ * ```typescript
2341
+ * import {createField} from '@verdocs/js-sdk/Templates';
2342
+ *
2343
+ * await createField((VerdocsEndpoint.getDefault(), template_id, { ... });
2344
+ * ```
2377
2345
  */
2378
2346
  const createField = (endpoint, templateId, params) => endpoint.api //
2379
- .post(`/templates/${templateId}/fields`, params)
2347
+ .post(`/v2/fields/${templateId}`, params)
2380
2348
  .then((r) => r.data);
2381
2349
  /**
2382
2350
  * Update a template field.
2351
+ *
2352
+ * ```typescript
2353
+ * import {updateField} from '@verdocs/js-sdk/Templates';
2354
+ *
2355
+ * await updateField((VerdocsEndpoint.getDefault(), template_id, field_name, { ... });
2356
+ * ```
2383
2357
  */
2384
- const updateField = (endpoint, templateId, fieldName, params) => endpoint.api //
2385
- .put(`/templates/${templateId}/fields/${fieldName}`, params)
2358
+ const updateField = (endpoint, templateId, name, params) => endpoint.api //
2359
+ .patch(`/fields/${templateId}/${name}`, params)
2386
2360
  .then((r) => r.data);
2387
2361
  /**
2388
- * REmove a field from a template.
2362
+ * Remove a field from a template.
2363
+ *
2364
+ * ```typescript
2365
+ * import {deleteField} from '@verdocs/js-sdk/Templates';
2366
+ *
2367
+ * await deleteField((VerdocsEndpoint.getDefault(), template_id, field_name);
2368
+ * ```
2389
2369
  */
2390
- const deleteField = (endpoint, templateId, fieldName) => endpoint.api //
2391
- .delete(`/templates/${templateId}/fields/${fieldName}`)
2370
+ const deleteField = (endpoint, templateId, name) => endpoint.api //
2371
+ .delete(`/fields/${templateId}/${name}`)
2392
2372
  .then((r) => r.data);
2393
2373
 
2394
2374
  /**
@@ -2635,46 +2615,24 @@ const getAllTags = (endpoint) => endpoint.api //
2635
2615
  * Get all templates accessible by the caller, with optional filters.
2636
2616
  *
2637
2617
  * ```typescript
2638
- * import {Templates} from '@verdocs/js-sdk/Templates';
2618
+ * import {getTemplates} from '@verdocs/js-sdk/Templates';
2639
2619
  *
2640
- * await Templates.getTemplates((VerdocsEndpoint.getDefault());
2641
- * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_starred: true });
2642
- * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_creator: true });
2643
- * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_organization: true });
2620
+ * await getTemplates((VerdocsEndpoint.getDefault());
2621
+ * await getTemplates((VerdocsEndpoint.getDefault(), { is_starred: true });
2622
+ * await getTemplates((VerdocsEndpoint.getDefault(), { is_creator: true });
2623
+ * await getTemplates((VerdocsEndpoint.getDefault(), { is_organization: true });
2644
2624
  * ```
2645
2625
  */
2646
2626
  const getTemplates = (endpoint, params) => endpoint.api //
2647
2627
  .post('/v2/templates', { params })
2648
2628
  .then((r) => r.data);
2649
- // export interface IListTemplatesParams {
2650
- // name?: string;
2651
- // sharing?: 'all' | 'personal' | 'shared' | 'public';
2652
- // starred?: 'all' | 'starred' | 'unstarred';
2653
- // sort?: 'name' | 'created_at' | 'updated_at' | 'last_used_at' | 'counter' | 'star_counter';
2654
- // direction?: 'asc' | 'desc';
2655
- // page?: number;
2656
- // rows?: number;
2657
- // }
2658
- /**
2659
- * Lists all templates accessible by the caller, with optional filters.
2660
- *
2661
- * ```typescript
2662
- * import {Templates} from '@verdocs/js-sdk/Templates';
2663
- *
2664
- * await Templates.listTemplates((VerdocsEndpoint.getDefault(), { sharing: 'personal', sort: 'last_used_at' });
2665
- * ```
2666
- */
2667
- // export const listTemplates = (endpoint: VerdocsEndpoint, params?: IListTemplatesParams) =>
2668
- // endpoint.api //
2669
- // .post<ITemplateSummaries>('/templates/list', params, {baseURL: endpoint.getBaseURLv2()})
2670
- // .then((r) => r.data);
2671
2629
  /**
2672
2630
  * Get one template by its ID.
2673
2631
  *
2674
2632
  * ```typescript
2675
- * import {Templates} from '@verdocs/js-sdk/Templates';
2633
+ * import {getTemplate} from '@verdocs/js-sdk/Templates';
2676
2634
  *
2677
- * const template = await Templates.getTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2635
+ * const template = await getTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2678
2636
  * ```
2679
2637
  */
2680
2638
  const getTemplate = (endpoint, templateId) => endpoint.api //
@@ -2694,6 +2652,7 @@ const getTemplate = (endpoint, templateId) => endpoint.api //
2694
2652
  document.pages = document.page_numbers;
2695
2653
  }
2696
2654
  });
2655
+ // Temporary upgrade from legacy app
2697
2656
  template.fields?.forEach((field) => {
2698
2657
  if (field.setting) {
2699
2658
  field.settings = field.setting;
@@ -2714,9 +2673,9 @@ const ALLOWED_CREATE_FIELDS = [
2714
2673
  * Create a template.
2715
2674
  *
2716
2675
  * ```typescript
2717
- * import {Templates} from '@verdocs/js-sdk/Templates';
2676
+ * import {createTemplate} from '@verdocs/js-sdk/Templates';
2718
2677
  *
2719
- * const newTemplate = await Templates.createTemplatev2((VerdocsEndpoint.getDefault(), {...});
2678
+ * const newTemplate = await createTemplate((VerdocsEndpoint.getDefault(), {...});
2720
2679
  * ```
2721
2680
  */
2722
2681
  const createTemplate = (endpoint, params, onUploadProgress) => {
@@ -2748,63 +2707,40 @@ const createTemplate = (endpoint, params, onUploadProgress) => {
2748
2707
  * Create a template from a Sharepoint asset.
2749
2708
  *
2750
2709
  * ```typescript
2751
- * import {Templates} from '@verdocs/js-sdk/Templates';
2710
+ * import {createTemplateFromSharepoint} from '@verdocs/js-sdk/Templates';
2752
2711
  *
2753
- * const newTemplate = await Templates.createTemplateFromSharepoint((VerdocsEndpoint.getDefault(), {...});
2712
+ * const newTemplate = await createTemplateFromSharepoint((VerdocsEndpoint.getDefault(), {...});
2754
2713
  * ```
2755
2714
  */
2756
2715
  const createTemplateFromSharepoint = (endpoint, params) => {
2757
2716
  const options = {
2758
2717
  timeout: 120000,
2759
2718
  };
2760
- return endpoint.api.post('/templates/from-sharepoint', params, options).then((r) => r.data);
2719
+ return endpoint.api.post('/v2/templates/from-sharepoint', params, options).then((r) => r.data);
2761
2720
  };
2762
2721
  /**
2763
2722
  * Update a template.
2764
2723
  *
2765
2724
  * ```typescript
2766
- * import {Templates} from '@verdocs/js-sdk/Templates';
2725
+ * import {updateTemplate} from '@verdocs/js-sdk/Templates';
2767
2726
  *
2768
- * const updatedTemplate = await Templates.updateTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9', { name: 'New Name' });
2727
+ * const updatedTemplate = await updateTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9', { name: 'New Name' });
2769
2728
  * ```
2770
2729
  */
2771
2730
  const updateTemplate = (endpoint, templateId, params) => endpoint.api //
2772
- .put(`/templates/${templateId}`, params)
2731
+ .put(`/v2/templates/${templateId}`, params)
2773
2732
  .then((r) => r.data);
2774
2733
  /**
2775
2734
  * Delete a template.
2776
2735
  *
2777
2736
  * ```typescript
2778
- * import {Templates} from '@verdocs/js-sdk/Templates';
2737
+ * import {deleteTemplate} from '@verdocs/js-sdk/Templates';
2779
2738
  *
2780
- * await Templates.deleteTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2739
+ * await deleteTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
2781
2740
  * ```
2782
2741
  */
2783
2742
  const deleteTemplate = (endpoint, templateId) => endpoint.api //
2784
- .delete(`/templates/${templateId}`)
2785
- .then((r) => r.data);
2786
- /**
2787
- * Search for templates matching various criteria.
2788
- *
2789
- * ```typescript
2790
- * import {Templates} from '@verdocs/js-sdk/Templates';
2791
- *
2792
- * const {result, page, total} = await Templates.search((VerdocsEndpoint.getDefault(), { ... });
2793
- * ```
2794
- */
2795
- const searchTemplates = async (endpoint, params) => endpoint.api //
2796
- .post('/templates/search', params)
2797
- .then((r) => r.data);
2798
- /**
2799
- * List templates.
2800
- *
2801
- * ```typescript
2802
- * import {Templates} from '@verdocs/js-sdk/Templates';
2803
- *
2804
- * const {totals, templates} = await Templates.listTemplates((VerdocsEndpoint.getDefault(), { q: 'test', sort: 'created_at' }); * ```
2805
- */
2806
- const listTemplates = async (endpoint, params = {}) => endpoint.api //
2807
- .post('/templates/list', params)
2743
+ .delete(`/v2/templates/${templateId}`)
2808
2744
  .then((r) => r.data);
2809
2745
 
2810
2746
  /**
@@ -3052,7 +2988,6 @@ exports.isValidEmail = isValidEmail;
3052
2988
  exports.isValidPhone = isValidPhone;
3053
2989
  exports.isValidRoleName = isValidRoleName;
3054
2990
  exports.isValidTag = isValidTag;
3055
- exports.listTemplates = listTemplates;
3056
2991
  exports.nameToRGBA = nameToRGBA;
3057
2992
  exports.recipientCanAct = recipientCanAct;
3058
2993
  exports.recipientHasAction = recipientHasAction;
@@ -3063,14 +2998,12 @@ exports.resendOrganizationInvitation = resendOrganizationInvitation;
3063
2998
  exports.resendVerification = resendVerification;
3064
2999
  exports.resetPassword = resetPassword;
3065
3000
  exports.rotateApiKey = rotateApiKey;
3066
- exports.searchTemplates = searchTemplates;
3067
3001
  exports.sendDelegate = sendDelegate;
3068
3002
  exports.setWebhooks = setWebhooks;
3069
3003
  exports.submitKbaChallengeResponse = submitKbaChallengeResponse;
3070
3004
  exports.submitKbaIdentity = submitKbaIdentity;
3071
3005
  exports.submitKbaPin = submitKbaPin;
3072
3006
  exports.switchProfile = switchProfile;
3073
- exports.timePeriod = timePeriod;
3074
3007
  exports.toggleStar = toggleStar;
3075
3008
  exports.updateApiKey = updateApiKey;
3076
3009
  exports.updateEnvelopeField = updateEnvelopeField;