groupdocs-parser-cloud 25.9.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 (48) hide show
  1. package/lib/{model.d.ts → src/model.d.ts} +37 -0
  2. package/lib/{model.js → src/model.js} +38 -2
  3. package/lib/{package_version.js → src/package_version.js} +1 -1
  4. package/lib/{parser_api.d.ts → src/parser_api.d.ts} +5 -0
  5. package/lib/{parser_api.js → src/parser_api.js} +27 -0
  6. package/lib/test/api/test_auth_api.d.ts +1 -0
  7. package/lib/test/api/test_auth_api.js +45 -0
  8. package/lib/test/api/test_barcode_api.d.ts +1 -0
  9. package/lib/test/api/test_barcode_api.js +64 -0
  10. package/lib/test/api/test_file_api.d.ts +1 -0
  11. package/lib/test/api/test_file_api.js +95 -0
  12. package/lib/test/api/test_folder_api.d.ts +1 -0
  13. package/lib/test/api/test_folder_api.js +84 -0
  14. package/lib/test/api/test_formats_api.d.ts +1 -0
  15. package/lib/test/api/test_formats_api.js +60 -0
  16. package/lib/test/api/test_parser_container_api.d.ts +1 -0
  17. package/lib/test/api/test_parser_container_api.js +134 -0
  18. package/lib/test/api/test_parser_image_api.d.ts +1 -0
  19. package/lib/test/api/test_parser_image_api.js +179 -0
  20. package/lib/test/api/test_parser_info_api.d.ts +1 -0
  21. package/lib/test/api/test_parser_info_api.js +112 -0
  22. package/lib/test/api/test_parser_parse_api.d.ts +1 -0
  23. package/lib/test/api/test_parser_parse_api.js +184 -0
  24. package/lib/test/api/test_parser_template_api.d.ts +1 -0
  25. package/lib/test/api/test_parser_template_api.js +168 -0
  26. package/lib/test/api/test_parser_text_api.d.ts +1 -0
  27. package/lib/test/api/test_parser_text_api.js +180 -0
  28. package/lib/test/api/test_storage_api.d.ts +1 -0
  29. package/lib/test/api/test_storage_api.js +76 -0
  30. package/lib/test/test_context.d.ts +30 -0
  31. package/lib/test/test_context.js +156 -0
  32. package/lib/test/test_coverage.d.ts +1 -0
  33. package/lib/test/test_coverage.js +77 -0
  34. package/lib/test/test_file.d.ts +50 -0
  35. package/lib/test/test_file.js +92 -0
  36. package/lib/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +3 -3
  38. /package/lib/{api_client.d.ts → src/api_client.d.ts} +0 -0
  39. /package/lib/{api_client.js → src/api_client.js} +0 -0
  40. /package/lib/{api_error.d.ts → src/api_error.d.ts} +0 -0
  41. /package/lib/{api_error.js → src/api_error.js} +0 -0
  42. /package/lib/{auth.d.ts → src/auth.d.ts} +0 -0
  43. /package/lib/{auth.js → src/auth.js} +0 -0
  44. /package/lib/{configuration.d.ts → src/configuration.d.ts} +0 -0
  45. /package/lib/{configuration.js → src/configuration.js} +0 -0
  46. /package/lib/{package_version.d.ts → src/package_version.d.ts} +0 -0
  47. /package/lib/{serializer.d.ts → src/serializer.d.ts} +0 -0
  48. /package/lib/{serializer.js → src/serializer.js} +0 -0
