ti2-tourplan 1.0.11 → 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 -38
- 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,47 +18,17 @@ 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
|
-
const axiosSafeRequest = R.pick(['headers', 'method', 'url', 'data']);
|
|
30
|
-
const axiosSafeResponse = response => {
|
|
31
|
-
const retVal = R.pick(['data', 'status', 'statusText', 'headers', 'request'], response);
|
|
32
|
-
retVal.request = axiosSafeRequest(retVal.request);
|
|
33
|
-
return retVal;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
27
|
class Plugin {
|
|
37
28
|
constructor(params = {}) { // we get the env variables from here
|
|
38
29
|
Object.entries(params).forEach(([attr, value]) => {
|
|
39
30
|
this[attr] = value;
|
|
40
31
|
});
|
|
41
|
-
if (this.events) {
|
|
42
|
-
axiosRaw.interceptors.request.use(request => {
|
|
43
|
-
this.events.emit(`${this.name}.axios.request`, axiosSafeRequest(request));
|
|
44
|
-
return request;
|
|
45
|
-
});
|
|
46
|
-
axiosRaw.interceptors.response.use(response => {
|
|
47
|
-
this.events.emit(`${this.name}.axios.response`, axiosSafeResponse(response));
|
|
48
|
-
return response;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
const pluginObj = this;
|
|
52
|
-
this.axios = async (...args) => axiosRaw(...args).catch(err => {
|
|
53
|
-
const errMsg = R.omit(['config'], err.toJSON());
|
|
54
|
-
console.log(`error in ${this.name}`, args[0], errMsg);
|
|
55
|
-
if (pluginObj.events) {
|
|
56
|
-
pluginObj.events.emit(`${this.name}.axios.error`, {
|
|
57
|
-
request: args[0],
|
|
58
|
-
err: errMsg,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
throw err;
|
|
62
|
-
});
|
|
63
32
|
this.tokenTemplate = () => ({
|
|
64
33
|
endpoint: {
|
|
65
34
|
type: 'text',
|
|
@@ -82,12 +51,12 @@ class Plugin {
|
|
|
82
51
|
}
|
|
83
52
|
|
|
84
53
|
async validateToken({
|
|
54
|
+
axios,
|
|
85
55
|
token: {
|
|
86
56
|
endpoint,
|
|
87
57
|
username,
|
|
88
58
|
password,
|
|
89
59
|
},
|
|
90
|
-
requestId,
|
|
91
60
|
}) {
|
|
92
61
|
try {
|
|
93
62
|
const model = {
|
|
@@ -100,12 +69,11 @@ class Plugin {
|
|
|
100
69
|
js2xmlparser.parse('Request', model, xmlOptions),
|
|
101
70
|
);
|
|
102
71
|
data = data.replace(xmlOptions.dtd.name, `Request SYSTEM "${xmlOptions.dtd.name}"`);
|
|
103
|
-
const reply = R.path(['data'], await
|
|
72
|
+
const reply = R.path(['data'], await axios({
|
|
104
73
|
metod: 'post',
|
|
105
74
|
url: endpoint,
|
|
106
75
|
data,
|
|
107
76
|
headers: getHeaders({ length: data.length }),
|
|
108
|
-
requestId,
|
|
109
77
|
}));
|
|
110
78
|
const replyObj = await xmlParser.parseStringPromise(reply);
|
|
111
79
|
assert(R.path(['Reply', 'AuthenticationReply', 0], replyObj) === '');
|
|
@@ -116,6 +84,7 @@ class Plugin {
|
|
|
116
84
|
}
|
|
117
85
|
|
|
118
86
|
async queryAllotment({
|
|
87
|
+
axios,
|
|
119
88
|
token: {
|
|
120
89
|
endpoint = this.endpoint,
|
|
121
90
|
username = this.username,
|
|
@@ -128,7 +97,6 @@ class Plugin {
|
|
|
128
97
|
keyPath,
|
|
129
98
|
appliesTo: appliesToFilter,
|
|
130
99
|
},
|
|
131
|
-
requestId,
|
|
132
100
|
}) {
|
|
133
101
|
const verbose = R.path(['verbose'], this);
|
|
134
102
|
const cleanLog = inputString =>
|
|
@@ -161,11 +129,11 @@ class Plugin {
|
|
|
161
129
|
);
|
|
162
130
|
data = data.replace(xmlOptions.dtd.name, `Request SYSTEM "${xmlOptions.dtd.name}"`);
|
|
163
131
|
if (verbose) console.log('request', cleanLog(data));
|
|
164
|
-
const reply = R.path(['data'], await
|
|
132
|
+
const reply = R.path(['data'], await axios({
|
|
165
133
|
metod: 'post',
|
|
166
134
|
url: endpoint,
|
|
167
135
|
data,
|
|
168
|
-
headers: getHeaders({ length: data.length
|
|
136
|
+
headers: getHeaders({ length: data.length }),
|
|
169
137
|
}));
|
|
170
138
|
if (verbose) console.log('reply', cleanLog(reply));
|
|
171
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",
|