cozy-client 46.10.0 → 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.
- package/dist/CozyClient.js +1 -1
- package/dist/models/contact.js +1 -1
- package/dist/models/contact.spec.js +36 -0
- package/dist/models/document/emojiCountry.js +23 -8
- package/dist/models/document/emojiCountry.spec.js +21 -13
- package/dist/models/document/locales/index.js +4 -2
- package/dist/models/document/locales/index.spec.js +2 -0
- package/package.json +2 -2
- package/types/models/document/emojiCountry.d.ts +1 -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 = "46.
|
|
2785
|
+
CozyClient.version = "46.11.0";
|
|
2786
2786
|
|
|
2787
2787
|
_microee.default.mixin(CozyClient);
|
|
2788
2788
|
|
package/dist/models/contact.js
CHANGED
|
@@ -22,7 +22,7 @@ exports.CONTACTS_DOCTYPE = CONTACTS_DOCTYPE;
|
|
|
22
22
|
|
|
23
23
|
var getPrimaryOrFirst = function getPrimaryOrFirst(property) {
|
|
24
24
|
return function (obj) {
|
|
25
|
-
return !obj[property] || obj[property].length === 0 ? '' : obj[property].find(function (property) {
|
|
25
|
+
return !obj || !obj[property] || obj[property].length === 0 || !obj[property][0] ? '' : obj[property].find(function (property) {
|
|
26
26
|
return property.primary;
|
|
27
27
|
}) || obj[property][0];
|
|
28
28
|
};
|
|
@@ -15,6 +15,12 @@ import {
|
|
|
15
15
|
} from './contact'
|
|
16
16
|
|
|
17
17
|
describe('getPrimaryOrFirst', () => {
|
|
18
|
+
it('should not crash if array is undefined, or contents null/undefined', () => {
|
|
19
|
+
expect(getPrimaryOrFirst('email')({ email: undefined })).toEqual('')
|
|
20
|
+
expect(getPrimaryOrFirst('email')({ email: [null] })).toEqual('')
|
|
21
|
+
expect(getPrimaryOrFirst('email')({ email: [undefined] })).toEqual('')
|
|
22
|
+
})
|
|
23
|
+
|
|
18
24
|
it("should return the first contact's email address if no primary", () => {
|
|
19
25
|
const contact = {
|
|
20
26
|
email: [
|
|
@@ -136,6 +142,12 @@ describe('getInitials', () => {
|
|
|
136
142
|
})
|
|
137
143
|
|
|
138
144
|
describe('getPrimaryCozy', () => {
|
|
145
|
+
it('should not crash if array is undefined, or contents null/undefined', () => {
|
|
146
|
+
expect(getPrimaryCozy({ cozy: undefined })).toEqual(undefined)
|
|
147
|
+
expect(getPrimaryCozy({ cozy: [null] })).toEqual('')
|
|
148
|
+
expect(getPrimaryCozy({ cozy: [undefined] })).toEqual('')
|
|
149
|
+
})
|
|
150
|
+
|
|
139
151
|
it('should return the main cozy', () => {
|
|
140
152
|
const contact = {
|
|
141
153
|
cozy: [
|
|
@@ -178,6 +190,12 @@ describe('getPrimaryCozy', () => {
|
|
|
178
190
|
})
|
|
179
191
|
|
|
180
192
|
describe('getPrimaryPhone', () => {
|
|
193
|
+
it('should not crash if array is undefined, or contents null/undefined', () => {
|
|
194
|
+
expect(getPrimaryPhone({ phone: undefined })).toEqual('')
|
|
195
|
+
expect(getPrimaryPhone({ phone: [null] })).toEqual('')
|
|
196
|
+
expect(getPrimaryPhone({ phone: [undefined] })).toEqual('')
|
|
197
|
+
})
|
|
198
|
+
|
|
181
199
|
it('should return the main phone number', () => {
|
|
182
200
|
const contact = {
|
|
183
201
|
phone: [
|
|
@@ -192,6 +210,12 @@ describe('getPrimaryPhone', () => {
|
|
|
192
210
|
})
|
|
193
211
|
|
|
194
212
|
describe('getPrimaryAddress', () => {
|
|
213
|
+
it('should not crash if array is undefined, or contents null/undefined', () => {
|
|
214
|
+
expect(getPrimaryAddress({ address: undefined })).toEqual('')
|
|
215
|
+
expect(getPrimaryAddress({ address: [null] })).toEqual('')
|
|
216
|
+
expect(getPrimaryAddress({ address: [undefined] })).toEqual('')
|
|
217
|
+
})
|
|
218
|
+
|
|
195
219
|
it('should return the main address', () => {
|
|
196
220
|
const contact = {
|
|
197
221
|
name: {
|
|
@@ -438,6 +462,12 @@ describe('makeDisplayName', () => {
|
|
|
438
462
|
})
|
|
439
463
|
|
|
440
464
|
describe('getPrimaryEmail', () => {
|
|
465
|
+
it('should not crash if array is undefined, or contents null/undefined', () => {
|
|
466
|
+
expect(getPrimaryEmail({ email: undefined })).toEqual(undefined)
|
|
467
|
+
expect(getPrimaryEmail({ email: [null] })).toEqual('')
|
|
468
|
+
expect(getPrimaryEmail({ email: [undefined] })).toEqual('')
|
|
469
|
+
})
|
|
470
|
+
|
|
441
471
|
it('should return the main email', () => {
|
|
442
472
|
const contact = {
|
|
443
473
|
email: [
|
|
@@ -609,6 +639,12 @@ describe('makeDefaultSortIndexValue', () => {
|
|
|
609
639
|
})
|
|
610
640
|
|
|
611
641
|
describe('getPrimaryCozyDomain', () => {
|
|
642
|
+
it('should not crash if array is undefined, or contents null/undefined', () => {
|
|
643
|
+
expect(getPrimaryCozyDomain({ cozy: undefined })).toEqual(undefined)
|
|
644
|
+
expect(getPrimaryCozyDomain({ cozy: [null] })).toEqual('')
|
|
645
|
+
expect(getPrimaryCozyDomain({ cozy: [undefined] })).toEqual('')
|
|
646
|
+
})
|
|
647
|
+
|
|
612
648
|
it('should returns empty string if no cozy url', () => {
|
|
613
649
|
const contact = {
|
|
614
650
|
cozy: [{ url: '' }]
|
|
@@ -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
|
-
|
|
8
|
-
|
|
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}
|
|
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(
|
|
17
|
-
if (
|
|
18
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
11
|
-
const
|
|
12
|
-
const res = getEmojiByCountry('stranger', mockT)
|
|
17
|
+
it('should return Belgian flag', () => {
|
|
18
|
+
const res = getEmojiByCountry('be')
|
|
13
19
|
|
|
14
|
-
expect(res).toBe('
|
|
20
|
+
expect(res).toBe('🇧🇪')
|
|
15
21
|
})
|
|
16
|
-
it('should return "
|
|
17
|
-
const res = getEmojiByCountry('
|
|
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(
|
|
25
|
+
expect(logger.error).toHaveBeenCalledTimes(1)
|
|
26
|
+
expect(res).toBe(null)
|
|
20
27
|
})
|
|
21
|
-
it('should return "
|
|
22
|
-
const res = getEmojiByCountry(undefined
|
|
28
|
+
it('should return "null" if the country is undefined', () => {
|
|
29
|
+
const res = getEmojiByCountry(undefined)
|
|
23
30
|
|
|
24
|
-
expect(
|
|
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
|
|
53
|
-
|
|
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.
|
|
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": "
|
|
78
|
+
"gitHead": "c3881442529ce33d979fdc8a90396b6d68f507d7"
|
|
79
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function getEmojiByCountry(
|
|
1
|
+
export function getEmojiByCountry(countryCode: string): string;
|