cozy-client 60.3.0 → 60.5.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 +80 -2
- package/dist/models/contact.spec.js +114 -0
- package/package.json +2 -2
- package/types/models/contact.d.ts +3 -0
package/dist/CozyClient.js
CHANGED
|
@@ -3126,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3126
3126
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
3127
3127
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
3128
3128
|
|
|
3129
|
-
CozyClient.version = "60.
|
|
3129
|
+
CozyClient.version = "60.5.0";
|
|
3130
3130
|
|
|
3131
3131
|
_microee.default.mixin(CozyClient);
|
|
3132
3132
|
|
package/dist/models/contact.js
CHANGED
|
@@ -5,7 +5,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.isContact = exports.getIndexByFamilyNameGivenNameEmailCozyUrl = exports.getDefaultSortIndexValue = exports.makeDefaultSortIndexValue = exports.getDisplayName = exports.makeDisplayName = exports.getFullname = exports.makeFullname = exports.getPrimaryAddress = exports.getPrimaryPhone = exports.getPrimaryCozyDomain = exports.getPrimaryCozy = exports.getPrimaryEmail = exports.getInitials = exports.getPrimaryOrFirst = exports.CONTACTS_DOCTYPE = void 0;
|
|
8
|
+
exports.updateIndexFullNameAndDisplayName = exports.getFormattedAddress = exports.cleanFormattedAddress = exports.isContact = exports.getIndexByFamilyNameGivenNameEmailCozyUrl = exports.getDefaultSortIndexValue = exports.makeDefaultSortIndexValue = exports.getDisplayName = exports.makeDisplayName = exports.getFullname = exports.makeFullname = exports.getPrimaryAddress = exports.getPrimaryPhone = exports.getPrimaryCozyDomain = exports.getPrimaryCozy = exports.getPrimaryEmail = exports.getInitials = exports.getPrimaryOrFirst = exports.CONTACTS_DOCTYPE = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
11
|
|
|
10
12
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
11
13
|
|
|
@@ -13,6 +15,10 @@ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
|
13
15
|
|
|
14
16
|
var _logger = _interopRequireDefault(require("../logger"));
|
|
15
17
|
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
16
22
|
var CONTACTS_DOCTYPE = 'io.cozy.contacts';
|
|
17
23
|
/**
|
|
18
24
|
* @typedef {'namePrefix'|'givenName'|'additionalName'|'familyName'|'nameSuffix'} FullnameAttributes
|
|
@@ -289,5 +295,77 @@ exports.getIndexByFamilyNameGivenNameEmailCozyUrl = getIndexByFamilyNameGivenNam
|
|
|
289
295
|
var isContact = function isContact(doc) {
|
|
290
296
|
return doc._type === CONTACTS_DOCTYPE;
|
|
291
297
|
};
|
|
298
|
+
/**
|
|
299
|
+
* Removed unwanted characters on contact's formatted address
|
|
300
|
+
*
|
|
301
|
+
* @param {string} formattedAddress - The contact's formatted address
|
|
302
|
+
* @returns {string}
|
|
303
|
+
*/
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
exports.isContact = isContact;
|
|
307
|
+
|
|
308
|
+
var cleanFormattedAddress = function cleanFormattedAddress(formattedAddress) {
|
|
309
|
+
// Replace all spaces by one space, to fix cases where there are multiple spaces
|
|
310
|
+
// Replace commas that have a space before
|
|
311
|
+
// And remove all spaces before & after the string
|
|
312
|
+
var formattedAddressClean = formattedAddress.replace(/\s+/g, ' ').replace(/\s,/g, '').trim(); // Case where a comma is the last character
|
|
313
|
+
|
|
314
|
+
if (formattedAddressClean.lastIndexOf(',') === formattedAddressClean.length - 1) {
|
|
315
|
+
formattedAddressClean = formattedAddressClean.slice(0, formattedAddressClean.length - 1);
|
|
316
|
+
} // Case where a comma is the first character
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
if (formattedAddressClean.indexOf(',') === 0) {
|
|
320
|
+
formattedAddressClean = formattedAddressClean.slice(1);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return formattedAddressClean;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Returns the contact's formatted address
|
|
327
|
+
*
|
|
328
|
+
* @param {object} address - A contact address
|
|
329
|
+
* @param {function} t - Translate function
|
|
330
|
+
* @returns {string} - The contact's formatted address
|
|
331
|
+
*/
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
exports.cleanFormattedAddress = cleanFormattedAddress;
|
|
335
|
+
|
|
336
|
+
var getFormattedAddress = function getFormattedAddress(address, t) {
|
|
337
|
+
if (address && address.formattedAddress) {
|
|
338
|
+
return address.formattedAddress;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
var unformattedAddress = {
|
|
342
|
+
number: address.number || '',
|
|
343
|
+
street: address.street || '',
|
|
344
|
+
code: address.postcode || '',
|
|
345
|
+
city: address.city || '',
|
|
346
|
+
region: address.region || '',
|
|
347
|
+
country: address.country || ''
|
|
348
|
+
};
|
|
349
|
+
return cleanFormattedAddress(t('formatted.address', unformattedAddress));
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Update fullname, displayName and Index values of a contact
|
|
353
|
+
*
|
|
354
|
+
* @param {object} contact - an io.cozy.contact document
|
|
355
|
+
* @returns {object} an io.cozy.contact document
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
exports.getFormattedAddress = getFormattedAddress;
|
|
360
|
+
|
|
361
|
+
var updateIndexFullNameAndDisplayName = function updateIndexFullNameAndDisplayName(contact) {
|
|
362
|
+
return _objectSpread(_objectSpread({}, contact), {}, {
|
|
363
|
+
fullname: makeFullname(contact),
|
|
364
|
+
displayName: makeDisplayName(contact),
|
|
365
|
+
indexes: {
|
|
366
|
+
byFamilyNameGivenNameEmailCozyUrl: makeDefaultSortIndexValue(contact)
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
};
|
|
292
370
|
|
|
293
|
-
exports.
|
|
371
|
+
exports.updateIndexFullNameAndDisplayName = updateIndexFullNameAndDisplayName;
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
getPrimaryCozyDomain,
|
|
12
12
|
makeFullname,
|
|
13
13
|
makeDisplayName,
|
|
14
|
+
getFormattedAddress,
|
|
15
|
+
updateIndexFullNameAndDisplayName,
|
|
14
16
|
makeDefaultSortIndexValue
|
|
15
17
|
} from './contact'
|
|
16
18
|
|
|
@@ -715,3 +717,115 @@ describe('getPrimaryCozyDomain', () => {
|
|
|
715
717
|
expect(result).toEqual(expected)
|
|
716
718
|
})
|
|
717
719
|
})
|
|
720
|
+
|
|
721
|
+
describe('getFormattedAddress', () => {
|
|
722
|
+
describe('with connector address format', () => {
|
|
723
|
+
it('should return full formatted address', () => {
|
|
724
|
+
const addressMock = {
|
|
725
|
+
city: 'Cambridge',
|
|
726
|
+
country: 'Russian Federation',
|
|
727
|
+
postcode: '16862',
|
|
728
|
+
street: '38 Taylor Street'
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const res = getFormattedAddress(
|
|
732
|
+
addressMock,
|
|
733
|
+
jest.fn(() => '38 Taylor Street, 16862 Cambridge, Russian Federation')
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
expect(res).toBe('38 Taylor Street, 16862 Cambridge, Russian Federation')
|
|
737
|
+
})
|
|
738
|
+
it('should return formatted address if only "postcode" & "city" values are defined', () => {
|
|
739
|
+
const addressMock = {
|
|
740
|
+
city: 'Cambridge',
|
|
741
|
+
country: undefined,
|
|
742
|
+
postcode: '16862',
|
|
743
|
+
street: undefined
|
|
744
|
+
}
|
|
745
|
+
const res = getFormattedAddress(
|
|
746
|
+
addressMock,
|
|
747
|
+
jest.fn(() => ' , 16862 Cambridge, ')
|
|
748
|
+
)
|
|
749
|
+
|
|
750
|
+
expect(res).toBe('16862 Cambridge')
|
|
751
|
+
})
|
|
752
|
+
it('should return formatted address if "postcode" & "city" values are undefined', () => {
|
|
753
|
+
const addressMock = {
|
|
754
|
+
city: 'Cambridge',
|
|
755
|
+
country: undefined,
|
|
756
|
+
postcode: undefined,
|
|
757
|
+
street: '38 Taylor Street'
|
|
758
|
+
}
|
|
759
|
+
const res = getFormattedAddress(
|
|
760
|
+
addressMock,
|
|
761
|
+
jest.fn(() => '38 Taylor Street, , Cambridge')
|
|
762
|
+
)
|
|
763
|
+
|
|
764
|
+
expect(res).toBe('38 Taylor Street, Cambridge')
|
|
765
|
+
})
|
|
766
|
+
it('should return formatted address if "postcode" & "city" values are undefined', () => {
|
|
767
|
+
const addressMock = {
|
|
768
|
+
city: undefined,
|
|
769
|
+
country: undefined,
|
|
770
|
+
postcode: undefined,
|
|
771
|
+
street: undefined
|
|
772
|
+
}
|
|
773
|
+
const res = getFormattedAddress(addressMock, jest.fn(() => ' , , '))
|
|
774
|
+
|
|
775
|
+
expect(res).toBe('')
|
|
776
|
+
})
|
|
777
|
+
})
|
|
778
|
+
|
|
779
|
+
describe('with manual address format', () => {
|
|
780
|
+
it('should return full formatted address', () => {
|
|
781
|
+
const addressMock = {
|
|
782
|
+
formattedAddress: '38 Taylor Street 16862 Cambridge Russian Federation'
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
const res = getFormattedAddress(addressMock, jest.fn(() => ''))
|
|
786
|
+
|
|
787
|
+
expect(res).toBe('38 Taylor Street 16862 Cambridge Russian Federation')
|
|
788
|
+
})
|
|
789
|
+
})
|
|
790
|
+
})
|
|
791
|
+
|
|
792
|
+
describe('updateIndexFullNameAndDisplayName', () => {
|
|
793
|
+
it('should returns a contact with new attributes', () => {
|
|
794
|
+
const contact = {
|
|
795
|
+
name: {
|
|
796
|
+
givenName: 'John',
|
|
797
|
+
familyName: 'Doe',
|
|
798
|
+
additionalName: 'J.'
|
|
799
|
+
},
|
|
800
|
+
email: [
|
|
801
|
+
{
|
|
802
|
+
address: 'john.doe@posteo.net',
|
|
803
|
+
type: 'personal',
|
|
804
|
+
primary: false
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
address: 'john.doe@cozycloud.cc',
|
|
808
|
+
primary: true
|
|
809
|
+
}
|
|
810
|
+
],
|
|
811
|
+
cozy: [
|
|
812
|
+
{
|
|
813
|
+
type: 'MyCozy',
|
|
814
|
+
primary: true,
|
|
815
|
+
url: 'https://johndoe.mycozy.cloud'
|
|
816
|
+
}
|
|
817
|
+
]
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const expected = {
|
|
821
|
+
...contact,
|
|
822
|
+
displayName: 'John J. Doe',
|
|
823
|
+
fullname: 'John J. Doe',
|
|
824
|
+
indexes: {
|
|
825
|
+
byFamilyNameGivenNameEmailCozyUrl:
|
|
826
|
+
'doejohnjohn.doe@cozycloud.ccjohndoe.mycozy.cloud'
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
expect(updateIndexFullNameAndDisplayName(contact)).toEqual(expected)
|
|
830
|
+
})
|
|
831
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-native-ios11-devicecheck": "^0.0.3"
|
|
75
75
|
},
|
|
76
76
|
"sideEffects": false,
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "d26e07930ac302bdabbfe968f523f9e03582ae92"
|
|
78
78
|
}
|
|
@@ -18,4 +18,7 @@ export function makeDefaultSortIndexValue(contact: import('../types').IOCozyCont
|
|
|
18
18
|
export function getDefaultSortIndexValue(contact: import('../types').IOCozyContact): string;
|
|
19
19
|
export function getIndexByFamilyNameGivenNameEmailCozyUrl(contact: import('../types').IOCozyContact): string;
|
|
20
20
|
export function isContact(doc: object): boolean;
|
|
21
|
+
export function cleanFormattedAddress(formattedAddress: string): string;
|
|
22
|
+
export function getFormattedAddress(address: object, t: Function): string;
|
|
23
|
+
export function updateIndexFullNameAndDisplayName(contact: object): object;
|
|
21
24
|
export type FullnameAttributes = "namePrefix" | "givenName" | "additionalName" | "familyName" | "nameSuffix";
|