groupdocs-parser-cloud 23.10.0 → 26.2.0

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.
Files changed (49) hide show
  1. package/LICENSE +1 -1
  2. package/lib/{api_client.d.ts → src/api_client.d.ts} +17 -17
  3. package/lib/{api_client.js → src/api_client.js} +135 -125
  4. package/lib/{api_error.d.ts → src/api_error.d.ts} +56 -56
  5. package/lib/{api_error.js → src/api_error.js} +81 -80
  6. package/lib/{auth.d.ts → src/auth.d.ts} +23 -22
  7. package/lib/{auth.js → src/auth.js} +96 -71
  8. package/lib/{configuration.d.ts → src/configuration.d.ts} +39 -39
  9. package/lib/{configuration.js → src/configuration.js} +56 -55
  10. package/lib/{model.d.ts → src/model.d.ts} +2248 -2206
  11. package/lib/{model.js → src/model.js} +2216 -2169
  12. package/lib/{package_version.d.ts → src/package_version.d.ts} +4 -4
  13. package/lib/{package_version.js → src/package_version.js} +30 -29
  14. package/lib/{parser_api.d.ts → src/parser_api.d.ts} +274 -270
  15. package/lib/{parser_api.js → src/parser_api.js} +930 -893
  16. package/lib/{serializer.d.ts → src/serializer.d.ts} +14 -14
  17. package/lib/{serializer.js → src/serializer.js} +171 -170
  18. package/lib/test/api/test_auth_api.d.ts +1 -0
  19. package/lib/test/api/test_auth_api.js +45 -0
  20. package/lib/test/api/test_barcode_api.d.ts +1 -0
  21. package/lib/test/api/test_barcode_api.js +64 -0
  22. package/lib/test/api/test_file_api.d.ts +1 -0
  23. package/lib/test/api/test_file_api.js +95 -0
  24. package/lib/test/api/test_folder_api.d.ts +1 -0
  25. package/lib/test/api/test_folder_api.js +84 -0
  26. package/lib/test/api/test_formats_api.d.ts +1 -0
  27. package/lib/test/api/test_formats_api.js +60 -0
  28. package/lib/test/api/test_parser_container_api.d.ts +1 -0
  29. package/lib/test/api/test_parser_container_api.js +134 -0
  30. package/lib/test/api/test_parser_image_api.d.ts +1 -0
  31. package/lib/test/api/test_parser_image_api.js +179 -0
  32. package/lib/test/api/test_parser_info_api.d.ts +1 -0
  33. package/lib/test/api/test_parser_info_api.js +112 -0
  34. package/lib/test/api/test_parser_parse_api.d.ts +1 -0
  35. package/lib/test/api/test_parser_parse_api.js +184 -0
  36. package/lib/test/api/test_parser_template_api.d.ts +1 -0
  37. package/lib/test/api/test_parser_template_api.js +168 -0
  38. package/lib/test/api/test_parser_text_api.d.ts +1 -0
  39. package/lib/test/api/test_parser_text_api.js +180 -0
  40. package/lib/test/api/test_storage_api.d.ts +1 -0
  41. package/lib/test/api/test_storage_api.js +76 -0
  42. package/lib/test/test_context.d.ts +30 -0
  43. package/lib/test/test_context.js +156 -0
  44. package/lib/test/test_coverage.d.ts +1 -0
  45. package/lib/test/test_coverage.js +77 -0
  46. package/lib/test/test_file.d.ts +50 -0
  47. package/lib/test/test_file.js +92 -0
  48. package/lib/tsconfig.tsbuildinfo +1 -0
  49. package/package.json +16 -14
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ // --------------------------------------------------------------------------------------------------------------------
3
+ // <copyright company="Aspose Pty Ltd">
4
+ // Copyright (c) Aspose Pty Ltd
5
+ // </copyright>
6
+ // <summary>
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ // SOFTWARE.
24
+ // </summary>
25
+ // --------------------------------------------------------------------------------------------------------------------
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const chai_1 = require("chai");
37
+ require("mocha");
38
+ const model_1 = require("../../src/model");
39
+ const TestContext = require("../test_context");
40
+ const test_file_1 = require("../test_file");
41
+ const model_2 = require("../../src/model");
42
+ describe("test_parser_parse_api", () => {
43
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
44
+ yield TestContext.uploadTestFiles();
45
+ }));
46
+ afterEach(function () {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ yield TestContext.cleanupTempFiles();
49
+ });
50
+ });
51
+ describe("TestParseApi", () => {
52
+ it("TestParseDocument_SavedTemplate", () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const templatePath = "templates/document-template.json";
54
+ const template = new model_1.CreateTemplateOptions();
55
+ template.template = Setup.getTemplate();
56
+ template.templatePath = templatePath;
57
+ const templateRequest = new model_1.CreateTemplateRequest(template);
58
+ var templateResult = yield TestContext.getTemplateApi().createTemplate(templateRequest);
59
+ (0, chai_1.expect)(templateResult).not.to.be.null;
60
+ const parseOptions = new model_1.ParseOptions();
61
+ parseOptions.fileInfo = test_file_1.TestFile.TemplateDocumentDocx.ToFileInfo();
62
+ parseOptions.templatePath = templatePath;
63
+ const request = new model_1.ParseRequest(parseOptions);
64
+ return TestContext.getParseApi().parse(request)
65
+ .then((result) => {
66
+ (0, chai_1.expect)(result).not.to.be.null;
67
+ (0, chai_1.expect)(result.fieldsData).not.to.be.empty;
68
+ (0, chai_1.expect)(result.count).equal(1);
69
+ });
70
+ }));
71
+ it("TestParseDocument_RawTemplate", () => __awaiter(void 0, void 0, void 0, function* () {
72
+ const parseOptions = new model_1.ParseOptions();
73
+ parseOptions.fileInfo = test_file_1.TestFile.TemplateDocumentDocx.ToFileInfo();
74
+ parseOptions.template = Setup.getTemplate();
75
+ const request = new model_1.ParseRequest(parseOptions);
76
+ return TestContext.getParseApi().parse(request)
77
+ .then((result) => {
78
+ (0, chai_1.expect)(result).not.to.be.null;
79
+ (0, chai_1.expect)(result.fieldsData).not.to.be.empty;
80
+ (0, chai_1.expect)(result.count).equal(1);
81
+ });
82
+ }));
83
+ it("TestParseDocument_FileNotFoundResult", () => {
84
+ const parseOptions = new model_1.ParseOptions();
85
+ parseOptions.fileInfo = test_file_1.TestFile.NotExist.ToFileInfo();
86
+ parseOptions.template = Setup.getTemplate();
87
+ const request = new model_1.ParseRequest(parseOptions);
88
+ try {
89
+ TestContext.getParseApi().parse(request);
90
+ }
91
+ catch (error) {
92
+ (0, chai_1.expect)(error.message).equal("Can\'t find file located at \'folder/file-not-exist.pdf\'.");
93
+ }
94
+ });
95
+ });
96
+ it("TestParseDocument_WithoutOptions", () => {
97
+ const parseOptions = new model_1.ParseOptions();
98
+ parseOptions.fileInfo = test_file_1.TestFile.JpegFile.ToFileInfo();
99
+ const request = new model_1.ParseRequest(parseOptions);
100
+ try {
101
+ TestContext.getParseApi().parse(request);
102
+ }
103
+ catch (error) {
104
+ (0, chai_1.expect)(error.message).equal("Request parameters missing or have incorrect format");
105
+ }
106
+ });
107
+ it("TestParseDocument_NotSupportedFile", () => {
108
+ const parseOptions = new model_1.ParseOptions();
109
+ parseOptions.fileInfo = test_file_1.TestFile.JpegFile.ToFileInfo();
110
+ parseOptions.templatePath = "templates/document-template.json";
111
+ parseOptions.template = Setup.getTemplate();
112
+ const request = new model_1.ParseRequest(parseOptions);
113
+ try {
114
+ TestContext.getParseApi().parse(request);
115
+ }
116
+ catch (error) {
117
+ (0, chai_1.expect)(error.message).equal("The specified file \'image/jpeg/document.jpeg\' has type which is not currently supported.");
118
+ }
119
+ });
120
+ it("TestParseDocument_IncorrectPassword", () => {
121
+ const parseOptions = new model_1.ParseOptions();
122
+ parseOptions.fileInfo = test_file_1.TestFile.PasswordProtected.ToFileInfo();
123
+ parseOptions.fileInfo.password = "123";
124
+ parseOptions.templatePath = "templates/document-template.json";
125
+ parseOptions.template = Setup.getTemplate();
126
+ const request = new model_1.ParseRequest(parseOptions);
127
+ try {
128
+ TestContext.getParseApi().parse(request);
129
+ }
130
+ catch (error) {
131
+ (0, chai_1.expect)(error.message).equal("Password provided for file \'words/docx/password-protected.docx\' is incorrect.");
132
+ }
133
+ });
134
+ });
135
+ it("TestAIParse", () => __awaiter(void 0, void 0, void 0, function* () {
136
+ const aiOptions = new model_1.AIParseOptions();
137
+ aiOptions.fileInfo = test_file_1.TestFile.Invoice.ToFileInfo();
138
+ aiOptions.template = {
139
+ InvoiceNum: "",
140
+ Date: "",
141
+ Email: ""
142
+ };
143
+ const request = new model_1.AIParseRequest(aiOptions);
144
+ const result = yield TestContext.getParseApi().aIParse(request);
145
+ (0, chai_1.expect)(result).to.not.be.null;
146
+ const invoiceNum = result["InvoiceNum"];
147
+ (0, chai_1.expect)(invoiceNum).to.not.be.undefined;
148
+ }));
149
+ class Setup {
150
+ static getTemplate() {
151
+ var options = new model_1.Template();
152
+ const field1 = new model_2.Field();
153
+ field1.fieldName = "Field1";
154
+ field1.pageIndex = 4;
155
+ field1.fieldPosition = new model_2.FieldPosition();
156
+ field1.fieldPosition.fieldPositionType = "Fixed";
157
+ field1.fieldPosition.rectangle = new model_2.Rectangle({ size: new model_1.Size({ height: 30, width: 140 }), position: new model_1.Point({ x: 0, y: 0 }) });
158
+ const field2 = new model_2.Field();
159
+ field2.fieldName = "RelatedField2";
160
+ field2.fieldPosition = new model_2.FieldPosition();
161
+ field2.fieldPosition.fieldPositionType = "Linked";
162
+ field2.fieldPosition.linkedFieldName = "Field1";
163
+ field2.fieldPosition.isBottomLinked = true;
164
+ field2.fieldPosition.isRightLinked = true;
165
+ field2.fieldPosition.searchArea = new model_1.Size({ height: 24, width: 209 });
166
+ field2.fieldPosition.autoScale = false;
167
+ const field3 = new model_2.Field();
168
+ field3.fieldName = "Regex";
169
+ field3.fieldPosition = new model_2.FieldPosition();
170
+ field3.fieldPosition.fieldPositionType = "Regex";
171
+ field3.fieldPosition.regex = "REGEX TEXT 123";
172
+ options.fields = new Array(field1, field2, field3);
173
+ let table = new model_2.Table({
174
+ tableName: "TableCells",
175
+ pageIndex: 5,
176
+ detectorParameters: new model_2.DetectorParameters({
177
+ rectangle: new model_2.Rectangle({ size: new model_1.Size({ height: 400, width: 600 }), position: new model_1.Point({ x: 0, y: 0 }) })
178
+ })
179
+ });
180
+ options.tables = new Array(table);
181
+ return options;
182
+ }
183
+ ;
184
+ }
@@ -0,0 +1 @@
1
+ import "mocha";
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ // --------------------------------------------------------------------------------------------------------------------
3
+ // <copyright company="Aspose Pty Ltd">
4
+ // Copyright (c) Aspose Pty Ltd
5
+ // </copyright>
6
+ // <summary>
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ // SOFTWARE.
24
+ // </summary>
25
+ // --------------------------------------------------------------------------------------------------------------------
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const chai_1 = require("chai");
37
+ require("mocha");
38
+ const model_1 = require("../../src/model");
39
+ const TestContext = require("../test_context");
40
+ const model_2 = require("../../src/model");
41
+ describe("test_parser_template_api", () => {
42
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
43
+ yield TestContext.uploadTestFiles();
44
+ }));
45
+ afterEach(function () {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield TestContext.cleanupTempFiles();
48
+ });
49
+ });
50
+ describe("TestTemplateApi", () => {
51
+ it("TestCreateTemplate", () => {
52
+ const templatePath = "templates/template_2.json";
53
+ const template = new model_1.CreateTemplateOptions();
54
+ template.template = Setup.getTemplate();
55
+ template.templatePath = templatePath;
56
+ const templateRequest = new model_1.CreateTemplateRequest(template);
57
+ return TestContext.getTemplateApi().createTemplate(templateRequest).then((templateResult) => {
58
+ (0, chai_1.expect)(templateResult).not.to.be.null;
59
+ (0, chai_1.expect)(templateResult.url).to.have.string("storage/file/templates/template_2.json");
60
+ });
61
+ });
62
+ it("TestUpdateTemplate", () => __awaiter(void 0, void 0, void 0, function* () {
63
+ const templatePath = "templates/template_1.json";
64
+ const template = new model_1.CreateTemplateOptions();
65
+ template.template = Setup.getTemplate();
66
+ template.templatePath = templatePath;
67
+ const templateRequest = new model_1.CreateTemplateRequest(template);
68
+ var templateResult = yield TestContext.getTemplateApi().createTemplate(templateRequest);
69
+ (0, chai_1.expect)(templateResult).not.to.be.null;
70
+ return yield TestContext.getTemplateApi().createTemplate(templateRequest).then((updateResult) => {
71
+ (0, chai_1.expect)(updateResult).not.to.be.null;
72
+ (0, chai_1.expect)(updateResult.url).to.have.string("storage/file/templates/template_1.json");
73
+ });
74
+ }));
75
+ it("TestGetTemplate", () => __awaiter(void 0, void 0, void 0, function* () {
76
+ const templatePath = "templates/template_1.json";
77
+ const template = new model_1.CreateTemplateOptions();
78
+ template.template = Setup.getTemplate();
79
+ template.templatePath = templatePath;
80
+ const templateRequest = new model_1.CreateTemplateRequest(template);
81
+ var templateResult = yield TestContext.getTemplateApi().createTemplate(templateRequest);
82
+ (0, chai_1.expect)(templateResult).not.to.be.null;
83
+ const getOptions = new model_1.TemplateOptions({
84
+ templatePath: "templates/template_1.json"
85
+ });
86
+ const getRequest = new model_2.GetTemplateRequest(getOptions);
87
+ return yield TestContext.getTemplateApi().getTemplate(getRequest).then((getResult) => {
88
+ (0, chai_1.expect)(getResult).not.to.be.null;
89
+ (0, chai_1.expect)(getResult.fields.length).equal(3);
90
+ (0, chai_1.expect)(getResult.tables.length).equal(1);
91
+ });
92
+ }));
93
+ it("TestDeleteTemplate", () => __awaiter(void 0, void 0, void 0, function* () {
94
+ const templatePath = "templates/template_1.json";
95
+ const template = new model_1.CreateTemplateOptions();
96
+ template.template = Setup.getTemplate();
97
+ template.templatePath = templatePath;
98
+ const templateRequest = new model_1.CreateTemplateRequest(template);
99
+ var templateResult = yield TestContext.getTemplateApi().createTemplate(templateRequest);
100
+ (0, chai_1.expect)(templateResult).not.to.be.null;
101
+ const deleteOptions = new model_1.TemplateOptions({
102
+ templatePath: "templates/template_1.json"
103
+ });
104
+ const deleteRequest = new model_2.GetTemplateRequest(deleteOptions);
105
+ yield TestContext.getTemplateApi().deleteTemplate(deleteRequest);
106
+ }));
107
+ it("TestTemplate_Delete_FileNotFoundResult", () => {
108
+ const deleteOptions = new model_1.TemplateOptions({
109
+ templatePath: "notExistTemplate.json"
110
+ });
111
+ const deleteRequest = new model_2.GetTemplateRequest(deleteOptions);
112
+ try {
113
+ TestContext.getTemplateApi().deleteTemplate(deleteRequest);
114
+ }
115
+ catch (error) {
116
+ (0, chai_1.expect)(error.message).equal("Can\'t find file located at \'notExistTemplate.json\'.");
117
+ }
118
+ });
119
+ it("TestTemplate_Get_FileNotFoundResult", () => {
120
+ const getOptions = new model_1.TemplateOptions({
121
+ templatePath: "notExistTemplate.json"
122
+ });
123
+ const getRequest = new model_2.GetTemplateRequest(getOptions);
124
+ try {
125
+ TestContext.getTemplateApi().getTemplate(getRequest);
126
+ }
127
+ catch (error) {
128
+ (0, chai_1.expect)(error.message).equal("Can\'t find file located at \'notExistTemplate.json\'.");
129
+ }
130
+ });
131
+ });
132
+ });
133
+ class Setup {
134
+ static getTemplate() {
135
+ var options = new model_1.Template();
136
+ const field1 = new model_2.Field();
137
+ field1.fieldName = "Field1";
138
+ field1.pageIndex = 4;
139
+ field1.fieldPosition = new model_2.FieldPosition();
140
+ field1.fieldPosition.fieldPositionType = "Fixed";
141
+ field1.fieldPosition.rectangle = new model_2.Rectangle({ size: new model_1.Size({ height: 30, width: 140 }), position: new model_1.Point({ x: 0, y: 0 }) });
142
+ const field2 = new model_2.Field();
143
+ field2.fieldName = "RelatedField2";
144
+ field2.fieldPosition = new model_2.FieldPosition();
145
+ field2.fieldPosition.fieldPositionType = "Linked";
146
+ field2.fieldPosition.linkedFieldName = "Field1";
147
+ field2.fieldPosition.isBottomLinked = true;
148
+ field2.fieldPosition.isRightLinked = true;
149
+ field2.fieldPosition.searchArea = new model_1.Size({ height: 24, width: 209 });
150
+ field2.fieldPosition.autoScale = false;
151
+ const field3 = new model_2.Field();
152
+ field3.fieldName = "Regex";
153
+ field3.fieldPosition = new model_2.FieldPosition();
154
+ field3.fieldPosition.fieldPositionType = "Regex";
155
+ field3.fieldPosition.regex = "REGEX TEXT 123";
156
+ options.fields = new Array(field1, field2, field3);
157
+ let table = new model_2.Table({
158
+ tableName: "TableCells",
159
+ pageIndex: 5,
160
+ detectorParameters: new model_2.DetectorParameters({
161
+ rectangle: new model_2.Rectangle({ size: new model_1.Size({ height: 400, width: 600 }), position: new model_1.Point({ x: 0, y: 0 }) })
162
+ })
163
+ });
164
+ options.tables = new Array(table);
165
+ return options;
166
+ }
167
+ ;
168
+ }
@@ -0,0 +1 @@
1
+ import "mocha";
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ // --------------------------------------------------------------------------------------------------------------------
3
+ // <copyright company="Aspose Pty Ltd">
4
+ // Copyright (c) Aspose Pty Ltd
5
+ // </copyright>
6
+ // <summary>
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ // SOFTWARE.
24
+ // </summary>
25
+ // --------------------------------------------------------------------------------------------------------------------
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const chai_1 = require("chai");
37
+ require("mocha");
38
+ const model_1 = require("../../src/model");
39
+ const TestContext = require("../test_context");
40
+ const test_file_1 = require("../test_file");
41
+ describe("test_parser_text_api", () => {
42
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
43
+ yield TestContext.uploadTestFiles();
44
+ }));
45
+ afterEach(function () {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield TestContext.cleanupTempFiles();
48
+ });
49
+ });
50
+ describe("TestTextApi", () => {
51
+ it("TestExtractText", () => {
52
+ const textOptions = new model_1.TextOptions();
53
+ textOptions.fileInfo = test_file_1.TestFile.OnePage.ToFileInfo();
54
+ const request = new model_1.TextRequest(textOptions);
55
+ return TestContext.getParseApi().text(request)
56
+ .then((result) => {
57
+ (0, chai_1.expect)(result.text).not.to.be.null;
58
+ (0, chai_1.expect)(result.text).to.have.string("First Page\r\r\f");
59
+ });
60
+ });
61
+ it("TestExtractText_md", () => {
62
+ const textOptions = new model_1.TextOptions();
63
+ textOptions.fileInfo = test_file_1.TestFile.Md.ToFileInfo();
64
+ const request = new model_1.TextRequest(textOptions);
65
+ return TestContext.getParseApi().text(request)
66
+ .then((result) => {
67
+ (0, chai_1.expect)(result.text).not.to.be.null;
68
+ (0, chai_1.expect)(result.text).to.have.string("# Test\r\rText for test:\r\r\tOne\r\tTwo\r\tSub1\rSub2\r\tThree\r\rBullets:\r\rA\rAA\rB\rC\f");
69
+ });
70
+ });
71
+ it("TestExtractText_WithPassword", () => {
72
+ const textOptions = new model_1.TextOptions({
73
+ fileInfo: test_file_1.TestFile.PasswordProtected.ToFileInfo(),
74
+ startPageNumber: 0,
75
+ countPagesToExtract: 1,
76
+ formattedTextOptions: new model_1.FormattedTextOptions({
77
+ mode: "PlainText"
78
+ })
79
+ });
80
+ const request = new model_1.TextRequest(textOptions);
81
+ return TestContext.getParseApi().text(request)
82
+ .then((result) => {
83
+ (0, chai_1.expect)(result.text).to.be.null;
84
+ (0, chai_1.expect)(result.pages[0].text).to.have.string("Text inside a bookmark 1\n\nPage 1 heading!\n\nSample test text - Page 1!\n\n\fText inside a bookmark 2\n\n");
85
+ });
86
+ });
87
+ it("TestExtractPages", () => {
88
+ const textOptions = new model_1.TextOptions({
89
+ fileInfo: test_file_1.TestFile.FourPages.ToFileInfo(),
90
+ startPageNumber: 0,
91
+ countPagesToExtract: 4,
92
+ formattedTextOptions: new model_1.FormattedTextOptions({
93
+ mode: "PlainText"
94
+ })
95
+ });
96
+ const request = new model_1.TextRequest(textOptions);
97
+ return TestContext.getParseApi().text(request)
98
+ .then((result) => {
99
+ (0, chai_1.expect)(result.pages).not.to.be.null;
100
+ (0, chai_1.expect)(result.pages[0].pageIndex).equal(0);
101
+ (0, chai_1.expect)(result.pages[0].text).to.have.string("Text inside bookmark 0\n\nPage 0 heading\n\nPage Text - Page 0\n\n\fText inside bookmark 1\n\n");
102
+ (0, chai_1.expect)(result.pages[3].pageIndex).equal(3);
103
+ (0, chai_1.expect)(result.pages[3].text).to.have.string("\fText inside bookmark 3\n\nPage 3 heading\n\nPage Text - Page 3\n\n");
104
+ });
105
+ });
106
+ it("TestExtractFormatted", () => {
107
+ const textOptions = new model_1.TextOptions({
108
+ fileInfo: test_file_1.TestFile.FormattedDocument.ToFileInfo(),
109
+ formattedTextOptions: new model_1.FormattedTextOptions({
110
+ mode: "Html"
111
+ })
112
+ });
113
+ const request = new model_1.TextRequest(textOptions);
114
+ return TestContext.getParseApi().text(request)
115
+ .then((result) => {
116
+ (0, chai_1.expect)(result).not.to.be.null;
117
+ (0, chai_1.expect)(result.text).to.have.string("<b>Bold text</b>");
118
+ (0, chai_1.expect)(result.text).to.have.string("<i>Italic text</i>");
119
+ (0, chai_1.expect)(result.text).to.have.string("<h1>Heading 1</h1>");
120
+ (0, chai_1.expect)(result.text).to.have.string("<tr><td><p>table</p></td>");
121
+ (0, chai_1.expect)(result.text).to.have.string("<ol><li><i>First element</i>");
122
+ (0, chai_1.expect)(result.text).to.have.string("<a href=\"http://targetwebsite.domain\">Hyperlink </a>");
123
+ });
124
+ });
125
+ it("TestExtractFormattedPage", () => {
126
+ const textOptions = new model_1.TextOptions({
127
+ fileInfo: test_file_1.TestFile.FormattedDocument.ToFileInfo(),
128
+ formattedTextOptions: new model_1.FormattedTextOptions({
129
+ mode: "Markdown"
130
+ }),
131
+ startPageNumber: 1,
132
+ countPagesToExtract: 1
133
+ });
134
+ const request = new model_1.TextRequest(textOptions);
135
+ return TestContext.getParseApi().text(request)
136
+ .then((result) => {
137
+ (0, chai_1.expect)(result.pages).not.to.be.empty;
138
+ (0, chai_1.expect)(result.pages[0].text).to.have.string("**Second page bold text**");
139
+ (0, chai_1.expect)(result.pages[0].text).to.have.string("# Second page heading");
140
+ });
141
+ });
142
+ it("TestExtractText_FileNotFoundResult", () => {
143
+ const textOptions = new model_1.TextOptions({
144
+ fileInfo: test_file_1.TestFile.NotExist.ToFileInfo()
145
+ });
146
+ const request = new model_1.TextRequest(textOptions);
147
+ try {
148
+ TestContext.getParseApi().text(request);
149
+ }
150
+ catch (error) {
151
+ (0, chai_1.expect)(error.message).equal("Can\'t find file located at \'folder/file-not-exist.pdf\'.");
152
+ }
153
+ });
154
+ it("TestExtractText_NotSupportedFile", () => {
155
+ const textOptions = new model_1.TextOptions({
156
+ fileInfo: test_file_1.TestFile.JpegFile.ToFileInfo()
157
+ });
158
+ const request = new model_1.TextRequest(textOptions);
159
+ try {
160
+ TestContext.getParseApi().text(request);
161
+ }
162
+ catch (error) {
163
+ (0, chai_1.expect)(error.message).equal("The specified file \'image/jpeg/document.jpeg\' has type which is not currently supported.");
164
+ }
165
+ });
166
+ it("TestExtractText_IncorrectPassword", () => {
167
+ const textOptions = new model_1.TextOptions({
168
+ fileInfo: test_file_1.TestFile.PasswordProtected.ToFileInfo()
169
+ });
170
+ textOptions.fileInfo.password = "123";
171
+ const request = new model_1.TextRequest(textOptions);
172
+ try {
173
+ TestContext.getParseApi().text(request);
174
+ }
175
+ catch (error) {
176
+ (0, chai_1.expect)(error.message).equal("Password provided for file \'words/docx/password-protected.docx\' is incorrect.");
177
+ }
178
+ });
179
+ });
180
+ });
@@ -0,0 +1 @@
1
+ import "mocha";
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) Aspose Pty Ltd
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const chai_1 = require("chai");
36
+ require("mocha");
37
+ const model_1 = require("../../src/model");
38
+ const TestContext = require("../test_context");
39
+ const test_file_1 = require("../test_file");
40
+ describe("storage_api", () => {
41
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
42
+ process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = "0";
43
+ yield TestContext.uploadTestFiles();
44
+ }));
45
+ afterEach(function () {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield TestContext.cleanupTempFiles();
48
+ });
49
+ });
50
+ describe("test_storage_api", () => {
51
+ it("TestGetDiscUsage", () => __awaiter(void 0, void 0, void 0, function* () {
52
+ var request = new model_1.GetDiscUsageRequest();
53
+ var response = yield TestContext.getStorageApi().getDiscUsage(request);
54
+ (0, chai_1.expect)(response.totalSize).greaterThan(0);
55
+ (0, chai_1.expect)(response.usedSize).greaterThan(0);
56
+ }));
57
+ it("TestStorageExist", () => __awaiter(void 0, void 0, void 0, function* () {
58
+ var request = new model_1.StorageExistsRequest("First Storage");
59
+ var response = yield TestContext.getStorageApi().storageExists(request);
60
+ (0, chai_1.expect)(response.exists).equals(true);
61
+ }));
62
+ it("TestGetFileVersions", () => __awaiter(void 0, void 0, void 0, function* () {
63
+ var testFile = test_file_1.TestFile.OnePage;
64
+ var request = new model_1.GetFileVersionsRequest(testFile.GetPath());
65
+ var response = yield TestContext.getStorageApi().getFileVersions(request);
66
+ (0, chai_1.expect)(response.value.length).greaterThan(0);
67
+ }));
68
+ it("TestObjectExists", () => __awaiter(void 0, void 0, void 0, function* () {
69
+ var testFile = test_file_1.TestFile.OnePage;
70
+ var request = new model_1.ObjectExistsRequest(testFile.GetPath());
71
+ var eResponse = yield TestContext.getStorageApi().objectExists(request);
72
+ (0, chai_1.expect)(eResponse.exists).equals(true);
73
+ (0, chai_1.expect)(eResponse.isFolder).equals(false);
74
+ }));
75
+ });
76
+ });
@@ -0,0 +1,30 @@
1
+ import { ParseApi, InfoApi, TemplateApi } from "../src/parser_api";
2
+ import { StorageApi } from "../src/parser_api";
3
+ import { FileApi } from "../src/parser_api";
4
+ import { FolderApi } from "../src/parser_api";
5
+ import { TestFile } from "./test_file";
6
+ /**
7
+ * Initializes ParserApi
8
+ */
9
+ export declare function getParseApi(): ParseApi;
10
+ export declare function getInfoApi(): InfoApi;
11
+ export declare function getTemplateApi(): TemplateApi;
12
+ export declare function getStorageApi(): StorageApi;
13
+ export declare function getFileApi(): FileApi;
14
+ export declare function getFolderApi(): FolderApi;
15
+ /**
16
+ * Uploads test files
17
+ */
18
+ export declare function uploadTestFiles(): void;
19
+ /**
20
+ * Cleanups temp files
21
+ */
22
+ export declare function cleanupTempFiles(): Promise<any[]>;
23
+ /**
24
+ * Retrieves test file
25
+ */
26
+ export declare function getTestFileBuffer(file: TestFile): Buffer;
27
+ /**
28
+ * Retrieves test file
29
+ */
30
+ export declare function serializeIntoBuffer(obj: any): Buffer;