vtb-appit 0.1.26 → 0.1.28

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.
@@ -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 jwt = await this.fetchTSJWT();
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(jwt, decoded, endPath);
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': jwt
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
- let jwt = null
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': jwt
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 = [];
package/appit.js CHANGED
@@ -398,7 +398,7 @@ class Appit {
398
398
  delete place.images;
399
399
 
400
400
  if(place.category_id && typeof place.category_id === 'string') {
401
- place.category_id = await this.findOrCreateCategory(place.category_id);
401
+ place.category_id = await this.findOrCreateCategory(place.category_id, 'places');
402
402
  }
403
403
 
404
404
  const placeData = {...place, ...images, excursion_id: this.history.excursionId};
@@ -455,7 +455,7 @@ class Appit {
455
455
  }
456
456
  }
457
457
 
458
- async findOrCreateCategory(title)
458
+ async findOrCreateCategory(title, type)
459
459
  {
460
460
  let category_id = null;
461
461
 
@@ -474,7 +474,7 @@ class Appit {
474
474
  })
475
475
 
476
476
  if(!category_id) {
477
- let result = await this.request('POST', `categories`, {title: title});
477
+ let result = await this.request('POST', `categories`, {title: title, workspace_id: this.transformer.workspace_id, type: type});
478
478
  if(result && result.success) {
479
479
  category_id = result.data.id;
480
480
  let categories = await this.request('GET', `categories?per_page=50000`);
@@ -849,7 +849,7 @@ class Appit {
849
849
  let info = this.clean(JSON.parse(JSON.stringify(travelInfo[i])));
850
850
 
851
851
  if(info.category_id && typeof info.category_id === 'string') {
852
- info.category_id = await this.findOrCreateCategory(info.category_id);
852
+ info.category_id = await this.findOrCreateCategory(info.category_id, 'travel');
853
853
  }
854
854
 
855
855
  const travelData = {...info, excursion_id: this.history.excursionId};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},