cozy-client 47.1.2 → 47.3.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 = "47.1.2";
2785
+ CozyClient.version = "47.3.0";
2786
2786
 
2787
2787
  _microee.default.mixin(CozyClient);
2788
2788
 
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getEmojiByCountry = exports.getAllNationalities = exports.getNationalityByCodeISO = exports.getAllCountryNames = exports.getCountryNameByCodeISO = exports.getAllCountries = exports.checkCountryCode = exports.COUNTRIES_ISO = void 0;
8
+ exports.getEmojiByCountry = exports.getAllNationalities = exports.getNationalityByCodeISO = exports.getAllCountryNames = exports.getCountryNameByCodeISO = exports.getAllCountries = exports.checkCountryCode = exports.isCountryCodeAlpha2 = exports.isCountryCodeAlpha3 = exports.isValidCountryCodeTranslation = exports.COUNTRIES_ISO = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
@@ -1003,21 +1003,67 @@ var COUNTRIES_ISO = [{
1003
1003
  number: '248'
1004
1004
  }];
1005
1005
  /**
1006
- * Check if a country code is valid
1006
+ * Check if a country code translation is valid
1007
1007
  *
1008
- * @param {string} code - The country code
1009
- * @returns {boolean} - True if the code is valid, false otherwise
1008
+ * @param {string} lang - Language of country names and nationalities
1009
+ * @param {string} val - Country code
1010
+ * @returns {boolean} - True if the translation is valid, false otherwise
1010
1011
  */
1011
1012
 
1012
1013
  exports.COUNTRIES_ISO = COUNTRIES_ISO;
1013
1014
 
