From cdde4fda972195f11c2cc5d1d8b0bf37f030f044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Fri, 17 May 2024 22:22:16 +0200 Subject: [PATCH] #58: normalize cross-type references with r__ for transactionalPush --- lib/metadataTypes/TransactionalPush.js | 11 +++++++---- .../definitions/TransactionalPush.definition.js | 6 ++++++ .../testExisting_tpush.transactionalPush-meta.json | 4 +--- .../testNew_tpush.transactionalPush-meta.json | 4 +--- .../9999999/transactionalPush/build-expected.json | 2 +- .../9999999/transactionalPush/get-expected.json | 2 +- .../9999999/transactionalPush/patch-expected.json | 4 +--- .../9999999/transactionalPush/post-expected.json | 4 +--- .../9999999/transactionalPush/template-expected.json | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/metadataTypes/TransactionalPush.js b/lib/metadataTypes/TransactionalPush.js index 4fc95b2d7..89d98e907 100644 --- a/lib/metadataTypes/TransactionalPush.js +++ b/lib/metadataTypes/TransactionalPush.js @@ -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 @@ -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]} (${ diff --git a/lib/metadataTypes/definitions/TransactionalPush.definition.js b/lib/metadataTypes/definitions/TransactionalPush.definition.js index f1ee79c13..1b502f2ae 100644 --- a/lib/metadataTypes/definitions/TransactionalPush.definition.js +++ b/lib/metadataTypes/definitions/TransactionalPush.definition.js @@ -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, diff --git a/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testExisting_tpush.transactionalPush-meta.json b/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testExisting_tpush.transactionalPush-meta.json index 39407d688..38f5010bf 100644 --- a/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testExisting_tpush.transactionalPush-meta.json +++ b/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testExisting_tpush.transactionalPush-meta.json @@ -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", diff --git a/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testNew_tpush.transactionalPush-meta.json b/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testNew_tpush.transactionalPush-meta.json index e3c0301cf..44d75684a 100644 --- a/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testNew_tpush.transactionalPush-meta.json +++ b/test/mockRoot/deploy/testInstance/testBU/transactionalPush/testNew_tpush.transactionalPush-meta.json @@ -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", diff --git a/test/resources/9999999/transactionalPush/build-expected.json b/test/resources/9999999/transactionalPush/build-expected.json index 0f464a59c..bfb884d23 100644 --- a/test/resources/9999999/transactionalPush/build-expected.json +++ b/test/resources/9999999/transactionalPush/build-expected.json @@ -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" } } diff --git a/test/resources/9999999/transactionalPush/get-expected.json b/test/resources/9999999/transactionalPush/get-expected.json index 242a9a809..92bf55110 100644 --- a/test/resources/9999999/transactionalPush/get-expected.json +++ b/test/resources/9999999/transactionalPush/get-expected.json @@ -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" } } diff --git a/test/resources/9999999/transactionalPush/patch-expected.json b/test/resources/9999999/transactionalPush/patch-expected.json index 2cf1ecd9b..403946381 100644 --- a/test/resources/9999999/transactionalPush/patch-expected.json +++ b/test/resources/9999999/transactionalPush/patch-expected.json @@ -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" diff --git a/test/resources/9999999/transactionalPush/post-expected.json b/test/resources/9999999/transactionalPush/post-expected.json index 7f87af359..cdf1c84ac 100644 --- a/test/resources/9999999/transactionalPush/post-expected.json +++ b/test/resources/9999999/transactionalPush/post-expected.json @@ -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" diff --git a/test/resources/9999999/transactionalPush/template-expected.json b/test/resources/9999999/transactionalPush/template-expected.json index 78de6f6c6..6f13ae378 100644 --- a/test/resources/9999999/transactionalPush/template-expected.json +++ b/test/resources/9999999/transactionalPush/template-expected.json @@ -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" } }