Skip to content

Commit

Permalink
#58: normalize cross-type references with r__ for transactionalPush
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed May 17, 2024
1 parent 6c7d623 commit cdde4fd
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
11 changes: 7 additions & 4 deletions lib/metadataTypes/TransactionalPush.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ class TransactionalPush extends TransactionalMessage {
*/
static async preDeployTasks(metadata) {
// asset
if (metadata.content?.customerKey) {
if (metadata.r__asset_customerKey) {
// we merely want to be able to show an error if it does not exist
cache.searchForField(
metadata.content ||= {};
metadata.content.customerKey = cache.searchForField(
'asset',
metadata.content.customerKey,
metadata.r__asset_customerKey,
'customerKey',
'customerKey'
);
delete metadata.r__asset_customerKey;
}
if (metadata.options?.badge && typeof metadata.options?.badge !== 'string') {
// ensure it's a string, or else the API will return an error. Our SDK turns numbers in strings into actual numbers
Expand All @@ -60,12 +62,13 @@ class TransactionalPush extends TransactionalMessage {
if (metadata.content?.customerKey) {
try {
// we merely want to be able to show an error if it does not exist
cache.searchForField(
metadata.r__asset_customerKey = cache.searchForField(
'asset',
metadata.content.customerKey,
'customerKey',
'customerKey'
);
delete metadata.content;
} catch (ex) {
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.nameField]} (${
Expand Down
6 changes: 6 additions & 0 deletions lib/metadataTypes/definitions/TransactionalPush.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export default {
retrieving: true,
template: true,
},
r__asset_customerKey: {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
'options.badge': {
isCreateable: true,
isUpdateable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"status": "Active",
"applicationId": "ffbab4c9-fbf6-4b87-9c9a-10c6ce86e81d",
"description": "updated via deploy; note that applicationId can only be manually set up in Setup - Mobile Push",
"content": {
"customerKey": "mobileMessage_test"
},
"r__asset_customerKey": "mobileMessage_test",
"options": {
"sound": "temp.wmv",
"badge": "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"status": "Active",
"applicationId": "ffbab4c9-fbf6-4b87-9c9a-10c6ce86e81d",
"description": "created on deploy; note that applicationId can only be manually set up in Setup - Mobile Push",
"content": {
"customerKey": "mobileMessage_test"
},
"r__asset_customerKey": "mobileMessage_test",
"options": {
"sound": "temp.wmv",
"badge": "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"definitionKey": "testTemplated_tpush",
"description": "foobar. note that applicationId can only be manually set up in Setup - Mobile Push",
"applicationId": "ffbab4c9-fbf6-4b87-9c9a-10c6ce86e81d",
"content": { "customerKey": "mobileMessage_testTarget" },
"r__asset_customerKey": "mobileMessage_testTarget",
"options": { "sound": "temp.wmv", "badge": "1" }
}
2 changes: 1 addition & 1 deletion test/resources/9999999/transactionalPush/get-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"status": "Active",
"createdDate": "2022-12-07T02:56:00",
"modifiedDate": "2022-12-07T02:56:00",
"content": { "customerKey": "mobileMessage_test" },
"r__asset_customerKey": "mobileMessage_test",
"options": { "sound": "temp.wmv", "badge": "1" }
}
4 changes: 1 addition & 3 deletions test/resources/9999999/transactionalPush/patch-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"description": "updated via deploy; note that applicationId can only be manually set up in Setup - Mobile Push",
"createdDate": "2022-12-07T02:56:00",
"modifiedDate": "2022-12-07T03:26:00",
"content": {
"customerKey": "mobileMessage_test"
},
"r__asset_customerKey": "mobileMessage_test",
"options": {
"sound": "temp.wmv",
"badge": "1"
Expand Down
4 changes: 1 addition & 3 deletions test/resources/9999999/transactionalPush/post-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"description": "created on deploy; note that applicationId can only be manually set up in Setup - Mobile Push",
"createdDate": "2022-12-07T02:56:00",
"modifiedDate": "2022-12-07T03:26:00",
"content": {
"customerKey": "mobileMessage_test"
},
"r__asset_customerKey": "mobileMessage_test",
"options": {
"sound": "temp.wmv",
"badge": "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"definitionKey": "{{{prefix}}}tpush",
"description": "{{{description}}}. note that applicationId can only be manually set up in Setup - Mobile Push",
"applicationId": "ffbab4c9-fbf6-4b87-9c9a-10c6ce86e81d",
"content": { "customerKey": "mobileMessage{{{suffix}}}" },
"r__asset_customerKey": "mobileMessage{{{suffix}}}",
"options": { "sound": "temp.wmv", "badge": "1" }
}

0 comments on commit cdde4fd

Please sign in to comment.