mcdev 10.1.1 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -279,6 +279,19 @@ class Folder extends MetadataType {
279
279
  continue;
280
280
  }
281
281
  }
282
+ if (
283
+ existingId &&
284
+ this.definition.deployFolderTypesEmailRest.includes(
285
+ deployableMetadata.ContentType
286
+ )
287
+ ) {
288
+ // update() cannot update these folder types; report them as filtered instead of failed
289
+ Util.logger.verbose(
290
+ ` - skipping ${this.definition.type} ${deployableMetadata.Path}: updating ${deployableMetadata.ContentType} folders is not supported`
291
+ );
292
+ filteredByPreDeploy++;
293
+ continue;
294
+ }
282
295
  if (existingId && Util.OPTIONS.noUpdate) {
283
296
  Util.logger.verbose(
284
297
  ` - skipping ${this.definition.type} ${
@@ -495,6 +508,13 @@ class Folder extends MetadataType {
495
508
  );
496
509
  return {};
497
510
  }
511
+ if (this.definition.deployFolderTypesEmailRest.includes(metadataEntry.ContentType)) {
512
+ // the SOAP endpoint does not support these folder types and there is no update call for the REST endpoint that we create them with
513
+ Util.logger.verbose(
514
+ ` - skipping update of ${metadataEntry.ContentType} folder ${metadataEntry.Path}: updating this folder type is not supported`
515
+ );
516
+ return {};
517
+ }
498
518
  const path = metadataEntry.Path;
499
519
  let apiTypeSoap = false;
500
520
  try {
@@ -5,6 +5,8 @@ import TransactionalEmail from './TransactionalEmail.js';
5
5
  import DataExtensionField from './DataExtensionField.js';
6
6
  import TriggeredSend from './TriggeredSend.js';
7
7
  import Event from './Event.js';
8
+ import MobileMessage from './MobileMessage.js';
9
+ import MobilePush from './MobilePush.js';
8
10
  import { Util } from '../util/util.js';
9
11
  import cache from '../util/cache.js';
10
12
  import File from '../util/file.js';
@@ -26,6 +28,19 @@ import { createSpinner } from '../util/progress.js';
26
28
  * @typedef {import('../../types/mcdev.d.js').TypeKeyCombo} TypeKeyCombo
27
29
  */
28
30
 
31
+ /** @type {Set.<string>} ids (prefixed with the MID) of mobileMessages that could not be retrieved directly; avoids repeated API calls */
32
+ const mobileMessageLookupMisses = new Set();
33
+
34
+ /**
35
+ * copies Journey Builder creates on publish share names with the item they were created from and are never deployed
36
+ *
37
+ * @param {MetadataTypeItem} [item] cached mobilePush or mobileMessage
38
+ * @returns {boolean} true if the item is owned by a journey
39
+ */
40
+ function isJourneyOwnedMobileItem(item) {
41
+ return MobilePush._isJourneyOwned(item) || MobileMessage._isJourneyOwned(item);
42
+ }
43
+
29
44
  /**
30
45
  * Journey MetadataType
31
46
  * id: A unique id of the journey assigned by the journey’s API during its creation
@@ -659,6 +674,140 @@ class Journey extends MetadataType {
659
674
  return metadata;
660
675
  }
661
676
 
677
+ /**
678
+ * the Journey Builder UI state repeats the id and name of the mobilePushApp in 6 places. They are
679
+ * redundant with r__mobilePushApp_key/_name and therefore not stored on disk.
680
+ *
681
+ * @private
682
+ * @param {MetadataTypeItem} activity a single journey activity
683
+ * @returns {void}
684
+ */
685
+ static _stripMobilePushAppFromStore(activity) {
686
+ const messageConfiguration = activity.metaData?.store?.messageConfiguration;
687
+ if (!messageConfiguration) {
688
+ return;
689
+ }
690
+ if (messageConfiguration.payload?.application) {
691
+ delete messageConfiguration.payload.application.id;
692
+ delete messageConfiguration.payload.application.name;
693
+ if (!Object.keys(messageConfiguration.payload.application).length) {
694
+ delete messageConfiguration.payload.application;
695
+ }
696
+ if (!Object.keys(messageConfiguration.payload).length) {
697
+ delete messageConfiguration.payload;
698
+ }
699
+ }
700
+ if (messageConfiguration.application) {
701
+ for (const field of ['id', 'name', 'value', 'title']) {
702
+ delete messageConfiguration.application[field];
703
+ }
704
+ if (!Object.keys(messageConfiguration.application).length) {
705
+ delete messageConfiguration.application;
706
+ }
707
+ }
708
+ }
709
+
710
+ /**
711
+ * counterpart of {@link Journey._stripMobilePushAppFromStore}
712
+ *
713
+ * @private
714
+ * @param {MetadataTypeItem} activity a single journey activity
715
+ * @param {MetadataTypeItem} mobilePushApp the mobilePushApp on the target BU
716
+ * @returns {void}
717
+ */
718
+ static _restoreMobilePushAppInStore(activity, mobilePushApp) {
719
+ activity.metaData ||= {};
720
+ activity.metaData.store ||= {};
721
+ const messageConfiguration = (activity.metaData.store.messageConfiguration ||= {});
722
+ messageConfiguration.payload ||= {};
723
+ messageConfiguration.payload.application = {
724
+ id: mobilePushApp.id,
725
+ name: mobilePushApp.name,
726
+ };
727
+ messageConfiguration.application = {
728
+ disabled: false,
729
+ expired: false,
730
+ ...messageConfiguration.application,
731
+ id: mobilePushApp.id,
732
+ name: mobilePushApp.name,
733
+ value: mobilePushApp.name,
734
+ title: mobilePushApp.name,
735
+ };
736
+ }
737
+
738
+ /**
739
+ * @private
740
+ * @param {string} id base64-encoded id in the format <number>:<entity code>:<number>
741
+ * @returns {string} the leading number of the decoded id
742
+ */
743
+ static _decodeIdPrefix(id) {
744
+ return Buffer.from(String(id), 'base64').toString('utf8').split(':', 1)[0];
745
+ }
746
+
747
+ /**
748
+ * Journey Builder stores the id of a journey-owned mobileMessage with a different entity-type code
749
+ * than the mobileMessage API (e.g. NDQ6NjI1OjA = 44:625:0 vs. NDQ6Nzg6MA = 44:78:0); only the numeric
750
+ * prefix is identical. Hence, we fall back to matching that prefix against the cached ids.
751
+ *
752
+ * @private
753
+ * @param {string} messageId id as found in the journey
754
+ * @returns {string | undefined} id as known to the mobileMessage cache
755
+ */
756
+ static _findMobileMessageIdInCache(messageId) {
757
+ const typeCache = cache.getCache()?.mobileMessage;
758
+ if (!typeCache) {
759
+ return;
760
+ }
761
+ for (const key in typeCache) {
762
+ if (typeCache[key]?.id === messageId) {
763
+ return messageId;
764
+ }
765
+ }
766
+ const prefix = this._decodeIdPrefix(messageId);
767
+ if (!/^\d+$/.test(prefix)) {
768
+ return;
769
+ }
770
+ const matches = Object.values(typeCache).filter(
771
+ (item) => item?.id && this._decodeIdPrefix(item.id) === prefix
772
+ );
773
+ // ambiguous prefixes must not be guessed
774
+ return matches.length === 1 ? matches[0].id : undefined;
775
+ }
776
+
777
+ /**
778
+ * resolves the id of a mobileMessage found in a journey to the id known to the cache. If the cache
779
+ * does not know it (list retrieval skips archived and test messages), the item is requested directly.
780
+ *
781
+ * @private
782
+ * @param {string} messageId id as found in the journey
783
+ * @returns {Promise.<string>} id as known to the mobileMessage cache; unchanged if it cannot be found
784
+ */
785
+ static async _resolveMobileMessageId(messageId) {
786
+ const found = this._findMobileMessageIdInCache(messageId);
787
+ if (found) {
788
+ return found;
789
+ }
790
+ const missKey = `${this.buObject?.mid}:${messageId}`;
791
+ if (mobileMessageLookupMisses.has(missKey)) {
792
+ return messageId;
793
+ }
794
+ try {
795
+ const result = await MobileMessage.retrieveForCache(null, null, messageId);
796
+ if (result?.metadata) {
797
+ cache.mergeMetadata('mobileMessage', result.metadata);
798
+ }
799
+ } catch (ex) {
800
+ Util.logger.debug(
801
+ ` - could not retrieve mobileMessage ${messageId} directly: ${ex.message}`
802
+ );
803
+ }
804
+ const resolved = this._findMobileMessageIdInCache(messageId);
805
+ if (!resolved) {
806
+ mobileMessageLookupMisses.add(missKey);
807
+ }
808
+ return resolved || messageId;
809
+ }
810
+
662
811
  /**
663
812
  * helper for {@link Journey.postRetrieveTasks}
664
813
  *
@@ -1171,6 +1320,13 @@ class Journey extends MetadataType {
1171
1320
  let sourceName;
1172
1321
  for (const key in typeCache) {
1173
1322
  if (typeCache[key]?.id === id) {
1323
+ if (
1324
+ MobilePush._isJourneyOwned(typeCache[key]) ||
1325
+ MobileMessage._isJourneyOwned(typeCache[key])
1326
+ ) {
1327
+ // copies created by Journey Builder share names by design and are never deployed
1328
+ return;
1329
+ }
1174
1330
  sourceName = typeCache[key]?.name;
1175
1331
  break;
1176
1332
  }
@@ -1181,7 +1337,10 @@ class Journey extends MetadataType {
1181
1337
  // collect all source items sharing that name
1182
1338
  const potentials = [];
1183
1339
  for (const key in typeCache) {
1184
- if (typeCache[key]?.name === sourceName) {
1340
+ if (
1341
+ typeCache[key]?.name === sourceName &&
1342
+ !isJourneyOwnedMobileItem(typeCache[key])
1343
+ ) {
1185
1344
  potentials.push(typeCache[key]);
1186
1345
  }
1187
1346
  }
@@ -1240,6 +1399,7 @@ class Journey extends MetadataType {
1240
1399
  configurationArguments.application.id
1241
1400
  );
1242
1401
  delete configurationArguments.application;
1402
+ this._stripMobilePushAppFromStore(activity);
1243
1403
  }
1244
1404
  } catch (ex) {
1245
1405
  Util.logger.warn(
@@ -1251,24 +1411,25 @@ class Journey extends MetadataType {
1251
1411
  // mobileMessage
1252
1412
  try {
1253
1413
  if (configurationArguments.messageId) {
1254
- // faithful id-based ref (primary/unchanged)
1255
- configurationArguments.r__mobileMessage_key = cache.searchForField(
1256
- 'mobileMessage',
1257
- configurationArguments.messageId,
1258
- 'id',
1259
- 'id'
1260
- );
1414
+ // a published journey stores the id of its journey-owned copy with a different entity code than the mobileMessage API returns
1415
+ const journeyMessageId = configurationArguments.messageId;
1416
+ const messageId =
1417
+ await this._resolveMobileMessageId(journeyMessageId);
1418
+ // faithful id-based ref: keep the id exactly as the journey stores it
1419
+ configurationArguments.r__mobileMessage_key = journeyMessageId;
1261
1420
  // additionally write the portable name ref for cross-BU deploys
1262
1421
  configurationArguments.r__mobileMessage_name = cache.searchForField(
1263
1422
  'mobileMessage',
1264
- configurationArguments.messageId,
1423
+ messageId,
1265
1424
  'id',
1266
1425
  'name'
1267
1426
  );
1268
- warnOnSourceDupName(
1269
- 'mobileMessage',
1270
- configurationArguments.messageId
1271
- );
1427
+ if (messageId !== journeyMessageId) {
1428
+ Util.logger.debug(
1429
+ ` - ${this.definition.type} ${metadata[this.definition.keyField]} activity-key=${activity.key}: journey stores mobileMessage id ${journeyMessageId}, mobileMessage API returns ${messageId}`
1430
+ );
1431
+ }
1432
+ warnOnSourceDupName('mobileMessage', messageId);
1272
1433
  delete configurationArguments.messageId;
1273
1434
  }
1274
1435
  } catch (ex) {
@@ -1330,6 +1491,8 @@ class Journey extends MetadataType {
1330
1491
  'code'
1331
1492
  );
1332
1493
  delete configurationArguments.codeId;
1494
+ // selectedCode only repeats the details of the mobileCode we now reference
1495
+ delete activity.metaData?.store?.messageConfiguration?.selectedCode;
1333
1496
  }
1334
1497
  } catch (ex) {
1335
1498
  Util.logger.warn(
@@ -1648,6 +1811,8 @@ class Journey extends MetadataType {
1648
1811
  * @param {MetadataTypeItem} metadata a single item
1649
1812
  */
1650
1813
  static async _preDeployTasks_activities(metadata) {
1814
+ // unresolvable references to journey-owned items are only tolerated while creating the journey
1815
+ const journeyExistsOnTarget = Boolean(cache.getByKey('journey', metadata.key));
1651
1816
  for (const activity of metadata.activities) {
1652
1817
  switch (activity.type) {
1653
1818
  case 'EMAILV2': {
@@ -1838,7 +2003,10 @@ class Journey extends MetadataType {
1838
2003
  const typeCache = cache.getCache()?.[type];
1839
2004
  const potentials = [];
1840
2005
  for (const cacheKey in typeCache) {
1841
- if (typeCache[cacheKey]?.name === name) {
2006
+ if (
2007
+ typeCache[cacheKey]?.name === name &&
2008
+ !isJourneyOwnedMobileItem(typeCache[cacheKey])
2009
+ ) {
1842
2010
  potentials.push(typeCache[cacheKey]);
1843
2011
  }
1844
2012
  }
@@ -1857,6 +2025,26 @@ class Journey extends MetadataType {
1857
2025
  }
1858
2026
  return match;
1859
2027
  };
2028
+ /**
2029
+ * reports that a reference to an item owned by this journey is not sent with the Draft
2030
+ *
2031
+ * @param {string} type mobilePush or mobileMessage
2032
+ * @param {MetadataTypeItem | undefined} match the cached item, if it could be resolved
2033
+ * @param {string} activityKey key of the activity
2034
+ */
2035
+ const dropJourneyOwnedRef = (type, match, activityKey) => {
2036
+ const msg = ` - ${this.definition.type} '${metadata[this.definition.nameField]}' (${metadata[this.definition.keyField]}) activity-key=${activityKey}: ${type} reference removed from Draft; Journey Builder creates a journey-owned ${type} when the journey is published.`;
2037
+ if (match) {
2038
+ Util.logger.debug(msg);
2039
+ } else {
2040
+ Util.logger.warn(
2041
+ msg.replace(
2042
+ 'reference removed',
2043
+ `reference (${configurationArguments['r__' + type + '_name'] || configurationArguments['r__' + type + '_key']}) not found on target BU and removed`
2044
+ )
2045
+ );
2046
+ }
2047
+ };
1860
2048
  // mobilePush REFERENCE resolution: resolve to the target-BU id (key==id).
1861
2049
  // delete-parity: retain r__mobilePush_key + r__mobilePush_name.
1862
2050
  if (
@@ -1868,13 +2056,22 @@ class Journey extends MetadataType {
1868
2056
  configurationArguments.r__mobilePush_key,
1869
2057
  configurationArguments.r__mobilePush_name
1870
2058
  );
1871
- // 0 matches on key AND name → referenced item is missing on target BU
1872
- if (!mobilePush) {
2059
+ if (
2060
+ MobilePush._isJourneyOwned(mobilePush) ||
2061
+ (!mobilePush && !journeyExistsOnTarget)
2062
+ ) {
2063
+ // Draft journeys carry no pushMessageId; Journey Builder creates the journey-owned item on publish
2064
+ dropJourneyOwnedRef('mobilePush', mobilePush, activity.key);
2065
+ delete configurationArguments.r__mobilePush_key;
2066
+ delete configurationArguments.r__mobilePush_name;
2067
+ } else if (mobilePush) {
2068
+ configurationArguments.pushMessageId = mobilePush.id;
2069
+ } else {
2070
+ // 0 matches on key AND name → referenced item is missing on target BU
1873
2071
  throw new Error(
1874
2072
  `mobilePush '${configurationArguments.r__mobilePush_name || configurationArguments.r__mobilePush_key}' not found on target BU — must be deployed first`
1875
2073
  );
1876
2074
  }
1877
- configurationArguments.pushMessageId = mobilePush.id;
1878
2075
  }
1879
2076
  // mobilePushApp REFERENCE resolution: resolve to the target-BU app object.
1880
2077
  // shape parity: keep application = { id, name } (this site's existing shape).
@@ -1898,6 +2095,7 @@ class Journey extends MetadataType {
1898
2095
  id: mobilePushApp.id,
1899
2096
  name: mobilePushApp.name,
1900
2097
  };
2098
+ this._restoreMobilePushAppInStore(activity, mobilePushApp);
1901
2099
  }
1902
2100
 
1903
2101
  // mobileMessage REFERENCE resolution: resolve to the target-BU id (key==id).
@@ -1908,16 +2106,35 @@ class Journey extends MetadataType {
1908
2106
  ) {
1909
2107
  const mobileMessage = resolveMobileRef(
1910
2108
  'mobileMessage',
1911
- configurationArguments.r__mobileMessage_key,
2109
+ // the key is stored as the journey holds it (entity code 625); the cache knows the mobileMessage API id (entity code 78)
2110
+ this._findMobileMessageIdInCache(
2111
+ configurationArguments.r__mobileMessage_key
2112
+ ) || configurationArguments.r__mobileMessage_key,
1912
2113
  configurationArguments.r__mobileMessage_name
1913
2114
  );
1914
- // 0 matches on key AND name → referenced item is missing on target BU
1915
- if (!mobileMessage) {
2115
+ if (
2116
+ MobileMessage._isJourneyOwned(mobileMessage) ||
2117
+ (!mobileMessage && !journeyExistsOnTarget)
2118
+ ) {
2119
+ if (mobileMessage && !configurationArguments.r__asset_key) {
2120
+ // without an asset Journey Builder cannot create its own copy on publish and needs the picked MobileConnect message
2121
+ configurationArguments.messageId = mobileMessage.id;
2122
+ } else {
2123
+ // Draft journeys carry no messageId for journey-owned copies; Journey Builder creates them from the asset on publish
2124
+ dropJourneyOwnedRef(
2125
+ 'mobileMessage',
2126
+ mobileMessage,
2127
+ activity.key
2128
+ );
2129
+ }
2130
+ } else if (mobileMessage) {
2131
+ configurationArguments.messageId = mobileMessage.id;
2132
+ } else {
2133
+ // 0 matches on key AND name → referenced item is missing on target BU
1916
2134
  throw new Error(
1917
2135
  `mobileMessage '${configurationArguments.r__mobileMessage_name || configurationArguments.r__mobileMessage_key}' not found on target BU — must be deployed first`
1918
2136
  );
1919
2137
  }
1920
- configurationArguments.messageId = mobileMessage.id;
1921
2138
  delete configurationArguments.r__mobileMessage_key;
1922
2139
  delete configurationArguments.r__mobileMessage_name;
1923
2140
  }
@@ -1947,6 +2164,21 @@ class Journey extends MetadataType {
1947
2164
  'code',
1948
2165
  'id'
1949
2166
  );
2167
+ if (activity.type === 'SMSSYNC') {
2168
+ // restore the selectedCode which is stripped on retrieve
2169
+ const mobileCode = cache.getByKey(
2170
+ 'mobileCode',
2171
+ configurationArguments.r__mobileCode_key
2172
+ );
2173
+ activity.metaData ||= {};
2174
+ activity.metaData.store ||= {};
2175
+ activity.metaData.store.messageConfiguration ||= {};
2176
+ activity.metaData.store.messageConfiguration.selectedCode = {
2177
+ countryCode: mobileCode?.countryCode,
2178
+ id: configurationArguments.codeId,
2179
+ code: configurationArguments.r__mobileCode_key,
2180
+ };
2181
+ }
1950
2182
  delete configurationArguments.r__mobileCode_key;
1951
2183
  }
1952
2184
  // asset-asset: jsonmessage
@@ -2621,6 +2853,18 @@ class Journey extends MetadataType {
2621
2853
  return;
2622
2854
  }
2623
2855
  Util.logger.info('Re-retrieving published journeys');
2856
+ if (multiStepCounter) {
2857
+ // publishing creates journey-owned mobilePush and mobileMessage items; reset their caches to trigger re-caching them
2858
+ if (cache.getCache()) {
2859
+ cache.clearCache(this.buObject.mid, 'mobileMessage');
2860
+ cache.clearCache(this.buObject.mid, 'mobilePush');
2861
+ }
2862
+ for (const missKey of mobileMessageLookupMisses) {
2863
+ if (missKey.startsWith(`${this.buObject.mid}:`)) {
2864
+ mobileMessageLookupMisses.delete(missKey);
2865
+ }
2866
+ }
2867
+ }
2624
2868
  const retriever = new Retriever(this.properties, this.buObject);
2625
2869
  try {
2626
2870
  // we need to retrieve the updated journeys and all dependencies
@@ -752,7 +752,7 @@ class MetadataType {
752
752
  Util.logger.debug(
753
753
  `${this.definition.type}:: ${
754
754
  identifier
755
- }.${prop} changed: '${cachedVersion[prop]}' to '${clonedMetada[prop]}'`
755
+ }.${prop} changed: '${JSON.stringify(cachedVersion[prop])}' to '${JSON.stringify(clonedMetada[prop])}'`
756
756
  );
757
757
  return true;
758
758
  }
