cozy-client 46.10.1 → 46.11.0

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.
@@ -2782,7 +2782,7 @@ var CozyClient = /*#__PURE__*/function () {
2782
2782
  CozyClient.hooks = CozyClient.hooks || {};
2783
2783
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2784
2784
 
2785
- CozyClient.version = "46.10.1";
2785
+ CozyClient.version = "46.11.0";
2786
2786
 
2787
2787
  _microee.default.mixin(CozyClient);
2788
2788
 
@@ -1,21 +1,36 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.getEmojiByCountry = void 0;
7
- var emojiCountry = {
8
- fr: '🇫🇷'
9
- };
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ var _logger = _interopRequireDefault(require("../../logger"));
13
+
14
+ // The offset between uppercase ASCII and regional indicator symbols
15
+ var UNICODE_OFFSET = 127397;
10
16
  /**
11
- * @param {string} country - fr, en, etc
12
- * @param {Function} t - Translation function
17
+ * @param {string} countryCode - ISO 3166-1 alpha-2 (eg. fr, us, etc)
13
18
  * @returns {string} - Emoji of country
14
19
  */
15
20
 
16
- var getEmojiByCountry = function getEmojiByCountry(country, t) {
17
- if (country === 'stranger') return t('country.stranger');
18
- return emojiCountry[country];
21
+ var getEmojiByCountry = function getEmojiByCountry(countryCode) {
22
+ if (!countryCode) return null;
23
+
24
+ if (!/^[a-z]{2}$/i.test(countryCode)) {
25
+ _logger.default.error("Country argument must be an ISO 3166-1 alpha-2 string, but got '".concat(JSON.stringify(countryCode), "' instead."));
26
+
27
+ return null;
28
+ }
29
+
30
+ var codePoints = (0, _toConsumableArray2.default)(countryCode.toUpperCase()).map(function (letter) {
31
+ return letter.codePointAt(0) + UNICODE_OFFSET;
32
+ });
33
+ return String.fromCodePoint.apply(String, (0, _toConsumableArray2.default)(codePoints));
19
34
  };
20
35
 
21
36
  exports.getEmojiByCountry = getEmojiByCountry;
@@ -1,26 +1,34 @@
1
1
  import { getEmojiByCountry } from './emojiCountry'
2
+ import logger from '../../logger'
2
3
 
3
4
  describe('getEmojiByCountry', () => {
4
- const mockT = jest.fn(key => key)
5
- it('should return fr flag', () => {
6
- const res = getEmojiByCountry('fr', mockT)
5
+ beforeEach(() => {
6
+ jest.spyOn(logger, 'error').mockImplementation(() => jest.fn())
7
+ })
8
+ afterEach(() => {
9
+ logger.error.mockRestore()
10
+ })
11
+
12
+ it('should return French flag', () => {
13
+ const res = getEmojiByCountry('fr')
7
14
 
8
15
  expect(res).toBe('🇫🇷')
9
16
  })
10
- it('should return "stranger" string (key: country.stranger)', () => {
11
- const mockT = jest.fn(key => key)
12
- const res = getEmojiByCountry('stranger', mockT)
17
+ it('should return Belgian flag', () => {
18
+ const res = getEmojiByCountry('be')
13
19
 
14
- expect(res).toBe('country.stranger')
20
+ expect(res).toBe('🇧🇪')
15
21
  })
16
- it('should return "undefined" if the country is not "fr"', () => {
17
- const res = getEmojiByCountry('en', mockT)
22
+ it('should return "null" if the country is not ISO 3166-1 alpha-2 string', () => {
23
+ const res = getEmojiByCountry('fra')
18
24
 
19
- expect(res).toBe(undefined)
25
+ expect(logger.error).toHaveBeenCalledTimes(1)
26
+ expect(res).toBe(null)
20
27
  })
21
- it('should return "undefined" if the country is undefined', () => {
22
- const res = getEmojiByCountry(undefined, mockT)
28
+ it('should return "null" if the country is undefined', () => {
29
+ const res = getEmojiByCountry(undefined)
23
30
 
24
- expect(res).toBe(undefined)
31
+ expect(logger.error).not.toHaveBeenCalled()
32
+ expect(res).toBe(null)
25
33
  })
26
34
  })
@@ -49,8 +49,10 @@ var getBoundT = function getBoundT(lang) {
49
49
  smart_count: (opts === null || opts === void 0 ? void 0 : opts.smart_count) || 1
50
50
  });
51
51
 
52
- var emojiCountry = (0, _emojiCountry.getEmojiByCountry)(opts === null || opts === void 0 ? void 0 : opts.country, t);
53
- return emojiCountry ? "".concat(t(label, newOpts), " ").concat(emojiCountry) : t(label, newOpts);
52
+ var country = opts === null || opts === void 0 ? void 0 : opts.country;
53
+ var emojiCountry = country !== 'stranger' ? (0, _emojiCountry.getEmojiByCountry)(country) : null;
54
+ var strangerLabel = country === 'stranger' ? t('country.stranger') : null;
55
+ return emojiCountry || strangerLabel ? "".concat(t(label, newOpts), " ").concat(emojiCountry || strangerLabel) : t(label, newOpts);
54
56
  };
55
57
  };
56
58
  /**
@@ -24,6 +24,8 @@ describe('getBoundT', () => {
24
24
  ${'Scan.items.national_id_card'} | ${undefined} | ${undefined} | ${'en'} | ${'ID card'}
25
25
  ${'Scan.items.national_id_card'} | ${'fr'} | ${undefined} | ${'en'} | ${'ID card 🇫🇷'}
26
26
  ${'Scan.items.national_id_card'} | ${'stranger'} | ${undefined} | ${'en'} | ${'ID card Stranger'}
27
+ ${'Scan.items.national_id_card'} | ${'be'} | ${1} | ${'en'} | ${'ID card 🇧🇪'}
28
+ ${'Scan.items.national_id_card'} | ${'be'} | ${2} | ${'en'} | ${'ID cards 🇧🇪'}
27
29
  ${'Scan.items.national_id_card'} | ${'fr'} | ${1} | ${'en'} | ${'ID card 🇫🇷'}
28
30
  ${'Scan.items.national_id_card'} | ${'fr'} | ${2} | ${'en'} | ${'ID cards 🇫🇷'}
29
31
  ${'Scan.items.national_id_card'} | ${undefined} | ${1} | ${'en'} | ${'ID card'}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "46.10.1",
3
+ "version": "46.11.0",
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": "68d9fab92251c68a202c3eed18f479a0eca1a945"
78
+ "gitHead": "c3881442529ce33d979fdc8a90396b6d68f507d7"
79
79
  }
@@ -1 +1 @@
1
- export function getEmojiByCountry(country: string, t: Function): string;
1
+ export function getEmojiByCountry(countryCode: string): string;