czech-data-box 0.1.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 (41) hide show
  1. package/.gitattributes +16 -0
  2. package/.nvmrc +1 -0
  3. package/.prettierignore +1 -0
  4. package/.prettierrc.yaml +6 -0
  5. package/.vscode/launch.json +15 -0
  6. package/.vscode/settings.json +5 -0
  7. package/CHANGELOG.md +17 -0
  8. package/CODE_OF_CONDUCT.md +128 -0
  9. package/CONTRIBUTING.md +84 -0
  10. package/LICENSE +21 -0
  11. package/README.md +76 -0
  12. package/eslint.config.js +26 -0
  13. package/examples/db_login_with_certificate.js +27 -0
  14. package/examples/db_search.js +27 -0
  15. package/examples/dm_operations.js +58 -0
  16. package/package.json +57 -0
  17. package/resources/certs/cacert_postsignum_vca4.pem +44 -0
  18. package/resources/wsdl/ChangePassword.wsdl +84 -0
  19. package/resources/wsdl/ChangePasswordTypes.xsd +69 -0
  20. package/resources/wsdl/ExtWs.wsdl +65 -0
  21. package/resources/wsdl/dbTypes.xsd +1688 -0
  22. package/resources/wsdl/db_access.wsdl +197 -0
  23. package/resources/wsdl/db_manipulations.wsdl +598 -0
  24. package/resources/wsdl/db_search.wsdl +362 -0
  25. package/resources/wsdl/dmBaseTypes.xsd +1497 -0
  26. package/resources/wsdl/dm_VoDZ.wsdl +212 -0
  27. package/resources/wsdl/dm_info.wsdl +412 -0
  28. package/resources/wsdl/dm_operations.wsdl +242 -0
  29. package/src/index.js +4 -0
  30. package/src/lib/ISDSBox.js +309 -0
  31. package/src/lib/ISDSSentOutFiles.js +84 -0
  32. package/src/lib/ISDSSoapClient.js +201 -0
  33. package/src/lib/config.js +64 -0
  34. package/src/models/DataBox.js +142 -0
  35. package/src/models/DataMessage.js +153 -0
  36. package/src/models/DataMessageFile.js +69 -0
  37. package/src/models/DataMessageFiles.js +23 -0
  38. package/test/ISDSBox.test.js +129 -0
  39. package/test/ISDSSentOutFiles.test.js +124 -0
  40. package/test/ISDSSoapClient.test.js +81 -0
  41. package/test/communication_test.pdf +0 -0
