cozy-client 41.3.0 → 41.4.1

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.
@@ -2703,7 +2703,7 @@ var CozyClient = /*#__PURE__*/function () {
2703
2703
  CozyClient.hooks = CozyClient.hooks || {};
2704
2704
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2705
2705
 
2706
- CozyClient.version = "41.3.0";
2706
+ CozyClient.version = "41.4.1";
2707
2707
 
2708
2708
  _microee.default.mixin(CozyClient);
2709
2709
 
@@ -13,24 +13,25 @@ var _nodePolyglot = _interopRequireDefault(require("node-polyglot"));
13
13
 
14
14
  var _emojiCountry = require("../emojiCountry");
15
15
 
16
+ var _en = _interopRequireDefault(require("./en.json"));
17
+
18
+ var _fr = _interopRequireDefault(require("./fr.json"));
19
+
16
20
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17
21
 
18
22
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
23
 
24
+ var locales = {
25
+ en: _en.default,
26
+ fr: _fr.default
27
+ };
20
28
  var polyglots = {};
21
29
  var langs = ['fr', 'en'];
22
30
 
23
31
  for (var _i = 0, _langs = langs; _i < _langs.length; _i++) {
24
32
  var lang = _langs[_i];
25
- var locales = {};
26
-
27
- try {
28
- locales = require("./".concat(lang, ".json"));
29
- } catch (e) {// eslint-disable-line no-empty-block
30
- }
31
-
32
33
  var polyglot = new _nodePolyglot.default();
33
- polyglot.extend(locales);
34
+ polyglot.extend(locales[lang]);
34
35
  polyglots[lang] = polyglot;
35
36
  }
36
37
  /**
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.geodesicDistance = exports.computeSpeed = void 0;
7
+
8
+ /**
9
+ * Compute the speed from distance and duration
10
+ *
11
+ * @param {number} distance - The distance in meters
12
+ * @param {number} duration - The duration in seconds
13
+ * @returns {number} - The speed, in m/s, rounded to 2 decimals
14
+ */
15
+ var computeSpeed = function computeSpeed(distance, duration) {
16
+ if (!distance || !duration) {
17
+ return 0;
18
+ }
19
+
20
+ return Math.round(distance / duration * 100) / 100;
21
+ };
22
+
23
+ exports.computeSpeed = computeSpeed;
24
+
25
+ var degreesToRadians = function degreesToRadians(degrees) {
26
+ return degrees * Math.PI / 180;
27
+ };
28
+ /**
29
+ * Compute the distance between 2 geographic points, in meters.
30
+ *
31
+ * This is an implementation of the Haversine formula, that
32
+ * supposes a perfect sphere. We know this is not exactly the case
33
+ * for Earth, especially at the poles, but this approximation is good enough.
34
+ * More complex methods do exist, such as Vincenty formula, but we prefer
35
+ * simplicity over precision here.
36
+ * See https://en.wikipedia.org/wiki/Geodesics_on_an_ellipsoid
37
+ *
38
+ * @param {import("../types").Coordinates} point1 - The first point coordinates, in decimal degrees
39
+ * @param {import("../types").Coordinates} point2 - The second point coordinates, in decimal degrees
40
+ * @returns {number} The distance between the points, in meters, rounded to 2 decimals
41
+ */
42
+
43
+
44
+ var geodesicDistance = function geodesicDistance(point1, point2) {
45
+ if ((point1 === null || point1 === void 0 ? void 0 : point1.lon) === undefined || (point1 === null || point1 === void 0 ? void 0 : point1.lat) === undefined || (point2 === null || point2 === void 0 ? void 0 : point2.lon) === undefined || (point2 === null || point2 === void 0 ? void 0 : point2.lat) === undefined) {
46
+ return null;
47
+ }
48
+
49
+ var lon1 = degreesToRadians(point1.lon);
50
+ var lat1 = degreesToRadians(point1.lat);
51
+ var lon2 = degreesToRadians(point2.lon);
52
+ var lat2 = degreesToRadians(point2.lat);
53
+ var diffLon = lon2 - lon1;
54
+ var diffLat = lat2 - lat1;
55
+ var aLat = Math.pow(Math.sin(diffLat / 2), 2);
56
+ var aLon = Math.pow(Math.sin(diffLon / 2), 2);
57
+ var a = aLat + Math.cos(lat1) * Math.cos(lat2) * aLon;
58
+ var c = 2 * Math.asin(Math.sqrt(a)); // Radius of earth is 6371 km
59
+
60
+ var distance = 6371 * 1000 * c;
61
+ return Math.round(distance * 100) / 100;
62
+ };
63
+
64
+ exports.geodesicDistance = geodesicDistance;
@@ -0,0 +1,32 @@
1
+ const { geodesicDistance, computeSpeed } = require('./geo')
2
+
3
+ describe('geodesicDistance', () => {
4
+ it('should return 0 for 2 points with same coordinates', () => {
5
+ const p1 = { lat: 0.0, lon: 0.0 }
6
+ const p2 = { lat: 0.0, lon: 0.0 }
7
+ expect(geodesicDistance(p1, p2)).toEqual(0)
8
+ })
9
+
10
+ it('should return null when points are not properly formatted', () => {
11
+ expect(geodesicDistance(null, null)).toEqual(null)
12
+ expect(geodesicDistance({ lat: 1.0 }, { lon: 5.6 })).toEqual(null)
13
+ })
14
+
15
+ it('should return the correct Paris-NY distance', () => {
16
+ const paris = { lat: 48.8566, lon: 2.3522 }
17
+ const NY = { lat: 40.7128, lon: -74.006 }
18
+ expect(geodesicDistance(paris, NY)).toEqual(5837240.9)
19
+ })
20
+ })
21
+
22
+ describe('speed', () => {
23
+ it('should return 0 when the speed or distance is not set or 0', () => {
24
+ expect(computeSpeed(0, 0)).toEqual(0)
25
+ expect(computeSpeed(10, 0)).toEqual(0)
26
+ expect(computeSpeed(0, 10)).toEqual(0)
27
+ expect(computeSpeed()).toEqual(0)
28
+ })
29
+ it('should return the correct running speed of the developer', () => {
30
+ expect(computeSpeed(10000, 1800)).toEqual(5.56)
31
+ })
32
+ })
package/dist/types.js CHANGED
@@ -493,6 +493,12 @@ var _dsl = require("./queries/dsl");
493
493
  *
494
494
  */
495
495
 
496
+ /**
497
+ * @typedef {object} Coordinates
498
+ * @property {number} lat - The latitude, in decimal degrees
499
+ * @property {number} lon - The longitude, in decimal degrees
500
+ */
501
+
496
502
  /**
497
503
  * Receives the URL to present to the user as a parameter, and should return a promise that resolves with the URL the user was redirected to after accepting the permissions.
498
504
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "41.3.0",
3
+ "version": "41.4.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -75,5 +75,5 @@
75
75
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
76
76
  },
77
77
  "sideEffects": false,
78
- "gitHead": "b69af4c4c28456f2d24e3dffa19f7921cb489e4e"
78
+ "gitHead": "973c0aa500d04e1463b5a7a9f4f3d5a8d80e2bd9"
79
79
  }
@@ -0,0 +1,2 @@
1
+ export function computeSpeed(distance: number, duration: number): number;
2
+ export function geodesicDistance(point1: import("../types").Coordinates, point2: import("../types").Coordinates): number;
package/types/types.d.ts CHANGED
@@ -824,6 +824,16 @@ export type DACCAggregate = {
824
824
  */
825
825
  std: number;
826
826
  };
827
+ export type Coordinates = {
828
+ /**
829
+ * - The latitude, in decimal degrees
830
+ */
831
+ lat: number;
832
+ /**
833
+ * - The longitude, in decimal degrees
834
+ */
835
+ lon: number;
836
+ };
827
837
  /**
828
838
  * Receives the URL to present to the user as a parameter, and should return a promise that resolves with the URL the user was redirected to after accepting the permissions.
829
839
  */