cozy-client 46.2.0 → 46.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.
@@ -2705,7 +2705,7 @@ var CozyClient = /*#__PURE__*/function () {
2705
2705
  CozyClient.hooks = CozyClient.hooks || {};
2706
2706
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2707
2707
 
2708
- CozyClient.version = "46.2.0";
2708
+ CozyClient.version = "46.3.0";
2709
2709
 
2710
2710
  _microee.default.mixin(CozyClient);
2711
2711
 
@@ -14,6 +14,10 @@ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
14
14
  var _logger = _interopRequireDefault(require("../logger"));
15
15
 
16
16
  var CONTACTS_DOCTYPE = 'io.cozy.contacts';
17
+ /**
18
+ * @typedef {'namePrefix'|'givenName'|'additionalName'|'familyName'|'nameSuffix'} FullnameAttributes
19
+ */
20
+
17
21
  exports.CONTACTS_DOCTYPE = CONTACTS_DOCTYPE;
18
22
 
19
23
  var getPrimaryOrFirst = function getPrimaryOrFirst(property) {
@@ -124,19 +128,26 @@ exports.getPrimaryPhone = getPrimaryPhone;
124
128
  var getPrimaryAddress = function getPrimaryAddress(contact) {
125
129
  return getPrimaryOrFirst('address')(contact).formattedAddress || '';
126
130
  };
131
+ /**
132
+ * @type {FullnameAttributes[]}
133
+ */
134
+
135
+
136
+ exports.getPrimaryAddress = getPrimaryAddress;
137
+ var defaultFullnameAttributes = ['namePrefix', 'givenName', 'additionalName', 'familyName', 'nameSuffix'];
127
138
  /**
128
139
  * Makes fullname from contact name
129
140
  *
130
- * @param {*} contact - A contact
141
+ * @param {object} contact - A contact
142
+ * @param {{ attributesFullname: FullnameAttributes[] }} [opts] - Options
131
143
  * @returns {string} - The contact's fullname
132
144
  */
133
145
 
146
+ var makeFullname = function makeFullname(contact, opts) {
147
+ var fullnameAttributes = (opts === null || opts === void 0 ? void 0 : opts.attributesFullname) || defaultFullnameAttributes;
134
148
 
135
- exports.getPrimaryAddress = getPrimaryAddress;
136
-
137
- var makeFullname = function makeFullname(contact) {
138
149
  if (contact.name) {
139
- return ['namePrefix', 'givenName', 'additionalName', 'familyName', 'nameSuffix'].map(function (part) {
150
+ return fullnameAttributes.map(function (part) {
140
151
  return contact.name[part];
141
152
  }).filter(function (part) {
142
153
  return part !== undefined;
@@ -166,14 +177,15 @@ var getFullname = function getFullname(contact) {
166
177
  * Makes displayName from contact data
167
178
  *
168
179
  * @param {*} contact - A contact
180
+ * @param {{ attributesFullname: FullnameAttributes[] }} [opts] - Options
169
181
  * @returns {string} - The contact's displayName
170
182
  */
171
183
 
172
184
 
173
185
  exports.getFullname = getFullname;
174
186
 
175
- var makeDisplayName = function makeDisplayName(contact) {
176
- var fullname = makeFullname(contact);
187
+ var makeDisplayName = function makeDisplayName(contact, opts) {
188
+ var fullname = makeFullname(contact, opts);
177
189
  var primaryEmail = getPrimaryEmail(contact);
178
190
  var primaryCozyDomain = getPrimaryCozyDomain(contact);
179
191
 
@@ -247,6 +247,22 @@ describe('makeFullname', () => {
247
247
  )
248
248
  })
249
249
 
250
+ it('should combine all name parts passed as options', () => {
251
+ const contact = {
252
+ name: {
253
+ namePrefix: 'The Mother of Dragons',
254
+ givenName: 'Daenerys',
255
+ additionalName: 'The Unburnt',
256
+ familyName: 'Targaryen',
257
+ nameSuffix: 'Breaker of Chains'
258
+ }
259
+ }
260
+ const result = makeFullname(contact, {
261
+ attributesFullname: ['givenName', 'additionalName', 'familyName']
262
+ })
263
+ expect(result).toEqual('Daenerys The Unburnt Targaryen')
264
+ })
265
+
250
266
  it("should return contact's givenName if no familyName", () => {
251
267
  const contact = {
252
268
  name: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "46.2.0",
3
+ "version": "46.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": "e355e47c34cce739a12e046682df2aef47721de8"
78
+ "gitHead": "c696c81b4c3c4831a4d5acb9826bee65963848fa"
79
79
  }
@@ -6,11 +6,16 @@ export function getPrimaryCozy(contact: object): string;
6
6
  export function getPrimaryCozyDomain(contact: object): string;
7
7
  export function getPrimaryPhone(contact: object): string;
8
8
  export function getPrimaryAddress(contact: object): string;
9
- export function makeFullname(contact: any): string;
9
+ export function makeFullname(contact: object, opts?: {
10
+ attributesFullname: FullnameAttributes[];
11
+ }): string;
10
12
  export function getFullname(contact: object): string;
11
- export function makeDisplayName(contact: any): string;
13
+ export function makeDisplayName(contact: any, opts?: {
14
+ attributesFullname: FullnameAttributes[];
15
+ }): string;
12
16
  export function getDisplayName(contact: object): string;
13
17
  export function makeDefaultSortIndexValue(contact: object): string;
14
18
  export function getDefaultSortIndexValue(contact: object): string;
15
19
  export function getIndexByFamilyNameGivenNameEmailCozyUrl(contact: object): string;
16
20
  export function isContact(doc: object): boolean;
21
+ export type FullnameAttributes = "namePrefix" | "givenName" | "additionalName" | "familyName" | "nameSuffix";