@@ -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;
@@ -0,0 +1,156 @@
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
+ exports.getParseApi = getParseApi;
36
+ exports.getInfoApi = getInfoApi;
37
+ exports.getTemplateApi = getTemplateApi;
38
+ exports.getStorageApi = getStorageApi;
39
+ exports.getFileApi = getFileApi;
40
+ exports.getFolderApi = getFolderApi;
41
+ exports.uploadTestFiles = uploadTestFiles;
42
+ exports.cleanupTempFiles = cleanupTempFiles;
43
+ exports.getTestFileBuffer = getTestFileBuffer;
44
+ exports.serializeIntoBuffer = serializeIntoBuffer;
45
+ const fs = require("fs");
46
+ const configuration_1 = require("../src/configuration");
47
+ const serializer_1 = require("../src/serializer");
48
+ const parser_api_1 = require("../src/parser_api");
49
+ const parser_api_2 = require("../src/parser_api");
50
+ const parser_api_3 = require("../src/parser_api");
51
+ const parser_api_4 = require("../src/parser_api");
52
+ const test_file_1 = require("./test_file");
53
+ let parseApi;
54
+ let infoApi;
55
+ let templateApi;
56
+ let storageApi;
57
+ let fileApi;
58
+ let folderApi;
59
+ var uploaded = false;
60
+ let config;
61
+ /**
62
+ * Initializes ParserApi
63
+ */
64
+ function getParseApi() {
65
+ if (!parseApi) {
66
+ parseApi = parser_api_1.ParseApi.fromConfig(getConfig());
67
+ }
68
+ return parseApi;
69
+ }
70
+ function getInfoApi() {
71
+ if (!infoApi) {
72
+ infoApi = parser_api_1.InfoApi.fromConfig(getConfig());
73
+ }
74
+ return infoApi;
75
+ }
76
+ function getTemplateApi() {
77
+ if (!templateApi) {
78
+ templateApi = parser_api_1.TemplateApi.fromConfig(getConfig());
79
+ }
80
+ return templateApi;
81
+ }
82
+ function getStorageApi() {
83
+ if (!storageApi) {
84
+ storageApi = parser_api_2.StorageApi.fromConfig(getConfig());
85
+ }
86
+ return storageApi;
87
+ }
88
+ function getFileApi() {
89
+ if (!fileApi) {
90
+ fileApi = parser_api_3.FileApi.fromConfig(getConfig());
91
+ }
92
+ return fileApi;
93
+ }
94
+ function getFolderApi() {
95
+ if (!folderApi) {
96
+ folderApi = parser_api_4.FolderApi.fromConfig(getConfig());
97
+ }
98
+ return folderApi;
99
+ }
100
+ /**
101
+ * Uploads test files
102
+ */
103
+ function uploadTestFiles() {
104
+ if (uploaded)
105
+ return;
106
+ getStorageApi();
107
+ const testFiles = test_file_1.TestFile.GetTestFiles();
108
+ testFiles.forEach(function (file) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const response = yield storageApi.objectExists(new parser_api_1.ObjectExistsRequest(file.GetPath()));
111
+ if (!response.exists) {
112
+ console.log("Uploading: " + file.GetPath());
113
+ let filebuf = getTestFileBuffer(file);
114
+ yield fileApi.uploadFile(new parser_api_1.UploadFileRequest(file.GetPath(), filebuf));
115
+ }
116
+ });
117
+ });
118
+ uploaded = true;
119
+ }
120
+ function getConfig() {
121
+ if (!config) {
122
+ const settings = require("./test_settings.json");
123
+ config = new configuration_1.Configuration(settings.AppSid, settings.AppKey);
124
+ config.apiBaseUrl = settings.ApiBaseUrl;
125
+ }
126
+ return config;
127
+ }
128
+ /**
129
+ * Cleanups temp files
130
+ */
131
+ function cleanupTempFiles() {
132
+ const api = getFolderApi();
133
+ const tempDirs = ["parser"];
134
+ return Promise.all(tempDirs.map((dir) => {
135
+ return deleteTempDir(api, dir);
136
+ }));
137
+ }
138
+ /**
139
+ * Retrieves test file
140
+ */
141
+ function getTestFileBuffer(file) {
142
+ const testFilesDir = __dirname + "/test_files";
143
+ const testFilePath = testFilesDir + "/" + file.GetPath();
144
+ return fs.readFileSync(testFilePath);
145
+ }
146
+ /**
147
+ * Retrieves test file
148
+ */
149
+ function serializeIntoBuffer(obj) {
150
+ const serialized = serializer_1.Serializer.serialize(obj, obj.constructor.name);
151
+ const json = JSON.stringify(serialized, undefined, 2);
152
+ return new Buffer(json, "utf-8");
153
+ }
154
+ const deleteTempDir = (api, dir) => {
155
+ return api.deleteFolder(new parser_api_4.DeleteFolderRequest(dir, undefined, true));
156
+ };
@@ -0,0 +1 @@
1
+ import "mocha";