vtb-appit 0.1.26 → 0.1.27
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/appit-base-transformer.js +6 -59
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ class AppitBaseTransformer {
|
|
|
12
12
|
this.vtbMessages = [];
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
|
-
this.token = fs.readFileSync(pth.join(__dirname, '../../assets/token.jwt'), {encoding: 'utf8' });
|
|
15
|
+
this.token = fs.readFileSync(pth.join(__dirname, '../../assets/token.jwt'), {encoding: 'utf8' }).trim();
|
|
16
16
|
} catch(e) {
|
|
17
17
|
this.token = false;
|
|
18
18
|
}
|
|
@@ -186,11 +186,10 @@ class AppitBaseTransformer {
|
|
|
186
186
|
|
|
187
187
|
async tsGetDocuments()
|
|
188
188
|
{
|
|
189
|
-
const
|
|
190
|
-
const tokenDecodablePart = jwt.split('.')[1];
|
|
189
|
+
const tokenDecodablePart = this.token.split('.')[1];
|
|
191
190
|
const decoded = JSON.parse(Buffer.from(tokenDecodablePart, 'base64').toString());
|
|
192
191
|
const endPath = '/documentdata/';
|
|
193
|
-
let documents = await this.tsFetchDocuments(
|
|
192
|
+
let documents = await this.tsFetchDocuments(this.token, decoded, endPath);
|
|
194
193
|
|
|
195
194
|
let baseUrl = (decoded.hasOwnProperty('https://visualtourbuilder.com/app_metadata')) ?
|
|
196
195
|
decoded['https://visualtourbuilder.com/app_metadata'].baseUrl :
|
|
@@ -201,7 +200,7 @@ class AppitBaseTransformer {
|
|
|
201
200
|
promises.push(new Promise(resolve => {
|
|
202
201
|
const req = https.request({
|
|
203
202
|
headers: {
|
|
204
|
-
'Authorization':
|
|
203
|
+
'Authorization': this.token
|
|
205
204
|
},
|
|
206
205
|
hostname: baseUrl.replace('https://', '').replace(/.com\/.*/, '.com').replace(/.app\/.*/, '.app'),
|
|
207
206
|
path: baseUrl.replace(/.*?.app/, '').replace(/.*?.com/, '') + endPath + document.id,
|
|
@@ -264,14 +263,7 @@ class AppitBaseTransformer {
|
|
|
264
263
|
async tsGetData()
|
|
265
264
|
{
|
|
266
265
|
return new Promise(async (resolve, reject) => {
|
|
267
|
-
|
|
268
|
-
try {
|
|
269
|
-
jwt = await this.fetchTSJWT()
|
|
270
|
-
} catch(e) {
|
|
271
|
-
return reject(e);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const tokenDecodablePart = jwt.split('.')[1];
|
|
266
|
+
const tokenDecodablePart = this.token.split('.')[1];
|
|
275
267
|
const decoded = JSON.parse(Buffer.from(tokenDecodablePart, 'base64').toString());
|
|
276
268
|
const endPath = '/dynamicdata/';
|
|
277
269
|
|
|
@@ -281,7 +273,7 @@ class AppitBaseTransformer {
|
|
|
281
273
|
|
|
282
274
|
let req = https.request({
|
|
283
275
|
headers: {
|
|
284
|
-
'Authorization':
|
|
276
|
+
'Authorization': this.token
|
|
285
277
|
},
|
|
286
278
|
hostname: baseUrl.replace('https://', '').replace(/.com\/.*/, '.com').replace(/.app\/.*/, '.app'),
|
|
287
279
|
path: baseUrl.replace(/.*?.app/, '').replace(/.*?.com/, '') + endPath,
|
|
@@ -304,51 +296,6 @@ class AppitBaseTransformer {
|
|
|
304
296
|
})
|
|
305
297
|
}
|
|
306
298
|
|
|
307
|
-
fetchTSJWT()
|
|
308
|
-
{
|
|
309
|
-
return new Promise((resolve, reject) => {
|
|
310
|
-
const data = JSON.stringify({
|
|
311
|
-
query: `{
|
|
312
|
-
tsJWT {
|
|
313
|
-
jwt
|
|
314
|
-
}
|
|
315
|
-
}`,
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
const options = {
|
|
319
|
-
hostname: 'vtb-gateway-legacy.visualtourbuilder.com',
|
|
320
|
-
path: '/graphql',
|
|
321
|
-
port: 443,
|
|
322
|
-
method: 'POST',
|
|
323
|
-
headers: {
|
|
324
|
-
'Content-Type': 'application/json',
|
|
325
|
-
'Content-Length': data.length,
|
|
326
|
-
'Authorization': `Bearer ${this.token}`,
|
|
327
|
-
'User-Agent': 'Node',
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
const req = https.request(options, (res) => {
|
|
332
|
-
let data = '';
|
|
333
|
-
|
|
334
|
-
res.on('data', (d) => {
|
|
335
|
-
data += d;
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
res.on('error', (e) => {
|
|
339
|
-
reject(e);
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
res.on('end', () => {
|
|
343
|
-
resolve(JSON.parse(data).data.tsJWT.jwt);
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
req.write(data);
|
|
348
|
-
req.end();
|
|
349
|
-
})
|
|
350
|
-
}
|
|
351
|
-
|
|
352
299
|
async mediaToBase64(media)
|
|
353
300
|
{
|
|
354
301
|
let promises = [];
|