diff --git a/lib/metadataTypes/Role.js b/lib/metadataTypes/Role.js index e08cf34b8..4d3f6175c 100644 --- a/lib/metadataTypes/Role.js +++ b/lib/metadataTypes/Role.js @@ -4,6 +4,7 @@ const TYPE = require('../../types/mcdev.d'); const MetadataType = require('./MetadataType'); const Util = require('../util/util'); const File = require('../util/file'); +const cache = require('../util/cache'); /** * ImportFile MetadataType @@ -62,7 +63,9 @@ class Role extends MetadataType { const parsed = this.parseResponseBody(results); if (!retrieveDir) { // retrieve "Marketing Cloud%" roles not returned by SOAP API - const { roles } = await this.client.rest.get('/platform/v1/setup/quickflow/data'); + const { roles, languages, timeZones } = await this.client.rest.get( + '/platform/v1/setup/quickflow/data' + ); // this endpoint does not provide keys const roleNameKeyMap = { 'Marketing Cloud Administrator': 'SYS_DEF_IMHADMIN', @@ -84,6 +87,19 @@ class Role extends MetadataType { }; } } + // convert languages to object + const languagesObj = {}; + for (const language of languages) { + languagesObj[language.Key] = language; + } + // convert timeZones to object + const timeZonesObj = {}; + for (const timeZone of timeZones) { + timeZonesObj[timeZone.id] = timeZone; + } + // cache languages and timeZones to share it with other type-classes + cache.setMetadata('_language', languagesObj); + cache.setMetadata('_timezone', timeZonesObj); } if (retrieveDir) { const savedMetadata = await super.saveResults(parsed, retrieveDir, null); diff --git a/lib/metadataTypes/User.js b/lib/metadataTypes/User.js index 9f0075d1b..a6b9bd092 100644 --- a/lib/metadataTypes/User.js +++ b/lib/metadataTypes/User.js @@ -123,6 +123,27 @@ class User extends MetadataType { metadata.c__AssociatedBusinessUnits = [...new Set(metadata.c__AssociatedBusinessUnits)]; } + // Timezone + if (metadata.c__TimeZoneName) { + // find the ID of the timezone + metadata.TimeZone = { Name: metadata.c__TimeZoneName }; + metadata.TimeZone.ID = cache.searchForField( + '_timezone', + metadata.c__TimeZoneName, + 'description', + 'id' + ); + delete metadata.c__TimeZoneName; + } + + // Locale + if (metadata.c__LocaleCode) { + // confirm it's a valid locale + cache.getByKey('_language', metadata.c__LocaleCode); + metadata.Locale = { LocaleCode: metadata.c__LocaleCode }; + delete metadata.c__LocaleCode; + } + // convert SSO / Federation Token into API compliant format if (metadata.SsoIdentity || metadata.SsoIdentities) { const ssoIdentity = {}; @@ -1056,6 +1077,23 @@ class User extends MetadataType { metadata.c__RoleNamesGlobal = roles; delete metadata.Roles; + // Timezone + if (metadata.TimeZone?.ID) { + metadata.c__TimeZoneName = cache.searchForField( + '_timezone', + metadata.TimeZone.ID, + 'id', + 'description' + ); + delete metadata.TimeZone; + } + + // Locale + if (metadata.Locale?.LocaleCode) { + metadata.c__LocaleCode = metadata.Locale.LocaleCode; + delete metadata.Locale; + } + return metadata; } } diff --git a/lib/metadataTypes/definitions/User.definition.js b/lib/metadataTypes/definitions/User.definition.js index f142b1149..d7df58de1 100644 --- a/lib/metadataTypes/definitions/User.definition.js +++ b/lib/metadataTypes/definitions/User.definition.js @@ -82,8 +82,8 @@ module.exports = { ID: { isCreateable: false, isUpdateable: false, retrieving: false, template: false }, IsAPIUser: { isCreateable: true, isUpdateable: true, retrieving: true, template: true }, IsLocked: { isCreateable: null, isUpdateable: null, retrieving: true, template: true }, - LanguageLocale: { - // not supported by API + 'LanguageLocale.LocaleCode': { + // seems to always return en-US isCreateable: false, isUpdateable: false, retrieving: false, @@ -95,8 +95,19 @@ module.exports = { retrieving: true, template: false, }, - Locale: { - // not supported by API + 'Locale.LocaleCode': { + isCreateable: true, + isUpdateable: true, + retrieving: true, + template: true, + }, + 'Locale.ObjectID': { + isCreateable: false, + isUpdateable: false, + retrieving: false, + template: false, + }, + 'Locale.PartnerKey': { isCreateable: false, isUpdateable: false, retrieving: false, @@ -163,8 +174,25 @@ module.exports = { retrieving: false, template: false, }, - TimeZone: { - // not supported by API + 'TimeZone.ID': { + isCreateable: true, + isUpdateable: true, + retrieving: true, + template: false, + }, + 'TimeZone.Name': { + isCreateable: true, + isUpdateable: true, + retrieving: true, + template: true, + }, + 'TimeZone.ObjectID': { + isCreateable: false, + isUpdateable: false, + retrieving: false, + template: false, + }, + 'TimeZone.PartnerKey': { isCreateable: false, isUpdateable: false, retrieving: false, @@ -266,5 +294,11 @@ module.exports = { c__RoleNamesGlobal: { skipValidation: true, }, + c__LocaleCode: { + skipValidation: true, + }, + c__TimeZoneName: { + skipValidation: true, + }, }, };