ti2-tourplan 1.0.10 → 1.0.12
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/index.js +6 -27
- package/index.test.js +5 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -3,7 +3,6 @@ const assert = require('assert');
|
|
|
3
3
|
const moment = require('moment');
|
|
4
4
|
const js2xmlparser = require('js2xmlparser');
|
|
5
5
|
const xml2js = require('xml2js');
|
|
6
|
-
const axiosRaw = require('axios');
|
|
7
6
|
|
|
8
7
|
const Normalizer = require('./normalizer');
|
|
9
8
|
|
|
@@ -19,11 +18,10 @@ const xmlOptions = {
|
|
|
19
18
|
},
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
const getHeaders = ({ length
|
|
21
|
+
const getHeaders = ({ length }) => ({
|
|
23
22
|
Accept: 'application/xml',
|
|
24
23
|
'Content-Type': 'application/xml; charset=utf-8',
|
|
25
24
|
'Content-Length': length,
|
|
26
|
-
...requestId ? { requestId } : {},
|
|
27
25
|
});
|
|
28
26
|
|
|
29
27
|
class Plugin {
|
|
@@ -31,24 +29,6 @@ class Plugin {
|
|
|
31
29
|
Object.entries(params).forEach(([attr, value]) => {
|
|
32
30
|
this[attr] = value;
|
|
33
31
|
});
|
|
34
|
-
if (this.events) {
|
|
35
|
-
axiosRaw.interceptors.request.use(request => {
|
|
36
|
-
this.events.emit(`${this.name}.axios.request`, JSON.parse(JSON.stringify(request)));
|
|
37
|
-
return request;
|
|
38
|
-
});
|
|
39
|
-
axiosRaw.interceptors.response.use(response => {
|
|
40
|
-
this.events.emit(`${this.name}.axios.response`, JSON.parse(JSON.stringify(response)));
|
|
41
|
-
return response;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const pluginObj = this;
|
|
45
|
-
this.axios = async (...args) => axiosRaw(...args).catch(err => {
|
|
46
|
-
console.log('error in ti2-tourplan', err);
|
|
47
|
-
if (pluginObj.events) {
|
|
48
|
-
pluginObj.events.emit(`${this.name}.axios.error`, { request: args[0], err });
|
|
49
|
-
}
|
|
50
|
-
throw err;
|
|
51
|
-
});
|
|
52
32
|
this.tokenTemplate = () => ({
|
|
53
33
|
endpoint: {
|
|
54
34
|
type: 'text',
|
|
@@ -71,12 +51,12 @@ class Plugin {
|
|
|
71
51
|
}
|
|
72
52
|
|
|
73
53
|
async validateToken({
|
|
54
|
+
axios,
|
|
74
55
|
token: {
|
|
75
56
|
endpoint,
|
|
76
57
|
username,
|
|
77
58
|
password,
|
|
78
59
|
},
|
|
79
|
-
requestId,
|
|
80
60
|
}) {
|
|
81
61
|
try {
|
|
82
62
|
const model = {
|
|
@@ -89,12 +69,11 @@ class Plugin {
|
|
|
89
69
|
js2xmlparser.parse('Request', model, xmlOptions),
|
|
90
70
|
);
|
|
91
71
|
data = data.replace(xmlOptions.dtd.name, `Request SYSTEM "${xmlOptions.dtd.name}"`);
|
|
92
|
-
const reply = R.path(['data'], await
|
|
72
|
+
const reply = R.path(['data'], await axios({
|
|
93
73
|
metod: 'post',
|
|
94
74
|
url: endpoint,
|
|
95
75
|
data,
|
|
96
76
|
headers: getHeaders({ length: data.length }),
|
|
97
|
-
requestId,
|
|
98
77
|
}));
|
|
99
78
|
const replyObj = await xmlParser.parseStringPromise(reply);
|
|
100
79
|
assert(R.path(['Reply', 'AuthenticationReply', 0], replyObj) === '');
|
|
@@ -105,6 +84,7 @@ class Plugin {
|
|
|
105
84
|
}
|
|
106
85
|
|
|
107
86
|
async queryAllotment({
|
|
87
|
+
axios,
|
|
108
88
|
token: {
|
|
109
89
|
endpoint = this.endpoint,
|
|
110
90
|
username = this.username,
|
|
@@ -117,7 +97,6 @@ class Plugin {
|
|
|
117
97
|
keyPath,
|
|
118
98
|
appliesTo: appliesToFilter,
|
|
119
99
|
},
|
|
120
|
-
requestId,
|
|
121
100
|
}) {
|
|
122
101
|
const verbose = R.path(['verbose'], this);
|
|
123
102
|
const cleanLog = inputString =>
|
|
@@ -150,11 +129,11 @@ class Plugin {
|
|
|
150
129
|
);
|
|
151
130
|
data = data.replace(xmlOptions.dtd.name, `Request SYSTEM "${xmlOptions.dtd.name}"`);
|
|
152
131
|
if (verbose) console.log('request', cleanLog(data));
|
|
153
|
-
const reply = R.path(['data'], await
|
|
132
|
+
const reply = R.path(['data'], await axios({
|
|
154
133
|
metod: 'post',
|
|
155
134
|
url: endpoint,
|
|
156
135
|
data,
|
|
157
|
-
headers: getHeaders({ length: data.length
|
|
136
|
+
headers: getHeaders({ length: data.length }),
|
|
158
137
|
}));
|
|
159
138
|
if (verbose) console.log('reply', cleanLog(reply));
|
|
160
139
|
const returnObj = await xmlParser.parseStringPromise(reply);
|
package/index.test.js
CHANGED
|
@@ -44,6 +44,7 @@ describe('search tests', () => {
|
|
|
44
44
|
it('valid token', async () => {
|
|
45
45
|
axios.mockImplementation(getFixture);
|
|
46
46
|
const retVal = await app.validateToken({
|
|
47
|
+
axios,
|
|
47
48
|
token,
|
|
48
49
|
});
|
|
49
50
|
expect(retVal).toBeTruthy();
|
|
@@ -51,6 +52,7 @@ describe('search tests', () => {
|
|
|
51
52
|
it('invalid token', async () => {
|
|
52
53
|
axios.mockImplementation(getFixture);
|
|
53
54
|
const retVal = await app.validateToken({
|
|
55
|
+
axios,
|
|
54
56
|
token: { ...token, username: 'somerandom' },
|
|
55
57
|
});
|
|
56
58
|
expect(retVal).toBeFalsy();
|
|
@@ -85,6 +87,7 @@ describe('search tests', () => {
|
|
|
85
87
|
it('read allotment empty', async () => {
|
|
86
88
|
const request = axios.mockImplementation(getFixture);
|
|
87
89
|
const retVal = await app.queryAllotment({
|
|
90
|
+
axios,
|
|
88
91
|
token,
|
|
89
92
|
payload: {
|
|
90
93
|
dateFormat,
|
|
@@ -107,6 +110,7 @@ describe('search tests', () => {
|
|
|
107
110
|
it('read allotment not empty', async () => {
|
|
108
111
|
const request = axios.mockImplementation(getFixture);
|
|
109
112
|
const retVal = await app.queryAllotment({
|
|
113
|
+
axios,
|
|
110
114
|
token,
|
|
111
115
|
payload: {
|
|
112
116
|
dateFormat,
|
|
@@ -142,6 +146,7 @@ describe('search tests', () => {
|
|
|
142
146
|
it('read allotment that applies to more products', async () => {
|
|
143
147
|
const request = axios.mockImplementation(getFixture);
|
|
144
148
|
const retVal = await app.queryAllotment({
|
|
149
|
+
axios,
|
|
145
150
|
token,
|
|
146
151
|
payload: {
|
|
147
152
|
dateFormat,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ti2-tourplan",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Tourplan's TI2 Plugin",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"testTimeout": 10000
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"axios": "^0.24.0",
|
|
31
30
|
"bluebird": "^3.7.2",
|
|
32
31
|
"js2xmlparser": "^4.0.2",
|
|
33
32
|
"jsonwebtoken": "^8.5.1",
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
"xml2js": "^0.4.23"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
39
|
+
"axios": "^0.24.0",
|
|
40
40
|
"eslint": "^8.4.1",
|
|
41
41
|
"eslint-config-airbnb": "^19.0.2",
|
|
42
42
|
"eslint-plugin-import": "^2.25.4",
|