Skip to content

Commit

Permalink
#58: normalize cross-type references with r__ for importFile
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed May 21, 2024
1 parent 94e1cb1 commit a76e055
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
31 changes: 25 additions & 6 deletions lib/metadataTypes/ImportFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,27 @@ class ImportFile extends MetadataType {
break;
}
case 'SMS': {
if (metadata.destination.c__codeKeyword) {
if (metadata.destination.r__mobileKeyword_c__codeKeyword) {
// code
const codeObj = cache.getByKey(
'mobileCode',
metadata.destination.c__codeKeyword.split('.')[0]
metadata.destination.r__mobileKeyword_c__codeKeyword.split('.')[0]
);
if (!codeObj) {
throw new Error(
`mobileCode ${metadata.destination.c__codeKeyword} not found in cache`
`mobileCode ${metadata.destination.r__mobileKeyword_c__codeKeyword} not found in cache`
);
}
metadata.code = codeObj;

// keyword
const keywordObj = cache.getByKey(
'mobileKeyword',
metadata.destination.c__codeKeyword
metadata.destination.r__mobileKeyword_c__codeKeyword
);
if (!keywordObj) {
throw new Error(
`mobileKeyword ${metadata.destination.c__codeKeyword} not found in cache`
`mobileKeyword ${metadata.destination.r__mobileKeyword_c__codeKeyword} not found in cache`
);
}
metadata.keyword = keywordObj;
Expand Down Expand Up @@ -398,8 +398,27 @@ class ImportFile extends MetadataType {
case 'SMS': {
if (this.smsImports[metadata.name]) {
const smsImport = this.smsImports[metadata.name];

// code
try {
cache.searchForField('mobileCode', smsImport.code?.code, 'code', 'code');
} catch (ex) {
Util.logger.warn(` - ImportFile ${metadata.customerKey}: ${ex.message}`);
}
// keyword
try {
cache.searchForField(
'mobileKeyword',
smsImport.keyword?.keyword,
'c__codeKeyword',
'c__codeKeyword'
);
} catch (ex) {
Util.logger.warn(` - ImportFile ${metadata.customerKey}: ${ex.message}`);
}

// code + keyword
metadata.destination.c__codeKeyword =
metadata.destination.r__mobileKeyword_c__codeKeyword =
smsImport.code?.code + '.' + smsImport.keyword?.keyword;
// source dataExtension
if (smsImport.sourceObjectKey) {
Expand Down
2 changes: 1 addition & 1 deletion lib/metadataTypes/definitions/ImportFile.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default {
retrieving: true,
template: true,
},
'destination.c__codeKeyword': {
'destination.r__mobileKeyword_c__codeKeyword': {
isCreateable: false,
isUpdateable: false,
retrieving: true,
Expand Down
2 changes: 1 addition & 1 deletion test/resources/9999999/importFile/get-sms-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"standardQuotedStrings": false,
"destination": {
"c__destinationType": "SMS",
"c__codeKeyword": "4912312345678.TESTEXISTING_KEYWORD"
"r__mobileKeyword_c__codeKeyword": "4912312345678.TESTEXISTING_KEYWORD"
},
"source": {
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
Expand Down

0 comments on commit a76e055

Please sign in to comment.