mcdev 10.1.0 → 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.
Files changed (31) hide show
  1. package/@types/lib/index.d.ts.map +1 -1
  2. package/@types/lib/metadataTypes/AttributeGroup.d.ts +69 -24
  3. package/@types/lib/metadataTypes/AttributeGroup.d.ts.map +1 -1
  4. package/@types/lib/metadataTypes/AttributeSet.d.ts +521 -301
  5. package/@types/lib/metadataTypes/AttributeSet.d.ts.map +1 -1
  6. package/@types/lib/metadataTypes/DataExtension.d.ts.map +1 -1
  7. package/@types/lib/metadataTypes/Folder.d.ts.map +1 -1
  8. package/@types/lib/metadataTypes/Journey.d.ts +43 -12
  9. package/@types/lib/metadataTypes/Journey.d.ts.map +1 -1
  10. package/@types/lib/metadataTypes/MetadataType.d.ts.map +1 -1
  11. package/@types/lib/metadataTypes/MobileMessage.d.ts +7 -0
  12. package/@types/lib/metadataTypes/MobileMessage.d.ts.map +1 -1
  13. package/@types/lib/metadataTypes/MobilePush.d.ts +8 -0
  14. package/@types/lib/metadataTypes/MobilePush.d.ts.map +1 -1
  15. package/@types/lib/metadataTypes/definitions/AttributeGroup.definition.d.ts +25 -20
  16. package/@types/lib/metadataTypes/definitions/AttributeSet.definition.d.ts +327 -296
  17. package/lib/cli.js +4 -1
  18. package/lib/index.js +24 -1
  19. package/lib/metadataTypes/AttributeGroup.js +173 -1
  20. package/lib/metadataTypes/AttributeSet.js +847 -14
  21. package/lib/metadataTypes/DataExtension.js +17 -7
  22. package/lib/metadataTypes/Folder.js +20 -0
  23. package/lib/metadataTypes/Journey.js +265 -21
  24. package/lib/metadataTypes/MetadataType.js +21 -13
  25. package/lib/metadataTypes/MobileMessage.js +32 -3
  26. package/lib/metadataTypes/MobilePush.js +37 -3
  27. package/lib/metadataTypes/definitions/AttributeGroup.definition.js +55 -48
  28. package/lib/metadataTypes/definitions/AttributeSet.definition.js +345 -316
  29. package/lib/util/init.git.js +1 -1
  30. package/package.json +19 -17
  31. package/scripts/verify-own-dependencies-latest.mjs +117 -0
package/lib/cli.js CHANGED
@@ -170,7 +170,8 @@ yargs(hideBin(process.argv))
170
170
  'start existing schedule instead of running item once immediately (only works for automations)',
171
171
  })
172
172
  .option('fixShared', {
173
- type: 'boolean',
173
+ type: 'string',
174
+ coerce: (value) => value === '' || value,
174
175
  group: 'Options for deploy:',
175
176
  describe:
176
177
  "ensure that updates to shared DataExtensions become visible in child BU's data designer (SF Known issue W-11031095)",
@@ -425,6 +426,7 @@ yargs(hideBin(process.argv))
425
426
  'allows reducing validation rules from error to warn to handle edge cases',
426
427
  })
427
428
  .option('purge', {
429
+ type: 'boolean',
428
430
  group: 'Options for clone:',
429
431
  describe:
430
432
  'deletes the relevant deploy folder before building the definition. Add "--no-purge" to skip the question and not delete anything',
@@ -506,6 +508,7 @@ yargs(hideBin(process.argv))
506
508
  'allows reducing validation rules from error to warn to handle edge cases',
507
509
  })
