@veryfi/veryfi-sdk 1.3.1 → 1.3.2

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/lib/main.js CHANGED
@@ -67,7 +67,7 @@ Client.prototype._check_w2_version = function () {
67
67
  */
68
68
  Client.prototype._get_headers = function (has_files = false) {
69
69
  let final_headers = {
70
- "User-Agent": "Node.js Veryfi-Nodejs/1.3.1",
70
+ "User-Agent": "Node.js Veryfi-Nodejs/1.3.2",
71
71
  "Accept": "application/json",
72
72
  "Content-Type": "application/json",
73
73
  "Client-Id": this.client_id,
@@ -174,7 +174,13 @@ Client.prototype._request = async function (http_verb, endpoint_name, request_ar
174
174
  * @memberof Client
175
175
  * @returns {JSON} JSON object of previously processed documents
176
176
  */
177
- Client.prototype.get_documents = async function () {
177
+ Client.prototype.get_documents = async function (
178
+ page = 1,
179
+ page_size = 50,
180
+ bounding_boxes = false,
181
+ confidence_details = false,
182
+ {...kwargs} = {}
183
+ ) {
178
184
  let endpoint_name = "/documents/";
179
185
  let request_arguments = {};
180
186
  let documents = await this._request("GET", endpoint_name, request_arguments);
@@ -563,6 +569,214 @@ Client.prototype.add_tags = async function (document_id, tags) {
563
569
  return response['data'];
564
570
  }
565
571
 
572
+ /**
573
+ * Process any document and extract all the fields from it
574
+ * @example
575
+ * veryfi_client.process_any_document('file/path','blue_print')
576
+ *
577
+ * @memberof Client
578
+ * @param {String} file_path Path on disk to a file to submit for data extraction
579
+ * @param {String} template_name name of the extraction templates.
580
+ * @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
581
+ * @param {Object} kwargs Additional request parameters
582
+ * @returns {JSON} Data extracted from the document
583
+ */
584
+ Client.prototype.process_any_document = async function (
585
+ file_path,
586
+ template_name,
587
+ max_pages_to_process = 20,
588
+ {...kwargs} = {}
589
+ ) {
590
+
591
+ let endpoint_name = "/any-documents/";
592
+ let file_name = path.basename(file_path);
593
+ const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
594
+ const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
595
+ let request_arguments = {
596
+ "file_name": file_name,
597
+ "file_data": base64_encoded_string,
598
+ "template_name": template_name,
599
+ "max_pages_to_process": max_pages_to_process,
600
+ };
601
+ request_arguments = Object.assign(request_arguments, kwargs);
602
+ let document = await this._request("POST", endpoint_name, request_arguments);
603
+ return document['data'];
604
+ }
605
+
606
+ /**
607
+ * Process any document and extract all the fields from it
608
+ * @example
609
+ * veryfi_client.process_any_document_url('file_url','blue_print')
610
+ *
611
+ * @memberof Client
612
+ * @param {String} file_url url file to submit for data extraction
613
+ * @param {String} template_name name of the extraction templates.
614
+ * @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
615
+ * @param {Object} kwargs Additional request parameters
616
+ * @returns {JSON} Data extracted from the document
617
+ */
618
+ Client.prototype.process_any_document_url = async function (
619
+ file_url,
620
+ template_name,
621
+ max_pages_to_process = 20,
622
+ {...kwargs} = {}
623
+ ) {
624
+
625
+ let endpoint_name = "/any-documents/";
626
+ let request_arguments = {
627
+ "file_url": file_url,
628
+ "template_name": template_name,
629
+ "max_pages_to_process": max_pages_to_process,
630
+ };
631
+ request_arguments = Object.assign(request_arguments, kwargs);
632
+ let document = await this._request("POST", endpoint_name, request_arguments);
633
+ return document['data'];
634
+ }
635
+
636
+ /**
637
+ * Get all any documents
638
+ * @memberof Client
639
+ * @param {number} page The page number. The response is capped to maximum of 50 results per page.
640
+ * @param {number} page_size The number of Documents per page.
641
+ * @returns {JSON} Object of previously processed any documents
642
+ */
643
+ Client.prototype.get_any_documents = async function (
644
+ page = 1,
645
+ page_size = 50) {
646
+ let endpoint_name = "/any-documents/";
647
+ let request_arguments = {"page": page, "page_size": page_size};
648
+ let documents = await this._request("GET", endpoint_name, request_arguments);
649
+ if ("data" in documents) {
650
+ documents = documents["data"];
651
+ }
652
+ return documents;
653
+ }
654
+
655
+ /**
656
+ * Get a specific any document
657
+ * @memberof Client
658
+ * @param {number} document_id The unique identifier of the document.
659
+ * @returns {JSON} Object of a previously processed blueprinted document.
660
+ */
661
+ Client.prototype.get_any_document = async function (document_id) {
662
+ let endpoint_name = `/any-documents/${document_id}/`;
663
+ let request_arguments = {};
664
+ let document = await this._request("GET", endpoint_name, request_arguments);
665
+ return document['data'];
666
+ }
667
+
668
+ /**
669
+ * Get a specific bank statement
670
+ * @memberof Client
671
+ * @param {number} document_id The unique identifier of the document.
672
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
673
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
674
+ * @returns {JSON} Object of a previously processed blueprinted document.
675
+ */
676
+ Client.prototype.get_bank_statement = async function (
677
+ document_id,
678
+ bounding_boxes = false,
679
+ confidence_details = false
680
+ ) {
681
+ let endpoint_name = `/bank-statements/${document_id}/`;
682
+ let request_arguments = {
683
+ "bounding_boxes": bounding_boxes,
684
+ "confidence_details": confidence_details
685
+ };
686
+ let document = await this._request("GET", endpoint_name, request_arguments);
687
+ return document['data'];
688
+ }
689
+
690
+ /**
691
+ * Get all bank statements
692
+ * @memberof Client
693
+ * @param {number} page The page number. The response is capped to maximum of 50 results per page.
694
+ * @param {number} page_size The number of Documents per page.
695
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
696
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
697
+ * @returns {JSON} Object of previously processed any documents
698
+ */
699
+ Client.prototype.get_bank_statements = async function (
700
+ page = 1,
701
+ page_size = 50,
702
+ bounding_boxes = false,
703
+ confidence_details = false
704
+ ) {
705
+ let endpoint_name = `/bank-statements/`;
706
+ let request_arguments = {
707
+ "page": page,
708
+ "page_size": page_size,
709
+ "bounding_boxes": bounding_boxes,
710
+ "confidence_details": confidence_details
711
+ };
712
+ let document = await this._request("GET", endpoint_name, request_arguments);
713
+ return document['data'];
714
+ }
715
+
716
+ /**
717
+ * Process bank statement and extract all the fields from it
718
+ * @example
719
+ * veryfi_client.process_bank_statement('file_path')
720
+ *
721
+ * @memberof Client
722
+ * @param {String} file_path Path on disk to a file to submit for data extraction
723
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
724
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
725
+ * @param {Object} kwargs Additional request parameters
726
+ * @returns {JSON} Data extracted from the document
727
+ */
728
+ Client.prototype.process_bank_statement = async function (
729
+ file_path,
730
+ bounding_boxes = false,
731
+ confidence_details = false,
732
+ {...kwargs} = {}
733
+ ) {
734
+
735
+ let endpoint_name = "/bank-statements/";
736
+ let file_name = path.basename(file_path);
737
+ const image_file = fs.readFileSync(file_path, {encoding: 'base64'});
738
+ const base64_encoded_string = Buffer.from(image_file).toString('utf-8');
739
+ let request_arguments = {
740
+ "file_name": file_name,
741
+ "file_data": base64_encoded_string,
742
+ "bounding_boxes": bounding_boxes,
743
+ "confidence_details": confidence_details,
744
+ };
745
+ request_arguments = Object.assign(request_arguments, kwargs);
746
+ let document = await this._request("POST", endpoint_name, request_arguments);
747
+ return document['data'];
748
+ }
749
+
750
+ /**
751
+ * Process bank statement and extract all the fields from it
752
+ * @example
753
+ * veryfi_client.process_bank_statement_url('file_url')
754
+ *
755
+ * @memberof Client
756
+ * @param {String} file_url url file to submit for data extraction
757
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
758
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
759
+ * @param {Object} kwargs Additional request parameters
760
+ * @returns {JSON} Data extracted from the document
761
+ */
762
+ Client.prototype.process_bank_statement_url = async function (
763
+ file_url,
764
+ bounding_boxes = false,
765
+ confidence_details = false,
766
+ {...kwargs} = {}
767
+ ) {
768
+
769
+ let endpoint_name = "/bank-statements/";
770
+ let request_arguments = {
771
+ "file_url": file_url,
772
+ "bounding_boxes": bounding_boxes,
773
+ "confidence_details": confidence_details,
774
+ };
775
+ request_arguments = Object.assign(request_arguments, kwargs);
776
+ let document = await this._request("POST", endpoint_name, request_arguments);
777
+ return document['data'];
778
+ }
779
+
566
780
 
567
781
  // Exports
568
782
 
@@ -1,4 +1,5 @@
1
1
  import fs from "fs";
2
+ import path from "path";
2
3
 
3
4
  /**
4
5
  * Additional request parameters type
@@ -15,6 +16,8 @@ export declare type BoundingElement = {
15
16
  value?: null | number | string;
16
17
  }
17
18
 
19
+ export type JsonObject = Record<string, any>;
20
+
18
21
  /**
19
22
  * Object of data extracted from the document
20
23
  */
@@ -114,7 +117,7 @@ declare type LineItem = {
114
117
  sku?: null | string | BoundingElement;
115
118
  start_date?: null | string;
116
119
  tags?: null | null[];
117
- tax?: null | number| BoundingElement;
120
+ tax?: null | number | BoundingElement;
118
121
  tax_rate?: null | number;
119
122
  total?: null | number | BoundingElement;
120
123
  type?: null | string;
@@ -220,7 +223,12 @@ export declare class Client {
220
223
  * @memberof Client
221
224
  * @returns {Promise<VeryfiDocument>} Object of previously processed documents
222
225
  */
223
- public get_documents(): Promise<VeryfiDocument[]>;
226
+ public get_documents(
227
+ page?: number,
228
+ page_size?: number,
229
+ bounding_boxes?: boolean,
230
+ confidence_details?: boolean
231
+ ): Promise<VeryfiDocument[]>;
224
232
 
225
233
  /**
226
234
  * Retrieve document by ID
@@ -252,7 +260,7 @@ export declare class Client {
252
260
  file_name: string,
253
261
  categories?: string[],
254
262
  delete_after_processing?: boolean,
255
- { ...kwargs }?: VeryfiExtraArgs
263
+ {...kwargs}?: VeryfiExtraArgs
256
264
  ): Promise<VeryfiDocument>;
257
265
 
258
266
  /**
@@ -277,7 +285,7 @@ export declare class Client {
277
285
  file_name: string,
278
286
  categories?: string[],
279
287
  delete_after_processing?: boolean,
280
- { ...kwargs }?: VeryfiExtraArgs
288
+ {...kwargs}?: VeryfiExtraArgs
281
289
  ): Promise<VeryfiDocument>;
282
290
 
283
291
  /**
@@ -300,7 +308,7 @@ export declare class Client {
300
308
  file_path: string,
301
309
  categories?: string[],
302
310
  delete_after_processing?: boolean,
303
- { ...kwargs }?: VeryfiExtraArgs
311
+ {...kwargs}?: VeryfiExtraArgs
304
312
  ): Promise<VeryfiDocument>;
305
313
 
306
314
  /**
@@ -324,7 +332,7 @@ export declare class Client {
324
332
  boost_mode?: number,
325
333
  external_id?: string,
326
334
  max_pages_to_process?: number,
327
- { ...kwargs }?: VeryfiExtraArgs
335
+ {...kwargs}?: VeryfiExtraArgs
328
336
  ): Promise<VeryfiDocument>;
329
337
 
330
338
  /**
@@ -349,7 +357,7 @@ export declare class Client {
349
357
  */
350
358
  public update_document(
351
359
  document_id: string,
352
- { ...kwargs }?: VeryfiExtraArgs
360
+ {...kwargs}?: VeryfiExtraArgs
353
361
  ): Promise<VeryfiDocument>;
354
362
 
355
363
  /**
@@ -387,6 +395,126 @@ export declare class Client {
387
395
  */
388
396
  public replace_tags(document_id: string, tags: string[]): Promise<Tag>;
389
397
 
398
+ /**
399
+ * Process any document and extract all the fields from it
400
+ * @example
401
+ * veryfi_client.process_any_document('file/path','template_name')
402
+ *
403
+ * @memberof Client
404
+ * @param {String} file_path Path on disk to a file to submit for data extraction
405
+ * @param {String} template_name name of the extraction templates.
406
+ * @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
407
+ * @param {Object} kwargs Additional request parameters
408
+ * @returns {JSON} Data extracted from the document
409
+ */
410
+ public process_any_document(
411
+ file_path: string,
412
+ template_name?: string,
413
+ max_pages_to_process?: number,
414
+ {...kwargs}?: VeryfiExtraArgs
415
+ ): Promise<JsonObject>;
416
+
417
+ /**
418
+ * Process any document and extract all the fields from it
419
+ * @example
420
+ * veryfi_client.process_any_document_url('file_url','template_name')
421
+ *
422
+ * @memberof Client
423
+ * @param {String} file_url url file to submit for data extraction
424
+ * @param {String} template_name name of the extraction templates.
425
+ * @param {number} max_pages_to_process The number of pages to process for the document. The limit is 50 pages per document.
426
+ * @param {Object} kwargs Additional request parameters
427
+ * @returns {JSON} Data extracted from the document
428
+ */
429
+ public process_any_document_url(
430
+ file_url: string,
431
+ template_name?: string,
432
+ max_pages_to_process?: number,
433
+ {...kwargs}?: VeryfiExtraArgs
434
+ ): Promise<JsonObject>;
435
+
436
+ /**
437
+ * Get all any documents
438
+ * @memberof Client
439
+ * @param {number} page The page number. The response is capped to maximum of 50 results per page.
440
+ * @param {number} page_size The number of Documents per page.
441
+ * @returns {Promise<JsonObject>} Object of previously processed any documents
442
+ */
443
+ public get_any_documents(page?: number, page_size?: number): Promise<JsonObject[]>;
444
+
445
+ /**
446
+ * Get a specific any document
447
+ * @memberof Client
448
+ * @param {number} document_id The unique identifier of the document.
449
+ * @returns {Promise<JsonObject>} Object of a previously processed blueprinted document.
450
+ */
451
+ public get_any_document(document_id: number): Promise<JsonObject[]>;
452
+
453
+ /**
454
+ * Get a specific bank statement
455
+ * @memberof Client
456
+ * @param {number} document_id The unique identifier of the document.
457
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
458
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
459
+ * @returns {Promise<JsonObject>} Object of a previously processed blueprinted document.
460
+ */
461
+ public get_bank_statement(document_id: number, bounding_boxes?: boolean,
462
+ confidence_details?: boolean): Promise<JsonObject[]>;
463
+
464
+ /**
465
+ * Get all bank statements
466
+ * @memberof Client
467
+ * @param {number} page The page number. The response is capped to maximum of 50 results per page.
468
+ * @param {number} page_size The number of Documents per page.
469
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
470
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
471
+ * @returns {Promise<JsonObject>} Object of previously processed any documents
472
+ */
473
+ public get_bank_statements(
474
+ page?: number,
475
+ page_size?: number,
476
+ bounding_boxes?: boolean,
477
+ confidence_details?: boolean
478
+ ): Promise<JsonObject[]>;
479
+
480
+ /**
481
+ * Process bank statement and extract all the fields from it
482
+ * @example
483
+ * veryfi_client.process_bank_statement('file/path')
484
+ *
485
+ * @memberof Client
486
+ * @param {String} file_path Path on disk to a file to submit for data extraction
487
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
488
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
489
+ * @param {Object} kwargs Additional request parameters
490
+ * @returns {JSON} Data extracted from the document
491
+ */
492
+ public process_bank_statement(
493
+ file_path: string,
494
+ bounding_boxes?: boolean,
495
+ confidence_details?: boolean,
496
+ {...kwargs}?: VeryfiExtraArgs
497
+ ): Promise<JsonObject>;
498
+
499
+ /**
500
+ * Process any document and extract all the fields from it
501
+ * @example
502
+ * veryfi_client.process_bank_statement_url('file_url')
503
+ *
504
+ * @memberof Client
505
+ * @param {String} file_url url file to submit for data extraction
506
+ * @param {boolean} bounding_boxes A field used to determine whether to return bounding_box and bounding_region for extracted fields in the Document response.
507
+ * @param {boolean} confidence_details A field used to determine whether to return the score and ocr_score fields in the Document response.
508
+ * @param {Object} kwargs Additional request parameters
509
+ * @returns {JSON} Data extracted from the document
510
+ */
511
+ public process_bank_statement_url(
512
+ file_url: string,
513
+ bounding_boxes?: boolean,
514
+ confidence_details?: boolean,
515
+ {...kwargs}?: VeryfiExtraArgs
516
+ ): Promise<JsonObject>;
517
+
390
518
  }
391
519
 
392
520
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veryfi/veryfi-sdk",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Node.js module for communicating with the Veryfi OCR API",
5
5
  "main": "lib/main.js",
6
6
  "typings": "lib/types/main.d.ts",