cozy-client 47.1.1 → 47.2.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.
- package/dist/CozyClient.js +1 -1
- package/dist/models/country/countries.js +57 -9
- package/dist/models/country/countries.spec.js +37 -1
- package/dist/models/country/locales/index.js +6 -2
- package/dist/models/document/locales/en.json +1 -1
- package/dist/models/document/locales/fr.json +1 -1
- package/dist/models/document/locales/index.js +2 -2
- package/dist/models/document/locales/index.spec.js +10 -10
- package/dist/models/paper.js +4 -2
- package/package.json +2 -2
- package/types/models/country/countries.d.ts +3 -0
- package/types/models/country/locales/index.d.ts +5 -1
package/dist/CozyClient.js
CHANGED
|
@@ -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.
|
|
2785
|
+
CozyClient.version = "47.2.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}
|
|
1009
|
-
* @
|
|
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
|
|
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
|
-
|
|
1018
|
-
return
|
|
1034
|
+
return COUNTRIES_ISO.some(function (c) {
|
|
1035
|
+
return c.code3 === codeUpperCase;
|
|
1019
1036
|
});
|
|
1020
|
-
|
|
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
|
|
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
|
|
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
|
|
38
|
+
return {
|
|
39
|
+
t: t,
|
|
40
|
+
polyglot: polyglot,
|
|
41
|
+
lang: lang
|
|
42
|
+
};
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
exports.getLocalizer = getLocalizer;
|
|
@@ -50,8 +50,8 @@ var getBoundT = function getBoundT(lang) {
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
var country = opts === null || opts === void 0 ? void 0 : opts.country;
|
|
53
|
-
var emojiCountry = country !== '
|
|
54
|
-
var strangerLabel = country === '
|
|
53
|
+
var emojiCountry = country !== 'foreign' ? (0, _countries.getEmojiByCountry)(country) : null;
|
|
54
|
+
var strangerLabel = country === 'foreign' ? t('country.foreign') : null;
|
|
55
55
|
return emojiCountry || strangerLabel ? "".concat(t(label, newOpts), " ").concat(emojiCountry || strangerLabel) : t(label, newOpts);
|
|
56
56
|
};
|
|
57
57
|
};
|
|
@@ -20,16 +20,16 @@ describe('getBoundT', () => {
|
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
it.each`
|
|
23
|
-
translationKey | country
|
|
24
|
-
${'Scan.items.national_id_card'} | ${undefined}
|
|
25
|
-
${'Scan.items.national_id_card'} | ${'fr'}
|
|
26
|
-
${'Scan.items.national_id_card'} | ${'
|
|
27
|
-
${'Scan.items.national_id_card'} | ${'be'}
|
|
28
|
-
${'Scan.items.national_id_card'} | ${'be'}
|
|
29
|
-
${'Scan.items.national_id_card'} | ${'fr'}
|
|
30
|
-
${'Scan.items.national_id_card'} | ${'fr'}
|
|
31
|
-
${'Scan.items.national_id_card'} | ${undefined}
|
|
32
|
-
${'Scan.items.national_id_card'} | ${undefined}
|
|
23
|
+
translationKey | country | smart_count | lang | expected
|
|
24
|
+
${'Scan.items.national_id_card'} | ${undefined} | ${undefined} | ${'en'} | ${'ID card'}
|
|
25
|
+
${'Scan.items.national_id_card'} | ${'fr'} | ${undefined} | ${'en'} | ${'ID card 🇫🇷'}
|
|
26
|
+
${'Scan.items.national_id_card'} | ${'foreign'} | ${undefined} | ${'en'} | ${'ID card Foreign'}
|
|
27
|
+
${'Scan.items.national_id_card'} | ${'be'} | ${1} | ${'en'} | ${'ID card 🇧🇪'}
|
|
28
|
+
${'Scan.items.national_id_card'} | ${'be'} | ${2} | ${'en'} | ${'ID cards 🇧🇪'}
|
|
29
|
+
${'Scan.items.national_id_card'} | ${'fr'} | ${1} | ${'en'} | ${'ID card 🇫🇷'}
|
|
30
|
+
${'Scan.items.national_id_card'} | ${'fr'} | ${2} | ${'en'} | ${'ID cards 🇫🇷'}
|
|
31
|
+
${'Scan.items.national_id_card'} | ${undefined} | ${1} | ${'en'} | ${'ID card'}
|
|
32
|
+
${'Scan.items.national_id_card'} | ${undefined} | ${2} | ${'en'} | ${'ID cards'}
|
|
33
33
|
`(
|
|
34
34
|
'should test if the translation is suitable with the param country: $country and with the param smart_count: $smart_count',
|
|
35
35
|
({ translationKey, country, smart_count, lang, expected }) => {
|
package/dist/models/paper.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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.
|
|
3
|
+
"version": "47.2.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": "
|
|
78
|
+
"gitHead": "6e8e15ab4f4d7ee4a2a1ef52367f6fea9b41f9fe"
|
|
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 }?: {
|