vtb-appit 0.0.21 → 0.0.24

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.
@@ -1,12 +1,15 @@
1
1
  const https = require('https');
2
2
  const fs = require("fs");
3
3
  const pth = require("path");
4
+ const { resolve } = require('path');
4
5
 
5
6
  class AppitBaseTransformer {
6
7
  constructor()
7
8
  {
8
9
  const data = JSON.parse(fs.readFileSync(pth.join(__dirname, '../../assets/travelplan.json'), {encoding: 'utf8' }));
9
10
  this.travelplan = JSON.parse(JSON.stringify(data));
11
+
12
+ this.token = JSON.parse(fs.readFileSync(pth.join(__dirname, '../../assets/token.json'), {encoding: 'utf8' }));
10
13
  }
11
14
 
12
15
  labels()
@@ -105,6 +108,75 @@ class AppitBaseTransformer {
105
108
  return result;
106
109
  }
107
110
 
111
+ async tsData()
112
+ {
113
+ return new Promise(resolve => {
114
+ const jwt = await this.fetchTSJWT();
115
+ const tokenDecodablePart = jwt.split('.')[1];
116
+ const decoded = JSON.parse(Buffer.from(tokenDecodablePart, 'base64').toString());
117
+ const endPath = '/dynamicdata/';
118
+
119
+ let req = https.request({
120
+ headers: {
121
+ 'Authorization': jwt
122
+ },
123
+ hostname: decoded['https://visualtourbuilder.com/app_metadata'].baseUrl.replace('https://', '').replace(/.app\/.*/, '.app'),
124
+ path: decoded['https://visualtourbuilder.com/app_metadata'].baseUrl.replace(/.*?.app/, '') + endPath,
125
+ method: 'GET'
126
+ }, (r) => {
127
+ let data = '';
128
+
129
+ r.on('data', (d) => { data += d; });
130
+
131
+ r.on('end', () => {
132
+ console.log('RES', res);
133
+ let res = JSON.parse(data);
134
+ resolve(res);
135
+ });
136
+ });
137
+ req.end();
138
+ })
139
+ }
140
+
141
+ fetchTSJWT()
142
+ {
143
+ return new Promise(resolve => {
144
+ const data = JSON.stringify({
145
+ query: `{
146
+ tsJWT {
147
+ jwt
148
+ }
149
+ }`,
150
+ });
151
+
152
+ const options = {
153
+ hostname: 'vtb-global-vtb-gateway-z7stqwbrxa-ew.a.run.app',
154
+ path: '/graphql',
155
+ port: 443,
156
+ method: 'POST',
157
+ headers: {
158
+ 'Content-Type': 'application/json',
159
+ 'Content-Length': data.length,
160
+ 'Authorization': `Bearer ${this.token}`,
161
+ 'User-Agent': 'Node',
162
+ },
163
+ };
164
+
165
+ const req = https.request(options, (res) => {
166
+ let data = '';
167
+
168
+ res.on('data', (d) => {
169
+ data += d;
170
+ });
171
+
172
+ res.on('end', () => {
173
+ console.log('JWT', JSON.parse(data).data.tsJWT.jwt);
174
+ resolve(JSON.parse(data).data.tsJWT.jwt);
175
+ });
176
+ });
177
+ })
178
+ }
179
+
108
180
  async mediaToBase64(media)
109
181
  {
110
182
  let promises = [];
package/appit.js CHANGED
@@ -4,9 +4,10 @@ const https = require('https');
4
4
 
5
5
  class Appit {
6
6
 
7
- constructor(transformer)
7
+ constructor(transformer, options)
8
8
  {
9
9
  this.transformer = transformer;
10
+ this.options = options;
10
11
 
11
12
  this.historyPath = pth.join(__dirname, '../../assets/history.json');
12
13
 
@@ -48,6 +49,10 @@ class Appit {
48
49
  {
49
50
  if(!await this.login()) return false;
50
51
 
52
+ if(this.options && this.options.tsData) {
53
+ this.transformer.tsData = this.transformer.tsData();
54
+ }
55
+
51
56
  await this.excursion();
52
57
  await this.labels();
53
58
  await this.places();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.0.21",
3
+ "version": "0.0.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {