Skip to content

Commit

Permalink
#627: move journey-version-param into key/id field as a req suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Jan 23, 2023
1 parent ecbc5c9 commit 4e5c565
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
10 changes: 4 additions & 6 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ main class
* [.initProject([credentialsName])](#Mcdev.initProject) ⇒ <code>Promise.&lt;void&gt;</code>
* [.findBUs(credentialsName)](#Mcdev.findBUs) ⇒ <code>Promise.&lt;void&gt;</code>
* [.document(businessUnit, type)](#Mcdev.document) ⇒ <code>Promise.&lt;void&gt;</code>
* [.deleteByKey(businessUnit, type, customerKey, [version])](#Mcdev.deleteByKey) ⇒ <code>Promise.&lt;void&gt;</code>
* [.deleteByKey(businessUnit, type, customerKey)](#Mcdev.deleteByKey) ⇒ <code>Promise.&lt;void&gt;</code>
* [.badKeys(businessUnit)](#Mcdev.badKeys) ⇒ <code>Promise.&lt;void&gt;</code>
* [.retrieveAsTemplate(businessUnit, selectedType, name, market)](#Mcdev.retrieveAsTemplate) ⇒ <code>Promise.&lt;TYPE.MultiMetadataTypeList&gt;</code>
* [.buildTemplate(businessUnit, selectedType, keyArr, market)](#Mcdev.buildTemplate) ⇒ <code>Promise.&lt;TYPE.MultiMetadataTypeList&gt;</code>
Expand Down Expand Up @@ -607,7 +607,7 @@ Creates docs for supported metadata types in Markdown and/or HTML format

<a name="Mcdev.deleteByKey"></a>

### Mcdev.deleteByKey(businessUnit, type, customerKey, [version]) ⇒ <code>Promise.&lt;void&gt;</code>
### Mcdev.deleteByKey(businessUnit, type, customerKey) ⇒ <code>Promise.&lt;void&gt;</code>
Creates docs for supported metadata types in Markdown and/or HTML format

**Kind**: static method of [<code>Mcdev</code>](#Mcdev)
Expand All @@ -618,7 +618,6 @@ Creates docs for supported metadata types in Markdown and/or HTML format
| businessUnit | <code>string</code> | references credentials from properties.json |
| type | <code>string</code> | supported metadata type |
| customerKey | <code>string</code> | Identifier of metadata |
| [version] | <code>number</code> | optional version of metadata |

<a name="Mcdev.badKeys"></a>

Expand Down Expand Up @@ -2929,7 +2928,7 @@ definitionId: A unique UUID provided by Salesforce Marketing Cloud. Each version

* [Interaction](#Interaction)[<code>MetadataType</code>](#MetadataType)
* [.retrieve(retrieveDir, [_], [__], [___], [key])](#Interaction.retrieve) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
* [.deleteByKey(buObject, key, version)](#Interaction.deleteByKey) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.deleteByKey(buObject, key)](#Interaction.deleteByKey) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.update(metadata)](#Interaction.update) ⇒ <code>Promise</code>
* [.create(metadata)](#Interaction.create) ⇒ <code>Promise</code>
* [.postRetrieveTasks(metadata)](#Interaction.postRetrieveTasks) ⇒ <code>TYPE.MetadataTypeItem</code>
Expand All @@ -2954,7 +2953,7 @@ Retrieves Metadata of Interaction

<a name="Interaction.deleteByKey"></a>

### Interaction.deleteByKey(buObject, key, version) ⇒ <code>Promise.&lt;boolean&gt;</code>
### Interaction.deleteByKey(buObject, key) ⇒ <code>Promise.&lt;boolean&gt;</code>
Delete a metadata item from the specified business unit

**Kind**: static method of [<code>Interaction</code>](#Interaction)
Expand All @@ -2964,7 +2963,6 @@ Delete a metadata item from the specified business unit
| --- | --- | --- |
| buObject | <code>TYPE.BuObject</code> | references credentials |
| key | <code>string</code> | Identifier of item |
| version | <code>number</code> | required version of metadata |

<a name="Interaction.update"></a>

Expand Down
8 changes: 2 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ yargs
},
})
.command({
command: 'delete <BU> <TYPE> <EXTERNALKEY> [VERSION]',
command: 'delete <BU> <TYPE> <EXTERNALKEY>',
aliases: ['del'],
desc: 'deletes metadata of selected type and external key',
builder: (yargs) => {
Expand All @@ -156,16 +156,12 @@ yargs
.positional('EXTERNALKEY', {
type: 'string',
describe: 'the key to delete',
})
.positional('VERSION', {
type: 'string',
describe: 'some types have versions (e.g. interaction)',
});
},
handler: (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.deleteByKey(argv.BU, argv.TYPE, argv.EXTERNALKEY, argv.VERSION);
Mcdev.deleteByKey(argv.BU, argv.TYPE, argv.EXTERNALKEY);
},
})
.command({
Expand Down
5 changes: 2 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,9 @@ class Mcdev {
* @param {string} businessUnit references credentials from properties.json
* @param {string} type supported metadata type
* @param {string} customerKey Identifier of metadata
* @param {number} [version] optional version of metadata
* @returns {Promise.<void>} -
*/
static async deleteByKey(businessUnit, type, customerKey, version) {
static async deleteByKey(businessUnit, type, customerKey) {
Util.logger.info('mcdev:: delete');
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
Expand All @@ -378,7 +377,7 @@ class Mcdev {
}
try {
MetadataTypeInfo[type].properties = properties;
await MetadataTypeInfo[type].deleteByKey(buObject, customerKey, version);
await MetadataTypeInfo[type].deleteByKey(buObject, customerKey);
} catch (ex) {
Util.logger.errorStack(ex, ` - Deleting ${type} failed`);
}
Expand Down
30 changes: 23 additions & 7 deletions lib/metadataTypes/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Interaction extends MetadataType {
let mode = 'key';
if (key) {
/* eslint-disable unicorn/prefer-ternary */
if (key.startsWith('%23')) {
// in the journey URL the Id is prefixed with an HTML-encoded "#" which could accidentally be copied by users

singleKey = singleKey.slice(3);
}
if (key.startsWith('id:')) {
// ! allow selecting journeys by ID because that's what users see in the URL
singleKey = key.slice(3);
Expand Down Expand Up @@ -81,15 +86,10 @@ class Interaction extends MetadataType {
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} key Identifier of item
* @param {number} version required version of metadata
* @returns {Promise.<boolean>} deletion success status
*/
static async deleteByKey(buObject, key, version) {
if (Number.isNaN(version)) {
throw new TypeError(
'Version is required for deleting interactions to avoid accidental deletion of the wrong item.'
);
}
static async deleteByKey(buObject, key) {
let version;
let singleKey = '';
/* eslint-disable unicorn/prefer-ternary */
if (key.startsWith('id:')) {
Expand All @@ -99,7 +99,16 @@ class Interaction extends MetadataType {
// in the journey URL the Id is prefixed with an HTML-encoded "#" which could accidentally be copied by users
singleKey = singleKey.slice(3);
}
if (singleKey.includes('/')) {
// in the journey URL the version is appended after the ID, separated by a forward-slash.
[singleKey, version] = singleKey.split('/');
}
} else {
if (key.includes('/')) {
// in the journey URL the version is appended after the ID, separated by a forward-slash.
[singleKey, version] = key.split('/');
}

// delete by key with specified version does not work, therefore we need to get the ID first
const response = await this.client.rest.get(
`/interaction/v1/interactions/key:${key}?extras=`
Expand All @@ -108,6 +117,13 @@ class Interaction extends MetadataType {
singleKey = results[key].id;
Util.logger.debug(`Deleting interaction ${key} via its ID ${singleKey}`);
}
if (!/^\d+$/.test(version)) {
throw new TypeError(
'Version is required for deleting interactions to avoid accidental deletion of the wrong item. Please append it at the end of the key or id, separated by forward-slash. Example for deleting version 4: ' +
key +
'/4'
);
}
Util.logger.warn(
`Deleting Interactions via this command breaks following retrieve-by-key/id requests until you've deployed/created a new draft version! You can get still get the latest available version of your journey by retrieving all interactions on this BU.`
);
Expand Down

0 comments on commit 4e5c565

Please sign in to comment.