@@ -2430,21 +2430,29 @@ class MetadataType {
2430
2430
  if (ex?.response?.status >= 400 && ex?.response?.status < 600) {
2431
2431
  if (ex.response.data.errors) {
2432
2432
  for (const errMsg of ex.response.data.errors) {
2433
- errors.push(
2434
- ...errMsg.message
2435
- .split('<br />')
2436
- .map((el) => el.trim())
2437
- .filter(Boolean)
2438
- );
2433
+ if (errMsg.message) {
2434
+ errors.push(
2435
+ ...errMsg.message
2436
+ .split('<br />')
2437
+ .map((el) => el.trim())
2438
+ .filter(Boolean)
2439
+ );
2440
+ } else {
2441
+ errors.push(JSON.stringify(errMsg));
2442
+ }
2439
2443
  }
2440
2444
  } else if (ex.response.data.validationErrors) {
2441
2445
  for (const errMsg of ex.response.data.validationErrors) {
2442
- errors.push(
2443
- ...errMsg.message
2444
- .split('<br />')
2445
- .map((el) => el.trim())
2446
- .filter(Boolean)
2447
- );
2446
+ if (errMsg.message) {
2447
+ errors.push(
2448
+ ...errMsg.message
2449
+ .split('<br />')
2450
+ .map((el) => el.trim())
2451
+ .filter(Boolean)
2452
+ );
2453
+ } else {
2454
+ errors.push(JSON.stringify(errMsg));
2455
+ }
2448
2456
  }
2449
2457
  } else if (ex.response.data.message) {
2450
2458
  errors.push(ex.response.data.message);
@@ -112,7 +112,8 @@ class MobileMessage extends MetadataType {
112
112
  for (const key in typeCache) {
113
113
  if (
114
114
  typeCache[key][this.definition.nameField] ===
115
- metadataItem[this.definition.nameField]
115
+ metadataItem[this.definition.nameField] &&
116
+ !this._isJourneyOwned(typeCache[key])
116
117
  ) {
117
118
  potentials.push(typeCache[key]);
118
119
  }
@@ -137,6 +138,16 @@ class MobileMessage extends MetadataType {
137
138
  return super.getCacheMatchedByName(metadataItem);
138
139
  }
139
140
 
141
+ /**
142
+ * mobileMessages with sendMethod INTERACTION are the copies Journey Builder creates when a journey is published
143
+ *
144
+ * @param {MetadataTypeItem} metadataItem a single mobileMessage
145
+ * @returns {boolean} true if the item is owned by a journey
146
+ */
147
+ static _isJourneyOwned(metadataItem) {
148
+ return metadataItem?.sendMethod === 'INTERACTION';
149
+ }
150
+
140
151
  /**
141
152
  * warns (loudly, without dropping any item) when a retrieved metadata map contains multiple
142
153
  * items that share the same name. Duplicate names make cross-BU name-fallback deploys ambiguous.
@@ -149,9 +160,9 @@ class MobileMessage extends MetadataType {
149
160
  if (!metadata) {
150
161
  return;
151
162
  }
152
- // group ids + createdDates by name
163
+ // group ids + createdDates by name; journey-owned copies share names by design and are never deployed
153
164
  const byName = Object.groupBy(
154
- Object.values(metadata),
165
+ Object.values(metadata).filter((item) => !this._isJourneyOwned(item)),
155
166
  (item) => item[this.definition.nameField]
156
167
  );
157
168
  // emit a loud warn for any name used by >1 item
@@ -265,6 +276,18 @@ class MobileMessage extends MetadataType {
265
276
  * @returns {CodeExtractItem} Array with one metadata object and one query string
266
277
  */
267
278
  static postRetrieveTasks(metadata) {
279
+ if (this._isJourneyOwned(metadata)) {
280
+ // journey-owned copies are created and managed by Journey Builder on publish; the journey
281
+ // keeps referencing them via r__mobileMessage_key, so they must stay resolvable in the cache
282
+ // even though they are not written to disk (saveResults skips falsy results before caching)
283
+ cache.mergeMetadata(this.definition.type, {
284
+ [metadata[this.definition.keyField]]: metadata,
285
+ });
286
+ Util.logger.debug(
287
+ ` ☇ skipping ${this.definition.type} ${Util.getKeyName(this.definition, metadata)}: owned by a journey`
288
+ );
289
+ return null;
290
+ }
268
291
  // mobileCode
269
292
  try {
270
293
  metadata.r__mobileCode_key = cache.searchForField(
@@ -375,6 +398,12 @@ class MobileMessage extends MetadataType {
375
398
  * @returns {Promise.<MetadataTypeItem>} Promise
376
399
  */
377
400
  static async preDeployTasks(metadata, deployDir) {
401
+ if (this._isJourneyOwned(metadata)) {
402
+ Util.logger.info(
403
+ ` ☇ skipping ${this.definition.type} ${Util.getKeyName(this.definition, metadata)}: owned by a journey. Deploy and publish the journey instead (mcdev publish).`
404
+ );
405
+ return null;
406
+ }
378
407
  // mobileCode
379
408
  if (metadata.r__mobileCode_key) {
380
409
  metadata.code ||= {};
@@ -93,6 +93,21 @@ class MobilePush extends MetadataType {
93
93
  return this.retrieve(null, null, null, null, true);
94
94
  }
95
95
 
96
+ /**
97
+ * mobilePush items with sendInitiator journeyBuilder are the copies Journey Builder creates when a journey is published.
98
+ * Works on the raw API value (number) and on the retrieved file format (c__sendInitiator).
99
+ *
100
+ * @param {MetadataTypeItem} metadataItem a single mobilePush
101
+ * @returns {boolean} true if the item is owned by a journey
102
+ */
103
+ static _isJourneyOwned(metadataItem) {
104
+ const journeyBuilder = this.definition.sendInitiatorMapping.journeyBuilder;
105
+ return (
106
+ metadataItem?.sendInitiator === journeyBuilder ||
107
+ metadataItem?.c__sendInitiator === 'journeyBuilder'
108
+ );
109
+ }
110
+
96
111
  /**
97
112
  * warns (loudly, without dropping any item) when a retrieved metadata map contains multiple
98
113
  * items that share the same name. Duplicate names make cross-BU name-fallback deploys ambiguous.
@@ -105,9 +120,9 @@ class MobilePush extends MetadataType {
105
120
  if (!metadata) {
106
121
  return;
107
122
  }
108
- // group ids + createdDates by name
123
+ // group ids + createdDates by name; journey-owned copies share names by design and are never deployed
109
124
  const byName = Object.groupBy(
110
- Object.values(metadata),
125
+ Object.values(metadata).filter((item) => !this._isJourneyOwned(item)),
111
126
  (item) => item[this.definition.nameField]
112
127
  );
113
128
  // emit a loud warn for any name used by >1 item
@@ -163,6 +178,18 @@ class MobilePush extends MetadataType {
163
178
  * @returns {MetadataTypeItem} Array with one metadata object and one query string
164
179
  */
165
180
  static postRetrieveTasks(metadata) {
181
+ if (this._isJourneyOwned(metadata)) {
182
+ // journey-owned copies are created and managed by Journey Builder on publish; the journey
183
+ // keeps referencing them via r__mobilePush_key, so they must stay resolvable in the cache
184
+ // even though they are not written to disk (saveResults skips falsy results before caching)
185
+ cache.mergeMetadata(this.definition.type, {
186
+ [metadata[this.definition.keyField]]: metadata,
187
+ });
188
+ Util.logger.debug(
189
+ ` ☇ skipping ${this.definition.type} ${Util.getKeyName(this.definition, metadata)}: owned by a journey`
190
+ );
191
+ return null;
192
+ }
166
193
  // mobile application
167
194
  if (metadata.application?.id) {
168
195
  const appId = metadata.application.id;
@@ -303,7 +330,8 @@ class MobilePush extends MetadataType {
303
330
  for (const key in typeCache) {
304
331
  if (
305
332
  typeCache[key][this.definition.nameField] ===
306
- metadataItem[this.definition.nameField]
333
+ metadataItem[this.definition.nameField] &&
334
+ !this._isJourneyOwned(typeCache[key])
307
335
  ) {
308
336
  potentials.push(typeCache[key]);
309
337
  }
@@ -335,6 +363,12 @@ class MobilePush extends MetadataType {
335
363
  * @returns {Promise.<MetadataTypeItem>} Promise
336
364
  */
337
365
  static async preDeployTasks(metadata) {
366
+ if (this._isJourneyOwned(metadata)) {
367
+ Util.logger.info(
368
+ ` ☇ skipping ${this.definition.type} ${Util.getKeyName(this.definition, metadata)}: owned by a journey. Deploy and publish the journey instead (mcdev publish).`
369
+ );
370
+ return null;
371
+ }
338
372
  // mobilePushApp REFERENCE resolution: key-first, name-fallback to a target-BU app.
339
373
  // ! this is a REFERENCE site — mobilePushApp is retrieve-only/GUI-created, so 0 matches is
340
374
  // ! a hard error (never a create, unlike the top-level item deploy path).