@laboratoria/sdk-js 5.0.0 → 5.1.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -10,6 +10,8 @@ import { createAPI as createCoreAPI } from './lib/core';
10
10
  import { createAPI as createCurriculumAPI } from './lib/curriculum';
11
11
  import { createAPI as createJobsAPI } from './lib/jobs';
12
12
 
13
+ export * from './lib/util';
14
+
13
15
  export const createApp = ({
14
16
  firebaseApiKey = 'AIzaSyAXbaEbpq8NOfn0r8mIrcoHvoGRkJThwdc',
15
17
  firebaseProject = 'laboratoria-la',
package/lib/core.js CHANGED
@@ -10,7 +10,8 @@ const extended = {
10
10
  Country: {
11
11
  primaryKey: 'code',
12
12
  plural: 'countries',
13
- searchProps: ['code', 'name'],
13
+ searchProps: ['code', 'name', "timeZone"],
14
+ getOptionLabel: ({ code, name }) => `${code} / ${name}`,
14
15
  },
15
16
  ActivityLogEntry: {
16
17
  plural: 'activityLog',
@@ -87,6 +88,7 @@ const extended = {
87
88
  'admissionStart',
88
89
  'admissionEnd',
89
90
  'placementStart',
91
+ 'admissionCountries',
90
92
  ],
91
93
  searchProps: ['name'],
92
94
  getOptionLabel: ({ id, name, stage }) => (
@@ -172,7 +174,10 @@ const extended = {
172
174
  },
173
175
  },
174
176
  Student: {
175
- inputProps: [],
177
+ inputProps: [
178
+ 'cohort',
179
+ 'user',
180
+ ],
176
181
  searchProps: [],
177
182
  },
178
183
  Dropout: {
package/lib/util.js ADDED
@@ -0,0 +1,68 @@
1
+ const pad = n => n > 9 ? `${n}` : `0${n}`;
2
+
3
+ export const formatDate = date => (
4
+ `${pad(date.getUTCDate())}/${pad(date.getUTCMonth() + 1)}/${date.getUTCFullYear()}`
5
+ );
6
+
7
+ export const formatTime = date => (
8
+ `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${date.getUTCSeconds()} UTC`
9
+ );
10
+
11
+ export const formatDateTime = date => `${formatDate(date)} ${formatTime(date)}`;
12
+
13
+ const locales = {
14
+ es: 'es-ES',
15
+ pt: 'pt-BR',
16
+ };
17
+
18
+ export const formatMonth = (date, lang = 'es', showYear = false) => {
19
+ return new Intl.DateTimeFormat(locales[lang], {
20
+ ...(showYear && {
21
+ year: 'numeric',
22
+ }),
23
+ month: 'long',
24
+ day: 'numeric',
25
+ timeZone: 'UTC',
26
+ }).format(new Date(date));
27
+ };
28
+
29
+ export const getAgeAt = (dateOfBirth, at) => {
30
+ let age = at.getFullYear() - dateOfBirth.getFullYear();
31
+ const m = at.getMonth() - dateOfBirth.getMonth();
32
+
33
+ if (m < 0 || (m === 0 && at.getDate() < dateOfBirth.getDate())) {
34
+ age--;
35
+ }
36
+
37
+ return age;
38
+ };
39
+
40
+ const createCurrencyFormatter = (
41
+ lang,
42
+ countryCode,
43
+ currencyCode,
44
+ ) => new Intl.NumberFormat(
45
+ `${lang}-${countryCode}`,
46
+ { currency: currencyCode },
47
+ );
48
+
49
+ export const formatCurrency = (
50
+ val,
51
+ lang,
52
+ countryCode,
53
+ currencyCode,
54
+ ) => createCurrencyFormatter(
55
+ lang,
56
+ countryCode,
57
+ currencyCode,
58
+ ).format(val);
59
+
60
+ export const parseCurrency = val => parseInt(val.replace(/[,\.]/g, ''), 10);
61
+
62
+ export const loadFromLocalStorage = (path) => {
63
+ try {
64
+ return JSON.parse(window.localStorage.getItem(path));
65
+ } catch (_) {
66
+ return null;
67
+ }
68
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laboratoria/sdk-js",
3
- "version": "5.0.0",
3
+ "version": "5.1.0-beta.0",
4
4
  "description": "Laboratoria JavaScript (browser) SDK",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -11,16 +11,16 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "blueimp-md5": "^2.19.0",
14
- "firebase": "^9.20.0"
14
+ "firebase": "^9.22.1"
15
15
  },
16
16
  "devDependencies": {
17
- "@babel/core": "^7.21.4",
18
- "@babel/plugin-transform-modules-commonjs": "^7.21.2",
17
+ "@babel/core": "^7.21.8",
18
+ "@babel/plugin-transform-modules-commonjs": "^7.21.5",
19
19
  "babel-jest": "^29.5.0",
20
20
  "jest": "^29.5.0",
21
21
  "jest-environment-jsdom": "^29.5.0",
22
- "webpack": "^5.80.0",
23
- "webpack-cli": "^5.0.2"
22
+ "webpack": "^5.84.1",
23
+ "webpack-cli": "^5.1.1"
24
24
  },
25
25
  "jest": {
26
26
  "testEnvironment": "jsdom",
@@ -33,4 +33,4 @@
33
33
  }
34
34
  }
35
35
  }
36
- }
36
+ }
package/schemas/core.json CHANGED
@@ -10,6 +10,44 @@
10
10
  "name": {
11
11
  "type": "string"
12
12
  },
13
+ "incomeFilter": {
14
+ "type": [
15
+ "integer",
16
+ "null"
17
+ ]
18
+ },
19
+ "canApply": {
20
+ "type": "boolean",
21
+ "default": false
22
+ },
23
+ "capital": {
24
+ "type": "array",
25
+ "items": {
26
+ "type": "string"
27
+ }
28
+ },
29
+ "timeZone": {
30
+ "type": [
31
+ "string",
32
+ "null"
33
+ ]
34
+ },
35
+ "flag": {
36
+ "type": [
37
+ "string",
38
+ "null"
39
+ ]
40
+ },
41
+ "currency": {
42
+ "anyOf": [
43
+ {
44
+ "$ref": "#/definitions/Currency"
45
+ },
46
+ {
47
+ "type": "null"
48
+ }
49
+ ]
50
+ },
13
51
  "contracts": {
14
52
  "type": "array",
15
53
  "items": {
@@ -39,6 +77,32 @@
39
77
  "items": {
40
78
  "$ref": "#/definitions/EducationLevel"
41
79
  }
80
+ },
81
+ "universities": {
82
+ "type": "array",
83
+ "items": {
84
+ "$ref": "#/definitions/University"
85
+ }
86
+ }
87
+ }
88
+ },
89
+ "Currency": {
90
+ "type": "object",
91
+ "properties": {
92
+ "code": {
93
+ "type": "string"
94
+ },
95
+ "name": {
96
+ "type": "string"
97
+ },
98
+ "symbol": {
99
+ "type": "string"
100
+ },
101
+ "countries": {
102
+ "type": "array",
103
+ "items": {
104
+ "$ref": "#/definitions/Country"
105
+ }
42
106
  }
43
107
  }
44
108
  },
@@ -397,6 +461,12 @@
397
461
  ],
398
462
  "format": "date-time"
399
463
  },
464
+ "admissionCountries": {
465
+ "type": "array",
466
+ "items": {
467
+ "type": "string"
468
+ }
469
+ },
400
470
  "placementStart": {
401
471
  "type": [
402
472
  "string",
@@ -659,9 +729,6 @@
659
729
  "type": "string",
660
730
  "format": "date-time"
661
731
  },
662
- "countryCode": {
663
- "type": "string"
664
- },
665
732
  "lang": {
666
733
  "type": "string",
667
734
  "enum": [
@@ -676,6 +743,9 @@
676
743
  "filter": {
677
744
  "type": "boolean"
678
745
  },
746
+ "country": {
747
+ "$ref": "#/definitions/Country"
748
+ },
679
749
  "applications": {
680
750
  "type": "array",
681
751
  "items": {
@@ -1258,6 +1328,9 @@
1258
1328
  "country": {
1259
1329
  "$ref": "#/definitions/Country"
1260
1330
  },
1331
+ "currency": {
1332
+ "$ref": "#/definitions/Currency"
1333
+ },
1261
1334
  "user": {
1262
1335
  "$ref": "#/definitions/User"
1263
1336
  },