@@ -0,0 +1,129 @@
1
+ import { expect } from 'chai';
2
+ import sinon from 'sinon';
3
+ import ISDSBox from '../src/lib/ISDSBox.js';
4
+ import ISDSSoapClient from '../src/lib/ISDSSoapClient.js';
5
+ import DataBox from '../src/models/DataBox.js';
6
+
7
+ describe('ISDSBox', function () {
8
+ let sandbox;
9
+ let soapClientMock;
10
+ let isdsBox;
11
+
12
+ beforeEach(function () {
13
+ sandbox = sinon.createSandbox();
14
+ soapClientMock = sandbox.stub(ISDSSoapClient.prototype, 'request');
15
+ isdsBox = new ISDSBox(0, 'loginname', 'password', '', '', '');
16
+ });
17
+
18
+ afterEach(function () {
19
+ sandbox.restore();
20
+ });
21
+
22
+ it('should create a message', async function () {
23
+ const dataMessageFiles = [
24
+ {
25
+ dmFilePath: './test/communication_test.pdf',
26
+ dmMimeType: 'application/pdf',
27
+ dmFileMetaType: 'main',
28
+ dmFileDescr: 'file1.pdf',
29
+ },
30
+ ];
31
+
32
+ const params = {
33
+ dmSenderOrgUnit: null,
34
+ dmSenderOrgUnitNum: null,
35
+ dbIDRecipient: 'fdjklz2',
36
+ dmRecipientOrgUnit: null,
37
+ dmRecipientOrgUnitNum: null,
38
+ dmToHands: 'MK',
39
+ dmAnnotation: 'MK Communication test (ignore)',
40
+ dmRecipientRefNumber: null,
41
+ dmSenderRefNumber: null,
42
+ dmRecipientIdent: '',
43
+ dmSenderIdent: '',
44
+ dmLegalTitleLaw: '',
45
+ dmLegalTitleYear: '',
46
+ dmLegalTitleSect: 'f',
47
+ dmLegalTitlePar: '',
48
+ dmLegalTitlePoint: '',
49
+ dmPersonalDelivery: true,
50
+ dmAllowSubstDelivery: true,
51
+ dmOVM: false,
52
+ dmPublishOwnID: false,
53
+ };
54
+
55
+ soapClientMock.withArgs('CreateMessage', sinon.match.any).resolves({
56
+ dmID: 'messageID',
57
+ dmStatus: { dmStatusCode: '0000', dmStatusMessage: 'OK' },
58
+ });
59
+
60
+ const result = await isdsBox.createMessage(params, dataMessageFiles);
61
+ expect(result).to.have.property('dmID', 'messageID');
62
+ });
63
+
64
+ it('should find a data box based on the provided input', async function () {
65
+ const dataBox = new DataBox();
66
+ dataBox.setDbId('e26gfgu');
67
+ dataBox.setDbType('FO');
68
+ // Add other search criteria as needed
69
+
70
+ const mockResponse = {
71
+ // Mock response that matches the expected structure from the SOAP service
72
+ dbStatus: { dbStatusCode: '0000', dbStatusMessage: 'OK' },
73
+ dbResults: [{ dbID: 'e26gfgu', dbType: 'FO' }],
74
+ };
75
+
76
+ soapClientMock
77
+ .withArgs('FindDataBox', sinon.match.any)
78
+ .resolves(mockResponse);
79
+
80
+ const result = await isdsBox.findDataBox(dataBox);
81
+ expect(result).to.deep.equal(mockResponse);
82
+ });
83
+
84
+ it('should throw an error if the SOAP request fails', async function () {
85
+ const dataBox = new DataBox();
86
+ dataBox.setDbId('e26gfgu');
87
+ dataBox.setDbType('FO');
88
+ // Add other search criteria as needed
89
+
90
+ const mockError = new Error('SOAP request failed');
91
+ soapClientMock.withArgs('FindDataBox', sinon.match.any).rejects(mockError);
92
+
93
+ try {
94
+ await isdsBox.findDataBox(dataBox);
95
+ throw new Error('Expected findDataBox to throw an error');
96
+ } catch (error) {
97
+ expect(error.message).to.equal('Error: SOAP request failed');
98
+ }
99
+ });
100
+
101
+ it('should get owner info from login', async function () {
102
+ const mockResponse = {
103
+ dbStatus: { dbStatusCode: '0000', dbStatusMessage: 'OK' },
104
+ ownerInfo: { ownerId: 'owner123', ownerName: 'Owner Name' },
105
+ };
106
+
107
+ soapClientMock
108
+ .withArgs('GetOwnerInfoFromLogin', { dbDummy: '' })
109
+ .resolves(mockResponse);
110
+
111
+ const result = await isdsBox.getOwnerInfoFromLogin();
112
+ expect(result).to.deep.equal(mockResponse);
113
+ });
114
+
115
+ it('should throw an error if the SOAP request fails', async function () {
116
+ const mockError = new Error('SOAP request failed');
117
+ soapClientMock
118
+ .withArgs('GetOwnerInfoFromLogin', { dbDummy: '' })
119
+ .rejects(mockError);
120
+
121
+ try {
122
+ await isdsBox.getOwnerInfoFromLogin();
123
+ throw new Error('Expected getOwnerInfoFromLogin to throw an error');
124
+ } catch (error) {
125
+ expect(error.message).to.equal('Error: SOAP request failed');
126
+ }
127
+ });
128
+ // Add more test cases for other methods
129
+ });
@@ -0,0 +1,124 @@
1
+ import { expect } from 'chai';
2
+ import sinon from 'sinon';
3
+ import fs from 'fs';
4
+ import ISDSSentOutFiles from '../src/lib/ISDSSentOutFiles.js';
5
+ import DataMessageFile from '../src/models/DataMessageFile.js';
6
+ import path from 'path';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname } from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+
13
+ describe('ISDSSentOutFiles', function () {
14
+ let sentOutFiles;
15
+ let readFileStub;
16
+ let existsSyncStub;
17
+
18
+ beforeEach(function () {
19
+ sentOutFiles = new ISDSSentOutFiles();
20
+ readFileStub = sinon.stub(fs.promises, 'readFile');
21
+ existsSyncStub = sinon.stub(fs, 'existsSync');
22
+ });
23
+
24
+ afterEach(function () {
25
+ sinon.restore();
26
+ });
27
+
28
+ it('should add file from memory', function () {
29
+ const fileContent = Buffer.from('file content').toString('base64');
30
+ sentOutFiles.addFileFromMemory(
31
+ fileContent,
32
+ 'application/pdf',
33
+ 'main',
34
+ 'description',
35
+ );
36
+
37
+ const builtFiles = sentOutFiles.build();
38
+ expect(builtFiles.dmFile).to.have.lengthOf(1);
39
+ expect(builtFiles.dmFile[0]).to.deep.include({
40
+ attributes: {
41
+ dmMimeType: 'application/pdf',
42
+ dmFileMetaType: 'main',
43
+ dmFileDescr: 'description',
44
+ dmFileGuid: '',
45
+ dmUpFileGuid: '',
46
+ dmFormat: '',
47
+ },
48
+ dmEncodedContent: fileContent,
49
+ });
50
+ });
51
+
52
+ it('should add file from file system', async function () {
53
+ const testFilePath = path.join(__dirname, 'testfile.txt');
54
+ const fileContent = Buffer.from('file content').toString('base64');
55
+
56
+ existsSyncStub.withArgs(testFilePath).returns(true);
57
+ readFileStub
58
+ .withArgs(testFilePath, { encoding: 'base64' })
59
+ .resolves(fileContent);
60
+
61
+ const result = await sentOutFiles.addFileFromFilePath(
62
+ testFilePath,
63
+ 'application/pdf',
64
+ 'main',
65
+ 'description',
66
+ );
67
+
68
+ expect(result).to.be.true;
69
+ const builtFiles = sentOutFiles.build();
70
+ expect(builtFiles.dmFile).to.have.lengthOf(1);
71
+ expect(builtFiles.dmFile[0]).to.deep.include({
72
+ attributes: {
73
+ dmMimeType: 'application/pdf',
74
+ dmFileMetaType: 'main',
75
+ dmFileDescr: 'description',
76
+ dmFileGuid: '',
77
+ dmUpFileGuid: '',
78
+ dmFormat: '',
79
+ },
80
+ dmEncodedContent: fileContent,
81
+ });
82
+ });
83
+
84
+ it('should handle file not found error', async function () {
85
+ const testFilePath = path.join(__dirname, 'nonexistentfile.txt');
86
+
87
+ existsSyncStub.withArgs(testFilePath).returns(false);
88
+
89
+ const result = await sentOutFiles.addFileFromFilePath(
90
+ testFilePath,
91
+ 'application/pdf',
92
+ 'main',
93
+ 'description',
94
+ );
95
+
96
+ expect(result).to.be.false;
97
+ const builtFiles = sentOutFiles.build();
98
+ expect(builtFiles.dmFile).to.be.empty;
99
+ });
100
+
101
+ it('should build files correctly', function () {
102
+ const file = new DataMessageFile();
103
+ file.setDmEncodedContent('encodedContent');
104
+ file.setDmMimeType('application/pdf');
105
+ file.setDmFileMetaType('main');
106
+ file.setDmFileDescr('description');
107
+
108
+ sentOutFiles.dataMessageFiles.addFile(file);
109
+
110
+ const builtFiles = sentOutFiles.build();
111
+ expect(builtFiles.dmFile).to.have.lengthOf(1);
112
+ expect(builtFiles.dmFile[0]).to.deep.include({
113
+ attributes: {
114
+ dmMimeType: 'application/pdf',
115
+ dmFileMetaType: 'main',
116
+ dmFileDescr: 'description',
117
+ dmFileGuid: '',
118
+ dmUpFileGuid: '',
119
+ dmFormat: '',
120
+ },
121
+ dmEncodedContent: 'encodedContent',
122
+ });
123
+ });
124
+ });
@@ -0,0 +1,81 @@
1
+ import { expect } from "chai";
2
+ import sinon from "sinon";
3
+ import ISDSSoapClient from "../src/lib/ISDSSoapClient.js";
4
+ import soap from "soap";
5
+
6
+ describe("ISDSSoapClient", function () {
7
+ let soapClient;
8
+ let createClientAsyncStub;
9
+ let soapClientInstance;
10
+
11
+ beforeEach(function () {
12
+ createClientAsyncStub = sinon.stub(soap, "createClientAsync");
13
+ soapClientInstance = {
14
+ CreateMessageAsync: sinon.stub().resolves([
15
+ {
16
+ dmID: "messageID",
17
+ dmStatus: { dmStatusCode: "0000", dmStatusMessage: "OK" },
18
+ },
19
+ ]),
20
+ on: sinon.stub(),
21
+ addHttpHeader: sinon.stub(),
22
+ setEndpoint: sinon.stub(),
23
+ };
24
+ createClientAsyncStub.resolves(soapClientInstance);
25
+
26
+ soapClient = new ISDSSoapClient(
27
+ "wsdl_url",
28
+ { login: "test", password: "test", location: "test_location" },
29
+ false // Set debug to false for tests
30
+ );
31
+ });
32
+
33
+ afterEach(function () {
34
+ sinon.restore();
35
+ });
36
+
37
+ it("should initialize and make a request", async function () {
38
+ await soapClient.init();
39
+ const result = await soapClient.request("CreateMessage", {});
40
+
41
+ expect(result).to.deep.equal([
42
+ {
43
+ dmID: "messageID",
44
+ dmStatus: { dmStatusCode: "0000", dmStatusMessage: "OK" },
45
+ },
46
+ ]);
47
+ expect(createClientAsyncStub.calledOnce).to.be.true;
48
+ expect(soapClientInstance.CreateMessageAsync.calledOnceWith({})).to.be.true;
49
+ });
50
+
51
+ it("should not reinitialize the client if already initialized", async function () {
52
+ await soapClient.init();
53
+ await soapClient.request("CreateMessage", {});
54
+
55
+ expect(createClientAsyncStub.calledOnce).to.be.true;
56
+ expect(soapClientInstance.CreateMessageAsync.calledOnceWith({})).to.be.true;
57
+
58
+ await soapClient.request("CreateMessage", {});
59
+ expect(createClientAsyncStub.calledOnce).to.be.true; // Should still be called only once
60
+ expect(soapClientInstance.CreateMessageAsync.calledTwice).to.be.true;
61
+ });
62
+
63
+ it("should throw an error if SOAP client initialization fails", async function () {
64
+ createClientAsyncStub.rejects(
65
+ new Error("SOAP client initialization failed")
66
+ );
67
+
68
+ try {
69
+ await soapClient.init();
70
+ } catch (error) {
71
+ expect(error).to.be.an.instanceOf(Error);
72
+ expect(error.message).to.equal("SOAP client initialization failed");
73
+ return;
74
+ }
75
+
76
+ // If the code reaches here, the test should fail
77
+ expect.fail("Expected an error but none was thrown");
78
+ });
79
+
80
+ // Add more test cases as needed
81
+ });
Binary file