1014
- var checkCountryCode = function checkCountryCode(code) {
1015
+ var isValidCountryCodeTranslation = function isValidCountryCodeTranslation(lang, val) {
1016
+ var _getLocalizer = (0, _locales.getLocalizer)(lang),
1017
+ polyglot = _getLocalizer.polyglot;
1018
+
1019
+ return isCountryCodeAlpha2(val) && polyglot.has("nationalities.".concat(val)) && polyglot.has("countries.".concat(val));
1020
+ };
1021
+ /**
1022
+ * Check if a country code is an ISO 3166-1 alpha-3 code
1023
+ *
1024
+ * @param {string} code - The country code
1025
+ * @returns {boolean} - True if the code is an ISO 3166-1 alpha-3 code, false otherwise
1026
+ */
1027
+
1028
+
1029
+ exports.isValidCountryCodeTranslation = isValidCountryCodeTranslation;
1030
+
1031
+ var isCountryCodeAlpha3 = function isCountryCodeAlpha3(code) {
1015
1032
  if (!code) return false;
1016
1033
  var codeUpperCase = code.toUpperCase();
1017
- var foundCountry = COUNTRIES_ISO.find(function (country) {
1018
- return country.code2 === codeUpperCase || country.code3 === codeUpperCase;
1034
+ return COUNTRIES_ISO.some(function (c) {
1035
+ return c.code3 === codeUpperCase;
1019
1036
  });
1020
- return !!foundCountry;
1037
+ };
1038
+ /**
1039
+ * Check if a country code is an ISO 3166-1 alpha-2 code
1040
+ *
1041
+ * @param {string} code - The country code
1042
+ * @returns {boolean} - True if the code is an ISO 3166-1 alpha-2 code, false otherwise
1043
+ */
1044
+
1045
+
1046
+ exports.isCountryCodeAlpha3 = isCountryCodeAlpha3;
1047
+
1048
+ var isCountryCodeAlpha2 = function isCountryCodeAlpha2(code) {
1049
+ if (!code) return false;
1050
+ var codeUpperCase = code.toUpperCase();
1051
+ return COUNTRIES_ISO.some(function (c) {
1052
+ return c.code2 === codeUpperCase;
1053
+ });
1054
+ };
1055
+ /**
1056
+ * Check if a country code is valid
1057
+ *
1058
+ * @param {string} code - The country code
1059
+ * @returns {boolean} - True if the code is valid, false otherwise
1060
+ */
1061
+
1062
+
1063
+ exports.isCountryCodeAlpha2 = isCountryCodeAlpha2;
1064
+
1065
+ var checkCountryCode = function checkCountryCode(code) {
1066
+ return isCountryCodeAlpha2(code) || isCountryCodeAlpha3(code);
1021
1067
  };
1022
1068
  /**
1023
1069
  * Get all countries with all their information (ISO codes, names, nationalities)
@@ -1030,7 +1076,9 @@ var checkCountryCode = function checkCountryCode(code) {
1030
1076
  exports.checkCountryCode = checkCountryCode;
1031
1077
 
1032
1078
  var getAllCountries = function getAllCountries(lang) {
1033
- var t = (0, _locales.getLocalizer)(lang);
1079
+ var _getLocalizer2 = (0, _locales.getLocalizer)(lang),
1080
+ t = _getLocalizer2.t;
1081
+
1034
1082
  return COUNTRIES_ISO.map(function (country) {
1035
1083
  return {
1036
1084
  code2: country.code2,
@@ -4,7 +4,9 @@ import {
4
4
  getAllCountryNames,
5
5
  getAllNationalities,
6
6
  getCountryNameByCodeISO,
7
- getEmojiByCountry
7
+ getEmojiByCountry,
8
+ isCountryCodeAlpha2,
9
+ isCountryCodeAlpha3
8
10
  } from './countries'
9
11
  import logger from '../../logger'
10
12
 
@@ -165,3 +167,37 @@ describe('getEmojiByCountry', () => {
165
167
  expect(res).toBe(null)
166
168
  })
167
169
  })
170
+
171
+ describe('isCountryCodeAlpha3', () => {
172
+ it('should return true for valid country codes', () => {
173
+ expect(isCountryCodeAlpha3('FRA')).toBe(true)
174
+ expect(isCountryCodeAlpha3('fra')).toBe(true)
175
+ expect(isCountryCodeAlpha3('USA')).toBe(true)
176
+ expect(isCountryCodeAlpha3('usa')).toBe(true)
177
+ })
178
+
179
+ it('should return false for invalid country codes', () => {
180
+ expect(isCountryCodeAlpha3(undefined)).toBe(false)
181
+ expect(isCountryCodeAlpha3(null)).toBe(false)
182
+ expect(isCountryCodeAlpha3('')).toBe(false)
183
+ expect(isCountryCodeAlpha3('AAA')).toBe(false)
184
+ expect(isCountryCodeAlpha3('FR')).toBe(false)
185
+ })
186
+ })
187
+
188
+ describe('isCountryCodeAlpha2', () => {
189
+ it('should return true for valid country codes', () => {
190
+ expect(isCountryCodeAlpha2('FR')).toBe(true)
191
+ expect(isCountryCodeAlpha2('fr')).toBe(true)
192
+ expect(isCountryCodeAlpha2('US')).toBe(true)
193
+ expect(isCountryCodeAlpha2('us')).toBe(true)
194
+ })
195
+
196
+ it('should return false for invalid country codes', () => {
197
+ expect(isCountryCodeAlpha2(undefined)).toBe(false)
198
+ expect(isCountryCodeAlpha2(null)).toBe(false)
199
+ expect(isCountryCodeAlpha2('')).toBe(false)
200
+ expect(isCountryCodeAlpha2('AA')).toBe(false)
201
+ expect(isCountryCodeAlpha2('FRA')).toBe(false)
202
+ })
203
+ })
@@ -28,14 +28,18 @@ for (var _i = 0, _langs = langs; _i < _langs.length; _i++) {
28
28
  }
29
29
  /**
30
30
  * @param {string} lang - fr, en, etc
31
- * @returns {Function} - localization function
31
+ * @returns {{ t: Function, polyglot: object, lang: string }}
32
32
  */
33
33
 
34
34
 
35
35
  var getLocalizer = function getLocalizer(lang) {
36
36
  var polyglot = polyglots[lang] || polyglots['en'];
37
37
  var t = polyglot.t.bind(polyglot);
38
- return t;
38
+ return {
39
+ t: t,
40
+ polyglot: polyglot,
41
+ lang: lang
42
+ };
39
43
  };
40
44
 
41
45
  exports.getLocalizer = getLocalizer;
@@ -47,7 +47,7 @@ var themesList = [{
47
47
  }, {
48
48
  id: 'theme3',
49
49
  label: 'work_study',
50
- icon: 'company',
50
+ icon: 'work',
51
51
  items: buildItemsByLabel(_constants.THEME_WORK_STUDY_LABELS)
52
52
  }, {
53
53
  id: 'theme4',
@@ -68,7 +68,7 @@ var themesList = [{
68
68
  }, {
69
69
  id: 'theme7',
70
70
  label: 'activity',
71
- icon: 'compass',
71
+ icon: 'chess',
72
72
  items: buildItemsByLabel(_constants.THEME_ACTIVITY_LABELS)
73
73
  }, {
74
74
  id: 'theme8',
@@ -427,7 +427,9 @@ var formatInformationMetadataValue = function formatInformationMetadataValue(val
427
427
  name = _ref5.name,
428
428
  qualificationLabel = _ref5.qualificationLabel;
429
429
  var tDoc = (0, _locales.getLocalizer)(lang);
430
- var tCountry = (0, _locales2.getLocalizer)(lang);
430
+
431
+ var _localizerCountry = (0, _locales2.getLocalizer)(lang),
432
+ tCountry = _localizerCountry.t;
431
433
 
432
434
  if (typeof value !== 'number' && !value) {
433
435
  return tDoc('Scan.qualification.noInfo');
@@ -449,7 +451,7 @@ var formatInformationMetadataValue = function formatInformationMetadataValue(val
449
451
  return "".concat(value, " \u20AC");
450
452
  }
451
453
 
452
- if (name === 'country' && (0, _countries.checkCountryCode)(value)) {
454
+ if (name === 'country' && (0, _countries.isValidCountryCodeTranslation)(lang, value)) {
453
455
  return tCountry("nationalities.".concat(value));
454
456
  }
455
457
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "47.1.2",
3
+ "version": "47.3.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": "308052cb1f01d11f22787d3a06146b5127eee5b4"
78
+ "gitHead": "0fc65682f558668d7b06fd16efb465e33e798f50"
79
79
  }
@@ -5,6 +5,9 @@
5
5
  * @type {import('../../types').CountryISO[]}
6
6
  */
7
7
  export const COUNTRIES_ISO: import('../../types').CountryISO[];
8
+ export function isValidCountryCodeTranslation(lang: string, val: string): boolean;
9
+ export function isCountryCodeAlpha3(code: string): boolean;
10
+ export function isCountryCodeAlpha2(code: string): boolean;
8
11
  export function checkCountryCode(code: string): boolean;
9
12
  export function getAllCountries(lang: string): import('../../types').Country[];
10
13
  export function getCountryNameByCodeISO(code: string | number, { lang }?: {
@@ -1 +1,5 @@
1
- export function getLocalizer(lang: string): Function;
1
+ export function getLocalizer(lang: string): {
2
+ t: Function;
3
+ polyglot: object;
4
+ lang: string;
5
+ };