Skip to content

Commit

Permalink
#964: define actual maxKeyLength per type
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Jun 6, 2023
1 parent 9ff3bc3 commit 3a2da96
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/metadataTypes/MetadataType.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ class MetadataType {
metadataMap[metadataKey][this.definition.keyField]
);
// Update if it already exists; Create it if not
const maxKeyLength = this.definition.maxKeyLength || 36;
if (
Util.logger.level === 'debug' &&
metadataMap[metadataKey][this.definition.idField] &&
Expand Down Expand Up @@ -709,11 +710,11 @@ class MetadataType {
// NOTE: trim twice while getting the newKey value to remove leading spaces before limiting the length
const newKey = (metadataMap[metadataKey][Util.OPTIONS.changeKeyField] + '')
.trim()
.slice(0, 36)
.slice(0, maxKeyLength)
.trim();
if (metadataMap[metadataKey][Util.OPTIONS.changeKeyField] + '' > 36) {
if (metadataMap[metadataKey][Util.OPTIONS.changeKeyField] + '' > maxKeyLength) {
Util.logger.warn(
`Customer Keys may not exceed 36 characters. Truncated the value in field ${Util.OPTIONS.changeKeyField} to ${newKey}`
`${this.definition.type} ${this.definition.keyField} may not exceed ${maxKeyLength} characters. Truncated the value in field ${Util.OPTIONS.changeKeyField} to ${newKey}`
);
}
if (metadataKey == newKey) {
Expand All @@ -733,10 +734,10 @@ class MetadataType {
}
} else if (Util.OPTIONS.changeKeyValue) {
// NOTE: trim twice while getting the newKey value to remove leading spaces before limiting the length
const newKey = Util.OPTIONS.changeKeyValue.trim().slice(0, 36).trim();
if (Util.OPTIONS.changeKeyValue.trim().length > 36) {
const newKey = Util.OPTIONS.changeKeyValue.trim().slice(0, maxKeyLength).trim();
if (Util.OPTIONS.changeKeyValue.trim().length > maxKeyLength) {
Util.logger.warn(
`Customer Keys may not exceed 36 characters. Truncated your value to ${newKey}`
`${this.definition.type} ${this.definition.keyField} may not exceed ${maxKeyLength} characters. Truncated your value to ${newKey}`
);
}
if (this.definition.keyField == this.definition.idField) {
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/Asset.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
lastmodDateField: 'modifiedDate',
lastmodNameField: 'modifiedBy.name',
restPagination: true,
maxKeyLength: 36, // confirmed max length
type: 'asset',
typeDescription: 'Assets from Content Builder grouped into subtypes.',
typeRetrieveByDefault: ['asset', 'code', 'textfile', 'block', 'message', 'template', 'other'],
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/Automation.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = {
lastmodDateField: 'lastSavedDate',
lastmodNameField: 'lastSavedByName',
restPagination: true,
maxKeyLength: 200, // confirmed max length
statusMapping: {
AwaitingTrigger: 7,
Building: 1,
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/DataExtension.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ module.exports = {
lastmodDateField: 'ModifiedDate',
lastmodNameField: null,
restPagination: false,
maxKeyLength: 200, // confirmed max length
type: 'dataExtension',
typeDescription: 'Database table schemas.',
typeRetrieveByDefault: true,
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/DataExtract.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
lastmodNameField: 'modifiedBy',
nameField: 'name',
restPagination: true,
maxKeyLength: 36, // confirmed max length
type: 'dataExtract',
typeDescription: 'Creates zipped files in your FTP directory or convert XML into CSV.',
typeRetrieveByDefault: true,
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/EmailSend.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
lastmodDateField: 'ModifiedDate',
lastmodNameField: null,
restPagination: null,
maxKeyLength: 36, // confirmed max length
type: 'emailSend',
soapType: 'emailSendDefinition',
typeDescription: 'Mainly used in Automations as "Send Email Activity".',
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/Event.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
lastmodDateField: 'modifiedDate',
lastmodNameField: 'modifiedBy',
restPagination: true,
maxKeyLength: 200, // confirmed max length
type: 'event',
typeDescription: 'Used in Journeys (Interactions) to define Entry Events.',
typeRetrieveByDefault: true,
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/Filter.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
lastmodDateField: 'modifiedDate',
lastmodNameField: null,
restPagination: true,
maxKeyLength: 36, // confirmed max length
type: 'filter',
typeDescription:
'BETA: Part of how filtered Data Extensions are created. Depends on type "FilterDefinitions".',
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/ImportFile.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
DataExtension: 255,
Email: 0,
},
maxKeyLength: 36, // confirmed max length
type: 'importFile',
typeDescription: 'Reads files in FTP directory for further processing.',
typeRetrieveByDefault: true,
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/MobileKeyword.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
lastmodNameField: null,
restPagination: true,
restPageSize: 50,
maxKeyLength: 50, // assumed max length
type: 'mobileKeyword',
typeDescription: 'Used for managing subscriptions for Mobile numbers in Mobile Connect',
typeRetrieveByDefault: true,
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/Query.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
Overwrite: 0,
Update: 1,
},
maxKeyLength: 36, // confirmed max length
type: 'query',
typeDescription: 'Select & transform data using SQL.',
typeRetrieveByDefault: true,
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/Role.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
createdNameField: null,
lastmodDateField: 'ModifiedDate',
lastmodNameField: null,
maxKeyLength: 36, // confirmed max length
type: 'role',
typeDescription:
'User Roles define groups that are used to grant users access to SFMC systems.',
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/TriggeredSend.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
lastmodDateField: 'ModifiedDate',
lastmodNameField: null,
restPagination: null,
maxKeyLength: 36, // confirmed max length
type: 'triggeredSend',
soapType: 'triggeredSendDefinition',
typeDescription: 'DEPRECATED: Sends emails via API or DataExtension Event.',
Expand Down
1 change: 1 addition & 0 deletions lib/metadataTypes/definitions/User.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
createdNameField: null,
lastmodDateField: 'ModifiedDate',
lastmodNameField: 'Client.ModifiedBy',
maxKeyLength: 50, // confirmed max length
type: 'user',
soapType: 'AccountUser',
typeDescription: 'Marketing Cloud users',
Expand Down

0 comments on commit 3a2da96

Please sign in to comment.