508
510
  .option('purge', {
511
+ type: 'boolean',
509
512
  group: 'Options for build:',
510
513
  describe:
511
514
  'deletes the relevant deploy folder before building the definition. Add "--no-purge" to skip the question and not delete anything',
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ import auth from './util/auth.js';
5
5
  import File from './util/file.js';
6
6
  import config from './util/config.js';
7
7
  import Init from './util/init.js';
8
+ import InitConfig from './util/init.config.js';
8
9
  import InitGit from './util/init.git.js';
9
10
  import Cli from './util/cli.js';
10
11
  import DevOps from './util/devops.js';
@@ -19,6 +20,7 @@ import ReplaceContentBlockReference from './util/replaceContentBlockReference.js
19
20
  import { migrateAssetV10Tree } from './util/migrations/assetV10.js';
20
21
  import fs from 'fs-extra';
21
22
  import pLimit from 'p-limit';
23
+ import semver from 'semver';
22
24
  import path from 'node:path';
23
25
 
24
26
  import { confirm } from '@inquirer/prompts';
@@ -374,7 +376,28 @@ export default class Mcdev {
374
376
  return false;
375
377
  }
376
378
 
377
- return Init.upgradeProject(properties, false);
379
+ const versionBeforeUpgrade = properties.version;
380
+ const success = await Init.upgradeProject(properties, false);
381
+ if (
382
+ success &&
383
+ semver.valid(versionBeforeUpgrade) &&
384
+ semver.lt(versionBeforeUpgrade, '10.0.0')
385
+ ) {
386
+ Util.logger.warn(
387
+ 'Migration is mandatory after upgrading a project from before v10. Run mcdev migrate to reorganize your local retrieve assets.'
388
+ );
389
+ if (
390
+ !Util.skipInteraction &&
391
+ !Util.OPTIONS.skipInteraction &&
392
+ (await InitConfig.promptConfirmation(
393
+ 'Run mcdev migrate now? (No = not now)',
394
+ false
395
+ ))
396
+ ) {
397
+ await this.migrate();
398
+ }
399
+ }
400
+ return success;
378
401
  }
379
402
 
380
403
  /**
@@ -1,14 +1,28 @@
1
1
  'use strict';
2
2
 
3
+ import AttributeSet from './AttributeSet.js';
3
4
  import MetadataType from './MetadataType.js';
4
5
  import { Util } from '../util/util.js';
5
6
  import cache from '../util/cache.js';
6
7
 
7
8
  /**
8
9
  * @typedef {import('../../types/mcdev.d.js').MetadataTypeItem} MetadataTypeItem
10
+ * @typedef {import('../../types/mcdev.d.js').MetadataTypeMap} MetadataTypeMap
9
11
  * @typedef {import('../../types/mcdev.d.js').MetadataTypeMapObj} MetadataTypeMapObj
10
12
  */
11
13
 
14
+ /**
15
+ * helper for {@link AttributeGroup.hasChanged}: description is a plain string in the cache (raw API, absent when empty) and {value} after preDeployTasks
16
+ *
17
+ * @param {MetadataTypeItem} item attributeGroup
18
+ * @returns {string} description or empty string
19
+ */
20
+ function getDescription(item) {
21
+ return (
22
+ (typeof item.description === 'object' ? item.description?.value : item.description) || ''
23
+ );
24
+ }
25
+
12
26
  /**
13
27
  * AttributeGroup MetadataType
14
28
  *
@@ -25,6 +39,15 @@ class AttributeGroup extends MetadataType {
25
39
  * @returns {Promise.<MetadataTypeMapObj>} Promise of metadata
26
40
  */
27
41
  static async retrieve(retrieveDir, _, __, key) {
42
+ if (retrieveDir && !cache.getCache()?.attributeSet) {
43
+ // ! attributeSet depends on attributeGroup (deploy order) but postRetrieveTasks needs the attributeSet cache to resolve r__attributeSet_key. caching attributeSet here "manually"
44
+ Util.logger.info(' - Caching dependent Metadata: attributeSet');
45
+ AttributeSet.buObject = this.buObject;
46
+ AttributeSet.client = this.client;
47
+ AttributeSet.properties = this.properties;
48
+ const result = await AttributeSet.retrieveForCache();
49
+ cache.setMetadata('attributeSet', result.metadata);
50
+ }
28
51
  return super.retrieveREST(retrieveDir, '/hub/v1/contacts/schema/attributeGroups', key);
29
52
  }
30
53
 
@@ -104,12 +127,161 @@ class AttributeGroup extends MetadataType {
104
127
  return metadata;
105
128
  }
106
129
 
130
+ /**
131
+ * Deploys metadata - merely kept here to be able to print {@link Util.logBeta} once per deploy
132
+ *
133
+ * @param {MetadataTypeMap} metadata metadata mapped by their keyField
134
+ * @param {string} deployDir directory where deploy metadata are saved
135
+ * @param {string} retrieveDir directory where metadata after deploy should be saved
136
+ * @returns {Promise.<MetadataTypeMap>} Promise of keyField => metadata map
137
+ */
138
+ static async deploy(metadata, deployDir, retrieveDir) {
139
+ Util.logBeta(this.definition.type);
140
+ return super.deploy(metadata, deployDir, retrieveDir);
141
+ }
142
+
107
143
  /**
108
144
  * prepares for deployment
109
145
  *
110
146
  * @param {MetadataTypeItem} metadata a single item
111
- * @returns {MetadataTypeItem} Promise
147
+ * @returns {Promise.<MetadataTypeItem>} Promise
148
+ */
149
+ static async preDeployTasks(metadata) {
150
+ if (metadata.isSystemDefined || metadata.applicationKey) {
151
+ throw new Error(
152
+ 'system-defined attributeGroups cannot be deployed (isSystemDefined / applicationKey is set)'
153
+ );
154
+ }
155
+ if (!metadata.definitionName?.value) {
156
+ throw new Error('definitionName.value is required');
157
+ }
158
+ // the API only accepts description as {value}; retrieve stores it as a plain string
159
+ if (typeof metadata.description === 'string') {
160
+ metadata.description = { value: metadata.description };
161
+ }
162
+ metadata.fullyQualifiedName = metadata.definitionName.value;
163
+ // membership is owned by the attributeSets and read-only on the group
164
+ delete metadata.r__attributeSet_key;
165
+ // server id of the source BU; never sent and must not trigger the id-based update path in createOrUpdate (debug mode)
166
+ delete metadata.definitionID;
167
+ return metadata;
168
+ }
169
+
170
+ /**
171
+ * Creates a single attributeGroup
172
+ *
173
+ * @param {MetadataTypeItem} metadata single metadata entry
174
+ * @returns {Promise.<object> | null} Promise of API response or null in case of an error
175
+ */
176
+ static async create(metadata) {
177
+ return super.createREST(metadata, '/hub/v1/contacts/schema/attributeGroups');
178
+ }
179
+
180
+ /**
181
+ * helper for {@link MetadataType.createREST}: unwraps the created item so that upsert can parse it like a retrieved item
182
+ *
183
+ * @param {MetadataTypeItem} metadataEntry a single metadata Entry
184
+ * @param {object} apiResponse varies depending on the API call
185
+ * @returns {Promise.<object>} apiResponse, potentially modified
186
+ */
187
+ static async postCreateTasks(metadataEntry, apiResponse) {
188
+ return apiResponse?.attributeGroupDefinition || apiResponse;
189
+ }
190
+
191
+ /**
192
+ * attributeGroups cannot be changed via API after creation (only a rename exists, which also overwrites the key on the server).
193
+ * Nothing is sent; differences are only reported. Compares against the raw cached API data.
194
+ *
195
+ * @param {MetadataTypeItem} metadata single metadata entry
196
+ * @param {MetadataTypeItem} metadataBefore cached version from the server
197
+ * @returns {Promise.<null>} always null as nothing is updated
198
+ */
199
+ static async update(metadata, metadataBefore) {
200
+ const key = metadata[this.definition.keyField];
201
+ if (metadata.definitionName?.value !== metadataBefore?.definitionName?.value) {
202
+ Util.logger.error(
203
+ ` ☇ skipping ${this.definition.type} ${key}: renaming an attributeGroup changes its key on the server; rename it in Contact Builder and re-retrieve`
204
+ );
205
+ } else if (
206
+ getDescription(metadata) !== getDescription(metadataBefore) ||
207
+ (metadata.attributeGroupIconKey || '') !== (metadataBefore?.attributeGroupIconKey || '')
208
+ ) {
209
+ Util.logger.warn(
210
+ ` ☇ skipping ${this.definition.type} ${key}: description and attributeGroupIconKey cannot be changed via API after creation`
211
+ );
212
+ } else {
213
+ Util.logger.verbose(` ☇ skipping ${this.definition.type} ${key}: no change detected`);
214
+ }
215
+ return null;
216
+ }
217
+
218
+ /**
219
+ * caches attributeGroup and attributeSet (raw API format) unless already cached; shared by both types' preDeleteTasks
220
+ *
221
+ * @returns {Promise.<void>} -
112
222
  */
223
+ static async cacheForDelete() {
224
+ if (!cache.getCache()) {
225
+ cache.initCache(this.buObject);
226
+ }
227
+ AttributeSet.buObject = this.buObject;
228
+ AttributeSet.client = this.client;
229
+ AttributeSet.properties = this.properties;
230
+ if (!cache.getCache().attributeGroup) {
231
+ cache.setMetadata('attributeGroup', (await this.retrieveForCache()).metadata);
232
+ }
233
+ if (!cache.getCache().attributeSet) {
234
+ // a fresh cache starts a new delete run: forget cascade-deleted keys of earlier runs / other BUs.
235
+ // Not reset when already cached so that deleting attributeGroup and attributeSet in one command keeps the group's cascade
236
+ AttributeSet.cascadeDeletedKeys.clear();
237
+ // parseResponseBody already writes the raw list into the cache
238
+ await AttributeSet.retrieveForCache();
239
+ }
240
+ }
241
+
242
+ /**
243
+ * makes sure attributeGroup and attributeSet are cached before deleting
244
+ *
245
+ * @returns {Promise.<void>} -
246
+ */
247
+ static async preDeleteTasks() {
248
+ await this.cacheForDelete();
249
+ }
250
+
251
+ /**
252
+ * Delete an attributeGroup. The server deletes all attributeSets of the group with it (data extensions stay).
253
+ *
254
+ * @param {string} key Identifier of the attributeGroup
255
+ * @returns {Promise.<boolean>} deletion success flag
256
+ */
257
+ static async deleteByKey(key) {
258
+ const group = cache.getByKey(this.definition.type, key);
259
+ if (!group) {
260
+ await this.deleteNotFound(key);
261
+ return false;
262
+ }
263
+ if (group.isSystemDefined) {
264
+ Util.logger.error(
265
+ ` ☇ skipping deletion of ${this.definition.type} ${key}: system-defined attributeGroups cannot be deleted`
266
+ );
267
+ return false;
268
+ }
269
+ const cascaded = AttributeSet._getSetKeysOfGroup(group.definitionID);
270
+ if (cascaded.length) {
271
+ Util.logger.warn(
272
+ ` - deleting ${this.definition.type} ${key} also deletes all of its attributeSets: ${cascaded.join(', ')}`
273
+ );
274
+ }
275
+ const isDeleted = await super.deleteByKeyREST(
276
+ '/hub/v1/contacts/schema/attributeGroups/' + group.definitionID,
277
+ key
278
+ );
279
+ if (isDeleted) {
280
+ delete cache.getCache()[this.definition.type][key];
281
+ await AttributeSet.removeDeletedSets(cascaded, true);
282
+ }
283
+ return isDeleted;
284
+ }
113
285
  }
114
286
 
115
287
  // Assign definition to static attributes