@nachocab/pipedream-global 2.0.37 → 2.0.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nachocab/pipedream-global",
3
- "version": "2.0.37",
3
+ "version": "2.0.40",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,14 +4,24 @@ const _ = require('lodash');
4
4
  function parseClassEmail(emailBody) {
5
5
  let classesToSchedule = emailBody
6
6
  .replace(/agenda:/gi, '\nAgenda:')
7
- .replace(/t[íi]tulo:/gi, '\nTítulo:')
8
- .replace(/(\S)(d[íi]a:)/gi, '$1 $2') // ensure space before Día:
9
- .replace(/(\S)(hora:)/gi, '$1 $2') // ensure space before Hora:
10
- .replace(/(\S)(nivel:)/gi, '$1 $2') // ensure space before Nivel:
11
- .replace(/(\S)(zona:)/gi, '$1 $2') // ensure space before Zona:
12
- .replace(/(\S)(t[íi]tulo:)/gi, '$1 $2') // ensure space before Título:
13
- .replace(/(\S)(participantes:)/gi, '$1 $2') // ensure space before Participantes:
14
- .replace(/(\S)(agenda:)/gi, '$1 $2'); // ensure space before Agenda:
7
+ .replace(/t[íi]tulo:|title:/gi, 'Title:')
8
+ .replace(/d[íi]a:|day:/gi, 'Day:')
9
+ .replace(/hora:|time:/gi, 'Time:')
10
+ .replace(/zona:|timezone:/gi, 'Timezone:')
11
+ .replace(/nivel:|level:/gi, 'Level:')
12
+ .replace(/@nombre:|@username:/gi, 'Username:')
13
+ .replace(/participantes:|participants:/gi, 'NumParticipants:')
14
+ .replace(/zoom:/gi, 'Zoom:')
15
+
16
+ .replace(/(\S)(Title:)/gi, '$1 $2') // I think we do this to prevent '>> whatever' from being counted
17
+ .replace(/(\S)(Day:)/gi, '$1 $2')
18
+ .replace(/(\S)(Time:)/gi, '$1 $2')
19
+ .replace(/(\S)(Timezone:)/gi, '$1 $2')
20
+ .replace(/(\S)(Level:)/gi, '$1 $2')
21
+ .replace(/(\S)(Username:)/gi, '$1 $2')
22
+ .replace(/(\S)(Zoom:)/gi, '$1 $2')
23
+ .replace(/(\S)(NumParticipants:)/gi, '$1 $2')
24
+ .replace(/(\S)(Agenda:)/gi, '$1 $2');
15
25
 
16
26
  classesToSchedule = classesToSchedule
17
27
  .split(/\n/)
@@ -20,39 +30,40 @@ function parseClassEmail(emailBody) {
20
30
  .split(/\n*[-=]{2,}\n*/); // split on === but also ==, ------, etc.
21
31
 
22
32
  return classesToSchedule
23
- .filter((x) => x && x.match('@nombre'))
33
+ .filter((x) => x && x.match(/@nombre|@username|Username/))
24
34
  .map((body) => {
25
- let teacherUsername = body.match(/@nombre:\s*@?([\wáéíóúü]+)/i);
35
+ let teacherUsername = body.match(/Username:\s*@?([\wáéíóúü]+)/i);
36
+
26
37
  if (teacherUsername) {
27
38
  teacherUsername = teacherUsername[1];
28
39
  } else {
29
- throw new Error('@nombre not valid');
40
+ throw new Error('Invalid username');
30
41
  }
31
42
 
32
- let classLevelName = body.match(/nivel:\s*([\wáéíóúü]+)/i);
43
+ let classLevelName = body.match(/Level:\s*([\wáéíóúü]+)/i);
33
44
  if (classLevelName) {
34
45
  classLevelName = classLevelName[1].toLowerCase();
35
46
  } else {
36
- throw new Error('Nivel not valid');
47
+ // throw new Error('Invalid level');
37
48
  }
38
49
 
39
- let numParticipants = body.match(/participantes:\s*(\d+)/i);
50
+ let numParticipants = body.match(/NumParticipants:\s*(\d+)/i);
40
51
  if (numParticipants) {
41
52
  numParticipants = Number(numParticipants[1]);
42
53
  }
43
54
 
44
- let day = body.match(/d[ií]a:\s*(\d{1,2}[-/]\d{1,2}[-/]\d{4})/i);
55
+ let day = body.match(/Day:\s*(\d{1,2}[-/]\d{1,2}[-/]\d{4})/i);
45
56
  if (day) {
46
57
  day = day[1];
47
58
  } else {
48
- throw new Error('Día not valid');
59
+ throw new Error('Invalid day');
49
60
  }
50
61
 
51
- let hour = body.match(/hora:\s*(\d{1,2}:\d{2})/i);
62
+ let hour = body.match(/Time:\s*(\d{1,2}:\d{2})/i);
52
63
  if (hour) {
53
64
  hour = hour[1];
54
65
  } else {
55
- throw new Error('Hora not valid');
66
+ throw new Error('Invalid time');
56
67
  }
57
68
 
58
69
  const scheduledFor = moment(
@@ -65,14 +76,14 @@ function parseClassEmail(emailBody) {
65
76
  throw new Error(`Invalid datetime: ${day} ${hour}`);
66
77
  }
67
78
 
68
- let timeZone = body.match(/zona:\s*([\w]+\/[\w_]+)/i);
79
+ let timeZone = body.match(/Timezone:\s*([\w]+\/[\w_]+)/i);
69
80
  if (timeZone) {
70
81
  timeZone = timeZone[1];
71
82
  } else {
72
- throw new Error('Zona not valid');
83
+ throw new Error('Invalid timezone');
73
84
  }
74
85
 
75
- let classTitle = body.match(/t[ií]tulo:\s*(?:> )?(.+)/i);
86
+ let classTitle = body.match(/Title:\s*(?:> )?(.+)/i);
76
87
  if (classTitle) {
77
88
  classTitle = classTitle[1]
78
89
  .trim()
@@ -82,7 +93,7 @@ function parseClassEmail(emailBody) {
82
93
  classTitle = 'Por decidir';
83
94
  }
84
95
 
85
- let classDescription = body.match(/agenda:\s*(?:> )?([\s\S]+)/i);
96
+ let classDescription = body.match(/Agenda:\s*(?:> )?([\s\S]+)/i);
86
97
  if (classDescription) {
87
98
  classDescription = classDescription[1]
88
99
  .split('\n')
package/src/util.js CHANGED
@@ -51,7 +51,7 @@ function getMerchantName({ rawName, translator }) {
51
51
 
52
52
  const formattedName = rawName
53
53
  .replace(
54
- /Pago en |Recibo |Transferencia emitida a |Devolución Tarjeta |Transferencia emitida periódica|Traspaso interno emitido/g,
54
+ /Pago en |Recibo |Transferencia emitida a |Devolución Tarjeta |Transferencia emitida periódica|Traspaso interno emitido|Paddle\.net\* /g,
55
55
  ''
56
56
  )
57
57
  .trim()
@@ -8,23 +8,23 @@ describe('parseClassEmail', function () {
8
8
  const emailBody = `
9
9
  @nombre @gloria
10
10
  `;
11
- expect(() => parseClassEmail(emailBody)).to.throw('@nombre not valid');
11
+ expect(() => parseClassEmail(emailBody)).to.throw('Invalid username');
12
12
  });
13
13
 
14
14
  it.skip('detects missing @ at sign', function () {
15
15
  const emailBody = `
16
16
  nombre: @Santiago
17
17
  `;
18
- expect(() => parseClassEmail(emailBody)).to.throw('@nombre not valid');
18
+ expect(() => parseClassEmail(emailBody)).to.throw('Invalid username');
19
19
  });
20
20
 
21
- it('detects missing Nivel', function () {
22
- const emailBody = `
23
- @nombre: @gloria
24
- Nivel Intermedio
25
- `;
26
- expect(() => parseClassEmail(emailBody)).to.throw('Nivel not valid');
27
- });
21
+ // it('detects missing Nivel', function () {
22
+ // const emailBody = `
23
+ // @nombre: @gloria
24
+ // Nivel Intermedio
25
+ // `;
26
+ // expect(() => parseClassEmail(emailBody)).to.throw('Invalid level');
27
+ // });
28
28
 
29
29
  it('detects invalid day', function () {
30
30
  const emailBody = `
@@ -33,7 +33,7 @@ describe('parseClassEmail', function () {
33
33
  Día: 13 octubre  
34
34
  hora: 16:00
35
35
  `;
36
- expect(() => parseClassEmail(emailBody)).to.throw('Día not valid');
36
+ expect(() => parseClassEmail(emailBody)).to.throw('Invalid day');
37
37
  });
38
38
 
39
39
  it('allows one-digit day', function () {
@@ -54,7 +54,7 @@ describe('parseClassEmail', function () {
54
54
  Día: 10-10-2020
55
55
  hora: 1600
56
56
  `;
57
- expect(() => parseClassEmail(emailBody)).to.throw('Hora not valid');
57
+ expect(() => parseClassEmail(emailBody)).to.throw('Invalid time');
58
58
  });
59
59
 
60
60
  it('detects invalid timeZone', function () {
@@ -65,7 +65,7 @@ describe('parseClassEmail', function () {
65
65
  hora: 16:00
66
66
  Zona: AmericaMexico_City
67
67
  `;
68
- expect(() => parseClassEmail(emailBody)).to.throw('Zona not valid');
68
+ expect(() => parseClassEmail(emailBody)).to.throw('Invalid timezone');
69
69
  });
70
70
 
71
71
  it('uses default title and agenda', function () {
@@ -434,4 +434,46 @@ En la sesión del día 30 de noviembre seguiremos con nuestra clase de`,
434
434
  },
435
435
  ]);
436
436
  });
437
+
438
+ it('ignores URGENT markers', function () {
439
+ const emailBody = `
440
+ @nombre: @nacho Nivel: Avanzado Día: 1-11-2020 hora: 17:30 Zona: Europe/Madrid Título: Traducciones a la vista Agenda: Buscaremos los equivalentes más naturales === URGENT @nombre: @nacho Nivel: Avanzado Día: 8-11-2020 hora: 18:30 Zona: Europe/Madrid Título: Traducciones a la vista 2 Agenda: Buscaremos los equivalentes más naturales ===`;
441
+ expect(parseClassEmail(emailBody)).to.eql([
442
+ {
443
+ teacherUsername: 'nacho',
444
+ classLevelName: 'avanzado',
445
+ scheduledFor: '2020-11-01T17:30',
446
+ timeZone: 'Europe/Madrid',
447
+ classTitle: 'Traducciones a la vista',
448
+ classDescription: 'Buscaremos los equivalentes más naturales',
449
+ },
450
+ {
451
+ teacherUsername: 'nacho',
452
+ classLevelName: 'avanzado',
453
+ scheduledFor: '2020-11-08T18:30',
454
+ timeZone: 'Europe/Madrid',
455
+ classTitle: 'Traducciones a la vista 2',
456
+ classDescription: 'Buscaremos los equivalentes más naturales',
457
+ },
458
+ ]);
459
+ });
460
+
461
+ it('handles English', function () {
462
+ const emailBody = `@username: @Kevin
463
+ Day: 21-10-2021
464
+ time: 18:30
465
+ Timezone: America/Chicago
466
+ Title: Vocab
467
+ Agenda: Blah blah
468
+ ===`;
469
+ expect(parseClassEmail(emailBody)).to.eql([
470
+ {
471
+ teacherUsername: 'Kevin',
472
+ scheduledFor: '2021-10-21T18:30',
473
+ timeZone: 'America/Chicago',
474
+ classTitle: 'Vocab',
475
+ classDescription: 'Blah blah\n',
476
+ },
477
+ ]);
478
+ });
437
479
  });
@@ -9,6 +9,11 @@ const {
9
9
 
10
10
  describe('reshape', function () {
11
11
  describe('nestedArrayToArrayOfObjects', function () {
12
+ it('works when empty', function () {
13
+ const objectOfArrays = nestedArrayToArrayOfObjects([]);
14
+ expect(objectOfArrays).to.eql([]);
15
+ });
16
+
12
17
  // default google sheets values
13
18
  it('works', function () {
14
19
  const objectOfArrays = nestedArrayToArrayOfObjects([